Skip to content

Commit 6282a74

Browse files
author
Chris Garrett
committed
respond to feedback
1 parent 255bd28 commit 6282a74

19 files changed

+119
-146
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export { default as Checkbox } from './lib/components/checkbox';
355355
export { default as TextField } from './lib/components/text-field';
356356
export { default as TextArea } from './lib/components/textarea';
357357
export { default as LinkComponent } from './lib/components/link-to';
358-
export { default as Component, ROOT_REF } from './lib/component';
358+
export { default as Component } from './lib/component';
359359
export { default as Helper, helper } from './lib/helper';
360360
export { default as Environment } from './lib/environment';
361361
export { SafeString, escapeExpression, htmlSafe, isHTMLSafe } from './lib/utils/string';

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

+12-20
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ import {
3535
WithStaticLayout,
3636
} from '@glimmer/runtime';
3737
import { Destroyable, EMPTY_ARRAY } from '@glimmer/util';
38-
import {
39-
BOUNDS,
40-
DIRTY_TAG,
41-
GLIMMER_ENV,
42-
HAS_BLOCK,
43-
IS_DISPATCHING_ATTRS,
44-
ROOT_REF,
45-
} from '../component';
38+
import { BOUNDS, DIRTY_TAG, HAS_BLOCK, IS_DISPATCHING_ATTRS } from '../component';
4639
import Environment from '../environment';
4740
import { DynamicScope } from '../renderer';
4841
import RuntimeResolver from '../resolver';
@@ -56,6 +49,7 @@ import {
5649
} from '../utils/bindings';
5750
import ComponentStateBucket, { Component } from '../utils/curly-component-state-bucket';
5851
import { processComponentArgs } from '../utils/process-args';
52+
import { RootReference } from '../utils/references';
5953
import AbstractManager from './abstract';
6054
import DefinitionState from './definition-state';
6155

@@ -77,6 +71,7 @@ function applyAttributeBindings(
7771
element: Simple.Element,
7872
attributeBindings: Array<string>,
7973
component: Component,
74+
rootRef: RootReference<Component>,
8075
operations: ElementOperations
8176
) {
8277
let seen: string[] = [];
@@ -89,7 +84,7 @@ function applyAttributeBindings(
8984

9085
if (seen.indexOf(attribute) === -1) {
9186
seen.push(attribute);
92-
AttributeBinding.install(element, component, parsed, operations);
87+
AttributeBinding.install(element, component, rootRef, parsed, operations);
9388
}
9489

9590
i--;
@@ -105,7 +100,7 @@ function applyAttributeBindings(
105100
IsVisibleBinding !== undefined &&
106101
seen.indexOf('style') === -1
107102
) {
108-
IsVisibleBinding.install(element, component, operations);
103+
IsVisibleBinding.install(element, component, rootRef, operations);
109104
}
110105
}
111106

@@ -289,9 +284,6 @@ export default class CurlyComponentManager
289284
props.layout = state.template;
290285
}
291286

292-
// Pass the environment for the root reference
293-
props[GLIMMER_ENV] = environment;
294-
295287
// caller:
296288
// <FaIcon @name="bug" />
297289
//
@@ -366,12 +358,12 @@ export default class CurlyComponentManager
366358
return bucket;
367359
}
368360

369-
getSelf({ component }: ComponentStateBucket): VersionedPathReference {
370-
return component[ROOT_REF];
361+
getSelf({ rootRef }: ComponentStateBucket): VersionedPathReference {
362+
return rootRef;
371363
}
372364

373365
didCreateElement(
374-
{ component, classRef, environment }: ComponentStateBucket,
366+
{ component, classRef, environment, rootRef }: ComponentStateBucket,
375367
element: Simple.Element,
376368
operations: ElementOperations
377369
): void {
@@ -381,12 +373,12 @@ export default class CurlyComponentManager
381373
let { attributeBindings, classNames, classNameBindings } = component;
382374

383375
if (attributeBindings && attributeBindings.length) {
384-
applyAttributeBindings(element, attributeBindings, component, operations);
376+
applyAttributeBindings(element, attributeBindings, component, rootRef, operations);
385377
} else {
386378
let id = component.elementId ? component.elementId : guidFor(component);
387379
operations.setAttribute('id', PrimitiveReference.create(id), false, null);
388380
if (EMBER_COMPONENT_IS_VISIBLE && IsVisibleBinding !== undefined) {
389-
IsVisibleBinding.install(element, component, operations);
381+
IsVisibleBinding.install(element, component, rootRef, operations);
390382
}
391383
}
392384

@@ -403,13 +395,13 @@ export default class CurlyComponentManager
403395

404396
if (classNameBindings && classNameBindings.length) {
405397
classNameBindings.forEach((binding: string) => {
406-
ClassNameBinding.install(element, component, binding, operations);
398+
ClassNameBinding.install(element, rootRef, binding, operations);
407399
});
408400
}
409401
operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);
410402

411403
if ('ariaRole' in component) {
412-
operations.setAttribute('role', referenceForKey(component, 'ariaRole'), false, null);
404+
operations.setAttribute('role', referenceForKey(rootRef, 'ariaRole'), false, null);
413405
}
414406

415407
component._transitionTo('hasElement');

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import { DEBUG } from '@glimmer/env';
1616
import { createTag, dirty } from '@glimmer/reference';
1717
import { normalizeProperty, SVG_NAMESPACE } from '@glimmer/runtime';
1818

19-
import { RootReference, UPDATE } from './utils/references';
19+
import { UPDATE } from './utils/references';
2020

2121
export const DIRTY_TAG = symbol('DIRTY_TAG');
2222
export const ARGS = symbol('ARGS');
23-
export const ROOT_REF = symbol('ROOT_REF');
2423
export const IS_DISPATCHING_ATTRS = symbol('IS_DISPATCHING_ATTRS');
2524
export const HAS_BLOCK = symbol('HAS_BLOCK');
2625
export const BOUNDS = symbol('BOUNDS');
27-
export const GLIMMER_ENV = symbol('GLIMMER_ENV');
2826

2927
/**
3028
@module @ember/component
@@ -723,7 +721,6 @@ const Component = CoreView.extend(
723721
this._super(...arguments);
724722
this[IS_DISPATCHING_ATTRS] = false;
725723
this[DIRTY_TAG] = createTag();
726-
this[ROOT_REF] = new RootReference(this, this[GLIMMER_ENV]);
727724
this[BOUNDS] = null;
728725

729726
if (DEBUG && this.renderer._destinedForDOM && this.tagName === '') {

packages/@ember/-internals/glimmer/lib/modifiers/custom.ts

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import {
2-
clearRenderingContextDesc,
3-
setRenderingContextDesc,
4-
track,
5-
untrack,
6-
} from '@ember/-internals/metal';
1+
import { track, untrack } from '@ember/-internals/metal';
72
import { Factory } from '@ember/-internals/owner';
83
import { getDebugName } from '@ember/-internals/utils';
94
import { assert, deprecate } from '@ember/debug';
105
import { DEBUG } from '@glimmer/env';
116
import { Dict, Opaque, Simple } from '@glimmer/interfaces';
127
import { combine, CONSTANT_TAG, createUpdatableTag, Tag, update } from '@glimmer/reference';
138
import { Arguments, CapturedArguments, ModifierManager } from '@glimmer/runtime';
9+
import debugRenderMessage from '../utils/debug-render-message';
1410

1511
export interface CustomModifierDefinitionState<ModifierInstance> {
1612
ModifierClass: Factory<ModifierInstance>;
@@ -169,19 +165,11 @@ class InteractiveCustomModifierManager<ModifierInstance>
169165
if (capabilities.disableAutoTracking === true) {
170166
untrack(() => delegate.installModifier(modifier, element, args.value()));
171167
} else {
172-
if (DEBUG) {
173-
let debugName = getDebugName!(modifier);
174-
setRenderingContextDesc!(`(instance of a \`${debugName}\` modifier)`);
175-
}
176-
177-
let combinedTrackingTag = track(() =>
178-
delegate.installModifier(modifier, element, args.value())
168+
let combinedTrackingTag = track(
169+
() => delegate.installModifier(modifier, element, args.value()),
170+
DEBUG && debugRenderMessage!(`(instance of a \`${getDebugName!(modifier)}\` modifier)`)
179171
);
180172

181-
if (DEBUG) {
182-
clearRenderingContextDesc!();
183-
}
184-
185173
update(tag, combinedTrackingTag);
186174
}
187175
}
@@ -193,7 +181,10 @@ class InteractiveCustomModifierManager<ModifierInstance>
193181
if (capabilities.disableAutoTracking === true) {
194182
untrack(() => delegate.updateModifier(modifier, args.value()));
195183
} else {
196-
let combinedTrackingTag = track(() => delegate.updateModifier(modifier, args.value()));
184+
let combinedTrackingTag = track(
185+
() => delegate.updateModifier(modifier, args.value()),
186+
DEBUG && debugRenderMessage!(`(instance of a \`${getDebugName!(modifier)}\` modifier)`)
187+
);
197188
update(tag, combinedTrackingTag);
198189
}
199190
}

packages/@ember/-internals/glimmer/lib/renderer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ export abstract class Renderer {
418418
}
419419

420420
if (DEBUG) {
421-
// run in an autotracking transaction to prevent backflow errors
421+
// run in an autotracking transaction to prevent backflow errors.
422+
// we use `bind` here to avoid creating a closure (and requiring a
423+
// hoisted variable).
422424
runInAutotrackingTransaction!(root.render.bind(root));
423425
} else {
424426
root.render();

packages/@ember/-internals/glimmer/lib/syntax/outlet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class OutletModelReference implements VersionedPathReference {
144144

145145
if (DEBUG) {
146146
OutletModelReference.prototype['debug'] = function debug(subPath: string): string {
147-
return `${this['debugStackLog']}@mount.${subPath}`;
147+
return `${this['debugStackLog']}@model.${subPath}`;
148148
};
149149
}
150150

packages/@ember/-internals/glimmer/lib/utils/bindings.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ import { Opaque, Option, Simple } from '@glimmer/interfaces';
66
import { CachedReference, combine, map, Reference, Tag } from '@glimmer/reference';
77
import { ElementOperations, PrimitiveReference } from '@glimmer/runtime';
88
import { Core, Ops } from '@glimmer/wire-format';
9-
import { ROOT_REF } from '../component';
109
import { Component } from './curly-component-state-bucket';
11-
import { referenceFromParts } from './references';
10+
import { referenceFromParts, RootReference } from './references';
1211
import { htmlSafe, isHTMLSafe, SafeString } from './string';
1312

14-
export function referenceForKey(component: Component, key: string) {
15-
return component[ROOT_REF].get(key);
13+
export function referenceForKey(rootRef: RootReference<Component>, key: string) {
14+
return rootRef.get(key);
1615
}
1716

18-
function referenceForParts(component: Component, parts: string[]): Reference {
17+
function referenceForParts(rootRef: RootReference<Component>, parts: string[]): Reference {
1918
let isAttrs = parts[0] === 'attrs';
2019

2120
// TODO deprecate this
2221
if (isAttrs) {
2322
parts.shift();
2423

2524
if (parts.length === 1) {
26-
return referenceForKey(component, parts[0]);
25+
return referenceForKey(rootRef, parts[0]);
2726
}
2827
}
2928

30-
return referenceFromParts(component[ROOT_REF], parts);
29+
return referenceFromParts(rootRef, parts);
3130
}
3231

3332
// TODO we should probably do this transform at build time
@@ -81,6 +80,7 @@ export const AttributeBinding = {
8180
install(
8281
_element: Simple.Element,
8382
component: Component,
83+
rootRef: RootReference<Component>,
8484
parsed: [string, string, boolean],
8585
operations: ElementOperations
8686
) {
@@ -99,8 +99,8 @@ export const AttributeBinding = {
9999

100100
let isPath = prop.indexOf('.') > -1;
101101
let reference = isPath
102-
? referenceForParts(component, prop.split('.'))
103-
: referenceForKey(component, prop);
102+
? referenceForParts(rootRef, prop.split('.'))
103+
: referenceForKey(rootRef, prop);
104104

105105
assert(
106106
`Illegal attributeBinding: '${prop}' is not a valid attribute name.`,
@@ -114,7 +114,7 @@ export const AttributeBinding = {
114114
) {
115115
reference = new StyleBindingReference(
116116
reference,
117-
referenceForKey(component, 'isVisible'),
117+
referenceForKey(rootRef, 'isVisible'),
118118
component
119119
);
120120
}
@@ -134,16 +134,14 @@ let StyleBindingReference:
134134
if (EMBER_COMPONENT_IS_VISIBLE) {
135135
StyleBindingReference = class extends CachedReference<string | SafeString> {
136136
public tag: Tag;
137-
private component: Component;
138137
constructor(
139138
private inner: Reference<string>,
140139
private isVisible: Reference<Opaque>,
141-
component: Component
140+
private component: Component
142141
) {
143142
super();
144143

145144
this.tag = combine([inner.tag, isVisible.tag]);
146-
this.component = component;
147145
}
148146

149147
compute(): string | SafeString {
@@ -179,20 +177,30 @@ if (EMBER_COMPONENT_IS_VISIBLE) {
179177
export let IsVisibleBinding:
180178
| undefined
181179
| {
182-
install(element: Simple.Element, component: Component, operations: ElementOperations): void;
180+
install(
181+
element: Simple.Element,
182+
component: Component,
183+
rootRef: RootReference<Component>,
184+
operations: ElementOperations
185+
): void;
183186
mapStyleValue(isVisible: boolean, component: Component): SafeString | null;
184187
};
185188

186189
if (EMBER_COMPONENT_IS_VISIBLE) {
187190
IsVisibleBinding = {
188-
install(_element: Simple.Element, component: Component, operations: ElementOperations) {
191+
install(
192+
_element: Simple.Element,
193+
component: Component,
194+
rootRef: RootReference<Component>,
195+
operations: ElementOperations
196+
) {
189197
let componentMapStyleValue = (isVisible: boolean) => {
190198
return this.mapStyleValue(isVisible, component);
191199
};
192200

193201
operations.setAttribute(
194202
'style',
195-
map(referenceForKey(component, 'isVisible'), componentMapStyleValue),
203+
map(referenceForKey(rootRef, 'isVisible') as any, componentMapStyleValue),
196204
false,
197205
null
198206
);
@@ -219,7 +227,7 @@ if (EMBER_COMPONENT_IS_VISIBLE) {
219227
export const ClassNameBinding = {
220228
install(
221229
_element: Simple.Element,
222-
component: Component,
230+
rootRef: RootReference<Component>,
223231
microsyntax: string,
224232
operations: ElementOperations
225233
) {
@@ -231,7 +239,7 @@ export const ClassNameBinding = {
231239
} else {
232240
let isPath = prop.indexOf('.') > -1;
233241
let parts = isPath ? prop.split('.') : [];
234-
let value = isPath ? referenceForParts(component, parts) : referenceForKey(component, prop);
242+
let value = isPath ? referenceForParts(rootRef, parts) : referenceForKey(rootRef, prop);
235243
let ref;
236244

237245
if (truthy === undefined) {

packages/@ember/-internals/glimmer/lib/utils/curly-component-state-bucket.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CapturedNamedArguments } from '@glimmer/runtime';
44
import { Opaque } from '@glimmer/util';
55
import Environment from '../environment';
66
import { Factory as TemplateFactory, OwnedTemplate } from '../template';
7+
import { RootReference } from './references';
78

89
export interface Component {
910
_debugContainerKey: string;
@@ -38,6 +39,7 @@ function NOOP() {}
3839
*/
3940
export default class ComponentStateBucket {
4041
public classRef: VersionedReference<Opaque> | null = null;
42+
public rootRef: RootReference<Component>;
4143
public argsRevision: Revision;
4244

4345
constructor(
@@ -49,6 +51,7 @@ export default class ComponentStateBucket {
4951
) {
5052
this.classRef = null;
5153
this.argsRevision = args === null ? 0 : value(args.tag);
54+
this.rootRef = new RootReference(component, environment);
5255
}
5356

5457
destroy() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DEBUG } from '@glimmer/env';
2+
3+
let debugRenderMessage: undefined | ((renderingStack: string) => string);
4+
5+
if (DEBUG) {
6+
debugRenderMessage = (renderingStack: string) => {
7+
return `While rendering:\n----------------\n${renderingStack.replace(/^/gm, ' ')}`;
8+
};
9+
}
10+
11+
export default debugRenderMessage;

packages/@ember/-internals/glimmer/lib/utils/debug-render-tree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default class DebugRenderTree<Bucket extends object = object> {
136136
logCurrentRenderStack(): string {
137137
let nodes = this.stack.toArray().map(bucket => this.nodeFor(bucket));
138138
let message = nodes
139-
.filter(node => node.type !== 'outlet')
139+
.filter(node => node.type !== 'outlet' && node.name !== '-top-level')
140140
.map((node, index) => `${repeatString(' ', index * 2)}${node.name}`);
141141

142142
message.push(`${repeatString(' ', message.length * 2)}`);

0 commit comments

Comments
 (0)