@@ -166,18 +166,11 @@ export default class Block {
166
166
toString ( ) {
167
167
const { dev } = this . compiler . options ;
168
168
169
- let introing ;
170
- const hasIntros = ! this . builders . intro . isEmpty ( ) ;
171
- if ( hasIntros ) {
172
- introing = this . getUniqueName ( 'introing' ) ;
173
- this . addVariable ( introing ) ;
174
- }
175
-
176
- let outroing ;
177
- const hasOutros = ! this . builders . outro . isEmpty ( ) ;
178
- if ( hasOutros ) {
179
- outroing = this . alias ( 'outroing' ) ;
180
- this . addVariable ( outroing ) ;
169
+ let current ;
170
+ if ( this . hasIntroMethod || this . hasOutroMethod ) {
171
+ current = this . getUniqueName ( 'current' ) ;
172
+ this . addVariable ( current ) ;
173
+ this . builders . mount . addLine ( `${ current } = true;` ) ;
181
174
}
182
175
183
176
if ( this . autofocus ) {
@@ -275,46 +268,30 @@ export default class Block {
275
268
}
276
269
277
270
if ( this . hasIntroMethod || this . hasOutroMethod ) {
278
- if ( hasIntros ) {
271
+ if ( this . builders . mount . isEmpty ( ) && this . builders . outro . isEmpty ( ) ) {
272
+ properties . addBlock ( `i: @noop,` ) ;
273
+ properties . addBlock ( `o: @run,` ) ;
274
+ } else {
279
275
properties . addBlock ( deindent `
280
276
${ dev ? 'i: function intro' : 'i' } (#target, anchor) {
281
- if (${ introing } ) return;
282
- ${ introing } = true;
283
- ${ hasOutros && `${ outroing } = false;` }
284
-
277
+ console.trace("intro", #component.constructor.name, ${ current } );
278
+ if (${ current } ) return;
285
279
${ this . builders . intro }
286
-
287
280
this.m(#target, anchor);
288
281
},
289
282
` ) ;
290
- } else {
291
- if ( this . builders . mount . isEmpty ( ) ) {
292
- properties . addBlock ( `i: @noop,` ) ;
293
- } else {
294
- properties . addBlock ( deindent `
295
- ${ dev ? 'i: function intro' : 'i' } (#target, anchor) {
296
- this.m(#target, anchor);
297
- },
298
- ` ) ;
299
- }
300
- }
301
283
302
- if ( hasOutros ) {
303
284
properties . addBlock ( deindent `
304
285
${ dev ? 'o: function outro' : 'o' } (#outrocallback) {
305
- if ( ${ outroing } ) return ;
306
- ${ outroing } = true ;
307
- ${ hasIntros && ` ${ introing } = false;` }
286
+ console.trace("outro", #component.constructor.name, ${ current } ) ;
287
+ if (! ${ current } ) return ;
288
+ ${ current } = false;
308
289
309
290
${ this . outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${ this . outros } );` }
310
291
311
292
${ this . builders . outro }
312
293
},
313
294
` ) ;
314
- } else {
315
- properties . addBlock ( deindent `
316
- o: @run,
317
- ` ) ;
318
295
}
319
296
}
320
297
0 commit comments