Skip to content

Commit 5d17ffe

Browse files
committed
[GLIMMER2] Move child ref caching into RootReference
1 parent 7458fd2 commit 5d17ffe

File tree

4 files changed

+20
-43
lines changed

4 files changed

+20
-43
lines changed

packages/ember-glimmer/lib/component.js

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ import ViewMixin from 'ember-views/mixins/view_support';
88
import ActionSupport from 'ember-views/mixins/action_support';
99
import TargetActionSupport from 'ember-runtime/mixins/target_action_support';
1010
import symbol from 'ember-metal/symbol';
11-
import EmptyObject from 'ember-metal/empty_object';
1211
import { get } from 'ember-metal/property_get';
1312
import { PROPERTY_DID_CHANGE } from 'ember-metal/property_events';
1413
import { getAttrFor } from 'ember-views/compat/attrs-proxy';
15-
import {
16-
UPDATE,
17-
TO_ROOT_REFERENCE,
18-
REFERENCE_FOR_KEY,
19-
RootReference,
20-
RootPropertyReference
21-
} from './utils/references';
14+
import { UPDATE, RootReference } from './utils/references';
2215
import { DirtyableTag } from 'glimmer-reference';
2316
import { readDOMAttr } from 'glimmer-runtime';
2417
import { assert, deprecate } from 'ember-metal/debug';
@@ -28,7 +21,6 @@ import { getOwner } from 'container/owner';
2821
export const DIRTY_TAG = symbol('DIRTY_TAG');
2922
export const ARGS = symbol('ARGS');
3023
export const ROOT_REF = symbol('ROOT_REF');
31-
export const REFS = symbol('REFS');
3224
export const IS_DISPATCHING_ATTRS = symbol('IS_DISPATCHING_ATTRS');
3325
export const HAS_BLOCK = symbol('HAS_BLOCK');
3426

@@ -49,8 +41,7 @@ const Component = CoreView.extend(
4941
this._super(...arguments);
5042
this[IS_DISPATCHING_ATTRS] = false;
5143
this[DIRTY_TAG] = new DirtyableTag();
52-
this[ROOT_REF] = null;
53-
this[REFS] = new EmptyObject();
44+
this[ROOT_REF] = new RootReference(this);
5445

5546
// If a `defaultLayout` was specified move it to the `layout` prop.
5647
// `layout` is no longer a CP, so this just ensures that the `defaultLayout`
@@ -117,27 +108,6 @@ const Component = CoreView.extend(
117108

118109
readDOMAttr(name) {
119110
return readDOMAttr(this.element, name);
120-
},
121-
122-
[TO_ROOT_REFERENCE]() {
123-
let ref = this[ROOT_REF];
124-
125-
if (!ref) {
126-
ref = this[ROOT_REF] = new RootReference(this);
127-
}
128-
129-
return ref;
130-
},
131-
132-
[REFERENCE_FOR_KEY](key) {
133-
let refs = this[REFS];
134-
let ref = refs[key];
135-
136-
if (ref) {
137-
return ref;
138-
} else {
139-
return refs[key] = new RootPropertyReference(this, key);
140-
}
141111
}
142112
}
143113
);

packages/ember-glimmer/lib/syntax/curly-component.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { StatementSyntax, ValueReference, EvaluatedArgs, EvaluatedNamedArgs, EvaluatedPositionalArgs } from 'glimmer-runtime';
2-
import { TO_ROOT_REFERENCE } from '../utils/references';
32
import { AttributeBinding, ClassNameBinding, IsVisibleBinding } from '../utils/bindings';
4-
import { DIRTY_TAG, IS_DISPATCHING_ATTRS, HAS_BLOCK } from '../component';
3+
import { ROOT_REF, DIRTY_TAG, IS_DISPATCHING_ATTRS, HAS_BLOCK } from '../component';
54
import { assert, runInDebug } from 'ember-metal/debug';
65
import processArgs from '../utils/process-args';
76
import { privatize as P } from 'container/registry';
@@ -224,7 +223,7 @@ class CurlyComponentManager {
224223
}
225224

226225
getSelf({ component }) {
227-
return component[TO_ROOT_REFERENCE]();
226+
return component[ROOT_REF];
228227
}
229228

230229
didCreateElement({ component, classRef }, element, operations) {

packages/ember-glimmer/lib/utils/bindings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { assert } from 'ember-metal/debug';
22
import { dasherize } from 'ember-runtime/system/string';
33
import { CachedReference, map, referenceFromParts } from 'glimmer-reference';
4-
import { REFERENCE_FOR_KEY, TO_ROOT_REFERENCE } from './references';
4+
import { ROOT_REF } from '../component';
55
import { htmlSafe, isHTMLSafe } from './string';
66

77
function referenceForKey(component, key) {
8-
return component[REFERENCE_FOR_KEY](key);
8+
return component[ROOT_REF].get(key);
99
}
1010

1111
function referenceForParts(component, parts) {
12-
return referenceFromParts(component[TO_ROOT_REFERENCE](), parts);
12+
return referenceFromParts(component[ROOT_REF], parts);
1313
}
1414

1515
export const AttributeBinding = {

packages/ember-glimmer/lib/utils/references.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { set } from 'ember-metal/property_set';
33
import { tagFor } from 'ember-metal/tags';
44
import { didRender } from 'ember-metal/transaction';
55
import symbol from 'ember-metal/symbol';
6+
import EmptyObject from 'ember-metal/empty_object';
67
import { CONSTANT_TAG, ConstReference, DirtyableTag, UpdatableTag, combine, isConst } from 'glimmer-reference';
78
import { ConditionalReference as GlimmerConditionalReference, NULL_REFERENCE, UNDEFINED_REFERENCE } from 'glimmer-runtime';
89
import emberToBool from './to-bool';
@@ -13,8 +14,6 @@ import isEnabled from 'ember-metal/features';
1314
import { isProxy } from 'ember-runtime/mixins/-proxy';
1415

1516
export const UPDATE = symbol('UPDATE');
16-
export const TO_ROOT_REFERENCE = symbol('TO_ROOT_REFERENCE');
17-
export const REFERENCE_FOR_KEY = symbol('REFERENCE_FOR_KEY');
1817

1918
// @implements PathReference
2019
export class PrimitiveReference extends ConstReference {
@@ -64,10 +63,19 @@ export class CachedReference extends EmberPathReference {
6463

6564
// @implements PathReference
6665
export class RootReference extends ConstReference {
66+
constructor(value) {
67+
super(value);
68+
this.children = new EmptyObject();
69+
}
70+
6771
get(propertyKey) {
68-
let self = this.value();
69-
let ref = self[REFERENCE_FOR_KEY] && self[REFERENCE_FOR_KEY](propertyKey);
70-
return ref || PropertyReference.create(this, propertyKey);
72+
let ref = this.children[propertyKey];
73+
74+
if (!ref) {
75+
ref = this.children[propertyKey] = PropertyReference.create(this, propertyKey);
76+
}
77+
78+
return ref;
7179
}
7280
}
7381

0 commit comments

Comments
 (0)