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

Function create_item

packages/svelte/src/internal/client/dom/blocks/each.js:668–698  ·  view source on GitHub ↗

* @template V * @param {Map<any, EachItem>} items * @param {Node} anchor * @param {V} value * @param {unknown} key * @param {number} index * @param {(anchor: Node, item: V | Source<V>, index: number | Value<number>, collection: () => V[]) => void} render_fn * @param {number} flags * @param {

(items, anchor, value, key, index, render_fn, flags, get_collection)

Source from the content-addressed store, hash-verified

666 * @returns {EachItem}
667 */
668function create_item(items, anchor, value, key, index, render_fn, flags, get_collection) {
669 var v =
670 (flags & EACH_ITEM_REACTIVE) !== 0
671 ? (flags & EACH_ITEM_IMMUTABLE) === 0
672 ? mutable_source(value, false, false)
673 : source(value)
674 : null;
675
676 var i = (flags & EACH_INDEX_REACTIVE) !== 0 ? source(index) : null;
677
678 if (DEV && v) {
679 // For tracing purposes, we need to link the source signal we create with the
680 // collection + index so that tracing works as intended
681 v.trace = () => {
682 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
683 get_collection()[i?.v ?? index];
684 };
685 }
686
687 return {
688 v,
689 i,
690 e: branch(() => {
691 render_fn(anchor, v ?? value, i ?? index, get_collection);
692
693 return () => {
694 items.delete(key);
695 };
696 })
697 };
698}
699
700/**
701 * @param {Effect} effect

Callers 1

eachFunction · 0.85

Calls 4

mutable_sourceFunction · 0.90
sourceFunction · 0.90
branchFunction · 0.90
deleteMethod · 0.45

Tested by

no test coverage detected