@hanzogui/use-store 7.0.0 → 7.3.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/LICENSE +40 -19
- package/dist/cjs/useStore.cjs +76 -186
- package/dist/cjs/useStore.native.js +95 -233
- package/dist/cjs/useStore.native.js.map +1 -1
- package/dist/esm/useStore.mjs +76 -186
- package/dist/esm/useStore.mjs.map +1 -1
- package/dist/esm/useStore.native.js +95 -233
- package/dist/esm/useStore.native.js.map +1 -1
- package/package.json +11 -9
|
@@ -59,19 +59,14 @@ var import_constants = require("./constants.native.js");
|
|
|
59
59
|
var import_helpers = require("./helpers.native.js");
|
|
60
60
|
var import_useStoreDebug = require("./useStoreDebug.native.js");
|
|
61
61
|
function _instanceof(left, right) {
|
|
62
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance])
|
|
63
|
-
return !!right[Symbol.hasInstance](left);
|
|
64
|
-
} else {
|
|
65
|
-
return left instanceof right;
|
|
66
|
-
}
|
|
62
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);else return left instanceof right;
|
|
67
63
|
}
|
|
68
64
|
var idFn = function (_) {
|
|
69
65
|
return _;
|
|
70
66
|
};
|
|
71
67
|
function useStore(StoreKlass, props) {
|
|
72
68
|
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : import_constants.defaultOptions;
|
|
73
|
-
|
|
74
|
-
return useStoreFromInfo(info, options.selector, options);
|
|
69
|
+
return useStoreFromInfo(getOrCreateStoreInfo(StoreKlass, props, options), options.selector, options);
|
|
75
70
|
}
|
|
76
71
|
function useStoreDebug(StoreKlass, props) {
|
|
77
72
|
return useStore(StoreKlass, props, {
|
|
@@ -86,9 +81,7 @@ function useGlobalStore(instance, debug) {
|
|
|
86
81
|
var store = instance[import_constants.UNWRAP_PROXY];
|
|
87
82
|
var uid = (0, import_helpers.getStoreUid)(store.constructor, store.props);
|
|
88
83
|
var info = import_helpers.cache.get(uid);
|
|
89
|
-
if (!info)
|
|
90
|
-
throw new Error(`This store not created using createStore()`);
|
|
91
|
-
}
|
|
84
|
+
if (!info) throw new Error(`This store not created using createStore()`);
|
|
92
85
|
return useStoreFromInfo(info, void 0, {
|
|
93
86
|
debug
|
|
94
87
|
});
|
|
@@ -97,9 +90,7 @@ function useGlobalStoreSelector(instance, selector, debug) {
|
|
|
97
90
|
var store = instance[import_constants.UNWRAP_PROXY];
|
|
98
91
|
var uid = (0, import_helpers.getStoreUid)(store.constructor, store.props);
|
|
99
92
|
var info = import_helpers.cache.get(uid);
|
|
100
|
-
if (!info)
|
|
101
|
-
throw new Error(`This store not created using createStore()`);
|
|
102
|
-
}
|
|
93
|
+
if (!info) throw new Error(`This store not created using createStore()`);
|
|
103
94
|
return useStoreFromInfo(info, selector, {
|
|
104
95
|
debug
|
|
105
96
|
});
|
|
@@ -152,16 +143,10 @@ function onCreateStore(cb) {
|
|
|
152
143
|
}
|
|
153
144
|
function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
154
145
|
var _store_mount;
|
|
155
|
-
if (!StoreKlass)
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
146
|
+
if (!StoreKlass) return null;
|
|
158
147
|
var uid = (0, import_helpers.getStoreUid)(StoreKlass, propsKeyCalculated !== null && propsKeyCalculated !== void 0 ? propsKeyCalculated : props);
|
|
159
|
-
if (!(options === null || options === void 0 ? void 0 : options.avoidCache) && import_helpers.cache.has(uid))
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
if (options === null || options === void 0 ? void 0 : options.refuseCreation) {
|
|
163
|
-
throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
|
|
164
|
-
}
|
|
148
|
+
if (!(options === null || options === void 0 ? void 0 : options.avoidCache) && import_helpers.cache.has(uid)) return import_helpers.cache.get(uid);
|
|
149
|
+
if (options === null || options === void 0 ? void 0 : options.refuseCreation) throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
|
|
165
150
|
var storeInstance = new StoreKlass(props);
|
|
166
151
|
storeInstance.props = props;
|
|
167
152
|
var getters = {};
|
|
@@ -170,15 +155,7 @@ function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
|
170
155
|
var descriptors = (0, import_helpers.getStoreDescriptors)(storeInstance);
|
|
171
156
|
for (var key in descriptors) {
|
|
172
157
|
var descriptor = descriptors[key];
|
|
173
|
-
if (typeof descriptor.value === "function")
|
|
174
|
-
actions[key] = descriptor.value;
|
|
175
|
-
} else if (typeof descriptor.get === "function") {
|
|
176
|
-
getters[key] = descriptor.get;
|
|
177
|
-
} else {
|
|
178
|
-
if (key !== "props" && key[0] !== "_") {
|
|
179
|
-
stateKeys.add(key);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
158
|
+
if (typeof descriptor.value === "function") actions[key] = descriptor.value;else if (typeof descriptor.get === "function") getters[key] = descriptor.get;else if (key !== "props" && key[0] !== "_") stateKeys.add(key);
|
|
182
159
|
}
|
|
183
160
|
var keyComparators = storeInstance["_comparators"];
|
|
184
161
|
var listeners = /* @__PURE__ */new Set();
|
|
@@ -222,13 +199,9 @@ function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
|
222
199
|
_iteratorError = err;
|
|
223
200
|
} finally {
|
|
224
201
|
try {
|
|
225
|
-
if (!_iteratorNormalCompletion && _iterator.return != null)
|
|
226
|
-
_iterator.return();
|
|
227
|
-
}
|
|
202
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
228
203
|
} finally {
|
|
229
|
-
if (_didIteratorError)
|
|
230
|
-
throw _iteratorError;
|
|
231
|
-
}
|
|
204
|
+
if (_didIteratorError) throw _iteratorError;
|
|
232
205
|
}
|
|
233
206
|
}
|
|
234
207
|
}
|
|
@@ -236,10 +209,8 @@ function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
|
236
209
|
var store = createProxiedStore(
|
|
237
210
|
// we assign store right after and proxiedStore never accesses it until later on
|
|
238
211
|
storeInfo);
|
|
239
|
-
if (process.env.NODE_ENV === "development")
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
(_store_mount = store.mount) === null || _store_mount === void 0 ? void 0 : _store_mount.call(store);
|
|
212
|
+
if (process.env.NODE_ENV === "development") allStores[StoreKlass.name + uid] = store;
|
|
213
|
+
(_store_mount = store.mount) === null || _store_mount === void 0 || _store_mount.call(store);
|
|
243
214
|
storeInfo.store = store;
|
|
244
215
|
var result = storeInfo;
|
|
245
216
|
import_helpers.cache.set(uid, result);
|
|
@@ -255,9 +226,7 @@ if (process.env.NODE_ENV === "development") {
|
|
|
255
226
|
}
|
|
256
227
|
var emptyObj = {};
|
|
257
228
|
var selectKeys = function (obj, keys) {
|
|
258
|
-
if (!keys.length)
|
|
259
|
-
return emptyObj;
|
|
260
|
-
}
|
|
229
|
+
if (!keys.length) return emptyObj;
|
|
261
230
|
var res = {};
|
|
262
231
|
var _iteratorNormalCompletion = true,
|
|
263
232
|
_didIteratorError = false,
|
|
@@ -272,13 +241,9 @@ var selectKeys = function (obj, keys) {
|
|
|
272
241
|
_iteratorError = err;
|
|
273
242
|
} finally {
|
|
274
243
|
try {
|
|
275
|
-
if (!_iteratorNormalCompletion && _iterator.return != null)
|
|
276
|
-
_iterator.return();
|
|
277
|
-
}
|
|
244
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
278
245
|
} finally {
|
|
279
|
-
if (_didIteratorError)
|
|
280
|
-
throw _iteratorError;
|
|
281
|
-
}
|
|
246
|
+
if (_didIteratorError) throw _iteratorError;
|
|
282
247
|
}
|
|
283
248
|
}
|
|
284
249
|
return res;
|
|
@@ -291,14 +256,12 @@ function useStoreFromInfo(info, userSelector, options) {
|
|
|
291
256
|
var store = info === null || info === void 0 ? void 0 : info.store;
|
|
292
257
|
var internal = import_react.default.useRef(void 0);
|
|
293
258
|
var component = (0, import_useStoreDebug.useCurrentComponent)();
|
|
294
|
-
if (!internal.current) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
};
|
|
301
|
-
}
|
|
259
|
+
if (!internal.current) internal.current = {
|
|
260
|
+
component,
|
|
261
|
+
tracked: /* @__PURE__ */new Set(),
|
|
262
|
+
last: null,
|
|
263
|
+
lastKeys: null
|
|
264
|
+
};
|
|
302
265
|
var curInternal = internal.current;
|
|
303
266
|
var shouldPrintDebug = options === null || options === void 0 ? void 0 : options.debug;
|
|
304
267
|
var getSnapshot = import_react.default.useCallback(function () {
|
|
@@ -308,66 +271,46 @@ function useStoreFromInfo(info, userSelector, options) {
|
|
|
308
271
|
var keys = [...(!isTracking ? info.stateKeys : curInternal2.tracked)];
|
|
309
272
|
var nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`;
|
|
310
273
|
var lastKeys = curInternal2.lastKeys;
|
|
311
|
-
if (nextKeys === curInternal2.lastKeys)
|
|
312
|
-
return curInternal2.last;
|
|
313
|
-
}
|
|
274
|
+
if (nextKeys === curInternal2.lastKeys) return curInternal2.last;
|
|
314
275
|
curInternal2.lastKeys = nextKeys;
|
|
315
276
|
var snap;
|
|
316
277
|
info.disableTracking = true;
|
|
317
278
|
var last = curInternal2.last;
|
|
318
|
-
if (userSelector)
|
|
319
|
-
snap = userSelector(store);
|
|
320
|
-
} else {
|
|
321
|
-
snap = selectKeys(store, keys);
|
|
322
|
-
}
|
|
279
|
+
if (userSelector) snap = userSelector(store);else snap = selectKeys(store, keys);
|
|
323
280
|
info.disableTracking = false;
|
|
324
281
|
var isUnchanged = !userSelector && !isTracking && last || typeof last !== "undefined" && (0, import_comparators.isEqualSubsetShallow)(last, snap, {
|
|
325
282
|
keyComparators: info.keyComparators
|
|
326
283
|
});
|
|
327
|
-
if (shouldPrintDebug) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
if (isUnchanged) {
|
|
343
|
-
return last;
|
|
344
|
-
}
|
|
284
|
+
if (shouldPrintDebug) console.info("🌑 getSnapshot", {
|
|
285
|
+
storeState: selectKeys(store, Object.keys(store)),
|
|
286
|
+
userSelector,
|
|
287
|
+
info,
|
|
288
|
+
isUnchanged,
|
|
289
|
+
component,
|
|
290
|
+
keys,
|
|
291
|
+
last,
|
|
292
|
+
snap,
|
|
293
|
+
curInternal: curInternal2,
|
|
294
|
+
nextKeys,
|
|
295
|
+
lastKeys
|
|
296
|
+
});
|
|
297
|
+
if (isUnchanged) return last;
|
|
345
298
|
curInternal2.last = snap;
|
|
346
299
|
return snap;
|
|
347
300
|
}, [store]);
|
|
348
301
|
var state = import_react.default.useSyncExternalStore((info === null || info === void 0 ? void 0 : info.subscribe) || idFn, getSnapshot, getSnapshot);
|
|
349
|
-
if (!info || !store || !state)
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
if (userSelector) {
|
|
353
|
-
return state;
|
|
354
|
-
}
|
|
302
|
+
if (!info || !store || !state) return state;
|
|
303
|
+
if (userSelector) return state;
|
|
355
304
|
return new Proxy(store, {
|
|
356
305
|
get(target, key) {
|
|
357
306
|
var curVal = Reflect.get(target, key);
|
|
358
|
-
if (isInReaction)
|
|
359
|
-
return curVal;
|
|
360
|
-
}
|
|
307
|
+
if (isInReaction) return curVal;
|
|
361
308
|
var keyString = key;
|
|
362
309
|
if (info.stateKeys.has(keyString) || keyString in info.getters) {
|
|
363
|
-
if (shouldPrintDebug)
|
|
364
|
-
console.info("\u{1F440} tracking", keyString);
|
|
365
|
-
}
|
|
310
|
+
if (shouldPrintDebug) console.info("👀 tracking", keyString);
|
|
366
311
|
curInternal.tracked.add(keyString);
|
|
367
312
|
}
|
|
368
|
-
if (Reflect.has(state, key))
|
|
369
|
-
return Reflect.get(state, key);
|
|
370
|
-
}
|
|
313
|
+
if (Reflect.has(state, key)) return Reflect.get(state, key);
|
|
371
314
|
return curVal;
|
|
372
315
|
}
|
|
373
316
|
});
|
|
@@ -376,51 +319,34 @@ var setters = /* @__PURE__ */new Set();
|
|
|
376
319
|
var logStack = /* @__PURE__ */new Set();
|
|
377
320
|
function createProxiedStore(storeInfo) {
|
|
378
321
|
var _loop = function (key2) {
|
|
379
|
-
if (key2 === "subscribe")
|
|
380
|
-
return "continue";
|
|
381
|
-
}
|
|
322
|
+
if (key2 === "subscribe") return "continue";
|
|
382
323
|
var actionFn = actions[key2];
|
|
383
324
|
var isGetFn = key2.startsWith("get");
|
|
384
325
|
wrappedActions[key2] = function useStoreAction() {
|
|
385
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)
|
|
386
|
-
args[_key] = arguments[_key];
|
|
387
|
-
}
|
|
326
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
388
327
|
var res;
|
|
389
|
-
if (isGetFn || gettersState.isGetting)
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) {
|
|
393
|
-
console.info("(debug) startAction", key2);
|
|
394
|
-
}
|
|
328
|
+
if (isGetFn || gettersState.isGetting) return Reflect.apply(actionFn, proxiedStore, args);
|
|
329
|
+
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("(debug) startAction", key2);
|
|
395
330
|
res = Reflect.apply(actionFn, proxiedStore, args);
|
|
396
|
-
if (_instanceof(res, Promise))
|
|
397
|
-
return res.then(finishAction);
|
|
398
|
-
}
|
|
331
|
+
if (_instanceof(res, Promise)) return res.then(finishAction);
|
|
399
332
|
finishAction();
|
|
400
333
|
return res;
|
|
401
334
|
};
|
|
402
335
|
if (process.env.NODE_ENV === "development") {
|
|
403
336
|
let hashCode2 = function (str) {
|
|
404
337
|
var hash = 0;
|
|
405
|
-
for (var i = 0; i < str.length; i++)
|
|
406
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
407
|
-
}
|
|
338
|
+
for (var i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
408
339
|
return hash;
|
|
409
340
|
},
|
|
410
341
|
strColor2 = function (str) {
|
|
411
342
|
return `hsl(${hashCode2(str) % 360}, 90%, 40%)`;
|
|
412
343
|
};
|
|
413
|
-
var hashCode = hashCode2,
|
|
414
|
-
strColor = strColor2;
|
|
415
344
|
if (!key2.startsWith("get") && !key2.startsWith("_") && key2 !== "subscribe") {
|
|
416
345
|
var ogAction = wrappedActions[key2];
|
|
417
346
|
wrappedActions[key2] = new Proxy(ogAction, {
|
|
418
347
|
apply(target, thisArg, args) {
|
|
419
348
|
var isDebugging = shouldDebug2 || storeInfo.debug;
|
|
420
|
-
|
|
421
|
-
if (!shouldLog) {
|
|
422
|
-
return Reflect.apply(target, thisArg, args);
|
|
423
|
-
}
|
|
349
|
+
if (!(process.env.LOG_LEVEL !== "0" && (isDebugging || import_configureUseStore.configureOpts.logLevel !== "error"))) return Reflect.apply(target, thisArg, args);
|
|
424
350
|
setters = /* @__PURE__ */new Set();
|
|
425
351
|
var curSetters = setters;
|
|
426
352
|
var isTopLevelLogger = logStack.size == 0;
|
|
@@ -439,19 +365,13 @@ function createProxiedStore(storeInfo) {
|
|
|
439
365
|
var color = strColor2(name);
|
|
440
366
|
var simpleArgs = args.map(import_helpers.simpleStr);
|
|
441
367
|
logs.add([`%c \u{1F311} ${id} ${name.padStart(isTopLevelLogger ? 8 : 4)}%c.${key2}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`, `color: ${color};`, "color: black;"]);
|
|
442
|
-
if (curSetters.size) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
logs.add([` SET ${key3} ${value}`, value]);
|
|
450
|
-
} else {
|
|
451
|
-
logs.add([` SET ${key3}`, value]);
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
}
|
|
368
|
+
if (curSetters.size) curSetters.forEach(function (param) {
|
|
369
|
+
var {
|
|
370
|
+
key: key3,
|
|
371
|
+
value
|
|
372
|
+
} = param;
|
|
373
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") logs.add([` SET ${key3} ${value}`, value]);else logs.add([` SET ${key3}`, value]);
|
|
374
|
+
});
|
|
455
375
|
if (isTopLevelLogger) {
|
|
456
376
|
var error = null;
|
|
457
377
|
try {
|
|
@@ -490,31 +410,21 @@ function createProxiedStore(storeInfo) {
|
|
|
490
410
|
_iteratorError1 = err;
|
|
491
411
|
} finally {
|
|
492
412
|
try {
|
|
493
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null)
|
|
494
|
-
_iterator1.return();
|
|
495
|
-
}
|
|
413
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) _iterator1.return();
|
|
496
414
|
} finally {
|
|
497
|
-
if (_didIteratorError1)
|
|
498
|
-
throw _iteratorError1;
|
|
499
|
-
}
|
|
415
|
+
if (_didIteratorError1) throw _iteratorError1;
|
|
500
416
|
}
|
|
501
417
|
}
|
|
502
|
-
} else
|
|
503
|
-
console.info("Weird log", head, ...rest);
|
|
504
|
-
}
|
|
418
|
+
} else console.info("Weird log", head, ...rest);
|
|
505
419
|
}
|
|
506
420
|
} catch (err) {
|
|
507
421
|
_didIteratorError = true;
|
|
508
422
|
_iteratorError = err;
|
|
509
423
|
} finally {
|
|
510
424
|
try {
|
|
511
|
-
if (!_iteratorNormalCompletion && _iterator.return != null)
|
|
512
|
-
_iterator.return();
|
|
513
|
-
}
|
|
425
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
514
426
|
} finally {
|
|
515
|
-
if (_didIteratorError)
|
|
516
|
-
throw _iteratorError;
|
|
517
|
-
}
|
|
427
|
+
if (_didIteratorError) throw _iteratorError;
|
|
518
428
|
}
|
|
519
429
|
}
|
|
520
430
|
} catch (err) {
|
|
@@ -525,7 +435,7 @@ function createProxiedStore(storeInfo) {
|
|
|
525
435
|
_iteratorError2 = void 0;
|
|
526
436
|
try {
|
|
527
437
|
for (var _iterator2 = logStack[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
528
|
-
|
|
438
|
+
_step2.value;
|
|
529
439
|
console.groupEnd();
|
|
530
440
|
}
|
|
531
441
|
} catch (err) {
|
|
@@ -533,18 +443,12 @@ function createProxiedStore(storeInfo) {
|
|
|
533
443
|
_iteratorError2 = err;
|
|
534
444
|
} finally {
|
|
535
445
|
try {
|
|
536
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null)
|
|
537
|
-
_iterator2.return();
|
|
538
|
-
}
|
|
446
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) _iterator2.return();
|
|
539
447
|
} finally {
|
|
540
|
-
if (_didIteratorError2)
|
|
541
|
-
throw _iteratorError2;
|
|
542
|
-
}
|
|
448
|
+
if (_didIteratorError2) throw _iteratorError2;
|
|
543
449
|
}
|
|
544
450
|
}
|
|
545
|
-
if (error)
|
|
546
|
-
console.error(`error loggin`, error);
|
|
547
|
-
}
|
|
451
|
+
if (error) console.error(`error loggin`, error);
|
|
548
452
|
logStack.clear();
|
|
549
453
|
}
|
|
550
454
|
return res;
|
|
@@ -572,11 +476,9 @@ function createProxiedStore(storeInfo) {
|
|
|
572
476
|
var wrappedActions = {};
|
|
573
477
|
for (var key in actions) _loop(key);
|
|
574
478
|
var finishAction = function (val) {
|
|
575
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
});
|
|
579
|
-
}
|
|
479
|
+
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("(debug) finishAction", {
|
|
480
|
+
didSet
|
|
481
|
+
});
|
|
580
482
|
if (didSet) {
|
|
581
483
|
storeInfo.triggerUpdate();
|
|
582
484
|
didSet = false;
|
|
@@ -585,68 +487,42 @@ function createProxiedStore(storeInfo) {
|
|
|
585
487
|
};
|
|
586
488
|
var isTriggering = false;
|
|
587
489
|
var proxiedStore = new Proxy(storeInstance, {
|
|
588
|
-
// GET
|
|
589
490
|
get(_, key2) {
|
|
590
|
-
if (key2 in wrappedActions)
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (key2
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}
|
|
599
|
-
if (key2 === import_helpers.UNWRAP_STORE_INFO) {
|
|
600
|
-
return storeInfo;
|
|
601
|
-
}
|
|
602
|
-
if (storeAccessTrackers.size) {
|
|
603
|
-
storeAccessTrackers.forEach(function (cb) {
|
|
604
|
-
return cb(storeInfo);
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
if (typeof key2 !== "string") {
|
|
608
|
-
return Reflect.get(storeInstance, key2);
|
|
609
|
-
}
|
|
491
|
+
if (key2 in wrappedActions) return wrappedActions[key2];
|
|
492
|
+
if (key2 in passThroughKeys) return Reflect.get(storeInstance, key2);
|
|
493
|
+
if (key2 === import_constants.UNWRAP_PROXY) return storeInstance;
|
|
494
|
+
if (key2 === import_helpers.UNWRAP_STORE_INFO) return storeInfo;
|
|
495
|
+
if (storeAccessTrackers.size) storeAccessTrackers.forEach(function (cb) {
|
|
496
|
+
return cb(storeInfo);
|
|
497
|
+
});
|
|
498
|
+
if (typeof key2 !== "string") return Reflect.get(storeInstance, key2);
|
|
610
499
|
if (!storeInfo.disableTracking) {
|
|
611
|
-
if (gettersState.isGetting)
|
|
612
|
-
gettersState.curGetKeys.add(key2);
|
|
613
|
-
} else {}
|
|
500
|
+
if (gettersState.isGetting) gettersState.curGetKeys.add(key2);
|
|
614
501
|
}
|
|
615
502
|
if (key2 in getters) {
|
|
616
|
-
if (getCache.has(key2))
|
|
617
|
-
return getCache.get(key2);
|
|
618
|
-
}
|
|
503
|
+
if (getCache.has(key2)) return getCache.get(key2);
|
|
619
504
|
curGetKeys.clear();
|
|
620
505
|
var isSubGetter = gettersState.isGetting;
|
|
621
506
|
gettersState.isGetting = true;
|
|
622
507
|
var res = getters[key2].call(proxiedStore);
|
|
623
|
-
if (!isSubGetter)
|
|
624
|
-
gettersState.isGetting = false;
|
|
625
|
-
}
|
|
508
|
+
if (!isSubGetter) gettersState.isGetting = false;
|
|
626
509
|
var _iteratorNormalCompletion = true,
|
|
627
510
|
_didIteratorError = false,
|
|
628
511
|
_iteratorError = void 0;
|
|
629
512
|
try {
|
|
630
513
|
for (var _iterator = curGetKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
631
514
|
var gk = _step.value;
|
|
632
|
-
if (!depsToGetter.has(gk))
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
var cur = depsToGetter.get(gk);
|
|
636
|
-
cur.add(key2);
|
|
515
|
+
if (!depsToGetter.has(gk)) depsToGetter.set(gk, /* @__PURE__ */new Set());
|
|
516
|
+
depsToGetter.get(gk).add(key2);
|
|
637
517
|
}
|
|
638
518
|
} catch (err) {
|
|
639
519
|
_didIteratorError = true;
|
|
640
520
|
_iteratorError = err;
|
|
641
521
|
} finally {
|
|
642
522
|
try {
|
|
643
|
-
if (!_iteratorNormalCompletion && _iterator.return != null)
|
|
644
|
-
_iterator.return();
|
|
645
|
-
}
|
|
523
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
646
524
|
} finally {
|
|
647
|
-
if (_didIteratorError)
|
|
648
|
-
throw _iteratorError;
|
|
649
|
-
}
|
|
525
|
+
if (_didIteratorError) throw _iteratorError;
|
|
650
526
|
}
|
|
651
527
|
}
|
|
652
528
|
getCache.set(key2, res);
|
|
@@ -654,7 +530,6 @@ function createProxiedStore(storeInfo) {
|
|
|
654
530
|
}
|
|
655
531
|
return Reflect.get(storeInstance, key2);
|
|
656
532
|
},
|
|
657
|
-
// SET
|
|
658
533
|
set(target, key2, value, receiver) {
|
|
659
534
|
var cur = Reflect.get(target, key2);
|
|
660
535
|
var res = Reflect.set(target, key2, value, receiver);
|
|
@@ -666,16 +541,12 @@ function createProxiedStore(storeInfo) {
|
|
|
666
541
|
key: key2,
|
|
667
542
|
value
|
|
668
543
|
});
|
|
669
|
-
if (getShouldDebug(storeInfo))
|
|
670
|
-
console.info("(debug) SET", res, key2, value);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) {
|
|
674
|
-
console.info("SET...", {
|
|
675
|
-
key: key2,
|
|
676
|
-
value
|
|
677
|
-
});
|
|
544
|
+
if (getShouldDebug(storeInfo)) console.info("(debug) SET", res, key2, value);
|
|
678
545
|
}
|
|
546
|
+
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("SET...", {
|
|
547
|
+
key: key2,
|
|
548
|
+
value
|
|
549
|
+
});
|
|
679
550
|
}
|
|
680
551
|
if (!isTriggering) {
|
|
681
552
|
isTriggering = true;
|
|
@@ -691,9 +562,7 @@ function createProxiedStore(storeInfo) {
|
|
|
691
562
|
function clearGetterCache(setKey) {
|
|
692
563
|
var parentGetters = depsToGetter.get(setKey);
|
|
693
564
|
getCache.delete(setKey);
|
|
694
|
-
if (!parentGetters)
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
565
|
+
if (!parentGetters) return;
|
|
697
566
|
var _iteratorNormalCompletion = true,
|
|
698
567
|
_didIteratorError = false,
|
|
699
568
|
_iteratorError = void 0;
|
|
@@ -701,30 +570,24 @@ function createProxiedStore(storeInfo) {
|
|
|
701
570
|
for (var _iterator = parentGetters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
702
571
|
var gk = _step.value;
|
|
703
572
|
getCache.delete(gk);
|
|
704
|
-
if (depsToGetter.has(gk))
|
|
705
|
-
clearGetterCache(gk);
|
|
706
|
-
}
|
|
573
|
+
if (depsToGetter.has(gk)) clearGetterCache(gk);
|
|
707
574
|
}
|
|
708
575
|
} catch (err) {
|
|
709
576
|
_didIteratorError = true;
|
|
710
577
|
_iteratorError = err;
|
|
711
578
|
} finally {
|
|
712
579
|
try {
|
|
713
|
-
if (!_iteratorNormalCompletion && _iterator.return != null)
|
|
714
|
-
_iterator.return();
|
|
715
|
-
}
|
|
580
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
716
581
|
} finally {
|
|
717
|
-
if (_didIteratorError)
|
|
718
|
-
throw _iteratorError;
|
|
719
|
-
}
|
|
582
|
+
if (_didIteratorError) throw _iteratorError;
|
|
720
583
|
}
|
|
721
584
|
}
|
|
722
585
|
}
|
|
723
586
|
return proxiedStore;
|
|
724
587
|
}
|
|
725
|
-
var waitForEventLoop = process.env.NODE_ENV
|
|
588
|
+
var waitForEventLoop = (process.env.NODE_ENV, function (cb) {
|
|
726
589
|
return cb();
|
|
727
|
-
}
|
|
590
|
+
});
|
|
728
591
|
var counter = 0;
|
|
729
592
|
var passThroughKeys = {
|
|
730
593
|
subscribe: true,
|
|
@@ -738,8 +601,7 @@ function getShouldDebug(storeInfo) {
|
|
|
738
601
|
var info = {
|
|
739
602
|
storeInstance: storeInfo.store
|
|
740
603
|
};
|
|
741
|
-
|
|
742
|
-
return [...trackers].some(function (tracker) {
|
|
604
|
+
return [...storeInfo.trackers].some(function (tracker) {
|
|
743
605
|
return tracker.component && (0, import_useStoreDebug.shouldDebug)(tracker.component, info);
|
|
744
606
|
});
|
|
745
607
|
}
|