@@ -21,8 +21,14 @@ import {
21
21
WithJitDynamicLayout ,
22
22
WithJitStaticLayout ,
23
23
} from '@glimmer/interfaces' ;
24
- import { PathReference , RootReference } from '@glimmer/reference' ;
25
- import { PrimitiveReference , registerDestructor , ReifyPositionalReference } from '@glimmer/runtime' ;
24
+ import {
25
+ childRefFor ,
26
+ createComputeRef ,
27
+ createPrimitiveRef ,
28
+ Reference ,
29
+ valueForRef ,
30
+ } from '@glimmer/reference' ;
31
+ import { registerDestructor , reifyPositional } from '@glimmer/runtime' ;
26
32
import { EMPTY_ARRAY , unwrapTemplate } from '@glimmer/util' ;
27
33
import {
28
34
beginTrackFrame ,
@@ -40,18 +46,20 @@ import { DynamicScope } from '../renderer';
40
46
import RuntimeResolver from '../resolver' ;
41
47
import { Factory as TemplateFactory , isTemplateFactory , OwnedTemplate } from '../template' ;
42
48
import {
43
- AttributeBinding ,
44
- ClassNameBinding ,
49
+ createClassNameBindingRef ,
50
+ createSimpleClassNameBindingRef ,
51
+ installAttributeBinding ,
45
52
installIsVisibleBinding ,
46
- referenceForKey ,
47
- SimpleClassNameBindingReference ,
53
+ parseAttributeBinding ,
48
54
} from '../utils/bindings' ;
49
55
50
56
import ComponentStateBucket , { Component } from '../utils/curly-component-state-bucket' ;
51
57
import { processComponentArgs } from '../utils/process-args' ;
52
58
import AbstractManager from './abstract' ;
53
59
import DefinitionState from './definition-state' ;
54
60
61
+ const EMBER_VIEW_REF = createPrimitiveRef ( 'ember-view' ) ;
62
+
55
63
function aliasIdToElementId ( args : VMArguments , props : any ) {
56
64
if ( args . named . has ( 'id' ) ) {
57
65
// tslint:disable-next-line:max-line-length
@@ -69,28 +77,28 @@ function aliasIdToElementId(args: VMArguments, props: any) {
69
77
function applyAttributeBindings (
70
78
attributeBindings : Array < string > ,
71
79
component : Component ,
72
- rootRef : RootReference < Component > ,
80
+ rootRef : Reference < Component > ,
73
81
operations : ElementOperations
74
82
) {
75
83
let seen : string [ ] = [ ] ;
76
84
let i = attributeBindings . length - 1 ;
77
85
78
86
while ( i !== - 1 ) {
79
87
let binding = attributeBindings [ i ] ;
80
- let parsed : [ string , string , boolean ] = AttributeBinding . parse ( binding ) ;
88
+ let parsed : [ string , string , boolean ] = parseAttributeBinding ( binding ) ;
81
89
let attribute = parsed [ 1 ] ;
82
90
83
91
if ( seen . indexOf ( attribute ) === - 1 ) {
84
92
seen . push ( attribute ) ;
85
- AttributeBinding . install ( component , rootRef , parsed , operations ) ;
93
+ installAttributeBinding ( component , rootRef , parsed , operations ) ;
86
94
}
87
95
88
96
i -- ;
89
97
}
90
98
91
99
if ( seen . indexOf ( 'id' ) === - 1 ) {
92
100
let id = component . elementId ? component . elementId : guidFor ( component ) ;
93
- operations . setAttribute ( 'id' , PrimitiveReference . create ( id ) , false , null ) ;
101
+ operations . setAttribute ( 'id' , createPrimitiveRef ( id ) , false , null ) ;
94
102
}
95
103
96
104
if (
@@ -103,7 +111,7 @@ function applyAttributeBindings(
103
111
}
104
112
105
113
const DEFAULT_LAYOUT = P `template:components/-default` ;
106
- const EMPTY_POSITIONAL_ARGS : PathReference [ ] = [ ] ;
114
+ const EMPTY_POSITIONAL_ARGS : Reference [ ] = [ ] ;
107
115
108
116
debugFreeze ( EMPTY_POSITIONAL_ARGS ) ;
109
117
@@ -174,7 +182,7 @@ export default class CurlyComponentManager
174
182
positional : EMPTY_POSITIONAL_ARGS ,
175
183
named : {
176
184
...rest ,
177
- ...( __ARGS__ . value ( ) as { [ key : string ] : PathReference < unknown > } ) ,
185
+ ...( valueForRef ( __ARGS__ ) as { [ key : string ] : Reference } ) ,
178
186
} ,
179
187
} ;
180
188
@@ -199,7 +207,10 @@ export default class CurlyComponentManager
199
207
`You cannot specify positional parameters and the hash argument \`${ positionalParams } \`.` ,
200
208
! args . named . has ( positionalParams )
201
209
) ;
202
- named = { [ positionalParams ] : new ReifyPositionalReference ( args . positional . capture ( ) ) } ;
210
+ let captured = args . positional . capture ( ) ;
211
+ named = {
212
+ [ positionalParams ] : createComputeRef ( ( ) => reifyPositional ( captured ) ) ,
213
+ } ;
203
214
assign ( named , args . named . capture ( ) ) ;
204
215
} else if ( Array . isArray ( positionalParams ) && positionalParams . length > 0 ) {
205
216
const count = Math . min ( positionalParams . length , args . positional . length ) ;
@@ -234,7 +245,7 @@ export default class CurlyComponentManager
234
245
state : DefinitionState ,
235
246
args : VMArguments ,
236
247
dynamicScope : DynamicScope ,
237
- callerSelfRef : PathReference ,
248
+ callerSelfRef : Reference ,
238
249
hasBlock : boolean
239
250
) : ComponentStateBucket {
240
251
// Get the nearest concrete component instance from the scope. "Virtual"
@@ -266,7 +277,7 @@ export default class CurlyComponentManager
266
277
267
278
// Save the current `this` context of the template as the component's
268
279
// `_target`, so bubbled actions are routed to the right place.
269
- props . _target = callerSelfRef . value ( ) ;
280
+ props . _target = valueForRef ( callerSelfRef ) ;
270
281
271
282
// static layout asserts CurriedDefinition
272
283
if ( state . template ) {
@@ -363,7 +374,7 @@ export default class CurlyComponentManager
363
374
return name ;
364
375
}
365
376
366
- getSelf ( { rootRef } : ComponentStateBucket ) : PathReference {
377
+ getSelf ( { rootRef } : ComponentStateBucket ) : Reference {
367
378
return rootRef ;
368
379
}
369
380
@@ -381,32 +392,32 @@ export default class CurlyComponentManager
381
392
applyAttributeBindings ( attributeBindings , component , rootRef , operations ) ;
382
393
} else {
383
394
let id = component . elementId ? component . elementId : guidFor ( component ) ;
384
- operations . setAttribute ( 'id' , PrimitiveReference . create ( id ) , false , null ) ;
395
+ operations . setAttribute ( 'id' , createPrimitiveRef ( id ) , false , null ) ;
385
396
if ( EMBER_COMPONENT_IS_VISIBLE ) {
386
397
installIsVisibleBinding ! ( rootRef , operations ) ;
387
398
}
388
399
}
389
400
390
401
if ( classRef ) {
391
- const ref = new SimpleClassNameBindingReference ( classRef , classRef [ 'propertyKey' ] ) ;
402
+ const ref = createSimpleClassNameBindingRef ( classRef ) ;
392
403
operations . setAttribute ( 'class' , ref , false , null ) ;
393
404
}
394
405
395
406
if ( classNames && classNames . length ) {
396
407
classNames . forEach ( ( name : string ) => {
397
- operations . setAttribute ( 'class' , PrimitiveReference . create ( name ) , false , null ) ;
408
+ operations . setAttribute ( 'class' , createPrimitiveRef ( name ) , false , null ) ;
398
409
} ) ;
399
410
}
400
411
401
412
if ( classNameBindings && classNameBindings . length ) {
402
413
classNameBindings . forEach ( ( binding : string ) => {
403
- ClassNameBinding . install ( element , rootRef , binding , operations ) ;
414
+ createClassNameBindingRef ( rootRef , binding , operations ) ;
404
415
} ) ;
405
416
}
406
- operations . setAttribute ( 'class' , PrimitiveReference . create ( 'ember-view' ) , false , null ) ;
417
+ operations . setAttribute ( 'class' , EMBER_VIEW_REF , false , null ) ;
407
418
408
419
if ( 'ariaRole' in component ) {
409
- operations . setAttribute ( 'role' , referenceForKey ( rootRef , 'ariaRole' ) , false , null ) ;
420
+ operations . setAttribute ( 'role' , childRefFor ( rootRef , 'ariaRole' ) , false , null ) ;
410
421
}
411
422
412
423
component . _transitionTo ( 'hasElement' ) ;
0 commit comments