@ember-data/store 5.1.1 → 5.1.2
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 +59 -23
- package/addon/-private.js.map +1 -1
- package/package.json +7 -7
package/addon/-private.js
CHANGED
|
@@ -2664,13 +2664,13 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
2664
2664
|
@type Store
|
|
2665
2665
|
*/
|
|
2666
2666
|
|
|
2667
|
-
destroy() {
|
|
2668
|
-
this.isDestroying =
|
|
2667
|
+
destroy(clear) {
|
|
2668
|
+
this.isDestroying = !clear;
|
|
2669
2669
|
// changing the reference breaks the Proxy
|
|
2670
2670
|
// this[SOURCE] = [];
|
|
2671
2671
|
this[SOURCE].length = 0;
|
|
2672
2672
|
this[NOTIFY]();
|
|
2673
|
-
this.isDestroyed =
|
|
2673
|
+
this.isDestroyed = !clear;
|
|
2674
2674
|
}
|
|
2675
2675
|
|
|
2676
2676
|
// length must be on self for proxied methods to work properly
|
|
@@ -2961,8 +2961,8 @@ class Collection extends IdentifierArray {
|
|
|
2961
2961
|
});
|
|
2962
2962
|
return promise;
|
|
2963
2963
|
}
|
|
2964
|
-
destroy() {
|
|
2965
|
-
super.destroy();
|
|
2964
|
+
destroy(clear) {
|
|
2965
|
+
super.destroy(clear);
|
|
2966
2966
|
this._manager._managed.delete(this);
|
|
2967
2967
|
this._manager._pending.delete(this);
|
|
2968
2968
|
}
|
|
@@ -3060,10 +3060,14 @@ class RecordArrayManager {
|
|
|
3060
3060
|
this._staged = new Map();
|
|
3061
3061
|
this._keyedArrays = new Map();
|
|
3062
3062
|
this._identifiers = new Map();
|
|
3063
|
+
this._set = new Map();
|
|
3064
|
+
this._visibilitySet = new Map();
|
|
3063
3065
|
this._subscription = this.store.notifications.subscribe('resource', (identifier, type) => {
|
|
3064
3066
|
if (type === 'added') {
|
|
3067
|
+
this._visibilitySet.set(identifier, true);
|
|
3065
3068
|
this.identifierAdded(identifier);
|
|
3066
3069
|
} else if (type === 'removed') {
|
|
3070
|
+
this._visibilitySet.set(identifier, false);
|
|
3067
3071
|
this.identifierRemoved(identifier);
|
|
3068
3072
|
} else if (type === 'state') {
|
|
3069
3073
|
this.identifierChanged(identifier);
|
|
@@ -3075,7 +3079,7 @@ class RecordArrayManager {
|
|
|
3075
3079
|
if (!pending || this.isDestroying || this.isDestroyed) {
|
|
3076
3080
|
return;
|
|
3077
3081
|
}
|
|
3078
|
-
sync(array, pending);
|
|
3082
|
+
sync(array, pending, this._set.get(array));
|
|
3079
3083
|
this._pending.delete(array);
|
|
3080
3084
|
}
|
|
3081
3085
|
|
|
@@ -3108,6 +3112,7 @@ class RecordArrayManager {
|
|
|
3108
3112
|
manager: this
|
|
3109
3113
|
});
|
|
3110
3114
|
this._live.set(type, array);
|
|
3115
|
+
this._set.set(array, new Set(identifiers));
|
|
3111
3116
|
}
|
|
3112
3117
|
return array;
|
|
3113
3118
|
}
|
|
@@ -3125,6 +3130,7 @@ class RecordArrayManager {
|
|
|
3125
3130
|
};
|
|
3126
3131
|
let array = new Collection(options);
|
|
3127
3132
|
this._managed.add(array);
|
|
3133
|
+
this._set.set(array, new Set(options.identifiers || []));
|
|
3128
3134
|
if (config.identifiers) {
|
|
3129
3135
|
associate(this._identifiers, array, config.identifiers);
|
|
3130
3136
|
}
|
|
@@ -3196,6 +3202,7 @@ class RecordArrayManager {
|
|
|
3196
3202
|
const old = source.slice();
|
|
3197
3203
|
source.length = 0;
|
|
3198
3204
|
fastPush(source, identifiers);
|
|
3205
|
+
this._set.set(array, new Set(identifiers));
|
|
3199
3206
|
notifyArray(array);
|
|
3200
3207
|
array.meta = payload.meta || null;
|
|
3201
3208
|
array.links = payload.links || null;
|
|
@@ -3233,21 +3240,30 @@ class RecordArrayManager {
|
|
|
3233
3240
|
}
|
|
3234
3241
|
identifierChanged(identifier) {
|
|
3235
3242
|
let newState = this.store._instanceCache.recordIsLoaded(identifier, true);
|
|
3243
|
+
|
|
3244
|
+
// if the change matches the most recent direct added/removed
|
|
3245
|
+
// state, then we can ignore it
|
|
3246
|
+
if (this._visibilitySet.get(identifier) === newState) {
|
|
3247
|
+
return;
|
|
3248
|
+
}
|
|
3236
3249
|
if (newState) {
|
|
3237
3250
|
this.identifierAdded(identifier);
|
|
3238
3251
|
} else {
|
|
3239
3252
|
this.identifierRemoved(identifier);
|
|
3240
3253
|
}
|
|
3241
3254
|
}
|
|
3242
|
-
clear() {
|
|
3243
|
-
this._live.forEach(array => array.destroy());
|
|
3244
|
-
this._managed.forEach(array => array.destroy());
|
|
3255
|
+
clear(isClear = true) {
|
|
3256
|
+
this._live.forEach(array => array.destroy(isClear));
|
|
3257
|
+
this._managed.forEach(array => array.destroy(isClear));
|
|
3245
3258
|
this._managed.clear();
|
|
3246
3259
|
this._identifiers.clear();
|
|
3260
|
+
this._pending.clear();
|
|
3261
|
+
this._set.forEach(set => set.clear());
|
|
3262
|
+
this._visibilitySet.clear();
|
|
3247
3263
|
}
|
|
3248
3264
|
destroy() {
|
|
3249
3265
|
this.isDestroying = true;
|
|
3250
|
-
this.clear();
|
|
3266
|
+
this.clear(false);
|
|
3251
3267
|
this._live.clear();
|
|
3252
3268
|
this.isDestroyed = true;
|
|
3253
3269
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -3276,19 +3292,20 @@ function disassociateIdentifier(ArraysCache, array, identifier) {
|
|
|
3276
3292
|
cache.delete(array);
|
|
3277
3293
|
}
|
|
3278
3294
|
}
|
|
3279
|
-
function sync(array, changes) {
|
|
3295
|
+
function sync(array, changes, arraySet) {
|
|
3280
3296
|
let state = array[SOURCE];
|
|
3281
3297
|
const adds = [];
|
|
3282
3298
|
const removes = [];
|
|
3283
3299
|
changes.forEach((value, key) => {
|
|
3284
3300
|
if (value === 'add') {
|
|
3285
3301
|
// likely we want to keep a Set along-side
|
|
3286
|
-
if (
|
|
3302
|
+
if (arraySet.has(key)) {
|
|
3287
3303
|
return;
|
|
3288
3304
|
}
|
|
3289
3305
|
adds.push(key);
|
|
3306
|
+
arraySet.add(key);
|
|
3290
3307
|
} else {
|
|
3291
|
-
if (
|
|
3308
|
+
if (arraySet.has(key)) {
|
|
3292
3309
|
removes.push(key);
|
|
3293
3310
|
}
|
|
3294
3311
|
}
|
|
@@ -3296,6 +3313,7 @@ function sync(array, changes) {
|
|
|
3296
3313
|
if (removes.length) {
|
|
3297
3314
|
if (removes.length === state.length) {
|
|
3298
3315
|
state.length = 0;
|
|
3316
|
+
arraySet.clear();
|
|
3299
3317
|
// changing the reference breaks the Proxy
|
|
3300
3318
|
// state = array[SOURCE] = [];
|
|
3301
3319
|
} else {
|
|
@@ -3303,6 +3321,7 @@ function sync(array, changes) {
|
|
|
3303
3321
|
const index = state.indexOf(i);
|
|
3304
3322
|
if (index !== -1) {
|
|
3305
3323
|
state.splice(index, 1);
|
|
3324
|
+
arraySet.delete(i);
|
|
3306
3325
|
}
|
|
3307
3326
|
});
|
|
3308
3327
|
}
|
|
@@ -3722,17 +3741,34 @@ class Store extends EmberObject {
|
|
|
3722
3741
|
_run(cb) {
|
|
3723
3742
|
assert(`EmberData should never encounter a nested run`, !this._cbs);
|
|
3724
3743
|
const _cbs = this._cbs = {};
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3744
|
+
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
3745
|
+
try {
|
|
3746
|
+
cb();
|
|
3747
|
+
if (_cbs.coalesce) {
|
|
3748
|
+
_cbs.coalesce();
|
|
3749
|
+
}
|
|
3750
|
+
if (_cbs.sync) {
|
|
3751
|
+
_cbs.sync();
|
|
3752
|
+
}
|
|
3753
|
+
if (_cbs.notify) {
|
|
3754
|
+
_cbs.notify();
|
|
3755
|
+
}
|
|
3756
|
+
} finally {
|
|
3757
|
+
this._cbs = null;
|
|
3758
|
+
}
|
|
3759
|
+
} else {
|
|
3760
|
+
cb();
|
|
3761
|
+
if (_cbs.coalesce) {
|
|
3762
|
+
_cbs.coalesce();
|
|
3763
|
+
}
|
|
3764
|
+
if (_cbs.sync) {
|
|
3765
|
+
_cbs.sync();
|
|
3766
|
+
}
|
|
3767
|
+
if (_cbs.notify) {
|
|
3768
|
+
_cbs.notify();
|
|
3769
|
+
}
|
|
3770
|
+
this._cbs = null;
|
|
3734
3771
|
}
|
|
3735
|
-
this._cbs = null;
|
|
3736
3772
|
}
|
|
3737
3773
|
_join(cb) {
|
|
3738
3774
|
if (this._cbs) {
|