@@ -9,7 +9,7 @@ import type {
9
9
SimpleNode ,
10
10
} from '@glimmer/interfaces' ;
11
11
import type { TemplateOnlyComponent } from '@glimmer/runtime' ;
12
- import { setComponentTemplate } from '@glimmer/manager' ;
12
+ import { modifierCapabilities , setComponentTemplate , setModifierManager } from '@glimmer/manager' ;
13
13
import { EMPTY_ARGS , templateOnlyComponent , TemplateOnlyComponentManager } from '@glimmer/runtime' ;
14
14
import { assign , expect } from '@glimmer/util' ;
15
15
@@ -67,6 +67,21 @@ class DebugRenderTreeDelegate extends JitRenderDelegate {
67
67
68
68
this . registry . register ( 'component' , name , definition ) ;
69
69
}
70
+
71
+ registerCustomModifier ( name : string ) {
72
+ const r = setModifierManager (
73
+ ( ) => ( {
74
+ capabilities : modifierCapabilities ( '3.22' ) ,
75
+ createModifier ( ) { } ,
76
+ installModifier ( ) { } ,
77
+ updateModifier ( ) { } ,
78
+ destroyModifier ( ) { } ,
79
+ } ) ,
80
+ class DidInsertModifier { }
81
+ ) ;
82
+ this . registry . register ( 'modifier' , name , r ) ;
83
+ return r ;
84
+ }
70
85
}
71
86
72
87
class DebugRenderTreeTest extends RenderTest {
@@ -327,6 +342,196 @@ class DebugRenderTreeTest extends RenderTest {
327
342
] ,
328
343
} ,
329
344
] ,
345
+ }
346
+ ] ) ;
347
+ }
348
+
349
+ @test modifiers ( ) {
350
+ this . registerComponent ( 'Glimmer' , 'HelloWorld' , 'Hello World' ) ;
351
+ const didInsert = ( ) => null ;
352
+ this . registerModifier (
353
+ 'did-insert' ,
354
+ class {
355
+ element ?: SimpleElement ;
356
+ didInsertElement ( ) { }
357
+ didUpdate ( ) { }
358
+ willDestroyElement ( ) { }
359
+ }
360
+ ) ;
361
+ const modifier = this . defineModifier ( 'did-update' ) ;
362
+
363
+ this . render (
364
+ `<div {{on 'click' this.didInsert}} {{did-insert this.didInsert}} {{did-update this.didInsert}} {{this.modifier this.didInsert}}
365
+ ><HelloWorld />
366
+ {{~#if this.more~}}
367
+ <div {{on 'click' this.didInsert}}></div>
368
+ {{~/if~}}
369
+ </div>` ,
370
+ {
371
+ didInsert : didInsert ,
372
+ modifier : modifier ,
373
+ more : false ,
374
+ }
375
+ ) ;
376
+
377
+ this . assertRenderTree ( [
378
+ {
379
+ type : 'modifier' ,
380
+ name : 'did-update' ,
381
+ args : { positional : [ didInsert ] , named : { } } ,
382
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
383
+ template : null ,
384
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
385
+ children : [ ] ,
386
+ } ,
387
+ {
388
+ type : 'modifier' ,
389
+ name : 'on' ,
390
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
391
+ instance : ( instance : any ) => typeof instance === 'object' ,
392
+ template : null ,
393
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
394
+ children : [ ] ,
395
+ } ,
396
+ {
397
+ type : 'modifier' ,
398
+ name : 'DidInsertModifier' ,
399
+ args : { positional : [ didInsert ] , named : { } } ,
400
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
401
+ template : null ,
402
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
403
+ children : [ ] ,
404
+ } ,
405
+ {
406
+ type : 'modifier' ,
407
+ name : 'did-insert' ,
408
+ args : { positional : [ didInsert ] , named : { } } ,
409
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
410
+ template : null ,
411
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
412
+ children : [ ] ,
413
+ } ,
414
+ {
415
+ type : 'component' ,
416
+ name : 'HelloWorld' ,
417
+ args : { positional : [ ] , named : { } } ,
418
+ instance : ( instance : any ) => instance !== undefined ,
419
+ template : '(unknown template module)' ,
420
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
421
+ children : [ ] ,
422
+ } ,
423
+ ] ) ;
424
+
425
+ this . rerender ( {
426
+ more : true ,
427
+ } ) ;
428
+
429
+ this . assertRenderTree ( [
430
+ {
431
+ type : 'modifier' ,
432
+ name : 'on' ,
433
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
434
+ instance : ( instance : any ) => typeof instance === 'object' ,
435
+ template : null ,
436
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
437
+ children : [ ] ,
438
+ } ,
439
+ {
440
+ type : 'modifier' ,
441
+ name : 'did-update' ,
442
+ args : { positional : [ didInsert ] , named : { } } ,
443
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
444
+ template : null ,
445
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
446
+ children : [ ] ,
447
+ } ,
448
+ {
449
+ type : 'modifier' ,
450
+ name : 'DidInsertModifier' ,
451
+ args : { positional : [ didInsert ] , named : { } } ,
452
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
453
+ template : null ,
454
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
455
+ children : [ ] ,
456
+ } ,
457
+ {
458
+ type : 'modifier' ,
459
+ name : 'did-insert' ,
460
+ args : { positional : [ didInsert ] , named : { } } ,
461
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
462
+ template : null ,
463
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
464
+ children : [ ] ,
465
+ } ,
466
+ {
467
+ type : 'component' ,
468
+ name : 'HelloWorld' ,
469
+ args : { positional : [ ] , named : { } } ,
470
+ instance : ( instance : any ) => instance !== undefined ,
471
+ template : '(unknown template module)' ,
472
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
473
+ children : [ ] ,
474
+ } ,
475
+ {
476
+ type : 'modifier' ,
477
+ name : 'on' ,
478
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
479
+ instance : ( instance : any ) => typeof instance === 'object' ,
480
+ template : null ,
481
+ bounds : this . nodeBounds ( this . element . firstChild ! . lastChild ) ,
482
+ children : [ ] ,
483
+ } ,
484
+ ] ) ;
485
+
486
+ this . rerender ( {
487
+ more : false ,
488
+ } ) ;
489
+
490
+ this . assertRenderTree ( [
491
+ {
492
+ type : 'modifier' ,
493
+ name : 'did-update' ,
494
+ args : { positional : [ didInsert ] , named : { } } ,
495
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
496
+ template : null ,
497
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
498
+ children : [ ] ,
499
+ } ,
500
+ {
501
+ type : 'modifier' ,
502
+ name : 'on' ,
503
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
504
+ instance : ( instance : any ) => typeof instance === 'object' ,
505
+ template : null ,
506
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
507
+ children : [ ] ,
508
+ } ,
509
+ {
510
+ type : 'modifier' ,
511
+ name : 'DidInsertModifier' ,
512
+ args : { positional : [ didInsert ] , named : { } } ,
513
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
514
+ template : null ,
515
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
516
+ children : [ ] ,
517
+ } ,
518
+ {
519
+ type : 'modifier' ,
520
+ name : 'did-insert' ,
521
+ args : { positional : [ didInsert ] , named : { } } ,
522
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
523
+ template : null ,
524
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
525
+ children : [ ] ,
526
+ } ,
527
+ {
528
+ type : 'component' ,
529
+ name : 'HelloWorld' ,
530
+ args : { positional : [ ] , named : { } } ,
531
+ instance : ( instance : any ) => instance !== undefined ,
532
+ template : '(unknown template module)' ,
533
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
534
+ children : [ ] ,
330
535
} ,
331
536
] ) ;
332
537
}
@@ -519,6 +724,10 @@ class DebugRenderTreeTest extends RenderTest {
519
724
assert . deepEqual ( this . delegate . getCapturedRenderTree ( ) , [ ] , 'there was no output' ) ;
520
725
}
521
726
727
+ defineModifier ( name : string ) {
728
+ return this . delegate . registerCustomModifier ( name ) ;
729
+ }
730
+
522
731
nodeBounds ( _node : SimpleNode | null ) : CapturedBounds {
523
732
let node = expect ( _node , 'BUG: Expected node' ) ;
524
733
0 commit comments