* 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)
| 426 | * @returns {void} |
| 427 | */ |
| 428 | function 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); |
no test coverage detected