@@ -52,6 +52,7 @@ export default class Block {
52
52
claim : Array < Node | Node [ ] > ;
53
53
hydrate : Array < Node | Node [ ] > ;
54
54
mount : Array < Node | Node [ ] > ;
55
+ bubble : Array < Node | Node [ ] > ;
55
56
measure : Array < Node | Node [ ] > ;
56
57
fix : Array < Node | Node [ ] > ;
57
58
animate : Array < Node | Node [ ] > ;
@@ -100,6 +101,7 @@ export default class Block {
100
101
claim : [ ] ,
101
102
hydrate : [ ] ,
102
103
mount : [ ] ,
104
+ bubble : [ ] ,
103
105
measure : [ ] ,
104
106
fix : [ ] ,
105
107
animate : [ ] ,
@@ -292,9 +294,39 @@ export default class Block {
292
294
}` ;
293
295
}
294
296
297
+ if ( this . chunks . bubble . length === 0 ) {
298
+ properties . bubble = noop ;
299
+ } else {
300
+ const mounted : Identifier = {
301
+ type : 'Identifier' ,
302
+ name : '#mounted'
303
+ } ;
304
+ this . add_variable ( mounted , x `false` ) ;
305
+ const bubble_fns : Identifier = {
306
+ type : 'Identifier' ,
307
+ name : '#bubble_fns'
308
+ } ;
309
+ this . add_variable ( bubble_fns , x `[]` ) ;
310
+
311
+ properties . bubble = x `function #bubble(type, callback) {
312
+ const local_dispose = [];
313
+ const fn = () => {
314
+ ${ this . chunks . bubble }
315
+ #dispose.push(...local_dispose);
316
+ }
317
+ if (${ mounted } ) fn()
318
+ else ${ bubble_fns } .push(fn);
319
+ return () => @run_all(local_dispose);
320
+ }` ;
321
+ this . chunks . mount . push ( b `
322
+ ${ mounted } = true;
323
+ @run_all(${ bubble_fns } );
324
+ ` ) ;
325
+ }
326
+
295
327
if ( this . chunks . mount . length === 0 ) {
296
328
properties . mount = noop ;
297
- } else if ( this . event_listeners . length === 0 ) {
329
+ } else if ( this . event_listeners . length === 0 && this . chunks . bubble . length === 0 ) {
298
330
properties . mount = x `function #mount(#target, #anchor) {
299
331
${ this . chunks . mount }
300
332
}` ;
@@ -378,6 +410,7 @@ export default class Block {
378
410
l: ${ properties . claim } ,
379
411
h: ${ properties . hydrate } ,
380
412
m: ${ properties . mount } ,
413
+ b: ${ properties . bubble } ,
381
414
p: ${ properties . update } ,
382
415
r: ${ properties . measure } ,
383
416
f: ${ properties . fix } ,
@@ -428,6 +461,7 @@ export default class Block {
428
461
this . chunks . hydrate . length > 0 ||
429
462
this . chunks . claim . length > 0 ||
430
463
this . chunks . mount . length > 0 ||
464
+ this . chunks . bubble . length > 0 ||
431
465
this . chunks . update . length > 0 ||
432
466
this . chunks . destroy . length > 0 ||
433
467
this . has_animation ;
@@ -451,15 +485,26 @@ export default class Block {
451
485
}
452
486
453
487
render_listeners ( chunk : string = '' ) {
454
- if ( this . event_listeners . length > 0 ) {
488
+ if ( this . chunks . bubble . length > 0 || this . event_listeners . length > 0 ) {
455
489
const dispose : Identifier = {
456
490
type : 'Identifier' ,
457
491
name : `#dispose${ chunk } `
458
492
} ;
459
493
460
494
this . add_variable ( dispose ) ;
461
495
462
- if ( this . event_listeners . length === 1 ) {
496
+ if ( this . chunks . bubble . length > 0 || this . event_listeners . length > 1 ) {
497
+ this . chunks . mount . push ( b `
498
+ if (#remount) @run_all(${ dispose } );
499
+ ${ dispose } = [
500
+ ${ this . event_listeners . length > 0 ? this . event_listeners : '' }
501
+ ];
502
+ ` ) ;
503
+
504
+ this . chunks . destroy . push (
505
+ b `@run_all(${ dispose } );`
506
+ ) ;
507
+ } else {
463
508
this . chunks . mount . push (
464
509
b `
465
510
if (#remount) ${ dispose } ();
@@ -470,18 +515,7 @@ export default class Block {
470
515
this . chunks . destroy . push (
471
516
b `${ dispose } ();`
472
517
) ;
473
- } else {
474
- this . chunks . mount . push ( b `
475
- if (#remount) @run_all(${ dispose } );
476
- ${ dispose } = [
477
- ${ this . event_listeners }
478
- ];
479
- ` ) ;
480
-
481
- this . chunks . destroy . push (
482
- b `@run_all(${ dispose } );`
483
- ) ;
484
518
}
485
519
}
486
520
}
487
- }
521
+ }
0 commit comments