@@ -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
@@ -331,6 +331,188 @@ class DebugRenderTreeTest extends RenderTest {
331
331
] ) ;
332
332
}
333
333
334
+ @test modifiers ( ) {
335
+ this . registerComponent ( 'Glimmer' , 'HelloWorld' , 'Hello World' ) ;
336
+ const didInsert = ( ) => null ;
337
+
338
+ class DidInsertModifier {
339
+ element ?: SimpleElement ;
340
+ didInsertElement ( ) { }
341
+ didUpdate ( ) { }
342
+ willDestroyElement ( ) { }
343
+ }
344
+
345
+ this . registerModifier ( 'did-insert' , DidInsertModifier ) ;
346
+
347
+ class MyCustomModifier { }
348
+
349
+ setModifierManager (
350
+ ( ) => ( {
351
+ capabilities : modifierCapabilities ( '3.22' ) ,
352
+ createModifier ( ) {
353
+ return new MyCustomModifier ( ) ;
354
+ } ,
355
+ installModifier ( ) { } ,
356
+ updateModifier ( ) { } ,
357
+ destroyModifier ( ) { } ,
358
+ } ) ,
359
+ MyCustomModifier
360
+ ) ;
361
+
362
+ const foo = Symbol ( 'foo' ) ;
363
+ const bar = Symbol ( 'bar' ) ;
364
+
365
+ this . render (
366
+ `<div {{on 'click' this.didInsert}} {{did-insert this.foo bar=this.bar}} {{this.modifier this.bar foo=this.foo}}
367
+ ><HelloWorld />
368
+ {{~#if this.more~}}
369
+ <div {{on 'click' this.didInsert passive=true}}></div>
370
+ {{~/if~}}
371
+ </div>` ,
372
+ {
373
+ didInsert : didInsert ,
374
+ modifier : MyCustomModifier ,
375
+ foo,
376
+ bar,
377
+ more : false ,
378
+ }
379
+ ) ;
380
+
381
+ this . assertRenderTree ( [
382
+ {
383
+ type : 'modifier' ,
384
+ name : 'on' ,
385
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
386
+ instance : null ,
387
+ template : null ,
388
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
389
+ children : [ ] ,
390
+ } ,
391
+ {
392
+ type : 'modifier' ,
393
+ name : 'DidInsertModifier' ,
394
+ args : { positional : [ foo ] , named : { bar } } ,
395
+ instance : ( instance : unknown ) => instance instanceof DidInsertModifier ,
396
+ template : null ,
397
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
398
+ children : [ ] ,
399
+ } ,
400
+ {
401
+ type : 'modifier' ,
402
+ name : 'MyCustomModifier' ,
403
+ args : { positional : [ bar ] , named : { foo } } ,
404
+ instance : ( instance : unknown ) => instance instanceof MyCustomModifier ,
405
+ template : null ,
406
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
407
+ children : [ ] ,
408
+ } ,
409
+ {
410
+ type : 'component' ,
411
+ name : 'HelloWorld' ,
412
+ args : { positional : [ ] , named : { } } ,
413
+ instance : ( instance : any ) => instance !== undefined ,
414
+ template : '(unknown template module)' ,
415
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
416
+ children : [ ] ,
417
+ } ,
418
+ ] ) ;
419
+
420
+ this . rerender ( {
421
+ more : true ,
422
+ } ) ;
423
+
424
+ this . assertRenderTree ( [
425
+ {
426
+ type : 'modifier' ,
427
+ name : 'on' ,
428
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
429
+ instance : null ,
430
+ template : null ,
431
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
432
+ children : [ ] ,
433
+ } ,
434
+ {
435
+ type : 'modifier' ,
436
+ name : 'DidInsertModifier' ,
437
+ args : { positional : [ foo ] , named : { bar } } ,
438
+ instance : ( instance : unknown ) => instance instanceof DidInsertModifier ,
439
+ template : null ,
440
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
441
+ children : [ ] ,
442
+ } ,
443
+ {
444
+ type : 'modifier' ,
445
+ name : 'MyCustomModifier' ,
446
+ args : { positional : [ bar ] , named : { foo } } ,
447
+ instance : ( instance : unknown ) => instance instanceof MyCustomModifier ,
448
+ template : null ,
449
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
450
+ children : [ ] ,
451
+ } ,
452
+ {
453
+ type : 'component' ,
454
+ name : 'HelloWorld' ,
455
+ args : { positional : [ ] , named : { } } ,
456
+ instance : ( instance : any ) => instance !== undefined ,
457
+ template : '(unknown template module)' ,
458
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
459
+ children : [ ] ,
460
+ } ,
461
+ {
462
+ type : 'modifier' ,
463
+ name : 'on' ,
464
+ args : { positional : [ 'click' , didInsert ] , named : { passive : true } } ,
465
+ instance : null ,
466
+ template : null ,
467
+ bounds : this . nodeBounds ( this . element . firstChild ! . lastChild ) ,
468
+ children : [ ] ,
469
+ } ,
470
+ ] ) ;
471
+
472
+ this . rerender ( {
473
+ more : false ,
474
+ } ) ;
475
+
476
+ this . assertRenderTree ( [
477
+ {
478
+ type : 'modifier' ,
479
+ name : 'on' ,
480
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
481
+ instance : null ,
482
+ template : null ,
483
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
484
+ children : [ ] ,
485
+ } ,
486
+ {
487
+ type : 'modifier' ,
488
+ name : 'DidInsertModifier' ,
489
+ args : { positional : [ foo ] , named : { bar } } ,
490
+ instance : ( instance : unknown ) => instance instanceof DidInsertModifier ,
491
+ template : null ,
492
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
493
+ children : [ ] ,
494
+ } ,
495
+ {
496
+ type : 'modifier' ,
497
+ name : 'MyCustomModifier' ,
498
+ args : { positional : [ bar ] , named : { foo } } ,
499
+ instance : ( instance : unknown ) => instance instanceof MyCustomModifier ,
500
+ template : null ,
501
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
502
+ children : [ ] ,
503
+ } ,
504
+ {
505
+ type : 'component' ,
506
+ name : 'HelloWorld' ,
507
+ args : { positional : [ ] , named : { } } ,
508
+ instance : ( instance : any ) => instance !== undefined ,
509
+ template : '(unknown template module)' ,
510
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
511
+ children : [ ] ,
512
+ } ,
513
+ ] ) ;
514
+ }
515
+
334
516
@test 'getDebugCustomRenderTree works' ( ) {
335
517
let bucket1 = { } ;
336
518
let instance1 = { } ;
0 commit comments