@tamagui/use-store 1.113.0 → 1.113.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/comparators.native.js +8 -6
- package/dist/esm/comparators.native.js.map +6 -1
- package/dist/esm/configureUseStore.native.js +5 -2
- package/dist/esm/configureUseStore.native.js.map +6 -1
- package/dist/esm/constants.native.js +9 -7
- package/dist/esm/constants.native.js.map +6 -1
- package/dist/esm/decorators.native.js +5 -3
- package/dist/esm/decorators.native.js.map +6 -1
- package/dist/esm/helpers.native.js +15 -11
- package/dist/esm/helpers.native.js.map +6 -1
- package/dist/esm/index.native.js +15 -11
- package/dist/esm/index.native.js.map +6 -1
- package/dist/esm/interfaces.native.js +1 -2
- package/dist/esm/interfaces.native.js.map +6 -1
- package/dist/esm/observe.native.js +98 -97
- package/dist/esm/observe.native.js.map +6 -1
- package/dist/esm/useStore.native.js +312 -320
- package/dist/esm/useStore.native.js.map +6 -1
- package/dist/esm/useStoreDebug.native.js +16 -14
- package/dist/esm/useStoreDebug.native.js.map +6 -1
- package/package.json +3 -3
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { isEqualSubsetShallow } from "./comparators
|
|
3
|
-
import { configureOpts } from "./configureUseStore
|
|
4
|
-
import { UNWRAP_PROXY, defaultOptions } from "./constants
|
|
5
|
-
import { UNWRAP_STORE_INFO, cache, getStoreDescriptors, getStoreUid, simpleStr } from "./helpers
|
|
6
|
-
import { DebugStores, shouldDebug, useCurrentComponent } from "./useStoreDebug
|
|
7
|
-
var idFn = function
|
|
2
|
+
import { isEqualSubsetShallow } from "./comparators";
|
|
3
|
+
import { configureOpts } from "./configureUseStore";
|
|
4
|
+
import { UNWRAP_PROXY, defaultOptions } from "./constants";
|
|
5
|
+
import { UNWRAP_STORE_INFO, cache, getStoreDescriptors, getStoreUid, simpleStr } from "./helpers";
|
|
6
|
+
import { DebugStores, shouldDebug, useCurrentComponent } from "./useStoreDebug";
|
|
7
|
+
var idFn = function(_) {
|
|
8
8
|
return _;
|
|
9
9
|
};
|
|
10
10
|
function useStore(StoreKlass, props) {
|
|
11
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions,
|
|
12
|
-
info = getOrCreateStoreInfo(StoreKlass, props, options);
|
|
11
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions, info = getOrCreateStoreInfo(StoreKlass, props, options);
|
|
13
12
|
return useStoreFromInfo(info, options.selector, options);
|
|
14
13
|
}
|
|
15
14
|
function useStoreDebug(StoreKlass, props) {
|
|
@@ -22,30 +21,28 @@ function createStore(StoreKlass, props, options) {
|
|
|
22
21
|
return (_getOrCreateStoreInfo = getOrCreateStoreInfo(StoreKlass, props, options)) === null || _getOrCreateStoreInfo === void 0 ? void 0 : _getOrCreateStoreInfo.store;
|
|
23
22
|
}
|
|
24
23
|
function useGlobalStore(instance, debug) {
|
|
25
|
-
var store = instance[UNWRAP_PROXY],
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!info) throw new Error("This store not created using createStore()");
|
|
24
|
+
var store = instance[UNWRAP_PROXY], uid = getStoreUid(store.constructor, store.props), info = cache.get(uid);
|
|
25
|
+
if (!info)
|
|
26
|
+
throw new Error("This store not created using createStore()");
|
|
29
27
|
return useStoreFromInfo(info, void 0, {
|
|
30
28
|
debug
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
function useGlobalStoreSelector(instance, selector, debug) {
|
|
34
|
-
var store = instance[UNWRAP_PROXY],
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!info) throw new Error("This store not created using createStore()");
|
|
32
|
+
var store = instance[UNWRAP_PROXY], uid = getStoreUid(store.constructor, store.props), info = cache.get(uid);
|
|
33
|
+
if (!info)
|
|
34
|
+
throw new Error("This store not created using createStore()");
|
|
38
35
|
return useStoreFromInfo(info, selector, {
|
|
39
36
|
debug
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
39
|
function createUseStore(StoreKlass) {
|
|
43
|
-
return function
|
|
40
|
+
return function(props, options) {
|
|
44
41
|
return useStore(StoreKlass, props, options);
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
function createUseStoreSelector(StoreKlass, selector) {
|
|
48
|
-
return function
|
|
45
|
+
return function(props) {
|
|
49
46
|
return useStore(StoreKlass, props, {
|
|
50
47
|
selector
|
|
51
48
|
});
|
|
@@ -56,9 +53,9 @@ function useStoreSelector(StoreKlass, selector, props) {
|
|
|
56
53
|
selector
|
|
57
54
|
});
|
|
58
55
|
}
|
|
59
|
-
var storeAccessTrackers = /* @__PURE__ */new Set();
|
|
56
|
+
var storeAccessTrackers = /* @__PURE__ */ new Set();
|
|
60
57
|
function trackStoresAccess(cb) {
|
|
61
|
-
return storeAccessTrackers.add(cb), function
|
|
58
|
+
return storeAccessTrackers.add(cb), function() {
|
|
62
59
|
storeAccessTrackers.delete(cb);
|
|
63
60
|
};
|
|
64
61
|
}
|
|
@@ -77,81 +74,78 @@ function getStoreInfo(StoreKlass, props) {
|
|
|
77
74
|
refuseCreation: !0
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
|
-
var onCreateListeners = /* @__PURE__ */new Set();
|
|
77
|
+
var onCreateListeners = /* @__PURE__ */ new Set();
|
|
81
78
|
function onCreateStore(cb) {
|
|
82
|
-
return onCreateListeners.add(cb), function
|
|
79
|
+
return onCreateListeners.add(cb), function() {
|
|
83
80
|
onCreateListeners.delete(cb);
|
|
84
81
|
};
|
|
85
82
|
}
|
|
86
83
|
function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
87
84
|
var _store_mount;
|
|
88
|
-
if (!StoreKlass)
|
|
85
|
+
if (!StoreKlass)
|
|
86
|
+
return null;
|
|
89
87
|
var uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
|
|
90
|
-
if (!options?.avoidCache && cache.has(uid))
|
|
91
|
-
|
|
88
|
+
if (!options?.avoidCache && cache.has(uid))
|
|
89
|
+
return cache.get(uid);
|
|
90
|
+
if (options?.refuseCreation)
|
|
91
|
+
throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
|
|
92
92
|
var storeInstance = new StoreKlass(props);
|
|
93
93
|
storeInstance.props = props;
|
|
94
|
-
var getters = {},
|
|
95
|
-
actions = {},
|
|
96
|
-
stateKeys = /* @__PURE__ */new Set(),
|
|
97
|
-
descriptors = getStoreDescriptors(storeInstance);
|
|
94
|
+
var getters = {}, actions = {}, stateKeys = /* @__PURE__ */ new Set(), descriptors = getStoreDescriptors(storeInstance);
|
|
98
95
|
for (var key in descriptors) {
|
|
99
96
|
var descriptor = descriptors[key];
|
|
100
97
|
typeof descriptor.value == "function" ? actions[key] = descriptor.value : typeof descriptor.get == "function" ? getters[key] = descriptor.get : key !== "props" && key[0] !== "_" && stateKeys.add(key);
|
|
101
98
|
}
|
|
102
|
-
var keyComparators = storeInstance._comparators,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
var _iteratorNormalCompletion = !0
|
|
131
|
-
|
|
132
|
-
|
|
99
|
+
var keyComparators = storeInstance._comparators, listeners = /* @__PURE__ */ new Set(), storeInfo = {
|
|
100
|
+
uid,
|
|
101
|
+
keyComparators,
|
|
102
|
+
storeInstance,
|
|
103
|
+
getters,
|
|
104
|
+
stateKeys,
|
|
105
|
+
props,
|
|
106
|
+
actions,
|
|
107
|
+
debug: options?.debug,
|
|
108
|
+
disableTracking: !1,
|
|
109
|
+
gettersState: {
|
|
110
|
+
getCache: /* @__PURE__ */ new Map(),
|
|
111
|
+
depsToGetter: /* @__PURE__ */ new Map(),
|
|
112
|
+
curGetKeys: /* @__PURE__ */ new Set(),
|
|
113
|
+
isGetting: !1
|
|
114
|
+
},
|
|
115
|
+
listeners,
|
|
116
|
+
trackers: /* @__PURE__ */ new Set(),
|
|
117
|
+
version: 0,
|
|
118
|
+
subscribe: function(onChanged) {
|
|
119
|
+
return listeners.add(onChanged), function() {
|
|
120
|
+
listeners.delete(onChanged);
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
triggerUpdate: function() {
|
|
124
|
+
storeInfo.version = (storeInfo.version + 1) % Number.MAX_SAFE_INTEGER;
|
|
125
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
126
|
+
try {
|
|
127
|
+
for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
128
|
+
var cb = _step.value;
|
|
129
|
+
cb();
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
133
|
+
} finally {
|
|
133
134
|
try {
|
|
134
|
-
|
|
135
|
-
var cb = _step.value;
|
|
136
|
-
cb();
|
|
137
|
-
}
|
|
138
|
-
} catch (err) {
|
|
139
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
135
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
140
136
|
} finally {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} finally {
|
|
144
|
-
if (_didIteratorError) throw _iteratorError;
|
|
145
|
-
}
|
|
137
|
+
if (_didIteratorError)
|
|
138
|
+
throw _iteratorError;
|
|
146
139
|
}
|
|
147
140
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
141
|
+
}
|
|
142
|
+
}, store = createProxiedStore(
|
|
150
143
|
// we assign store right after and proxiedStore never accesses it until later on
|
|
151
|
-
storeInfo
|
|
144
|
+
storeInfo
|
|
145
|
+
);
|
|
152
146
|
process.env.NODE_ENV === "development" && (allStores[StoreKlass.name + uid] = store), (_store_mount = store.mount) === null || _store_mount === void 0 || _store_mount.call(store), storeInfo.store = store;
|
|
153
147
|
var result = storeInfo;
|
|
154
|
-
return cache.set(uid, result), onCreateListeners.forEach(function
|
|
148
|
+
return cache.set(uid, result), onCreateListeners.forEach(function(cb) {
|
|
155
149
|
return cb(result);
|
|
156
150
|
}), result;
|
|
157
151
|
}
|
|
@@ -160,267 +154,249 @@ if (process.env.NODE_ENV === "development") {
|
|
|
160
154
|
var _globalThis, _Store;
|
|
161
155
|
(_globalThis = globalThis)[_Store = "Store"] || (_globalThis[_Store] = allStores);
|
|
162
156
|
}
|
|
163
|
-
var emptyObj = {},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
157
|
+
var emptyObj = {}, selectKeys = function(obj, keys) {
|
|
158
|
+
if (!keys.length)
|
|
159
|
+
return emptyObj;
|
|
160
|
+
var res = {}, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
161
|
+
try {
|
|
162
|
+
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
163
|
+
var key = _step.value;
|
|
164
|
+
res[key] = obj[key];
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
168
|
+
} finally {
|
|
170
169
|
try {
|
|
171
|
-
|
|
172
|
-
var key = _step.value;
|
|
173
|
-
res[key] = obj[key];
|
|
174
|
-
}
|
|
175
|
-
} catch (err) {
|
|
176
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
170
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
177
171
|
} finally {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
} finally {
|
|
181
|
-
if (_didIteratorError) throw _iteratorError;
|
|
182
|
-
}
|
|
172
|
+
if (_didIteratorError)
|
|
173
|
+
throw _iteratorError;
|
|
183
174
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
175
|
+
}
|
|
176
|
+
return res;
|
|
177
|
+
}, isInReaction = !1, setIsInReaction = function(val) {
|
|
178
|
+
isInReaction = val;
|
|
179
|
+
};
|
|
190
180
|
function useStoreFromInfo(info, userSelector, options) {
|
|
191
|
-
var store = info?.store,
|
|
192
|
-
internal = React.useRef(),
|
|
193
|
-
component = useCurrentComponent();
|
|
181
|
+
var store = info?.store, internal = React.useRef(), component = useCurrentComponent();
|
|
194
182
|
internal.current || (internal.current = {
|
|
195
183
|
component,
|
|
196
|
-
tracked: /* @__PURE__ */new Set(),
|
|
184
|
+
tracked: /* @__PURE__ */ new Set(),
|
|
197
185
|
last: null,
|
|
198
186
|
lastKeys: null
|
|
199
187
|
});
|
|
200
|
-
var curInternal = internal.current,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}, [store]),
|
|
233
|
-
state = React.useSyncExternalStore(info?.subscribe || idFn, getSnapshot, getSnapshot);
|
|
188
|
+
var curInternal = internal.current, shouldPrintDebug = options?.debug, getSnapshot = React.useCallback(function() {
|
|
189
|
+
if (!(!info || !store)) {
|
|
190
|
+
var curInternal2 = internal.current, isTracking = curInternal2.tracked.size, keys = [
|
|
191
|
+
...isTracking ? curInternal2.tracked : info.stateKeys
|
|
192
|
+
], nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`, lastKeys = curInternal2.lastKeys;
|
|
193
|
+
if (nextKeys === curInternal2.lastKeys)
|
|
194
|
+
return curInternal2.last;
|
|
195
|
+
curInternal2.lastKeys = nextKeys;
|
|
196
|
+
var snap;
|
|
197
|
+
info.disableTracking = !0;
|
|
198
|
+
var last = curInternal2.last;
|
|
199
|
+
userSelector ? snap = userSelector(store) : snap = selectKeys(store, keys), info.disableTracking = !1;
|
|
200
|
+
var isUnchanged = !userSelector && !isTracking && last || typeof last < "u" && isEqualSubsetShallow(last, snap, {
|
|
201
|
+
keyComparators: info.keyComparators
|
|
202
|
+
});
|
|
203
|
+
return shouldPrintDebug && console.info("\u{1F311} getSnapshot", {
|
|
204
|
+
storeState: selectKeys(store, Object.keys(store)),
|
|
205
|
+
userSelector,
|
|
206
|
+
info,
|
|
207
|
+
isUnchanged,
|
|
208
|
+
component,
|
|
209
|
+
keys,
|
|
210
|
+
last,
|
|
211
|
+
snap,
|
|
212
|
+
curInternal: curInternal2,
|
|
213
|
+
nextKeys,
|
|
214
|
+
lastKeys
|
|
215
|
+
}), isUnchanged ? last : (curInternal2.last = snap, snap);
|
|
216
|
+
}
|
|
217
|
+
}, [
|
|
218
|
+
store
|
|
219
|
+
]), state = React.useSyncExternalStore(info?.subscribe || idFn, getSnapshot, getSnapshot);
|
|
234
220
|
return !info || !store || !state || userSelector ? state : new Proxy(store, {
|
|
235
221
|
get(target, key) {
|
|
236
222
|
var curVal = Reflect.get(target, key);
|
|
237
|
-
if (isInReaction)
|
|
223
|
+
if (isInReaction)
|
|
224
|
+
return curVal;
|
|
238
225
|
var keyString = key;
|
|
239
226
|
return (info.stateKeys.has(keyString) || keyString in info.getters) && (shouldPrintDebug && console.info("\u{1F440} tracking", keyString), curInternal.tracked.add(keyString)), Reflect.has(state, key) ? Reflect.get(state, key) : curVal;
|
|
240
227
|
}
|
|
241
228
|
});
|
|
242
229
|
}
|
|
243
|
-
var setters = /* @__PURE__ */new Set(),
|
|
244
|
-
logStack = /* @__PURE__ */new Set();
|
|
230
|
+
var setters = /* @__PURE__ */ new Set(), logStack = /* @__PURE__ */ new Set();
|
|
245
231
|
function createProxiedStore(storeInfo) {
|
|
246
|
-
var _loop = function
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
logStack.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
232
|
+
var _loop = function(key2) {
|
|
233
|
+
if (key2 === "subscribe")
|
|
234
|
+
return "continue";
|
|
235
|
+
var actionFn = actions[key2], isGetFn = key2.startsWith("get");
|
|
236
|
+
if (wrappedActions[key2] = function() {
|
|
237
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)
|
|
238
|
+
args[_key] = arguments[_key];
|
|
239
|
+
var res;
|
|
240
|
+
return isGetFn || gettersState.isGetting ? Reflect.apply(actionFn, proxiedStore, args) : (process.env.NODE_ENV === "development" && shouldDebug2 && console.info("(debug) startAction", key2), res = Reflect.apply(actionFn, proxiedStore, args), res instanceof Promise ? res.then(finishAction) : (finishAction(), res));
|
|
241
|
+
}, process.env.NODE_ENV === "development") {
|
|
242
|
+
let hashCode2 = function(str) {
|
|
243
|
+
for (var hash = 0, i = 0; i < str.length; i++)
|
|
244
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
245
|
+
return hash;
|
|
246
|
+
}, strColor2 = function(str) {
|
|
247
|
+
return `hsl(${hashCode2(str) % 360}, 90%, 40%)`;
|
|
248
|
+
};
|
|
249
|
+
var hashCode = hashCode2, strColor = strColor2;
|
|
250
|
+
if (!key2.startsWith("get") && !key2.startsWith("_") && key2 !== "subscribe") {
|
|
251
|
+
var ogAction = wrappedActions[key2];
|
|
252
|
+
wrappedActions[key2] = new Proxy(ogAction, {
|
|
253
|
+
apply(target, thisArg, args) {
|
|
254
|
+
var isDebugging = shouldDebug2 || storeInfo.debug, shouldLog = process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error");
|
|
255
|
+
if (!shouldLog)
|
|
256
|
+
return Reflect.apply(target, thisArg, args);
|
|
257
|
+
setters = /* @__PURE__ */ new Set();
|
|
258
|
+
var curSetters = setters, isTopLevelLogger = logStack.size == 0, logs = /* @__PURE__ */ new Set();
|
|
259
|
+
logStack.add(logs);
|
|
260
|
+
var res, id = counter++;
|
|
261
|
+
try {
|
|
262
|
+
res = Reflect.apply(target, thisArg, args);
|
|
263
|
+
} catch (err) {
|
|
264
|
+
throw console.error("Error", err), err;
|
|
265
|
+
} finally {
|
|
266
|
+
logStack.add("end");
|
|
267
|
+
var name = constr.name, color = strColor2(name), simpleArgs = args.map(simpleStr);
|
|
268
|
+
if (logs.add([
|
|
269
|
+
`%c \u{1F311} ${id} ${name.padStart(isTopLevelLogger ? 8 : 4)}%c.${key2}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`,
|
|
270
|
+
`color: ${color};`,
|
|
271
|
+
"color: black;"
|
|
272
|
+
]), curSetters.size && curSetters.forEach(function(param) {
|
|
273
|
+
var { key: key3, value } = param;
|
|
274
|
+
typeof value == "string" || typeof value == "number" || typeof value == "boolean" ? logs.add([
|
|
275
|
+
` SET ${key3} ${value}`,
|
|
276
|
+
value
|
|
277
|
+
]) : logs.add([
|
|
278
|
+
` SET ${key3}`,
|
|
279
|
+
value
|
|
280
|
+
]);
|
|
281
|
+
}), isTopLevelLogger) {
|
|
282
|
+
var error = null;
|
|
283
|
+
try {
|
|
284
|
+
for (var _i = 0, _iter = [
|
|
285
|
+
...logStack
|
|
286
|
+
]; _i < _iter.length; _i++) {
|
|
287
|
+
var item = _iter[_i];
|
|
288
|
+
if (item === "end") {
|
|
289
|
+
console.groupEnd();
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
var [head, ...rest] = item;
|
|
293
|
+
if (head) {
|
|
294
|
+
console.groupCollapsed(...head), console.groupCollapsed("..."), console.info("args", args), console.info("response", res), console.groupCollapsed("trace"), console.trace(), console.groupEnd(), console.groupEnd();
|
|
295
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
296
|
+
try {
|
|
297
|
+
for (var _iterator = rest[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
298
|
+
var [name1, ...log] = _step.value;
|
|
299
|
+
console.groupCollapsed(name1), console.info(...log), console.groupEnd();
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
303
|
+
} finally {
|
|
308
304
|
try {
|
|
309
|
-
|
|
310
|
-
var [name1, ...log] = _step.value;
|
|
311
|
-
console.groupCollapsed(name1), console.info(...log), console.groupEnd();
|
|
312
|
-
}
|
|
313
|
-
} catch (err) {
|
|
314
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
305
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
315
306
|
} finally {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
} finally {
|
|
319
|
-
if (_didIteratorError) throw _iteratorError;
|
|
320
|
-
}
|
|
307
|
+
if (_didIteratorError)
|
|
308
|
+
throw _iteratorError;
|
|
321
309
|
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
error = err;
|
|
326
|
-
}
|
|
327
|
-
for (var _i1 = 0, _iter1 = [...logStack]; _i1 < _iter1.length; _i1++) {
|
|
328
|
-
var _ = _iter1[_i1];
|
|
329
|
-
console.groupEnd();
|
|
310
|
+
}
|
|
311
|
+
} else
|
|
312
|
+
console.info("Weird log", head, ...rest);
|
|
330
313
|
}
|
|
331
|
-
|
|
314
|
+
} catch (err) {
|
|
315
|
+
error = err;
|
|
332
316
|
}
|
|
333
|
-
|
|
317
|
+
for (var _i1 = 0, _iter1 = [
|
|
318
|
+
...logStack
|
|
319
|
+
]; _i1 < _iter1.length; _i1++) {
|
|
320
|
+
var _ = _iter1[_i1];
|
|
321
|
+
console.groupEnd();
|
|
322
|
+
}
|
|
323
|
+
error && console.error("error loggin", error), logStack.clear();
|
|
334
324
|
}
|
|
325
|
+
return res;
|
|
335
326
|
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
338
329
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
actions,
|
|
342
|
-
storeInstance,
|
|
343
|
-
getters,
|
|
344
|
-
gettersState
|
|
345
|
-
} = storeInfo,
|
|
346
|
-
{
|
|
347
|
-
getCache,
|
|
348
|
-
curGetKeys,
|
|
349
|
-
depsToGetter
|
|
350
|
-
} = gettersState,
|
|
351
|
-
constr = storeInstance.constructor,
|
|
352
|
-
_storeInfo_debug,
|
|
353
|
-
shouldDebug2 = (_storeInfo_debug = storeInfo.debug) !== null && _storeInfo_debug !== void 0 ? _storeInfo_debug : DebugStores.has(constr),
|
|
354
|
-
didSet = !1,
|
|
355
|
-
wrappedActions = {};
|
|
330
|
+
}
|
|
331
|
+
}, { actions, storeInstance, getters, gettersState } = storeInfo, { getCache, curGetKeys, depsToGetter } = gettersState, constr = storeInstance.constructor, _storeInfo_debug, shouldDebug2 = (_storeInfo_debug = storeInfo.debug) !== null && _storeInfo_debug !== void 0 ? _storeInfo_debug : DebugStores.has(constr), didSet = !1, wrappedActions = {};
|
|
356
332
|
for (var key in actions) _loop(key);
|
|
357
|
-
var finishAction = function
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
333
|
+
var finishAction = function(val) {
|
|
334
|
+
return process.env.NODE_ENV === "development" && shouldDebug2 && console.info("(debug) finishAction", {
|
|
335
|
+
didSet
|
|
336
|
+
}), didSet && (storeInfo.triggerUpdate(), didSet = !1), val;
|
|
337
|
+
}, isTriggering = !1, proxiedStore = new Proxy(storeInstance, {
|
|
338
|
+
// GET
|
|
339
|
+
get(_, key2) {
|
|
340
|
+
if (key2 in wrappedActions)
|
|
341
|
+
return wrappedActions[key2];
|
|
342
|
+
if (key2 in passThroughKeys)
|
|
343
|
+
return Reflect.get(storeInstance, key2);
|
|
344
|
+
if (key2 === UNWRAP_PROXY)
|
|
345
|
+
return storeInstance;
|
|
346
|
+
if (key2 === UNWRAP_STORE_INFO)
|
|
347
|
+
return storeInfo;
|
|
348
|
+
if (storeAccessTrackers.size && storeAccessTrackers.forEach(function(cb) {
|
|
349
|
+
return cb(storeInfo);
|
|
350
|
+
}), typeof key2 != "string")
|
|
351
|
+
return Reflect.get(storeInstance, key2);
|
|
352
|
+
if (storeInfo.disableTracking || gettersState.isGetting && gettersState.curGetKeys.add(key2), key2 in getters) {
|
|
353
|
+
if (getCache.has(key2))
|
|
354
|
+
return getCache.get(key2);
|
|
355
|
+
curGetKeys.clear();
|
|
356
|
+
var isSubGetter = gettersState.isGetting;
|
|
357
|
+
gettersState.isGetting = !0;
|
|
358
|
+
var res = getters[key2].call(proxiedStore);
|
|
359
|
+
isSubGetter || (gettersState.isGetting = !1);
|
|
360
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
361
|
+
try {
|
|
362
|
+
for (var _iterator = curGetKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
363
|
+
var gk = _step.value;
|
|
364
|
+
depsToGetter.has(gk) || depsToGetter.set(gk, /* @__PURE__ */ new Set());
|
|
365
|
+
var cur = depsToGetter.get(gk);
|
|
366
|
+
cur.add(key2);
|
|
367
|
+
}
|
|
368
|
+
} catch (err) {
|
|
369
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
370
|
+
} finally {
|
|
383
371
|
try {
|
|
384
|
-
|
|
385
|
-
var gk = _step.value;
|
|
386
|
-
depsToGetter.has(gk) || depsToGetter.set(gk, /* @__PURE__ */new Set());
|
|
387
|
-
var cur = depsToGetter.get(gk);
|
|
388
|
-
cur.add(key2);
|
|
389
|
-
}
|
|
390
|
-
} catch (err) {
|
|
391
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
372
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
392
373
|
} finally {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
} finally {
|
|
396
|
-
if (_didIteratorError) throw _iteratorError;
|
|
397
|
-
}
|
|
374
|
+
if (_didIteratorError)
|
|
375
|
+
throw _iteratorError;
|
|
398
376
|
}
|
|
399
|
-
return getCache.set(key2, res), res;
|
|
400
377
|
}
|
|
401
|
-
return
|
|
402
|
-
},
|
|
403
|
-
// SET
|
|
404
|
-
set(target, key2, value, receiver) {
|
|
405
|
-
var cur = Reflect.get(target, key2),
|
|
406
|
-
res = Reflect.set(target, key2, value, receiver);
|
|
407
|
-
return res && cur !== value && (typeof key2 == "string" && (clearGetterCache(key2), shouldDebug2 && (setters.add({
|
|
408
|
-
key: key2,
|
|
409
|
-
value
|
|
410
|
-
}), getShouldDebug(storeInfo) && console.info("(debug) SET", res, key2, value)), process.env.NODE_ENV === "development" && shouldDebug2 && console.info("SET...", {
|
|
411
|
-
key: key2,
|
|
412
|
-
value
|
|
413
|
-
})), isTriggering || (isTriggering = !0, waitForEventLoop(function () {
|
|
414
|
-
storeInfo.triggerUpdate(), isTriggering = !1;
|
|
415
|
-
}))), res;
|
|
378
|
+
return getCache.set(key2, res), res;
|
|
416
379
|
}
|
|
417
|
-
|
|
380
|
+
return Reflect.get(storeInstance, key2);
|
|
381
|
+
},
|
|
382
|
+
// SET
|
|
383
|
+
set(target, key2, value, receiver) {
|
|
384
|
+
var cur = Reflect.get(target, key2), res = Reflect.set(target, key2, value, receiver);
|
|
385
|
+
return res && cur !== value && (typeof key2 == "string" && (clearGetterCache(key2), shouldDebug2 && (setters.add({
|
|
386
|
+
key: key2,
|
|
387
|
+
value
|
|
388
|
+
}), getShouldDebug(storeInfo) && console.info("(debug) SET", res, key2, value)), process.env.NODE_ENV === "development" && shouldDebug2 && console.info("SET...", {
|
|
389
|
+
key: key2,
|
|
390
|
+
value
|
|
391
|
+
})), isTriggering || (isTriggering = !0, waitForEventLoop(function() {
|
|
392
|
+
storeInfo.triggerUpdate(), isTriggering = !1;
|
|
393
|
+
}))), res;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
418
396
|
function clearGetterCache(setKey) {
|
|
419
397
|
var parentGetters = depsToGetter.get(setKey);
|
|
420
398
|
if (getCache.delete(setKey), !!parentGetters) {
|
|
421
|
-
var _iteratorNormalCompletion = !0,
|
|
422
|
-
_didIteratorError = !1,
|
|
423
|
-
_iteratorError = void 0;
|
|
399
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
424
400
|
try {
|
|
425
401
|
for (var _iterator = parentGetters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
426
402
|
var gk = _step.value;
|
|
@@ -432,33 +408,49 @@ function createProxiedStore(storeInfo) {
|
|
|
432
408
|
try {
|
|
433
409
|
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
434
410
|
} finally {
|
|
435
|
-
if (_didIteratorError)
|
|
411
|
+
if (_didIteratorError)
|
|
412
|
+
throw _iteratorError;
|
|
436
413
|
}
|
|
437
414
|
}
|
|
438
415
|
}
|
|
439
416
|
}
|
|
440
417
|
return proxiedStore;
|
|
441
418
|
}
|
|
442
|
-
var waitForEventLoop = (process.env.NODE_ENV, function
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
_enableTracking: !0
|
|
453
|
-
};
|
|
419
|
+
var waitForEventLoop = (process.env.NODE_ENV, function(cb) {
|
|
420
|
+
return cb();
|
|
421
|
+
}), counter = 0, passThroughKeys = {
|
|
422
|
+
subscribe: !0,
|
|
423
|
+
_version: !0,
|
|
424
|
+
_trackers: !0,
|
|
425
|
+
$$typeof: !0,
|
|
426
|
+
_listeners: !0,
|
|
427
|
+
_enableTracking: !0
|
|
428
|
+
};
|
|
454
429
|
function getShouldDebug(storeInfo) {
|
|
455
430
|
var info = {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
431
|
+
storeInstance: storeInfo.store
|
|
432
|
+
}, trackers = storeInfo.trackers;
|
|
433
|
+
return [
|
|
434
|
+
...trackers
|
|
435
|
+
].some(function(tracker) {
|
|
460
436
|
return tracker.component && shouldDebug(tracker.component, info);
|
|
461
437
|
});
|
|
462
438
|
}
|
|
463
|
-
export {
|
|
464
|
-
|
|
439
|
+
export {
|
|
440
|
+
allStores,
|
|
441
|
+
createStore,
|
|
442
|
+
createUseStore,
|
|
443
|
+
createUseStoreSelector,
|
|
444
|
+
getOrCreateStore,
|
|
445
|
+
getStore,
|
|
446
|
+
getStoreInfo,
|
|
447
|
+
onCreateStore,
|
|
448
|
+
setIsInReaction,
|
|
449
|
+
trackStoresAccess,
|
|
450
|
+
useGlobalStore,
|
|
451
|
+
useGlobalStoreSelector,
|
|
452
|
+
useStore,
|
|
453
|
+
useStoreDebug,
|
|
454
|
+
useStoreSelector
|
|
455
|
+
};
|
|
456
|
+
//# sourceMappingURL=useStore.js.map
|