@@ -64,15 +64,17 @@ export default function visitEachBlock ( generator: DomGenerator, block: Block,
64
64
${ each_block_else } = ${ node . else . _block . name } ( ${ params } , ${ block . component } );
65
65
${ each_block_else } .${ mountOrIntro } ( ${ parentNode } , ${ anchor } );
66
66
} else if ( ${ each_block_else } ) {
67
- ${ each_block_else } .destroy( true );
67
+ ${ each_block_else } .unmount();
68
+ ${ each_block_else } .destroy();
68
69
${ each_block_else } = null;
69
70
}
70
71
` ) ;
71
72
} else {
72
73
block . builders . update . addBlock ( deindent `
73
74
if ( ${ each_block_value } .length ) {
74
75
if ( ${ each_block_else } ) {
75
- ${ each_block_else } .destroy( true );
76
+ ${ each_block_else } .unmount();
77
+ ${ each_block_else } .destroy();
76
78
${ each_block_else } = null;
77
79
}
78
80
} else if ( !${ each_block_else } ) {
@@ -82,11 +84,12 @@ export default function visitEachBlock ( generator: DomGenerator, block: Block,
82
84
` ) ;
83
85
}
84
86
87
+ block . builders . unmount . addLine (
88
+ `if ( ${ each_block_else } ) ${ each_block_else } .unmount()`
89
+ ) ;
85
90
86
91
block . builders . destroy . addBlock ( deindent `
87
- if ( ${ each_block_else } ) {
88
- ${ each_block_else } .destroy( ${ isToplevel ? 'detach' : 'false' } );
89
- }
92
+ if ( ${ each_block_else } ) ${ each_block_else } .destroy( false );
90
93
` ) ;
91
94
}
92
95
@@ -154,7 +157,8 @@ function keyed ( generator: DomGenerator, block: Block, state: State, node: Node
154
157
block . builders . create . addBlock ( deindent `
155
158
function ${ fn } ( iteration ) {
156
159
iteration.outro( function () {
157
- iteration.destroy( true );
160
+ iteration.unmount();
161
+ iteration.destroy();
158
162
${ lookup } [iteration.key] = null;
159
163
});
160
164
}
@@ -176,7 +180,8 @@ function keyed ( generator: DomGenerator, block: Block, state: State, node: Node
176
180
const fn = block . getUniqueName ( `${ each_block } _destroy` ) ;
177
181
block . builders . create . addBlock ( deindent `
178
182
function ${ fn } ( iteration ) {
179
- iteration.destroy( true );
183
+ iteration.unmount();
184
+ iteration.destroy();
180
185
${ lookup } [iteration.key] = null;
181
186
}
182
187
` ) ;
@@ -262,10 +267,20 @@ function keyed ( generator: DomGenerator, block: Block, state: State, node: Node
262
267
${ head } = ${ lookup } [${ each_block_value } [0] && ${ each_block_value } [0].${ node . key } ];
263
268
` ) ;
264
269
270
+ if ( ! state . parentNode ) {
271
+ block . builders . unmount . addBlock ( deindent `
272
+ var ${ iteration } = ${ head } ;
273
+ while ( ${ iteration } ) {
274
+ ${ iteration } .unmount();
275
+ ${ iteration } = ${ iteration } .next;
276
+ }
277
+ ` ) ;
278
+ }
279
+
265
280
block . builders . destroy . addBlock ( deindent `
266
281
var ${ iteration } = ${ head } ;
267
282
while ( ${ iteration } ) {
268
- ${ iteration } .destroy( ${ state . parentNode ? ' false' : 'detach' } );
283
+ ${ iteration } .destroy( false );
269
284
${ iteration } = ${ iteration } .next;
270
285
}
271
286
` ) ;
@@ -334,7 +349,8 @@ function unkeyed ( generator: DomGenerator, block: Block, state: State, node: No
334
349
function ${ outro } ( i ) {
335
350
if ( ${ iterations } [i] ) {
336
351
${ iterations } [i].outro( function () {
337
- ${ iterations } [i].destroy( true );
352
+ ${ iterations } [i].unmount();
353
+ ${ iterations } [i].destroy();
338
354
${ iterations } [i] = null;
339
355
});
340
356
}
@@ -343,7 +359,10 @@ function unkeyed ( generator: DomGenerator, block: Block, state: State, node: No
343
359
for ( ; ${ i } < ${ iterations } .length; ${ i } += 1 ) ${ outro } ( ${ i } );
344
360
` :
345
361
deindent `
346
- ${ generator . helper ( 'destroyEach' ) } ( ${ iterations } , true, ${ each_block_value } .length );
362
+ for ( ; ${ i } < ${ iterations } .length; ${ i } += 1 ) {
363
+ ${ iterations } [${ i } ].unmount();
364
+ ${ iterations } [${ i } ].destroy();
365
+ }
347
366
${ iterations } .length = ${ each_block_value } .length;
348
367
` ;
349
368
@@ -360,7 +379,13 @@ function unkeyed ( generator: DomGenerator, block: Block, state: State, node: No
360
379
` ) ;
361
380
}
362
381
382
+ block . builders . unmount . addBlock ( deindent `
383
+ for ( var ${ i } = 0; ${ i } < ${ iterations } .length; ${ i } += 1 ) {
384
+ ${ iterations } [${ i } ].unmount();
385
+ }
386
+ ` ) ;
387
+
363
388
block . builders . destroy . addBlock (
364
- `${ generator . helper ( 'destroyEach' ) } ( ${ iterations } , ${ state . parentNode ? ' false' : 'detach' } , 0 );`
389
+ `${ generator . helper ( 'destroyEach' ) } ( ${ iterations } , false, 0 );`
365
390
) ;
366
391
}
0 commit comments