Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING BUGFIX beta] Adds autotracking transaction #18554

Merged
merged 6 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/@ember/-internals/glimmer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export { default as Checkbox } from './lib/components/checkbox';
export { default as TextField } from './lib/components/text-field';
export { default as TextArea } from './lib/components/textarea';
export { default as LinkComponent } from './lib/components/link-to';
export { default as Component, ROOT_REF } from './lib/component';
export { default as Component } from './lib/component';
export { default as Helper, helper } from './lib/helper';
export { default as Environment } from './lib/environment';
export { SafeString, escapeExpression, htmlSafe, isHTMLSafe } from './lib/utils/string';
Expand Down Expand Up @@ -385,11 +385,8 @@ export { default as AbstractComponentManager } from './lib/component-managers/ab
// TODO just test these through public API
// a lot of these are testing how a problem was solved
// rather than the problem was solved
// DebugStack should just test the assert message
// it supports for example
export { UpdatableReference, INVOKE } from './lib/utils/references';
export { default as iterableFor } from './lib/utils/iterable';
export { default as getDebugStack, DebugStack } from './lib/utils/debug-stack';
export { default as OutletView } from './lib/views/outlet';
export { capabilities } from './lib/component-managers/custom';
export { setComponentManager, getComponentManager } from './lib/utils/custom-component-manager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@ import {
PreparedArguments,
} from '@glimmer/runtime';
import { Destroyable, Opaque, Option } from '@glimmer/util';
import { DebugStack } from '../utils/debug-stack';

// implements the ComponentManager interface as defined in glimmer:
// tslint:disable-next-line:max-line-length
// https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21

export default abstract class AbstractManager<T, U> implements ComponentManager<T, U> {
public debugStack: DebugStack | undefined = undefined;

prepareArgs(_state: U, _args: Arguments): Option<PreparedArguments> {
return null;
}

// must be implemented by inheritors, inheritors should also
// call `this._pushToDebugStack` to ensure the rerendering
// assertion messages are properly maintained

abstract create(
env: Environment,
definition: U,
Expand All @@ -43,9 +36,6 @@ export default abstract class AbstractManager<T, U> implements ComponentManager<
// noop
}

// inheritors should also call `this.debugStack.pop()` to
// ensure the rerendering assertion messages are properly
// maintained
didRenderLayout(_component: T, _bounds: Bounds): void {
// noop
}
Expand All @@ -56,16 +46,10 @@ export default abstract class AbstractManager<T, U> implements ComponentManager<

abstract getTag(_bucket: T): Tag;

// inheritors should also call `this._pushToDebugStack`
// to ensure the rerendering assertion messages are
// properly maintained
update(_bucket: T, _dynamicScope: DynamicScope): void {
// noop
}

// inheritors should also call `this.debugStack.pop()` to
// ensure the rerendering assertion messages are properly
// maintained
didUpdateLayout(_bucket: T, _bounds: Bounds): void {
// noop
}
Expand Down
38 changes: 12 additions & 26 deletions packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
WithStaticLayout,
} from '@glimmer/runtime';
import { Destroyable, EMPTY_ARRAY } from '@glimmer/util';
import { BOUNDS, DIRTY_TAG, HAS_BLOCK, IS_DISPATCHING_ATTRS, ROOT_REF } from '../component';
import { BOUNDS, DIRTY_TAG, HAS_BLOCK, IS_DISPATCHING_ATTRS } from '../component';
import Environment from '../environment';
import { DynamicScope } from '../renderer';
import RuntimeResolver from '../resolver';
Expand All @@ -49,6 +49,7 @@ import {
} from '../utils/bindings';
import ComponentStateBucket, { Component } from '../utils/curly-component-state-bucket';
import { processComponentArgs } from '../utils/process-args';
import { RootReference } from '../utils/references';
import AbstractManager from './abstract';
import DefinitionState from './definition-state';

Expand All @@ -70,6 +71,7 @@ function applyAttributeBindings(
element: Simple.Element,
attributeBindings: Array<string>,
component: Component,
rootRef: RootReference<Component>,
operations: ElementOperations
) {
let seen: string[] = [];
Expand All @@ -82,7 +84,7 @@ function applyAttributeBindings(

if (seen.indexOf(attribute) === -1) {
seen.push(attribute);
AttributeBinding.install(element, component, parsed, operations);
AttributeBinding.install(element, component, rootRef, parsed, operations);
}

i--;
Expand All @@ -98,7 +100,7 @@ function applyAttributeBindings(
IsVisibleBinding !== undefined &&
seen.indexOf('style') === -1
) {
IsVisibleBinding.install(element, component, operations);
IsVisibleBinding.install(element, component, rootRef, operations);
}
}

Expand Down Expand Up @@ -249,10 +251,6 @@ export default class CurlyComponentManager
callerSelfRef: VersionedPathReference,
hasBlock: boolean
): ComponentStateBucket {
if (DEBUG) {
environment.debugStack.push(`component:${state.name}`);
}

// Get the nearest concrete component instance from the scope. "Virtual"
// components will be skipped.
let parentView = dynamicScope.view;
Expand Down Expand Up @@ -360,12 +358,12 @@ export default class CurlyComponentManager
return bucket;
}

getSelf({ component }: ComponentStateBucket): VersionedPathReference {
return component[ROOT_REF];
getSelf({ rootRef }: ComponentStateBucket): VersionedPathReference {
return rootRef;
}

didCreateElement(
{ component, classRef, environment }: ComponentStateBucket,
{ component, classRef, environment, rootRef }: ComponentStateBucket,
element: Simple.Element,
operations: ElementOperations
): void {
Expand All @@ -375,12 +373,12 @@ export default class CurlyComponentManager
let { attributeBindings, classNames, classNameBindings } = component;

if (attributeBindings && attributeBindings.length) {
applyAttributeBindings(element, attributeBindings, component, operations);
applyAttributeBindings(element, attributeBindings, component, rootRef, operations);
} else {
let id = component.elementId ? component.elementId : guidFor(component);
operations.setAttribute('id', PrimitiveReference.create(id), false, null);
if (EMBER_COMPONENT_IS_VISIBLE && IsVisibleBinding !== undefined) {
IsVisibleBinding.install(element, component, operations);
IsVisibleBinding.install(element, component, rootRef, operations);
}
}

Expand All @@ -397,13 +395,13 @@ export default class CurlyComponentManager

if (classNameBindings && classNameBindings.length) {
classNameBindings.forEach((binding: string) => {
ClassNameBinding.install(element, component, binding, operations);
ClassNameBinding.install(element, rootRef, binding, operations);
});
}
operations.setAttribute('class', PrimitiveReference.create('ember-view'), false, null);

if ('ariaRole' in component) {
operations.setAttribute('role', referenceForKey(component, 'ariaRole'), false, null);
operations.setAttribute('role', referenceForKey(rootRef, 'ariaRole'), false, null);
}

component._transitionTo('hasElement');
Expand All @@ -420,10 +418,6 @@ export default class CurlyComponentManager
if (ENV._DEBUG_RENDER_TREE) {
bucket.environment.debugRenderTree.didRender(bucket, bounds);
}

if (DEBUG) {
bucket.environment.debugStack.pop();
}
}

getTag({ args, component }: ComponentStateBucket): Tag {
Expand All @@ -445,10 +439,6 @@ export default class CurlyComponentManager
environment.debugRenderTree.update(bucket);
}

if (DEBUG) {
environment.debugStack.push(component._debugContainerKey);
}

bucket.finalizer = _instrumentStart('render.component', rerenderInstrumentDetails, component);

if (args && !validate(args.tag, argsRevision)) {
Expand Down Expand Up @@ -476,10 +466,6 @@ export default class CurlyComponentManager
if (ENV._DEBUG_RENDER_TREE) {
bucket.environment.debugRenderTree.didRender(bucket, bounds);
}

if (DEBUG) {
bucket.environment.debugStack.pop();
}
}

didUpdate({ component, environment }: ComponentStateBucket): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ export default class CustomComponentManager<ComponentInstance>
delegate.getContext(component);
}

getSelf({ delegate, component }: CustomComponentState<ComponentInstance>): PathReference<Opaque> {
return RootReference.create(delegate.getContext(component));
getSelf({
env,
delegate,
component,
}: CustomComponentState<ComponentInstance>): PathReference<Opaque> {
return RootReference.create(delegate.getContext(component), env);
}

getDestructor(state: CustomComponentState<ComponentInstance>): Option<Destroyable> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
return state;
}

getSelf({ instance }: InputComponentState): VersionedPathReference {
return new RootReference(instance);
getSelf({ env, instance }: InputComponentState): VersionedPathReference {
return new RootReference(instance, env);
pzuraq marked this conversation as resolved.
Show resolved Hide resolved
}

getTag() {
Expand Down
12 changes: 2 additions & 10 deletions packages/@ember/-internals/glimmer/lib/component-managers/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
}

create(environment: Environment, { name }: EngineDefinitionState, args: Arguments) {
if (DEBUG) {
environment.debugStack.pushEngine(`engine:${name}`);
}

// TODO
// mount is a runtime helper, this shouldn't use dynamic layout
// we should resolve the engine app template in the helper
Expand All @@ -106,12 +102,12 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>

if (modelRef === undefined) {
controller = controllerFactory.create();
self = new RootReference(controller);
self = new RootReference(controller, environment);
bucket = { engine, controller, self, environment };
} else {
let model = modelRef.value();
controller = controllerFactory.create({ model });
self = new RootReference(controller);
self = new RootReference(controller, environment);
bucket = { engine, controller, self, modelRef, environment };
}

Expand Down Expand Up @@ -172,10 +168,6 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
}

didRenderLayout(bucket: EngineState, bounds: Bounds): void {
if (DEBUG) {
bucket.environment.debugStack.pop();
}

if (ENV._DEBUG_RENDER_TREE) {
bucket.environment.debugRenderTree.didRender(bucket.controller, bounds);
bucket.environment.debugRenderTree.didRender(bucket, bounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { assert } from '@ember/debug';
import EngineInstance from '@ember/engine/instance';
import { _instrumentStart } from '@ember/instrumentation';
import { assign } from '@ember/polyfills';
import { DEBUG } from '@glimmer/env';
import { ComponentCapabilities, Option, Simple } from '@glimmer/interfaces';
import { CONSTANT_TAG, createTag, Tag, VersionedPathReference } from '@glimmer/reference';
import {
Expand Down Expand Up @@ -76,10 +75,6 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
args: Arguments,
dynamicScope: DynamicScope
): OutletInstanceState {
if (DEBUG) {
environment.debugStack.push(`template:${definition.template.referrer.moduleName}`);
}

let parentStateRef = dynamicScope.outletState;
let currentStateRef = definition.ref;

Expand Down Expand Up @@ -167,10 +162,6 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
didRenderLayout(state: OutletInstanceState, bounds: Bounds): void {
state.finalize();

if (DEBUG) {
state.environment.debugStack.pop();
}

if (ENV._DEBUG_RENDER_TREE) {
state.environment.debugRenderTree.didRender(state, bounds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class RootComponentManager extends CurlyComponentManager {
) {
let component = this.component;

if (DEBUG) {
environment.debugStack.push((component as any)._debugContainerKey);
}

let finalizer = _instrumentStart('render.component', initialRenderInstrumentDetails, component);

dynamicScope.view = component;
Expand Down
4 changes: 1 addition & 3 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import { DEBUG } from '@glimmer/env';
import { createTag, dirty } from '@glimmer/reference';
import { normalizeProperty, SVG_NAMESPACE } from '@glimmer/runtime';

import { RootReference, UPDATE } from './utils/references';
import { UPDATE } from './utils/references';

export const DIRTY_TAG = symbol('DIRTY_TAG');
export const ARGS = symbol('ARGS');
export const ROOT_REF = symbol('ROOT_REF');
export const IS_DISPATCHING_ATTRS = symbol('IS_DISPATCHING_ATTRS');
export const HAS_BLOCK = symbol('HAS_BLOCK');
export const BOUNDS = symbol('BOUNDS');
Expand Down Expand Up @@ -722,7 +721,6 @@ const Component = CoreView.extend(
this._super(...arguments);
this[IS_DISPATCHING_ATTRS] = false;
this[DIRTY_TAG] = createTag();
this[ROOT_REF] = new RootReference(this);
this[BOUNDS] = null;

if (DEBUG && this.renderer._destinedForDOM && this.tagName === '') {
Expand Down
14 changes: 0 additions & 14 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SimpleDynamicAttribute,
} from '@glimmer/runtime';
import { Destroyable, Opaque } from '@glimmer/util';
import getDebugStack, { DebugStack } from './utils/debug-stack';
import createIterable from './utils/iterable';
import { ConditionalReference, UpdatableReference } from './utils/references';
import { isHTMLSafe } from './utils/string';
Expand All @@ -35,7 +34,6 @@ export default class Environment extends GlimmerEnvironment {
public isInteractive: boolean;
public destroyedComponents: Destroyable[];

private _debugStack: DebugStack | undefined;
private _debugRenderTree: DebugRenderTree | undefined;
public inTransaction = false;

Expand All @@ -52,23 +50,11 @@ export default class Environment extends GlimmerEnvironment {

installPlatformSpecificProtocolForURL(this);

if (DEBUG) {
this._debugStack = getDebugStack();
}

if (ENV._DEBUG_RENDER_TREE) {
this._debugRenderTree = new DebugRenderTree();
}
}

get debugStack(): DebugStack {
if (DEBUG) {
return this._debugStack!;
} else {
throw new Error("Can't access debug stack outside of debug mode");
}
}

get debugRenderTree(): DebugRenderTree {
if (ENV._DEBUG_RENDER_TREE) {
return this._debugRenderTree!;
Expand Down
Loading