Skip to content

Commit

Permalink
Merge pull request #18839 from emberjs/refactor/update-autotracking-apis
Browse files Browse the repository at this point in the history
[CLEANUP] Updates the VM and autotracking APIs
  • Loading branch information
rwjblue authored Mar 28, 2020
2 parents 1370ef5 + 8a91fe3 commit afbfec0
Show file tree
Hide file tree
Showing 27 changed files with 272 additions and 261 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@
},
"devDependencies": {
"@babel/preset-env": "^7.9.0",
"@glimmer/compiler": "^0.49.0",
"@glimmer/compiler": "^0.50.0",
"@glimmer/env": "^0.1.7",
"@glimmer/interfaces": "^0.49.0",
"@glimmer/node": "^0.49.0",
"@glimmer/opcode-compiler": "^0.49.0",
"@glimmer/program": "^0.49.0",
"@glimmer/reference": "^0.49.0",
"@glimmer/runtime": "^0.49.0",
"@glimmer/validator": "^0.49.0",
"@glimmer/interfaces": "^0.50.0",
"@glimmer/node": "^0.50.0",
"@glimmer/opcode-compiler": "^0.50.0",
"@glimmer/program": "^0.50.0",
"@glimmer/reference": "^0.50.0",
"@glimmer/runtime": "^0.50.0",
"@glimmer/validator": "^0.50.0",
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.5.4",
"@types/rsvp": "^4.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { RootReference, VersionedPathReference } from '@glimmer/reference';
import { PrimitiveReference } from '@glimmer/runtime';
import { EMPTY_ARRAY, unwrapTemplate } from '@glimmer/util';
import { combine, Tag, validate, value } from '@glimmer/validator';
import { combine, Tag, validateTag, valueForTag } from '@glimmer/validator';
import { SimpleElement } from '@simple-dom/interface';
import { BOUNDS, DIRTY_TAG, HAS_BLOCK, IS_DISPATCHING_ATTRS } from '../component';
import { EmberVMEnvironment } from '../environment';
Expand Down Expand Up @@ -419,10 +419,10 @@ export default class CurlyComponentManager

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

if (args && !validate(args.tag, argsRevision)) {
if (args && !validateTag(args.tag, argsRevision)) {
let props = processComponentArgs(args!);

bucket.argsRevision = value(args!.tag);
bucket.argsRevision = valueForTag(args!.tag);

component[IS_DISPATCHING_ATTRS] = true;
component.setProperties(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@glimmer/interfaces';
import { ComponentRootReference, PathReference } from '@glimmer/reference';
import { unwrapTemplate } from '@glimmer/util';
import { consume, createTag, isConst, Tag } from '@glimmer/validator';
import { consumeTag, createTag, isConst, Tag } from '@glimmer/validator';

import { ENV } from '@ember/-internals/environment';
import { EmberVMEnvironment } from '../environment';
Expand Down Expand Up @@ -202,7 +202,7 @@ export default class CustomComponentManager<ComponentInstance>
get(_target, prop) {
if (namedArgs.has(prop as string)) {
let ref = namedArgs.get(prop as string);
consume(ref.tag);
consumeTag(ref.tag);

return ref.value();
} else if (prop === CUSTOM_TAG_FOR) {
Expand Down Expand Up @@ -257,7 +257,7 @@ export default class CustomComponentManager<ComponentInstance>
configurable: true,
get() {
let ref = namedArgs.get(name);
consume(ref.tag);
consumeTag(ref.tag);

return ref.value();
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { assert, deprecate } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { UPDATE_REFERENCED_VALUE } from '@glimmer/reference';
import { normalizeProperty } from '@glimmer/runtime';
import { createTag, dirty } from '@glimmer/validator';
import { createTag, dirtyTag } from '@glimmer/validator';
import { Namespace } from '@simple-dom/interface';

export const DIRTY_TAG = symbol('DIRTY_TAG');
Expand Down Expand Up @@ -774,7 +774,7 @@ const Component = CoreView.extend(
},

rerender() {
dirty(this[DIRTY_TAG]);
dirtyTag(this[DIRTY_TAG]);
this._super();
},

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FrameworkObject, setFrameworkClass } from '@ember/-internals/runtime';
import { symbol } from '@ember/-internals/utils';
import { join } from '@ember/runloop';
import { Dict } from '@glimmer/interfaces';
import { createTag, dirty } from '@glimmer/validator';
import { createTag, dirtyTag } from '@glimmer/validator';

export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG');

Expand Down Expand Up @@ -122,7 +122,7 @@ let Helper = FrameworkObject.extend({
@since 1.13.0
*/
recompute() {
join(() => dirty(this[RECOMPUTE_TAG]));
join(() => dirtyTag(this[RECOMPUTE_TAG]));
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { tagForProperty } from '@ember/-internals/metal';
import { VMArguments } from '@glimmer/interfaces';
import { VersionedPathReference } from '@glimmer/reference';
import { combine, createUpdatableTag, Tag, update } from '@glimmer/validator';
import { combine, createUpdatableTag, Tag, updateTag } from '@glimmer/validator';

/**
This reference is used to get the `[]` tag of iterables, so we can trigger
Expand All @@ -24,7 +24,7 @@ class TrackArrayReference implements VersionedPathReference {

let tag = tagForProperty(iterable, '[]');

update(this.valueTag, tag);
updateTag(this.valueTag, tag);

return iterable;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/helpers/each-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { _contentFor } from '@ember/-internals/runtime';
import { isProxy } from '@ember/-internals/utils';
import { VMArguments } from '@glimmer/interfaces';
import { VersionedPathReference } from '@glimmer/reference';
import { combine, createUpdatableTag, Tag, update } from '@glimmer/validator';
import { combine, createUpdatableTag, Tag, updateTag } from '@glimmer/validator';

/**
The `{{#each}}` helper loops over elements in a collection. It is an extension
Expand Down Expand Up @@ -173,7 +173,7 @@ class EachInReference implements VersionedPathReference {
iterable = _contentFor(iterable);
}

update(this.valueTag, tag);
updateTag(this.valueTag, tag);

return new EachInWrapper(iterable);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/modifiers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Tag,
track,
untrack,
update,
updateTag,
} from '@glimmer/validator';
import { SimpleElement } from '@simple-dom/interface';
import debugRenderMessage from '../utils/debug-render-message';
Expand Down Expand Up @@ -151,7 +151,7 @@ class InteractiveCustomModifierManager<ModifierInstance>
DEBUG && debugRenderMessage!(`(instance of a \`${getDebugName!(modifier)}\` modifier)`)
);

update(tag, combinedTrackingTag);
updateTag(tag, combinedTrackingTag);
}
}

Expand All @@ -166,7 +166,7 @@ class InteractiveCustomModifierManager<ModifierInstance>
() => delegate.updateModifier(modifier, args.value()),
DEBUG && debugRenderMessage!(`(instance of a \`${getDebugName!(modifier)}\` modifier)`)
);
update(tag, combinedTrackingTag);
updateTag(tag, combinedTrackingTag);
}
}

Expand Down
15 changes: 11 additions & 4 deletions packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import {
UNDEFINED_REFERENCE,
} from '@glimmer/runtime';
import { unwrapHandle, unwrapTemplate } from '@glimmer/util';
import { CURRENT_TAG, runInAutotrackingTransaction, validate, value } from '@glimmer/validator';
import {
CURRENT_TAG,
runInAutotrackingTransaction,
validateTag,
valueForTag,
} from '@glimmer/validator';
import { SimpleDocument, SimpleElement, SimpleNode } from '@simple-dom/interface';
import RSVP from 'rsvp';
import CompileTimeResolver from './compile-time-lookup';
Expand Down Expand Up @@ -461,7 +466,7 @@ export abstract class Renderer {
}
}

this._lastRevision = value(CURRENT_TAG);
this._lastRevision = valueForTag(CURRENT_TAG);
});
} while (roots.length > initialRootsLength);

Expand Down Expand Up @@ -495,7 +500,7 @@ export abstract class Renderer {
completedWithoutError = true;
} finally {
if (!completedWithoutError) {
this._lastRevision = value(CURRENT_TAG);
this._lastRevision = valueForTag(CURRENT_TAG);
}
this._inRenderTransaction = false;
}
Expand Down Expand Up @@ -523,7 +528,9 @@ export abstract class Renderer {
}

_isValid() {
return this._destroyed || this._roots.length === 0 || validate(CURRENT_TAG, this._lastRevision);
return (
this._destroyed || this._roots.length === 0 || validateTag(CURRENT_TAG, this._lastRevision)
);
}

_revalidate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { clearElementView, clearViewElement, getViewElement } from '@ember/-internals/views';
import { CapturedNamedArguments } from '@glimmer/interfaces';
import { ComponentRootReference, VersionedReference } from '@glimmer/reference';
import { Revision, value } from '@glimmer/validator';
import { Revision, valueForTag } from '@glimmer/validator';
import { EmberVMEnvironment } from '../environment';
import { Renderer } from '../renderer';
import { Factory as TemplateFactory, OwnedTemplate } from '../template';
Expand Down Expand Up @@ -51,7 +51,7 @@ export default class ComponentStateBucket {
public hasWrappedElement: boolean
) {
this.classRef = null;
this.argsRevision = args === null ? 0 : value(args.tag);
this.argsRevision = args === null ? 0 : valueForTag(args.tag);
this.rootRef = new ComponentRootReference(component, environment);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/utils/iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { _contentFor } from '@ember/-internals/runtime';
import { EmberArray, HAS_NATIVE_SYMBOL, isEmberArray, isObject } from '@ember/-internals/utils';
import { Option } from '@glimmer/interfaces';
import { IteratorDelegate } from '@glimmer/reference';
import { consume, isTracking } from '@glimmer/validator';
import { consumeTag, isTracking } from '@glimmer/validator';
import { EachInWrapper } from '../helpers/each-in';

export default function toIterator(iterable: unknown): Option<IteratorDelegate> {
Expand Down Expand Up @@ -131,10 +131,10 @@ class ObjectIterator extends BoundedIterator {
// Add the tag of the returned value if it is an array, since arrays
// should always cause updates if they are consumed and then changed
if (isTracking()) {
consume(tagForProperty(obj, key));
consumeTag(tagForProperty(obj, key));

if (Array.isArray(value) || isEmberArray(value)) {
consume(tagForProperty(value, '[]'));
consumeTag(tagForProperty(value, '[]'));
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/utils/outlet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Owner } from '@ember/-internals/owner';
import { Reference, VersionedPathReference } from '@glimmer/reference';
import { combine, createTag, dirty, Tag } from '@glimmer/validator';
import { combine, createTag, dirtyTag, Tag } from '@glimmer/validator';
import { Factory as TemplateFactory, OwnedTemplate } from '../template';

export interface RenderState {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class RootOutletReference implements VersionedPathReference<OutletState>

update(state: OutletState) {
this.outletState.outlets.main = state;
dirty(this.tag);
dirtyTag(this.tag);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/utils/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEBUG } from '@glimmer/env';
import { CapturedArguments, Environment } from '@glimmer/interfaces';
import { HelperRootReference, RootReference, VersionedPathReference } from '@glimmer/reference';
import { PrimitiveReference } from '@glimmer/runtime';
import { consume, deprecateMutationsInAutotrackingTransaction } from '@glimmer/validator';
import { consumeTag, deprecateMutationsInAutotrackingTransaction } from '@glimmer/validator';
import { HelperInstance, isClassHelper, RECOMPUTE_TAG, SimpleHelper } from '../helper';

export class EmberHelperRootReference<T = unknown> extends HelperRootReference<T> {
Expand Down Expand Up @@ -33,7 +33,7 @@ export class EmberHelperRootReference<T = unknown> extends HelperRootReference<T
}

if (helper[RECOMPUTE_TAG]) {
consume(helper[RECOMPUTE_TAG]);
consumeTag(helper[RECOMPUTE_TAG]);
}

return ret!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ moduleFor(
hooks.push('compute');
},
willDestroy() {
hooks.push('willDestroy'),
hooks.push('willDestroy');
this._super();
},
destroy() {
Expand Down
16 changes: 8 additions & 8 deletions packages/@ember/-internals/metal/lib/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { assert } from '@ember/debug';
import EmberError from '@ember/error';
import {
combine,
consume,
consumeTag,
untrack,
UpdatableTag,
update,
validate,
value,
updateTag,
validateTag,
valueForTag,
} from '@glimmer/validator';
import { finishLazyChains, getChainTagsForKey } from './chain-tags';
import { getLastRevisionFor, setLastRevisionFor } from './computed_cache';
Expand Down Expand Up @@ -90,13 +90,13 @@ export class AliasedProperty extends ComputedDescriptor {

let lastRevision = getLastRevisionFor(obj, keyName);

if (!validate(propertyTag, lastRevision)) {
update(propertyTag, combine(getChainTagsForKey(obj, this.altKey)));
setLastRevisionFor(obj, keyName, value(propertyTag));
if (!validateTag(propertyTag, lastRevision)) {
updateTag(propertyTag, combine(getChainTagsForKey(obj, this.altKey)));
setLastRevisionFor(obj, keyName, valueForTag(propertyTag));
finishLazyChains(obj, keyName, ret);
}

consume(propertyTag);
consumeTag(propertyTag);

return ret;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/metal/lib/chain-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
combine,
createUpdatableTag,
Tag,
update,
validate,
updateTag,
validateTag,
} from '@glimmer/validator';
import { objectAt } from './array';
import { getLastRevisionFor, peekCacheFor } from './computed_cache';
Expand All @@ -32,7 +32,7 @@ export function finishLazyChains(obj: any, key: string, value: any) {
for (let path in lazyTags) {
let tag = lazyTags[path];

update(tag, combine(getChainTagsForKey(value, path)));
updateTag(tag, combine(getChainTagsForKey(value, path)));

delete lazyTags[path];
}
Expand Down Expand Up @@ -193,7 +193,7 @@ export function getChainTagsForKey(obj: any, path: string) {
// it will update that lazy chain.
let lastRevision = getLastRevisionFor(current, segment);

if (validate(propertyTag, lastRevision)) {
if (validateTag(propertyTag, lastRevision)) {
current = peekCacheFor(current).get(segment);
} else {
let lazyChains = metaFor(current).writableLazyChainsFor(segment);
Expand Down
Loading

0 comments on commit afbfec0

Please sign in to comment.