@legendapp/state 3.0.0-alpha.9 → 3.0.0-beta.0
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/config/configureLegendState.d.mts +13 -0
- package/config/configureLegendState.d.ts +13 -0
- package/config/configureLegendState.js +45 -0
- package/config/configureLegendState.mjs +43 -0
- package/config/enable$GetSet.js +2 -1
- package/config/enable$GetSet.mjs +2 -1
- package/config/enableReactTracking.js +2 -1
- package/config/enableReactTracking.mjs +2 -1
- package/config/enableReactUse.js +2 -1
- package/config/enableReactUse.mjs +2 -1
- package/config/enable_PeekAssign.js +2 -1
- package/config/enable_PeekAssign.mjs +2 -1
- package/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +103 -79
- package/index.d.ts +103 -79
- package/index.js +326 -316
- package/index.mjs +323 -314
- package/package.json +36 -1
- package/persist-plugins/async-storage.d.mts +6 -3
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +8 -4
- package/persist-plugins/async-storage.mjs +8 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +35 -15
- package/persist-plugins/indexeddb.mjs +35 -16
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +10 -5
- package/persist-plugins/mmkv.mjs +10 -6
- package/react-reactive/enableReactComponents.d.mts +9 -0
- package/react-reactive/enableReactComponents.d.ts +9 -0
- package/react-reactive/enableReactComponents.js +19 -0
- package/react-reactive/enableReactComponents.mjs +17 -0
- package/react-reactive/enableReactNativeComponents.d.mts +22 -0
- package/react-reactive/enableReactNativeComponents.d.ts +22 -0
- package/react-reactive/enableReactNativeComponents.js +53 -0
- package/react-reactive/enableReactNativeComponents.mjs +51 -0
- package/react-reactive/enableReactive.d.mts +5 -0
- package/react-reactive/enableReactive.d.ts +5 -0
- package/react-reactive/enableReactive.js +24 -0
- package/react-reactive/enableReactive.mjs +22 -0
- package/react-reactive/enableReactive.native.d.mts +5 -0
- package/react-reactive/enableReactive.native.d.ts +5 -0
- package/react-reactive/enableReactive.native.js +58 -0
- package/react-reactive/enableReactive.native.mjs +56 -0
- package/react-reactive/enableReactive.web.d.mts +5 -0
- package/react-reactive/enableReactive.web.d.ts +5 -0
- package/react-reactive/enableReactive.web.js +58 -0
- package/react-reactive/enableReactive.web.mjs +56 -0
- package/react.d.mts +39 -34
- package/react.d.ts +39 -34
- package/react.js +39 -17
- package/react.mjs +39 -17
- package/sync-plugins/crud.d.mts +21 -23
- package/sync-plugins/crud.d.ts +21 -23
- package/sync-plugins/crud.js +224 -112
- package/sync-plugins/crud.mjs +226 -114
- package/sync-plugins/fetch.js +12 -8
- package/sync-plugins/fetch.mjs +13 -9
- package/sync-plugins/firebase.d.mts +27 -0
- package/sync-plugins/firebase.d.ts +27 -0
- package/sync-plugins/firebase.js +373 -0
- package/sync-plugins/firebase.mjs +368 -0
- package/sync-plugins/keel.d.mts +43 -26
- package/sync-plugins/keel.d.ts +43 -26
- package/sync-plugins/keel.js +145 -99
- package/sync-plugins/keel.mjs +147 -99
- package/sync-plugins/supabase.d.mts +19 -9
- package/sync-plugins/supabase.d.ts +19 -9
- package/sync-plugins/supabase.js +52 -21
- package/sync-plugins/supabase.mjs +53 -22
- package/sync-plugins/tanstack-query.d.mts +2 -2
- package/sync-plugins/tanstack-query.d.ts +2 -2
- package/sync-plugins/tanstack-query.js +22 -5
- package/sync-plugins/tanstack-query.mjs +22 -5
- package/sync-plugins/tanstack-react-query.d.mts +1 -1
- package/sync-plugins/tanstack-react-query.d.ts +1 -1
- package/sync-plugins/tanstack-react-query.js +8 -1
- package/sync-plugins/tanstack-react-query.mjs +8 -1
- package/sync.d.mts +74 -200
- package/sync.d.ts +74 -200
- package/sync.js +495 -281
- package/sync.mjs +500 -286
package/index.js
CHANGED
|
@@ -11,6 +11,9 @@ function isString(obj) {
|
|
|
11
11
|
function isObject(obj) {
|
|
12
12
|
return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isArray(obj);
|
|
13
13
|
}
|
|
14
|
+
function isPlainObject(obj) {
|
|
15
|
+
return isObject(obj) && obj.constructor === Object;
|
|
16
|
+
}
|
|
14
17
|
function isFunction(obj) {
|
|
15
18
|
return typeof obj === "function";
|
|
16
19
|
}
|
|
@@ -31,17 +34,22 @@ function isPromise(obj) {
|
|
|
31
34
|
return obj instanceof Promise;
|
|
32
35
|
}
|
|
33
36
|
function isMap(obj) {
|
|
34
|
-
return obj instanceof Map;
|
|
37
|
+
return obj instanceof Map || obj instanceof WeakMap;
|
|
38
|
+
}
|
|
39
|
+
function isSet(obj) {
|
|
40
|
+
return obj instanceof Set || obj instanceof WeakSet;
|
|
35
41
|
}
|
|
36
42
|
function isNumber(obj) {
|
|
37
43
|
const n = obj;
|
|
38
|
-
return n - n < 1;
|
|
44
|
+
return typeof n === "number" && n - n < 1;
|
|
39
45
|
}
|
|
40
46
|
function isEmpty(obj) {
|
|
41
47
|
if (!obj)
|
|
42
48
|
return false;
|
|
43
49
|
if (isArray(obj))
|
|
44
50
|
return obj.length === 0;
|
|
51
|
+
if (isMap(obj) || isSet(obj))
|
|
52
|
+
return obj.size === 0;
|
|
45
53
|
for (const key in obj) {
|
|
46
54
|
if (hasOwnProperty.call(obj, key)) {
|
|
47
55
|
return false;
|
|
@@ -56,27 +64,29 @@ var setPrimitives = /* @__PURE__ */ new Set(["boolean", "string", "number"]);
|
|
|
56
64
|
function isActualPrimitive(arg) {
|
|
57
65
|
return setPrimitives.has(typeof arg);
|
|
58
66
|
}
|
|
59
|
-
function
|
|
67
|
+
function isChildNode(node) {
|
|
60
68
|
return !!node.parent;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
// src/globals.ts
|
|
64
72
|
var symbolToPrimitive = Symbol.toPrimitive;
|
|
73
|
+
var symbolIterator = Symbol.iterator;
|
|
65
74
|
var symbolGetNode = Symbol("getNode");
|
|
66
75
|
var symbolDelete = /* @__PURE__ */ Symbol("delete");
|
|
67
76
|
var symbolOpaque = Symbol("opaque");
|
|
77
|
+
var symbolPlain = Symbol("plain");
|
|
68
78
|
var optimized = Symbol("optimized");
|
|
69
79
|
var symbolLinked = Symbol("linked");
|
|
70
80
|
var globalState = {
|
|
71
|
-
isLoadingLocal: false,
|
|
72
|
-
isMerging: false,
|
|
73
|
-
isLoadingRemote: false,
|
|
74
|
-
activateSyncedNode: void 0,
|
|
75
81
|
pendingNodes: /* @__PURE__ */ new Map(),
|
|
76
|
-
dirtyNodes: /* @__PURE__ */ new Set()
|
|
77
|
-
replacer: void 0,
|
|
78
|
-
reviver: void 0
|
|
82
|
+
dirtyNodes: /* @__PURE__ */ new Set()
|
|
79
83
|
};
|
|
84
|
+
function isHintOpaque(value) {
|
|
85
|
+
return value && (value[symbolOpaque] || value["$$typeof"]);
|
|
86
|
+
}
|
|
87
|
+
function isHintPlain(value) {
|
|
88
|
+
return value && value[symbolPlain];
|
|
89
|
+
}
|
|
80
90
|
function getPathType(value) {
|
|
81
91
|
return isArray(value) ? "array" : isMap(value) ? "map" : value instanceof Set ? "set" : "object";
|
|
82
92
|
}
|
|
@@ -137,29 +147,31 @@ function isEvent(value$) {
|
|
|
137
147
|
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
138
148
|
}
|
|
139
149
|
function setNodeValue(node, newValue) {
|
|
140
|
-
var _a
|
|
150
|
+
var _a;
|
|
141
151
|
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
142
152
|
const key = node.parent ? node.key : "_";
|
|
143
153
|
const isDelete = newValue === symbolDelete;
|
|
144
154
|
if (isDelete)
|
|
145
155
|
newValue = void 0;
|
|
146
156
|
const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
|
|
147
|
-
const
|
|
157
|
+
const useSetFn = isSet(parentValue);
|
|
158
|
+
const useMapFn = isMap(parentValue);
|
|
159
|
+
const prevValue = useSetFn ? key : useMapFn ? parentValue.get(key) : parentValue[key];
|
|
148
160
|
const isFunc = isFunction(newValue);
|
|
149
161
|
newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
|
|
150
|
-
if (
|
|
162
|
+
if (newValue !== prevValue) {
|
|
151
163
|
try {
|
|
152
164
|
parentNode.isSetting = (parentNode.isSetting || 0) + 1;
|
|
153
|
-
const useMapFn = isMap(parentValue);
|
|
154
165
|
if (isDelete) {
|
|
155
|
-
if (useMapFn) {
|
|
166
|
+
if (useMapFn || useSetFn) {
|
|
156
167
|
parentValue.delete(key);
|
|
157
168
|
} else {
|
|
158
169
|
delete parentValue[key];
|
|
159
170
|
}
|
|
160
171
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
if (useSetFn) {
|
|
173
|
+
parentValue.add(newValue);
|
|
174
|
+
} else if (useMapFn) {
|
|
163
175
|
parentValue.set(key, newValue);
|
|
164
176
|
} else {
|
|
165
177
|
parentValue[key] = newValue;
|
|
@@ -175,7 +187,7 @@ var arrNodeKeys = [];
|
|
|
175
187
|
function getNodeValue(node) {
|
|
176
188
|
let count = 0;
|
|
177
189
|
let n = node;
|
|
178
|
-
while (
|
|
190
|
+
while (isChildNode(n)) {
|
|
179
191
|
arrNodeKeys[count++] = n.key;
|
|
180
192
|
n = n.parent;
|
|
181
193
|
}
|
|
@@ -215,7 +227,7 @@ function getChildNode(node, key, asFunction) {
|
|
|
215
227
|
function ensureNodeValue(node) {
|
|
216
228
|
let value = getNodeValue(node);
|
|
217
229
|
if (!value || isFunction(value)) {
|
|
218
|
-
if (
|
|
230
|
+
if (isChildNode(node)) {
|
|
219
231
|
const parent = ensureNodeValue(node.parent);
|
|
220
232
|
value = parent[node.key] = {};
|
|
221
233
|
} else {
|
|
@@ -246,6 +258,27 @@ function equals(a, b) {
|
|
|
246
258
|
return a === b || isDate(a) && isDate(b) && +a === +b;
|
|
247
259
|
}
|
|
248
260
|
|
|
261
|
+
// src/ObservableHint.ts
|
|
262
|
+
function addSymbol(value, symbol) {
|
|
263
|
+
if (value) {
|
|
264
|
+
Object.defineProperty(value, symbol, {
|
|
265
|
+
value: true,
|
|
266
|
+
enumerable: false,
|
|
267
|
+
writable: true,
|
|
268
|
+
configurable: true
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
var ObservableHint = {
|
|
274
|
+
opaque: function opaqueObject(value) {
|
|
275
|
+
return addSymbol(value, symbolOpaque);
|
|
276
|
+
},
|
|
277
|
+
plain: function plainObject(value) {
|
|
278
|
+
return addSymbol(value, symbolPlain);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
249
282
|
// src/helpers.ts
|
|
250
283
|
function computeSelector(selector, e, retainObservable) {
|
|
251
284
|
let c = selector;
|
|
@@ -259,7 +292,10 @@ function getObservableIndex(value$) {
|
|
|
259
292
|
const n = +node.key;
|
|
260
293
|
return isNumber(n) ? n : -1;
|
|
261
294
|
}
|
|
262
|
-
function
|
|
295
|
+
function opaqueObject2(value) {
|
|
296
|
+
if (process.env.NODE_ENV === "development") {
|
|
297
|
+
console.warn("[legend-state]: In version 3.0 opaqueObject is moved to ObservableHint.opaque");
|
|
298
|
+
}
|
|
263
299
|
if (value) {
|
|
264
300
|
value[symbolOpaque] = true;
|
|
265
301
|
}
|
|
@@ -276,34 +312,46 @@ function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
|
276
312
|
let oFull = fullObj;
|
|
277
313
|
for (let i = 0; i < path.length; i++) {
|
|
278
314
|
p = path[i];
|
|
279
|
-
|
|
315
|
+
const map = isMap(o);
|
|
316
|
+
let child = o ? map ? o.get(p) : o[p] : void 0;
|
|
317
|
+
const fullChild = oFull ? map ? oFull.get(p) : oFull[p] : void 0;
|
|
318
|
+
if (child === symbolDelete) {
|
|
280
319
|
if (oFull) {
|
|
281
|
-
|
|
282
|
-
|
|
320
|
+
if (map) {
|
|
321
|
+
o.set(p, fullChild);
|
|
322
|
+
} else {
|
|
323
|
+
o[p] = fullChild;
|
|
324
|
+
}
|
|
325
|
+
restore == null ? void 0 : restore(path.slice(0, i + 1), fullChild);
|
|
283
326
|
}
|
|
284
327
|
return obj;
|
|
285
|
-
} else if (
|
|
328
|
+
} else if (child === void 0 && value === void 0 && i === path.length - 1) {
|
|
286
329
|
return obj;
|
|
287
|
-
} else if (
|
|
288
|
-
|
|
330
|
+
} else if (i < path.length - 1 && (child === void 0 || child === null)) {
|
|
331
|
+
child = initializePathType(pathTypes[i]);
|
|
332
|
+
if (isMap(o)) {
|
|
333
|
+
o.set(p, child);
|
|
334
|
+
} else {
|
|
335
|
+
o[p] = child;
|
|
336
|
+
}
|
|
289
337
|
}
|
|
290
338
|
if (i < path.length - 1) {
|
|
291
|
-
o =
|
|
339
|
+
o = child;
|
|
292
340
|
if (oFull) {
|
|
293
|
-
oFull =
|
|
341
|
+
oFull = fullChild;
|
|
294
342
|
}
|
|
295
343
|
}
|
|
296
344
|
}
|
|
297
345
|
}
|
|
298
346
|
if (p === void 0) {
|
|
299
347
|
if (mode === "merge") {
|
|
300
|
-
obj =
|
|
348
|
+
obj = deepMerge(obj, value);
|
|
301
349
|
} else {
|
|
302
350
|
obj = value;
|
|
303
351
|
}
|
|
304
352
|
} else {
|
|
305
353
|
if (mode === "merge") {
|
|
306
|
-
o[p] =
|
|
354
|
+
o[p] = deepMerge(o[p], value);
|
|
307
355
|
} else if (isMap(o)) {
|
|
308
356
|
o.set(p, value);
|
|
309
357
|
} else {
|
|
@@ -312,80 +360,53 @@ function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
|
312
360
|
}
|
|
313
361
|
return obj;
|
|
314
362
|
}
|
|
315
|
-
function setInObservableAtPath(value$, path, pathTypes, value, mode) {
|
|
316
|
-
let o = value$;
|
|
317
|
-
let v = value;
|
|
318
|
-
for (let i = 0; i < path.length; i++) {
|
|
319
|
-
const p = path[i];
|
|
320
|
-
if (!o.peek()[p]) {
|
|
321
|
-
o[p].set(initializePathType(pathTypes[i]));
|
|
322
|
-
}
|
|
323
|
-
o = o[p];
|
|
324
|
-
v = v[p];
|
|
325
|
-
}
|
|
326
|
-
if (v === symbolDelete) {
|
|
327
|
-
o.delete();
|
|
328
|
-
} else if (mode === "assign" && o.assign && isObject(o.peek())) {
|
|
329
|
-
o.assign(v);
|
|
330
|
-
} else if (mode === "merge") {
|
|
331
|
-
mergeIntoObservable(o, v);
|
|
332
|
-
} else {
|
|
333
|
-
o.set(v);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
363
|
function mergeIntoObservable(target, ...sources) {
|
|
364
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
365
|
+
if (!isObservable(target)) {
|
|
366
|
+
console.error("[legend-state] should only use mergeIntoObservable with observables");
|
|
367
|
+
}
|
|
368
|
+
}
|
|
337
369
|
beginBatch();
|
|
338
|
-
globalState.isMerging = true;
|
|
339
370
|
for (let i = 0; i < sources.length; i++) {
|
|
340
|
-
target
|
|
341
|
-
target,
|
|
342
|
-
sources[i],
|
|
343
|
-
/*assign*/
|
|
344
|
-
i < sources.length - 1
|
|
345
|
-
);
|
|
371
|
+
_mergeIntoObservable(target, sources[i], 0);
|
|
346
372
|
}
|
|
347
|
-
globalState.isMerging = false;
|
|
348
373
|
endBatch();
|
|
349
374
|
return target;
|
|
350
375
|
}
|
|
351
|
-
function _mergeIntoObservable(target, source,
|
|
352
|
-
var _a;
|
|
376
|
+
function _mergeIntoObservable(target, source, levelsDeep) {
|
|
353
377
|
if (isObservable(source)) {
|
|
354
378
|
source = source.peek();
|
|
355
379
|
}
|
|
356
|
-
const
|
|
357
|
-
const targetValue = needsSet ? target.peek() : target;
|
|
380
|
+
const targetValue = target.peek();
|
|
358
381
|
const isTargetArr = isArray(targetValue);
|
|
359
382
|
const isTargetObj = !isTargetArr && isObject(targetValue);
|
|
360
|
-
|
|
361
|
-
|
|
383
|
+
const isSourceMap = isMap(source);
|
|
384
|
+
const isSourceSet = isSet(source);
|
|
385
|
+
if (isSourceSet && isSet(targetValue)) {
|
|
386
|
+
target.set(/* @__PURE__ */ new Set([...source, ...targetValue]));
|
|
387
|
+
} else if (isTargetObj && isObject(source) && !isEmpty(targetValue) || isTargetArr && targetValue.length > 0) {
|
|
388
|
+
const keys = isSourceMap || isSourceSet ? Array.from(source.keys()) : Object.keys(source);
|
|
362
389
|
for (let i = 0; i < keys.length; i++) {
|
|
363
390
|
const key = keys[i];
|
|
364
|
-
const sourceValue = source[key];
|
|
391
|
+
const sourceValue = isSourceSet ? key : isSourceMap ? source.get(key) : source[key];
|
|
365
392
|
if (sourceValue === symbolDelete) {
|
|
366
|
-
|
|
393
|
+
target[key].delete();
|
|
367
394
|
} else {
|
|
368
395
|
const isObj = isObject(sourceValue);
|
|
369
396
|
const isArr = !isObj && isArray(sourceValue);
|
|
370
397
|
const targetChild = target[key];
|
|
371
|
-
if ((isObj || isArr) && targetChild
|
|
372
|
-
if (
|
|
373
|
-
target[key] = assign2 ? isArr ? [...sourceValue] : { ...sourceValue } : sourceValue;
|
|
374
|
-
} else {
|
|
375
|
-
_mergeIntoObservable(targetChild, sourceValue);
|
|
376
|
-
}
|
|
377
|
-
} else {
|
|
378
|
-
if (needsSet) {
|
|
398
|
+
if ((isObj || isArr) && targetChild) {
|
|
399
|
+
if (levelsDeep > 0 && isEmpty(sourceValue)) {
|
|
379
400
|
targetChild.set(sourceValue);
|
|
380
|
-
} else {
|
|
381
|
-
const toSet = isObject(sourceValue) ? { ...sourceValue } : isArray(sourceValue) ? [...sourceValue] : sourceValue;
|
|
382
|
-
target[key] = toSet;
|
|
383
401
|
}
|
|
402
|
+
_mergeIntoObservable(targetChild, sourceValue, levelsDeep + 1);
|
|
403
|
+
} else {
|
|
404
|
+
targetChild.set(sourceValue);
|
|
384
405
|
}
|
|
385
406
|
}
|
|
386
407
|
}
|
|
387
408
|
} else if (source !== void 0) {
|
|
388
|
-
|
|
409
|
+
target.set(source);
|
|
389
410
|
}
|
|
390
411
|
return target;
|
|
391
412
|
}
|
|
@@ -422,12 +443,13 @@ function initializePathType(pathType) {
|
|
|
422
443
|
switch (pathType) {
|
|
423
444
|
case "array":
|
|
424
445
|
return [];
|
|
425
|
-
case "object":
|
|
426
|
-
return {};
|
|
427
446
|
case "map":
|
|
428
447
|
return /* @__PURE__ */ new Map();
|
|
429
448
|
case "set":
|
|
430
449
|
return /* @__PURE__ */ new Set();
|
|
450
|
+
case "object":
|
|
451
|
+
default:
|
|
452
|
+
return {};
|
|
431
453
|
}
|
|
432
454
|
}
|
|
433
455
|
function applyChange(value, change, applyPrevious) {
|
|
@@ -440,6 +462,33 @@ function applyChanges(value, changes, applyPrevious) {
|
|
|
440
462
|
}
|
|
441
463
|
return value;
|
|
442
464
|
}
|
|
465
|
+
function deepMerge(target, ...sources) {
|
|
466
|
+
if (isPrimitive(target)) {
|
|
467
|
+
return sources[sources.length - 1];
|
|
468
|
+
}
|
|
469
|
+
let result = isArray(target) ? [...target] : { ...target };
|
|
470
|
+
for (let i = 0; i < sources.length; i++) {
|
|
471
|
+
const obj2 = sources[i];
|
|
472
|
+
if (isPlainObject(obj2) || isArray(obj2)) {
|
|
473
|
+
const objTarget = obj2;
|
|
474
|
+
for (const key in objTarget) {
|
|
475
|
+
if (hasOwnProperty.call(objTarget, key)) {
|
|
476
|
+
if (objTarget[key] instanceof Object && !isObservable(objTarget[key]) && Object.keys(objTarget[key]).length > 0) {
|
|
477
|
+
result[key] = deepMerge(
|
|
478
|
+
result[key] || (isArray(objTarget[key]) ? [] : {}),
|
|
479
|
+
objTarget[key]
|
|
480
|
+
);
|
|
481
|
+
} else {
|
|
482
|
+
result[key] = objTarget[key];
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
result = obj2;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
443
492
|
|
|
444
493
|
// src/batching.ts
|
|
445
494
|
var timeout;
|
|
@@ -486,9 +535,9 @@ function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
|
486
535
|
changesInBatch,
|
|
487
536
|
node,
|
|
488
537
|
/*loading*/
|
|
489
|
-
globalState.isLoadingLocal,
|
|
538
|
+
!!globalState.isLoadingLocal,
|
|
490
539
|
/*remote*/
|
|
491
|
-
globalState.isLoadingRemote,
|
|
540
|
+
!!globalState.isLoadingRemote,
|
|
492
541
|
value,
|
|
493
542
|
[],
|
|
494
543
|
[],
|
|
@@ -499,31 +548,35 @@ function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
|
499
548
|
level,
|
|
500
549
|
whenOptimizedOnlyIf
|
|
501
550
|
);
|
|
502
|
-
if (changesInBatch.size) {
|
|
503
|
-
batchNotifyChanges(
|
|
504
|
-
changesInBatch,
|
|
505
|
-
/*immediate*/
|
|
506
|
-
true
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
551
|
const existing = _batchMap.get(node);
|
|
510
552
|
if (existing) {
|
|
511
|
-
existing.
|
|
553
|
+
if (existing.prev === value) {
|
|
554
|
+
_batchMap.delete(node);
|
|
555
|
+
} else {
|
|
556
|
+
existing.value = value;
|
|
557
|
+
}
|
|
512
558
|
} else {
|
|
513
559
|
_batchMap.set(node, {
|
|
514
560
|
value,
|
|
515
561
|
prev,
|
|
516
562
|
level,
|
|
517
563
|
whenOptimizedOnlyIf,
|
|
518
|
-
|
|
519
|
-
|
|
564
|
+
isFromSync: !!globalState.isLoadingRemote,
|
|
565
|
+
isFromPersist: !!globalState.isLoadingLocal
|
|
520
566
|
});
|
|
521
567
|
}
|
|
568
|
+
if (changesInBatch.size) {
|
|
569
|
+
batchNotifyChanges(
|
|
570
|
+
changesInBatch,
|
|
571
|
+
/*immediate*/
|
|
572
|
+
true
|
|
573
|
+
);
|
|
574
|
+
}
|
|
522
575
|
if (numInBatch <= 0) {
|
|
523
576
|
runBatch();
|
|
524
577
|
}
|
|
525
578
|
}
|
|
526
|
-
function computeChangesAtNode(changesInBatch, node,
|
|
579
|
+
function computeChangesAtNode(changesInBatch, node, isFromPersist, isFromSync, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
527
580
|
if (immediate ? node.listenersImmediate : node.listeners) {
|
|
528
581
|
const change = {
|
|
529
582
|
path,
|
|
@@ -536,13 +589,14 @@ function computeChangesAtNode(changesInBatch, node, loading, remote, value, path
|
|
|
536
589
|
const { changes } = changeInBatch;
|
|
537
590
|
if (!isArraySubset(changes[0].path, change.path)) {
|
|
538
591
|
changes.push(change);
|
|
592
|
+
changeInBatch.level = Math.min(changeInBatch.level, level);
|
|
539
593
|
}
|
|
540
594
|
} else {
|
|
541
595
|
changesInBatch.set(node, {
|
|
542
596
|
level,
|
|
543
597
|
value,
|
|
544
|
-
|
|
545
|
-
|
|
598
|
+
isFromSync,
|
|
599
|
+
isFromPersist,
|
|
546
600
|
whenOptimizedOnlyIf,
|
|
547
601
|
changes: [change]
|
|
548
602
|
});
|
|
@@ -606,7 +660,7 @@ function computeChangesRecursive(changesInBatch, node, loading, remote, value, p
|
|
|
606
660
|
}
|
|
607
661
|
function batchNotifyChanges(changesInBatch, immediate) {
|
|
608
662
|
const listenersNotified = /* @__PURE__ */ new Set();
|
|
609
|
-
changesInBatch.forEach(({ changes, level, value,
|
|
663
|
+
changesInBatch.forEach(({ changes, level, value, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
610
664
|
const listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
611
665
|
if (listeners) {
|
|
612
666
|
let listenerParams;
|
|
@@ -620,8 +674,8 @@ function batchNotifyChanges(changesInBatch, immediate) {
|
|
|
620
674
|
if (!noArgs && !listenerParams) {
|
|
621
675
|
listenerParams = {
|
|
622
676
|
value,
|
|
623
|
-
|
|
624
|
-
|
|
677
|
+
isFromPersist,
|
|
678
|
+
isFromSync,
|
|
625
679
|
getPrevious: createPreviousHandler(value, changes),
|
|
626
680
|
changes
|
|
627
681
|
};
|
|
@@ -649,12 +703,12 @@ function runBatch() {
|
|
|
649
703
|
const map = _batchMap;
|
|
650
704
|
_batchMap = /* @__PURE__ */ new Map();
|
|
651
705
|
const changesInBatch = /* @__PURE__ */ new Map();
|
|
652
|
-
map.forEach(({ value, prev, level,
|
|
706
|
+
map.forEach(({ value, prev, level, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
653
707
|
computeChangesRecursive(
|
|
654
708
|
changesInBatch,
|
|
655
709
|
node,
|
|
656
|
-
|
|
657
|
-
|
|
710
|
+
isFromPersist,
|
|
711
|
+
isFromSync,
|
|
658
712
|
value,
|
|
659
713
|
[],
|
|
660
714
|
[],
|
|
@@ -713,21 +767,6 @@ function getNodeAtPath(obj, path) {
|
|
|
713
767
|
return o;
|
|
714
768
|
}
|
|
715
769
|
|
|
716
|
-
// src/linked.ts
|
|
717
|
-
function linked(params, options) {
|
|
718
|
-
if (isFunction(params)) {
|
|
719
|
-
params = { get: params };
|
|
720
|
-
}
|
|
721
|
-
if (options) {
|
|
722
|
-
params = { ...params, ...options };
|
|
723
|
-
}
|
|
724
|
-
const ret = function() {
|
|
725
|
-
return { [symbolLinked]: params };
|
|
726
|
-
};
|
|
727
|
-
ret.prototype[symbolLinked] = params;
|
|
728
|
-
return ret;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
770
|
// src/createObservable.ts
|
|
732
771
|
function createObservable(value, makePrimitive, extractPromise2, createObject, createPrimitive) {
|
|
733
772
|
if (isObservable(value)) {
|
|
@@ -757,6 +796,21 @@ function createObservable(value, makePrimitive, extractPromise2, createObject, c
|
|
|
757
796
|
return obs;
|
|
758
797
|
}
|
|
759
798
|
|
|
799
|
+
// src/linked.ts
|
|
800
|
+
function linked(params, options) {
|
|
801
|
+
if (isFunction(params)) {
|
|
802
|
+
params = { get: params };
|
|
803
|
+
}
|
|
804
|
+
if (options) {
|
|
805
|
+
params = { ...params, ...options };
|
|
806
|
+
}
|
|
807
|
+
const ret = function() {
|
|
808
|
+
return { [symbolLinked]: params };
|
|
809
|
+
};
|
|
810
|
+
ret.prototype[symbolLinked] = params;
|
|
811
|
+
return ret;
|
|
812
|
+
}
|
|
813
|
+
|
|
760
814
|
// src/onChange.ts
|
|
761
815
|
function onChange(node, callback, options = {}, fromLinks) {
|
|
762
816
|
var _a;
|
|
@@ -781,8 +835,8 @@ function onChange(node, callback, options = {}, fromLinks) {
|
|
|
781
835
|
const value = getNodeValue(node);
|
|
782
836
|
callback({
|
|
783
837
|
value,
|
|
784
|
-
|
|
785
|
-
|
|
838
|
+
isFromPersist: true,
|
|
839
|
+
isFromSync: false,
|
|
786
840
|
changes: [
|
|
787
841
|
{
|
|
788
842
|
path: [],
|
|
@@ -838,14 +892,14 @@ function onChange(node, callback, options = {}, fromLinks) {
|
|
|
838
892
|
};
|
|
839
893
|
}
|
|
840
894
|
function createCb(linkedFromNode, path, callback) {
|
|
841
|
-
let
|
|
842
|
-
return function({ value: valueA,
|
|
843
|
-
const
|
|
895
|
+
let prevAtPath = deconstructObjectWithPath(path, [], getNodeValue(linkedFromNode));
|
|
896
|
+
return function({ value: valueA, isFromPersist, isFromSync }) {
|
|
897
|
+
const valueAtPath = deconstructObjectWithPath(path, [], valueA);
|
|
844
898
|
if (valueAtPath !== prevAtPath) {
|
|
845
899
|
callback({
|
|
846
900
|
value: valueAtPath,
|
|
847
|
-
|
|
848
|
-
|
|
901
|
+
isFromPersist,
|
|
902
|
+
isFromSync,
|
|
849
903
|
changes: [
|
|
850
904
|
{
|
|
851
905
|
path: [],
|
|
@@ -860,16 +914,6 @@ function createCb(linkedFromNode, path, callback) {
|
|
|
860
914
|
prevAtPath = valueAtPath;
|
|
861
915
|
};
|
|
862
916
|
}
|
|
863
|
-
function getValueAtPath2(obj, path) {
|
|
864
|
-
let o = obj;
|
|
865
|
-
const pathTypes = [];
|
|
866
|
-
for (let i = 0; o && i < path.length; i++) {
|
|
867
|
-
pathTypes.push(isArray(o) ? "array" : "object");
|
|
868
|
-
const p = path[i];
|
|
869
|
-
o = o[p];
|
|
870
|
-
}
|
|
871
|
-
return { valueAtPath: o, pathTypes };
|
|
872
|
-
}
|
|
873
917
|
|
|
874
918
|
// src/setupTracking.ts
|
|
875
919
|
function setupTracking(nodes, update, noArgs, immediate) {
|
|
@@ -965,12 +1009,17 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
965
1009
|
options = reactionOrOptions;
|
|
966
1010
|
}
|
|
967
1011
|
let dispose;
|
|
1012
|
+
let isRunning = false;
|
|
968
1013
|
const e = { num: 0 };
|
|
969
1014
|
const update = function() {
|
|
1015
|
+
if (isRunning) {
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
970
1018
|
if (e.onCleanup) {
|
|
971
1019
|
e.onCleanup();
|
|
972
1020
|
e.onCleanup = void 0;
|
|
973
1021
|
}
|
|
1022
|
+
isRunning = true;
|
|
974
1023
|
beginBatch();
|
|
975
1024
|
delete e.value;
|
|
976
1025
|
dispose == null ? void 0 : dispose();
|
|
@@ -984,6 +1033,7 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
984
1033
|
e.onCleanupReaction = void 0;
|
|
985
1034
|
}
|
|
986
1035
|
endBatch();
|
|
1036
|
+
isRunning = false;
|
|
987
1037
|
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
988
1038
|
reaction(e);
|
|
989
1039
|
}
|
|
@@ -1006,16 +1056,30 @@ function _when(predicate, effect, checkReady) {
|
|
|
1006
1056
|
if (isPromise(predicate)) {
|
|
1007
1057
|
return effect ? predicate.then(effect) : predicate;
|
|
1008
1058
|
}
|
|
1059
|
+
const isPredicateArray = isArray(predicate);
|
|
1009
1060
|
let value;
|
|
1010
1061
|
let effectValue;
|
|
1011
1062
|
function run(e) {
|
|
1012
|
-
const ret = computeSelector(predicate);
|
|
1063
|
+
const ret = isPredicateArray ? predicate.map((p) => computeSelector(p)) : computeSelector(predicate);
|
|
1013
1064
|
if (isPromise(ret)) {
|
|
1014
1065
|
value = ret;
|
|
1015
1066
|
return void 0;
|
|
1016
|
-
} else
|
|
1017
|
-
|
|
1018
|
-
|
|
1067
|
+
} else {
|
|
1068
|
+
let isOk = true;
|
|
1069
|
+
if (isArray(ret)) {
|
|
1070
|
+
for (let i = 0; i < ret.length; i++) {
|
|
1071
|
+
if (isObservable(ret[i])) {
|
|
1072
|
+
ret[i] = computeSelector(ret[i]);
|
|
1073
|
+
}
|
|
1074
|
+
isOk = isOk && !!(checkReady ? isObservableValueReady(ret[i]) : ret[i]);
|
|
1075
|
+
}
|
|
1076
|
+
} else {
|
|
1077
|
+
isOk = checkReady ? isObservableValueReady(ret) : ret;
|
|
1078
|
+
}
|
|
1079
|
+
if (isOk) {
|
|
1080
|
+
value = ret;
|
|
1081
|
+
e.cancel = true;
|
|
1082
|
+
}
|
|
1019
1083
|
}
|
|
1020
1084
|
return value;
|
|
1021
1085
|
}
|
|
@@ -1067,6 +1131,7 @@ var ArrayLoopers = /* @__PURE__ */ new Set([
|
|
|
1067
1131
|
"filter",
|
|
1068
1132
|
"find",
|
|
1069
1133
|
"findIndex",
|
|
1134
|
+
"flatMap",
|
|
1070
1135
|
"forEach",
|
|
1071
1136
|
"join",
|
|
1072
1137
|
"map",
|
|
@@ -1096,7 +1161,7 @@ function collectionSetter(node, target, prop, ...args) {
|
|
|
1096
1161
|
const prevValue = target.slice();
|
|
1097
1162
|
const ret = target[prop].apply(target, args);
|
|
1098
1163
|
if (node) {
|
|
1099
|
-
const hasParent =
|
|
1164
|
+
const hasParent = isChildNode(node);
|
|
1100
1165
|
const key = hasParent ? node.key : "_";
|
|
1101
1166
|
const parentValue = hasParent ? getNodeValue(node.parent) : node.root;
|
|
1102
1167
|
parentValue[key] = prevValue;
|
|
@@ -1120,7 +1185,7 @@ function updateNodes(parent, obj, prevValue) {
|
|
|
1120
1185
|
}
|
|
1121
1186
|
__devUpdateNodes.add(obj);
|
|
1122
1187
|
}
|
|
1123
|
-
if (isObject(obj) && obj
|
|
1188
|
+
if (isObject(obj) && isHintOpaque(obj) || isObject(prevValue) && isHintOpaque(prevValue)) {
|
|
1124
1189
|
const isDiff = obj !== prevValue;
|
|
1125
1190
|
if (isDiff) {
|
|
1126
1191
|
if (parent.listeners || parent.listenersImmediate) {
|
|
@@ -1308,10 +1373,10 @@ var proxyHandler = {
|
|
|
1308
1373
|
if (p === symbolGetNode) {
|
|
1309
1374
|
return node;
|
|
1310
1375
|
}
|
|
1311
|
-
if (p === "apply") {
|
|
1376
|
+
if (p === "apply" || p === "call") {
|
|
1312
1377
|
const nodeValue = getNodeValue(node);
|
|
1313
1378
|
if (isFunction(nodeValue)) {
|
|
1314
|
-
return nodeValue
|
|
1379
|
+
return nodeValue[p];
|
|
1315
1380
|
}
|
|
1316
1381
|
}
|
|
1317
1382
|
let value = peekInternal(
|
|
@@ -1319,11 +1384,14 @@ var proxyHandler = {
|
|
|
1319
1384
|
/*activateRecursive*/
|
|
1320
1385
|
p === "get" || p === "peek"
|
|
1321
1386
|
);
|
|
1387
|
+
if (p === symbolIterator) {
|
|
1388
|
+
return !value || isPrimitive(value) ? void 0 : value[p];
|
|
1389
|
+
}
|
|
1322
1390
|
const targetNode = node.linkedToNode || (value == null ? void 0 : value[symbolGetNode]);
|
|
1323
1391
|
if (targetNode && p !== "onChange") {
|
|
1324
1392
|
return proxyHandler.get(targetNode, p, receiver);
|
|
1325
1393
|
}
|
|
1326
|
-
if (isMap(value) || value
|
|
1394
|
+
if (isMap(value) || isSet(value)) {
|
|
1327
1395
|
const ret = handlerMapSet(node, p, value);
|
|
1328
1396
|
if (ret !== void 0) {
|
|
1329
1397
|
return ret;
|
|
@@ -1353,7 +1421,7 @@ var proxyHandler = {
|
|
|
1353
1421
|
return property.get(node);
|
|
1354
1422
|
}
|
|
1355
1423
|
let vProp = value == null ? void 0 : value[p];
|
|
1356
|
-
if (isObject(value) && value
|
|
1424
|
+
if (isObject(value) && isHintOpaque(value)) {
|
|
1357
1425
|
return vProp;
|
|
1358
1426
|
}
|
|
1359
1427
|
const fnOrComputed = (_a = node.functions) == null ? void 0 : _a.get(p);
|
|
@@ -1415,7 +1483,7 @@ var proxyHandler = {
|
|
|
1415
1483
|
return vProp.bind(value);
|
|
1416
1484
|
}
|
|
1417
1485
|
if (isPrimitive(vProp)) {
|
|
1418
|
-
if (
|
|
1486
|
+
if (p === "length" && isArray(value)) {
|
|
1419
1487
|
updateTracking(node, true);
|
|
1420
1488
|
return vProp;
|
|
1421
1489
|
}
|
|
@@ -1519,11 +1587,17 @@ function setKey(node, key, newValue, level) {
|
|
|
1519
1587
|
} else {
|
|
1520
1588
|
const { newValue: savedValue, prevValue } = setNodeValue(childNode, newValue);
|
|
1521
1589
|
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1522
|
-
if (!equals(savedValue, prevValue)) {
|
|
1523
|
-
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level);
|
|
1524
|
-
}
|
|
1525
1590
|
if (!isPrim) {
|
|
1526
|
-
|
|
1591
|
+
let parent = childNode;
|
|
1592
|
+
do {
|
|
1593
|
+
parent.needsExtract = true;
|
|
1594
|
+
parent.recursivelyAutoActivated = false;
|
|
1595
|
+
} while (parent = parent.parent);
|
|
1596
|
+
}
|
|
1597
|
+
const notify2 = !equals(savedValue, prevValue);
|
|
1598
|
+
const forceNotify = !notify2 && childNode.isComputing && !isPrim;
|
|
1599
|
+
if (notify2 || forceNotify) {
|
|
1600
|
+
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level, forceNotify);
|
|
1527
1601
|
}
|
|
1528
1602
|
extractFunctionOrComputed(node, key, savedValue);
|
|
1529
1603
|
}
|
|
@@ -1538,6 +1612,8 @@ function assign(node, value) {
|
|
|
1538
1612
|
const currentValue = getNodeValue(node);
|
|
1539
1613
|
if (isMap(currentValue)) {
|
|
1540
1614
|
value.forEach((value2, key) => currentValue.set(key, value2));
|
|
1615
|
+
} else {
|
|
1616
|
+
set(node, value);
|
|
1541
1617
|
}
|
|
1542
1618
|
} else {
|
|
1543
1619
|
node.isAssigning = (node.isAssigning || 0) + 1;
|
|
@@ -1551,7 +1627,7 @@ function assign(node, value) {
|
|
|
1551
1627
|
return proxy2;
|
|
1552
1628
|
}
|
|
1553
1629
|
function deleteFn(node, key) {
|
|
1554
|
-
if (key === void 0 &&
|
|
1630
|
+
if (key === void 0 && isChildNode(node)) {
|
|
1555
1631
|
key = node.key;
|
|
1556
1632
|
node = node.parent;
|
|
1557
1633
|
}
|
|
@@ -1571,7 +1647,8 @@ function deleteFn(node, key) {
|
|
|
1571
1647
|
function handlerMapSet(node, p, value) {
|
|
1572
1648
|
const vProp = value == null ? void 0 : value[p];
|
|
1573
1649
|
if (p === "size") {
|
|
1574
|
-
|
|
1650
|
+
updateTracking(node, true);
|
|
1651
|
+
return value[p];
|
|
1575
1652
|
} else if (isFunction(vProp)) {
|
|
1576
1653
|
return function(a, b, c) {
|
|
1577
1654
|
const l = arguments.length;
|
|
@@ -1582,23 +1659,16 @@ function handlerMapSet(node, p, value) {
|
|
|
1582
1659
|
}
|
|
1583
1660
|
} else if (p === "set") {
|
|
1584
1661
|
if (l === 2) {
|
|
1585
|
-
|
|
1586
|
-
const ret = valueMap.set(a, b);
|
|
1587
|
-
if (prev !== b) {
|
|
1588
|
-
updateNodesAndNotify(getChildNode(node, a), b, prev);
|
|
1589
|
-
}
|
|
1590
|
-
return ret;
|
|
1662
|
+
set(getChildNode(node, a), b);
|
|
1591
1663
|
} else if (l === 1 && isMap(value)) {
|
|
1592
1664
|
set(node, a);
|
|
1593
1665
|
}
|
|
1666
|
+
return getProxy(node);
|
|
1594
1667
|
} else if (p === "delete") {
|
|
1595
1668
|
if (l > 0) {
|
|
1596
1669
|
const prev = value.get ? valueMap.get(a) : a;
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
updateNodesAndNotify(getChildNode(node, a), void 0, prev);
|
|
1600
|
-
}
|
|
1601
|
-
return ret;
|
|
1670
|
+
deleteFn(node, a);
|
|
1671
|
+
return prev !== void 0;
|
|
1602
1672
|
}
|
|
1603
1673
|
} else if (p === "clear") {
|
|
1604
1674
|
const prev = new Map(valueMap);
|
|
@@ -1614,7 +1684,7 @@ function handlerMapSet(node, p, value) {
|
|
|
1614
1684
|
if (!value.has(p)) {
|
|
1615
1685
|
notify(node, ret, prev, 0);
|
|
1616
1686
|
}
|
|
1617
|
-
return
|
|
1687
|
+
return getProxy(node);
|
|
1618
1688
|
}
|
|
1619
1689
|
const fn = observableFns.get(p);
|
|
1620
1690
|
if (fn) {
|
|
@@ -1634,20 +1704,20 @@ function handlerMapSet(node, p, value) {
|
|
|
1634
1704
|
};
|
|
1635
1705
|
}
|
|
1636
1706
|
}
|
|
1637
|
-
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level) {
|
|
1707
|
+
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level, forceNotify) {
|
|
1638
1708
|
if (!childNode)
|
|
1639
1709
|
childNode = node;
|
|
1640
1710
|
beginBatch();
|
|
1641
1711
|
if (isPrim === void 0) {
|
|
1642
1712
|
isPrim = isPrimitive(newValue);
|
|
1643
1713
|
}
|
|
1644
|
-
let hasADiff = isPrim;
|
|
1714
|
+
let hasADiff = forceNotify || isPrim;
|
|
1645
1715
|
let whenOptimizedOnlyIf = false;
|
|
1646
1716
|
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1647
1717
|
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1648
1718
|
__devUpdateNodes.clear();
|
|
1649
1719
|
}
|
|
1650
|
-
hasADiff = updateNodes(childNode, newValue, prevValue);
|
|
1720
|
+
hasADiff = hasADiff || updateNodes(childNode, newValue, prevValue);
|
|
1651
1721
|
if (isArray(newValue)) {
|
|
1652
1722
|
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1653
1723
|
}
|
|
@@ -1664,6 +1734,7 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRo
|
|
|
1664
1734
|
endBatch();
|
|
1665
1735
|
}
|
|
1666
1736
|
function extractPromise(node, value, setter) {
|
|
1737
|
+
const numGets = node.numGets = (node.numGets || 0) + 1;
|
|
1667
1738
|
if (!node.state) {
|
|
1668
1739
|
node.state = createObservable(
|
|
1669
1740
|
{
|
|
@@ -1675,11 +1746,14 @@ function extractPromise(node, value, setter) {
|
|
|
1675
1746
|
);
|
|
1676
1747
|
}
|
|
1677
1748
|
value.then((value2) => {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1749
|
+
if (numGets >= (node.getNumResolved || 0)) {
|
|
1750
|
+
node.getNumResolved = node.numGets;
|
|
1751
|
+
setter ? setter({ value: value2 }) : set(node, value2);
|
|
1752
|
+
node.state.assign({
|
|
1753
|
+
isLoaded: true,
|
|
1754
|
+
error: void 0
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1683
1757
|
}).catch((error) => {
|
|
1684
1758
|
node.state.error.set(error);
|
|
1685
1759
|
});
|
|
@@ -1696,6 +1770,7 @@ function extractFunctionOrComputed(node, k, v) {
|
|
|
1696
1770
|
const childNode = getChildNode(node, k, fn);
|
|
1697
1771
|
const targetNode = getNode(v);
|
|
1698
1772
|
const initialValue = peek(targetNode);
|
|
1773
|
+
setToObservable(childNode, v);
|
|
1699
1774
|
setNodeValue(childNode, initialValue);
|
|
1700
1775
|
return getNodeValue(childNode);
|
|
1701
1776
|
} else if (typeof v === "function") {
|
|
@@ -1728,7 +1803,9 @@ function peekInternal(node, activateRecursive) {
|
|
|
1728
1803
|
}
|
|
1729
1804
|
isFlushing = false;
|
|
1730
1805
|
let value = getNodeValue(node);
|
|
1731
|
-
|
|
1806
|
+
if (!globalState.isLoadingLocal) {
|
|
1807
|
+
value = checkLazy(node, value, !!activateRecursive);
|
|
1808
|
+
}
|
|
1732
1809
|
return value;
|
|
1733
1810
|
}
|
|
1734
1811
|
function checkLazy(node, value, activateRecursive) {
|
|
@@ -1743,10 +1820,12 @@ function checkLazy(node, value, activateRecursive) {
|
|
|
1743
1820
|
} else {
|
|
1744
1821
|
if (node.parent) {
|
|
1745
1822
|
const parentValue = getNodeValue(node.parent);
|
|
1746
|
-
if (
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1823
|
+
if (isFunction(value)) {
|
|
1824
|
+
if (parentValue) {
|
|
1825
|
+
delete parentValue[node.key];
|
|
1826
|
+
} else {
|
|
1827
|
+
node.root._ = void 0;
|
|
1828
|
+
}
|
|
1750
1829
|
}
|
|
1751
1830
|
}
|
|
1752
1831
|
value = activateNodeFunction(node, lazyFn);
|
|
@@ -1835,7 +1914,9 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1835
1914
|
var _a, _b, _c, _d;
|
|
1836
1915
|
if (isFirst) {
|
|
1837
1916
|
isFirst = false;
|
|
1838
|
-
|
|
1917
|
+
if (isFunction(getNodeValue(node))) {
|
|
1918
|
+
setNodeValue(node, void 0);
|
|
1919
|
+
}
|
|
1839
1920
|
} else if (!isFlushing && refreshFn) {
|
|
1840
1921
|
if (shouldIgnoreUnobserved(node, refreshFn)) {
|
|
1841
1922
|
ignoreThisUpdate = true;
|
|
@@ -1844,14 +1925,15 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1844
1925
|
}
|
|
1845
1926
|
let value = activateFn();
|
|
1846
1927
|
let didSetToObs = false;
|
|
1847
|
-
|
|
1848
|
-
|
|
1928
|
+
const isObs = isObservable(value);
|
|
1929
|
+
if (isObs || node.linkedToNode) {
|
|
1930
|
+
didSetToObs = isObs;
|
|
1849
1931
|
value = setToObservable(node, value);
|
|
1850
1932
|
}
|
|
1851
|
-
if (isFunction(value)) {
|
|
1933
|
+
if (isFunction(value) && value.length === 0) {
|
|
1852
1934
|
value = value();
|
|
1853
1935
|
}
|
|
1854
|
-
const activated = !
|
|
1936
|
+
const activated = !isObs ? value == null ? void 0 : value[symbolLinked] : void 0;
|
|
1855
1937
|
if (activated) {
|
|
1856
1938
|
node.activationState = activated;
|
|
1857
1939
|
value = void 0;
|
|
@@ -1906,16 +1988,14 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1906
1988
|
}
|
|
1907
1989
|
} else {
|
|
1908
1990
|
activatedValue = value;
|
|
1909
|
-
|
|
1991
|
+
const isLoaded = node.state.isLoaded.peek();
|
|
1992
|
+
if (isLoaded || !isFunction(value)) {
|
|
1910
1993
|
node.isComputing = true;
|
|
1911
1994
|
set(node, value);
|
|
1912
1995
|
node.isComputing = false;
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
node.state.assign({
|
|
1916
|
-
isLoaded: true,
|
|
1917
|
-
error: void 0
|
|
1918
|
-
});
|
|
1996
|
+
}
|
|
1997
|
+
if (!isLoaded) {
|
|
1998
|
+
node.state.assign({ isLoaded: true, error: void 0 });
|
|
1919
1999
|
}
|
|
1920
2000
|
}
|
|
1921
2001
|
}
|
|
@@ -1956,14 +2036,14 @@ function activateNodeBase(node, value) {
|
|
|
1956
2036
|
if (allChanges.length > 0) {
|
|
1957
2037
|
let changes;
|
|
1958
2038
|
let value2;
|
|
1959
|
-
let
|
|
1960
|
-
let
|
|
2039
|
+
let isFromPersist = false;
|
|
2040
|
+
let isFromSync = false;
|
|
1961
2041
|
let getPrevious;
|
|
1962
2042
|
if (listenerParams) {
|
|
1963
2043
|
changes = listenerParams.changes;
|
|
1964
2044
|
value2 = listenerParams.value;
|
|
1965
|
-
|
|
1966
|
-
|
|
2045
|
+
isFromPersist = listenerParams.isFromPersist;
|
|
2046
|
+
isFromSync = listenerParams.isFromSync;
|
|
1967
2047
|
getPrevious = listenerParams.getPrevious;
|
|
1968
2048
|
} else {
|
|
1969
2049
|
changes = allChanges;
|
|
@@ -1983,8 +2063,8 @@ function activateNodeBase(node, value) {
|
|
|
1983
2063
|
setFn({
|
|
1984
2064
|
value: value2,
|
|
1985
2065
|
changes,
|
|
1986
|
-
|
|
1987
|
-
|
|
2066
|
+
isFromPersist,
|
|
2067
|
+
isFromSync,
|
|
1988
2068
|
getPrevious
|
|
1989
2069
|
});
|
|
1990
2070
|
node.isComputing = false;
|
|
@@ -2019,32 +2099,37 @@ function activateNodeBase(node, value) {
|
|
|
2019
2099
|
}
|
|
2020
2100
|
function setToObservable(node, value) {
|
|
2021
2101
|
var _a;
|
|
2022
|
-
const linkedNode = getNode(value);
|
|
2102
|
+
const linkedNode = value ? getNode(value) : void 0;
|
|
2023
2103
|
if (linkedNode !== node && (linkedNode == null ? void 0 : linkedNode.linkedToNode) !== node) {
|
|
2024
2104
|
node.linkedToNode = linkedNode;
|
|
2025
|
-
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
2026
|
-
linkedNode.linkedFromNodes.add(node);
|
|
2027
2105
|
(_a = node.linkedToNodeDispose) == null ? void 0 : _a.call(node);
|
|
2028
|
-
|
|
2029
|
-
linkedNode
|
|
2030
|
-
()
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2106
|
+
if (linkedNode) {
|
|
2107
|
+
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
2108
|
+
linkedNode.linkedFromNodes.add(node);
|
|
2109
|
+
node.linkedToNodeDispose = onChange(
|
|
2110
|
+
linkedNode,
|
|
2111
|
+
() => {
|
|
2112
|
+
value = peekInternal(linkedNode);
|
|
2113
|
+
if (!isFunction(value)) {
|
|
2114
|
+
set(node, value);
|
|
2115
|
+
}
|
|
2116
|
+
},
|
|
2117
|
+
{ initial: true },
|
|
2118
|
+
/* @__PURE__ */ new Set([node])
|
|
2119
|
+
);
|
|
2120
|
+
}
|
|
2037
2121
|
}
|
|
2038
2122
|
return value;
|
|
2039
2123
|
}
|
|
2040
2124
|
function recursivelyAutoActivate(obj, node) {
|
|
2041
|
-
if ((isObject(obj) || isArray(obj)) && !obj
|
|
2125
|
+
if (!node.recursivelyAutoActivated && (isObject(obj) || isArray(obj)) && !isHintOpaque(obj)) {
|
|
2126
|
+
node.recursivelyAutoActivated = true;
|
|
2042
2127
|
const pathStack = [];
|
|
2043
2128
|
const getNodeAtPath2 = () => {
|
|
2044
2129
|
var _a;
|
|
2045
2130
|
let childNode = node;
|
|
2046
2131
|
for (let i = 0; i < pathStack.length; i++) {
|
|
2047
|
-
const
|
|
2132
|
+
const key = pathStack[i];
|
|
2048
2133
|
const value = (_a = getNodeValue(childNode)) == null ? void 0 : _a[key];
|
|
2049
2134
|
childNode = getChildNode(childNode, key, isFunction(value) ? value : void 0);
|
|
2050
2135
|
peekInternal(childNode);
|
|
@@ -2056,7 +2141,7 @@ function recursivelyAutoActivate(obj, node) {
|
|
|
2056
2141
|
}
|
|
2057
2142
|
function recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2) {
|
|
2058
2143
|
var _a;
|
|
2059
|
-
if ((isObject(obj) || isArray(obj)) && !obj
|
|
2144
|
+
if ((isObject(obj) || isArray(obj)) && !isHintOpaque(obj) && !isHintPlain(obj)) {
|
|
2060
2145
|
for (const key in obj) {
|
|
2061
2146
|
if (hasOwnProperty.call(obj, key)) {
|
|
2062
2147
|
const value = obj[key];
|
|
@@ -2075,7 +2160,7 @@ function recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2) {
|
|
|
2075
2160
|
}
|
|
2076
2161
|
}
|
|
2077
2162
|
if (typeof value === "object") {
|
|
2078
|
-
pathStack.push(
|
|
2163
|
+
pathStack.push(key);
|
|
2079
2164
|
recursivelyAutoActivateInner(value, pathStack, getNodeAtPath2);
|
|
2080
2165
|
pathStack.pop();
|
|
2081
2166
|
}
|
|
@@ -2134,16 +2219,6 @@ function observable(value) {
|
|
|
2134
2219
|
function observablePrimitive(value) {
|
|
2135
2220
|
return createObservable(value, true, extractPromise, getProxy, ObservablePrimitiveClass);
|
|
2136
2221
|
}
|
|
2137
|
-
function syncState(obs) {
|
|
2138
|
-
const node = getNode(obs);
|
|
2139
|
-
if (!node.state) {
|
|
2140
|
-
peekInternal(node);
|
|
2141
|
-
}
|
|
2142
|
-
if (!node.state) {
|
|
2143
|
-
node.state = observable({});
|
|
2144
|
-
}
|
|
2145
|
-
return node.state;
|
|
2146
|
-
}
|
|
2147
2222
|
|
|
2148
2223
|
// src/computed.ts
|
|
2149
2224
|
function computed(get2, set2) {
|
|
@@ -2152,45 +2227,6 @@ function computed(get2, set2) {
|
|
|
2152
2227
|
);
|
|
2153
2228
|
}
|
|
2154
2229
|
|
|
2155
|
-
// src/config.ts
|
|
2156
|
-
function configureLegendState({
|
|
2157
|
-
observableFunctions,
|
|
2158
|
-
observableProperties: observableProperties2,
|
|
2159
|
-
jsonReplacer,
|
|
2160
|
-
jsonReviver
|
|
2161
|
-
}) {
|
|
2162
|
-
if (observableFunctions) {
|
|
2163
|
-
for (const key in observableFunctions) {
|
|
2164
|
-
const fn = observableFunctions[key];
|
|
2165
|
-
observableFns.set(key, fn);
|
|
2166
|
-
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2167
|
-
return fn.call(this, this._node, ...args);
|
|
2168
|
-
};
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
if (observableProperties2) {
|
|
2172
|
-
for (const key in observableProperties2) {
|
|
2173
|
-
const fns2 = observableProperties2[key];
|
|
2174
|
-
observableProperties.set(key, fns2);
|
|
2175
|
-
Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
|
|
2176
|
-
configurable: true,
|
|
2177
|
-
get() {
|
|
2178
|
-
return fns2.get.call(this, this._node);
|
|
2179
|
-
},
|
|
2180
|
-
set(value) {
|
|
2181
|
-
return fns2.set.call(this, this._node, value);
|
|
2182
|
-
}
|
|
2183
|
-
});
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
if (jsonReplacer) {
|
|
2187
|
-
globalState.replacer = jsonReplacer;
|
|
2188
|
-
}
|
|
2189
|
-
if (jsonReviver) {
|
|
2190
|
-
globalState.reviver = jsonReviver;
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
2230
|
// src/event.ts
|
|
2195
2231
|
function event() {
|
|
2196
2232
|
const obs = observable(0);
|
|
@@ -2221,66 +2257,38 @@ function proxy(get2, set2) {
|
|
|
2221
2257
|
);
|
|
2222
2258
|
}
|
|
2223
2259
|
|
|
2224
|
-
// src/
|
|
2225
|
-
function
|
|
2226
|
-
const
|
|
2227
|
-
if (
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
return fn(e);
|
|
2248
|
-
});
|
|
2249
|
-
} else {
|
|
2250
|
-
value = fn(e);
|
|
2251
|
-
}
|
|
2252
|
-
if (isPromise(value) && retry) {
|
|
2253
|
-
let timeoutRetry;
|
|
2254
|
-
return new Promise((resolve) => {
|
|
2255
|
-
const run = () => {
|
|
2256
|
-
value.then((val) => {
|
|
2257
|
-
node.activationState.persistedRetry = false;
|
|
2258
|
-
resolve(val);
|
|
2259
|
-
}).catch(() => {
|
|
2260
|
-
state.attemptNum++;
|
|
2261
|
-
if (timeoutRetry) {
|
|
2262
|
-
clearTimeout(timeoutRetry);
|
|
2263
|
-
}
|
|
2264
|
-
if (!e.cancel) {
|
|
2265
|
-
timeoutRetry = createRetryTimeout(retry, state.attemptNum, () => {
|
|
2266
|
-
value = fn(e);
|
|
2267
|
-
run();
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
}).finally(() => {
|
|
2271
|
-
node.activationState.persistedRetry = false;
|
|
2272
|
-
});
|
|
2273
|
-
};
|
|
2274
|
-
run();
|
|
2275
|
-
});
|
|
2260
|
+
// src/syncState.ts
|
|
2261
|
+
function syncState(obs) {
|
|
2262
|
+
const node = getNode(obs);
|
|
2263
|
+
if (!node.state) {
|
|
2264
|
+
node.state = observable(
|
|
2265
|
+
ObservableHint.plain({
|
|
2266
|
+
isPersistLoaded: false,
|
|
2267
|
+
isLoaded: false,
|
|
2268
|
+
isPersistEnabled: true,
|
|
2269
|
+
isSyncEnabled: true,
|
|
2270
|
+
isGetting: false,
|
|
2271
|
+
isSetting: false,
|
|
2272
|
+
numPendingGets: 0,
|
|
2273
|
+
numPendingSets: 0,
|
|
2274
|
+
syncCount: 0,
|
|
2275
|
+
resetPersistence: void 0,
|
|
2276
|
+
reset: () => Promise.resolve(),
|
|
2277
|
+
sync: () => Promise.resolve(),
|
|
2278
|
+
getPendingChanges: () => ({}),
|
|
2279
|
+
// TODOV3 remove
|
|
2280
|
+
clearPersist: void 0
|
|
2281
|
+
})
|
|
2282
|
+
);
|
|
2276
2283
|
}
|
|
2277
|
-
return
|
|
2284
|
+
return node.state;
|
|
2278
2285
|
}
|
|
2279
2286
|
|
|
2280
2287
|
// index.ts
|
|
2281
2288
|
var internal = {
|
|
2282
2289
|
createPreviousHandler,
|
|
2283
2290
|
clone,
|
|
2291
|
+
deepMerge,
|
|
2284
2292
|
ensureNodeValue,
|
|
2285
2293
|
findIDKey,
|
|
2286
2294
|
get,
|
|
@@ -2291,10 +2299,11 @@ var internal = {
|
|
|
2291
2299
|
getValueAtPath,
|
|
2292
2300
|
globalState,
|
|
2293
2301
|
initializePathType,
|
|
2302
|
+
ObservablePrimitiveClass,
|
|
2303
|
+
observableProperties,
|
|
2294
2304
|
observableFns,
|
|
2295
2305
|
optimized,
|
|
2296
2306
|
peek,
|
|
2297
|
-
runWithRetry,
|
|
2298
2307
|
safeParse,
|
|
2299
2308
|
safeStringify,
|
|
2300
2309
|
set,
|
|
@@ -2305,6 +2314,7 @@ var internal = {
|
|
|
2305
2314
|
tracking
|
|
2306
2315
|
};
|
|
2307
2316
|
|
|
2317
|
+
exports.ObservableHint = ObservableHint;
|
|
2308
2318
|
exports.ObservablePrimitiveClass = ObservablePrimitiveClass;
|
|
2309
2319
|
exports.applyChange = applyChange;
|
|
2310
2320
|
exports.applyChanges = applyChanges;
|
|
@@ -2313,7 +2323,6 @@ exports.beginBatch = beginBatch;
|
|
|
2313
2323
|
exports.beginTracking = beginTracking;
|
|
2314
2324
|
exports.computeSelector = computeSelector;
|
|
2315
2325
|
exports.computed = computed;
|
|
2316
|
-
exports.configureLegendState = configureLegendState;
|
|
2317
2326
|
exports.constructObjectWithPath = constructObjectWithPath;
|
|
2318
2327
|
exports.deconstructObjectWithPath = deconstructObjectWithPath;
|
|
2319
2328
|
exports.endBatch = endBatch;
|
|
@@ -2337,8 +2346,10 @@ exports.isObject = isObject;
|
|
|
2337
2346
|
exports.isObservable = isObservable;
|
|
2338
2347
|
exports.isObservableValueReady = isObservableValueReady;
|
|
2339
2348
|
exports.isObserved = isObserved;
|
|
2349
|
+
exports.isPlainObject = isPlainObject;
|
|
2340
2350
|
exports.isPrimitive = isPrimitive;
|
|
2341
2351
|
exports.isPromise = isPromise;
|
|
2352
|
+
exports.isSet = isSet;
|
|
2342
2353
|
exports.isString = isString;
|
|
2343
2354
|
exports.isSymbol = isSymbol;
|
|
2344
2355
|
exports.linked = linked;
|
|
@@ -2346,11 +2357,10 @@ exports.mergeIntoObservable = mergeIntoObservable;
|
|
|
2346
2357
|
exports.observable = observable;
|
|
2347
2358
|
exports.observablePrimitive = observablePrimitive;
|
|
2348
2359
|
exports.observe = observe;
|
|
2349
|
-
exports.opaqueObject =
|
|
2360
|
+
exports.opaqueObject = opaqueObject2;
|
|
2350
2361
|
exports.optimized = optimized;
|
|
2351
2362
|
exports.proxy = proxy;
|
|
2352
2363
|
exports.setAtPath = setAtPath;
|
|
2353
|
-
exports.setInObservableAtPath = setInObservableAtPath;
|
|
2354
2364
|
exports.setSilently = setSilently;
|
|
2355
2365
|
exports.setupTracking = setupTracking;
|
|
2356
2366
|
exports.shouldIgnoreUnobserved = shouldIgnoreUnobserved;
|