ember-source 5.0.0-alpha.7 → 5.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-metadata.json +3 -3
- package/dist/dependencies/@glimmer/destroyable.js +2 -2
- package/dist/dependencies/@glimmer/env.js +1 -1
- package/dist/dependencies/@glimmer/global-context.js +1 -1
- package/dist/dependencies/@glimmer/low-level.js +1 -1
- package/dist/dependencies/@glimmer/manager.js +5 -13
- package/dist/dependencies/@glimmer/node.js +1 -1
- package/dist/dependencies/@glimmer/opcode-compiler.js +38 -38
- package/dist/dependencies/@glimmer/program.js +9 -9
- package/dist/dependencies/@glimmer/reference.js +4 -4
- package/dist/dependencies/@glimmer/runtime.js +41 -41
- package/dist/dependencies/@glimmer/util.js +3 -3
- package/dist/dependencies/@glimmer/validator.js +1 -1
- package/dist/dependencies/@glimmer/vm.js +1 -1
- package/dist/dependencies/@glimmer/wire-format.js +1 -1
- package/dist/dependencies/router_js.js +3 -4
- package/dist/dependencies/rsvp.js +23 -25
- package/dist/ember-template-compiler.js +343 -398
- package/dist/ember-template-compiler.map +1 -1
- package/dist/ember-testing.js +4 -4
- package/dist/ember-testing.map +1 -1
- package/dist/ember.debug.js +423 -649
- package/dist/ember.debug.map +1 -1
- package/dist/header/license.js +1 -1
- package/dist/packages/@ember/-internals/browser-environment/index.js +1 -1
- package/dist/packages/@ember/-internals/container/index.js +6 -12
- package/dist/packages/@ember/-internals/environment/index.js +1 -1
- package/dist/packages/@ember/-internals/glimmer/index.js +115 -208
- package/dist/packages/@ember/-internals/metal/index.js +106 -226
- package/dist/packages/@ember/-internals/utils/index.js +1 -12
- package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +10 -9
- package/dist/packages/@ember/-internals/views/lib/views/core_view.js +1 -2
- package/dist/packages/@ember/-internals/views/lib/views/states.js +12 -7
- package/dist/packages/@ember/application/index.js +11 -11
- package/dist/packages/@ember/application/instance.js +3 -2
- package/dist/packages/@ember/application/lib/lazy_load.js +2 -4
- package/dist/packages/@ember/array/index.js +3 -6
- package/dist/packages/@ember/debug/lib/deprecate.js +3 -3
- package/dist/packages/@ember/engine/index.js +3 -2
- package/dist/packages/@ember/engine/instance.js +1 -2
- package/dist/packages/@ember/object/index.js +1 -1
- package/dist/packages/@ember/routing/hash-location.js +1 -2
- package/dist/packages/@ember/routing/history-location.js +3 -5
- package/dist/packages/@ember/routing/lib/utils.js +4 -1
- package/dist/packages/@ember/routing/route.js +20 -6
- package/dist/packages/ember/index.js +4 -3
- package/dist/packages/ember/version.js +1 -1
- package/docs/data.json +4 -4
- package/lib/browsers.js +49 -24
- package/package.json +7 -9
- package/types/preview/@ember/routing/history-location.d.ts +2 -2
- package/CHANGELOG.md +0 -3828
- package/dist/packages/@ember/-internals/runtime/.gitignore +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { meta, peekMeta } from '@ember/-internals/meta';
|
|
2
|
-
import { setListeners,
|
|
3
|
-
import { assert, inspect, deprecate,
|
|
4
|
-
import { ENV, context } from '@ember/-internals/environment';
|
|
5
|
-
import { schedule } from '@ember/runloop';
|
|
2
|
+
import { setListeners, symbol, setupMandatorySetter, isObject, toString, setWithMandatorySetter, Cache, setProxy, lookupDescriptor, getName, setName } from '@ember/-internals/utils';
|
|
3
|
+
import { assert, inspect, deprecate, warn, debug } from '@ember/debug';
|
|
6
4
|
import { registerDestructor, isDestroyed } from '@glimmer/destroyable';
|
|
7
|
-
import { CURRENT_TAG, tagMetaFor, validateTag, valueForTag, CONSTANT_TAG, dirtyTagFor, tagFor, combine, createUpdatableTag, updateTag, ALLOW_CYCLES, consumeTag, track, untrack, isTracking, trackedData, createCache, getValue } from '@glimmer/validator';
|
|
8
|
-
export { createCache, getValue, isConst } from '@glimmer/validator';
|
|
9
5
|
import { DEBUG } from '@glimmer/env';
|
|
10
|
-
import {
|
|
6
|
+
import { tagMetaFor, valueForTag, CURRENT_TAG, validateTag, tagFor, CONSTANT_TAG, dirtyTagFor, combine, createUpdatableTag, updateTag, untrack, ALLOW_CYCLES, consumeTag, track, isTracking, trackedData, createCache, getValue } from '@glimmer/validator';
|
|
7
|
+
export { createCache, getValue, isConst } from '@glimmer/validator';
|
|
11
8
|
import { _WeakSet } from '@glimmer/util';
|
|
9
|
+
import { ENV, context } from '@ember/-internals/environment';
|
|
10
|
+
import { schedule } from '@ember/runloop';
|
|
11
|
+
import { getCustomTagFor } from '@glimmer/manager';
|
|
12
12
|
import { isEmberArray } from '@ember/array/-internals';
|
|
13
13
|
import VERSION from 'ember/version';
|
|
14
14
|
import { getOwner } from '@ember/-internals/owner';
|
|
@@ -95,8 +95,8 @@ function removeListener(obj, eventName, targetOrFunction, functionOrName) {
|
|
|
95
95
|
*/
|
|
96
96
|
function sendEvent(obj, eventName, params, actions, _meta) {
|
|
97
97
|
if (actions === undefined) {
|
|
98
|
-
let meta
|
|
99
|
-
actions = meta
|
|
98
|
+
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
99
|
+
actions = meta !== null ? meta.matchingListeners(eventName) : undefined;
|
|
100
100
|
}
|
|
101
101
|
if (actions === undefined || actions.length === 0) {
|
|
102
102
|
return false;
|
|
@@ -133,11 +133,11 @@ function sendEvent(obj, eventName, params, actions, _meta) {
|
|
|
133
133
|
@return {Boolean} if `obj` has listeners for event `eventName`
|
|
134
134
|
*/
|
|
135
135
|
function hasListeners(obj, eventName) {
|
|
136
|
-
let meta
|
|
137
|
-
if (meta
|
|
136
|
+
let meta = peekMeta(obj);
|
|
137
|
+
if (meta === null) {
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
|
-
let matched = meta
|
|
140
|
+
let matched = meta.matchingListeners(eventName);
|
|
141
141
|
return matched !== undefined && matched.length > 0;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
@@ -201,8 +201,8 @@ const ASYNC_OBSERVERS = new Map();
|
|
|
201
201
|
function addObserver(obj, path, target, method, sync = SYNC_DEFAULT) {
|
|
202
202
|
let eventName = changeEvent(path);
|
|
203
203
|
addListener(obj, eventName, target, method, false, sync);
|
|
204
|
-
let meta
|
|
205
|
-
if (meta
|
|
204
|
+
let meta = peekMeta(obj);
|
|
205
|
+
if (meta === null || !(meta.isPrototypeMeta(obj) || meta.isInitializing())) {
|
|
206
206
|
activateObserver(obj, eventName, sync);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
@@ -218,8 +218,8 @@ function addObserver(obj, path, target, method, sync = SYNC_DEFAULT) {
|
|
|
218
218
|
*/
|
|
219
219
|
function removeObserver(obj, path, target, method, sync = SYNC_DEFAULT) {
|
|
220
220
|
let eventName = changeEvent(path);
|
|
221
|
-
let meta
|
|
222
|
-
if (meta
|
|
221
|
+
let meta = peekMeta(obj);
|
|
222
|
+
if (meta === null || !(meta.isPrototypeMeta(obj) || meta.isInitializing())) {
|
|
223
223
|
deactivateObserver(obj, eventName, sync);
|
|
224
224
|
}
|
|
225
225
|
removeListener(obj, eventName, target, method);
|
|
@@ -307,12 +307,12 @@ function flushAsyncObservers(shouldSchedule = true) {
|
|
|
307
307
|
}
|
|
308
308
|
lastKnownRevision = currentRevision;
|
|
309
309
|
ASYNC_OBSERVERS.forEach((activeObservers, target) => {
|
|
310
|
-
let meta
|
|
310
|
+
let meta = peekMeta(target);
|
|
311
311
|
activeObservers.forEach((observer, eventName) => {
|
|
312
312
|
if (!validateTag(observer.tag, observer.lastRevision)) {
|
|
313
313
|
let sendObserver = () => {
|
|
314
314
|
try {
|
|
315
|
-
sendEvent(target, eventName, [target, observer.path], undefined, meta
|
|
315
|
+
sendEvent(target, eventName, [target, observer.path], undefined, meta);
|
|
316
316
|
} finally {
|
|
317
317
|
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
318
318
|
observer.lastRevision = valueForTag(observer.tag);
|
|
@@ -332,12 +332,12 @@ function flushSyncObservers() {
|
|
|
332
332
|
// only do this during a notifyPropertyChange), so there's no reason to check
|
|
333
333
|
// a global revision.
|
|
334
334
|
SYNC_OBSERVERS.forEach((activeObservers, target) => {
|
|
335
|
-
let meta
|
|
335
|
+
let meta = peekMeta(target);
|
|
336
336
|
activeObservers.forEach((observer, eventName) => {
|
|
337
337
|
if (!observer.suspended && !validateTag(observer.tag, observer.lastRevision)) {
|
|
338
338
|
try {
|
|
339
339
|
observer.suspended = true;
|
|
340
|
-
sendEvent(target, eventName, [target, observer.path], undefined, meta
|
|
340
|
+
sendEvent(target, eventName, [target, observer.path], undefined, meta);
|
|
341
341
|
} finally {
|
|
342
342
|
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
343
343
|
observer.lastRevision = valueForTag(observer.tag);
|
|
@@ -364,12 +364,12 @@ function destroyObservers(target) {
|
|
|
364
364
|
|
|
365
365
|
// This is exported for `@tracked`, but should otherwise be avoided. Use `tagForObject`.
|
|
366
366
|
const SELF_TAG = symbol('SELF_TAG');
|
|
367
|
-
function tagForProperty(obj, propertyKey, addMandatorySetter = false, meta
|
|
367
|
+
function tagForProperty(obj, propertyKey, addMandatorySetter = false, meta) {
|
|
368
368
|
let customTagFor = getCustomTagFor(obj);
|
|
369
369
|
if (customTagFor !== undefined) {
|
|
370
370
|
return customTagFor(obj, propertyKey, addMandatorySetter);
|
|
371
371
|
}
|
|
372
|
-
let tag = tagFor(obj, propertyKey, meta
|
|
372
|
+
let tag = tagFor(obj, propertyKey, meta);
|
|
373
373
|
if (DEBUG && addMandatorySetter) {
|
|
374
374
|
setupMandatorySetter(tag, obj, propertyKey);
|
|
375
375
|
}
|
|
@@ -417,8 +417,8 @@ let deferred = 0;
|
|
|
417
417
|
@public
|
|
418
418
|
*/
|
|
419
419
|
function notifyPropertyChange(obj, keyName, _meta, value) {
|
|
420
|
-
let meta
|
|
421
|
-
if (meta
|
|
420
|
+
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
421
|
+
if (meta !== null && (meta.isInitializing() || meta.isPrototypeMeta(obj))) {
|
|
422
422
|
return;
|
|
423
423
|
}
|
|
424
424
|
markObjectAsDirty(obj, keyName);
|
|
@@ -511,29 +511,29 @@ function arrayContentDidChange(array, startIdx, removeAmt, addAmt, notify = true
|
|
|
511
511
|
addAmt = -1;
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
let meta
|
|
514
|
+
let meta = peekMeta(array);
|
|
515
515
|
if (notify) {
|
|
516
516
|
if (addAmt < 0 || removeAmt < 0 || addAmt - removeAmt !== 0) {
|
|
517
|
-
notifyPropertyChange(array, 'length', meta
|
|
517
|
+
notifyPropertyChange(array, 'length', meta);
|
|
518
518
|
}
|
|
519
|
-
notifyPropertyChange(array, '[]', meta
|
|
519
|
+
notifyPropertyChange(array, '[]', meta);
|
|
520
520
|
}
|
|
521
521
|
sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
|
|
522
|
-
if (meta
|
|
522
|
+
if (meta !== null) {
|
|
523
523
|
let length = array.length;
|
|
524
524
|
let addedAmount = addAmt === -1 ? 0 : addAmt;
|
|
525
525
|
let removedAmount = removeAmt === -1 ? 0 : removeAmt;
|
|
526
526
|
let delta = addedAmount - removedAmount;
|
|
527
527
|
let previousLength = length - delta;
|
|
528
528
|
let normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx;
|
|
529
|
-
if (meta
|
|
530
|
-
notifyPropertyChange(array, 'firstObject', meta
|
|
529
|
+
if (meta.revisionFor('firstObject') !== undefined && normalStartIdx === 0) {
|
|
530
|
+
notifyPropertyChange(array, 'firstObject', meta);
|
|
531
531
|
}
|
|
532
|
-
if (meta
|
|
532
|
+
if (meta.revisionFor('lastObject') !== undefined) {
|
|
533
533
|
let previousLastIndex = previousLength - 1;
|
|
534
534
|
let lastAffectedIndex = normalStartIdx + removedAmount;
|
|
535
535
|
if (previousLastIndex < lastAffectedIndex) {
|
|
536
|
-
notifyPropertyChange(array, 'lastObject', meta
|
|
536
|
+
notifyPropertyChange(array, 'lastObject', meta);
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
}
|
|
@@ -578,7 +578,6 @@ function replaceInNativeArray(array, start, deleteCount, items) {
|
|
|
578
578
|
arrayContentDidChange(array, start, deleteCount, items.length);
|
|
579
579
|
}
|
|
580
580
|
function arrayObserversHelper(obj, target, opts, operation) {
|
|
581
|
-
var _a;
|
|
582
581
|
let {
|
|
583
582
|
willChange,
|
|
584
583
|
didChange
|
|
@@ -589,7 +588,7 @@ function arrayObserversHelper(obj, target, opts, operation) {
|
|
|
589
588
|
* Array proxies have a `_revalidate` method which must be called to set
|
|
590
589
|
* up their internal array observation systems.
|
|
591
590
|
*/
|
|
592
|
-
|
|
591
|
+
obj._revalidate?.();
|
|
593
592
|
return obj;
|
|
594
593
|
}
|
|
595
594
|
function addArrayObserver(array, target, opts) {
|
|
@@ -600,8 +599,8 @@ function removeArrayObserver(array, target, opts) {
|
|
|
600
599
|
}
|
|
601
600
|
|
|
602
601
|
const CHAIN_PASS_THROUGH = new _WeakSet();
|
|
603
|
-
function finishLazyChains(meta
|
|
604
|
-
let lazyTags = meta
|
|
602
|
+
function finishLazyChains(meta, key, value) {
|
|
603
|
+
let lazyTags = meta.readableLazyChainsFor(key);
|
|
605
604
|
if (lazyTags === undefined) {
|
|
606
605
|
return;
|
|
607
606
|
}
|
|
@@ -612,20 +611,20 @@ function finishLazyChains(meta$$1, key, value) {
|
|
|
612
611
|
}
|
|
613
612
|
lazyTags.length = 0;
|
|
614
613
|
}
|
|
615
|
-
function getChainTagsForKeys(obj, keys, tagMeta, meta
|
|
614
|
+
function getChainTagsForKeys(obj, keys, tagMeta, meta) {
|
|
616
615
|
let tags = [];
|
|
617
616
|
for (let key of keys) {
|
|
618
|
-
getChainTags(tags, obj, key, tagMeta, meta
|
|
617
|
+
getChainTags(tags, obj, key, tagMeta, meta);
|
|
619
618
|
}
|
|
620
619
|
return combine(tags);
|
|
621
620
|
}
|
|
622
|
-
function getChainTagsForKey(obj, key, tagMeta, meta
|
|
623
|
-
return combine(getChainTags([], obj, key, tagMeta, meta
|
|
621
|
+
function getChainTagsForKey(obj, key, tagMeta, meta) {
|
|
622
|
+
return combine(getChainTags([], obj, key, tagMeta, meta));
|
|
624
623
|
}
|
|
625
|
-
function getChainTags(chainTags, obj, path, tagMeta, meta
|
|
624
|
+
function getChainTags(chainTags, obj, path, tagMeta, meta$1) {
|
|
626
625
|
let current = obj;
|
|
627
626
|
let currentTagMeta = tagMeta;
|
|
628
|
-
let currentMeta = meta
|
|
627
|
+
let currentMeta = meta$1;
|
|
629
628
|
let pathLength = path.length;
|
|
630
629
|
let segmentEnd = -1;
|
|
631
630
|
// prevent closures
|
|
@@ -767,11 +766,11 @@ class ComputedDescriptor {
|
|
|
767
766
|
this._dependentKeys = undefined;
|
|
768
767
|
this._meta = undefined;
|
|
769
768
|
}
|
|
770
|
-
setup(_obj, keyName, _propertyDesc, meta
|
|
771
|
-
meta
|
|
769
|
+
setup(_obj, keyName, _propertyDesc, meta) {
|
|
770
|
+
meta.writeDescriptors(keyName, this);
|
|
772
771
|
}
|
|
773
|
-
teardown(_obj, keyName, meta
|
|
774
|
-
meta
|
|
772
|
+
teardown(_obj, keyName, meta) {
|
|
773
|
+
meta.removeDescriptors(keyName);
|
|
775
774
|
}
|
|
776
775
|
}
|
|
777
776
|
let COMPUTED_GETTERS;
|
|
@@ -798,8 +797,8 @@ const COMPUTED_SETTERS = new _WeakSet();
|
|
|
798
797
|
function makeComputedDecorator(desc, DecoratorClass) {
|
|
799
798
|
let decorator = function COMPUTED_DECORATOR(target, key, propertyDesc, maybeMeta, isClassicDecorator) {
|
|
800
799
|
assert(`Only one computed property decorator can be applied to a class field or accessor, but '${key}' was decorated twice. You may have added the decorator to both a getter and setter, which is unnecessary.`, isClassicDecorator || !propertyDesc || !propertyDesc.get || !COMPUTED_GETTERS.has(propertyDesc.get));
|
|
801
|
-
let meta
|
|
802
|
-
desc.setup(target, key, propertyDesc, meta
|
|
800
|
+
let meta$1 = arguments.length === 3 ? meta(target) : maybeMeta;
|
|
801
|
+
desc.setup(target, key, propertyDesc, meta$1);
|
|
803
802
|
let computedDesc = {
|
|
804
803
|
enumerable: desc.enumerable,
|
|
805
804
|
configurable: desc.configurable,
|
|
@@ -827,9 +826,9 @@ function descriptorForProperty(obj, keyName, _meta) {
|
|
|
827
826
|
assert('Cannot call `descriptorForProperty` on null', obj !== null);
|
|
828
827
|
assert('Cannot call `descriptorForProperty` on undefined', obj !== undefined);
|
|
829
828
|
assert(`Cannot call \`descriptorForProperty\` on ${typeof obj}`, typeof obj === 'object' || typeof obj === 'function');
|
|
830
|
-
let meta
|
|
831
|
-
if (meta
|
|
832
|
-
return meta
|
|
829
|
+
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
830
|
+
if (meta !== null) {
|
|
831
|
+
return meta.peekDescriptors(keyName);
|
|
833
832
|
}
|
|
834
833
|
}
|
|
835
834
|
function descriptorForDecorator(dec) {
|
|
@@ -1150,8 +1149,8 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1150
1149
|
this._property(...args);
|
|
1151
1150
|
}
|
|
1152
1151
|
}
|
|
1153
|
-
setup(obj, keyName, propertyDesc, meta
|
|
1154
|
-
super.setup(obj, keyName, propertyDesc, meta
|
|
1152
|
+
setup(obj, keyName, propertyDesc, meta) {
|
|
1153
|
+
super.setup(obj, keyName, propertyDesc, meta);
|
|
1155
1154
|
assert(`@computed can only be used on accessors or fields, attempted to use it with ${keyName} but that was a method. Try converting it to a getter (e.g. \`get ${keyName}() {}\`)`, !(propertyDesc && typeof propertyDesc.value === 'function'));
|
|
1156
1155
|
assert(`@computed can only be used on empty fields. ${keyName} has an initial value (e.g. \`${keyName} = someValue\`)`, !propertyDesc || !propertyDesc.initializer);
|
|
1157
1156
|
assert(`Attempted to apply a computed property that already has a getter/setter to a ${keyName}, but it is a method or an accessor. If you passed @computed a function or getter/setter (e.g. \`@computed({ get() { ... } })\`), then it must be applied to a field`, !(this._hasConfig && propertyDesc && (typeof propertyDesc.get === 'function' || typeof propertyDesc.set === 'function')));
|
|
@@ -1187,13 +1186,13 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1187
1186
|
this._dependentKeys = args;
|
|
1188
1187
|
}
|
|
1189
1188
|
get(obj, keyName) {
|
|
1190
|
-
let meta
|
|
1189
|
+
let meta$1 = meta(obj);
|
|
1191
1190
|
let tagMeta = tagMetaFor(obj);
|
|
1192
1191
|
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1193
1192
|
let ret;
|
|
1194
|
-
let revision = meta
|
|
1193
|
+
let revision = meta$1.revisionFor(keyName);
|
|
1195
1194
|
if (revision !== undefined && validateTag(propertyTag, revision)) {
|
|
1196
|
-
ret = meta
|
|
1195
|
+
ret = meta$1.valueFor(keyName);
|
|
1197
1196
|
} else {
|
|
1198
1197
|
// For backwards compatibility, we only throw if the CP has any dependencies. CPs without dependencies
|
|
1199
1198
|
// should be allowed, even after the object has been destroyed, which is why we check _dependentKeys.
|
|
@@ -1207,14 +1206,14 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1207
1206
|
ret = _getter.call(obj, keyName);
|
|
1208
1207
|
});
|
|
1209
1208
|
if (_dependentKeys !== undefined) {
|
|
1210
|
-
updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta
|
|
1209
|
+
updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta$1));
|
|
1211
1210
|
if (DEBUG) {
|
|
1212
1211
|
ALLOW_CYCLES.set(propertyTag, true);
|
|
1213
1212
|
}
|
|
1214
1213
|
}
|
|
1215
|
-
meta
|
|
1216
|
-
meta
|
|
1217
|
-
finishLazyChains(meta
|
|
1214
|
+
meta$1.setValueFor(keyName, ret);
|
|
1215
|
+
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1216
|
+
finishLazyChains(meta$1, keyName, ret);
|
|
1218
1217
|
}
|
|
1219
1218
|
consumeTag(propertyTag);
|
|
1220
1219
|
// Add the tag of the returned value if it is an array, since arrays
|
|
@@ -1229,7 +1228,7 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1229
1228
|
this._throwReadOnlyError(obj, keyName);
|
|
1230
1229
|
}
|
|
1231
1230
|
assert(`Cannot override the computed property \`${keyName}\` on ${toString(obj)}.`, this._setter !== undefined);
|
|
1232
|
-
let meta
|
|
1231
|
+
let meta$1 = meta(obj);
|
|
1233
1232
|
// ensure two way binding works when the component has defined a computed
|
|
1234
1233
|
// property with both a setter and dependent keys, in that scenario without
|
|
1235
1234
|
// the sync observer added below the caller's value will never be updated
|
|
@@ -1237,7 +1236,7 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1237
1236
|
// See GH#18147 / GH#19028 for details.
|
|
1238
1237
|
if (
|
|
1239
1238
|
// ensure that we only run this once, while the component is being instantiated
|
|
1240
|
-
meta
|
|
1239
|
+
meta$1.isInitializing() && this._dependentKeys !== undefined && this._dependentKeys.length > 0 && typeof obj[PROPERTY_DID_CHANGE] === 'function' && obj.isComponent) {
|
|
1241
1240
|
// It's redundant to do this here, but we don't want to check above so we can avoid an extra function call in prod.
|
|
1242
1241
|
assert('property did change hook is invalid', hasPropertyDidChange(obj));
|
|
1243
1242
|
addObserver(obj, keyName, () => {
|
|
@@ -1247,20 +1246,20 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1247
1246
|
let ret;
|
|
1248
1247
|
try {
|
|
1249
1248
|
beginPropertyChanges();
|
|
1250
|
-
ret = this._set(obj, keyName, value, meta
|
|
1251
|
-
finishLazyChains(meta
|
|
1249
|
+
ret = this._set(obj, keyName, value, meta$1);
|
|
1250
|
+
finishLazyChains(meta$1, keyName, ret);
|
|
1252
1251
|
let tagMeta = tagMetaFor(obj);
|
|
1253
1252
|
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1254
1253
|
let {
|
|
1255
1254
|
_dependentKeys
|
|
1256
1255
|
} = this;
|
|
1257
1256
|
if (_dependentKeys !== undefined) {
|
|
1258
|
-
updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta
|
|
1257
|
+
updateTag(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta$1));
|
|
1259
1258
|
if (DEBUG) {
|
|
1260
1259
|
ALLOW_CYCLES.set(propertyTag, true);
|
|
1261
1260
|
}
|
|
1262
1261
|
}
|
|
1263
|
-
meta
|
|
1262
|
+
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1264
1263
|
} finally {
|
|
1265
1264
|
endPropertyChanges();
|
|
1266
1265
|
}
|
|
@@ -1269,9 +1268,9 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1269
1268
|
_throwReadOnlyError(obj, keyName) {
|
|
1270
1269
|
throw new Error(`Cannot set read-only property "${keyName}" on object: ${inspect(obj)}`);
|
|
1271
1270
|
}
|
|
1272
|
-
_set(obj, keyName, value, meta
|
|
1273
|
-
let hadCachedValue = meta
|
|
1274
|
-
let cachedValue = meta
|
|
1271
|
+
_set(obj, keyName, value, meta) {
|
|
1272
|
+
let hadCachedValue = meta.revisionFor(keyName) !== undefined;
|
|
1273
|
+
let cachedValue = meta.valueFor(keyName);
|
|
1275
1274
|
let ret;
|
|
1276
1275
|
let {
|
|
1277
1276
|
_setter
|
|
@@ -1286,28 +1285,28 @@ class ComputedProperty extends ComputedDescriptor {
|
|
|
1286
1285
|
if (hadCachedValue && cachedValue === ret) {
|
|
1287
1286
|
return ret;
|
|
1288
1287
|
}
|
|
1289
|
-
meta
|
|
1290
|
-
notifyPropertyChange(obj, keyName, meta
|
|
1288
|
+
meta.setValueFor(keyName, ret);
|
|
1289
|
+
notifyPropertyChange(obj, keyName, meta, value);
|
|
1291
1290
|
return ret;
|
|
1292
1291
|
}
|
|
1293
1292
|
/* called before property is overridden */
|
|
1294
|
-
teardown(obj, keyName, meta
|
|
1295
|
-
if (meta
|
|
1296
|
-
meta
|
|
1297
|
-
meta
|
|
1293
|
+
teardown(obj, keyName, meta) {
|
|
1294
|
+
if (meta.revisionFor(keyName) !== undefined) {
|
|
1295
|
+
meta.setRevisionFor(keyName, undefined);
|
|
1296
|
+
meta.setValueFor(keyName, undefined);
|
|
1298
1297
|
}
|
|
1299
|
-
super.teardown(obj, keyName, meta
|
|
1298
|
+
super.teardown(obj, keyName, meta);
|
|
1300
1299
|
}
|
|
1301
1300
|
}
|
|
1302
1301
|
class AutoComputedProperty extends ComputedProperty {
|
|
1303
1302
|
get(obj, keyName) {
|
|
1304
|
-
let meta
|
|
1303
|
+
let meta$1 = meta(obj);
|
|
1305
1304
|
let tagMeta = tagMetaFor(obj);
|
|
1306
1305
|
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1307
1306
|
let ret;
|
|
1308
|
-
let revision = meta
|
|
1307
|
+
let revision = meta$1.revisionFor(keyName);
|
|
1309
1308
|
if (revision !== undefined && validateTag(propertyTag, revision)) {
|
|
1310
|
-
ret = meta
|
|
1309
|
+
ret = meta$1.valueFor(keyName);
|
|
1311
1310
|
} else {
|
|
1312
1311
|
assert(`Attempted to access the computed ${obj}.${keyName} on a destroyed object, which is not allowed`, !isDestroyed(obj));
|
|
1313
1312
|
let {
|
|
@@ -1318,9 +1317,9 @@ class AutoComputedProperty extends ComputedProperty {
|
|
|
1318
1317
|
ret = _getter.call(obj, keyName);
|
|
1319
1318
|
});
|
|
1320
1319
|
updateTag(propertyTag, tag);
|
|
1321
|
-
meta
|
|
1322
|
-
meta
|
|
1323
|
-
finishLazyChains(meta
|
|
1320
|
+
meta$1.setValueFor(keyName, ret);
|
|
1321
|
+
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1322
|
+
finishLazyChains(meta$1, keyName, ret);
|
|
1324
1323
|
}
|
|
1325
1324
|
consumeTag(propertyTag);
|
|
1326
1325
|
// Add the tag of the returned value if it is an array, since arrays
|
|
@@ -1408,12 +1407,12 @@ class ComputedDecoratorImpl extends Function {
|
|
|
1408
1407
|
@chainable
|
|
1409
1408
|
@public
|
|
1410
1409
|
*/
|
|
1411
|
-
meta(meta
|
|
1410
|
+
meta(meta) {
|
|
1412
1411
|
let prop = descriptorForDecorator(this);
|
|
1413
1412
|
if (arguments.length === 0) {
|
|
1414
1413
|
return prop._meta || {};
|
|
1415
1414
|
} else {
|
|
1416
|
-
prop._meta = meta
|
|
1415
|
+
prop._meta = meta;
|
|
1417
1416
|
return this;
|
|
1418
1417
|
}
|
|
1419
1418
|
}
|
|
@@ -1461,9 +1460,9 @@ function isComputed(obj, key) {
|
|
|
1461
1460
|
}
|
|
1462
1461
|
|
|
1463
1462
|
function getCachedValueFor(obj, key) {
|
|
1464
|
-
let meta
|
|
1465
|
-
if (meta
|
|
1466
|
-
return meta
|
|
1463
|
+
let meta = peekMeta(obj);
|
|
1464
|
+
if (meta) {
|
|
1465
|
+
return meta.valueFor(key);
|
|
1467
1466
|
} else {
|
|
1468
1467
|
return undefined;
|
|
1469
1468
|
}
|
|
@@ -1521,14 +1520,14 @@ function getCachedValueFor(obj, key) {
|
|
|
1521
1520
|
become the explicit value of this property.
|
|
1522
1521
|
*/
|
|
1523
1522
|
function defineProperty(obj, keyName, desc, data, _meta) {
|
|
1524
|
-
let meta
|
|
1525
|
-
let previousDesc = descriptorForProperty(obj, keyName, meta
|
|
1523
|
+
let meta$1 = _meta === undefined ? meta(obj) : _meta;
|
|
1524
|
+
let previousDesc = descriptorForProperty(obj, keyName, meta$1);
|
|
1526
1525
|
let wasDescriptor = previousDesc !== undefined;
|
|
1527
1526
|
if (wasDescriptor) {
|
|
1528
|
-
previousDesc.teardown(obj, keyName, meta
|
|
1527
|
+
previousDesc.teardown(obj, keyName, meta$1);
|
|
1529
1528
|
}
|
|
1530
1529
|
if (isClassicDecorator(desc)) {
|
|
1531
|
-
defineDecorator(obj, keyName, desc, meta
|
|
1530
|
+
defineDecorator(obj, keyName, desc, meta$1);
|
|
1532
1531
|
} else if (desc === null || desc === undefined) {
|
|
1533
1532
|
defineValue(obj, keyName, data, wasDescriptor, true);
|
|
1534
1533
|
} else {
|
|
@@ -1537,16 +1536,16 @@ function defineProperty(obj, keyName, desc, data, _meta) {
|
|
|
1537
1536
|
}
|
|
1538
1537
|
// if key is being watched, override chains that
|
|
1539
1538
|
// were initialized with the prototype
|
|
1540
|
-
if (!meta
|
|
1539
|
+
if (!meta$1.isPrototypeMeta(obj)) {
|
|
1541
1540
|
revalidateObservers(obj);
|
|
1542
1541
|
}
|
|
1543
1542
|
}
|
|
1544
|
-
function defineDecorator(obj, keyName, desc, meta
|
|
1543
|
+
function defineDecorator(obj, keyName, desc, meta) {
|
|
1545
1544
|
let propertyDesc;
|
|
1546
1545
|
if (DEBUG) {
|
|
1547
|
-
propertyDesc = desc(obj, keyName, undefined, meta
|
|
1546
|
+
propertyDesc = desc(obj, keyName, undefined, meta, true);
|
|
1548
1547
|
} else {
|
|
1549
|
-
propertyDesc = desc(obj, keyName, undefined, meta
|
|
1548
|
+
propertyDesc = desc(obj, keyName, undefined, meta);
|
|
1550
1549
|
}
|
|
1551
1550
|
Object.defineProperty(obj, keyName, propertyDesc);
|
|
1552
1551
|
// pass the decorator function forward for backwards compat
|
|
@@ -1778,12 +1777,12 @@ class AliasDecoratorImpl extends Function {
|
|
|
1778
1777
|
descriptorForDecorator(this).oneWay();
|
|
1779
1778
|
return this;
|
|
1780
1779
|
}
|
|
1781
|
-
meta(meta
|
|
1780
|
+
meta(meta) {
|
|
1782
1781
|
let prop = descriptorForDecorator(this);
|
|
1783
1782
|
if (arguments.length === 0) {
|
|
1784
1783
|
return prop._meta || {};
|
|
1785
1784
|
} else {
|
|
1786
|
-
prop._meta = meta
|
|
1785
|
+
prop._meta = meta;
|
|
1787
1786
|
}
|
|
1788
1787
|
}
|
|
1789
1788
|
}
|
|
@@ -1792,14 +1791,14 @@ class AliasedProperty extends ComputedDescriptor {
|
|
|
1792
1791
|
super();
|
|
1793
1792
|
this.altKey = altKey;
|
|
1794
1793
|
}
|
|
1795
|
-
setup(obj, keyName, propertyDesc, meta
|
|
1794
|
+
setup(obj, keyName, propertyDesc, meta) {
|
|
1796
1795
|
assert(`Setting alias '${keyName}' on self`, this.altKey !== keyName);
|
|
1797
|
-
super.setup(obj, keyName, propertyDesc, meta
|
|
1796
|
+
super.setup(obj, keyName, propertyDesc, meta);
|
|
1798
1797
|
CHAIN_PASS_THROUGH.add(this);
|
|
1799
1798
|
}
|
|
1800
1799
|
get(obj, keyName) {
|
|
1801
1800
|
let ret;
|
|
1802
|
-
let meta
|
|
1801
|
+
let meta$1 = meta(obj);
|
|
1803
1802
|
let tagMeta = tagMetaFor(obj);
|
|
1804
1803
|
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1805
1804
|
// We don't use the tag since CPs are not automatic, we just want to avoid
|
|
@@ -1807,11 +1806,11 @@ class AliasedProperty extends ComputedDescriptor {
|
|
|
1807
1806
|
untrack(() => {
|
|
1808
1807
|
ret = get(obj, this.altKey);
|
|
1809
1808
|
});
|
|
1810
|
-
let lastRevision = meta
|
|
1809
|
+
let lastRevision = meta$1.revisionFor(keyName);
|
|
1811
1810
|
if (lastRevision === undefined || !validateTag(propertyTag, lastRevision)) {
|
|
1812
|
-
updateTag(propertyTag, getChainTagsForKey(obj, this.altKey, tagMeta, meta
|
|
1813
|
-
meta
|
|
1814
|
-
finishLazyChains(meta
|
|
1811
|
+
updateTag(propertyTag, getChainTagsForKey(obj, this.altKey, tagMeta, meta$1));
|
|
1812
|
+
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1813
|
+
finishLazyChains(meta$1, keyName, ret);
|
|
1815
1814
|
}
|
|
1816
1815
|
consumeTag(propertyTag);
|
|
1817
1816
|
return ret;
|
|
@@ -2056,8 +2055,8 @@ function tracked(...args) {
|
|
|
2056
2055
|
}
|
|
2057
2056
|
let initializer = propertyDesc ? propertyDesc.initializer : undefined;
|
|
2058
2057
|
let value = propertyDesc ? propertyDesc.value : undefined;
|
|
2059
|
-
let decorator = function (target, key, _desc, _meta, isClassicDecorator
|
|
2060
|
-
assert(`You attempted to set a default value for ${key} with the @tracked({ value: 'default' }) syntax. You can only use this syntax with classic classes. For native classes, you can use class initializers: @tracked field = 'default';`, isClassicDecorator
|
|
2058
|
+
let decorator = function (target, key, _desc, _meta, isClassicDecorator) {
|
|
2059
|
+
assert(`You attempted to set a default value for ${key} with the @tracked({ value: 'default' }) syntax. You can only use this syntax with classic classes. For native classes, you can use class initializers: @tracked field = 'default';`, isClassicDecorator);
|
|
2061
2060
|
let fieldDesc = {
|
|
2062
2061
|
initializer: initializer || (() => value)
|
|
2063
2062
|
};
|
|
@@ -2148,125 +2147,6 @@ function throwCachedInvalidArgsError(args = []) {
|
|
|
2148
2147
|
throw new Error(`You attempted to use @cached on with ${args.length > 1 ? 'arguments' : 'an argument'} ( @cached(${args.map(d => `'${d}'`).join(', ')}), which is not supported. Dependencies are automatically tracked, so you can just use ${'`@cached`'}`);
|
|
2149
2148
|
}
|
|
2150
2149
|
|
|
2151
|
-
/**
|
|
2152
|
-
Ember uses caching based on trackable values to avoid updating large portions
|
|
2153
|
-
of the application. This caching is exposed via a cache primitive that can be
|
|
2154
|
-
used to cache a specific computation, so that it will not update and will
|
|
2155
|
-
return the cached value until a tracked value used in its computation has
|
|
2156
|
-
updated.
|
|
2157
|
-
|
|
2158
|
-
@module @glimmer/tracking/primitives/cache
|
|
2159
|
-
@public
|
|
2160
|
-
*/
|
|
2161
|
-
/**
|
|
2162
|
-
Receives a function, and returns a wrapped version of it that memoizes based on
|
|
2163
|
-
_autotracking_. The function will only rerun whenever any tracked values used
|
|
2164
|
-
within it have changed. Otherwise, it will return the previous value.
|
|
2165
|
-
|
|
2166
|
-
```js
|
|
2167
|
-
import { tracked } from '@glimmer/tracking';
|
|
2168
|
-
import { createCache, getValue } from '@glimmer/tracking/primitives/cache';
|
|
2169
|
-
|
|
2170
|
-
class State {
|
|
2171
|
-
@tracked value;
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
let state = new State();
|
|
2175
|
-
let computeCount = 0;
|
|
2176
|
-
|
|
2177
|
-
let counter = createCache(() => {
|
|
2178
|
-
// consume the state. Now, `counter` will
|
|
2179
|
-
// only rerun if `state.value` changes.
|
|
2180
|
-
state.value;
|
|
2181
|
-
|
|
2182
|
-
return ++computeCount;
|
|
2183
|
-
});
|
|
2184
|
-
|
|
2185
|
-
getValue(counter); // 1
|
|
2186
|
-
|
|
2187
|
-
// returns the same value because no tracked state has changed
|
|
2188
|
-
getValue(counter); // 1
|
|
2189
|
-
|
|
2190
|
-
state.value = 'foo';
|
|
2191
|
-
|
|
2192
|
-
// reruns because a tracked value used in the function has changed,
|
|
2193
|
-
// incermenting the counter
|
|
2194
|
-
getValue(counter); // 2
|
|
2195
|
-
```
|
|
2196
|
-
|
|
2197
|
-
@method createCache
|
|
2198
|
-
@static
|
|
2199
|
-
@for @glimmer/tracking/primitives/cache
|
|
2200
|
-
@public
|
|
2201
|
-
*/
|
|
2202
|
-
/**
|
|
2203
|
-
Gets the value of a cache created with `createCache`.
|
|
2204
|
-
|
|
2205
|
-
```js
|
|
2206
|
-
import { tracked } from '@glimmer/tracking';
|
|
2207
|
-
import { createCache, getValue } from '@glimmer/tracking/primitives/cache';
|
|
2208
|
-
|
|
2209
|
-
let computeCount = 0;
|
|
2210
|
-
|
|
2211
|
-
let counter = createCache(() => {
|
|
2212
|
-
return ++computeCount;
|
|
2213
|
-
});
|
|
2214
|
-
|
|
2215
|
-
getValue(counter); // 1
|
|
2216
|
-
```
|
|
2217
|
-
|
|
2218
|
-
@method getValue
|
|
2219
|
-
@static
|
|
2220
|
-
@for @glimmer/tracking/primitives/cache
|
|
2221
|
-
@public
|
|
2222
|
-
*/
|
|
2223
|
-
/**
|
|
2224
|
-
Can be used to check if a memoized function is _constant_. If no tracked state
|
|
2225
|
-
was used while running a memoized function, it will never rerun, because nothing
|
|
2226
|
-
can invalidate its result. `isConst` can be used to determine if a memoized
|
|
2227
|
-
function is constant or not, in order to optimize code surrounding that
|
|
2228
|
-
function.
|
|
2229
|
-
|
|
2230
|
-
```js
|
|
2231
|
-
import { tracked } from '@glimmer/tracking';
|
|
2232
|
-
import { createCache, getValue, isConst } from '@glimmer/tracking/primitives/cache';
|
|
2233
|
-
|
|
2234
|
-
class State {
|
|
2235
|
-
@tracked value;
|
|
2236
|
-
}
|
|
2237
|
-
|
|
2238
|
-
let state = new State();
|
|
2239
|
-
let computeCount = 0;
|
|
2240
|
-
|
|
2241
|
-
let counter = createCache(() => {
|
|
2242
|
-
// consume the state
|
|
2243
|
-
state.value;
|
|
2244
|
-
|
|
2245
|
-
return computeCount++;
|
|
2246
|
-
});
|
|
2247
|
-
|
|
2248
|
-
let constCounter = createCache(() => {
|
|
2249
|
-
return computeCount++;
|
|
2250
|
-
});
|
|
2251
|
-
|
|
2252
|
-
getValue(counter);
|
|
2253
|
-
getValue(constCounter);
|
|
2254
|
-
|
|
2255
|
-
isConst(counter); // false
|
|
2256
|
-
isConst(constCounter); // true
|
|
2257
|
-
```
|
|
2258
|
-
|
|
2259
|
-
If called on a cache that hasn't been accessed yet, it will throw an
|
|
2260
|
-
error. This is because there's no way to know if the function will be constant
|
|
2261
|
-
or not yet, and so this helps prevent missing an optimization opportunity on
|
|
2262
|
-
accident.
|
|
2263
|
-
|
|
2264
|
-
@method isConst
|
|
2265
|
-
@static
|
|
2266
|
-
@for @glimmer/tracking/primitives/cache
|
|
2267
|
-
@public
|
|
2268
|
-
*/
|
|
2269
|
-
|
|
2270
2150
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2271
2151
|
let searchDisabled = false;
|
|
2272
2152
|
const flags = {
|
|
@@ -2396,4 +2276,4 @@ function tryIsNamespace(lookup, prop) {
|
|
|
2396
2276
|
}
|
|
2397
2277
|
}
|
|
2398
2278
|
|
|
2399
|
-
export {
|
|
2279
|
+
export { ASYNC_OBSERVERS, ComputedDescriptor, ComputedProperty, DEBUG_INJECTION_FUNCTIONS, Libraries, NAMESPACES, NAMESPACES_BY_ID, PROPERTY_DID_CHANGE, PROXY_CONTENT, SYNC_OBSERVERS, TrackedDescriptor, _getPath, _getProp, _setProp, activateObserver, addArrayObserver, addListener, addNamespace, addObserver, alias, arrayContentDidChange, arrayContentWillChange, autoComputed, beginPropertyChanges, cached, changeProperties, computed, defineDecorator, defineProperty, defineValue, deprecateProperty, descriptorForDecorator, descriptorForProperty, eachProxyArrayDidChange, eachProxyArrayWillChange, endPropertyChanges, expandProperties, findNamespace, findNamespaces, flushAsyncObservers, get, getCachedValueFor, getProperties, hasListeners, hasUnknownProperty, inject, isClassicDecorator, isComputed, isElementDescriptor, isSearchDisabled as isNamespaceSearchDisabled, LIBRARIES as libraries, makeComputedDecorator, markObjectAsDirty, nativeDescDecorator, notifyPropertyChange, objectAt, on, processAllNamespaces, processNamespace, removeArrayObserver, removeListener, removeNamespace, removeObserver, replace, replaceInNativeArray, revalidateObservers, sendEvent, set, setClassicDecorator, setSearchDisabled as setNamespaceSearchDisabled, setProperties, setUnprocessedMixins, tagForObject, tagForProperty, tracked, trySet };
|