Skip to content

Commit cefff62

Browse files
committed
more
1 parent c0a069c commit cefff62

File tree

1 file changed

+39
-43
lines changed
  • packages/svelte/src/internal/client/dom/blocks

1 file changed

+39
-43
lines changed

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { TemplateNode } from '#client' */
1+
/** @import { EachItem, EachState, Effect, EffectNodes, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */
22
import {
33
EACH_INDEX_REACTIVE,
44
EACH_IS_ANIMATED,
@@ -36,11 +36,11 @@ import { current_effect } from '../../runtime.js';
3636
/**
3737
* The row of a keyed each block that is currently updating. We track this
3838
* so that `animate:` directives have something to attach themselves to
39-
* @type {import('#client').EachItem | null}
39+
* @type {EachItem | null}
4040
*/
4141
export let current_each_item = null;
4242

43-
/** @param {import('#client').EachItem | null} item */
43+
/** @param {EachItem | null} item */
4444
export function set_current_each_item(item) {
4545
current_each_item = item;
4646
}
@@ -56,13 +56,13 @@ export function index(_, i) {
5656
/**
5757
* Pause multiple effects simultaneously, and coordinate their
5858
* subsequent destruction. Used in each blocks
59-
* @param {import('#client').EachState} state
60-
* @param {import('#client').EachItem[]} items
59+
* @param {EachState} state
60+
* @param {EachItem[]} items
6161
* @param {null | Node} controlled_anchor
6262
* @param {Map<any, import("#client").EachItem>} items_map
6363
*/
6464
function pause_effects(state, items, controlled_anchor, items_map) {
65-
/** @type {import('#client').TransitionManager[]} */
65+
/** @type {TransitionManager[]} */
6666
var transitions = [];
6767
var length = items.length;
6868

@@ -101,14 +101,14 @@ function pause_effects(state, items, controlled_anchor, items_map) {
101101
* @param {number} flags
102102
* @param {() => V[]} get_collection
103103
* @param {(value: V, index: number) => any} get_key
104-
* @param {(anchor: Node, item: import('#client').MaybeSource<V>, index: import('#client').MaybeSource<number>) => void} render_fn
104+
* @param {(anchor: Node, item: MaybeSource<V>, index: MaybeSource<number>) => void} render_fn
105105
* @param {null | ((anchor: Node) => void)} fallback_fn
106106
* @returns {void}
107107
*/
108108
export function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
109109
var anchor = node;
110110

111-
/** @type {import('#client').EachState} */
111+
/** @type {EachState} */
112112
var state = { flags, items: new Map(), first: null };
113113

114114
var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
@@ -125,7 +125,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
125125
hydrate_next();
126126
}
127127

128-
/** @type {import('#client').Effect | null} */
128+
/** @type {Effect | null} */
129129
var fallback = null;
130130

131131
block(() => {
@@ -174,10 +174,10 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
174174

175175
// this is separate to the previous block because `hydrating` might change
176176
if (hydrating) {
177-
/** @type {import('#client').EachItem | null} */
177+
/** @type {EachItem | null} */
178178
var prev = null;
179179

180-
/** @type {import('#client').EachItem} */
180+
/** @type {EachItem} */
181181
var item;
182182

183183
for (var i = 0; i < length; i++) {
@@ -239,9 +239,9 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
239239
/**
240240
* @template V
241241
* @param {Array<V>} array
242-
* @param {import('#client').EachState} state
242+
* @param {EachState} state
243243
* @param {Element | Comment | Text} anchor
244-
* @param {(anchor: Node, item: import('#client').MaybeSource<V>, index: number | import('#client').Source<number>) => void} render_fn
244+
* @param {(anchor: Node, item: MaybeSource<V>, index: number | Source<number>) => void} render_fn
245245
* @param {number} flags
246246
* @param {(value: V, index: number) => any} get_key
247247
* @returns {void}
@@ -255,19 +255,19 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
255255
var first = state.first;
256256
var current = first;
257257

258-
/** @type {Set<import('#client').EachItem>} */
258+
/** @type {Set<EachItem>} */
259259
var seen = new Set();
260260

261-
/** @type {import('#client').EachItem | null} */
261+
/** @type {EachItem | null} */
262262
var prev = null;
263263

264-
/** @type {Set<import('#client').EachItem>} */
264+
/** @type {Set<EachItem>} */
265265
var to_animate = new Set();
266266

267-
/** @type {import('#client').EachItem[]} */
267+
/** @type {EachItem[]} */
268268
var matched = [];
269269

270-
/** @type {import('#client').EachItem[]} */
270+
/** @type {EachItem[]} */
271271
var stashed = [];
272272

273273
/** @type {V} */
@@ -276,7 +276,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
276276
/** @type {any} */
277277
var key;
278278

279-
/** @type {import('#client').EachItem | undefined} */
279+
/** @type {EachItem | undefined} */
280280
var item;
281281

282282
/** @type {number} */
@@ -301,9 +301,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
301301
item = items.get(key);
302302

303303
if (item === undefined) {
304-
var child_anchor = current
305-
? /** @type {import('#client').EffectNodes} */ (current.e.nodes).start
306-
: anchor;
304+
var child_anchor = current ? /** @type {EffectNodes} */ (current.e.nodes).start : anchor;
307305

308306
prev = create_item(
309307
child_anchor,
@@ -436,12 +434,12 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
436434
});
437435
}
438436

439-
/** @type {import('#client').Effect} */ (current_effect).first = state.first && state.first.e;
440-
/** @type {import('#client').Effect} */ (current_effect).last = prev && prev.e;
437+
/** @type {Effect} */ (current_effect).first = state.first && state.first.e;
438+
/** @type {Effect} */ (current_effect).last = prev && prev.e;
441439
}
442440

443441
/**
444-
* @param {import('#client').EachItem} item
442+
* @param {EachItem} item
445443
* @param {any} value
446444
* @param {number} index
447445
* @param {number} type
@@ -453,7 +451,7 @@ function update_item(item, value, index, type) {
453451
}
454452

455453
if ((type & EACH_INDEX_REACTIVE) !== 0) {
456-
set(/** @type {import('#client').Value<number>} */ (item.i), index);
454+
set(/** @type {Value<number>} */ (item.i), index);
457455
} else {
458456
item.i = index;
459457
}
@@ -462,15 +460,15 @@ function update_item(item, value, index, type) {
462460
/**
463461
* @template V
464462
* @param {Node} anchor
465-
* @param {import('#client').EachState} state
466-
* @param {import('#client').EachItem | null} prev
467-
* @param {import('#client').EachItem | null} next
463+
* @param {EachState} state
464+
* @param {EachItem | null} prev
465+
* @param {EachItem | null} next
468466
* @param {V} value
469467
* @param {unknown} key
470468
* @param {number} index
471-
* @param {(anchor: Node, item: V | import('#client').Source<V>, index: number | import('#client').Value<number>) => void} render_fn
469+
* @param {(anchor: Node, item: V | Source<V>, index: number | Value<number>) => void} render_fn
472470
* @param {number} flags
473-
* @returns {import('#client').EachItem}
471+
* @returns {EachItem}
474472
*/
475473
function create_item(anchor, state, prev, next, value, key, index, render_fn, flags) {
476474
var previous_each_item = current_each_item;
@@ -482,7 +480,7 @@ function create_item(anchor, state, prev, next, value, key, index, render_fn, fl
482480
var v = reactive ? (mutable ? mutable_source(value) : source(value)) : value;
483481
var i = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index);
484482

485-
/** @type {import('#client').EachItem} */
483+
/** @type {EachItem} */
486484
var item = {
487485
i,
488486
v,
@@ -519,29 +517,27 @@ function create_item(anchor, state, prev, next, value, key, index, render_fn, fl
519517
}
520518

521519
/**
522-
* @param {import('#client').EachItem} item
523-
* @param {import('#client').EachItem | null} next
520+
* @param {EachItem} item
521+
* @param {EachItem | null} next
524522
* @param {Text | Element | Comment} anchor
525523
*/
526524
function move(item, next, anchor) {
527-
var end = item.next
528-
? /** @type {import('#client').EffectNodes} */ (item.next.e.nodes).start
529-
: anchor;
525+
var end = item.next ? /** @type {EffectNodes} */ (item.next.e.nodes).start : anchor;
530526

531-
var dest = next ? /** @type {import('#client').EffectNodes} */ (next.e.nodes).start : anchor;
532-
var node = /** @type {import('#client').EffectNodes} */ (item.e.nodes).start;
527+
var dest = next ? /** @type {EffectNodes} */ (next.e.nodes).start : anchor;
528+
var node = /** @type {EffectNodes} */ (item.e.nodes).start;
533529

534530
while (node !== end) {
535-
var next_node = /** @type {import('#client').TemplateNode} */ (node.nextSibling);
531+
var next_node = /** @type {TemplateNode} */ (node.nextSibling);
536532
dest.before(node);
537533
node = next_node;
538534
}
539535
}
540536

541537
/**
542-
* @param {import('#client').EachState} state
543-
* @param {import('#client').EachItem | null} prev
544-
* @param {import('#client').EachItem | null} next
538+
* @param {EachState} state
539+
* @param {EachItem | null} prev
540+
* @param {EachItem | null} next
545541
*/
546542
function link(state, prev, next) {
547543
if (prev === null) {

0 commit comments

Comments
 (0)