@@ -15,11 +15,9 @@ import { untrack } from '../../runtime.js';
15
15
import {
16
16
block ,
17
17
branch ,
18
- destroy_effect ,
19
18
effect ,
20
- run_out_transitions ,
21
- pause_children ,
22
19
pause_effect ,
20
+ pause_effects ,
23
21
resume_effect
24
22
} from '../../reactivity/effects.js' ;
25
23
import { source , mutable_source , set } from '../../reactivity/sources.js' ;
@@ -41,39 +39,6 @@ export function set_current_each_item(item) {
41
39
current_each_item = item ;
42
40
}
43
41
44
- /**
45
- * Pause multiple effects simultaneously, and coordinate their
46
- * subsequent destruction. Used in each blocks
47
- * @param {import('#client').Effect[] } effects
48
- * @param {null | Node } controlled_anchor
49
- * @param {() => void } [callback]
50
- */
51
- function pause_effects ( effects , controlled_anchor , callback ) {
52
- /** @type {import('#client').TransitionManager[] } */
53
- var transitions = [ ] ;
54
- var length = effects . length ;
55
-
56
- for ( var i = 0 ; i < length ; i ++ ) {
57
- pause_children ( effects [ i ] , transitions , true ) ;
58
- }
59
-
60
- // If we have a controlled anchor, it means that the each block is inside a single
61
- // DOM element, so we can apply a fast-path for clearing the contents of the element.
62
- if ( effects . length > 0 && transitions . length === 0 && controlled_anchor !== null ) {
63
- var parent_node = /** @type {Element } */ ( controlled_anchor . parentNode ) ;
64
- parent_node . textContent = '' ;
65
- parent_node . append ( controlled_anchor ) ;
66
- }
67
-
68
- run_out_transitions ( transitions , ( ) => {
69
- for ( var i = 0 ; i < length ; i ++ ) {
70
- destroy_effect ( effects [ i ] ) ;
71
- }
72
-
73
- if ( callback !== undefined ) callback ( ) ;
74
- } ) ;
75
- }
76
-
77
42
/**
78
43
* @template V
79
44
* @param {Element | Comment } anchor The next sibling node, or the parent node if this is a 'controlled' block
@@ -180,6 +145,7 @@ function each(anchor, flags, get_collection, get_key, render_fn, fallback_fn, re
180
145
}
181
146
182
147
if ( ! hydrating ) {
148
+ // TODO add 'empty controlled block' optimisation here
183
149
reconcile_fn ( array , state , anchor , render_fn , flags , keys ) ;
184
150
}
185
151
@@ -278,9 +244,7 @@ function reconcile_indexed_array(array, state, anchor, render_fn, flags) {
278
244
effects . push ( a_items [ i ] . e ) ;
279
245
}
280
246
281
- var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && b === 0 ? anchor : null ;
282
-
283
- pause_effects ( effects , controlled_anchor , ( ) => {
247
+ pause_effects ( effects , ( ) => {
284
248
state . items . length = b ;
285
249
} ) ;
286
250
}
@@ -310,7 +274,6 @@ function reconcile_tracked_array(array, state, anchor, render_fn, flags, keys) {
310
274
311
275
var is_animated = ( flags & EACH_IS_ANIMATED ) !== 0 ;
312
276
var should_update = ( flags & ( EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE ) ) !== 0 ;
313
- var is_controlled = ( flags & EACH_IS_CONTROLLED ) !== 0 ;
314
277
var start = 0 ;
315
278
var item ;
316
279
@@ -418,11 +381,6 @@ function reconcile_tracked_array(array, state, anchor, render_fn, flags, keys) {
418
381
// I fully understand this part)
419
382
if ( moved ) {
420
383
mark_lis ( sources ) ;
421
- } else if ( is_controlled && to_destroy . length === a_items . length ) {
422
- // We can optimize the case in which all items are replaced —
423
- // destroy everything first, then append new items
424
- pause_effects ( to_destroy , anchor ) ;
425
- to_destroy = [ ] ;
426
384
}
427
385
428
386
// working from the back, insert new or moved items
@@ -463,9 +421,9 @@ function reconcile_tracked_array(array, state, anchor, render_fn, flags, keys) {
463
421
} ) ;
464
422
}
465
423
466
- var controlled_anchor = is_controlled && b === 0 ? anchor : null ;
467
-
468
- pause_effects ( to_destroy , controlled_anchor , ( ) => {
424
+ // TODO: would be good to avoid this closure in the case where we have no
425
+ // transitions at all. It would make it far more JIT friendly in the hot cases.
426
+ pause_effects ( to_destroy , ( ) => {
469
427
state . items = b_items ;
470
428
} ) ;
471
429
}
0 commit comments