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

Function reconcile

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

* Add, remove, or reorder items output by an each block as its input changes * @template V * @param {EachState} state * @param {Array<V>} array * @param {Element | Comment | Text} anchor * @param {number} flags * @param {(value: V, index: number) => any} get_key * @returns {void}

(state, array, anchor, flags, get_key)

Source from the content-addressed store, hash-verified

426 * @returns {void}
427 */
428function reconcile(state, array, anchor, flags, get_key) {
429 var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
430
431 var length = array.length;
432 var items = state.items;
433 var current = skip_to_branch(state.effect.first);
434
435 /** @type {undefined | Set<Effect>} */
436 var seen;
437
438 /** @type {Effect | null} */
439 var prev = null;
440
441 /** @type {undefined | Set<Effect>} */
442 var to_animate;
443
444 /** @type {Effect[]} */
445 var matched = [];
446
447 /** @type {Effect[]} */
448 var stashed = [];
449
450 /** @type {V} */
451 var value;
452
453 /** @type {any} */
454 var key;
455
456 /** @type {Effect | undefined} */
457 var effect;
458
459 /** @type {number} */
460 var i;
461
462 if (is_animated) {
463 for (i = 0; i < length; i += 1) {
464 value = array[i];
465 key = get_key(value, i);
466 effect = /** @type {EachItem} */ (items.get(key)).e;
467
468 // offscreen == coming in now, no animation in that case,
469 // else this would happen https://github.com/sveltejs/svelte/issues/17181
470 if ((effect.f & EFFECT_OFFSCREEN) === 0) {
471 effect.nodes?.a?.measure();
472 (to_animate ??= new Set()).add(effect);
473 }
474 }
475 }
476
477 for (i = 0; i < length; i += 1) {
478 value = array[i];
479 key = get_key(value, i);
480
481 effect = /** @type {EachItem} */ (items.get(key)).e;
482
483 if (state.outrogroups !== null) {
484 for (const group of state.outrogroups) {
485 group.pending.delete(effect);

Callers 1

commitFunction · 0.85

Calls 13

resume_effectFunction · 0.90
queue_micro_taskFunction · 0.90
skip_to_branchFunction · 0.85
moveFunction · 0.85
linkFunction · 0.85
destroy_effectsFunction · 0.85
pause_effectsFunction · 0.85
pushMethod · 0.80
getMethod · 0.45
addMethod · 0.45
deleteMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected