each() — svelte Function Reference
Architecture documentation for the each() function in each.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 7f76e82e_4ed8_1525_9136_2ae67868d44e["each()"] ca0d28d0_c4b0_db5c_32c9_bdad64d5deaa["each.js"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|defined in| ca0d28d0_c4b0_db5c_32c9_bdad64d5deaa 40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 40f27ad3_30bb_8f2a_3fb3_757088cf7428 f3bd5a62_2879_ccbe_7046_712cbf9eeaab["get_first_child()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| f3bd5a62_2879_ccbe_7046_712cbf9eeaab ec54e18a_a454_5d8c_9e00_7bc16e4f49c4["create_text()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| ec54e18a_a454_5d8c_9e00_7bc16e4f49c4 b31601aa_35ce_7827_5394_99fb97fa27d2["hydrate_next()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| b31601aa_35ce_7827_5394_99fb97fa27d2 bce9da9e_fd64_163a_8582_ad1a0c6518ce["derived_safe_equal()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| bce9da9e_fd64_163a_8582_ad1a0c6518ce 3ceb9b1c_7062_d75e_744a_fd12a80dfdc9["reconcile()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 3ceb9b1c_7062_d75e_744a_fd12a80dfdc9 9c654195_2948_bf49_8faa_cded59a1e3b9["resume_effect()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 9c654195_2948_bf49_8faa_cded59a1e3b9 1061f0bd_2bf2_7402_fa62_318d8455bb96["move()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 1061f0bd_2bf2_7402_fa62_318d8455bb96 27507f0c_dcab_c3a5_2ce6_5e4b1ef9df3d["pause_effect()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 27507f0c_dcab_c3a5_2ce6_5e4b1ef9df3d 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b["block()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b a08b6cc5_af73_1be4_d02f_3113cf8a8305["get()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| a08b6cc5_af73_1be4_d02f_3113cf8a8305 965d3fe6_c7da_0708_eb2c_13a616bc4bca["read_hydration_instruction()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 965d3fe6_c7da_0708_eb2c_13a616bc4bca 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e["skip_nodes()"] 7f76e82e_4ed8_1525_9136_2ae67868d44e -->|calls| 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e style 7f76e82e_4ed8_1525_9136_2ae67868d44e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/internal/client/dom/blocks/each.js lines 153–347
export function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
var anchor = node;
/** @type {Map<any, EachItem>} */
var items = new Map();
var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
if (is_controlled) {
var parent_node = /** @type {Element} */ (node);
anchor = hydrating
? set_hydrate_node(get_first_child(parent_node))
: parent_node.appendChild(create_text());
}
if (hydrating) {
hydrate_next();
}
/** @type {Effect | null} */
var fallback = null;
// TODO: ideally we could use derived for runes mode but because of the ability
// to use a store which can be mutated, we can't do that here as mutating a store
// will still result in the collection array being the same from the store
var each_array = derived_safe_equal(() => {
var collection = get_collection();
return is_array(collection) ? collection : collection == null ? [] : array_from(collection);
});
/** @type {V[]} */
var array;
var first_run = true;
function commit() {
state.fallback = fallback;
reconcile(state, array, anchor, flags, get_key);
if (fallback !== null) {
if (array.length === 0) {
if ((fallback.f & EFFECT_OFFSCREEN) === 0) {
resume_effect(fallback);
} else {
fallback.f ^= EFFECT_OFFSCREEN;
move(fallback, null, anchor);
}
} else {
pause_effect(fallback, () => {
// TODO only null out if no pending batch needs it,
// otherwise re-add `fallback.fragment` and move the
// effect into it
fallback = null;
});
}
}
}
var effect = block(() => {
array = /** @type {V[]} */ (get(each_array));
var length = array.length;
/** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false;
if (hydrating) {
var is_else = read_hydration_instruction(anchor) === HYDRATION_START_ELSE;
if (is_else !== (length === 0)) {
// hydration mismatch — remove the server-rendered DOM and start over
anchor = skip_nodes();
set_hydrate_node(anchor);
set_hydrating(false);
mismatch = true;
}
}
var keys = new Set();
Domain
Subdomains
Calls
- block()
- branch()
- create_item()
- create_text()
- derived_safe_equal()
- each_key_duplicate()
- get()
- get_first_child()
- hydrate_next()
- internal_set()
- move()
- oncommit()
- ondiscard()
- pause_effect()
- read_hydration_instruction()
- reconcile()
- resume_effect()
- set()
- set_hydrate_node()
- set_hydrating()
- should_defer_append()
- skip_effect()
- skip_nodes()
- unskip_effect()
- validate_each_keys()
Source
Frequently Asked Questions
What does each() do?
each() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/blocks/each.js.
Where is each() defined?
each() is defined in packages/svelte/src/internal/client/dom/blocks/each.js at line 153.
What does each() call?
each() calls 25 function(s): block, branch, create_item, create_text, derived_safe_equal, each_key_duplicate, get, get_first_child, and 17 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free