Skip to content

Commit 269d590

Browse files
authored
Merge pull request #19107 from emberjs/refactor/monomorphic-reference
2 parents 6b4f589 + 3caa6f8 commit 269d590

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+854
-1147
lines changed

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@
7474
},
7575
"devDependencies": {
7676
"@babel/preset-env": "^7.9.5",
77-
"@glimmer/compiler": "^0.59.0",
77+
"@glimmer/compiler": "^0.60.0",
7878
"@glimmer/env": "^0.1.7",
79-
"@glimmer/global-context": "^0.59.0",
80-
"@glimmer/interfaces": "^0.59.0",
81-
"@glimmer/node": "^0.59.0",
82-
"@glimmer/opcode-compiler": "^0.59.0",
83-
"@glimmer/program": "^0.59.0",
84-
"@glimmer/reference": "^0.59.0",
85-
"@glimmer/runtime": "^0.59.0",
86-
"@glimmer/validator": "^0.59.0",
79+
"@glimmer/global-context": "^0.60.0",
80+
"@glimmer/interfaces": "^0.60.0",
81+
"@glimmer/node": "^0.60.0",
82+
"@glimmer/opcode-compiler": "^0.60.0",
83+
"@glimmer/program": "^0.60.0",
84+
"@glimmer/reference": "^0.60.0",
85+
"@glimmer/runtime": "^0.60.0",
86+
"@glimmer/validator": "^0.60.0",
8787
"@simple-dom/document": "^1.4.0",
8888
"@types/qunit": "^2.9.1",
8989
"@types/rsvp": "^4.0.3",

packages/@ember/-internals/glimmer/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ export { default as AbstractComponentManager } from './lib/component-managers/ab
400400
// TODO just test these through public API
401401
// a lot of these are testing how a problem was solved
402402
// rather than the problem was solved
403-
export { INVOKE } from './lib/helpers/mut';
403+
export { INVOKE } from './lib/helpers/action';
404404
export { default as OutletView } from './lib/views/outlet';
405405
export { OutletState } from './lib/utils/outlet';
406406
export { capabilities } from './lib/component-managers/custom';

packages/@ember/-internals/glimmer/lib/component-managers/abstract.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
ElementOperations,
88
Option,
99
PreparedArguments,
10+
VM,
1011
VMArguments,
1112
} from '@glimmer/interfaces';
12-
import { PathReference } from '@glimmer/reference';
13+
import { Reference } from '@glimmer/reference';
1314
import { SimpleElement } from '@simple-dom/interface';
1415
import { EmberVMEnvironment } from '../environment';
1516

@@ -18,7 +19,7 @@ import { EmberVMEnvironment } from '../environment';
1819
// https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21
1920

2021
export default abstract class AbstractManager<T, U> implements ComponentManager<T, U> {
21-
prepareArgs(_state: U, _args: VMArguments): Option<PreparedArguments> {
22+
prepareArgs(_state: U, _args: VMArguments, _vm: VM): Option<PreparedArguments> {
2223
return null;
2324
}
2425

@@ -29,11 +30,11 @@ export default abstract class AbstractManager<T, U> implements ComponentManager<
2930
definition: U,
3031
args: VMArguments,
3132
dynamicScope: DynamicScope,
32-
caller: PathReference<void | {}>,
33+
caller: Reference<void | {}>,
3334
hasDefaultBlock: boolean
3435
): T;
3536

36-
abstract getSelf(component: T): PathReference<unknown>;
37+
abstract getSelf(component: T): Reference;
3738
abstract getCapabilities(state: U): ComponentCapabilities;
3839

3940
didCreateElement(_component: T, _element: SimpleElement, _operations: ElementOperations): void {

packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

+33-22
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ import {
2121
WithJitDynamicLayout,
2222
WithJitStaticLayout,
2323
} 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';
2632
import { EMPTY_ARRAY, unwrapTemplate } from '@glimmer/util';
2733
import {
2834
beginTrackFrame,
@@ -40,18 +46,20 @@ import { DynamicScope } from '../renderer';
4046
import RuntimeResolver from '../resolver';
4147
import { Factory as TemplateFactory, isTemplateFactory, OwnedTemplate } from '../template';
4248
import {
43-
AttributeBinding,
44-
ClassNameBinding,
49+
createClassNameBindingRef,
50+
createSimpleClassNameBindingRef,
51+
installAttributeBinding,
4552
installIsVisibleBinding,
46-
referenceForKey,
47-
SimpleClassNameBindingReference,
53+
parseAttributeBinding,
4854
} from '../utils/bindings';
4955

5056
import ComponentStateBucket, { Component } from '../utils/curly-component-state-bucket';
5157
import { processComponentArgs } from '../utils/process-args';
5258
import AbstractManager from './abstract';
5359
import DefinitionState from './definition-state';
5460

61+
const EMBER_VIEW_REF = createPrimitiveRef('ember-view');
62+
5563
function aliasIdToElementId(args: VMArguments, props: any) {
5664
if (args.named.has('id')) {
5765
// tslint:disable-next-line:max-line-length
@@ -69,28 +77,28 @@ function aliasIdToElementId(args: VMArguments, props: any) {
6977
function applyAttributeBindings(
7078
attributeBindings: Array<string>,
7179
component: Component,
72-
rootRef: RootReference<Component>,
80+
rootRef: Reference<Component>,
7381
operations: ElementOperations
7482
) {
7583
let seen: string[] = [];
7684
let i = attributeBindings.length - 1;
7785

7886
while (i !== -1) {
7987
let binding = attributeBindings[i];
80-
let parsed: [string, string, boolean] = AttributeBinding.parse(binding);
88+
let parsed: [string, string, boolean] = parseAttributeBinding(binding);
8189
let attribute = parsed[1];
8290

8391
if (seen.indexOf(attribute) === -1) {
8492
seen.push(attribute);
85-
AttributeBinding.install(component, rootRef, parsed, operations);
93+
installAttributeBinding(component, rootRef, parsed, operations);
8694
}
8795

8896
i--;
8997
}
9098

9199
if (seen.indexOf('id') === -1) {
92100
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);
94102
}
95103

96104
if (
@@ -103,7 +111,7 @@ function applyAttributeBindings(
103111
}
104112

105113
const DEFAULT_LAYOUT = P`template:components/-default`;
106-
const EMPTY_POSITIONAL_ARGS: PathReference[] = [];
114+
const EMPTY_POSITIONAL_ARGS: Reference[] = [];
107115

108116
debugFreeze(EMPTY_POSITIONAL_ARGS);
109117

@@ -174,7 +182,7 @@ export default class CurlyComponentManager
174182
positional: EMPTY_POSITIONAL_ARGS,
175183
named: {
176184
...rest,
177-
...(__ARGS__.value() as { [key: string]: PathReference<unknown> }),
185+
...(valueForRef(__ARGS__) as { [key: string]: Reference }),
178186
},
179187
};
180188

@@ -199,7 +207,10 @@ export default class CurlyComponentManager
199207
`You cannot specify positional parameters and the hash argument \`${positionalParams}\`.`,
200208
!args.named.has(positionalParams)
201209
);
202-
named = { [positionalParams]: new ReifyPositionalReference(args.positional.capture()) };
210+
let captured = args.positional.capture();
211+
named = {
212+
[positionalParams]: createComputeRef(() => reifyPositional(captured)),
213+
};
203214
assign(named, args.named.capture());
204215
} else if (Array.isArray(positionalParams) && positionalParams.length > 0) {
205216
const count = Math.min(positionalParams.length, args.positional.length);
@@ -234,7 +245,7 @@ export default class CurlyComponentManager
234245
state: DefinitionState,
235246
args: VMArguments,
236247
dynamicScope: DynamicScope,
237-
callerSelfRef: PathReference,
248+
callerSelfRef: Reference,
238249
hasBlock: boolean
239250
): ComponentStateBucket {
240251
// Get the nearest concrete component instance from the scope. "Virtual"
@@ -266,7 +277,7 @@ export default class CurlyComponentManager
266277

267278
// Save the current `this` context of the template as the component's
268279
// `_target`, so bubbled actions are routed to the right place.
269-
props._target = callerSelfRef.value();
280+
props._target = valueForRef(callerSelfRef);
270281

271282
// static layout asserts CurriedDefinition
272283
if (state.template) {
@@ -363,7 +374,7 @@ export default class CurlyComponentManager
363374
return name;
364375
}
365376

366-
getSelf({ rootRef }: ComponentStateBucket): PathReference {
377+
getSelf({ rootRef }: ComponentStateBucket): Reference {
367378
return rootRef;
368379
}
369380

@@ -381,32 +392,32 @@ export default class CurlyComponentManager
381392
applyAttributeBindings(attributeBindings, component, rootRef, operations);
382393
} else {
383394
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);
385396
if (EMBER_COMPONENT_IS_VISIBLE) {
386397
installIsVisibleBinding!(rootRef, operations);
387398
}
388399
}
389400

390401
if (classRef) {
391-
const ref = new SimpleClassNameBindingReference(classRef, classRef['propertyKey']);
402+
const ref = createSimpleClassNameBindingRef(classRef);
392403
operations.setAttribute('class', ref, false, null);
393404
}
394405

395406
if (classNames && classNames.length) {
396407
classNames.forEach((name: string) => {
397-
operations.setAttribute('class', PrimitiveReference.create(name), false, null);
408+
operations.setAttribute('class', createPrimitiveRef(name), false, null);
398409
});
399410
}
400411

401412
if (classNameBindings && classNameBindings.length) {
402413
classNameBindings.forEach((binding: string) => {
403-
ClassNameBinding.install(element, rootRef, binding, operations);
414+
createClassNameBindingRef(rootRef, binding, operations);
404415
});
405416
}
406-
operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);
417+
operations.setAttribute('class', EMBER_VIEW_REF, false, null);
407418

408419
if ('ariaRole' in component) {
409-
operations.setAttribute('role', referenceForKey(rootRef, 'ariaRole'), false, null);
420+
operations.setAttribute('role', childRefFor(rootRef, 'ariaRole'), false, null);
410421
}
411422

412423
component._transitionTo('hasElement');

packages/@ember/-internals/glimmer/lib/component-managers/custom.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
VMArguments,
1717
WithJitStaticLayout,
1818
} from '@glimmer/interfaces';
19-
import { ComponentRootReference, PathReference } from '@glimmer/reference';
19+
import { createConstRef, Reference, valueForRef } from '@glimmer/reference';
2020
import { registerDestructor, reifyArgs, reifyPositional } from '@glimmer/runtime';
2121
import { unwrapTemplate } from '@glimmer/util';
2222
import { track } from '@glimmer/validator';
@@ -194,7 +194,7 @@ export default class CustomComponentManager<ComponentInstance>
194194

195195
if (EMBER_CUSTOM_COMPONENT_ARG_PROXY) {
196196
let getTag = (key: string) => {
197-
return track(() => namedArgs[key].value());
197+
return track(() => valueForRef(namedArgs[key]));
198198
};
199199

200200
if (HAS_NATIVE_PROXY) {
@@ -203,7 +203,7 @@ export default class CustomComponentManager<ComponentInstance>
203203
let ref = namedArgs[prop as string];
204204

205205
if (ref !== undefined) {
206-
return ref.value();
206+
return valueForRef(ref);
207207
} else if (prop === CUSTOM_TAG_FOR) {
208208
return getTag;
209209
}
@@ -255,7 +255,7 @@ export default class CustomComponentManager<ComponentInstance>
255255
enumerable: true,
256256
configurable: true,
257257
get() {
258-
return namedArgs[name].value();
258+
return valueForRef(namedArgs[name]);
259259
},
260260
});
261261
});
@@ -333,11 +333,8 @@ export default class CustomComponentManager<ComponentInstance>
333333
delegate.getContext(component);
334334
}
335335

336-
getSelf({
337-
delegate,
338-
component,
339-
}: CustomComponentState<ComponentInstance>): PathReference<unknown> {
340-
return new ComponentRootReference(delegate.getContext(component));
336+
getSelf({ delegate, component }: CustomComponentState<ComponentInstance>): Reference {
337+
return createConstRef(delegate.getContext(component), 'this');
341338
}
342339

343340
getDestroyable(bucket: CustomComponentState<ComponentInstance>): Option<Destroyable> {

packages/@ember/-internals/glimmer/lib/component-managers/input.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
PreparedArguments,
1212
VMArguments,
1313
} from '@glimmer/interfaces';
14-
import { ComponentRootReference, ConstReference, PathReference } from '@glimmer/reference';
14+
import { createConstRef, isConstRef, Reference, valueForRef } from '@glimmer/reference';
1515
import { registerDestructor } from '@glimmer/runtime';
1616
import { EmberVMEnvironment } from '../environment';
1717
import InternalComponentManager, { InternalDefinitionState } from './internal';
@@ -33,11 +33,11 @@ const CAPABILITIES: ComponentCapabilities = {
3333

3434
export interface InputComponentState {
3535
env: EmberVMEnvironment;
36-
type: PathReference;
36+
type: Reference;
3737
instance: Destroyable;
3838
}
3939

40-
const EMPTY_POSITIONAL_ARGS: PathReference[] = [];
40+
const EMPTY_POSITIONAL_ARGS: Reference[] = [];
4141

4242
debugFreeze(EMPTY_POSITIONAL_ARGS);
4343

@@ -52,12 +52,12 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
5252
args.positional.length === 0
5353
);
5454

55-
let __ARGS__: Dict<PathReference> = args.named.capture();
55+
let __ARGS__: Dict<Reference> = args.named.capture();
5656

5757
return {
5858
positional: EMPTY_POSITIONAL_ARGS,
5959
named: {
60-
__ARGS__: new ConstReference(__ARGS__),
60+
__ARGS__: createConstRef(__ARGS__, 'args'),
6161
type: args.named.get('type'),
6262
},
6363
};
@@ -68,15 +68,15 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
6868
{ ComponentClass, layout }: InternalDefinitionState,
6969
args: VMArguments,
7070
_dynamicScope: DynamicScope,
71-
caller: PathReference
71+
caller: Reference
7272
): InputComponentState {
73-
assert('caller must be const', caller.isConst());
73+
assert('caller must be const', isConstRef(caller));
7474

7575
let type = args.named.get('type');
7676

7777
let instance = ComponentClass.create({
78-
caller: caller.value(),
79-
type: type.value(),
78+
caller: valueForRef(caller),
79+
type: valueForRef(type),
8080
});
8181

8282
let state = { env, type, instance };
@@ -100,8 +100,8 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
100100
return 'input';
101101
}
102102

103-
getSelf({ instance }: InputComponentState): PathReference {
104-
return new ComponentRootReference(instance);
103+
getSelf({ instance }: InputComponentState): Reference {
104+
return createConstRef(instance, 'this');
105105
}
106106

107107
didRenderLayout(state: InputComponentState, bounds: Bounds): void {
@@ -111,7 +111,7 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
111111
}
112112

113113
update(state: InputComponentState): void {
114-
set(state.instance, 'type', state.type.value());
114+
set(state.instance, 'type', valueForRef(state.type));
115115

116116
if (ENV._DEBUG_RENDER_TREE) {
117117
state.env.extra.debugRenderTree.update(state);

0 commit comments

Comments
 (0)