@@ -49,30 +49,30 @@ export function index(_, i) {
49
49
/**
50
50
* Pause multiple effects simultaneously, and coordinate their
51
51
* subsequent destruction. Used in each blocks
52
- * @param {import('#client').Effect [] } effects
52
+ * @param {import('#client').EachItem [] } items
53
53
* @param {null | Node } controlled_anchor
54
54
* @param {() => void } [callback]
55
55
*/
56
- function pause_effects ( effects , controlled_anchor , callback ) {
56
+ function pause_effects ( items , controlled_anchor , callback ) {
57
57
/** @type {import('#client').TransitionManager[] } */
58
58
var transitions = [ ] ;
59
- var length = effects . length ;
59
+ var length = items . length ;
60
60
61
61
for ( var i = 0 ; i < length ; i ++ ) {
62
- pause_children ( effects [ i ] , transitions , true ) ;
62
+ pause_children ( items [ i ] . e , transitions , true ) ;
63
63
}
64
64
65
65
// If we have a controlled anchor, it means that the each block is inside a single
66
66
// DOM element, so we can apply a fast-path for clearing the contents of the element.
67
- if ( effects . length > 0 && transitions . length === 0 && controlled_anchor !== null ) {
67
+ if ( length > 0 && transitions . length === 0 && controlled_anchor !== null ) {
68
68
var parent_node = /** @type {Element } */ ( controlled_anchor . parentNode ) ;
69
69
parent_node . textContent = '' ;
70
70
parent_node . append ( controlled_anchor ) ;
71
71
}
72
72
73
73
run_out_transitions ( transitions , ( ) => {
74
74
for ( var i = 0 ; i < length ; i ++ ) {
75
- destroy_effect ( effects [ i ] ) ;
75
+ destroy_effect ( items [ i ] . e ) ;
76
76
}
77
77
78
78
if ( callback !== undefined ) callback ( ) ;
@@ -225,7 +225,9 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
225
225
*/
226
226
function reconcile ( array , state , anchor , render_fn , flags , get_key ) {
227
227
var is_animated = ( flags & EACH_IS_ANIMATED ) !== 0 ;
228
+ var should_update = ( flags & ( EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE ) ) !== 0 ;
228
229
230
+ var length = array . length ;
229
231
var items = state . items ;
230
232
var first = state . next ;
231
233
var current = first ;
@@ -255,7 +257,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
255
257
var item ;
256
258
257
259
if ( is_animated ) {
258
- for ( let i = 0 ; i < array . length ; i += 1 ) {
260
+ for ( let i = 0 ; i < length ; i += 1 ) {
259
261
value = array [ i ] ;
260
262
key = get_key ( value , i ) ;
261
263
item = items . get ( key ) ;
@@ -267,7 +269,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
267
269
}
268
270
}
269
271
270
- for ( let i = 0 ; i < array . length ; i += 1 ) {
272
+ for ( let i = 0 ; i < length ; i += 1 ) {
271
273
value = array [ i ] ;
272
274
key = get_key ( value , i ) ;
273
275
item = items . get ( key ) ;
@@ -293,7 +295,10 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
293
295
continue ;
294
296
}
295
297
296
- update_item ( item , value , i , flags ) ;
298
+ if ( should_update ) {
299
+ update_item ( item , value , i , flags ) ;
300
+ }
301
+
297
302
resume_effect ( item . e ) ;
298
303
299
304
if ( item !== current ) {
@@ -333,7 +338,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
333
338
matched = [ ] ;
334
339
stashed = [ ] ;
335
340
336
- while ( current && current . k !== key ) {
341
+ while ( current !== null && current . k !== key ) {
337
342
seen . add ( current ) ;
338
343
stashed . push ( current ) ;
339
344
current = current . next ;
@@ -358,16 +363,15 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
358
363
359
364
const to_destroy = Array . from ( seen ) ;
360
365
361
- pause_effects (
362
- to_destroy . map ( ( item ) => item . e ) ,
363
- null ,
364
- ( ) => {
365
- for ( const item of to_destroy ) {
366
- items . delete ( item . k ) ;
367
- link ( item . prev , item . next ) ;
368
- }
366
+ var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && length === 0 ? anchor : null ;
367
+
368
+ pause_effects ( to_destroy , controlled_anchor , ( ) => {
369
+ for ( var i = 0 ; i < to_destroy . length ; i += 1 ) {
370
+ var item = to_destroy [ i ] ;
371
+ items . delete ( item . k ) ;
372
+ link ( item . prev , item . next ) ;
369
373
}
370
- ) ;
374
+ } ) ;
371
375
372
376
if ( is_animated ) {
373
377
effect ( ( ) => {
@@ -448,7 +452,7 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
448
452
} ;
449
453
450
454
prev . next = item ;
451
- if ( next ) next . prev = item ;
455
+ if ( next !== null ) next . prev = item ;
452
456
453
457
current_each_item = item ;
454
458
item . e = branch ( ( ) => render_fn ( anchor , v , i ) ) ;
@@ -489,5 +493,5 @@ function move(item, prev, anchor) {
489
493
*/
490
494
function link ( prev , next ) {
491
495
prev . next = next ;
492
- if ( next ) next . prev = prev ;
496
+ if ( next !== null ) next . prev = prev ;
493
497
}
0 commit comments