@ember-data/store 5.5.0-alpha.20 → 5.5.0-alpha.22
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/dist/-private.js +2 -1
- package/dist/-private.js.map +1 -1
- package/dist/configure-BfLLW6GY.js +161 -0
- package/dist/configure-BfLLW6GY.js.map +1 -0
- package/dist/configure.js +1 -0
- package/dist/configure.js.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/{request-state-Bue-PTUf.js → request-state-BrADgFy5.js} +310 -100
- package/dist/request-state-BrADgFy5.js.map +1 -0
- package/package.json +19 -11
- package/unstable-preview-types/-private/document.d.ts.map +1 -1
- package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/new-core-tmp/promise-state.d.ts.map +1 -1
- package/unstable-preview-types/-private/new-core-tmp/reactivity/configure.d.ts +92 -0
- package/unstable-preview-types/-private/new-core-tmp/reactivity/configure.d.ts.map +1 -0
- package/unstable-preview-types/-private/new-core-tmp/reactivity/internal.d.ts +172 -0
- package/unstable-preview-types/-private/new-core-tmp/reactivity/internal.d.ts.map +1 -0
- package/unstable-preview-types/-private/new-core-tmp/reactivity/signal.d.ts +32 -0
- package/unstable-preview-types/-private/new-core-tmp/reactivity/signal.d.ts.map +1 -0
- package/unstable-preview-types/-private/new-core-tmp/request-state.d.ts.map +1 -1
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +4 -9
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -1
- package/unstable-preview-types/-private/record-arrays/many-array.d.ts +2 -2
- package/unstable-preview-types/-private/record-arrays/many-array.d.ts.map +1 -1
- package/unstable-preview-types/-private.d.ts +4 -1
- package/unstable-preview-types/-private.d.ts.map +1 -1
- package/unstable-preview-types/configure.d.ts +21 -0
- package/unstable-preview-types/configure.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +4 -0
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/dist/request-state-Bue-PTUf.js.map +0 -1
|
@@ -3,11 +3,9 @@ import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from
|
|
|
3
3
|
import { EnableHydration, SkipCache } from '@warp-drive/core-types/request';
|
|
4
4
|
import { setLogging, getRuntimeConfig } from '@warp-drive/core-types/runtime';
|
|
5
5
|
import { getOrSetGlobal, peekTransient, setTransient } from '@warp-drive/core-types/-private';
|
|
6
|
-
import {
|
|
7
|
-
import { defineSubscription, notifySignal, defineSignal, createSignal, subscribe, createArrayTags, addToTransaction, addTransactionCB } from '@ember-data/tracking/-private';
|
|
6
|
+
import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, w as willSyncFlushWatchers, A as ARRAY_SIGNAL } from "./configure-BfLLW6GY.js";
|
|
8
7
|
import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_IDENTIFIER_BUCKET, DEBUG_CLIENT_ORIGINATED } from '@warp-drive/core-types/identifier';
|
|
9
8
|
import { dasherize } from '@ember-data/request-utils/string';
|
|
10
|
-
import { compat } from '@ember-data/tracking';
|
|
11
9
|
import { getPromiseResult, setPromiseResult } from '@ember-data/request';
|
|
12
10
|
|
|
13
11
|
/**
|
|
@@ -903,9 +901,245 @@ function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
|
903
901
|
return [];
|
|
904
902
|
}
|
|
905
903
|
|
|
904
|
+
/**
|
|
905
|
+
* A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
|
|
906
|
+
* that enables us to store and manage the signal in a universal way.
|
|
907
|
+
*
|
|
908
|
+
* WarpDrive uses signals to manage three separate concepts:
|
|
909
|
+
*
|
|
910
|
+
* - as a `storage` for a value local to the object that we want to be reactive
|
|
911
|
+
* (see `@local` schema field for an example)
|
|
912
|
+
* - as a `gate` for a memoized getter that we want to act as a reactive property
|
|
913
|
+
* but whose value is computed/pulled from a non-reactive source elsewhere
|
|
914
|
+
* and whose latest value is stored in the signal
|
|
915
|
+
* (see `field` schema field for an example)
|
|
916
|
+
* - as a `gate` with a manually managed value updated on pull when `isStale` is true
|
|
917
|
+
*
|
|
918
|
+
*
|
|
919
|
+
* It offers
|
|
920
|
+
*
|
|
921
|
+
* - a non-reactive way to access/update the current value
|
|
922
|
+
* - a non-reactive way to mark the signal as dirtied
|
|
923
|
+
* - a non-reactive way to store content for why the signal was dirtied
|
|
924
|
+
* - access to the underlying Signal(s) in-use
|
|
925
|
+
*
|
|
926
|
+
* For debugging:
|
|
927
|
+
* - the "key" or "name" of the signal
|
|
928
|
+
* - the "object identity" or "context" to which the signal is attached
|
|
929
|
+
*
|
|
930
|
+
* @internal
|
|
931
|
+
*/
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* We attach signals to their context object via
|
|
935
|
+
* a Map attached to the object via this symbol.
|
|
936
|
+
*
|
|
937
|
+
* This allows us to store multiple signals
|
|
938
|
+
* on the same object with smaller memory
|
|
939
|
+
* overhead and no WeakMap lookups.
|
|
940
|
+
*
|
|
941
|
+
* Performance sensitive objects should
|
|
942
|
+
* pre-warm their shape by assigning this
|
|
943
|
+
* during initialization.
|
|
944
|
+
*
|
|
945
|
+
* ```ts
|
|
946
|
+
* initializeSignalStore(obj);
|
|
947
|
+
* ```
|
|
948
|
+
*
|
|
949
|
+
* @internal
|
|
950
|
+
*/
|
|
951
|
+
const Signals = getOrSetGlobal('Signals', Symbol('Signals'));
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* A util that will create a signal store on the object
|
|
955
|
+
* if it does not already exist and returns the associated
|
|
956
|
+
* signal store.
|
|
957
|
+
*
|
|
958
|
+
* @internal
|
|
959
|
+
*/
|
|
960
|
+
function withSignalStore(obj) {
|
|
961
|
+
if (obj[Signals] === undefined) {
|
|
962
|
+
initializeSignalStore(obj);
|
|
963
|
+
}
|
|
964
|
+
return obj[Signals];
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* A util that will create a signal store on the object
|
|
969
|
+
* if it does not already exist.
|
|
970
|
+
*
|
|
971
|
+
* Useful for pre-warming the shape of an object to ensure
|
|
972
|
+
* a key-transition to add it is not required later.
|
|
973
|
+
*
|
|
974
|
+
* @internal
|
|
975
|
+
*/
|
|
976
|
+
function initializeSignalStore(obj) {
|
|
977
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
978
|
+
if (!test) {
|
|
979
|
+
throw new Error(`Signal store already exists on object`);
|
|
980
|
+
}
|
|
981
|
+
})(obj[Signals] === undefined) : {};
|
|
982
|
+
obj[Signals] = new Map();
|
|
983
|
+
}
|
|
984
|
+
function createInternalSignal(signals, obj, key, initialValue) {
|
|
985
|
+
const warpDriveSignal = {
|
|
986
|
+
key,
|
|
987
|
+
context: obj,
|
|
988
|
+
signal: createSignal(obj, key),
|
|
989
|
+
value: initialValue,
|
|
990
|
+
isStale: false
|
|
991
|
+
};
|
|
992
|
+
signals.set(key, warpDriveSignal);
|
|
993
|
+
return warpDriveSignal;
|
|
994
|
+
}
|
|
995
|
+
function getOrCreateInternalSignal(signals, obj, key, initialValue) {
|
|
996
|
+
let signal = peekInternalSignal(signals, key);
|
|
997
|
+
if (!signal) {
|
|
998
|
+
signal = createInternalSignal(signals, obj, key, initialValue);
|
|
999
|
+
}
|
|
1000
|
+
return signal;
|
|
1001
|
+
}
|
|
1002
|
+
function peekInternalSignal(signals, key) {
|
|
1003
|
+
return signals?.get(key);
|
|
1004
|
+
}
|
|
1005
|
+
function consumeInternalSignal(signal) {
|
|
1006
|
+
consumeSignal(signal.signal);
|
|
1007
|
+
}
|
|
1008
|
+
function notifyInternalSignal(signal) {
|
|
1009
|
+
if (signal) {
|
|
1010
|
+
signal.isStale = true;
|
|
1011
|
+
notifySignal(signal.signal);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function entangleSignal(signals, obj, key, initialValue) {
|
|
1015
|
+
let signal = peekInternalSignal(signals, key);
|
|
1016
|
+
if (!signal) {
|
|
1017
|
+
signal = createInternalSignal(signals, obj, key, initialValue);
|
|
1018
|
+
}
|
|
1019
|
+
consumeInternalSignal(signal);
|
|
1020
|
+
return signal;
|
|
1021
|
+
}
|
|
1022
|
+
function createSignalDescriptor(key, intialValue) {
|
|
1023
|
+
return {
|
|
1024
|
+
enumerable: true,
|
|
1025
|
+
configurable: false,
|
|
1026
|
+
get() {
|
|
1027
|
+
const signals = withSignalStore(this);
|
|
1028
|
+
return entangleSignal(signals, this, key, intialValue).value;
|
|
1029
|
+
},
|
|
1030
|
+
set(value) {
|
|
1031
|
+
const signals = withSignalStore(this);
|
|
1032
|
+
const signal = getOrCreateInternalSignal(signals, this, key, intialValue);
|
|
1033
|
+
if (signal.value !== value) {
|
|
1034
|
+
signal.value = value;
|
|
1035
|
+
notifyInternalSignal(signal);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* define an enumerable signal property.
|
|
1043
|
+
*
|
|
1044
|
+
* Akin to Object.defineProperty.
|
|
1045
|
+
*
|
|
1046
|
+
* The signal will be lazily created when accessed and scoped to the
|
|
1047
|
+
* instance of the object.
|
|
1048
|
+
*
|
|
1049
|
+
* @internal
|
|
1050
|
+
*/
|
|
1051
|
+
function defineSignal(obj, key, v) {
|
|
1052
|
+
Object.defineProperty(obj, key, createSignalDescriptor(key, v));
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Define a non-enumerable signal property.
|
|
1057
|
+
*
|
|
1058
|
+
* @internal
|
|
1059
|
+
*/
|
|
1060
|
+
function defineNonEnumerableSignal(obj, key, v) {
|
|
1061
|
+
const desc = createSignalDescriptor(key, v);
|
|
1062
|
+
desc.enumerable = false;
|
|
1063
|
+
Object.defineProperty(obj, key, desc);
|
|
1064
|
+
}
|
|
1065
|
+
function memoized(target, key, descriptor) {
|
|
1066
|
+
// Error on `@memoized()`, `@memoized(...args)`, and `@memoized propName = value;`
|
|
1067
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1068
|
+
if (!test) {
|
|
1069
|
+
throw new Error('You attempted to use @memoized(), which is not necessary nor supported. Remove the parentheses and you will be good to go!');
|
|
1070
|
+
}
|
|
1071
|
+
})(target !== undefined) : {};
|
|
1072
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1073
|
+
if (!test) {
|
|
1074
|
+
throw new Error(`You attempted to use @memoized on with ${arguments.length > 1 ? 'arguments' : 'an argument'} ( @memoized(${Array.from(arguments).map(d => `'${d}'`).join(', ')}), which is not supported. Dependencies are automatically tracked, so you can just use ${'`@memoized`'}`);
|
|
1075
|
+
}
|
|
1076
|
+
})(typeof target === 'object' && typeof key === 'string' && typeof descriptor === 'object' && arguments.length === 3) : {};
|
|
1077
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1078
|
+
if (!test) {
|
|
1079
|
+
throw new Error(`The @memoized decorator must be applied to getters. '${key}' is not a getter.`);
|
|
1080
|
+
}
|
|
1081
|
+
})(typeof descriptor.get === 'function') : {};
|
|
1082
|
+
|
|
1083
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1084
|
+
const getter = descriptor.get;
|
|
1085
|
+
descriptor.get = function () {
|
|
1086
|
+
const signals = withSignalStore(this);
|
|
1087
|
+
let memoSignal = signals.get(key);
|
|
1088
|
+
if (!memoSignal) {
|
|
1089
|
+
memoSignal = createMemo(this, key, getter.bind(this));
|
|
1090
|
+
signals.set(key, memoSignal);
|
|
1091
|
+
}
|
|
1092
|
+
return memoSignal();
|
|
1093
|
+
};
|
|
1094
|
+
return descriptor;
|
|
1095
|
+
}
|
|
1096
|
+
function gate(_target, key, desc) {
|
|
1097
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1098
|
+
const getter = desc.get;
|
|
1099
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1100
|
+
const setter = desc.set;
|
|
1101
|
+
desc.get = function () {
|
|
1102
|
+
const signals = withSignalStore(this);
|
|
1103
|
+
let signal = peekInternalSignal(signals, key);
|
|
1104
|
+
if (!signal) {
|
|
1105
|
+
signal = createInternalSignal(signals, this, key, getter.call(this));
|
|
1106
|
+
} else if (signal.isStale) {
|
|
1107
|
+
signal.isStale = false;
|
|
1108
|
+
signal.value = getter.call(this);
|
|
1109
|
+
}
|
|
1110
|
+
consumeInternalSignal(signal);
|
|
1111
|
+
return signal.value;
|
|
1112
|
+
};
|
|
1113
|
+
if (setter) {
|
|
1114
|
+
desc.set = function (v) {
|
|
1115
|
+
const signals = withSignalStore(this);
|
|
1116
|
+
let signal = peekInternalSignal(signals, key);
|
|
1117
|
+
if (!signal) {
|
|
1118
|
+
// we can't use `v` as initialValue here because setters don't
|
|
1119
|
+
// return the value and the final value may be different
|
|
1120
|
+
// than what the setter was called with.
|
|
1121
|
+
signal = createInternalSignal(signals, this, key, undefined);
|
|
1122
|
+
signal.isStale = true;
|
|
1123
|
+
}
|
|
1124
|
+
setter.call(this, v);
|
|
1125
|
+
// when a gate is set, we do not notify the signal
|
|
1126
|
+
// as its update is controlled externally.
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
return desc;
|
|
1130
|
+
}
|
|
1131
|
+
function defineGate(obj, key, desc) {
|
|
1132
|
+
const options = Object.assign({
|
|
1133
|
+
enumerable: true,
|
|
1134
|
+
configurable: false
|
|
1135
|
+
}, gate(obj, key, desc));
|
|
1136
|
+
Object.defineProperty(obj, key, options);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
906
1139
|
/**
|
|
907
1140
|
* @module @ember-data/store
|
|
908
1141
|
*/
|
|
1142
|
+
|
|
909
1143
|
function urlFromLink(link) {
|
|
910
1144
|
if (typeof link === 'string') return link;
|
|
911
1145
|
return link.href;
|
|
@@ -982,6 +1216,7 @@ class ReactiveDocument {
|
|
|
982
1216
|
this._store = store;
|
|
983
1217
|
this._localCache = localCache;
|
|
984
1218
|
this.identifier = identifier;
|
|
1219
|
+
const signals = withSignalStore(this);
|
|
985
1220
|
|
|
986
1221
|
// TODO if we ever enable auto-cleanup of the cache, we will need to tear this down
|
|
987
1222
|
// in a destroy method
|
|
@@ -991,10 +1226,10 @@ class ReactiveDocument {
|
|
|
991
1226
|
case 'updated':
|
|
992
1227
|
// FIXME in the case of a collection we need to notify it's length
|
|
993
1228
|
// and have it recalc
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1229
|
+
notifyInternalSignal(peekInternalSignal(signals, 'data'));
|
|
1230
|
+
notifyInternalSignal(peekInternalSignal(signals, 'links'));
|
|
1231
|
+
notifyInternalSignal(peekInternalSignal(signals, 'meta'));
|
|
1232
|
+
notifyInternalSignal(peekInternalSignal(signals, 'errors'));
|
|
998
1233
|
break;
|
|
999
1234
|
}
|
|
1000
1235
|
});
|
|
@@ -1121,7 +1356,7 @@ class ReactiveDocument {
|
|
|
1121
1356
|
return data;
|
|
1122
1357
|
}
|
|
1123
1358
|
}
|
|
1124
|
-
|
|
1359
|
+
defineGate(ReactiveDocument.prototype, 'errors', {
|
|
1125
1360
|
get() {
|
|
1126
1361
|
const {
|
|
1127
1362
|
identifier
|
|
@@ -1144,7 +1379,7 @@ defineSubscription(ReactiveDocument.prototype, 'errors', {
|
|
|
1144
1379
|
return 'errors' in doc ? doc.errors : undefined;
|
|
1145
1380
|
}
|
|
1146
1381
|
});
|
|
1147
|
-
|
|
1382
|
+
defineGate(ReactiveDocument.prototype, 'data', {
|
|
1148
1383
|
get() {
|
|
1149
1384
|
const {
|
|
1150
1385
|
identifier,
|
|
@@ -1171,7 +1406,7 @@ defineSubscription(ReactiveDocument.prototype, 'data', {
|
|
|
1171
1406
|
}
|
|
1172
1407
|
}
|
|
1173
1408
|
});
|
|
1174
|
-
|
|
1409
|
+
defineGate(ReactiveDocument.prototype, 'links', {
|
|
1175
1410
|
get() {
|
|
1176
1411
|
const {
|
|
1177
1412
|
identifier
|
|
@@ -1188,7 +1423,7 @@ defineSubscription(ReactiveDocument.prototype, 'links', {
|
|
|
1188
1423
|
return data.links;
|
|
1189
1424
|
}
|
|
1190
1425
|
});
|
|
1191
|
-
|
|
1426
|
+
defineGate(ReactiveDocument.prototype, 'meta', {
|
|
1192
1427
|
get() {
|
|
1193
1428
|
const {
|
|
1194
1429
|
identifier
|
|
@@ -1210,6 +1445,10 @@ defineSubscription(ReactiveDocument.prototype, 'meta', {
|
|
|
1210
1445
|
@module @ember-data/store
|
|
1211
1446
|
*/
|
|
1212
1447
|
|
|
1448
|
+
/**
|
|
1449
|
+
@module @ember-data/store
|
|
1450
|
+
*/
|
|
1451
|
+
|
|
1213
1452
|
/**
|
|
1214
1453
|
A `RecordReference` is a low-level API that allows users and
|
|
1215
1454
|
addon authors to perform meta-operations on a record.
|
|
@@ -2625,10 +2864,6 @@ class CacheManager {
|
|
|
2625
2864
|
function isCacheOperationValue(value) {
|
|
2626
2865
|
return value === 'added' || value === 'state' || value === 'updated' || value === 'removed' || value === 'invalidated';
|
|
2627
2866
|
}
|
|
2628
|
-
function runLoopIsFlushing() {
|
|
2629
|
-
//@ts-expect-error
|
|
2630
|
-
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
2631
|
-
}
|
|
2632
2867
|
function count(label) {
|
|
2633
2868
|
// @ts-expect-error
|
|
2634
2869
|
// eslint-disable-next-line
|
|
@@ -2824,11 +3059,11 @@ class NotificationManager {
|
|
|
2824
3059
|
_scheduleNotify() {
|
|
2825
3060
|
const asyncFlush = this.store._enableAsyncFlush;
|
|
2826
3061
|
if (this._hasFlush) {
|
|
2827
|
-
if (asyncFlush !== false && !
|
|
3062
|
+
if (asyncFlush !== false && !willSyncFlushWatchers()) {
|
|
2828
3063
|
return false;
|
|
2829
3064
|
}
|
|
2830
3065
|
}
|
|
2831
|
-
if (asyncFlush && !
|
|
3066
|
+
if (asyncFlush && !willSyncFlushWatchers()) {
|
|
2832
3067
|
this._hasFlush = true;
|
|
2833
3068
|
return false;
|
|
2834
3069
|
}
|
|
@@ -2891,24 +3126,11 @@ class NotificationManager {
|
|
|
2891
3126
|
*/
|
|
2892
3127
|
|
|
2893
3128
|
const NativeProxy = Proxy;
|
|
2894
|
-
function decorateMethodV2(prototype, prop, decorators) {
|
|
2895
|
-
const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
|
|
2896
|
-
let desc = {
|
|
2897
|
-
...origDesc
|
|
2898
|
-
};
|
|
2899
|
-
for (let decorator of decorators) {
|
|
2900
|
-
desc = decorator(prototype, prop, desc) || desc;
|
|
2901
|
-
}
|
|
2902
|
-
if (desc.initializer !== void 0) {
|
|
2903
|
-
desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
|
|
2904
|
-
desc.initializer = void 0;
|
|
2905
|
-
}
|
|
2906
|
-
Object.defineProperty(prototype, prop, desc);
|
|
2907
|
-
}
|
|
2908
3129
|
|
|
2909
3130
|
/**
|
|
2910
3131
|
@module @ember-data/store
|
|
2911
3132
|
*/
|
|
3133
|
+
|
|
2912
3134
|
const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
|
|
2913
3135
|
const ARRAY_SETTER_METHODS = new Set(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
|
|
2914
3136
|
const SYNC_PROPS = new Set(['[]', 'length', 'links', 'meta']);
|
|
@@ -2921,14 +3143,9 @@ function isArraySetter(prop) {
|
|
|
2921
3143
|
function isSelfProp(self, prop) {
|
|
2922
3144
|
return prop in self;
|
|
2923
3145
|
}
|
|
2924
|
-
const ARRAY_SIGNAL = getOrSetGlobal('#signal', Symbol('#signal'));
|
|
2925
3146
|
const SOURCE = getOrSetGlobal('#source', Symbol('#source'));
|
|
2926
3147
|
const MUTATE = getOrSetGlobal('#update', Symbol('#update'));
|
|
2927
|
-
const NOTIFY = getOrSetGlobal('#notify', Symbol('#notify'));
|
|
2928
3148
|
const IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));
|
|
2929
|
-
function notifyArray(arr) {
|
|
2930
|
-
addToTransaction(arr[ARRAY_SIGNAL]);
|
|
2931
|
-
}
|
|
2932
3149
|
function convertToInt(prop) {
|
|
2933
3150
|
if (typeof prop === 'symbol') return null;
|
|
2934
3151
|
const num = Number(prop);
|
|
@@ -2992,11 +3209,6 @@ class IdentifierArray {
|
|
|
2992
3209
|
isDestroyed = false;
|
|
2993
3210
|
_updatingPromise = null;
|
|
2994
3211
|
identifier;
|
|
2995
|
-
[IS_COLLECTION] = true;
|
|
2996
|
-
[SOURCE];
|
|
2997
|
-
[NOTIFY]() {
|
|
2998
|
-
notifyArray(this);
|
|
2999
|
-
}
|
|
3000
3212
|
|
|
3001
3213
|
/**
|
|
3002
3214
|
The store that created this record array.
|
|
@@ -3010,20 +3222,9 @@ class IdentifierArray {
|
|
|
3010
3222
|
// changing the reference breaks the Proxy
|
|
3011
3223
|
// this[SOURCE] = [];
|
|
3012
3224
|
this[SOURCE].length = 0;
|
|
3013
|
-
this[
|
|
3225
|
+
notifyInternalSignal(this[ARRAY_SIGNAL]);
|
|
3014
3226
|
this.isDestroyed = !clear;
|
|
3015
3227
|
}
|
|
3016
|
-
|
|
3017
|
-
// length must be on self for proxied methods to work properly
|
|
3018
|
-
get length() {
|
|
3019
|
-
return this[SOURCE].length;
|
|
3020
|
-
}
|
|
3021
|
-
static {
|
|
3022
|
-
decorateMethodV2(this.prototype, "length", [compat]);
|
|
3023
|
-
}
|
|
3024
|
-
set length(value) {
|
|
3025
|
-
this[SOURCE].length = value;
|
|
3026
|
-
}
|
|
3027
3228
|
constructor(options) {
|
|
3028
3229
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3029
3230
|
const self = this;
|
|
@@ -3032,10 +3233,13 @@ class IdentifierArray {
|
|
|
3032
3233
|
this._manager = options.manager;
|
|
3033
3234
|
this.identifier = options.identifier || null;
|
|
3034
3235
|
this[SOURCE] = options.identifiers;
|
|
3035
|
-
this[
|
|
3236
|
+
this[IS_COLLECTION] = true;
|
|
3237
|
+
|
|
3238
|
+
// we attach the signal storage to the class
|
|
3239
|
+
// so that its easier to find debugging.
|
|
3240
|
+
const signals = withSignalStore(this);
|
|
3036
3241
|
const store = options.store;
|
|
3037
3242
|
const boundFns = new Map();
|
|
3038
|
-
const _SIGNAL = this[ARRAY_SIGNAL];
|
|
3039
3243
|
const PrivateState = {
|
|
3040
3244
|
links: options.links || null,
|
|
3041
3245
|
meta: options.meta || null
|
|
@@ -3045,31 +3249,36 @@ class IdentifierArray {
|
|
|
3045
3249
|
// when a mutation occurs
|
|
3046
3250
|
// we track all mutations within the call
|
|
3047
3251
|
// and forward them as one
|
|
3048
|
-
|
|
3252
|
+
let _SIGNAL = null;
|
|
3049
3253
|
const proxy = new NativeProxy(this[SOURCE], {
|
|
3050
3254
|
get(target, prop, receiver) {
|
|
3051
3255
|
const index = convertToInt(prop);
|
|
3052
|
-
if (_SIGNAL.
|
|
3256
|
+
if (_SIGNAL.isStale && (index !== null || SYNC_PROPS.has(prop) || isArrayGetter(prop))) {
|
|
3053
3257
|
options.manager._syncArray(receiver);
|
|
3054
|
-
_SIGNAL.
|
|
3055
|
-
_SIGNAL.shouldReset = false;
|
|
3258
|
+
_SIGNAL.isStale = false;
|
|
3056
3259
|
}
|
|
3057
3260
|
if (index !== null) {
|
|
3058
3261
|
const identifier = target[index];
|
|
3059
3262
|
if (!transaction) {
|
|
3060
|
-
|
|
3263
|
+
consumeInternalSignal(_SIGNAL);
|
|
3061
3264
|
}
|
|
3062
3265
|
return identifier && store._instanceCache.getRecord(identifier);
|
|
3063
3266
|
}
|
|
3064
|
-
if (prop ===
|
|
3065
|
-
|
|
3066
|
-
|
|
3267
|
+
if (prop === ARRAY_SIGNAL) {
|
|
3268
|
+
return _SIGNAL;
|
|
3269
|
+
}
|
|
3270
|
+
if (prop === 'length') {
|
|
3271
|
+
return consumeInternalSignal(_SIGNAL), target.length;
|
|
3272
|
+
}
|
|
3273
|
+
if (prop === 'meta') return consumeInternalSignal(_SIGNAL), PrivateState.meta;
|
|
3274
|
+
if (prop === 'links') return consumeInternalSignal(_SIGNAL), PrivateState.links;
|
|
3275
|
+
if (prop === '[]') return consumeInternalSignal(_SIGNAL), receiver;
|
|
3067
3276
|
if (isArrayGetter(prop)) {
|
|
3068
3277
|
let fn = boundFns.get(prop);
|
|
3069
3278
|
if (fn === undefined) {
|
|
3070
3279
|
if (prop === 'forEach') {
|
|
3071
3280
|
fn = function () {
|
|
3072
|
-
|
|
3281
|
+
consumeInternalSignal(_SIGNAL);
|
|
3073
3282
|
transaction = true;
|
|
3074
3283
|
const result = safeForEach(receiver, target, store, arguments[0], arguments[1]);
|
|
3075
3284
|
transaction = false;
|
|
@@ -3077,7 +3286,7 @@ class IdentifierArray {
|
|
|
3077
3286
|
};
|
|
3078
3287
|
} else {
|
|
3079
3288
|
fn = function () {
|
|
3080
|
-
|
|
3289
|
+
consumeInternalSignal(_SIGNAL);
|
|
3081
3290
|
// array functions must run through Reflect to work properly
|
|
3082
3291
|
// binding via other means will not work.
|
|
3083
3292
|
transaction = true;
|
|
@@ -3120,7 +3329,7 @@ class IdentifierArray {
|
|
|
3120
3329
|
return fn;
|
|
3121
3330
|
}
|
|
3122
3331
|
if (isSelfProp(self, prop)) {
|
|
3123
|
-
if (prop ===
|
|
3332
|
+
if (prop === SOURCE) {
|
|
3124
3333
|
return self[prop];
|
|
3125
3334
|
}
|
|
3126
3335
|
let fn = boundFns.get(prop);
|
|
@@ -3128,7 +3337,7 @@ class IdentifierArray {
|
|
|
3128
3337
|
const outcome = self[prop];
|
|
3129
3338
|
if (typeof outcome === 'function') {
|
|
3130
3339
|
fn = function () {
|
|
3131
|
-
|
|
3340
|
+
consumeInternalSignal(_SIGNAL);
|
|
3132
3341
|
// array functions must run through Reflect to work properly
|
|
3133
3342
|
// binding via other means will not work.
|
|
3134
3343
|
return Reflect.apply(outcome, receiver, arguments);
|
|
@@ -3136,7 +3345,7 @@ class IdentifierArray {
|
|
|
3136
3345
|
boundFns.set(prop, fn);
|
|
3137
3346
|
return fn;
|
|
3138
3347
|
}
|
|
3139
|
-
return
|
|
3348
|
+
return consumeInternalSignal(_SIGNAL), outcome;
|
|
3140
3349
|
}
|
|
3141
3350
|
return target[prop];
|
|
3142
3351
|
},
|
|
@@ -3254,8 +3463,10 @@ class IdentifierArray {
|
|
|
3254
3463
|
}
|
|
3255
3464
|
});
|
|
3256
3465
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3466
|
+
|
|
3467
|
+
// we entangle the signal on the returned proxy since that is
|
|
3468
|
+
// the object that other code will be interfacing with.
|
|
3469
|
+
_SIGNAL = entangleSignal(signals, proxy, ARRAY_SIGNAL, undefined);
|
|
3259
3470
|
return proxy;
|
|
3260
3471
|
}
|
|
3261
3472
|
|
|
@@ -3346,7 +3557,7 @@ const desc = {
|
|
|
3346
3557
|
}
|
|
3347
3558
|
}
|
|
3348
3559
|
};
|
|
3349
|
-
compat(desc);
|
|
3560
|
+
// compat(desc);
|
|
3350
3561
|
Object.defineProperty(IdentifierArray.prototype, '[]', desc);
|
|
3351
3562
|
defineSignal(IdentifierArray.prototype, 'isUpdating', false);
|
|
3352
3563
|
class Collection extends IdentifierArray {
|
|
@@ -3419,6 +3630,7 @@ function extractIdentifierFromRecord$2(record) {
|
|
|
3419
3630
|
/**
|
|
3420
3631
|
@module @ember-data/store
|
|
3421
3632
|
*/
|
|
3633
|
+
|
|
3422
3634
|
const FAKE_ARR = getOrSetGlobal('FAKE_ARR', {});
|
|
3423
3635
|
const SLICE_BATCH_SIZE = 1200;
|
|
3424
3636
|
/**
|
|
@@ -3520,9 +3732,11 @@ class RecordArrayManager {
|
|
|
3520
3732
|
|
|
3521
3733
|
// then pull new state if required
|
|
3522
3734
|
if (isRequestArray) {
|
|
3523
|
-
const
|
|
3524
|
-
|
|
3525
|
-
|
|
3735
|
+
const signal = array[ARRAY_SIGNAL];
|
|
3736
|
+
|
|
3737
|
+
// we only need to rebuild the array from cache if a full sync is required
|
|
3738
|
+
// due to notification that the cache has changed
|
|
3739
|
+
if (signal.value === 'cache-sync') {
|
|
3526
3740
|
const doc = this.store.cache.peek(array.identifier);
|
|
3527
3741
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
3528
3742
|
if (!test) {
|
|
@@ -3605,15 +3819,13 @@ class RecordArrayManager {
|
|
|
3605
3819
|
if (array === FAKE_ARR) {
|
|
3606
3820
|
return;
|
|
3607
3821
|
}
|
|
3608
|
-
const
|
|
3609
|
-
if (
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
} else if (delta > 0 && !tag.t) {
|
|
3616
|
-
addTransactionCB(array[NOTIFY]);
|
|
3822
|
+
const signal = array[ARRAY_SIGNAL];
|
|
3823
|
+
if (!signal.isStale || delta > 0) {
|
|
3824
|
+
notifyInternalSignal(signal);
|
|
3825
|
+
|
|
3826
|
+
// when the cache has updated for our array, we need to
|
|
3827
|
+
// do a full rebuild of the array
|
|
3828
|
+
signal.value = shouldSyncFromCache ? 'cache-sync' : 'patch';
|
|
3617
3829
|
}
|
|
3618
3830
|
}
|
|
3619
3831
|
_getPendingFor(identifier, includeManaged, isRemove) {
|
|
@@ -3677,7 +3889,7 @@ class RecordArrayManager {
|
|
|
3677
3889
|
fastPush(source, identifiers);
|
|
3678
3890
|
this._set.set(array, new Set(identifiers));
|
|
3679
3891
|
if (!isCollection(array)) {
|
|
3680
|
-
|
|
3892
|
+
notifyInternalSignal(array[ARRAY_SIGNAL]);
|
|
3681
3893
|
array.meta = payload?.meta || null;
|
|
3682
3894
|
array.links = payload?.links || null;
|
|
3683
3895
|
}
|
|
@@ -6749,9 +6961,7 @@ class RelatedCollection extends IdentifierArray {
|
|
|
6749
6961
|
}
|
|
6750
6962
|
}
|
|
6751
6963
|
notify() {
|
|
6752
|
-
|
|
6753
|
-
signal.shouldReset = true;
|
|
6754
|
-
notifyArray(this);
|
|
6964
|
+
notifyInternalSignal(this[ARRAY_SIGNAL]);
|
|
6755
6965
|
}
|
|
6756
6966
|
|
|
6757
6967
|
/**
|
|
@@ -6917,7 +7127,7 @@ function mutate(collection, mutation, _SIGNAL) {
|
|
|
6917
7127
|
}
|
|
6918
7128
|
})(typeof collection._manager.mutate === 'function') : {};
|
|
6919
7129
|
collection._manager.mutate(mutation);
|
|
6920
|
-
|
|
7130
|
+
notifyInternalSignal(_SIGNAL);
|
|
6921
7131
|
}
|
|
6922
7132
|
const PromiseCache = new WeakMap();
|
|
6923
7133
|
|
|
@@ -7260,17 +7470,17 @@ class RequestLoadingState {
|
|
|
7260
7470
|
this._future.abort();
|
|
7261
7471
|
};
|
|
7262
7472
|
}
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7473
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isPending', true);
|
|
7474
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isStarted', false);
|
|
7475
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isComplete', false);
|
|
7476
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isCancelled', false);
|
|
7477
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isErrored', false);
|
|
7478
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_error', null);
|
|
7479
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_sizeHint', 0);
|
|
7480
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_bytesLoaded', 0);
|
|
7481
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_startTime', 0);
|
|
7482
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_endTime', 0);
|
|
7483
|
+
defineNonEnumerableSignal(RequestLoadingState.prototype, '_lastPacketTime', 0);
|
|
7274
7484
|
|
|
7275
7485
|
/**
|
|
7276
7486
|
* The state of a request in the "pending"
|
|
@@ -7486,4 +7696,4 @@ function getRequestState(future) {
|
|
|
7486
7696
|
}
|
|
7487
7697
|
return state;
|
|
7488
7698
|
}
|
|
7489
|
-
export {
|
|
7699
|
+
export { memoized as A, gate as B, CacheHandler as C, entangleSignal as D, defineSignal as E, defineNonEnumerableSignal as F, Signals as G, peekInternalSignal as H, IdentifierArray as I, withSignalStore as J, notifyInternalSignal as K, consumeInternalSignal as L, MUTATE as M, getOrCreateInternalSignal as N, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, isDocumentIdentifier as f, constructResource as g, coerceId as h, isStableIdentifier as i, ensureStringId as j, Collection as k, SOURCE as l, fastPush as m, removeRecordDataFor as n, setRecordIdentifier as o, peekCache as p, StoreMap as q, recordIdentifierFor as r, storeFor as s, setCacheFor as t, normalizeModelName as u, RelatedCollection as v, log as w, logGroup as x, getPromiseState as y, getRequestState as z };
|