@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.
@@ -1,15 +1,14 @@
1
1
  import React from "react";
2
- import { isEqualSubsetShallow } from "./comparators.native.js";
3
- import { configureOpts } from "./configureUseStore.native.js";
4
- import { UNWRAP_PROXY, defaultOptions } from "./constants.native.js";
5
- import { UNWRAP_STORE_INFO, cache, getStoreDescriptors, getStoreUid, simpleStr } from "./helpers.native.js";
6
- import { DebugStores, shouldDebug, useCurrentComponent } from "./useStoreDebug.native.js";
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
- uid = getStoreUid(store.constructor, store.props),
27
- info = cache.get(uid);
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
- uid = getStoreUid(store.constructor, store.props),
36
- info = cache.get(uid);
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 (props, options) {
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 (props) {
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) return null;
85
+ if (!StoreKlass)
86
+ return null;
89
87
  var uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
90
- if (!options?.avoidCache && cache.has(uid)) return cache.get(uid);
91
- if (options?.refuseCreation) throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
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
- listeners = /* @__PURE__ */new Set(),
104
- storeInfo = {
105
- uid,
106
- keyComparators,
107
- storeInstance,
108
- getters,
109
- stateKeys,
110
- props,
111
- actions,
112
- debug: options?.debug,
113
- disableTracking: !1,
114
- gettersState: {
115
- getCache: /* @__PURE__ */new Map(),
116
- depsToGetter: /* @__PURE__ */new Map(),
117
- curGetKeys: /* @__PURE__ */new Set(),
118
- isGetting: !1
119
- },
120
- listeners,
121
- trackers: /* @__PURE__ */new Set(),
122
- version: 0,
123
- subscribe: function (onChanged) {
124
- return listeners.add(onChanged), function () {
125
- listeners.delete(onChanged);
126
- };
127
- },
128
- triggerUpdate: function () {
129
- storeInfo.version = (storeInfo.version + 1) % Number.MAX_SAFE_INTEGER;
130
- var _iteratorNormalCompletion = !0,
131
- _didIteratorError = !1,
132
- _iteratorError = void 0;
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
- for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
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
- try {
142
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
143
- } finally {
144
- if (_didIteratorError) throw _iteratorError;
145
- }
137
+ if (_didIteratorError)
138
+ throw _iteratorError;
146
139
  }
147
140
  }
148
- },
149
- store = createProxiedStore(
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 (cb) {
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
- selectKeys = function (obj, keys) {
165
- if (!keys.length) return emptyObj;
166
- var res = {},
167
- _iteratorNormalCompletion = !0,
168
- _didIteratorError = !1,
169
- _iteratorError = void 0;
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
- for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
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
- try {
179
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
180
- } finally {
181
- if (_didIteratorError) throw _iteratorError;
182
- }
172
+ if (_didIteratorError)
173
+ throw _iteratorError;
183
174
  }
184
- return res;
185
- },
186
- isInReaction = !1,
187
- setIsInReaction = function (val) {
188
- isInReaction = val;
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
- shouldPrintDebug = options?.debug,
202
- getSnapshot = React.useCallback(function () {
203
- if (!(!info || !store)) {
204
- var curInternal2 = internal.current,
205
- isTracking = curInternal2.tracked.size,
206
- keys = [...(isTracking ? curInternal2.tracked : info.stateKeys)],
207
- nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`,
208
- lastKeys = curInternal2.lastKeys;
209
- if (nextKeys === curInternal2.lastKeys) return curInternal2.last;
210
- curInternal2.lastKeys = nextKeys;
211
- var snap;
212
- info.disableTracking = !0;
213
- var last = curInternal2.last;
214
- userSelector ? snap = userSelector(store) : snap = selectKeys(store, keys), info.disableTracking = !1;
215
- var isUnchanged = !userSelector && !isTracking && last || typeof last < "u" && isEqualSubsetShallow(last, snap, {
216
- keyComparators: info.keyComparators
217
- });
218
- return shouldPrintDebug && console.info("\u{1F311} getSnapshot", {
219
- storeState: selectKeys(store, Object.keys(store)),
220
- userSelector,
221
- info,
222
- isUnchanged,
223
- component,
224
- keys,
225
- last,
226
- snap,
227
- curInternal: curInternal2,
228
- nextKeys,
229
- lastKeys
230
- }), isUnchanged ? last : (curInternal2.last = snap, snap);
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) return curVal;
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 (key2) {
247
- if (key2 === "subscribe") return "continue";
248
- var actionFn = actions[key2],
249
- isGetFn = key2.startsWith("get");
250
- if (wrappedActions[key2] = function () {
251
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
252
- var res;
253
- 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));
254
- }, process.env.NODE_ENV === "development") {
255
- let hashCode2 = function (str) {
256
- for (var hash = 0, i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
257
- return hash;
258
- },
259
- strColor2 = function (str) {
260
- return `hsl(${hashCode2(str) % 360}, 90%, 40%)`;
261
- };
262
- var hashCode = hashCode2,
263
- strColor = strColor2;
264
- if (!key2.startsWith("get") && !key2.startsWith("_") && key2 !== "subscribe") {
265
- var ogAction = wrappedActions[key2];
266
- wrappedActions[key2] = new Proxy(ogAction, {
267
- apply(target, thisArg, args) {
268
- var isDebugging = shouldDebug2 || storeInfo.debug,
269
- shouldLog = process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error");
270
- if (!shouldLog) return Reflect.apply(target, thisArg, args);
271
- setters = /* @__PURE__ */new Set();
272
- var curSetters = setters,
273
- isTopLevelLogger = logStack.size == 0,
274
- logs = /* @__PURE__ */new Set();
275
- logStack.add(logs);
276
- var res,
277
- id = counter++;
278
- try {
279
- res = Reflect.apply(target, thisArg, args);
280
- } catch (err) {
281
- throw console.error("Error", err), err;
282
- } finally {
283
- logStack.add("end");
284
- var name = constr.name,
285
- color = strColor2(name),
286
- simpleArgs = args.map(simpleStr);
287
- if (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;"]), curSetters.size && curSetters.forEach(function (param) {
288
- var {
289
- key: key3,
290
- value
291
- } = param;
292
- typeof value == "string" || typeof value == "number" || typeof value == "boolean" ? logs.add([` SET ${key3} ${value}`, value]) : logs.add([` SET ${key3}`, value]);
293
- }), isTopLevelLogger) {
294
- var error = null;
295
- try {
296
- for (var _i = 0, _iter = [...logStack]; _i < _iter.length; _i++) {
297
- var item = _iter[_i];
298
- if (item === "end") {
299
- console.groupEnd();
300
- continue;
301
- }
302
- var [head, ...rest] = item;
303
- if (head) {
304
- console.groupCollapsed(...head), console.groupCollapsed("..."), console.info("args", args), console.info("response", res), console.groupCollapsed("trace"), console.trace(), console.groupEnd(), console.groupEnd();
305
- var _iteratorNormalCompletion = !0,
306
- _didIteratorError = !1,
307
- _iteratorError = void 0;
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
- for (var _iterator = rest[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
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
- try {
317
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
318
- } finally {
319
- if (_didIteratorError) throw _iteratorError;
320
- }
307
+ if (_didIteratorError)
308
+ throw _iteratorError;
321
309
  }
322
- } else console.info("Weird log", head, ...rest);
323
- }
324
- } catch (err) {
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
- error && console.error("error loggin", error), logStack.clear();
314
+ } catch (err) {
315
+ error = err;
332
316
  }
333
- return res;
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 (val) {
358
- return process.env.NODE_ENV === "development" && shouldDebug2 && console.info("(debug) finishAction", {
359
- didSet
360
- }), didSet && (storeInfo.triggerUpdate(), didSet = !1), val;
361
- },
362
- isTriggering = !1,
363
- proxiedStore = new Proxy(storeInstance, {
364
- // GET
365
- get(_, key2) {
366
- if (key2 in wrappedActions) return wrappedActions[key2];
367
- if (key2 in passThroughKeys) return Reflect.get(storeInstance, key2);
368
- if (key2 === UNWRAP_PROXY) return storeInstance;
369
- if (key2 === UNWRAP_STORE_INFO) return storeInfo;
370
- if (storeAccessTrackers.size && storeAccessTrackers.forEach(function (cb) {
371
- return cb(storeInfo);
372
- }), typeof key2 != "string") return Reflect.get(storeInstance, key2);
373
- if (storeInfo.disableTracking || gettersState.isGetting && gettersState.curGetKeys.add(key2), key2 in getters) {
374
- if (getCache.has(key2)) return getCache.get(key2);
375
- curGetKeys.clear();
376
- var isSubGetter = gettersState.isGetting;
377
- gettersState.isGetting = !0;
378
- var res = getters[key2].call(proxiedStore);
379
- isSubGetter || (gettersState.isGetting = !1);
380
- var _iteratorNormalCompletion = !0,
381
- _didIteratorError = !1,
382
- _iteratorError = void 0;
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
- for (var _iterator = curGetKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
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
- try {
394
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
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 Reflect.get(storeInstance, key2);
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) throw _iteratorError;
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 (cb) {
443
- return cb();
444
- }),
445
- counter = 0,
446
- passThroughKeys = {
447
- subscribe: !0,
448
- _version: !0,
449
- _trackers: !0,
450
- $$typeof: !0,
451
- _listeners: !0,
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
- storeInstance: storeInfo.store
457
- },
458
- trackers = storeInfo.trackers;
459
- return [...trackers].some(function (tracker) {
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 { allStores, createStore, createUseStore, createUseStoreSelector, getOrCreateStore, getStore, getStoreInfo, onCreateStore, setIsInReaction, trackStoresAccess, useGlobalStore, useGlobalStoreSelector, useStore, useStoreDebug, useStoreSelector };
464
- //# sourceMappingURL=useStore.native.js.map
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