@ember-data/store 4.12.1 → 4.12.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/addon/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { f as AdapterPopulatedRecordArray, C as CacheHandler, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-
|
|
1
|
+
export { f as AdapterPopulatedRecordArray, C as CacheHandler, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-36c7ac56";
|
|
@@ -5,7 +5,7 @@ import { getOwner, setOwner } from '@ember/application';
|
|
|
5
5
|
import EmberObject, { get, set } from '@ember/object';
|
|
6
6
|
import { _backburner } from '@ember/runloop';
|
|
7
7
|
import { tracked } from '@glimmer/tracking';
|
|
8
|
-
import {
|
|
8
|
+
import { addToTransaction, subscribe, addTransactionCB } from '@ember-data/tracking/-private';
|
|
9
9
|
import { tagForProperty } from '@ember/-internals/metal';
|
|
10
10
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
11
11
|
import { compare } from '@ember/utils';
|
|
@@ -200,6 +200,7 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
200
200
|
return document;
|
|
201
201
|
}
|
|
202
202
|
const data = recordArrayManager.createArray({
|
|
203
|
+
type: request.url,
|
|
203
204
|
identifiers: document.data,
|
|
204
205
|
doc: document,
|
|
205
206
|
query: request
|
|
@@ -213,6 +214,7 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
213
214
|
let managed = recordArrayManager._keyedArrays.get(identifier.lid);
|
|
214
215
|
if (!managed) {
|
|
215
216
|
managed = recordArrayManager.createArray({
|
|
217
|
+
type: identifier.lid,
|
|
216
218
|
identifiers: document.data,
|
|
217
219
|
doc: document
|
|
218
220
|
});
|
|
@@ -3856,7 +3858,7 @@ const MUTATE = Symbol('#update');
|
|
|
3856
3858
|
const NOTIFY = Symbol('#notify');
|
|
3857
3859
|
const IS_COLLECTION = Symbol.for('Collection');
|
|
3858
3860
|
function notifyArray(arr) {
|
|
3859
|
-
arr[IDENTIFIER_ARRAY_TAG]
|
|
3861
|
+
addToTransaction(arr[IDENTIFIER_ARRAY_TAG]);
|
|
3860
3862
|
if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
|
|
3861
3863
|
// eslint-disable-next-line
|
|
3862
3864
|
dirtyTag(tagForProperty(arr, 'length'));
|
|
@@ -3877,6 +3879,11 @@ let Tag = (_class = class Tag {
|
|
|
3877
3879
|
|
|
3878
3880
|
constructor() {
|
|
3879
3881
|
_initializerDefineProperty(this, "ref", _descriptor, this);
|
|
3882
|
+
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
3883
|
+
const [arr, prop] = arguments;
|
|
3884
|
+
this._debug_base = arr.constructor.name + ':' + String(arr.modelName);
|
|
3885
|
+
this._debug_prop = prop;
|
|
3886
|
+
}
|
|
3880
3887
|
this.shouldReset = false;
|
|
3881
3888
|
this.t = false;
|
|
3882
3889
|
}
|
|
@@ -3965,13 +3972,13 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
3965
3972
|
@type Store
|
|
3966
3973
|
*/
|
|
3967
3974
|
|
|
3968
|
-
destroy() {
|
|
3969
|
-
this.isDestroying =
|
|
3975
|
+
destroy(clear) {
|
|
3976
|
+
this.isDestroying = !clear;
|
|
3970
3977
|
// changing the reference breaks the Proxy
|
|
3971
3978
|
// this[SOURCE] = [];
|
|
3972
3979
|
this[SOURCE].length = 0;
|
|
3973
3980
|
this[NOTIFY]();
|
|
3974
|
-
this.isDestroyed =
|
|
3981
|
+
this.isDestroyed = !clear;
|
|
3975
3982
|
}
|
|
3976
3983
|
|
|
3977
3984
|
// length must be on self for proxied methods to work properly
|
|
@@ -3996,7 +4003,6 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
3996
4003
|
this.isDestroyed = false;
|
|
3997
4004
|
this._updatingPromise = null;
|
|
3998
4005
|
this[IS_COLLECTION] = true;
|
|
3999
|
-
this[IDENTIFIER_ARRAY_TAG] = new Tag();
|
|
4000
4006
|
this[SOURCE] = void 0;
|
|
4001
4007
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
4002
4008
|
let self = this;
|
|
@@ -4004,6 +4010,8 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
4004
4010
|
this.store = options.store;
|
|
4005
4011
|
this._manager = options.manager;
|
|
4006
4012
|
this[SOURCE] = options.identifiers;
|
|
4013
|
+
// @ts-expect-error
|
|
4014
|
+
this[IDENTIFIER_ARRAY_TAG] = macroCondition(getOwnConfig().env.DEBUG) ? new Tag(this, 'length') : new Tag();
|
|
4007
4015
|
const store = options.store;
|
|
4008
4016
|
const boundFns = new Map();
|
|
4009
4017
|
const _TAG = this[IDENTIFIER_ARRAY_TAG];
|
|
@@ -4316,8 +4324,8 @@ class Collection extends IdentifierArray {
|
|
|
4316
4324
|
}
|
|
4317
4325
|
return promise;
|
|
4318
4326
|
}
|
|
4319
|
-
destroy() {
|
|
4320
|
-
super.destroy();
|
|
4327
|
+
destroy(clear) {
|
|
4328
|
+
super.destroy(clear);
|
|
4321
4329
|
this._manager._managed.delete(this);
|
|
4322
4330
|
this._manager._pending.delete(this);
|
|
4323
4331
|
}
|
|
@@ -4703,10 +4711,14 @@ class RecordArrayManager {
|
|
|
4703
4711
|
this._staged = new Map();
|
|
4704
4712
|
this._keyedArrays = new Map();
|
|
4705
4713
|
this._identifiers = new Map();
|
|
4714
|
+
this._set = new Map();
|
|
4715
|
+
this._visibilitySet = new Map();
|
|
4706
4716
|
this._subscription = this.store.notifications.subscribe('resource', (identifier, type) => {
|
|
4707
4717
|
if (type === 'added') {
|
|
4718
|
+
this._visibilitySet.set(identifier, true);
|
|
4708
4719
|
this.identifierAdded(identifier);
|
|
4709
4720
|
} else if (type === 'removed') {
|
|
4721
|
+
this._visibilitySet.set(identifier, false);
|
|
4710
4722
|
this.identifierRemoved(identifier);
|
|
4711
4723
|
} else if (type === 'state') {
|
|
4712
4724
|
this.identifierChanged(identifier);
|
|
@@ -4718,7 +4730,7 @@ class RecordArrayManager {
|
|
|
4718
4730
|
if (!pending || this.isDestroying || this.isDestroyed) {
|
|
4719
4731
|
return;
|
|
4720
4732
|
}
|
|
4721
|
-
sync(array, pending);
|
|
4733
|
+
sync(array, pending, this._set.get(array));
|
|
4722
4734
|
this._pending.delete(array);
|
|
4723
4735
|
}
|
|
4724
4736
|
|
|
@@ -4751,6 +4763,7 @@ class RecordArrayManager {
|
|
|
4751
4763
|
manager: this
|
|
4752
4764
|
});
|
|
4753
4765
|
this._live.set(type, array);
|
|
4766
|
+
this._set.set(array, new Set(identifiers));
|
|
4754
4767
|
}
|
|
4755
4768
|
return array;
|
|
4756
4769
|
}
|
|
@@ -4768,6 +4781,7 @@ class RecordArrayManager {
|
|
|
4768
4781
|
};
|
|
4769
4782
|
let array = new Collection(options);
|
|
4770
4783
|
this._managed.add(array);
|
|
4784
|
+
this._set.set(array, new Set(options.identifiers || []));
|
|
4771
4785
|
if (config.identifiers) {
|
|
4772
4786
|
associate(this._identifiers, array, config.identifiers);
|
|
4773
4787
|
}
|
|
@@ -4839,6 +4853,7 @@ class RecordArrayManager {
|
|
|
4839
4853
|
const old = source.slice();
|
|
4840
4854
|
source.length = 0;
|
|
4841
4855
|
fastPush(source, identifiers);
|
|
4856
|
+
this._set.set(array, new Set(identifiers));
|
|
4842
4857
|
notifyArray(array);
|
|
4843
4858
|
array.meta = payload.meta || null;
|
|
4844
4859
|
array.links = payload.links || null;
|
|
@@ -4876,21 +4891,30 @@ class RecordArrayManager {
|
|
|
4876
4891
|
}
|
|
4877
4892
|
identifierChanged(identifier) {
|
|
4878
4893
|
let newState = this.store._instanceCache.recordIsLoaded(identifier, true);
|
|
4894
|
+
|
|
4895
|
+
// if the change matches the most recent direct added/removed
|
|
4896
|
+
// state, then we can ignore it
|
|
4897
|
+
if (this._visibilitySet.get(identifier) === newState) {
|
|
4898
|
+
return;
|
|
4899
|
+
}
|
|
4879
4900
|
if (newState) {
|
|
4880
4901
|
this.identifierAdded(identifier);
|
|
4881
4902
|
} else {
|
|
4882
4903
|
this.identifierRemoved(identifier);
|
|
4883
4904
|
}
|
|
4884
4905
|
}
|
|
4885
|
-
clear() {
|
|
4886
|
-
this._live.forEach(array => array.destroy());
|
|
4887
|
-
this._managed.forEach(array => array.destroy());
|
|
4906
|
+
clear(isClear = true) {
|
|
4907
|
+
this._live.forEach(array => array.destroy(isClear));
|
|
4908
|
+
this._managed.forEach(array => array.destroy(isClear));
|
|
4888
4909
|
this._managed.clear();
|
|
4889
4910
|
this._identifiers.clear();
|
|
4911
|
+
this._pending.clear();
|
|
4912
|
+
this._set.forEach(set => set.clear());
|
|
4913
|
+
this._visibilitySet.clear();
|
|
4890
4914
|
}
|
|
4891
4915
|
destroy() {
|
|
4892
4916
|
this.isDestroying = true;
|
|
4893
|
-
this.clear();
|
|
4917
|
+
this.clear(false);
|
|
4894
4918
|
this._live.clear();
|
|
4895
4919
|
this.isDestroyed = true;
|
|
4896
4920
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -4919,19 +4943,20 @@ function disassociateIdentifier(ArraysCache, array, identifier) {
|
|
|
4919
4943
|
cache.delete(array);
|
|
4920
4944
|
}
|
|
4921
4945
|
}
|
|
4922
|
-
function sync(array, changes) {
|
|
4946
|
+
function sync(array, changes, arraySet) {
|
|
4923
4947
|
let state = array[SOURCE];
|
|
4924
4948
|
const adds = [];
|
|
4925
4949
|
const removes = [];
|
|
4926
4950
|
changes.forEach((value, key) => {
|
|
4927
4951
|
if (value === 'add') {
|
|
4928
4952
|
// likely we want to keep a Set along-side
|
|
4929
|
-
if (
|
|
4953
|
+
if (arraySet.has(key)) {
|
|
4930
4954
|
return;
|
|
4931
4955
|
}
|
|
4932
4956
|
adds.push(key);
|
|
4957
|
+
arraySet.add(key);
|
|
4933
4958
|
} else {
|
|
4934
|
-
if (
|
|
4959
|
+
if (arraySet.has(key)) {
|
|
4935
4960
|
removes.push(key);
|
|
4936
4961
|
}
|
|
4937
4962
|
}
|
|
@@ -4939,6 +4964,7 @@ function sync(array, changes) {
|
|
|
4939
4964
|
if (removes.length) {
|
|
4940
4965
|
if (removes.length === state.length) {
|
|
4941
4966
|
state.length = 0;
|
|
4967
|
+
arraySet.clear();
|
|
4942
4968
|
// changing the reference breaks the Proxy
|
|
4943
4969
|
// state = array[SOURCE] = [];
|
|
4944
4970
|
} else {
|
|
@@ -4946,6 +4972,7 @@ function sync(array, changes) {
|
|
|
4946
4972
|
const index = state.indexOf(i);
|
|
4947
4973
|
if (index !== -1) {
|
|
4948
4974
|
state.splice(index, 1);
|
|
4975
|
+
arraySet.delete(i);
|
|
4949
4976
|
}
|
|
4950
4977
|
});
|
|
4951
4978
|
}
|
|
@@ -5329,17 +5356,34 @@ class Store extends EmberObject {
|
|
|
5329
5356
|
_run(cb) {
|
|
5330
5357
|
assert(`EmberData should never encounter a nested run`, !this._cbs);
|
|
5331
5358
|
const _cbs = this._cbs = {};
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5359
|
+
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
5360
|
+
try {
|
|
5361
|
+
cb();
|
|
5362
|
+
if (_cbs.coalesce) {
|
|
5363
|
+
_cbs.coalesce();
|
|
5364
|
+
}
|
|
5365
|
+
if (_cbs.sync) {
|
|
5366
|
+
_cbs.sync();
|
|
5367
|
+
}
|
|
5368
|
+
if (_cbs.notify) {
|
|
5369
|
+
_cbs.notify();
|
|
5370
|
+
}
|
|
5371
|
+
} finally {
|
|
5372
|
+
this._cbs = null;
|
|
5373
|
+
}
|
|
5374
|
+
} else {
|
|
5375
|
+
cb();
|
|
5376
|
+
if (_cbs.coalesce) {
|
|
5377
|
+
_cbs.coalesce();
|
|
5378
|
+
}
|
|
5379
|
+
if (_cbs.sync) {
|
|
5380
|
+
_cbs.sync();
|
|
5381
|
+
}
|
|
5382
|
+
if (_cbs.notify) {
|
|
5383
|
+
_cbs.notify();
|
|
5384
|
+
}
|
|
5385
|
+
this._cbs = null;
|
|
5341
5386
|
}
|
|
5342
|
-
this._cbs = null;
|
|
5343
5387
|
}
|
|
5344
5388
|
_join(cb) {
|
|
5345
5389
|
if (this._cbs) {
|
|
@@ -6726,12 +6770,11 @@ class Store extends EmberObject {
|
|
|
6726
6770
|
// during unload
|
|
6727
6771
|
if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
|
|
6728
6772
|
const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
|
|
6729
|
-
|
|
6773
|
+
const graph = peekGraph(this);
|
|
6730
6774
|
if (graph) {
|
|
6731
6775
|
graph.identifiers.clear();
|
|
6732
6776
|
}
|
|
6733
6777
|
}
|
|
6734
|
-
this.notifications.destroy();
|
|
6735
6778
|
this.recordArrayManager.clear();
|
|
6736
6779
|
this._instanceCache.clear();
|
|
6737
6780
|
} else {
|
|
@@ -7289,6 +7332,7 @@ class Store extends EmberObject {
|
|
|
7289
7332
|
graph.destroy();
|
|
7290
7333
|
}
|
|
7291
7334
|
}
|
|
7335
|
+
this.notifications.destroy();
|
|
7292
7336
|
this.recordArrayManager.destroy();
|
|
7293
7337
|
this.identifierCache.destroy();
|
|
7294
7338
|
this.unloadAll();
|