MCPcopy
hub / github.com/sveltejs/svelte / each

Function each

packages/svelte/src/internal/client/dom/blocks/each.js:177–404  ·  view source on GitHub ↗
(node, flags, get_collection, get_key, render_fn, fallback_fn = null)

Source from the content-addressed store, hash-verified

175 * @returns {void}
176 */
177export function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
178 var anchor = node;
179
180 /** @type {Map<any, EachItem>} */
181 var items = new Map();
182
183 var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
184
185 if (is_controlled) {
186 var parent_node = /** @type {Element} */ (node);
187
188 anchor = hydrating
189 ? set_hydrate_node(get_first_child(parent_node))
190 : parent_node.appendChild(create_text());
191 }
192
193 if (hydrating) {
194 hydrate_next();
195 }
196
197 /** @type {Effect | null} */
198 var fallback = null;
199
200 // TODO: ideally we could use derived for runes mode but because of the ability
201 // to use a store which can be mutated, we can't do that here as mutating a store
202 // will still result in the collection array being the same from the store
203 var each_array = derived_safe_equal(() => {
204 var collection = get_collection();
205
206 return /** @type {V[]} */ (
207 is_array(collection) ? collection : collection == null ? [] : array_from(collection)
208 );
209 });
210
211 if (DEV) {
212 tag(each_array, '{#each ...}');
213 }
214
215 /** @type {V[]} */
216 var array;
217
218 /** @type {Map<Batch, Set<any>>} */
219 var pending = new Map();
220
221 var first_run = true;
222
223 /**
224 * @param {Batch} batch
225 */
226 function commit(batch) {
227 if ((state.effect.f & DESTROYED) !== 0) {
228 return;
229 }
230
231 state.pending.delete(batch);
232
233 state.fallback = fallback;
234 reconcile(state, array, anchor, flags, get_key);

Callers

nothing calls this directly

Calls 15

set_hydrate_nodeFunction · 0.90
get_first_childFunction · 0.90
create_textFunction · 0.90
hydrate_nextFunction · 0.90
derived_safe_equalFunction · 0.90
tagFunction · 0.90
blockFunction · 0.90
getFunction · 0.90
skip_nodesFunction · 0.90
set_hydratingFunction · 0.90
should_defer_appendFunction · 0.90

Tested by

no test coverage detected