@legendapp/state 3.0.0-alpha.1 → 3.0.0-alpha.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/.DS_Store +0 -0
- package/CHANGELOG.md +1 -831
- package/LICENSE +1 -21
- package/README.md +1 -141
- package/as/arrayAsRecord.d.mts +5 -0
- package/as/arrayAsRecord.d.ts +5 -0
- package/as/arrayAsRecord.js +28 -0
- package/as/arrayAsRecord.mjs +26 -0
- package/as/arrayAsSet.d.mts +5 -0
- package/as/arrayAsSet.d.ts +5 -0
- package/as/arrayAsSet.js +13 -0
- package/as/arrayAsSet.mjs +11 -0
- package/as/arrayAsString.d.mts +5 -0
- package/as/arrayAsString.d.ts +5 -0
- package/as/arrayAsString.js +13 -0
- package/as/arrayAsString.mjs +11 -0
- package/as/numberAsString.d.mts +5 -0
- package/as/numberAsString.d.ts +5 -0
- package/as/numberAsString.js +13 -0
- package/as/numberAsString.mjs +11 -0
- package/as/recordAsArray.d.mts +5 -0
- package/as/recordAsArray.d.ts +5 -0
- package/as/recordAsArray.js +25 -0
- package/as/recordAsArray.mjs +23 -0
- package/as/recordAsString.d.mts +5 -0
- package/as/recordAsString.d.ts +5 -0
- package/as/recordAsString.js +13 -0
- package/as/recordAsString.mjs +11 -0
- package/as/setAsArray.d.mts +5 -0
- package/as/setAsArray.d.ts +5 -0
- package/as/setAsArray.js +13 -0
- package/as/setAsArray.mjs +11 -0
- package/as/setAsString.d.mts +5 -0
- package/as/setAsString.d.ts +5 -0
- package/as/setAsString.js +13 -0
- package/as/setAsString.mjs +11 -0
- package/as/stringAsArray.d.mts +5 -0
- package/as/stringAsArray.d.ts +5 -0
- package/as/stringAsArray.js +13 -0
- package/as/stringAsArray.mjs +11 -0
- package/as/stringAsNumber.d.mts +5 -0
- package/as/stringAsNumber.d.ts +5 -0
- package/as/stringAsNumber.js +16 -0
- package/as/stringAsNumber.mjs +14 -0
- package/as/stringAsRecord.d.mts +5 -0
- package/as/stringAsRecord.d.ts +5 -0
- package/as/stringAsRecord.js +15 -0
- package/as/stringAsRecord.mjs +13 -0
- package/as/stringAsSet.d.mts +5 -0
- package/as/stringAsSet.d.ts +5 -0
- package/as/stringAsSet.js +13 -0
- package/as/stringAsSet.mjs +11 -0
- package/babel.d.mts +21 -0
- package/babel.d.ts +21 -2
- package/babel.js +57 -53
- package/babel.mjs +65 -0
- package/config/enable$GetSet.js +13 -14
- package/config/enable$GetSet.mjs +13 -14
- package/config/enableReactComponents.d.mts +9 -0
- package/config/enableReactComponents.d.ts +4 -2
- package/config/enableReactComponents.js +13 -10
- package/config/enableReactComponents.mjs +13 -10
- package/config/enableReactNativeComponents.d.mts +22 -0
- package/config/enableReactNativeComponents.d.ts +6 -4
- package/config/enableReactNativeComponents.js +43 -47
- package/config/enableReactNativeComponents.mjs +43 -47
- package/config/enableReactTracking.d.mts +7 -0
- package/config/enableReactTracking.d.ts +3 -2
- package/config/enableReactTracking.js +33 -38
- package/config/enableReactTracking.mjs +33 -38
- package/config/enableReactUse.d.mts +10 -0
- package/config/enableReactUse.d.ts +4 -1
- package/config/enableReactUse.js +15 -14
- package/config/enableReactUse.mjs +15 -14
- package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
- package/config/enable_GetSet.d.ts +10 -0
- package/config/enable_PeekAssign.d.mts +10 -0
- package/config/enable_PeekAssign.d.ts +4 -2
- package/config/enable_PeekAssign.js +13 -14
- package/config/enable_PeekAssign.mjs +13 -14
- package/helpers/pageHash.d.mts +9 -0
- package/helpers/pageHash.d.ts +2 -0
- package/helpers/pageHash.js +25 -30
- package/helpers/pageHash.mjs +25 -30
- package/helpers/pageHashParams.d.mts +9 -0
- package/helpers/pageHashParams.d.ts +2 -0
- package/helpers/pageHashParams.js +34 -37
- package/helpers/pageHashParams.mjs +34 -37
- package/helpers/time.d.mts +6 -0
- package/helpers/time.d.ts +6 -3
- package/helpers/time.js +17 -17
- package/helpers/time.mjs +17 -17
- package/helpers/trackHistory.d.mts +6 -0
- package/helpers/trackHistory.d.ts +4 -2
- package/helpers/trackHistory.js +13 -16
- package/helpers/trackHistory.mjs +13 -16
- package/helpers/undoRedo.d.mts +37 -0
- package/helpers/undoRedo.d.ts +5 -3
- package/helpers/undoRedo.js +59 -94
- package/helpers/undoRedo.mjs +59 -94
- package/index.d.mts +404 -0
- package/index.d.ts +371 -28
- package/index.js +2015 -2166
- package/index.mjs +2015 -2166
- package/package.json +254 -195
- package/persist-plugins/async-storage.d.mts +18 -0
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +79 -86
- package/persist-plugins/async-storage.mjs +79 -86
- package/persist-plugins/indexeddb.d.mts +29 -0
- package/persist-plugins/indexeddb.d.ts +6 -3
- package/persist-plugins/indexeddb.js +331 -352
- package/persist-plugins/indexeddb.mjs +331 -352
- package/persist-plugins/local-storage.d.mts +23 -0
- package/persist-plugins/local-storage.d.ts +8 -5
- package/persist-plugins/local-storage.js +74 -76
- package/persist-plugins/local-storage.mjs +74 -76
- package/persist-plugins/mmkv.d.mts +18 -0
- package/persist-plugins/mmkv.d.ts +6 -3
- package/persist-plugins/mmkv.js +82 -86
- package/persist-plugins/mmkv.mjs +82 -86
- package/react-hooks/createObservableHook.d.mts +5 -0
- package/react-hooks/createObservableHook.d.ts +4 -1
- package/react-hooks/createObservableHook.js +29 -30
- package/react-hooks/createObservableHook.mjs +25 -30
- package/react-hooks/useHover.d.mts +5 -0
- package/react-hooks/useHover.d.ts +5 -3
- package/react-hooks/useHover.js +29 -29
- package/react-hooks/useHover.mjs +29 -29
- package/react-hooks/useMeasure.d.mts +9 -0
- package/react-hooks/useMeasure.d.ts +5 -2
- package/react-hooks/useMeasure.js +30 -32
- package/react-hooks/useMeasure.mjs +30 -32
- package/react-hooks/useObservableNextRouter.d.mts +35 -0
- package/react-hooks/useObservableNextRouter.d.ts +9 -7
- package/react-hooks/useObservableNextRouter.js +64 -77
- package/react-hooks/useObservableNextRouter.mjs +60 -77
- package/react.d.mts +157 -0
- package/react.d.ts +157 -21
- package/react.js +458 -749
- package/react.mjs +457 -752
- package/sync-plugins/crud.d.mts +54 -0
- package/sync-plugins/crud.d.ts +12 -10
- package/sync-plugins/crud.js +253 -270
- package/sync-plugins/crud.mjs +253 -270
- package/sync-plugins/fetch.d.mts +21 -0
- package/sync-plugins/fetch.d.ts +7 -4
- package/sync-plugins/fetch.js +50 -37
- package/sync-plugins/fetch.mjs +50 -37
- package/sync-plugins/keel.d.mts +108 -0
- package/sync-plugins/keel.d.ts +17 -15
- package/sync-plugins/keel.js +229 -462
- package/sync-plugins/keel.mjs +227 -464
- package/sync-plugins/supabase.d.mts +39 -0
- package/sync-plugins/supabase.d.ts +16 -14
- package/sync-plugins/supabase.js +128 -128
- package/sync-plugins/supabase.mjs +128 -128
- package/sync-plugins/tanstack-query.d.mts +14 -0
- package/sync-plugins/tanstack-query.d.ts +7 -4
- package/sync-plugins/tanstack-query.js +51 -57
- package/sync-plugins/tanstack-query.mjs +51 -57
- package/sync-plugins/tanstack-react-query.d.mts +8 -0
- package/sync-plugins/tanstack-react-query.d.ts +6 -1
- package/sync-plugins/tanstack-react-query.js +2 -2
- package/sync-plugins/tanstack-react-query.mjs +2 -2
- package/sync.d.mts +351 -0
- package/sync.d.ts +349 -9
- package/sync.js +910 -964
- package/sync.mjs +920 -974
- package/trace.d.mts +9 -0
- package/trace.d.ts +9 -4
- package/trace.js +72 -62
- package/trace.mjs +72 -62
- package/types/babel.d.ts +1 -12
- package/babel.js.map +0 -1
- package/config/enable$GetSet.js.map +0 -1
- package/config/enable$GetSet.mjs.map +0 -1
- package/config/enableReactComponents.js.map +0 -1
- package/config/enableReactComponents.mjs.map +0 -1
- package/config/enableReactNativeComponents.js.map +0 -1
- package/config/enableReactNativeComponents.mjs.map +0 -1
- package/config/enableReactTracking.js.map +0 -1
- package/config/enableReactTracking.mjs.map +0 -1
- package/config/enableReactUse.js.map +0 -1
- package/config/enableReactUse.mjs.map +0 -1
- package/config/enable_PeekAssign.js.map +0 -1
- package/config/enable_PeekAssign.mjs.map +0 -1
- package/helpers/pageHash.js.map +0 -1
- package/helpers/pageHash.mjs.map +0 -1
- package/helpers/pageHashParams.js.map +0 -1
- package/helpers/pageHashParams.mjs.map +0 -1
- package/helpers/time.js.map +0 -1
- package/helpers/time.mjs.map +0 -1
- package/helpers/trackHistory.js.map +0 -1
- package/helpers/trackHistory.mjs.map +0 -1
- package/helpers/undoRedo.js.map +0 -1
- package/helpers/undoRedo.mjs.map +0 -1
- package/history.d.ts +0 -1
- package/history.js +0 -24
- package/history.js.map +0 -1
- package/history.mjs +0 -22
- package/history.mjs.map +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/persist-plugins/async-storage.js.map +0 -1
- package/persist-plugins/async-storage.mjs.map +0 -1
- package/persist-plugins/indexeddb.js.map +0 -1
- package/persist-plugins/indexeddb.mjs.map +0 -1
- package/persist-plugins/local-storage.js.map +0 -1
- package/persist-plugins/local-storage.mjs.map +0 -1
- package/persist-plugins/mmkv.js.map +0 -1
- package/persist-plugins/mmkv.mjs.map +0 -1
- package/react-hooks/createObservableHook.js.map +0 -1
- package/react-hooks/createObservableHook.mjs.map +0 -1
- package/react-hooks/useHover.js.map +0 -1
- package/react-hooks/useHover.mjs.map +0 -1
- package/react-hooks/useMeasure.js.map +0 -1
- package/react-hooks/useMeasure.mjs.map +0 -1
- package/react-hooks/useObservableNextRouter.js.map +0 -1
- package/react-hooks/useObservableNextRouter.mjs.map +0 -1
- package/react.js.map +0 -1
- package/react.mjs.map +0 -1
- package/src/ObservableObject.ts +0 -1350
- package/src/ObservablePrimitive.ts +0 -62
- package/src/babel/index.ts +0 -83
- package/src/batching.ts +0 -357
- package/src/computed.ts +0 -18
- package/src/config/enable$GetSet.ts +0 -30
- package/src/config/enableReactComponents.ts +0 -26
- package/src/config/enableReactNativeComponents.ts +0 -102
- package/src/config/enableReactTracking.ts +0 -62
- package/src/config/enableReactUse.ts +0 -32
- package/src/config/enable_PeekAssign.ts +0 -31
- package/src/config.ts +0 -47
- package/src/createObservable.ts +0 -47
- package/src/event.ts +0 -26
- package/src/globals.ts +0 -235
- package/src/helpers/pageHash.ts +0 -41
- package/src/helpers/pageHashParams.ts +0 -55
- package/src/helpers/time.ts +0 -30
- package/src/helpers/trackHistory.ts +0 -29
- package/src/helpers/undoRedo.ts +0 -111
- package/src/helpers.ts +0 -231
- package/src/is.ts +0 -63
- package/src/linked.ts +0 -17
- package/src/observable.ts +0 -32
- package/src/observableInterfaces.ts +0 -151
- package/src/observableTypes.ts +0 -232
- package/src/observe.ts +0 -89
- package/src/old-plugins/firebase.ts +0 -1053
- package/src/onChange.ts +0 -146
- package/src/persist/configureObservablePersistence.ts +0 -7
- package/src/persist/fieldTransformer.ts +0 -149
- package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
- package/src/persist/persistObservable.ts +0 -1034
- package/src/persist-plugins/async-storage.ts +0 -99
- package/src/persist-plugins/indexeddb.ts +0 -439
- package/src/persist-plugins/local-storage.ts +0 -86
- package/src/persist-plugins/mmkv.ts +0 -91
- package/src/proxy.ts +0 -28
- package/src/react/Computed.tsx +0 -8
- package/src/react/For.tsx +0 -116
- package/src/react/Memo.tsx +0 -4
- package/src/react/Reactive.tsx +0 -53
- package/src/react/Show.tsx +0 -33
- package/src/react/Switch.tsx +0 -43
- package/src/react/react-globals.ts +0 -3
- package/src/react/reactInterfaces.ts +0 -32
- package/src/react/reactive-observer.tsx +0 -210
- package/src/react/useComputed.ts +0 -36
- package/src/react/useEffectOnce.ts +0 -41
- package/src/react/useIsMounted.ts +0 -16
- package/src/react/useMount.ts +0 -15
- package/src/react/useObservable.ts +0 -24
- package/src/react/useObservableReducer.ts +0 -52
- package/src/react/useObservableState.ts +0 -30
- package/src/react/useObserve.ts +0 -54
- package/src/react/useObserveEffect.ts +0 -40
- package/src/react/usePauseProvider.tsx +0 -16
- package/src/react/useSelector.ts +0 -167
- package/src/react/useUnmount.ts +0 -8
- package/src/react/useWhen.ts +0 -9
- package/src/react-hooks/createObservableHook.ts +0 -53
- package/src/react-hooks/useHover.ts +0 -40
- package/src/react-hooks/useMeasure.ts +0 -48
- package/src/react-hooks/useObservableNextRouter.ts +0 -137
- package/src/retry.ts +0 -71
- package/src/setupTracking.ts +0 -26
- package/src/sync/activateSyncedNode.ts +0 -128
- package/src/sync/configureObservableSync.ts +0 -7
- package/src/sync/persistTypes.ts +0 -216
- package/src/sync/syncHelpers.ts +0 -180
- package/src/sync/syncObservable.ts +0 -1056
- package/src/sync/syncObservableAdapter.ts +0 -31
- package/src/sync/syncTypes.ts +0 -189
- package/src/sync/synced.ts +0 -21
- package/src/sync-plugins/crud.ts +0 -412
- package/src/sync-plugins/fetch.ts +0 -80
- package/src/sync-plugins/keel.ts +0 -495
- package/src/sync-plugins/supabase.ts +0 -249
- package/src/sync-plugins/tanstack-query.ts +0 -113
- package/src/sync-plugins/tanstack-react-query.ts +0 -12
- package/src/trace/traceHelpers.ts +0 -11
- package/src/trace/useTraceListeners.ts +0 -34
- package/src/trace/useTraceUpdates.ts +0 -24
- package/src/trace/useVerifyNotTracking.ts +0 -33
- package/src/trace/useVerifyOneRender.ts +0 -10
- package/src/trackSelector.ts +0 -52
- package/src/tracking.ts +0 -43
- package/src/types/babel.d.ts +0 -12
- package/src/when.ts +0 -75
- package/sync-plugins/crud.js.map +0 -1
- package/sync-plugins/crud.mjs.map +0 -1
- package/sync-plugins/fetch.js.map +0 -1
- package/sync-plugins/fetch.mjs.map +0 -1
- package/sync-plugins/keel.js.map +0 -1
- package/sync-plugins/keel.mjs.map +0 -1
- package/sync-plugins/supabase.js.map +0 -1
- package/sync-plugins/supabase.mjs.map +0 -1
- package/sync-plugins/tanstack-query.js.map +0 -1
- package/sync-plugins/tanstack-query.mjs.map +0 -1
- package/sync-plugins/tanstack-react-query.js.map +0 -1
- package/sync-plugins/tanstack-react-query.mjs.map +0 -1
- package/sync.js.map +0 -1
- package/sync.mjs.map +0 -1
- package/trace.js.map +0 -1
- package/trace.mjs.map +0 -1
package/index.mjs
CHANGED
|
@@ -1,2455 +1,2304 @@
|
|
|
1
|
-
|
|
1
|
+
// src/is.ts
|
|
2
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2
3
|
function isArray(obj) {
|
|
3
|
-
|
|
4
|
+
return Array.isArray(obj);
|
|
4
5
|
}
|
|
5
6
|
function isString(obj) {
|
|
6
|
-
|
|
7
|
+
return typeof obj === "string";
|
|
7
8
|
}
|
|
8
9
|
function isObject(obj) {
|
|
9
|
-
|
|
10
|
+
return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isArray(obj);
|
|
10
11
|
}
|
|
11
12
|
function isFunction(obj) {
|
|
12
|
-
|
|
13
|
+
return typeof obj === "function";
|
|
13
14
|
}
|
|
14
15
|
function isPrimitive(arg) {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const type = typeof arg;
|
|
17
|
+
return arg !== void 0 && (isDate(arg) || type !== "object" && type !== "function");
|
|
17
18
|
}
|
|
18
19
|
function isDate(obj) {
|
|
19
|
-
|
|
20
|
+
return obj instanceof Date;
|
|
20
21
|
}
|
|
21
22
|
function isSymbol(obj) {
|
|
22
|
-
|
|
23
|
+
return typeof obj === "symbol";
|
|
23
24
|
}
|
|
24
25
|
function isBoolean(obj) {
|
|
25
|
-
|
|
26
|
+
return typeof obj === "boolean";
|
|
26
27
|
}
|
|
27
28
|
function isPromise(obj) {
|
|
28
|
-
|
|
29
|
+
return obj instanceof Promise;
|
|
29
30
|
}
|
|
30
31
|
function isMap(obj) {
|
|
31
|
-
|
|
32
|
+
return obj instanceof Map;
|
|
32
33
|
}
|
|
33
34
|
function isNumber(obj) {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const n = obj;
|
|
36
|
+
return n - n < 1;
|
|
36
37
|
}
|
|
37
38
|
function isEmpty(obj) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (hasOwnProperty.call(obj, key)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
39
|
+
if (!obj)
|
|
40
|
+
return false;
|
|
41
|
+
if (isArray(obj))
|
|
42
|
+
return obj.length === 0;
|
|
43
|
+
for (const key in obj) {
|
|
44
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
45
|
+
return false;
|
|
48
46
|
}
|
|
49
|
-
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
50
49
|
}
|
|
51
50
|
function isNullOrUndefined(value) {
|
|
52
|
-
|
|
51
|
+
return value === void 0 || value === null;
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
/** @internal */
|
|
53
|
+
var setPrimitives = /* @__PURE__ */ new Set(["boolean", "string", "number"]);
|
|
56
54
|
function isActualPrimitive(arg) {
|
|
57
|
-
|
|
55
|
+
return setPrimitives.has(typeof arg);
|
|
58
56
|
}
|
|
59
|
-
/** @internal */
|
|
60
57
|
function isChildNodeValue(node) {
|
|
61
|
-
|
|
58
|
+
return !!node.parent;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
// src/globals.ts
|
|
62
|
+
var symbolToPrimitive = Symbol.toPrimitive;
|
|
63
|
+
var symbolGetNode = Symbol("getNode");
|
|
64
|
+
var symbolDelete = /* @__PURE__ */ Symbol("delete");
|
|
65
|
+
var symbolOpaque = Symbol("opaque");
|
|
66
|
+
var optimized = Symbol("optimized");
|
|
67
|
+
var symbolLinked = Symbol("linked");
|
|
68
|
+
var globalState = {
|
|
69
|
+
isLoadingLocal: false,
|
|
70
|
+
isMerging: false,
|
|
71
|
+
isLoadingRemote: false,
|
|
72
|
+
activateSyncedNode: void 0,
|
|
73
|
+
pendingNodes: /* @__PURE__ */ new Map(),
|
|
74
|
+
dirtyNodes: /* @__PURE__ */ new Set(),
|
|
75
|
+
replacer: void 0,
|
|
76
|
+
reviver: void 0
|
|
79
77
|
};
|
|
80
78
|
function getPathType(value) {
|
|
81
|
-
|
|
79
|
+
return isArray(value) ? "array" : isMap(value) ? "map" : value instanceof Set ? "set" : "object";
|
|
82
80
|
}
|
|
83
81
|
function replacer(key, value) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
82
|
+
if (isMap(value)) {
|
|
83
|
+
return {
|
|
84
|
+
__LSType: "Map",
|
|
85
|
+
value: Array.from(value.entries())
|
|
86
|
+
// or with spread: value: [...value]
|
|
87
|
+
};
|
|
88
|
+
} else if (value instanceof Set) {
|
|
89
|
+
return {
|
|
90
|
+
__LSType: "Set",
|
|
91
|
+
value: Array.from(value)
|
|
92
|
+
// or with spread: value: [...value]
|
|
93
|
+
};
|
|
94
|
+
} else if (globalState.replacer) {
|
|
95
|
+
value = globalState.replacer(key, value);
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
100
98
|
}
|
|
101
|
-
|
|
99
|
+
var ISO8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
|
102
100
|
function reviver(key, value) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
if (typeof value === 'object') {
|
|
108
|
-
if (value.__LSType === 'Map') {
|
|
109
|
-
return new Map(value.value);
|
|
110
|
-
}
|
|
111
|
-
else if (value.__LSType === 'Set') {
|
|
112
|
-
return new Set(value.value);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (globalState.reviver) {
|
|
116
|
-
value = globalState.reviver(key, value);
|
|
117
|
-
}
|
|
101
|
+
if (value) {
|
|
102
|
+
if (typeof value === "string" && ISO8601.test(value)) {
|
|
103
|
+
return new Date(value);
|
|
118
104
|
}
|
|
119
|
-
|
|
105
|
+
if (typeof value === "object") {
|
|
106
|
+
if (value.__LSType === "Map") {
|
|
107
|
+
return new Map(value.value);
|
|
108
|
+
} else if (value.__LSType === "Set") {
|
|
109
|
+
return new Set(value.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (globalState.reviver) {
|
|
113
|
+
value = globalState.reviver(key, value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
120
117
|
}
|
|
121
118
|
function safeStringify(value) {
|
|
122
|
-
|
|
119
|
+
return JSON.stringify(value, replacer);
|
|
123
120
|
}
|
|
124
121
|
function safeParse(value) {
|
|
125
|
-
|
|
122
|
+
return JSON.parse(value, reviver);
|
|
126
123
|
}
|
|
127
124
|
function clone(value) {
|
|
128
|
-
|
|
125
|
+
return safeParse(safeStringify(value));
|
|
129
126
|
}
|
|
130
127
|
function isObservable(value$) {
|
|
131
|
-
|
|
128
|
+
return !!value$ && !!value$[symbolGetNode];
|
|
132
129
|
}
|
|
133
130
|
function getNode(value$) {
|
|
134
|
-
|
|
131
|
+
return value$ && value$[symbolGetNode];
|
|
135
132
|
}
|
|
136
133
|
function isEvent(value$) {
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
var _a;
|
|
135
|
+
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
139
136
|
}
|
|
140
137
|
function setNodeValue(node, newValue) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
parentValue[key] = newValue;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
finally {
|
|
181
|
-
parentNode.isSetting--;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return { prevValue, newValue };
|
|
185
|
-
}
|
|
186
|
-
const arrNodeKeys = [];
|
|
138
|
+
var _a, _b, _c;
|
|
139
|
+
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
140
|
+
const key = node.parent ? node.key : "_";
|
|
141
|
+
const isDelete = newValue === symbolDelete;
|
|
142
|
+
if (isDelete)
|
|
143
|
+
newValue = void 0;
|
|
144
|
+
const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
|
|
145
|
+
const prevValue = parentValue[key];
|
|
146
|
+
const isFunc = isFunction(newValue);
|
|
147
|
+
newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
|
|
148
|
+
if (!globalState.isMerging || isNullOrUndefined(prevValue) || isFunction(prevValue) || !((_c = (_b = node.parent) == null ? void 0 : _b.functions) == null ? void 0 : _c.get(key))) {
|
|
149
|
+
try {
|
|
150
|
+
parentNode.isSetting = (parentNode.isSetting || 0) + 1;
|
|
151
|
+
const useMapFn = isMap(parentValue);
|
|
152
|
+
if (isDelete) {
|
|
153
|
+
if (useMapFn) {
|
|
154
|
+
parentValue.delete(key);
|
|
155
|
+
} else {
|
|
156
|
+
delete parentValue[key];
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
const useMapFn2 = isMap(parentValue);
|
|
160
|
+
if (useMapFn2) {
|
|
161
|
+
parentValue.set(key, newValue);
|
|
162
|
+
} else {
|
|
163
|
+
parentValue[key] = newValue;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} finally {
|
|
167
|
+
parentNode.isSetting--;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { prevValue, newValue };
|
|
171
|
+
}
|
|
172
|
+
var arrNodeKeys = [];
|
|
187
173
|
function getNodeValue(node) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
174
|
+
let count = 0;
|
|
175
|
+
let n = node;
|
|
176
|
+
while (isChildNodeValue(n)) {
|
|
177
|
+
arrNodeKeys[count++] = n.key;
|
|
178
|
+
n = n.parent;
|
|
179
|
+
}
|
|
180
|
+
let child = node.root._;
|
|
181
|
+
for (let i = count - 1; child && i >= 0; i--) {
|
|
182
|
+
const key = arrNodeKeys[i];
|
|
183
|
+
child = key !== "size" && (isMap(child) || child instanceof WeakMap) ? child.get(key) : child[key];
|
|
184
|
+
}
|
|
185
|
+
return child;
|
|
200
186
|
}
|
|
201
187
|
function getChildNode(node, key, asFunction) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// Lookup functions are bound with the child key
|
|
215
|
-
if (((_b = node.lazyFn) === null || _b === void 0 ? void 0 : _b.length) === 1) {
|
|
216
|
-
asFunction = node.lazyFn.bind(node, key);
|
|
217
|
-
}
|
|
218
|
-
if (isFunction(asFunction)) {
|
|
219
|
-
child = Object.assign(() => { }, child);
|
|
220
|
-
child.lazyFn = asFunction;
|
|
221
|
-
}
|
|
222
|
-
if (!node.children) {
|
|
223
|
-
node.children = new Map();
|
|
224
|
-
}
|
|
225
|
-
node.children.set(key, child);
|
|
188
|
+
var _a, _b;
|
|
189
|
+
let child = (_a = node.children) == null ? void 0 : _a.get(key);
|
|
190
|
+
if (!child) {
|
|
191
|
+
child = {
|
|
192
|
+
root: node.root,
|
|
193
|
+
parent: node,
|
|
194
|
+
key,
|
|
195
|
+
lazy: true,
|
|
196
|
+
numListenersRecursive: 0
|
|
197
|
+
};
|
|
198
|
+
if (((_b = node.lazyFn) == null ? void 0 : _b.length) === 1) {
|
|
199
|
+
asFunction = node.lazyFn.bind(node, key);
|
|
226
200
|
}
|
|
227
|
-
|
|
201
|
+
if (isFunction(asFunction)) {
|
|
202
|
+
child = Object.assign(() => {
|
|
203
|
+
}, child);
|
|
204
|
+
child.lazyFn = asFunction;
|
|
205
|
+
}
|
|
206
|
+
if (!node.children) {
|
|
207
|
+
node.children = /* @__PURE__ */ new Map();
|
|
208
|
+
}
|
|
209
|
+
node.children.set(key, child);
|
|
210
|
+
}
|
|
211
|
+
return child;
|
|
228
212
|
}
|
|
229
213
|
function ensureNodeValue(node) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
value = node.root._ = {};
|
|
238
|
-
}
|
|
214
|
+
let value = getNodeValue(node);
|
|
215
|
+
if (!value || isFunction(value)) {
|
|
216
|
+
if (isChildNodeValue(node)) {
|
|
217
|
+
const parent = ensureNodeValue(node.parent);
|
|
218
|
+
value = parent[node.key] = {};
|
|
219
|
+
} else {
|
|
220
|
+
value = node.root._ = {};
|
|
239
221
|
}
|
|
240
|
-
|
|
222
|
+
}
|
|
223
|
+
return value;
|
|
241
224
|
}
|
|
242
225
|
function findIDKey(obj, node) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
? 'key'
|
|
251
|
-
: '_id' in obj
|
|
252
|
-
? '_id'
|
|
253
|
-
: '__id' in obj
|
|
254
|
-
? '__id'
|
|
255
|
-
: undefined
|
|
256
|
-
: undefined;
|
|
257
|
-
if (!idKey && node.parent) {
|
|
258
|
-
const k = node.key + '_keyExtractor';
|
|
259
|
-
const keyExtractor = (_b = (_a = node.functions) === null || _a === void 0 ? void 0 : _a.get(k)) !== null && _b !== void 0 ? _b : getNodeValue(node.parent)[node.key + '_keyExtractor'];
|
|
260
|
-
if (keyExtractor && isFunction(keyExtractor)) {
|
|
261
|
-
idKey = keyExtractor;
|
|
262
|
-
}
|
|
226
|
+
var _a, _b;
|
|
227
|
+
let idKey = isObservable(obj) ? void 0 : isObject(obj) ? "id" in obj ? "id" : "key" in obj ? "key" : "_id" in obj ? "_id" : "__id" in obj ? "__id" : void 0 : void 0;
|
|
228
|
+
if (!idKey && node.parent) {
|
|
229
|
+
const k = node.key + "_keyExtractor";
|
|
230
|
+
const keyExtractor = (_b = (_a = node.functions) == null ? void 0 : _a.get(k)) != null ? _b : getNodeValue(node.parent)[node.key + "_keyExtractor"];
|
|
231
|
+
if (keyExtractor && isFunction(keyExtractor)) {
|
|
232
|
+
idKey = keyExtractor;
|
|
263
233
|
}
|
|
264
|
-
|
|
234
|
+
}
|
|
235
|
+
return idKey;
|
|
265
236
|
}
|
|
266
237
|
function extractFunction(node, key, fnOrComputed) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
238
|
+
if (!node.functions) {
|
|
239
|
+
node.functions = /* @__PURE__ */ new Map();
|
|
240
|
+
}
|
|
241
|
+
node.functions.set(key, fnOrComputed);
|
|
271
242
|
}
|
|
272
243
|
function equals(a, b) {
|
|
273
|
-
|
|
244
|
+
return a === b || isDate(a) && isDate(b) && +a === +b;
|
|
274
245
|
}
|
|
275
246
|
|
|
247
|
+
// src/helpers.ts
|
|
276
248
|
function computeSelector(selector, e, retainObservable) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
249
|
+
let c = selector;
|
|
250
|
+
if (!isObservable(c) && isFunction(c)) {
|
|
251
|
+
c = e ? c(e) : c();
|
|
252
|
+
}
|
|
253
|
+
return isObservable(c) && !retainObservable ? c.get() : c;
|
|
282
254
|
}
|
|
283
255
|
function getObservableIndex(value$) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
256
|
+
const node = getNode(value$);
|
|
257
|
+
const n = +node.key;
|
|
258
|
+
return isNumber(n) ? n : -1;
|
|
287
259
|
}
|
|
288
260
|
function opaqueObject(value) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
261
|
+
if (value) {
|
|
262
|
+
value[symbolOpaque] = true;
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
293
265
|
}
|
|
294
|
-
|
|
295
|
-
function getValueAtPath
|
|
296
|
-
|
|
266
|
+
var getValueAtPathReducer = (o, p) => o && o[p];
|
|
267
|
+
function getValueAtPath(obj, path) {
|
|
268
|
+
return path.reduce(getValueAtPathReducer, obj);
|
|
297
269
|
}
|
|
298
270
|
function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (i < path.length - 1) {
|
|
321
|
-
o = o[p];
|
|
322
|
-
if (oFull) {
|
|
323
|
-
oFull = oFull[p];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
271
|
+
let p = void 0;
|
|
272
|
+
let o = obj;
|
|
273
|
+
if (path.length > 0) {
|
|
274
|
+
let oFull = fullObj;
|
|
275
|
+
for (let i = 0; i < path.length; i++) {
|
|
276
|
+
p = path[i];
|
|
277
|
+
if (o[p] === symbolDelete) {
|
|
278
|
+
if (oFull) {
|
|
279
|
+
o[p] = oFull[p];
|
|
280
|
+
restore == null ? void 0 : restore(path.slice(0, i + 1), o[p]);
|
|
281
|
+
}
|
|
282
|
+
return obj;
|
|
283
|
+
} else if (o[p] === void 0 && value === void 0 && i === path.length - 1) {
|
|
284
|
+
return obj;
|
|
285
|
+
} else if (o[p] === void 0 || o[p] === null) {
|
|
286
|
+
o[p] = initializePathType(pathTypes[i]);
|
|
287
|
+
}
|
|
288
|
+
if (i < path.length - 1) {
|
|
289
|
+
o = o[p];
|
|
290
|
+
if (oFull) {
|
|
291
|
+
oFull = oFull[p];
|
|
326
292
|
}
|
|
293
|
+
}
|
|
327
294
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
else {
|
|
335
|
-
obj = value;
|
|
336
|
-
}
|
|
295
|
+
}
|
|
296
|
+
if (p === void 0) {
|
|
297
|
+
if (mode === "merge") {
|
|
298
|
+
obj = _mergeIntoObservable(obj, value);
|
|
299
|
+
} else {
|
|
300
|
+
obj = value;
|
|
337
301
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
else {
|
|
346
|
-
o[p] = value;
|
|
347
|
-
}
|
|
302
|
+
} else {
|
|
303
|
+
if (mode === "merge") {
|
|
304
|
+
o[p] = _mergeIntoObservable(o[p], value);
|
|
305
|
+
} else if (isMap(o)) {
|
|
306
|
+
o.set(p, value);
|
|
307
|
+
} else {
|
|
308
|
+
o[p] = value;
|
|
348
309
|
}
|
|
349
|
-
|
|
310
|
+
}
|
|
311
|
+
return obj;
|
|
350
312
|
}
|
|
351
313
|
function setInObservableAtPath(value$, path, pathTypes, value, mode) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
o.set(v);
|
|
374
|
-
}
|
|
314
|
+
let o = value$;
|
|
315
|
+
let v = value;
|
|
316
|
+
for (let i = 0; i < path.length; i++) {
|
|
317
|
+
const p = path[i];
|
|
318
|
+
if (!o.peek()[p]) {
|
|
319
|
+
o[p].set(initializePathType(pathTypes[i]));
|
|
320
|
+
}
|
|
321
|
+
o = o[p];
|
|
322
|
+
v = v[p];
|
|
323
|
+
}
|
|
324
|
+
if (v === symbolDelete) {
|
|
325
|
+
o.delete();
|
|
326
|
+
} else if (mode === "assign" && o.assign && isObject(o.peek())) {
|
|
327
|
+
o.assign(v);
|
|
328
|
+
} else if (mode === "merge") {
|
|
329
|
+
mergeIntoObservable(o, v);
|
|
330
|
+
} else {
|
|
331
|
+
o.set(v);
|
|
332
|
+
}
|
|
375
333
|
}
|
|
376
334
|
function mergeIntoObservable(target, ...sources) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
335
|
+
beginBatch();
|
|
336
|
+
globalState.isMerging = true;
|
|
337
|
+
for (let i = 0; i < sources.length; i++) {
|
|
338
|
+
target = _mergeIntoObservable(
|
|
339
|
+
target,
|
|
340
|
+
sources[i],
|
|
341
|
+
/*assign*/
|
|
342
|
+
i < sources.length - 1
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
globalState.isMerging = false;
|
|
346
|
+
endBatch();
|
|
347
|
+
return target;
|
|
348
|
+
}
|
|
349
|
+
function _mergeIntoObservable(target, source, assign2) {
|
|
350
|
+
var _a;
|
|
351
|
+
if (isObservable(source)) {
|
|
352
|
+
source = source.peek();
|
|
353
|
+
}
|
|
354
|
+
const needsSet = isObservable(target);
|
|
355
|
+
const targetValue = needsSet ? target.peek() : target;
|
|
356
|
+
const isTargetArr = isArray(targetValue);
|
|
357
|
+
const isTargetObj = !isTargetArr && isObject(targetValue);
|
|
358
|
+
if (isTargetObj && isObject(source) && !isEmpty(targetValue) || isTargetArr && targetValue.length > 0) {
|
|
359
|
+
const keys = Object.keys(source);
|
|
360
|
+
for (let i = 0; i < keys.length; i++) {
|
|
361
|
+
const key = keys[i];
|
|
362
|
+
const sourceValue = source[key];
|
|
363
|
+
if (sourceValue === symbolDelete) {
|
|
364
|
+
needsSet && ((_a = target[key]) == null ? void 0 : _a.delete) ? target[key].delete() : delete target[key];
|
|
365
|
+
} else {
|
|
366
|
+
const isObj = isObject(sourceValue);
|
|
367
|
+
const isArr = !isObj && isArray(sourceValue);
|
|
368
|
+
const targetChild = target[key];
|
|
369
|
+
if ((isObj || isArr) && targetChild && (needsSet || !isEmpty(targetChild))) {
|
|
370
|
+
if (!needsSet && (!targetChild || (isObj ? !isObject(targetChild) : !isArray(targetChild)))) {
|
|
371
|
+
target[key] = assign2 ? isArr ? [...sourceValue] : { ...sourceValue } : sourceValue;
|
|
372
|
+
} else {
|
|
373
|
+
_mergeIntoObservable(targetChild, sourceValue);
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
if (needsSet) {
|
|
377
|
+
targetChild.set(sourceValue);
|
|
378
|
+
} else {
|
|
379
|
+
const toSet = isObject(sourceValue) ? { ...sourceValue } : isArray(sourceValue) ? [...sourceValue] : sourceValue;
|
|
380
|
+
target[key] = toSet;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (source !== void 0) {
|
|
386
|
+
needsSet ? target.set(source) : target = assign2 ? isArray(source) ? [...source] : { ...source } : source;
|
|
387
|
+
}
|
|
388
|
+
return target;
|
|
429
389
|
}
|
|
430
390
|
function constructObjectWithPath(path, pathTypes, value) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
out = value;
|
|
391
|
+
let out;
|
|
392
|
+
if (path.length > 0) {
|
|
393
|
+
let o = out = {};
|
|
394
|
+
for (let i = 0; i < path.length; i++) {
|
|
395
|
+
const p = path[i];
|
|
396
|
+
o[p] = i === path.length - 1 ? value : initializePathType(pathTypes[i]);
|
|
397
|
+
o = o[p];
|
|
442
398
|
}
|
|
443
|
-
|
|
399
|
+
} else {
|
|
400
|
+
out = value;
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
444
403
|
}
|
|
445
404
|
function deconstructObjectWithPath(path, pathTypes, value) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
405
|
+
let o = value;
|
|
406
|
+
for (let i = 0; i < path.length; i++) {
|
|
407
|
+
const p = path[i];
|
|
408
|
+
o = o ? o[p] : initializePathType(pathTypes[i]);
|
|
409
|
+
}
|
|
410
|
+
return o;
|
|
452
411
|
}
|
|
453
412
|
function isObservableValueReady(value) {
|
|
454
|
-
|
|
413
|
+
return !!value && (!isObject(value) && !isArray(value) || !isEmpty(value));
|
|
455
414
|
}
|
|
456
415
|
function setSilently(value$, newValue) {
|
|
457
|
-
|
|
458
|
-
|
|
416
|
+
const node = getNode(value$);
|
|
417
|
+
return setNodeValue(node, newValue).newValue;
|
|
459
418
|
}
|
|
460
419
|
function initializePathType(pathType) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
420
|
+
switch (pathType) {
|
|
421
|
+
case "array":
|
|
422
|
+
return [];
|
|
423
|
+
case "object":
|
|
424
|
+
return {};
|
|
425
|
+
case "map":
|
|
426
|
+
return /* @__PURE__ */ new Map();
|
|
427
|
+
case "set":
|
|
428
|
+
return /* @__PURE__ */ new Set();
|
|
429
|
+
}
|
|
471
430
|
}
|
|
472
431
|
function applyChange(value, change, applyPrevious) {
|
|
473
|
-
|
|
474
|
-
|
|
432
|
+
const { path, valueAtPath, prevAtPath, pathTypes } = change;
|
|
433
|
+
return setAtPath(value, path, pathTypes, applyPrevious ? prevAtPath : valueAtPath);
|
|
475
434
|
}
|
|
476
435
|
function applyChanges(value, changes, applyPrevious) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
436
|
+
for (let i = 0; i < changes.length; i++) {
|
|
437
|
+
value = applyChange(value, changes[i], applyPrevious);
|
|
438
|
+
}
|
|
439
|
+
return value;
|
|
481
440
|
}
|
|
482
441
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
442
|
+
// src/batching.ts
|
|
443
|
+
var timeout;
|
|
444
|
+
var numInBatch = 0;
|
|
445
|
+
var isRunningBatch = false;
|
|
446
|
+
var didDelayEndBatch = false;
|
|
447
|
+
var _batchMap = /* @__PURE__ */ new Map();
|
|
488
448
|
function onActionTimeout() {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
449
|
+
if (_batchMap.size > 0) {
|
|
450
|
+
if (process.env.NODE_ENV === "development") {
|
|
451
|
+
console.error(
|
|
452
|
+
"Forcibly completing observableBatcher because end() was never called. This may be due to an uncaught error between begin() and end()."
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
endBatch(
|
|
456
|
+
/*force*/
|
|
457
|
+
true
|
|
458
|
+
);
|
|
459
|
+
}
|
|
495
460
|
}
|
|
496
461
|
function isArraySubset(mainArr, subsetArr) {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
462
|
+
for (let i = 0; i < mainArr.length; i++) {
|
|
463
|
+
if (mainArr[i] !== subsetArr[i]) {
|
|
464
|
+
return false;
|
|
501
465
|
}
|
|
502
|
-
|
|
466
|
+
}
|
|
467
|
+
return true;
|
|
503
468
|
}
|
|
504
469
|
function createPreviousHandlerInner(value, changes) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return undefined;
|
|
511
|
-
}
|
|
470
|
+
try {
|
|
471
|
+
return applyChanges(value ? clone(value) : {}, changes, true);
|
|
472
|
+
} catch (e) {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
512
475
|
}
|
|
513
476
|
function createPreviousHandler(value, changes) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return function () {
|
|
518
|
-
return createPreviousHandlerInner(value, changes);
|
|
519
|
-
};
|
|
477
|
+
return function() {
|
|
478
|
+
return createPreviousHandlerInner(value, changes);
|
|
479
|
+
};
|
|
520
480
|
}
|
|
521
481
|
function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
/*
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
482
|
+
const changesInBatch = /* @__PURE__ */ new Map();
|
|
483
|
+
computeChangesRecursive(
|
|
484
|
+
changesInBatch,
|
|
485
|
+
node,
|
|
486
|
+
/*loading*/
|
|
487
|
+
globalState.isLoadingLocal,
|
|
488
|
+
/*remote*/
|
|
489
|
+
globalState.isLoadingRemote,
|
|
490
|
+
value,
|
|
491
|
+
[],
|
|
492
|
+
[],
|
|
493
|
+
value,
|
|
494
|
+
prev,
|
|
495
|
+
/*immediate*/
|
|
496
|
+
true,
|
|
497
|
+
level,
|
|
498
|
+
whenOptimizedOnlyIf
|
|
499
|
+
);
|
|
500
|
+
if (changesInBatch.size) {
|
|
501
|
+
batchNotifyChanges(
|
|
502
|
+
changesInBatch,
|
|
503
|
+
/*immediate*/
|
|
504
|
+
true
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
const existing = _batchMap.get(node);
|
|
508
|
+
if (existing) {
|
|
509
|
+
existing.value = value;
|
|
510
|
+
} else {
|
|
511
|
+
_batchMap.set(node, {
|
|
512
|
+
value,
|
|
513
|
+
prev,
|
|
514
|
+
level,
|
|
515
|
+
whenOptimizedOnlyIf,
|
|
516
|
+
remote: globalState.isLoadingRemote,
|
|
517
|
+
loading: globalState.isLoadingLocal
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (numInBatch <= 0) {
|
|
521
|
+
runBatch();
|
|
522
|
+
}
|
|
551
523
|
}
|
|
552
524
|
function computeChangesAtNode(changesInBatch, node, loading, remote, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}
|
|
525
|
+
if (immediate ? node.listenersImmediate : node.listeners) {
|
|
526
|
+
const change = {
|
|
527
|
+
path,
|
|
528
|
+
pathTypes,
|
|
529
|
+
valueAtPath,
|
|
530
|
+
prevAtPath
|
|
531
|
+
};
|
|
532
|
+
const changeInBatch = changesInBatch.get(node);
|
|
533
|
+
if (changeInBatch && path.length > 0) {
|
|
534
|
+
const { changes } = changeInBatch;
|
|
535
|
+
if (!isArraySubset(changes[0].path, change.path)) {
|
|
536
|
+
changes.push(change);
|
|
537
|
+
}
|
|
538
|
+
} else {
|
|
539
|
+
changesInBatch.set(node, {
|
|
540
|
+
level,
|
|
541
|
+
value,
|
|
542
|
+
remote,
|
|
543
|
+
loading,
|
|
544
|
+
whenOptimizedOnlyIf,
|
|
545
|
+
changes: [change]
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
580
549
|
}
|
|
581
550
|
function computeChangesRecursive(changesInBatch, node, loading, remote, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
551
|
+
computeChangesAtNode(
|
|
552
|
+
changesInBatch,
|
|
553
|
+
node,
|
|
554
|
+
loading,
|
|
555
|
+
remote,
|
|
556
|
+
value,
|
|
557
|
+
path,
|
|
558
|
+
pathTypes,
|
|
559
|
+
valueAtPath,
|
|
560
|
+
prevAtPath,
|
|
561
|
+
immediate,
|
|
562
|
+
level,
|
|
563
|
+
whenOptimizedOnlyIf
|
|
564
|
+
);
|
|
565
|
+
if (node.linkedFromNodes) {
|
|
566
|
+
for (const linkedFromNode of node.linkedFromNodes) {
|
|
567
|
+
const childNode = getNodeAtPath(linkedFromNode, path);
|
|
568
|
+
computeChangesRecursive(
|
|
569
|
+
changesInBatch,
|
|
570
|
+
childNode,
|
|
571
|
+
loading,
|
|
572
|
+
remote,
|
|
573
|
+
valueAtPath,
|
|
574
|
+
[],
|
|
575
|
+
[],
|
|
576
|
+
valueAtPath,
|
|
577
|
+
prevAtPath,
|
|
578
|
+
immediate,
|
|
579
|
+
0,
|
|
580
|
+
whenOptimizedOnlyIf
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (node.parent) {
|
|
585
|
+
const parent = node.parent;
|
|
586
|
+
if (parent) {
|
|
587
|
+
const parentValue = getNodeValue(parent);
|
|
588
|
+
computeChangesRecursive(
|
|
589
|
+
changesInBatch,
|
|
590
|
+
parent,
|
|
591
|
+
loading,
|
|
592
|
+
remote,
|
|
593
|
+
parentValue,
|
|
594
|
+
[node.key].concat(path),
|
|
595
|
+
[getPathType(value)].concat(pathTypes),
|
|
596
|
+
valueAtPath,
|
|
597
|
+
prevAtPath,
|
|
598
|
+
immediate,
|
|
599
|
+
level + 1,
|
|
600
|
+
whenOptimizedOnlyIf
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
598
604
|
}
|
|
599
605
|
function batchNotifyChanges(changesInBatch, immediate) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
remote,
|
|
621
|
-
getPrevious: createPreviousHandler(value, changes),
|
|
622
|
-
changes,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
if (!track) {
|
|
626
|
-
listenersNotified.add(listener);
|
|
627
|
-
}
|
|
628
|
-
listener(listenerParams);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
606
|
+
const listenersNotified = /* @__PURE__ */ new Set();
|
|
607
|
+
changesInBatch.forEach(({ changes, level, value, loading, remote, whenOptimizedOnlyIf }, node) => {
|
|
608
|
+
const listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
609
|
+
if (listeners) {
|
|
610
|
+
let listenerParams;
|
|
611
|
+
const arr = Array.from(listeners);
|
|
612
|
+
for (let i = 0; i < arr.length; i++) {
|
|
613
|
+
const listenerFn = arr[i];
|
|
614
|
+
const { track, noArgs, listener } = listenerFn;
|
|
615
|
+
if (!listenersNotified.has(listener)) {
|
|
616
|
+
const ok = track === true ? level <= 0 : track === optimized ? whenOptimizedOnlyIf && level <= 0 : true;
|
|
617
|
+
if (ok) {
|
|
618
|
+
if (!noArgs && !listenerParams) {
|
|
619
|
+
listenerParams = {
|
|
620
|
+
value,
|
|
621
|
+
loading,
|
|
622
|
+
remote,
|
|
623
|
+
getPrevious: createPreviousHandler(value, changes),
|
|
624
|
+
changes
|
|
625
|
+
};
|
|
631
626
|
}
|
|
627
|
+
if (!track) {
|
|
628
|
+
listenersNotified.add(listener);
|
|
629
|
+
}
|
|
630
|
+
listener(listenerParams);
|
|
631
|
+
}
|
|
632
632
|
}
|
|
633
|
-
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
634
636
|
}
|
|
635
637
|
function runBatch() {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
638
|
+
const dirtyNodes = Array.from(globalState.dirtyNodes);
|
|
639
|
+
globalState.dirtyNodes.clear();
|
|
640
|
+
dirtyNodes.forEach((node) => {
|
|
641
|
+
const dirtyFn = node.dirtyFn;
|
|
642
|
+
if (dirtyFn) {
|
|
643
|
+
node.dirtyFn = void 0;
|
|
644
|
+
dirtyFn();
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
const map = _batchMap;
|
|
648
|
+
_batchMap = /* @__PURE__ */ new Map();
|
|
649
|
+
const changesInBatch = /* @__PURE__ */ new Map();
|
|
650
|
+
map.forEach(({ value, prev, level, loading, remote, whenOptimizedOnlyIf }, node) => {
|
|
651
|
+
computeChangesRecursive(
|
|
652
|
+
changesInBatch,
|
|
653
|
+
node,
|
|
654
|
+
loading,
|
|
655
|
+
remote,
|
|
656
|
+
value,
|
|
657
|
+
[],
|
|
658
|
+
[],
|
|
659
|
+
value,
|
|
660
|
+
prev,
|
|
661
|
+
false,
|
|
662
|
+
level,
|
|
663
|
+
whenOptimizedOnlyIf
|
|
664
|
+
);
|
|
665
|
+
});
|
|
666
|
+
if (changesInBatch.size) {
|
|
667
|
+
batchNotifyChanges(changesInBatch, false);
|
|
668
|
+
}
|
|
660
669
|
}
|
|
661
670
|
function batch(fn) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
671
|
+
beginBatch();
|
|
672
|
+
try {
|
|
673
|
+
fn();
|
|
674
|
+
} finally {
|
|
675
|
+
endBatch();
|
|
676
|
+
}
|
|
669
677
|
}
|
|
670
678
|
function beginBatch() {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
679
|
+
numInBatch++;
|
|
680
|
+
if (!timeout) {
|
|
681
|
+
timeout = setTimeout(onActionTimeout, 0);
|
|
682
|
+
}
|
|
675
683
|
}
|
|
676
684
|
function endBatch(force) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
endBatch(true);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
685
|
+
numInBatch--;
|
|
686
|
+
if (numInBatch <= 0 || force) {
|
|
687
|
+
if (isRunningBatch) {
|
|
688
|
+
didDelayEndBatch = true;
|
|
689
|
+
} else {
|
|
690
|
+
if (timeout) {
|
|
691
|
+
clearTimeout(timeout);
|
|
692
|
+
timeout = void 0;
|
|
693
|
+
}
|
|
694
|
+
numInBatch = 0;
|
|
695
|
+
isRunningBatch = true;
|
|
696
|
+
runBatch();
|
|
697
|
+
isRunningBatch = false;
|
|
698
|
+
if (didDelayEndBatch) {
|
|
699
|
+
didDelayEndBatch = false;
|
|
700
|
+
endBatch(true);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
700
704
|
}
|
|
701
705
|
function getNodeAtPath(obj, path) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
706
|
+
let o = obj;
|
|
707
|
+
for (let i = 0; i < path.length; i++) {
|
|
708
|
+
const p = path[i];
|
|
709
|
+
o = getChildNode(o, p);
|
|
710
|
+
}
|
|
711
|
+
return o;
|
|
708
712
|
}
|
|
709
713
|
|
|
714
|
+
// src/linked.ts
|
|
710
715
|
function linked(params, options) {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
716
|
+
if (isFunction(params)) {
|
|
717
|
+
params = { get: params };
|
|
718
|
+
}
|
|
719
|
+
if (options) {
|
|
720
|
+
params = { ...params, ...options };
|
|
721
|
+
}
|
|
722
|
+
const ret = function() {
|
|
723
|
+
return { [symbolLinked]: params };
|
|
724
|
+
};
|
|
725
|
+
ret.prototype[symbolLinked] = params;
|
|
726
|
+
return ret;
|
|
722
727
|
}
|
|
723
728
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
729
|
+
// src/createObservable.ts
|
|
730
|
+
function createObservable(value, makePrimitive, extractPromise2, createObject, createPrimitive) {
|
|
731
|
+
if (isObservable(value)) {
|
|
732
|
+
return value;
|
|
733
|
+
}
|
|
734
|
+
const valueIsPromise = isPromise(value);
|
|
735
|
+
const valueIsFunction = isFunction(value);
|
|
736
|
+
const root = {
|
|
737
|
+
_: value
|
|
738
|
+
};
|
|
739
|
+
let node = {
|
|
740
|
+
root,
|
|
741
|
+
lazy: true,
|
|
742
|
+
numListenersRecursive: 0
|
|
743
|
+
};
|
|
744
|
+
if (valueIsFunction) {
|
|
745
|
+
node = Object.assign(() => {
|
|
746
|
+
}, node);
|
|
747
|
+
node.lazyFn = value;
|
|
748
|
+
}
|
|
749
|
+
const prim = makePrimitive || isActualPrimitive(value);
|
|
750
|
+
const obs = prim ? new createPrimitive(node) : createObject(node);
|
|
751
|
+
if (valueIsPromise) {
|
|
752
|
+
setNodeValue(node, void 0);
|
|
753
|
+
extractPromise2(node, value);
|
|
754
|
+
}
|
|
755
|
+
return obs;
|
|
751
756
|
}
|
|
752
757
|
|
|
758
|
+
// src/onChange.ts
|
|
753
759
|
function onChange(node, callback, options = {}, fromLinks) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
(
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
let parent = node;
|
|
832
|
-
while (parent) {
|
|
833
|
-
parent.numListenersRecursive--;
|
|
834
|
-
parent = parent.parent;
|
|
835
|
-
}
|
|
836
|
-
};
|
|
760
|
+
var _a;
|
|
761
|
+
const { initial, immediate, noArgs } = options;
|
|
762
|
+
const { trackingType } = options;
|
|
763
|
+
let listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
764
|
+
if (!listeners) {
|
|
765
|
+
listeners = /* @__PURE__ */ new Set();
|
|
766
|
+
if (immediate) {
|
|
767
|
+
node.listenersImmediate = listeners;
|
|
768
|
+
} else {
|
|
769
|
+
node.listeners = listeners;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
const listener = {
|
|
773
|
+
listener: callback,
|
|
774
|
+
track: trackingType,
|
|
775
|
+
noArgs
|
|
776
|
+
};
|
|
777
|
+
listeners.add(listener);
|
|
778
|
+
if (initial) {
|
|
779
|
+
const value = getNodeValue(node);
|
|
780
|
+
callback({
|
|
781
|
+
value,
|
|
782
|
+
loading: true,
|
|
783
|
+
remote: false,
|
|
784
|
+
changes: [
|
|
785
|
+
{
|
|
786
|
+
path: [],
|
|
787
|
+
pathTypes: [],
|
|
788
|
+
prevAtPath: value,
|
|
789
|
+
valueAtPath: value
|
|
790
|
+
}
|
|
791
|
+
],
|
|
792
|
+
getPrevious: () => void 0
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
let extraDisposes;
|
|
796
|
+
function addLinkedNodeListeners(childNode, cb = callback, from) {
|
|
797
|
+
if (!(fromLinks == null ? void 0 : fromLinks.has(childNode))) {
|
|
798
|
+
fromLinks || (fromLinks = /* @__PURE__ */ new Set());
|
|
799
|
+
fromLinks.add(from || node);
|
|
800
|
+
cb || (cb = callback);
|
|
801
|
+
const childOptions = {
|
|
802
|
+
trackingType: true,
|
|
803
|
+
...options
|
|
804
|
+
};
|
|
805
|
+
extraDisposes = [...extraDisposes || [], onChange(childNode, cb, childOptions, fromLinks)];
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (node.linkedToNode) {
|
|
809
|
+
addLinkedNodeListeners(node.linkedToNode);
|
|
810
|
+
}
|
|
811
|
+
(_a = node.linkedFromNodes) == null ? void 0 : _a.forEach((linkedFromNode) => addLinkedNodeListeners(linkedFromNode));
|
|
812
|
+
node.numListenersRecursive++;
|
|
813
|
+
let parent = node.parent;
|
|
814
|
+
let pathParent = [node.key];
|
|
815
|
+
while (parent) {
|
|
816
|
+
if (parent.linkedFromNodes) {
|
|
817
|
+
for (const linkedFromNode of parent.linkedFromNodes) {
|
|
818
|
+
if (!(fromLinks == null ? void 0 : fromLinks.has(linkedFromNode))) {
|
|
819
|
+
const cb = createCb(linkedFromNode, pathParent, callback);
|
|
820
|
+
addLinkedNodeListeners(linkedFromNode, cb, parent);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
parent.numListenersRecursive++;
|
|
825
|
+
pathParent = [parent.key, ...pathParent];
|
|
826
|
+
parent = parent.parent;
|
|
827
|
+
}
|
|
828
|
+
return () => {
|
|
829
|
+
listeners.delete(listener);
|
|
830
|
+
extraDisposes == null ? void 0 : extraDisposes.forEach((fn) => fn());
|
|
831
|
+
let parent2 = node;
|
|
832
|
+
while (parent2) {
|
|
833
|
+
parent2.numListenersRecursive--;
|
|
834
|
+
parent2 = parent2.parent;
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
837
|
}
|
|
838
838
|
function createCb(linkedFromNode, path, callback) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
return { valueAtPath: o, pathTypes };
|
|
839
|
+
let { valueAtPath: prevAtPath } = getValueAtPath2(getNodeValue(linkedFromNode), path);
|
|
840
|
+
return function({ value: valueA, loading, remote }) {
|
|
841
|
+
const { valueAtPath } = getValueAtPath2(valueA, path);
|
|
842
|
+
if (valueAtPath !== prevAtPath) {
|
|
843
|
+
callback({
|
|
844
|
+
value: valueAtPath,
|
|
845
|
+
loading,
|
|
846
|
+
remote,
|
|
847
|
+
changes: [
|
|
848
|
+
{
|
|
849
|
+
path: [],
|
|
850
|
+
pathTypes: [],
|
|
851
|
+
prevAtPath,
|
|
852
|
+
valueAtPath
|
|
853
|
+
}
|
|
854
|
+
],
|
|
855
|
+
getPrevious: () => prevAtPath
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
prevAtPath = valueAtPath;
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
function getValueAtPath2(obj, path) {
|
|
862
|
+
let o = obj;
|
|
863
|
+
const pathTypes = [];
|
|
864
|
+
for (let i = 0; o && i < path.length; i++) {
|
|
865
|
+
pathTypes.push(isArray(o) ? "array" : "object");
|
|
866
|
+
const p = path[i];
|
|
867
|
+
o = o[p];
|
|
868
|
+
}
|
|
869
|
+
return { valueAtPath: o, pathTypes };
|
|
871
870
|
}
|
|
872
871
|
|
|
872
|
+
// src/setupTracking.ts
|
|
873
873
|
function setupTracking(nodes, update, noArgs, immediate) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
};
|
|
874
|
+
let listeners = [];
|
|
875
|
+
nodes == null ? void 0 : nodes.forEach((tracked) => {
|
|
876
|
+
const { node, track } = tracked;
|
|
877
|
+
listeners.push(onChange(node, update, { trackingType: track, immediate, noArgs }));
|
|
878
|
+
});
|
|
879
|
+
return () => {
|
|
880
|
+
if (listeners) {
|
|
881
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
882
|
+
listeners[i]();
|
|
883
|
+
}
|
|
884
|
+
listeners = void 0;
|
|
885
|
+
}
|
|
886
|
+
};
|
|
888
887
|
}
|
|
889
888
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
889
|
+
// src/tracking.ts
|
|
890
|
+
var trackCount = 0;
|
|
891
|
+
var trackingQueue = [];
|
|
892
|
+
var tracking = {
|
|
893
|
+
current: void 0
|
|
894
894
|
};
|
|
895
895
|
function beginTracking() {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
trackCount++;
|
|
900
|
-
tracking.current = {};
|
|
896
|
+
trackingQueue.push(tracking.current);
|
|
897
|
+
trackCount++;
|
|
898
|
+
tracking.current = {};
|
|
901
899
|
}
|
|
902
900
|
function endTracking() {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
tracking.current = trackingQueue.pop();
|
|
901
|
+
trackCount--;
|
|
902
|
+
if (trackCount < 0) {
|
|
903
|
+
trackCount = 0;
|
|
904
|
+
}
|
|
905
|
+
tracking.current = trackingQueue.pop();
|
|
909
906
|
}
|
|
910
907
|
function updateTracking(node, track) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
908
|
+
if (trackCount) {
|
|
909
|
+
const tracker = tracking.current;
|
|
910
|
+
if (tracker) {
|
|
911
|
+
if (!tracker.nodes) {
|
|
912
|
+
tracker.nodes = /* @__PURE__ */ new Map();
|
|
913
|
+
}
|
|
914
|
+
const existing = tracker.nodes.get(node);
|
|
915
|
+
if (existing) {
|
|
916
|
+
existing.track = existing.track || track;
|
|
917
|
+
existing.num++;
|
|
918
|
+
} else {
|
|
919
|
+
tracker.nodes.set(node, { node, track, num: 1 });
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
927
923
|
}
|
|
928
924
|
|
|
925
|
+
// src/trackSelector.ts
|
|
929
926
|
function trackSelector(selector, update, observeEvent, observeOptions, createResubscribe) {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
dispose = setupTracking(nodes, updateFn
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
return dispose;
|
|
959
|
-
}
|
|
960
|
-
: undefined;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
return { nodes, value, dispose, resubscribe };
|
|
927
|
+
var _a;
|
|
928
|
+
let dispose;
|
|
929
|
+
let resubscribe;
|
|
930
|
+
let updateFn = update;
|
|
931
|
+
beginTracking();
|
|
932
|
+
const value = selector ? computeSelector(selector, observeEvent, observeOptions == null ? void 0 : observeOptions.fromComputed) : selector;
|
|
933
|
+
const tracker = tracking.current;
|
|
934
|
+
const nodes = tracker.nodes;
|
|
935
|
+
endTracking();
|
|
936
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracker && nodes) {
|
|
937
|
+
(_a = tracker.traceListeners) == null ? void 0 : _a.call(tracker, nodes);
|
|
938
|
+
if (tracker.traceUpdates) {
|
|
939
|
+
updateFn = tracker.traceUpdates(update);
|
|
940
|
+
}
|
|
941
|
+
tracker.traceListeners = void 0;
|
|
942
|
+
tracker.traceUpdates = void 0;
|
|
943
|
+
}
|
|
944
|
+
if (!(observeEvent == null ? void 0 : observeEvent.cancel)) {
|
|
945
|
+
dispose = setupTracking(nodes, updateFn, false, observeOptions == null ? void 0 : observeOptions.immediate);
|
|
946
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
947
|
+
resubscribe = createResubscribe ? () => {
|
|
948
|
+
dispose == null ? void 0 : dispose();
|
|
949
|
+
dispose = setupTracking(nodes, updateFn);
|
|
950
|
+
return dispose;
|
|
951
|
+
} : void 0;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return { nodes, value, dispose, resubscribe };
|
|
964
955
|
}
|
|
965
956
|
|
|
957
|
+
// src/observe.ts
|
|
966
958
|
function observe(selectorOrRun, reactionOrOptions, options) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
e.num++;
|
|
1009
|
-
};
|
|
1010
|
-
update();
|
|
1011
|
-
// Return function calling dispose because dispose may be changed in update()
|
|
1012
|
-
return () => {
|
|
1013
|
-
var _a, _b;
|
|
1014
|
-
(_a = e.onCleanup) === null || _a === void 0 ? void 0 : _a.call(e);
|
|
1015
|
-
e.onCleanup = undefined;
|
|
1016
|
-
(_b = e.onCleanupReaction) === null || _b === void 0 ? void 0 : _b.call(e);
|
|
1017
|
-
e.onCleanupReaction = undefined;
|
|
1018
|
-
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
1019
|
-
};
|
|
959
|
+
let reaction;
|
|
960
|
+
if (isFunction(reactionOrOptions)) {
|
|
961
|
+
reaction = reactionOrOptions;
|
|
962
|
+
} else {
|
|
963
|
+
options = reactionOrOptions;
|
|
964
|
+
}
|
|
965
|
+
let dispose;
|
|
966
|
+
const e = { num: 0 };
|
|
967
|
+
const update = function() {
|
|
968
|
+
if (e.onCleanup) {
|
|
969
|
+
e.onCleanup();
|
|
970
|
+
e.onCleanup = void 0;
|
|
971
|
+
}
|
|
972
|
+
beginBatch();
|
|
973
|
+
delete e.value;
|
|
974
|
+
dispose == null ? void 0 : dispose();
|
|
975
|
+
const { dispose: _dispose, value, nodes } = trackSelector(selectorOrRun, update, e, options);
|
|
976
|
+
dispose = _dispose;
|
|
977
|
+
e.value = value;
|
|
978
|
+
e.nodes = nodes;
|
|
979
|
+
e.refresh = update;
|
|
980
|
+
if (e.onCleanupReaction) {
|
|
981
|
+
e.onCleanupReaction();
|
|
982
|
+
e.onCleanupReaction = void 0;
|
|
983
|
+
}
|
|
984
|
+
endBatch();
|
|
985
|
+
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
986
|
+
reaction(e);
|
|
987
|
+
}
|
|
988
|
+
e.previous = e.value;
|
|
989
|
+
e.num++;
|
|
990
|
+
};
|
|
991
|
+
update();
|
|
992
|
+
return () => {
|
|
993
|
+
var _a, _b;
|
|
994
|
+
(_a = e.onCleanup) == null ? void 0 : _a.call(e);
|
|
995
|
+
e.onCleanup = void 0;
|
|
996
|
+
(_b = e.onCleanupReaction) == null ? void 0 : _b.call(e);
|
|
997
|
+
e.onCleanupReaction = void 0;
|
|
998
|
+
dispose == null ? void 0 : dispose();
|
|
999
|
+
};
|
|
1020
1000
|
}
|
|
1021
1001
|
|
|
1002
|
+
// src/when.ts
|
|
1022
1003
|
function _when(predicate, effect, checkReady) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
return undefined;
|
|
1037
|
-
}
|
|
1038
|
-
else if (!isPromise(ret) && (checkReady ? isObservableValueReady(ret) : ret)) {
|
|
1039
|
-
value = ret;
|
|
1040
|
-
// Set cancel so that observe does not track anymore
|
|
1041
|
-
e.cancel = true;
|
|
1042
|
-
}
|
|
1043
|
-
return value;
|
|
1044
|
-
}
|
|
1045
|
-
function doEffect() {
|
|
1046
|
-
// If value is truthy then run the effect
|
|
1047
|
-
effectValue = effect === null || effect === void 0 ? void 0 : effect(value);
|
|
1048
|
-
}
|
|
1049
|
-
// Run in an observe
|
|
1050
|
-
observe(run, doEffect);
|
|
1051
|
-
// If first run resulted in a truthy value just return it.
|
|
1052
|
-
// It will have set e.cancel so no need to dispose
|
|
1053
|
-
if (isPromise(value)) {
|
|
1054
|
-
return effect ? value.then(effect) : value;
|
|
1055
|
-
}
|
|
1056
|
-
else if (value !== undefined) {
|
|
1057
|
-
return effect ? effectValue : Promise.resolve(value);
|
|
1058
|
-
}
|
|
1059
|
-
else {
|
|
1060
|
-
// Wrap it in a promise
|
|
1061
|
-
const promise = new Promise((resolve) => {
|
|
1062
|
-
if (effect) {
|
|
1063
|
-
const originalEffect = effect;
|
|
1064
|
-
effect = ((value) => {
|
|
1065
|
-
const effectValue = originalEffect(value);
|
|
1066
|
-
resolve(isPromise(effectValue) ? effectValue.then((value) => value) : effectValue);
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
effect = resolve;
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
return promise;
|
|
1004
|
+
if (isPromise(predicate)) {
|
|
1005
|
+
return effect ? predicate.then(effect) : predicate;
|
|
1006
|
+
}
|
|
1007
|
+
let value;
|
|
1008
|
+
let effectValue;
|
|
1009
|
+
function run(e) {
|
|
1010
|
+
const ret = computeSelector(predicate);
|
|
1011
|
+
if (isPromise(ret)) {
|
|
1012
|
+
value = ret;
|
|
1013
|
+
return void 0;
|
|
1014
|
+
} else if (!isPromise(ret) && (checkReady ? isObservableValueReady(ret) : ret)) {
|
|
1015
|
+
value = ret;
|
|
1016
|
+
e.cancel = true;
|
|
1074
1017
|
}
|
|
1018
|
+
return value;
|
|
1019
|
+
}
|
|
1020
|
+
function doEffect() {
|
|
1021
|
+
effectValue = effect == null ? void 0 : effect(value);
|
|
1022
|
+
}
|
|
1023
|
+
observe(run, doEffect);
|
|
1024
|
+
if (isPromise(value)) {
|
|
1025
|
+
return effect ? value.then(effect) : value;
|
|
1026
|
+
} else if (value !== void 0) {
|
|
1027
|
+
return effect ? effectValue : Promise.resolve(value);
|
|
1028
|
+
} else {
|
|
1029
|
+
const promise = new Promise((resolve) => {
|
|
1030
|
+
if (effect) {
|
|
1031
|
+
const originalEffect = effect;
|
|
1032
|
+
effect = (value2) => {
|
|
1033
|
+
const effectValue2 = originalEffect(value2);
|
|
1034
|
+
resolve(isPromise(effectValue2) ? effectValue2.then((value3) => value3) : effectValue2);
|
|
1035
|
+
};
|
|
1036
|
+
} else {
|
|
1037
|
+
effect = resolve;
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
return promise;
|
|
1041
|
+
}
|
|
1075
1042
|
}
|
|
1076
1043
|
function when(predicate, effect) {
|
|
1077
|
-
|
|
1044
|
+
return _when(predicate, effect, false);
|
|
1078
1045
|
}
|
|
1079
1046
|
function whenReady(predicate, effect) {
|
|
1080
|
-
|
|
1047
|
+
return _when(predicate, effect, true);
|
|
1081
1048
|
}
|
|
1082
1049
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1050
|
+
// src/ObservableObject.ts
|
|
1051
|
+
var ArrayModifiers = /* @__PURE__ */ new Set([
|
|
1052
|
+
"copyWithin",
|
|
1053
|
+
"fill",
|
|
1054
|
+
"from",
|
|
1055
|
+
"pop",
|
|
1056
|
+
"push",
|
|
1057
|
+
"reverse",
|
|
1058
|
+
"shift",
|
|
1059
|
+
"sort",
|
|
1060
|
+
"splice",
|
|
1061
|
+
"unshift"
|
|
1094
1062
|
]);
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1063
|
+
var ArrayLoopers = /* @__PURE__ */ new Set([
|
|
1064
|
+
"every",
|
|
1065
|
+
"filter",
|
|
1066
|
+
"find",
|
|
1067
|
+
"findIndex",
|
|
1068
|
+
"forEach",
|
|
1069
|
+
"join",
|
|
1070
|
+
"map",
|
|
1071
|
+
"reduce",
|
|
1072
|
+
"some"
|
|
1105
1073
|
]);
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1074
|
+
var ArrayLoopersReturn = /* @__PURE__ */ new Set(["filter", "find"]);
|
|
1075
|
+
var observableProperties = /* @__PURE__ */ new Map();
|
|
1076
|
+
var observableFns = /* @__PURE__ */ new Map([
|
|
1077
|
+
["get", get],
|
|
1078
|
+
["set", set],
|
|
1079
|
+
["peek", peek],
|
|
1080
|
+
["onChange", onChange],
|
|
1081
|
+
["assign", assign],
|
|
1082
|
+
["delete", deleteFn],
|
|
1083
|
+
["toggle", toggle]
|
|
1116
1084
|
]);
|
|
1117
|
-
if (process.env.NODE_ENV ===
|
|
1118
|
-
|
|
1119
|
-
var __devUpdateNodes = new Set();
|
|
1085
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
1086
|
+
__devUpdateNodes = /* @__PURE__ */ new Set();
|
|
1120
1087
|
}
|
|
1088
|
+
var __devUpdateNodes;
|
|
1121
1089
|
function collectionSetter(node, target, prop, ...args) {
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
// Set the object to the previous value first
|
|
1135
|
-
parentValue[key] = prevValue;
|
|
1136
|
-
// Then set with the new value so it notifies with the correct prevValue
|
|
1137
|
-
setKey((_a = node.parent) !== null && _a !== void 0 ? _a : node, key, target);
|
|
1138
|
-
}
|
|
1139
|
-
// Return the original value
|
|
1140
|
-
return ret;
|
|
1090
|
+
var _a;
|
|
1091
|
+
if (prop === "push" && args.length === 1) {
|
|
1092
|
+
setKey(node, target.length + "", args[0]);
|
|
1093
|
+
} else {
|
|
1094
|
+
const prevValue = target.slice();
|
|
1095
|
+
const ret = target[prop].apply(target, args);
|
|
1096
|
+
if (node) {
|
|
1097
|
+
const hasParent = isChildNodeValue(node);
|
|
1098
|
+
const key = hasParent ? node.key : "_";
|
|
1099
|
+
const parentValue = hasParent ? getNodeValue(node.parent) : node.root;
|
|
1100
|
+
parentValue[key] = prevValue;
|
|
1101
|
+
setKey((_a = node.parent) != null ? _a : node, key, target);
|
|
1141
1102
|
}
|
|
1103
|
+
return ret;
|
|
1104
|
+
}
|
|
1142
1105
|
}
|
|
1143
|
-
function getKeys(obj, isArr,
|
|
1144
|
-
|
|
1106
|
+
function getKeys(obj, isArr, isMap2) {
|
|
1107
|
+
return isArr ? void 0 : obj ? isMap2 ? Array.from(obj.keys()) : Object.keys(obj) : [];
|
|
1145
1108
|
}
|
|
1146
1109
|
function updateNodes(parent, obj, prevValue) {
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (p) {
|
|
1203
|
-
const child = parent.children.get(i + '');
|
|
1204
|
-
if (child) {
|
|
1205
|
-
if (!obj[i]) {
|
|
1206
|
-
// If the previous value is not in the new array and it
|
|
1207
|
-
// is an activated, disable its listeners
|
|
1208
|
-
handleDeletedChild(child, p);
|
|
1209
|
-
}
|
|
1210
|
-
if (idField) {
|
|
1211
|
-
const key = isIdFieldFunction
|
|
1212
|
-
? idField(p)
|
|
1213
|
-
: p[idField];
|
|
1214
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
1215
|
-
if (keysSeen.has(key)) {
|
|
1216
|
-
console.warn(`[legend-state] Warning: Multiple elements in array have the same ID. Key field: ${idField}, Array:`, prevValue);
|
|
1217
|
-
}
|
|
1218
|
-
keysSeen.add(key);
|
|
1219
|
-
}
|
|
1220
|
-
prevChildrenById.set(key, child);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
else if (prevValue && (!obj || isObject(obj))) {
|
|
1230
|
-
// For keys that have been removed from object, notify and update children recursively
|
|
1231
|
-
const lengthPrev = keysPrev.length;
|
|
1232
|
-
for (let i = 0; i < lengthPrev; i++) {
|
|
1233
|
-
const key = keysPrev[i];
|
|
1234
|
-
if (!keys.includes(key)) {
|
|
1235
|
-
hasADiff = true;
|
|
1236
|
-
const child = getChildNode(parent, key);
|
|
1237
|
-
const prev = isPrevMap ? prevValue.get(key) : prevValue[key];
|
|
1238
|
-
if (prev !== undefined) {
|
|
1239
|
-
handleDeletedChild(child, prev);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
if (obj && !isPrimitive(obj)) {
|
|
1245
|
-
hasADiff = hasADiff || length !== lengthPrev;
|
|
1246
|
-
const isArrDiff = hasADiff;
|
|
1247
|
-
let didMove = false;
|
|
1248
|
-
for (let i = 0; i < length; i++) {
|
|
1249
|
-
const key = isArr ? i + '' : keys[i];
|
|
1250
|
-
let value = isCurMap ? obj.get(key) : obj[key];
|
|
1251
|
-
const prev = isPrevMap ? prevValue === null || prevValue === void 0 ? void 0 : prevValue.get(key) : prevValue === null || prevValue === void 0 ? void 0 : prevValue[key];
|
|
1252
|
-
let isDiff = !equals(value, prev);
|
|
1253
|
-
if (isDiff) {
|
|
1254
|
-
const id = idField && value
|
|
1255
|
-
? isIdFieldFunction
|
|
1256
|
-
? idField(value)
|
|
1257
|
-
: value[idField]
|
|
1258
|
-
: undefined;
|
|
1259
|
-
const existingChild = (_c = parent.children) === null || _c === void 0 ? void 0 : _c.get(key);
|
|
1260
|
-
if (isObservable(value)) {
|
|
1261
|
-
const valueNode = getNode(value);
|
|
1262
|
-
if ((existingChild === null || existingChild === void 0 ? void 0 : existingChild.linkedToNode) === valueNode) {
|
|
1263
|
-
const targetValue = getNodeValue(valueNode);
|
|
1264
|
-
isCurMap ? obj.set(key, targetValue) : (obj[key] = targetValue);
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
const obs = value;
|
|
1268
|
-
value = () => obs;
|
|
1269
|
-
}
|
|
1270
|
-
let child = getChildNode(parent, key, value);
|
|
1271
|
-
if (!child.lazy && (isFunction(value) || isObservable(value))) {
|
|
1272
|
-
reactivateNode(child, value);
|
|
1273
|
-
peekInternal(child);
|
|
1274
|
-
}
|
|
1275
|
-
// Detect moves within an array. Need to move the original proxy to the new position to keep
|
|
1276
|
-
// the proxy stable, so that listeners to this node will be unaffected by the array shift.
|
|
1277
|
-
if (isArr && id !== undefined) {
|
|
1278
|
-
// Find the previous position of this element in the array
|
|
1279
|
-
const prevChild = id !== undefined ? prevChildrenById === null || prevChildrenById === void 0 ? void 0 : prevChildrenById.get(id) : undefined;
|
|
1280
|
-
if (!prevChild) {
|
|
1281
|
-
// This id was not in the array before so it does not need to notify children
|
|
1282
|
-
// It does need to notify itself so isDiff should remain.
|
|
1283
|
-
hasADiff = true;
|
|
1284
|
-
}
|
|
1285
|
-
else if (prevChild !== undefined && prevChild.key !== key) {
|
|
1286
|
-
const valuePrevChild = prevValue[prevChild.key];
|
|
1287
|
-
// If array length changed then move the original node to the current position.
|
|
1288
|
-
// That should be faster than notifying every single element that
|
|
1289
|
-
// it's in a new position.
|
|
1290
|
-
if (isArrDiff) {
|
|
1291
|
-
child = prevChild;
|
|
1292
|
-
parent.children.delete(child.key);
|
|
1293
|
-
child.key = key;
|
|
1294
|
-
moved.push([key, child]);
|
|
1295
|
-
}
|
|
1296
|
-
didMove = true;
|
|
1297
|
-
// And check for diff against the previous value in the previous position
|
|
1298
|
-
isDiff = valuePrevChild !== value;
|
|
1299
|
-
}
|
|
1110
|
+
var _a, _b, _c;
|
|
1111
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && isObject(obj)) {
|
|
1112
|
+
if (__devUpdateNodes.has(obj)) {
|
|
1113
|
+
console.error(
|
|
1114
|
+
"[legend-state] Circular reference detected in object. You may want to use opaqueObject to stop traversing child nodes.",
|
|
1115
|
+
obj
|
|
1116
|
+
);
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
__devUpdateNodes.add(obj);
|
|
1120
|
+
}
|
|
1121
|
+
if (isObject(obj) && obj[symbolOpaque] || isObject(prevValue) && prevValue[symbolOpaque]) {
|
|
1122
|
+
const isDiff = obj !== prevValue;
|
|
1123
|
+
if (isDiff) {
|
|
1124
|
+
if (parent.listeners || parent.listenersImmediate) {
|
|
1125
|
+
notify(parent, obj, prevValue, 0);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && obj !== void 0) {
|
|
1129
|
+
__devUpdateNodes.delete(obj);
|
|
1130
|
+
}
|
|
1131
|
+
return isDiff;
|
|
1132
|
+
}
|
|
1133
|
+
const isArr = isArray(obj);
|
|
1134
|
+
let prevChildrenById;
|
|
1135
|
+
let moved;
|
|
1136
|
+
const isCurMap = isMap(obj);
|
|
1137
|
+
const isPrevMap = isMap(prevValue);
|
|
1138
|
+
const keys = getKeys(obj, isArr, isCurMap);
|
|
1139
|
+
const keysPrev = getKeys(prevValue, isArr, isPrevMap);
|
|
1140
|
+
const length = ((_a = keys || obj) == null ? void 0 : _a.length) || 0;
|
|
1141
|
+
const lengthPrev = ((_b = keysPrev || prevValue) == null ? void 0 : _b.length) || 0;
|
|
1142
|
+
let idField;
|
|
1143
|
+
let isIdFieldFunction;
|
|
1144
|
+
let hasADiff = false;
|
|
1145
|
+
let retValue;
|
|
1146
|
+
if (isArr && isArray(prevValue)) {
|
|
1147
|
+
if (prevValue.length > 0) {
|
|
1148
|
+
const firstPrevValue = prevValue[0];
|
|
1149
|
+
if (firstPrevValue !== void 0) {
|
|
1150
|
+
idField = findIDKey(firstPrevValue, parent);
|
|
1151
|
+
if (idField) {
|
|
1152
|
+
isIdFieldFunction = isFunction(idField);
|
|
1153
|
+
prevChildrenById = /* @__PURE__ */ new Map();
|
|
1154
|
+
moved = [];
|
|
1155
|
+
}
|
|
1156
|
+
const keysSeen = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" ? /* @__PURE__ */ new Set() : void 0;
|
|
1157
|
+
if (parent.children) {
|
|
1158
|
+
for (let i = 0; i < prevValue.length; i++) {
|
|
1159
|
+
const p = prevValue[i];
|
|
1160
|
+
if (p) {
|
|
1161
|
+
const child = parent.children.get(i + "");
|
|
1162
|
+
if (child) {
|
|
1163
|
+
if (!obj[i]) {
|
|
1164
|
+
handleDeletedChild(child, p);
|
|
1300
1165
|
}
|
|
1301
|
-
if (
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
if (
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1310
|
-
else {
|
|
1311
|
-
// Always need to updateNodes so we notify through all children
|
|
1312
|
-
const updatedNodes = updateNodes(child, value, prev);
|
|
1313
|
-
hasADiff = hasADiff || updatedNodes;
|
|
1314
|
-
isDiff = updatedNodes;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
if (isDiff || (isArr && !isArrDiff)) {
|
|
1318
|
-
// Notify for this child if this element is different and it has listeners
|
|
1319
|
-
// Or if the position changed in an array whose length did not change
|
|
1320
|
-
// But do not notify child if the parent is an array with changing length -
|
|
1321
|
-
// the array's listener will cover it
|
|
1322
|
-
if (child.listeners || child.listenersImmediate) {
|
|
1323
|
-
notify(child, value, prev, 0, !isArrDiff);
|
|
1166
|
+
if (idField) {
|
|
1167
|
+
const key = isIdFieldFunction ? idField(p) : p[idField];
|
|
1168
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
1169
|
+
if (keysSeen.has(key)) {
|
|
1170
|
+
console.warn(
|
|
1171
|
+
`[legend-state] Warning: Multiple elements in array have the same ID. Key field: ${idField}, Array:`,
|
|
1172
|
+
prevValue
|
|
1173
|
+
);
|
|
1324
1174
|
}
|
|
1175
|
+
keysSeen.add(key);
|
|
1176
|
+
}
|
|
1177
|
+
prevChildrenById.set(key, child);
|
|
1325
1178
|
}
|
|
1179
|
+
}
|
|
1326
1180
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
} else if (prevValue && (!obj || isObject(obj))) {
|
|
1186
|
+
const lengthPrev2 = keysPrev.length;
|
|
1187
|
+
for (let i = 0; i < lengthPrev2; i++) {
|
|
1188
|
+
const key = keysPrev[i];
|
|
1189
|
+
if (!keys.includes(key)) {
|
|
1190
|
+
hasADiff = true;
|
|
1191
|
+
const child = getChildNode(parent, key);
|
|
1192
|
+
const prev = isPrevMap ? prevValue.get(key) : prevValue[key];
|
|
1193
|
+
if (prev !== void 0) {
|
|
1194
|
+
handleDeletedChild(child, prev);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (obj && !isPrimitive(obj)) {
|
|
1200
|
+
hasADiff = hasADiff || length !== lengthPrev;
|
|
1201
|
+
const isArrDiff = hasADiff;
|
|
1202
|
+
let didMove = false;
|
|
1203
|
+
for (let i = 0; i < length; i++) {
|
|
1204
|
+
const key = isArr ? i + "" : keys[i];
|
|
1205
|
+
let value = isCurMap ? obj.get(key) : obj[key];
|
|
1206
|
+
const prev = isPrevMap ? prevValue == null ? void 0 : prevValue.get(key) : prevValue == null ? void 0 : prevValue[key];
|
|
1207
|
+
let isDiff = !equals(value, prev);
|
|
1208
|
+
if (isDiff) {
|
|
1209
|
+
const id = idField && value ? isIdFieldFunction ? idField(value) : value[idField] : void 0;
|
|
1210
|
+
const existingChild = (_c = parent.children) == null ? void 0 : _c.get(key);
|
|
1211
|
+
if (isObservable(value)) {
|
|
1212
|
+
const valueNode = getNode(value);
|
|
1213
|
+
if ((existingChild == null ? void 0 : existingChild.linkedToNode) === valueNode) {
|
|
1214
|
+
const targetValue = getNodeValue(valueNode);
|
|
1215
|
+
isCurMap ? obj.set(key, targetValue) : obj[key] = targetValue;
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
const obs = value;
|
|
1219
|
+
value = () => obs;
|
|
1220
|
+
}
|
|
1221
|
+
let child = getChildNode(parent, key, value);
|
|
1222
|
+
if (!child.lazy && (isFunction(value) || isObservable(value))) {
|
|
1223
|
+
reactivateNode(child, value);
|
|
1224
|
+
peekInternal(child);
|
|
1225
|
+
}
|
|
1226
|
+
if (isArr && id !== void 0) {
|
|
1227
|
+
const prevChild = id !== void 0 ? prevChildrenById == null ? void 0 : prevChildrenById.get(id) : void 0;
|
|
1228
|
+
if (!prevChild) {
|
|
1229
|
+
hasADiff = true;
|
|
1230
|
+
} else if (prevChild !== void 0 && prevChild.key !== key) {
|
|
1231
|
+
const valuePrevChild = prevValue[prevChild.key];
|
|
1232
|
+
if (isArrDiff) {
|
|
1233
|
+
child = prevChild;
|
|
1234
|
+
parent.children.delete(child.key);
|
|
1235
|
+
child.key = key;
|
|
1236
|
+
moved.push([key, child]);
|
|
1332
1237
|
}
|
|
1238
|
+
didMove = true;
|
|
1239
|
+
isDiff = valuePrevChild !== value;
|
|
1240
|
+
}
|
|
1333
1241
|
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1242
|
+
if (isDiff) {
|
|
1243
|
+
if (isFunction(value) || isObservable(value)) {
|
|
1244
|
+
extractFunctionOrComputed(parent, key, value);
|
|
1245
|
+
} else if (isPrimitive(value)) {
|
|
1246
|
+
hasADiff = true;
|
|
1247
|
+
} else {
|
|
1248
|
+
const updatedNodes = updateNodes(child, value, prev);
|
|
1249
|
+
hasADiff = hasADiff || updatedNodes;
|
|
1250
|
+
isDiff = updatedNodes;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (isDiff || isArr && !isArrDiff) {
|
|
1254
|
+
if (child.listeners || child.listenersImmediate) {
|
|
1255
|
+
notify(child, value, prev, 0, !isArrDiff);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (moved) {
|
|
1261
|
+
for (let i = 0; i < moved.length; i++) {
|
|
1262
|
+
const [key, child] = moved[i];
|
|
1263
|
+
parent.children.set(key, child);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
retValue = hasADiff || didMove;
|
|
1267
|
+
} else if (prevValue !== void 0) {
|
|
1268
|
+
retValue = true;
|
|
1269
|
+
}
|
|
1270
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && obj !== void 0) {
|
|
1271
|
+
__devUpdateNodes.delete(obj);
|
|
1272
|
+
}
|
|
1273
|
+
return retValue != null ? retValue : false;
|
|
1348
1274
|
}
|
|
1349
1275
|
function handleDeletedChild(child, p) {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
(
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
notify(child, undefined, p, 0);
|
|
1360
|
-
}
|
|
1276
|
+
var _a, _b;
|
|
1277
|
+
(_a = child.linkedToNodeDispose) == null ? void 0 : _a.call(child);
|
|
1278
|
+
(_b = child.activatedObserveDispose) == null ? void 0 : _b.call(child);
|
|
1279
|
+
if (!isPrimitive(p)) {
|
|
1280
|
+
updateNodes(child, void 0, p);
|
|
1281
|
+
}
|
|
1282
|
+
if (child.listeners || child.listenersImmediate) {
|
|
1283
|
+
notify(child, void 0, p, 0);
|
|
1284
|
+
}
|
|
1361
1285
|
}
|
|
1362
1286
|
function getProxy(node, p, asFunction) {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
// Create a proxy if not already cached and return it
|
|
1367
|
-
return (node.proxy || (node.proxy = new Proxy(node, proxyHandler)));
|
|
1287
|
+
if (p !== void 0)
|
|
1288
|
+
node = getChildNode(node, p, asFunction);
|
|
1289
|
+
return node.proxy || (node.proxy = new Proxy(node, proxyHandler));
|
|
1368
1290
|
}
|
|
1369
1291
|
function flushPending() {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1292
|
+
if (globalState.pendingNodes.size > 0) {
|
|
1293
|
+
const nodes = Array.from(globalState.pendingNodes.values());
|
|
1294
|
+
globalState.pendingNodes.clear();
|
|
1295
|
+
nodes.forEach((fn) => fn());
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
var proxyHandler = {
|
|
1299
|
+
get(node, p, receiver) {
|
|
1300
|
+
var _a, _b;
|
|
1301
|
+
if (p === symbolToPrimitive) {
|
|
1302
|
+
throw new Error(
|
|
1303
|
+
process.env.NODE_ENV === "development" ? "[legend-state] observable should not be used as a primitive. You may have forgotten to use .get() or .peek() to get the value of the observable." : "[legend-state] observable is not a primitive."
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
if (p === symbolGetNode) {
|
|
1307
|
+
return node;
|
|
1308
|
+
}
|
|
1309
|
+
if (p === "apply") {
|
|
1310
|
+
const nodeValue = getNodeValue(node);
|
|
1311
|
+
if (isFunction(nodeValue)) {
|
|
1312
|
+
return nodeValue.apply;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
let value = peekInternal(
|
|
1316
|
+
node,
|
|
1317
|
+
/*activateRecursive*/
|
|
1318
|
+
p === "get" || p === "peek"
|
|
1319
|
+
);
|
|
1320
|
+
const targetNode = node.linkedToNode || (value == null ? void 0 : value[symbolGetNode]);
|
|
1321
|
+
if (targetNode && p !== "onChange") {
|
|
1322
|
+
return proxyHandler.get(targetNode, p, receiver);
|
|
1323
|
+
}
|
|
1324
|
+
if (isMap(value) || value instanceof WeakMap || value instanceof Set || value instanceof WeakSet) {
|
|
1325
|
+
const ret = handlerMapSet(node, p, value);
|
|
1326
|
+
if (ret !== void 0) {
|
|
1327
|
+
return ret;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
const fn = observableFns.get(p);
|
|
1331
|
+
if (fn) {
|
|
1332
|
+
if (p === "get" || p === "peek") {
|
|
1333
|
+
flushPending();
|
|
1334
|
+
}
|
|
1335
|
+
return function(a, b, c) {
|
|
1336
|
+
const l = arguments.length;
|
|
1337
|
+
switch (l) {
|
|
1338
|
+
case 0:
|
|
1339
|
+
return fn(node);
|
|
1340
|
+
case 1:
|
|
1341
|
+
return fn(node, a);
|
|
1342
|
+
case 2:
|
|
1343
|
+
return fn(node, a, b);
|
|
1344
|
+
default:
|
|
1345
|
+
return fn(node, a, b, c);
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
const property = observableProperties.get(p);
|
|
1350
|
+
if (property) {
|
|
1351
|
+
return property.get(node);
|
|
1352
|
+
}
|
|
1353
|
+
let vProp = value == null ? void 0 : value[p];
|
|
1354
|
+
if (isObject(value) && value[symbolOpaque]) {
|
|
1355
|
+
return vProp;
|
|
1356
|
+
}
|
|
1357
|
+
const fnOrComputed = (_a = node.functions) == null ? void 0 : _a.get(p);
|
|
1358
|
+
if (fnOrComputed) {
|
|
1359
|
+
if (isObservable(fnOrComputed)) {
|
|
1360
|
+
return fnOrComputed;
|
|
1361
|
+
} else {
|
|
1362
|
+
return getProxy(node, p, fnOrComputed);
|
|
1363
|
+
}
|
|
1364
|
+
} else {
|
|
1365
|
+
vProp = checkProperty(value, p);
|
|
1366
|
+
}
|
|
1367
|
+
if (isNullOrUndefined(value) && vProp === void 0 && (ArrayModifiers.has(p) || ArrayLoopers.has(p))) {
|
|
1368
|
+
value = [];
|
|
1369
|
+
setNodeValue(node, value);
|
|
1370
|
+
vProp = value[p];
|
|
1371
|
+
}
|
|
1372
|
+
if (isFunction(vProp)) {
|
|
1373
|
+
if (isArray(value)) {
|
|
1374
|
+
if (ArrayModifiers.has(p)) {
|
|
1375
|
+
return (...args) => collectionSetter(node, value, p, ...args);
|
|
1376
|
+
} else if (ArrayLoopers.has(p)) {
|
|
1377
|
+
updateTracking(node, true);
|
|
1378
|
+
return function(cbOrig, thisArg) {
|
|
1379
|
+
const isReduce = p === "reduce";
|
|
1380
|
+
const cbWrapped = isReduce ? (previousValue, currentValue, currentIndex, array) => {
|
|
1381
|
+
return cbOrig(
|
|
1382
|
+
previousValue,
|
|
1383
|
+
getProxy(node, currentIndex + "", currentValue),
|
|
1384
|
+
currentIndex,
|
|
1385
|
+
array
|
|
1386
|
+
);
|
|
1387
|
+
} : (val, index, array) => {
|
|
1388
|
+
return cbOrig(getProxy(node, index + "", val), index, array);
|
|
1430
1389
|
};
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
if (property) {
|
|
1434
|
-
return property.get(node);
|
|
1435
|
-
}
|
|
1436
|
-
let vProp = value === null || value === void 0 ? void 0 : value[p];
|
|
1437
|
-
if (isObject(value) && value[symbolOpaque]) {
|
|
1438
|
-
return vProp;
|
|
1439
|
-
}
|
|
1440
|
-
const fnOrComputed = (_a = node.functions) === null || _a === void 0 ? void 0 : _a.get(p);
|
|
1441
|
-
if (fnOrComputed) {
|
|
1442
|
-
if (isObservable(fnOrComputed)) {
|
|
1443
|
-
return fnOrComputed;
|
|
1390
|
+
if (isReduce || !ArrayLoopersReturn.has(p)) {
|
|
1391
|
+
return value[p](cbWrapped, thisArg);
|
|
1444
1392
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
if (isNullOrUndefined(value) && vProp === undefined && (ArrayModifiers.has(p) || ArrayLoopers.has(p))) {
|
|
1453
|
-
value = [];
|
|
1454
|
-
setNodeValue(node, value);
|
|
1455
|
-
vProp = value[p];
|
|
1456
|
-
}
|
|
1457
|
-
// Handle function calls
|
|
1458
|
-
if (isFunction(vProp)) {
|
|
1459
|
-
if (isArray(value)) {
|
|
1460
|
-
if (ArrayModifiers.has(p)) {
|
|
1461
|
-
// Call the wrapped modifier function
|
|
1462
|
-
return (...args) => collectionSetter(node, value, p, ...args);
|
|
1393
|
+
const isFind = p === "find";
|
|
1394
|
+
const out = [];
|
|
1395
|
+
for (let i = 0; i < value.length; i++) {
|
|
1396
|
+
if (cbWrapped(value[i], i, value)) {
|
|
1397
|
+
const proxy2 = getProxy(node, i + "");
|
|
1398
|
+
if (isFind) {
|
|
1399
|
+
return proxy2;
|
|
1463
1400
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
updateTracking(node, true);
|
|
1467
|
-
return function (cbOrig, thisArg) {
|
|
1468
|
-
const isReduce = p === 'reduce';
|
|
1469
|
-
// Callbacks are given the Proxy rather than the underlying data
|
|
1470
|
-
const cbWrapped = isReduce
|
|
1471
|
-
? (previousValue, currentValue, currentIndex, array) => {
|
|
1472
|
-
return cbOrig(previousValue, getProxy(node, currentIndex + '', currentValue), currentIndex, array);
|
|
1473
|
-
}
|
|
1474
|
-
: (val, index, array) => {
|
|
1475
|
-
return cbOrig(getProxy(node, index + '', val), index, array);
|
|
1476
|
-
};
|
|
1477
|
-
if (isReduce || !ArrayLoopersReturn.has(p)) {
|
|
1478
|
-
return value[p](cbWrapped, thisArg);
|
|
1479
|
-
}
|
|
1480
|
-
const isFind = p === 'find';
|
|
1481
|
-
const out = [];
|
|
1482
|
-
for (let i = 0; i < value.length; i++) {
|
|
1483
|
-
if (cbWrapped(value[i], i, value)) {
|
|
1484
|
-
const proxy = getProxy(node, i + '');
|
|
1485
|
-
// find returns the first match, otherwise it returns an array
|
|
1486
|
-
if (isFind) {
|
|
1487
|
-
return proxy;
|
|
1488
|
-
}
|
|
1489
|
-
out.push(proxy);
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
return isFind ? undefined : out;
|
|
1493
|
-
};
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
extractFunctionOrComputed(node, p, vProp);
|
|
1497
|
-
const fnOrComputed2 = (_b = node.functions) === null || _b === void 0 ? void 0 : _b.get(p);
|
|
1498
|
-
if (fnOrComputed2) {
|
|
1499
|
-
return getProxy(node, p, fnOrComputed2);
|
|
1500
|
-
}
|
|
1501
|
-
// Return the function bound to the value
|
|
1502
|
-
return vProp.bind(value);
|
|
1503
|
-
}
|
|
1504
|
-
// Accessing primitive returns the raw value
|
|
1505
|
-
if (isPrimitive(vProp)) {
|
|
1506
|
-
// Update that this primitive node was accessed for observers
|
|
1507
|
-
if (isArray(value) && p === 'length') {
|
|
1508
|
-
updateTracking(node, true);
|
|
1509
|
-
return vProp;
|
|
1401
|
+
out.push(proxy2);
|
|
1402
|
+
}
|
|
1510
1403
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
return
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1404
|
+
return isFind ? void 0 : out;
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
extractFunctionOrComputed(node, p, vProp);
|
|
1409
|
+
const fnOrComputed2 = (_b = node.functions) == null ? void 0 : _b.get(p);
|
|
1410
|
+
if (fnOrComputed2) {
|
|
1411
|
+
return getProxy(node, p, fnOrComputed2);
|
|
1412
|
+
}
|
|
1413
|
+
return vProp.bind(value);
|
|
1414
|
+
}
|
|
1415
|
+
if (isPrimitive(vProp)) {
|
|
1416
|
+
if (isArray(value) && p === "length") {
|
|
1417
|
+
updateTracking(node, true);
|
|
1418
|
+
return vProp;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return getProxy(node, p);
|
|
1422
|
+
},
|
|
1423
|
+
// Forward all proxy properties to the target's value
|
|
1424
|
+
getPrototypeOf(node) {
|
|
1425
|
+
const value = getNodeValue(node);
|
|
1426
|
+
return value !== null && typeof value === "object" ? Reflect.getPrototypeOf(value) : null;
|
|
1427
|
+
},
|
|
1428
|
+
ownKeys(node) {
|
|
1429
|
+
peekInternal(node);
|
|
1430
|
+
const value = get(node, true);
|
|
1431
|
+
if (isPrimitive(value))
|
|
1432
|
+
return [];
|
|
1433
|
+
const keys = value ? Reflect.ownKeys(value) : [];
|
|
1434
|
+
if (isArray(value) && keys[keys.length - 1] === "length") {
|
|
1435
|
+
keys.splice(keys.length - 1, 1);
|
|
1436
|
+
}
|
|
1437
|
+
if (isFunction(node)) {
|
|
1438
|
+
const reflectedKeys = Reflect.ownKeys(node);
|
|
1439
|
+
["caller", "arguments", "prototype"].forEach((key) => reflectedKeys.includes(key) && keys.push(key));
|
|
1440
|
+
}
|
|
1441
|
+
return keys;
|
|
1442
|
+
},
|
|
1443
|
+
getOwnPropertyDescriptor(node, prop) {
|
|
1444
|
+
if (prop === "caller" || prop === "arguments" || prop === "prototype") {
|
|
1445
|
+
return { configurable: false, enumerable: false };
|
|
1446
|
+
}
|
|
1447
|
+
const value = getNodeValue(node);
|
|
1448
|
+
return isPrimitive(value) ? void 0 : Reflect.getOwnPropertyDescriptor(value, prop);
|
|
1449
|
+
},
|
|
1450
|
+
set(node, prop, value) {
|
|
1451
|
+
if (node.isSetting) {
|
|
1452
|
+
return Reflect.set(node, prop, value);
|
|
1453
|
+
}
|
|
1454
|
+
if (node.isAssigning) {
|
|
1455
|
+
setKey(node, prop, value);
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
const property = observableProperties.get(prop);
|
|
1459
|
+
if (property) {
|
|
1460
|
+
property.set(node, value);
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
if (process.env.NODE_ENV === "development") {
|
|
1464
|
+
console.warn("[legend-state]: Error: Cannot set a value directly:", prop, value);
|
|
1465
|
+
}
|
|
1466
|
+
return false;
|
|
1467
|
+
},
|
|
1468
|
+
deleteProperty(node, prop) {
|
|
1469
|
+
if (node.isSetting) {
|
|
1470
|
+
return Reflect.deleteProperty(node, prop);
|
|
1471
|
+
} else {
|
|
1472
|
+
if (process.env.NODE_ENV === "development") {
|
|
1473
|
+
console.warn("[legend-state]: Error: Cannot delete a value directly:", prop);
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
},
|
|
1478
|
+
has(node, prop) {
|
|
1479
|
+
const value = getNodeValue(node);
|
|
1480
|
+
return Reflect.has(value, prop);
|
|
1481
|
+
},
|
|
1482
|
+
apply(target, thisArg, argArray) {
|
|
1483
|
+
if (isObservable(thisArg)) {
|
|
1484
|
+
thisArg = thisArg.peek();
|
|
1485
|
+
}
|
|
1486
|
+
return Reflect.apply(target.lazyFn || target, thisArg, argArray);
|
|
1487
|
+
}
|
|
1589
1488
|
};
|
|
1590
1489
|
function set(node, newValue) {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1490
|
+
if (node.parent) {
|
|
1491
|
+
setKey(node.parent, node.key, newValue);
|
|
1492
|
+
} else {
|
|
1493
|
+
setKey(node, "_", newValue);
|
|
1494
|
+
}
|
|
1597
1495
|
}
|
|
1598
1496
|
function toggle(node) {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
}
|
|
1497
|
+
const value = getNodeValue(node);
|
|
1498
|
+
if (value === void 0 || value === null || isBoolean(value)) {
|
|
1499
|
+
set(node, !value);
|
|
1500
|
+
} else if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
1501
|
+
throw new Error("[legend-state] Cannot toggle a non-boolean value");
|
|
1502
|
+
}
|
|
1606
1503
|
}
|
|
1607
1504
|
function setKey(node, key, newValue, level) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1632
|
-
extractFunctionOrComputed(node, key, savedValue);
|
|
1633
|
-
}
|
|
1505
|
+
if (process.env.NODE_ENV === "development") {
|
|
1506
|
+
if (typeof HTMLElement !== "undefined" && newValue instanceof HTMLElement) {
|
|
1507
|
+
console.warn(`[legend-state] Set an HTMLElement into state. You probably don't want to do that.`);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
const isRoot = !node.parent && key === "_";
|
|
1511
|
+
if (node.parent && !getNodeValue(node) && !isFunction(newValue)) {
|
|
1512
|
+
set(node, { [key]: newValue });
|
|
1513
|
+
}
|
|
1514
|
+
const childNode = isRoot ? node : getChildNode(node, key, newValue);
|
|
1515
|
+
if (isObservable(newValue)) {
|
|
1516
|
+
setToObservable(childNode, newValue);
|
|
1517
|
+
} else {
|
|
1518
|
+
const { newValue: savedValue, prevValue } = setNodeValue(childNode, newValue);
|
|
1519
|
+
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1520
|
+
if (!equals(savedValue, prevValue)) {
|
|
1521
|
+
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level);
|
|
1522
|
+
}
|
|
1523
|
+
if (!isPrim) {
|
|
1524
|
+
childNode.needsExtract = true;
|
|
1525
|
+
}
|
|
1526
|
+
extractFunctionOrComputed(node, key, savedValue);
|
|
1527
|
+
}
|
|
1634
1528
|
}
|
|
1635
1529
|
function assign(node, value) {
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
Object.assign(proxy, value);
|
|
1653
|
-
}
|
|
1654
|
-
finally {
|
|
1655
|
-
node.isAssigning--;
|
|
1656
|
-
}
|
|
1530
|
+
const proxy2 = getProxy(node);
|
|
1531
|
+
beginBatch();
|
|
1532
|
+
if (isPrimitive(node.root._)) {
|
|
1533
|
+
node.root._ = {};
|
|
1534
|
+
}
|
|
1535
|
+
if (isMap(value)) {
|
|
1536
|
+
const currentValue = getNodeValue(node);
|
|
1537
|
+
if (isMap(currentValue)) {
|
|
1538
|
+
value.forEach((value2, key) => currentValue.set(key, value2));
|
|
1539
|
+
}
|
|
1540
|
+
} else {
|
|
1541
|
+
node.isAssigning = (node.isAssigning || 0) + 1;
|
|
1542
|
+
try {
|
|
1543
|
+
Object.assign(proxy2, value);
|
|
1544
|
+
} finally {
|
|
1545
|
+
node.isAssigning--;
|
|
1657
1546
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1547
|
+
}
|
|
1548
|
+
endBatch();
|
|
1549
|
+
return proxy2;
|
|
1660
1550
|
}
|
|
1661
1551
|
function deleteFn(node, key) {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1552
|
+
if (key === void 0 && isChildNodeValue(node)) {
|
|
1553
|
+
key = node.key;
|
|
1554
|
+
node = node.parent;
|
|
1555
|
+
}
|
|
1556
|
+
const value = getNodeValue(node);
|
|
1557
|
+
if (isArray(value)) {
|
|
1558
|
+
collectionSetter(node, value, "splice", key, 1);
|
|
1559
|
+
} else {
|
|
1560
|
+
setKey(
|
|
1561
|
+
node,
|
|
1562
|
+
key != null ? key : "_",
|
|
1563
|
+
symbolDelete,
|
|
1564
|
+
/*level*/
|
|
1565
|
+
-1
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1674
1568
|
}
|
|
1675
1569
|
function handlerMapSet(node, p, value) {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return fn(node, a);
|
|
1741
|
-
case 2:
|
|
1742
|
-
return fn(node, a, b);
|
|
1743
|
-
default:
|
|
1744
|
-
return fn(node, a, b, c);
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
else {
|
|
1748
|
-
return value[p](a, b);
|
|
1749
|
-
}
|
|
1750
|
-
};
|
|
1751
|
-
}
|
|
1570
|
+
const vProp = value == null ? void 0 : value[p];
|
|
1571
|
+
if (p === "size") {
|
|
1572
|
+
return getProxy(node, p);
|
|
1573
|
+
} else if (isFunction(vProp)) {
|
|
1574
|
+
return function(a, b, c) {
|
|
1575
|
+
const l = arguments.length;
|
|
1576
|
+
const valueMap = value;
|
|
1577
|
+
if (p === "get") {
|
|
1578
|
+
if (l > 0 && typeof a !== "boolean" && a !== optimized) {
|
|
1579
|
+
return getProxy(node, a);
|
|
1580
|
+
}
|
|
1581
|
+
} else if (p === "set") {
|
|
1582
|
+
if (l === 2) {
|
|
1583
|
+
const prev = valueMap.get(a);
|
|
1584
|
+
const ret = valueMap.set(a, b);
|
|
1585
|
+
if (prev !== b) {
|
|
1586
|
+
updateNodesAndNotify(getChildNode(node, a), b, prev);
|
|
1587
|
+
}
|
|
1588
|
+
return ret;
|
|
1589
|
+
} else if (l === 1 && isMap(value)) {
|
|
1590
|
+
set(node, a);
|
|
1591
|
+
}
|
|
1592
|
+
} else if (p === "delete") {
|
|
1593
|
+
if (l > 0) {
|
|
1594
|
+
const prev = value.get ? valueMap.get(a) : a;
|
|
1595
|
+
const ret = value.delete(a);
|
|
1596
|
+
if (ret) {
|
|
1597
|
+
updateNodesAndNotify(getChildNode(node, a), void 0, prev);
|
|
1598
|
+
}
|
|
1599
|
+
return ret;
|
|
1600
|
+
}
|
|
1601
|
+
} else if (p === "clear") {
|
|
1602
|
+
const prev = new Map(valueMap);
|
|
1603
|
+
const size = valueMap.size;
|
|
1604
|
+
valueMap.clear();
|
|
1605
|
+
if (size) {
|
|
1606
|
+
updateNodesAndNotify(node, value, prev);
|
|
1607
|
+
}
|
|
1608
|
+
return;
|
|
1609
|
+
} else if (p === "add") {
|
|
1610
|
+
const prev = new Set(value);
|
|
1611
|
+
const ret = value.add(a);
|
|
1612
|
+
if (!value.has(p)) {
|
|
1613
|
+
notify(node, ret, prev, 0);
|
|
1614
|
+
}
|
|
1615
|
+
return ret;
|
|
1616
|
+
}
|
|
1617
|
+
const fn = observableFns.get(p);
|
|
1618
|
+
if (fn) {
|
|
1619
|
+
switch (l) {
|
|
1620
|
+
case 0:
|
|
1621
|
+
return fn(node);
|
|
1622
|
+
case 1:
|
|
1623
|
+
return fn(node, a);
|
|
1624
|
+
case 2:
|
|
1625
|
+
return fn(node, a, b);
|
|
1626
|
+
default:
|
|
1627
|
+
return fn(node, a, b, c);
|
|
1628
|
+
}
|
|
1629
|
+
} else {
|
|
1630
|
+
return value[p](a, b);
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1752
1634
|
}
|
|
1753
1635
|
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1636
|
+
if (!childNode)
|
|
1637
|
+
childNode = node;
|
|
1638
|
+
beginBatch();
|
|
1639
|
+
if (isPrim === void 0) {
|
|
1640
|
+
isPrim = isPrimitive(newValue);
|
|
1641
|
+
}
|
|
1642
|
+
let hasADiff = isPrim;
|
|
1643
|
+
let whenOptimizedOnlyIf = false;
|
|
1644
|
+
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1645
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1646
|
+
__devUpdateNodes.clear();
|
|
1647
|
+
}
|
|
1648
|
+
hasADiff = updateNodes(childNode, newValue, prevValue);
|
|
1649
|
+
if (isArray(newValue)) {
|
|
1650
|
+
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
if (isPrim || !newValue || isEmpty(newValue) && !isEmpty(prevValue) ? newValue !== prevValue : hasADiff) {
|
|
1654
|
+
notify(
|
|
1655
|
+
isPrim && isRoot ? node : childNode,
|
|
1656
|
+
newValue,
|
|
1657
|
+
prevValue,
|
|
1658
|
+
(level != null ? level : prevValue === void 0) ? -1 : hasADiff ? 0 : 1,
|
|
1659
|
+
whenOptimizedOnlyIf
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
endBatch();
|
|
1779
1663
|
}
|
|
1780
1664
|
function extractPromise(node, value, setter) {
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1665
|
+
if (!node.state) {
|
|
1666
|
+
node.state = createObservable(
|
|
1667
|
+
{
|
|
1668
|
+
isLoaded: false
|
|
1669
|
+
},
|
|
1670
|
+
false,
|
|
1671
|
+
extractPromise,
|
|
1672
|
+
getProxy
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
value.then((value2) => {
|
|
1676
|
+
setter ? setter({ value: value2 }) : set(node, value2);
|
|
1677
|
+
node.state.assign({
|
|
1678
|
+
isLoaded: true,
|
|
1679
|
+
error: void 0
|
|
1796
1680
|
});
|
|
1681
|
+
}).catch((error) => {
|
|
1682
|
+
node.state.error.set(error);
|
|
1683
|
+
});
|
|
1797
1684
|
}
|
|
1798
1685
|
function extractFunctionOrComputed(node, k, v) {
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
}
|
|
1817
|
-
else if (typeof v === 'function') {
|
|
1818
|
-
extractFunction(node, k, v);
|
|
1819
|
-
return k;
|
|
1820
|
-
}
|
|
1686
|
+
if (isPromise(v)) {
|
|
1687
|
+
const childNode = getChildNode(node, k);
|
|
1688
|
+
extractPromise(childNode, v);
|
|
1689
|
+
setNodeValue(childNode, void 0);
|
|
1690
|
+
return void 0;
|
|
1691
|
+
} else if (isObservable(v)) {
|
|
1692
|
+
const fn = () => v;
|
|
1693
|
+
extractFunction(node, k, fn);
|
|
1694
|
+
const childNode = getChildNode(node, k, fn);
|
|
1695
|
+
const targetNode = getNode(v);
|
|
1696
|
+
const initialValue = peek(targetNode);
|
|
1697
|
+
setNodeValue(childNode, initialValue);
|
|
1698
|
+
return getNodeValue(childNode);
|
|
1699
|
+
} else if (typeof v === "function") {
|
|
1700
|
+
extractFunction(node, k, v);
|
|
1701
|
+
return k;
|
|
1702
|
+
}
|
|
1821
1703
|
}
|
|
1822
1704
|
function get(node, options) {
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
return peek(node);
|
|
1705
|
+
const track = options ? isObject(options) ? options.shallow : options : void 0;
|
|
1706
|
+
updateTracking(node, track);
|
|
1707
|
+
return peek(node);
|
|
1827
1708
|
}
|
|
1828
1709
|
function peek(node) {
|
|
1829
|
-
|
|
1710
|
+
return peekInternal(node, true);
|
|
1830
1711
|
}
|
|
1831
|
-
|
|
1712
|
+
var isFlushing = false;
|
|
1832
1713
|
function peekInternal(node, activateRecursive) {
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
return value;
|
|
1714
|
+
var _a;
|
|
1715
|
+
isFlushing = true;
|
|
1716
|
+
if (activateRecursive && ((_a = node.dirtyChildren) == null ? void 0 : _a.size)) {
|
|
1717
|
+
const dirty = Array.from(node.dirtyChildren);
|
|
1718
|
+
node.dirtyChildren.clear();
|
|
1719
|
+
dirty.forEach((node2) => node2.dirtyFn && peekInternal(node2));
|
|
1720
|
+
}
|
|
1721
|
+
if (node.dirtyFn) {
|
|
1722
|
+
const dirtyFn = node.dirtyFn;
|
|
1723
|
+
node.dirtyFn = void 0;
|
|
1724
|
+
globalState.dirtyNodes.delete(node);
|
|
1725
|
+
dirtyFn();
|
|
1726
|
+
}
|
|
1727
|
+
isFlushing = false;
|
|
1728
|
+
let value = getNodeValue(node);
|
|
1729
|
+
value = checkLazy(node, value, !!activateRecursive);
|
|
1730
|
+
return value;
|
|
1851
1731
|
}
|
|
1852
1732
|
function checkLazy(node, value, activateRecursive) {
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
value = {};
|
|
1863
|
-
}
|
|
1864
|
-
else {
|
|
1865
|
-
if (node.parent) {
|
|
1866
|
-
const parentValue = getNodeValue(node.parent);
|
|
1867
|
-
if (parentValue) {
|
|
1868
|
-
delete parentValue[node.key];
|
|
1869
|
-
}
|
|
1870
|
-
else {
|
|
1871
|
-
node.root._ = undefined;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
value = activateNodeFunction(node, lazyFn);
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
else if (isObservable(value)) {
|
|
1878
|
-
value = extractFunctionOrComputed(node.parent, node.key, value);
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
if ((lazy || node.needsExtract) && !isObservable(value) && !isPrimitive(value)) {
|
|
1882
|
-
// If this is a purposeful get, check descendants for observable or auto activated linked
|
|
1883
|
-
if (activateRecursive) {
|
|
1884
|
-
recursivelyAutoActivate(value, node);
|
|
1885
|
-
}
|
|
1886
|
-
// If this is an extractable node, extract it from parent before it's accessed
|
|
1733
|
+
const origValue = value;
|
|
1734
|
+
const lazy = node.lazy;
|
|
1735
|
+
if (lazy) {
|
|
1736
|
+
const lazyFn = node.lazyFn;
|
|
1737
|
+
delete node.lazy;
|
|
1738
|
+
if (isFunction(lazyFn)) {
|
|
1739
|
+
if (lazyFn.length === 1) {
|
|
1740
|
+
value = {};
|
|
1741
|
+
} else {
|
|
1887
1742
|
if (node.parent) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1743
|
+
const parentValue = getNodeValue(node.parent);
|
|
1744
|
+
if (parentValue) {
|
|
1745
|
+
delete parentValue[node.key];
|
|
1746
|
+
} else {
|
|
1747
|
+
node.root._ = void 0;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
value = activateNodeFunction(node, lazyFn);
|
|
1751
|
+
}
|
|
1752
|
+
} else if (isObservable(value)) {
|
|
1753
|
+
value = extractFunctionOrComputed(node.parent, node.key, value);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
if ((lazy || node.needsExtract) && !isObservable(value) && !isPrimitive(value)) {
|
|
1757
|
+
if (activateRecursive) {
|
|
1758
|
+
recursivelyAutoActivate(value, node);
|
|
1890
1759
|
}
|
|
1891
|
-
|
|
1760
|
+
if (node.parent) {
|
|
1761
|
+
extractFunctionOrComputed(node.parent, node.key, origValue);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
return value;
|
|
1892
1765
|
}
|
|
1893
1766
|
function checkProperty(value, key) {
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
return value[key];
|
|
1906
|
-
}
|
|
1767
|
+
if (value) {
|
|
1768
|
+
const property = Object.getOwnPropertyDescriptor(value, key);
|
|
1769
|
+
if (property == null ? void 0 : property.get) {
|
|
1770
|
+
delete value[key];
|
|
1771
|
+
value[key] = property.set ? linked({
|
|
1772
|
+
get: property.get,
|
|
1773
|
+
set: ({ value: value2 }) => property.set(value2)
|
|
1774
|
+
}) : property.get;
|
|
1775
|
+
}
|
|
1776
|
+
return value[key];
|
|
1777
|
+
}
|
|
1907
1778
|
}
|
|
1908
1779
|
function reactivateNode(node, lazyFn) {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1780
|
+
var _a, _b;
|
|
1781
|
+
(_a = node.activatedObserveDispose) == null ? void 0 : _a.call(node);
|
|
1782
|
+
(_b = node.linkedToNodeDispose) == null ? void 0 : _b.call(node);
|
|
1783
|
+
node.activatedObserveDispose = node.linkedToNodeDispose = node.linkedToNode = void 0;
|
|
1784
|
+
node.lazyFn = lazyFn;
|
|
1785
|
+
node.lazy = true;
|
|
1915
1786
|
}
|
|
1916
1787
|
function isObserved(node) {
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
}
|
|
1924
|
-
parent = parent.parent;
|
|
1788
|
+
var _a, _b;
|
|
1789
|
+
let parent = node;
|
|
1790
|
+
let hasListeners = node.numListenersRecursive > 0;
|
|
1791
|
+
while (parent && !hasListeners) {
|
|
1792
|
+
if (!!((_a = parent.listeners) == null ? void 0 : _a.size) || !!((_b = parent.listenersImmediate) == null ? void 0 : _b.size)) {
|
|
1793
|
+
hasListeners = true;
|
|
1925
1794
|
}
|
|
1926
|
-
|
|
1795
|
+
parent = parent.parent;
|
|
1796
|
+
}
|
|
1797
|
+
return hasListeners;
|
|
1927
1798
|
}
|
|
1928
1799
|
function shouldIgnoreUnobserved(node, refreshFn) {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
}
|
|
1940
|
-
parent.dirtyChildren.add(node);
|
|
1941
|
-
parent = parent.parent;
|
|
1942
|
-
}
|
|
1943
|
-
return true;
|
|
1800
|
+
if (!isFlushing) {
|
|
1801
|
+
const hasListeners = isObserved(node);
|
|
1802
|
+
if (!hasListeners) {
|
|
1803
|
+
if (refreshFn) {
|
|
1804
|
+
node.dirtyFn = refreshFn;
|
|
1805
|
+
}
|
|
1806
|
+
let parent = node;
|
|
1807
|
+
while (parent) {
|
|
1808
|
+
if (!parent.dirtyChildren) {
|
|
1809
|
+
parent.dirtyChildren = /* @__PURE__ */ new Set();
|
|
1944
1810
|
}
|
|
1811
|
+
parent.dirtyChildren.add(node);
|
|
1812
|
+
parent = parent.parent;
|
|
1813
|
+
}
|
|
1814
|
+
return true;
|
|
1945
1815
|
}
|
|
1816
|
+
}
|
|
1946
1817
|
}
|
|
1947
1818
|
function activateNodeFunction(node, lazyFn) {
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
if (!
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
1819
|
+
let update;
|
|
1820
|
+
let wasPromise;
|
|
1821
|
+
let ignoreThisUpdate;
|
|
1822
|
+
let isFirst = true;
|
|
1823
|
+
const activateFn = lazyFn;
|
|
1824
|
+
let activatedValue;
|
|
1825
|
+
let disposes = [];
|
|
1826
|
+
let refreshFn;
|
|
1827
|
+
function markDirty() {
|
|
1828
|
+
node.dirtyFn = refreshFn;
|
|
1829
|
+
globalState.dirtyNodes.add(node);
|
|
1830
|
+
}
|
|
1831
|
+
node.activatedObserveDispose = observe(
|
|
1832
|
+
() => {
|
|
1833
|
+
var _a, _b, _c, _d;
|
|
1834
|
+
if (isFirst) {
|
|
1835
|
+
isFirst = false;
|
|
1836
|
+
setNodeValue(node, void 0);
|
|
1837
|
+
} else if (!isFlushing && refreshFn) {
|
|
1838
|
+
if (shouldIgnoreUnobserved(node, refreshFn)) {
|
|
1839
|
+
ignoreThisUpdate = true;
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
let value = activateFn();
|
|
1844
|
+
let didSetToObs = false;
|
|
1845
|
+
if (isObservable(value)) {
|
|
1846
|
+
didSetToObs = true;
|
|
1847
|
+
value = setToObservable(node, value);
|
|
1848
|
+
}
|
|
1849
|
+
if (isFunction(value)) {
|
|
1850
|
+
value = value();
|
|
1851
|
+
}
|
|
1852
|
+
const activated = !isObservable(value) ? value == null ? void 0 : value[symbolLinked] : void 0;
|
|
1853
|
+
if (activated) {
|
|
1854
|
+
node.activationState = activated;
|
|
1855
|
+
value = void 0;
|
|
1856
|
+
}
|
|
1857
|
+
ignoreThisUpdate = false;
|
|
1858
|
+
wasPromise = isPromise(value);
|
|
1859
|
+
if (!node.activated) {
|
|
1860
|
+
node.activated = true;
|
|
1861
|
+
let activateNodeFn = activateNodeBase;
|
|
1862
|
+
if (activated == null ? void 0 : activated.synced) {
|
|
1863
|
+
activateNodeFn = globalState.activateSyncedNode;
|
|
1864
|
+
ignoreThisUpdate = true;
|
|
1865
|
+
}
|
|
1866
|
+
const result = activateNodeFn(node, value);
|
|
1867
|
+
update = result.update;
|
|
1868
|
+
let newValue = result.value;
|
|
1869
|
+
if (!didSetToObs && isObservable(newValue)) {
|
|
1870
|
+
newValue = setToObservable(node, newValue);
|
|
1871
|
+
}
|
|
1872
|
+
value = newValue != null ? newValue : activated == null ? void 0 : activated.initial;
|
|
1873
|
+
} else if (node.activationState) {
|
|
1874
|
+
const activated2 = node.activationState;
|
|
1875
|
+
if ((_b = (_a = node.state) == null ? void 0 : _a.peek()) == null ? void 0 : _b.sync) {
|
|
1876
|
+
node.state.sync();
|
|
1877
|
+
ignoreThisUpdate = true;
|
|
1878
|
+
} else {
|
|
1879
|
+
value = (_d = (_c = activated2.get) == null ? void 0 : _c.call(activated2)) != null ? _d : activated2.initial;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
wasPromise = wasPromise || isPromise(value);
|
|
1883
|
+
return value;
|
|
1884
|
+
},
|
|
1885
|
+
(e) => {
|
|
1886
|
+
const { value, nodes, refresh } = e;
|
|
1887
|
+
refreshFn = refresh;
|
|
1888
|
+
if (!ignoreThisUpdate) {
|
|
1889
|
+
if (!wasPromise || !globalState.isLoadingRemote) {
|
|
1890
|
+
if (wasPromise) {
|
|
1891
|
+
if (node.activationState) {
|
|
1892
|
+
const { initial } = node.activationState;
|
|
1893
|
+
if (value && isPromise(value)) {
|
|
1894
|
+
extractPromise(node, value, update);
|
|
1895
|
+
}
|
|
1896
|
+
if (isFunction(getNodeValue(node))) {
|
|
1897
|
+
setNodeValue(node, initial != null ? initial : void 0);
|
|
1898
|
+
}
|
|
1899
|
+
} else if (node.activated) {
|
|
1900
|
+
extractPromise(node, value, update);
|
|
1901
|
+
if (isFunction(getNodeValue(node))) {
|
|
1902
|
+
setNodeValue(node, void 0);
|
|
1903
|
+
}
|
|
2019
1904
|
}
|
|
2020
|
-
|
|
2021
|
-
|
|
1905
|
+
} else {
|
|
1906
|
+
activatedValue = value;
|
|
1907
|
+
if (node.state.isLoaded.peek()) {
|
|
1908
|
+
node.isComputing = true;
|
|
1909
|
+
set(node, value);
|
|
1910
|
+
node.isComputing = false;
|
|
1911
|
+
} else {
|
|
1912
|
+
setNodeValue(node, value);
|
|
1913
|
+
node.state.assign({
|
|
1914
|
+
isLoaded: true,
|
|
1915
|
+
error: void 0
|
|
1916
|
+
});
|
|
2022
1917
|
}
|
|
1918
|
+
}
|
|
2023
1919
|
}
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
if (value && isPromise(value)) {
|
|
2036
|
-
// Extract the promise to make it set the value/error when it comes in
|
|
2037
|
-
extractPromise(node, value, update);
|
|
2038
|
-
}
|
|
2039
|
-
// Set this to undefined only if it's replacing the activation function,
|
|
2040
|
-
// so we don't overwrite it if it already has real data from either local
|
|
2041
|
-
// cache or a previous run
|
|
2042
|
-
if (isFunction(getNodeValue(node))) {
|
|
2043
|
-
setNodeValue(node, initial !== null && initial !== void 0 ? initial : undefined);
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
else if (node.activated) {
|
|
2047
|
-
// Extract the promise to make it set the value/error when it comes in
|
|
2048
|
-
extractPromise(node, value, update);
|
|
2049
|
-
// Set this to undefined only if it's replacing the activation function,
|
|
2050
|
-
// so we don't overwrite it if it already has real data from either local
|
|
2051
|
-
// cache or a previous run
|
|
2052
|
-
if (isFunction(getNodeValue(node))) {
|
|
2053
|
-
setNodeValue(node, undefined);
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
else {
|
|
2058
|
-
activatedValue = value;
|
|
2059
|
-
if (node.state.isLoaded.peek()) {
|
|
2060
|
-
node.isComputing = true;
|
|
2061
|
-
set(node, value);
|
|
2062
|
-
node.isComputing = false;
|
|
2063
|
-
}
|
|
2064
|
-
else {
|
|
2065
|
-
setNodeValue(node, value);
|
|
2066
|
-
node.state.assign({
|
|
2067
|
-
isLoaded: true,
|
|
2068
|
-
error: undefined,
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
disposes.forEach((fn) => fn());
|
|
2074
|
-
disposes = [];
|
|
2075
|
-
nodes === null || nodes === void 0 ? void 0 : nodes.forEach(({ node, track }) => {
|
|
2076
|
-
disposes.push(onChange(node, markDirty, { immediate: true, trackingType: track }));
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
e.cancel = true;
|
|
2080
|
-
}, { fromComputed: true });
|
|
2081
|
-
return activatedValue;
|
|
1920
|
+
disposes.forEach((fn) => fn());
|
|
1921
|
+
disposes = [];
|
|
1922
|
+
nodes == null ? void 0 : nodes.forEach(({ node: node2, track }) => {
|
|
1923
|
+
disposes.push(onChange(node2, markDirty, { immediate: true, trackingType: track }));
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
e.cancel = true;
|
|
1927
|
+
},
|
|
1928
|
+
{ fromComputed: true }
|
|
1929
|
+
);
|
|
1930
|
+
return activatedValue;
|
|
2082
1931
|
}
|
|
2083
1932
|
function activateNodeBase(node, value) {
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
node.isComputing = true;
|
|
2132
|
-
setFn({
|
|
2133
|
-
value,
|
|
2134
|
-
changes,
|
|
2135
|
-
loading,
|
|
2136
|
-
remote,
|
|
2137
|
-
getPrevious,
|
|
2138
|
-
});
|
|
2139
|
-
node.isComputing = false;
|
|
2140
|
-
};
|
|
2141
|
-
whenReady(node.state.isLoaded, run);
|
|
2142
|
-
}
|
|
2143
|
-
};
|
|
2144
|
-
const onChangeImmediate = ({ value, changes }) => {
|
|
2145
|
-
if (!node.isComputing) {
|
|
2146
|
-
if (changes.length > 1 || !isFunction(changes[0].prevAtPath)) {
|
|
2147
|
-
latestValue = value;
|
|
2148
|
-
if (allChanges.length > 0) {
|
|
2149
|
-
changes = changes.filter((change) => !isArraySubset(allChanges[0].path, change.path));
|
|
2150
|
-
}
|
|
2151
|
-
allChanges.push(...changes);
|
|
2152
|
-
globalState.pendingNodes.set(node, runChanges);
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
};
|
|
2156
|
-
// Create an immediate listener to mark this node as pending. Then actually run
|
|
2157
|
-
// the changes at the end of the batch so everything is properly batched.
|
|
2158
|
-
// However, this can be short circuited if the user calls get() or peek()
|
|
2159
|
-
// in which case the set needs to run immediately so that the values are up to date.
|
|
2160
|
-
onChange(node, onChangeImmediate, { immediate: true });
|
|
2161
|
-
onChange(node, runChanges);
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
const update = ({ value }) => {
|
|
2165
|
-
if (!node.isComputing) {
|
|
1933
|
+
if (!node.state) {
|
|
1934
|
+
node.state = createObservable(
|
|
1935
|
+
{
|
|
1936
|
+
isLoaded: false
|
|
1937
|
+
},
|
|
1938
|
+
false,
|
|
1939
|
+
extractPromise,
|
|
1940
|
+
getProxy
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
if (node.activationState) {
|
|
1944
|
+
const { set: setFn, get: getFn, initial } = node.activationState;
|
|
1945
|
+
value = getFn == null ? void 0 : getFn();
|
|
1946
|
+
if (value == void 0 || value === null) {
|
|
1947
|
+
value = initial;
|
|
1948
|
+
}
|
|
1949
|
+
if (setFn) {
|
|
1950
|
+
let allChanges = [];
|
|
1951
|
+
let latestValue = void 0;
|
|
1952
|
+
let runNumber = 0;
|
|
1953
|
+
const runChanges = (listenerParams) => {
|
|
1954
|
+
if (allChanges.length > 0) {
|
|
1955
|
+
let changes;
|
|
1956
|
+
let value2;
|
|
1957
|
+
let loading = false;
|
|
1958
|
+
let remote = false;
|
|
1959
|
+
let getPrevious;
|
|
1960
|
+
if (listenerParams) {
|
|
1961
|
+
changes = listenerParams.changes;
|
|
1962
|
+
value2 = listenerParams.value;
|
|
1963
|
+
loading = listenerParams.loading;
|
|
1964
|
+
remote = listenerParams.remote;
|
|
1965
|
+
getPrevious = listenerParams.getPrevious;
|
|
1966
|
+
} else {
|
|
1967
|
+
changes = allChanges;
|
|
1968
|
+
value2 = latestValue;
|
|
1969
|
+
getPrevious = createPreviousHandler(value2, changes);
|
|
1970
|
+
}
|
|
1971
|
+
allChanges = [];
|
|
1972
|
+
latestValue = void 0;
|
|
1973
|
+
globalState.pendingNodes.delete(node);
|
|
1974
|
+
runNumber++;
|
|
1975
|
+
const thisRunNumber = runNumber;
|
|
1976
|
+
const run = () => {
|
|
1977
|
+
if (thisRunNumber !== runNumber) {
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
2166
1980
|
node.isComputing = true;
|
|
2167
|
-
|
|
1981
|
+
setFn({
|
|
1982
|
+
value: value2,
|
|
1983
|
+
changes,
|
|
1984
|
+
loading,
|
|
1985
|
+
remote,
|
|
1986
|
+
getPrevious
|
|
1987
|
+
});
|
|
2168
1988
|
node.isComputing = false;
|
|
1989
|
+
};
|
|
1990
|
+
whenReady(node.state.isLoaded, run);
|
|
2169
1991
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
1992
|
+
};
|
|
1993
|
+
const onChangeImmediate = ({ value: value2, changes }) => {
|
|
1994
|
+
if (!node.isComputing) {
|
|
1995
|
+
if (changes.length > 1 || !isFunction(changes[0].prevAtPath)) {
|
|
1996
|
+
latestValue = value2;
|
|
1997
|
+
if (allChanges.length > 0) {
|
|
1998
|
+
changes = changes.filter((change) => !isArraySubset(allChanges[0].path, change.path));
|
|
1999
|
+
}
|
|
2000
|
+
allChanges.push(...changes);
|
|
2001
|
+
globalState.pendingNodes.set(node, runChanges);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
onChange(node, onChangeImmediate, { immediate: true });
|
|
2006
|
+
onChange(node, runChanges);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
const update = ({ value: value2 }) => {
|
|
2010
|
+
if (!node.isComputing) {
|
|
2011
|
+
node.isComputing = true;
|
|
2012
|
+
set(node, value2);
|
|
2013
|
+
node.isComputing = false;
|
|
2014
|
+
}
|
|
2015
|
+
};
|
|
2016
|
+
return { update, value };
|
|
2172
2017
|
}
|
|
2173
2018
|
function setToObservable(node, value) {
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2019
|
+
var _a;
|
|
2020
|
+
const linkedNode = getNode(value);
|
|
2021
|
+
if (linkedNode !== node && (linkedNode == null ? void 0 : linkedNode.linkedToNode) !== node) {
|
|
2022
|
+
node.linkedToNode = linkedNode;
|
|
2023
|
+
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
2024
|
+
linkedNode.linkedFromNodes.add(node);
|
|
2025
|
+
(_a = node.linkedToNodeDispose) == null ? void 0 : _a.call(node);
|
|
2026
|
+
node.linkedToNodeDispose = onChange(
|
|
2027
|
+
linkedNode,
|
|
2028
|
+
() => {
|
|
2029
|
+
value = peekInternal(linkedNode);
|
|
2030
|
+
set(node, value);
|
|
2031
|
+
},
|
|
2032
|
+
{ initial: true },
|
|
2033
|
+
/* @__PURE__ */ new Set([node])
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
return value;
|
|
2189
2037
|
}
|
|
2190
2038
|
function recursivelyAutoActivate(obj, node) {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
}
|
|
2207
|
-
function recursivelyAutoActivateInner(obj, pathStack,
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
}
|
|
2039
|
+
if (isObject(obj) || isArray(obj)) {
|
|
2040
|
+
const pathStack = [];
|
|
2041
|
+
const getNodeAtPath2 = () => {
|
|
2042
|
+
var _a;
|
|
2043
|
+
let childNode = node;
|
|
2044
|
+
for (let i = 0; i < pathStack.length; i++) {
|
|
2045
|
+
const { key } = pathStack[i];
|
|
2046
|
+
const value = (_a = getNodeValue(childNode)) == null ? void 0 : _a[key];
|
|
2047
|
+
childNode = getChildNode(childNode, key, isFunction(value) ? value : void 0);
|
|
2048
|
+
peekInternal(childNode);
|
|
2049
|
+
}
|
|
2050
|
+
return childNode;
|
|
2051
|
+
};
|
|
2052
|
+
recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
function recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2) {
|
|
2056
|
+
var _a;
|
|
2057
|
+
for (const key in obj) {
|
|
2058
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
2059
|
+
const value = obj[key];
|
|
2060
|
+
if (isObservable(value)) {
|
|
2061
|
+
const childNode = getNodeAtPath2();
|
|
2062
|
+
extractFunctionOrComputed(childNode, key, value);
|
|
2063
|
+
delete childNode.lazy;
|
|
2064
|
+
} else {
|
|
2065
|
+
const linkedOptions = isFunction(value) && ((_a = value.prototype) == null ? void 0 : _a[symbolLinked]);
|
|
2066
|
+
if (linkedOptions) {
|
|
2067
|
+
const activate = linkedOptions.activate;
|
|
2068
|
+
if (!activate || activate === "auto") {
|
|
2069
|
+
const childNode = getNodeAtPath2();
|
|
2070
|
+
peek(getChildNode(childNode, key, value));
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
if (typeof value === "object") {
|
|
2075
|
+
pathStack.push({ key, value });
|
|
2076
|
+
recursivelyAutoActivateInner(value, pathStack, getNodeAtPath2);
|
|
2077
|
+
pathStack.pop();
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2234
2081
|
}
|
|
2235
2082
|
|
|
2236
|
-
|
|
2083
|
+
// src/ObservablePrimitive.ts
|
|
2084
|
+
var fns = ["get", "set", "peek", "onChange", "toggle"];
|
|
2237
2085
|
function ObservablePrimitiveClass(node) {
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
}
|
|
2086
|
+
this._node = node;
|
|
2087
|
+
for (let i = 0; i < fns.length; i++) {
|
|
2088
|
+
const key = fns[i];
|
|
2089
|
+
this[key] = this[key].bind(this);
|
|
2090
|
+
}
|
|
2244
2091
|
}
|
|
2245
|
-
// Add observable functions to prototype
|
|
2246
2092
|
function proto(key, fn) {
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2093
|
+
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2094
|
+
return fn.call(this, this._node, ...args);
|
|
2095
|
+
};
|
|
2250
2096
|
}
|
|
2251
|
-
proto(
|
|
2252
|
-
|
|
2253
|
-
|
|
2097
|
+
proto("peek", (node) => {
|
|
2098
|
+
flushPending();
|
|
2099
|
+
return peek(node);
|
|
2254
2100
|
});
|
|
2255
|
-
proto(
|
|
2256
|
-
|
|
2257
|
-
|
|
2101
|
+
proto("get", (node, options) => {
|
|
2102
|
+
flushPending();
|
|
2103
|
+
return get(node, options);
|
|
2258
2104
|
});
|
|
2259
|
-
proto(
|
|
2260
|
-
proto(
|
|
2261
|
-
// Getters
|
|
2105
|
+
proto("set", set);
|
|
2106
|
+
proto("onChange", onChange);
|
|
2262
2107
|
Object.defineProperty(ObservablePrimitiveClass.prototype, symbolGetNode, {
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2108
|
+
configurable: true,
|
|
2109
|
+
get() {
|
|
2110
|
+
return this._node;
|
|
2111
|
+
}
|
|
2267
2112
|
});
|
|
2268
|
-
ObservablePrimitiveClass.prototype.toggle = function
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
}
|
|
2113
|
+
ObservablePrimitiveClass.prototype.toggle = function() {
|
|
2114
|
+
const value = this.peek();
|
|
2115
|
+
if (value === void 0 || value === null || isBoolean(value)) {
|
|
2116
|
+
this.set(!value);
|
|
2117
|
+
} else if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
2118
|
+
throw new Error("[legend-state] Cannot toggle a non-boolean value");
|
|
2119
|
+
}
|
|
2276
2120
|
};
|
|
2277
|
-
ObservablePrimitiveClass.prototype.delete = function
|
|
2278
|
-
|
|
2279
|
-
|
|
2121
|
+
ObservablePrimitiveClass.prototype.delete = function() {
|
|
2122
|
+
this.set(void 0);
|
|
2123
|
+
return this;
|
|
2280
2124
|
};
|
|
2281
2125
|
|
|
2126
|
+
// src/observable.ts
|
|
2282
2127
|
function observable(value) {
|
|
2283
|
-
|
|
2128
|
+
return createObservable(value, false, extractPromise, getProxy, ObservablePrimitiveClass);
|
|
2284
2129
|
}
|
|
2285
2130
|
function observablePrimitive(value) {
|
|
2286
|
-
|
|
2131
|
+
return createObservable(value, true, extractPromise, getProxy, ObservablePrimitiveClass);
|
|
2287
2132
|
}
|
|
2288
2133
|
function syncState(obs) {
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2134
|
+
const node = getNode(obs);
|
|
2135
|
+
if (!node.state) {
|
|
2136
|
+
peekInternal(node);
|
|
2137
|
+
}
|
|
2138
|
+
if (!node.state) {
|
|
2139
|
+
node.state = observable({});
|
|
2140
|
+
}
|
|
2141
|
+
return node.state;
|
|
2297
2142
|
}
|
|
2298
2143
|
|
|
2299
|
-
|
|
2300
|
-
|
|
2144
|
+
// src/computed.ts
|
|
2145
|
+
function computed(get2, set2) {
|
|
2146
|
+
return observable(
|
|
2147
|
+
set2 ? linked({ get: get2, set: ({ value }) => set2(value) }) : get2
|
|
2148
|
+
);
|
|
2301
2149
|
}
|
|
2302
2150
|
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2151
|
+
// src/config.ts
|
|
2152
|
+
function configureLegendState({
|
|
2153
|
+
observableFunctions,
|
|
2154
|
+
observableProperties: observableProperties2,
|
|
2155
|
+
jsonReplacer,
|
|
2156
|
+
jsonReviver
|
|
2157
|
+
}) {
|
|
2158
|
+
if (observableFunctions) {
|
|
2159
|
+
for (const key in observableFunctions) {
|
|
2160
|
+
const fn = observableFunctions[key];
|
|
2161
|
+
observableFns.set(key, fn);
|
|
2162
|
+
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2163
|
+
return fn.call(this, this._node, ...args);
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
if (observableProperties2) {
|
|
2168
|
+
for (const key in observableProperties2) {
|
|
2169
|
+
const fns2 = observableProperties2[key];
|
|
2170
|
+
observableProperties.set(key, fns2);
|
|
2171
|
+
Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
|
|
2172
|
+
configurable: true,
|
|
2173
|
+
get() {
|
|
2174
|
+
return fns2.get.call(this, this._node);
|
|
2175
|
+
},
|
|
2176
|
+
set(value) {
|
|
2177
|
+
return fns2.set.call(this, this._node, value);
|
|
2326
2178
|
}
|
|
2179
|
+
});
|
|
2327
2180
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2181
|
+
}
|
|
2182
|
+
if (jsonReplacer) {
|
|
2183
|
+
globalState.replacer = jsonReplacer;
|
|
2184
|
+
}
|
|
2185
|
+
if (jsonReviver) {
|
|
2186
|
+
globalState.reviver = jsonReviver;
|
|
2187
|
+
}
|
|
2334
2188
|
}
|
|
2335
2189
|
|
|
2190
|
+
// src/event.ts
|
|
2336
2191
|
function event() {
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
},
|
|
2354
|
-
// @ts-expect-error eslint doesn't like adding symbols to the object but this does work
|
|
2355
|
-
[symbolGetNode]: node,
|
|
2356
|
-
};
|
|
2192
|
+
const obs = observable(0);
|
|
2193
|
+
const node = getNode(obs);
|
|
2194
|
+
node.isEvent = true;
|
|
2195
|
+
return {
|
|
2196
|
+
fire: function() {
|
|
2197
|
+
obs.set((v) => v + 1);
|
|
2198
|
+
},
|
|
2199
|
+
on: function(cb) {
|
|
2200
|
+
return obs.onChange(cb);
|
|
2201
|
+
},
|
|
2202
|
+
get: function() {
|
|
2203
|
+
return obs.get();
|
|
2204
|
+
},
|
|
2205
|
+
// @ts-expect-error eslint doesn't like adding symbols to the object but this does work
|
|
2206
|
+
[symbolGetNode]: node
|
|
2207
|
+
};
|
|
2357
2208
|
}
|
|
2358
2209
|
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2210
|
+
// src/proxy.ts
|
|
2211
|
+
function proxy(get2, set2) {
|
|
2212
|
+
return observable(
|
|
2213
|
+
(key) => set2 ? linked({
|
|
2214
|
+
get: () => get2(key),
|
|
2215
|
+
set: ({ value }) => set2(key, value)
|
|
2216
|
+
}) : get2(key)
|
|
2217
|
+
);
|
|
2366
2218
|
}
|
|
2367
2219
|
|
|
2220
|
+
// src/retry.ts
|
|
2368
2221
|
function calculateRetryDelay(retryOptions, attemptNum) {
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2222
|
+
const { backoff, delay = 1e3, infinite, times = 3, maxDelay = 3e4 } = retryOptions;
|
|
2223
|
+
if (infinite || attemptNum < times) {
|
|
2224
|
+
const delayTime = Math.min(delay * (backoff === "constant" ? 1 : 2 ** attemptNum), maxDelay);
|
|
2225
|
+
return delayTime;
|
|
2226
|
+
}
|
|
2227
|
+
return null;
|
|
2375
2228
|
}
|
|
2376
2229
|
function createRetryTimeout(retryOptions, attemptNum, fn) {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2230
|
+
const delayTime = calculateRetryDelay(retryOptions, attemptNum);
|
|
2231
|
+
if (delayTime) {
|
|
2232
|
+
return setTimeout(fn, delayTime);
|
|
2233
|
+
}
|
|
2381
2234
|
}
|
|
2382
2235
|
function runWithRetry(node, state, fn) {
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
}
|
|
2416
|
-
})
|
|
2417
|
-
.finally(() => {
|
|
2418
|
-
node.activationState.persistedRetry = false;
|
|
2419
|
-
});
|
|
2420
|
-
};
|
|
2421
|
-
run();
|
|
2236
|
+
const { waitFor } = node.activationState;
|
|
2237
|
+
const { retry } = state;
|
|
2238
|
+
const e = { cancel: false };
|
|
2239
|
+
let value = void 0;
|
|
2240
|
+
if (waitFor) {
|
|
2241
|
+
value = whenReady(waitFor, () => {
|
|
2242
|
+
node.activationState.waitFor = void 0;
|
|
2243
|
+
return fn(e);
|
|
2244
|
+
});
|
|
2245
|
+
} else {
|
|
2246
|
+
value = fn(e);
|
|
2247
|
+
}
|
|
2248
|
+
if (isPromise(value) && retry) {
|
|
2249
|
+
let timeoutRetry;
|
|
2250
|
+
return new Promise((resolve) => {
|
|
2251
|
+
const run = () => {
|
|
2252
|
+
value.then((val) => {
|
|
2253
|
+
node.activationState.persistedRetry = false;
|
|
2254
|
+
resolve(val);
|
|
2255
|
+
}).catch(() => {
|
|
2256
|
+
state.attemptNum++;
|
|
2257
|
+
if (timeoutRetry) {
|
|
2258
|
+
clearTimeout(timeoutRetry);
|
|
2259
|
+
}
|
|
2260
|
+
if (!e.cancel) {
|
|
2261
|
+
timeoutRetry = createRetryTimeout(retry, state.attemptNum, () => {
|
|
2262
|
+
value = fn(e);
|
|
2263
|
+
run();
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2266
|
+
}).finally(() => {
|
|
2267
|
+
node.activationState.persistedRetry = false;
|
|
2422
2268
|
});
|
|
2423
|
-
|
|
2424
|
-
|
|
2269
|
+
};
|
|
2270
|
+
run();
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
return value;
|
|
2425
2274
|
}
|
|
2426
2275
|
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2276
|
+
// index.ts
|
|
2277
|
+
var internal = {
|
|
2278
|
+
createPreviousHandler,
|
|
2279
|
+
clone,
|
|
2280
|
+
ensureNodeValue,
|
|
2281
|
+
findIDKey,
|
|
2282
|
+
get,
|
|
2283
|
+
getNode,
|
|
2284
|
+
getNodeValue,
|
|
2285
|
+
getPathType,
|
|
2286
|
+
getProxy,
|
|
2287
|
+
getValueAtPath,
|
|
2288
|
+
globalState,
|
|
2289
|
+
initializePathType,
|
|
2290
|
+
observableFns,
|
|
2291
|
+
optimized,
|
|
2292
|
+
peek,
|
|
2293
|
+
runWithRetry,
|
|
2294
|
+
safeParse,
|
|
2295
|
+
safeStringify,
|
|
2296
|
+
set,
|
|
2297
|
+
setAtPath,
|
|
2298
|
+
setNodeValue,
|
|
2299
|
+
symbolLinked,
|
|
2300
|
+
symbolDelete,
|
|
2301
|
+
tracking
|
|
2452
2302
|
};
|
|
2453
2303
|
|
|
2454
2304
|
export { ObservablePrimitiveClass, applyChange, applyChanges, batch, beginBatch, beginTracking, computeSelector, computed, configureLegendState, constructObjectWithPath, deconstructObjectWithPath, endBatch, endTracking, event, findIDKey, getNode, getNodeValue, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPrimitive, isPromise, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, optimized, proxy, setAtPath, setInObservableAtPath, setSilently, setupTracking, shouldIgnoreUnobserved, symbolDelete, syncState, trackSelector, tracking, updateTracking, when, whenReady };
|
|
2455
|
-
//# sourceMappingURL=index.mjs.map
|