@tamagui/use-store 1.15.40
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/README.md +91 -0
- package/dist/cjs/Store.js +99 -0
- package/dist/cjs/Store.js.map +6 -0
- package/dist/cjs/comparators.js +45 -0
- package/dist/cjs/comparators.js.map +6 -0
- package/dist/cjs/configureUseStore.js +34 -0
- package/dist/cjs/configureUseStore.js.map +6 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/constants.js.map +6 -0
- package/dist/cjs/decorators.js +34 -0
- package/dist/cjs/decorators.js.map +6 -0
- package/dist/cjs/fastCompare.js +168 -0
- package/dist/cjs/fastCompare.js.map +6 -0
- package/dist/cjs/helpers.js +101 -0
- package/dist/cjs/helpers.js.map +6 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/interfaces.js +17 -0
- package/dist/cjs/interfaces.js.map +6 -0
- package/dist/cjs/reaction.js +78 -0
- package/dist/cjs/reaction.js.map +6 -0
- package/dist/cjs/selector.js +139 -0
- package/dist/cjs/selector.js.map +6 -0
- package/dist/cjs/useStore.js +534 -0
- package/dist/cjs/useStore.js.map +6 -0
- package/dist/cjs/useStoreDebug.js +73 -0
- package/dist/cjs/useStoreDebug.js.map +6 -0
- package/dist/esm/Store.js +69 -0
- package/dist/esm/Store.js.map +6 -0
- package/dist/esm/Store.mjs +69 -0
- package/dist/esm/Store.mjs.map +6 -0
- package/dist/esm/comparators.js +21 -0
- package/dist/esm/comparators.js.map +6 -0
- package/dist/esm/comparators.mjs +21 -0
- package/dist/esm/comparators.mjs.map +6 -0
- package/dist/esm/configureUseStore.js +9 -0
- package/dist/esm/configureUseStore.js.map +6 -0
- package/dist/esm/configureUseStore.mjs +9 -0
- package/dist/esm/configureUseStore.mjs.map +6 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +6 -0
- package/dist/esm/constants.mjs +10 -0
- package/dist/esm/constants.mjs.map +6 -0
- package/dist/esm/decorators.js +10 -0
- package/dist/esm/decorators.js.map +6 -0
- package/dist/esm/decorators.mjs +10 -0
- package/dist/esm/decorators.mjs.map +6 -0
- package/dist/esm/fastCompare.js +143 -0
- package/dist/esm/fastCompare.js.map +6 -0
- package/dist/esm/fastCompare.mjs +143 -0
- package/dist/esm/fastCompare.mjs.map +6 -0
- package/dist/esm/helpers.js +70 -0
- package/dist/esm/helpers.js.map +6 -0
- package/dist/esm/helpers.mjs +70 -0
- package/dist/esm/helpers.mjs.map +6 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/index.mjs.map +6 -0
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/interfaces.js.map +6 -0
- package/dist/esm/interfaces.mjs +1 -0
- package/dist/esm/interfaces.mjs.map +6 -0
- package/dist/esm/reaction.js +53 -0
- package/dist/esm/reaction.js.map +6 -0
- package/dist/esm/reaction.mjs +53 -0
- package/dist/esm/reaction.mjs.map +6 -0
- package/dist/esm/selector.js +114 -0
- package/dist/esm/selector.js.map +6 -0
- package/dist/esm/selector.mjs +114 -0
- package/dist/esm/selector.mjs.map +6 -0
- package/dist/esm/useStore.js +516 -0
- package/dist/esm/useStore.js.map +6 -0
- package/dist/esm/useStore.mjs +516 -0
- package/dist/esm/useStore.mjs.map +6 -0
- package/dist/esm/useStoreDebug.js +35 -0
- package/dist/esm/useStoreDebug.js.map +6 -0
- package/dist/esm/useStoreDebug.mjs +35 -0
- package/dist/esm/useStoreDebug.mjs.map +6 -0
- package/package.json +44 -0
- package/src/Store.tsx +77 -0
- package/src/comparators.tsx +18 -0
- package/src/configureUseStore.tsx +7 -0
- package/src/constants.tsx +6 -0
- package/src/decorators.tsx +8 -0
- package/src/helpers.tsx +87 -0
- package/src/index.ts +9 -0
- package/src/interfaces.tsx +32 -0
- package/src/reaction.tsx +109 -0
- package/src/selector.tsx +129 -0
- package/src/useStore.tsx +705 -0
- package/src/useStoreDebug.tsx +40 -0
- package/types/Store.d.ts +28 -0
- package/types/Store.d.ts.map +1 -0
- package/types/comparators.d.ts +6 -0
- package/types/comparators.d.ts.map +1 -0
- package/types/configureUseStore.d.ts +4 -0
- package/types/configureUseStore.d.ts.map +1 -0
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/decorators.d.ts +3 -0
- package/types/decorators.d.ts.map +1 -0
- package/types/fastCompare.d.ts +13 -0
- package/types/fastCompare.d.ts.map +1 -0
- package/types/helpers.d.ts +13 -0
- package/types/helpers.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -0
- package/types/interfaces.d.ts +30 -0
- package/types/interfaces.d.ts.map +1 -0
- package/types/reaction.d.ts +4 -0
- package/types/reaction.d.ts.map +1 -0
- package/types/selector.d.ts +3 -0
- package/types/selector.d.ts.map +1 -0
- package/types/useStore.d.ts +18 -0
- package/types/useStore.d.ts.map +1 -0
- package/types/useStoreDebug.d.ts +7 -0
- package/types/useStoreDebug.d.ts.map +1 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim";
|
|
3
|
+
import { isEqualSubsetShallow } from "./comparators";
|
|
4
|
+
import { configureOpts } from "./configureUseStore";
|
|
5
|
+
import { UNWRAP_PROXY, defaultOptions } from "./constants";
|
|
6
|
+
import {
|
|
7
|
+
UNWRAP_STORE_INFO,
|
|
8
|
+
cache,
|
|
9
|
+
getStoreDescriptors,
|
|
10
|
+
getStoreUid,
|
|
11
|
+
simpleStr
|
|
12
|
+
} from "./helpers";
|
|
13
|
+
import {
|
|
14
|
+
ADD_TRACKER,
|
|
15
|
+
SHOULD_DEBUG,
|
|
16
|
+
TRACK,
|
|
17
|
+
TRIGGER_UPDATE,
|
|
18
|
+
disableTracking,
|
|
19
|
+
setDisableStoreTracking
|
|
20
|
+
} from "./Store";
|
|
21
|
+
import {
|
|
22
|
+
DebugStores,
|
|
23
|
+
shouldDebug,
|
|
24
|
+
useCurrentComponent,
|
|
25
|
+
useDebugStoreComponent
|
|
26
|
+
} from "./useStoreDebug";
|
|
27
|
+
const idFn = (_) => _;
|
|
28
|
+
function useStore(StoreKlass, props, options = defaultOptions) {
|
|
29
|
+
const selectorCb = useCallback(options.selector || idFn, []);
|
|
30
|
+
const selector = options.selector ? selectorCb : options.selector;
|
|
31
|
+
if (options.debug) {
|
|
32
|
+
useDebugStoreComponent(StoreKlass);
|
|
33
|
+
}
|
|
34
|
+
const info = getOrCreateStoreInfo(StoreKlass, props);
|
|
35
|
+
return useStoreFromInfo(info, selector);
|
|
36
|
+
}
|
|
37
|
+
function useStoreDebug(StoreKlass, props, selector) {
|
|
38
|
+
useDebugStoreComponent(StoreKlass);
|
|
39
|
+
return useStore(StoreKlass, props, selector);
|
|
40
|
+
}
|
|
41
|
+
function createStore(StoreKlass, props) {
|
|
42
|
+
return getOrCreateStoreInfo(StoreKlass, props).store;
|
|
43
|
+
}
|
|
44
|
+
function useGlobalStore(instance, debug) {
|
|
45
|
+
const store = instance[UNWRAP_PROXY];
|
|
46
|
+
const uid = getStoreUid(store.constructor, store.props);
|
|
47
|
+
const info = cache.get(uid);
|
|
48
|
+
if (!info) {
|
|
49
|
+
throw new Error(`This store not created using createStore()`);
|
|
50
|
+
}
|
|
51
|
+
if (debug) {
|
|
52
|
+
useDebugStoreComponent(store.constructor);
|
|
53
|
+
}
|
|
54
|
+
return useStoreFromInfo(info);
|
|
55
|
+
}
|
|
56
|
+
function useGlobalStoreSelector(instance, selector, debug) {
|
|
57
|
+
const store = instance[UNWRAP_PROXY];
|
|
58
|
+
const uid = getStoreUid(store.constructor, store.props);
|
|
59
|
+
const info = cache.get(uid);
|
|
60
|
+
if (!info) {
|
|
61
|
+
throw new Error(`This store not created using createStore()`);
|
|
62
|
+
}
|
|
63
|
+
if (debug) {
|
|
64
|
+
useDebugStoreComponent(store.constructor);
|
|
65
|
+
}
|
|
66
|
+
return useStoreFromInfo(info, selector);
|
|
67
|
+
}
|
|
68
|
+
function createUseStore(StoreKlass) {
|
|
69
|
+
return function(props, options) {
|
|
70
|
+
return useStore(StoreKlass, props, options);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function createUseStoreSelector(StoreKlass, selector) {
|
|
74
|
+
return (props) => {
|
|
75
|
+
return useStore(StoreKlass, props, { selector });
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function useStoreSelector(StoreKlass, selector, props) {
|
|
79
|
+
return useStore(StoreKlass, props, { selector });
|
|
80
|
+
}
|
|
81
|
+
const storeAccessTrackers = /* @__PURE__ */ new Set();
|
|
82
|
+
function trackStoresAccess(cb) {
|
|
83
|
+
storeAccessTrackers.add(cb);
|
|
84
|
+
return () => {
|
|
85
|
+
storeAccessTrackers.delete(cb);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function useStoreOnce(StoreKlass, props, selector) {
|
|
89
|
+
return useStore(StoreKlass, props, { selector, once: true });
|
|
90
|
+
}
|
|
91
|
+
function getStore(StoreKlass, props) {
|
|
92
|
+
return getOrCreateStoreInfo(StoreKlass, props).store;
|
|
93
|
+
}
|
|
94
|
+
function getOrCreateStoreInfo(StoreKlass, props, opts, propsKeyCalculated) {
|
|
95
|
+
var _a;
|
|
96
|
+
const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
|
|
97
|
+
if (!(opts == null ? void 0 : opts.avoidCache)) {
|
|
98
|
+
const cached = cache.get(uid);
|
|
99
|
+
if (cached) {
|
|
100
|
+
if (cached.storeInstance.constructor.toString() !== StoreKlass.toString()) {
|
|
101
|
+
console.warn(
|
|
102
|
+
"Error: Stores must have a unique name (ignore if this is a hot reload)"
|
|
103
|
+
);
|
|
104
|
+
} else {
|
|
105
|
+
return cached;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const storeInstance = new StoreKlass(props);
|
|
110
|
+
const getters = {};
|
|
111
|
+
const actions = {};
|
|
112
|
+
const stateKeys = [];
|
|
113
|
+
const descriptors = getStoreDescriptors(storeInstance);
|
|
114
|
+
for (const key in descriptors) {
|
|
115
|
+
const descriptor = descriptors[key];
|
|
116
|
+
if (typeof descriptor.value === "function") {
|
|
117
|
+
actions[key] = descriptor.value;
|
|
118
|
+
} else if (typeof descriptor.get === "function") {
|
|
119
|
+
getters[key] = descriptor.get;
|
|
120
|
+
} else {
|
|
121
|
+
if (key !== "props" && key[0] !== "_") {
|
|
122
|
+
stateKeys.push(key);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const keyComparators = storeInstance["_comparators"];
|
|
127
|
+
const storeInfo = {
|
|
128
|
+
keyComparators,
|
|
129
|
+
storeInstance,
|
|
130
|
+
getters,
|
|
131
|
+
stateKeys,
|
|
132
|
+
actions,
|
|
133
|
+
gettersState: {
|
|
134
|
+
getCache: /* @__PURE__ */ new Map(),
|
|
135
|
+
depsToGetter: /* @__PURE__ */ new Map(),
|
|
136
|
+
curGetKeys: /* @__PURE__ */ new Set(),
|
|
137
|
+
isGetting: false
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const store = createProxiedStore(storeInfo);
|
|
141
|
+
if (process.env.NODE_ENV === "development") {
|
|
142
|
+
allStores[uid] = store;
|
|
143
|
+
}
|
|
144
|
+
(_a = store.mount) == null ? void 0 : _a.call(store);
|
|
145
|
+
const value = {
|
|
146
|
+
...storeInfo,
|
|
147
|
+
store
|
|
148
|
+
};
|
|
149
|
+
if (!(opts == null ? void 0 : opts.avoidCache)) {
|
|
150
|
+
cache.set(uid, value);
|
|
151
|
+
}
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
const allStores = {};
|
|
155
|
+
const emptyObj = {};
|
|
156
|
+
const selectKeys = (obj, keys) => {
|
|
157
|
+
if (!keys.length) {
|
|
158
|
+
return emptyObj;
|
|
159
|
+
}
|
|
160
|
+
const res = {};
|
|
161
|
+
for (const key of keys) {
|
|
162
|
+
res[key] = obj[key];
|
|
163
|
+
}
|
|
164
|
+
return res;
|
|
165
|
+
};
|
|
166
|
+
let isInReaction = false;
|
|
167
|
+
const setIsInReaction = (val) => {
|
|
168
|
+
isInReaction = val;
|
|
169
|
+
};
|
|
170
|
+
function useStoreFromInfo(info, userSelector) {
|
|
171
|
+
const { store } = info;
|
|
172
|
+
if (!store) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const internal = useRef();
|
|
176
|
+
const component = useCurrentComponent();
|
|
177
|
+
if (!internal.current) {
|
|
178
|
+
internal.current = {
|
|
179
|
+
component,
|
|
180
|
+
isTracking: false,
|
|
181
|
+
firstRun: true,
|
|
182
|
+
tracked: /* @__PURE__ */ new Set(),
|
|
183
|
+
dispose: null,
|
|
184
|
+
last: null,
|
|
185
|
+
lastKeys: null
|
|
186
|
+
};
|
|
187
|
+
const dispose = store[ADD_TRACKER](internal.current);
|
|
188
|
+
internal.current.dispose = dispose;
|
|
189
|
+
}
|
|
190
|
+
const curInternal = internal.current;
|
|
191
|
+
const shouldPrintDebug = !!process.env.LOG_LEVEL && (configureOpts.logLevel === "debug" || shouldDebug(component, info));
|
|
192
|
+
const getSnapshot = useCallback(() => {
|
|
193
|
+
const curInternal2 = internal.current;
|
|
194
|
+
const keys = curInternal2.firstRun ? info.stateKeys : [...curInternal2.tracked];
|
|
195
|
+
const nextKeys = `${store._version}${keys.join("")}${(userSelector == null ? void 0 : userSelector.toString()) || ""}`;
|
|
196
|
+
if (nextKeys === curInternal2.lastKeys) {
|
|
197
|
+
if (shouldPrintDebug) {
|
|
198
|
+
console.log("avoid update", nextKeys, curInternal2.lastKeys);
|
|
199
|
+
}
|
|
200
|
+
return curInternal2.last;
|
|
201
|
+
}
|
|
202
|
+
curInternal2.lastKeys = nextKeys;
|
|
203
|
+
let snap;
|
|
204
|
+
setDisableStoreTracking(store, true);
|
|
205
|
+
const last = curInternal2.last;
|
|
206
|
+
if (userSelector) {
|
|
207
|
+
snap = userSelector(store);
|
|
208
|
+
} else {
|
|
209
|
+
snap = selectKeys(store, keys);
|
|
210
|
+
}
|
|
211
|
+
setDisableStoreTracking(store, false);
|
|
212
|
+
const isUnchanged = typeof last !== "undefined" && isEqualSubsetShallow(last, snap, {
|
|
213
|
+
keyComparators: info.keyComparators
|
|
214
|
+
});
|
|
215
|
+
if (shouldPrintDebug) {
|
|
216
|
+
console.log("\u{1F311} getSnapshot", { userSelector, info, isUnchanged, component, keys, snap, curInternal: curInternal2 });
|
|
217
|
+
}
|
|
218
|
+
if (isUnchanged) {
|
|
219
|
+
return last;
|
|
220
|
+
}
|
|
221
|
+
curInternal2.last = snap;
|
|
222
|
+
return snap;
|
|
223
|
+
}, []);
|
|
224
|
+
const state = useSyncExternalStore(store.subscribe, getSnapshot);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
return curInternal.dispose;
|
|
227
|
+
}, []);
|
|
228
|
+
if (!userSelector) {
|
|
229
|
+
curInternal.isTracking = true;
|
|
230
|
+
useLayoutEffect(() => {
|
|
231
|
+
curInternal.isTracking = false;
|
|
232
|
+
curInternal.firstRun = false;
|
|
233
|
+
if (shouldPrintDebug) {
|
|
234
|
+
console.log("\u{1F311} finish render, tracking", [...curInternal.tracked]);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
} else {
|
|
238
|
+
return state;
|
|
239
|
+
}
|
|
240
|
+
return new Proxy(store, {
|
|
241
|
+
get(target, key) {
|
|
242
|
+
const curVal = Reflect.get(target, key);
|
|
243
|
+
if (isInReaction) {
|
|
244
|
+
return curVal;
|
|
245
|
+
}
|
|
246
|
+
if (Reflect.has(state, key)) {
|
|
247
|
+
return Reflect.get(state, key);
|
|
248
|
+
}
|
|
249
|
+
return curVal;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
let setters = /* @__PURE__ */ new Set();
|
|
254
|
+
const logStack = /* @__PURE__ */ new Set();
|
|
255
|
+
function createProxiedStore(storeInfo) {
|
|
256
|
+
const { actions, storeInstance, getters, gettersState } = storeInfo;
|
|
257
|
+
const { getCache, curGetKeys, depsToGetter } = gettersState;
|
|
258
|
+
const constr = storeInstance.constructor;
|
|
259
|
+
let didSet = false;
|
|
260
|
+
let isInAction = false;
|
|
261
|
+
const wrappedActions = {};
|
|
262
|
+
for (const key in actions) {
|
|
263
|
+
if (key === "subscribe") {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const actionFn = actions[key];
|
|
267
|
+
const isGetFn = key.startsWith("get");
|
|
268
|
+
wrappedActions[key] = function useStoreAction(...args) {
|
|
269
|
+
let res;
|
|
270
|
+
try {
|
|
271
|
+
if (isGetFn || gettersState.isGetting) {
|
|
272
|
+
return Reflect.apply(actionFn, proxiedStore, args);
|
|
273
|
+
}
|
|
274
|
+
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
275
|
+
console.log("(debug) startAction", key, { isInAction });
|
|
276
|
+
}
|
|
277
|
+
isInAction = true;
|
|
278
|
+
res = Reflect.apply(actionFn, proxiedStore, args);
|
|
279
|
+
if (res instanceof Promise) {
|
|
280
|
+
return res.then(finishAction);
|
|
281
|
+
}
|
|
282
|
+
finishAction();
|
|
283
|
+
return res;
|
|
284
|
+
} catch (err) {
|
|
285
|
+
console.error(err.message, err.stack);
|
|
286
|
+
return res;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
if (process.env.NODE_ENV === "development") {
|
|
290
|
+
if (!key.startsWith("get") && !key.startsWith("_") && key !== "subscribe") {
|
|
291
|
+
const ogAction = wrappedActions[key];
|
|
292
|
+
wrappedActions[key] = new Proxy(ogAction, {
|
|
293
|
+
apply(target, thisArg, args) {
|
|
294
|
+
const isDebugging = DebugStores.has(constr);
|
|
295
|
+
const shouldLog = process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error");
|
|
296
|
+
if (!shouldLog) {
|
|
297
|
+
return Reflect.apply(target, thisArg, args);
|
|
298
|
+
}
|
|
299
|
+
setters = /* @__PURE__ */ new Set();
|
|
300
|
+
const curSetters = setters;
|
|
301
|
+
const isTopLevelLogger = logStack.size == 0;
|
|
302
|
+
const logs = /* @__PURE__ */ new Set();
|
|
303
|
+
logStack.add(logs);
|
|
304
|
+
let res;
|
|
305
|
+
const id = counter++;
|
|
306
|
+
try {
|
|
307
|
+
res = Reflect.apply(target, thisArg, args);
|
|
308
|
+
} finally {
|
|
309
|
+
logStack.add("end");
|
|
310
|
+
const name = constr.name;
|
|
311
|
+
const color = strColor(name);
|
|
312
|
+
const simpleArgs = args.map(simpleStr);
|
|
313
|
+
logs.add([
|
|
314
|
+
`%c \u{1F311} ${id} ${name.padStart(
|
|
315
|
+
isTopLevelLogger ? 8 : 4
|
|
316
|
+
)}%c.${key}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`,
|
|
317
|
+
`color: ${color};`,
|
|
318
|
+
"color: black;"
|
|
319
|
+
]);
|
|
320
|
+
if (curSetters.size) {
|
|
321
|
+
curSetters.forEach(({ key: key2, value }) => {
|
|
322
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
323
|
+
logs.add([` SET ${key2} ${value}`, value]);
|
|
324
|
+
} else {
|
|
325
|
+
logs.add([` SET ${key2}`, value]);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
if (isTopLevelLogger) {
|
|
330
|
+
let error = null;
|
|
331
|
+
try {
|
|
332
|
+
for (const item of [...logStack]) {
|
|
333
|
+
if (item === "end") {
|
|
334
|
+
console.groupEnd();
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const [head, ...rest] = item;
|
|
338
|
+
if (head) {
|
|
339
|
+
console.groupCollapsed(...head);
|
|
340
|
+
console.groupCollapsed("...");
|
|
341
|
+
console.log("args", args);
|
|
342
|
+
console.log("response", res);
|
|
343
|
+
console.groupCollapsed("trace");
|
|
344
|
+
console.trace();
|
|
345
|
+
console.groupEnd();
|
|
346
|
+
console.groupEnd();
|
|
347
|
+
for (const [name2, ...log] of rest) {
|
|
348
|
+
console.groupCollapsed(name2);
|
|
349
|
+
console.log(...log);
|
|
350
|
+
console.groupEnd();
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
console.log("Weird log", head, ...rest);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
error = err;
|
|
358
|
+
}
|
|
359
|
+
for (const _ of [...logStack]) {
|
|
360
|
+
console.groupEnd();
|
|
361
|
+
}
|
|
362
|
+
if (error) {
|
|
363
|
+
console.error(`error loggin`, error);
|
|
364
|
+
}
|
|
365
|
+
logStack.clear();
|
|
366
|
+
}
|
|
367
|
+
return res;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function hashCode(str) {
|
|
375
|
+
let hash = 0;
|
|
376
|
+
for (let i = 0; i < str.length; i++) {
|
|
377
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
378
|
+
}
|
|
379
|
+
return hash;
|
|
380
|
+
}
|
|
381
|
+
function strColor(str) {
|
|
382
|
+
return `hsl(${hashCode(str) % 360}, 90%, 40%)`;
|
|
383
|
+
}
|
|
384
|
+
const finishAction = () => {
|
|
385
|
+
var _a;
|
|
386
|
+
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
387
|
+
console.log("(debug) finishAction", { didSet });
|
|
388
|
+
}
|
|
389
|
+
isInAction = false;
|
|
390
|
+
if (didSet) {
|
|
391
|
+
(_a = storeInstance[TRIGGER_UPDATE]) == null ? void 0 : _a.call(storeInstance);
|
|
392
|
+
didSet = false;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const proxiedStore = new Proxy(storeInstance, {
|
|
396
|
+
// GET
|
|
397
|
+
get(_, key) {
|
|
398
|
+
if (key in wrappedActions) {
|
|
399
|
+
return wrappedActions[key];
|
|
400
|
+
}
|
|
401
|
+
if (passThroughKeys[key]) {
|
|
402
|
+
return Reflect.get(storeInstance, key);
|
|
403
|
+
}
|
|
404
|
+
if (key === UNWRAP_PROXY) {
|
|
405
|
+
return storeInstance;
|
|
406
|
+
}
|
|
407
|
+
if (key === UNWRAP_STORE_INFO) {
|
|
408
|
+
return storeInfo;
|
|
409
|
+
}
|
|
410
|
+
if (disableTracking.get(storeInstance)) {
|
|
411
|
+
return Reflect.get(storeInstance, key);
|
|
412
|
+
}
|
|
413
|
+
if (typeof key !== "string") {
|
|
414
|
+
return Reflect.get(storeInstance, key);
|
|
415
|
+
}
|
|
416
|
+
if (storeAccessTrackers.size && !storeAccessTrackers.has(storeInstance)) {
|
|
417
|
+
for (const t of storeAccessTrackers) {
|
|
418
|
+
t(storeInstance);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const shouldPrintDebug = process.env.NODE_ENV === "development" && DebugStores.has(constr);
|
|
422
|
+
if (gettersState.isGetting) {
|
|
423
|
+
gettersState.curGetKeys.add(key);
|
|
424
|
+
} else {
|
|
425
|
+
storeInstance[TRACK](key, shouldPrintDebug);
|
|
426
|
+
}
|
|
427
|
+
if (key in getters) {
|
|
428
|
+
if (getCache.has(key)) {
|
|
429
|
+
return getCache.get(key);
|
|
430
|
+
}
|
|
431
|
+
curGetKeys.clear();
|
|
432
|
+
const isSubGetter = gettersState.isGetting;
|
|
433
|
+
gettersState.isGetting = true;
|
|
434
|
+
const res = getters[key].call(proxiedStore);
|
|
435
|
+
if (!isSubGetter) {
|
|
436
|
+
gettersState.isGetting = false;
|
|
437
|
+
}
|
|
438
|
+
for (const gk of curGetKeys) {
|
|
439
|
+
if (!depsToGetter.has(gk)) {
|
|
440
|
+
depsToGetter.set(gk, /* @__PURE__ */ new Set());
|
|
441
|
+
}
|
|
442
|
+
const cur = depsToGetter.get(gk);
|
|
443
|
+
cur.add(key);
|
|
444
|
+
}
|
|
445
|
+
getCache.set(key, res);
|
|
446
|
+
return res;
|
|
447
|
+
}
|
|
448
|
+
return Reflect.get(storeInstance, key);
|
|
449
|
+
},
|
|
450
|
+
// SET
|
|
451
|
+
set(target, key, value, receiver) {
|
|
452
|
+
var _a;
|
|
453
|
+
const cur = Reflect.get(target, key);
|
|
454
|
+
const res = Reflect.set(target, key, value, receiver);
|
|
455
|
+
if (res && cur !== value) {
|
|
456
|
+
if (typeof key === "string") {
|
|
457
|
+
clearGetterCache(key);
|
|
458
|
+
}
|
|
459
|
+
if (process.env.LOG_LEVEL && configureOpts.logLevel !== "error") {
|
|
460
|
+
setters.add({ key, value });
|
|
461
|
+
if (storeInstance[SHOULD_DEBUG]()) {
|
|
462
|
+
console.log("(debug) SET", res, key, value);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
466
|
+
console.log("SET...", { key, value, isInAction });
|
|
467
|
+
}
|
|
468
|
+
if (isInAction) {
|
|
469
|
+
didSet = true;
|
|
470
|
+
} else {
|
|
471
|
+
(_a = storeInstance[TRIGGER_UPDATE]) == null ? void 0 : _a.call(storeInstance);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return res;
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
function clearGetterCache(setKey) {
|
|
478
|
+
const getters2 = depsToGetter.get(setKey);
|
|
479
|
+
getCache.delete(setKey);
|
|
480
|
+
if (!getters2) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
for (const gk of getters2) {
|
|
484
|
+
getCache.delete(gk);
|
|
485
|
+
if (depsToGetter.has(gk)) {
|
|
486
|
+
clearGetterCache(gk);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return proxiedStore;
|
|
491
|
+
}
|
|
492
|
+
let counter = 0;
|
|
493
|
+
const passThroughKeys = {
|
|
494
|
+
subscribe: true,
|
|
495
|
+
_version: true,
|
|
496
|
+
_trackers: true,
|
|
497
|
+
$$typeof: true,
|
|
498
|
+
_listeners: true,
|
|
499
|
+
_enableTracking: true
|
|
500
|
+
};
|
|
501
|
+
export {
|
|
502
|
+
allStores,
|
|
503
|
+
createStore,
|
|
504
|
+
createUseStore,
|
|
505
|
+
createUseStoreSelector,
|
|
506
|
+
getStore,
|
|
507
|
+
setIsInReaction,
|
|
508
|
+
trackStoresAccess,
|
|
509
|
+
useGlobalStore,
|
|
510
|
+
useGlobalStoreSelector,
|
|
511
|
+
useStore,
|
|
512
|
+
useStoreDebug,
|
|
513
|
+
useStoreOnce,
|
|
514
|
+
useStoreSelector
|
|
515
|
+
};
|
|
516
|
+
//# sourceMappingURL=useStore.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useStore.tsx"],
|
|
4
|
+
"mappings": "AAAA,SAAS,aAAa,WAAW,iBAAiB,cAAc;AAChE,SAAS,4BAA4B;AAErC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,cAAc,sBAAsB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,MAAM,OAAO,CAAC,MAAM;AAGb,SAAS,SACd,YACA,OACA,UAAmC,gBAChC;AACH,QAAM,aAAa,YAAY,QAAQ,YAAY,MAAM,CAAC,CAAC;AAC3D,QAAM,WAAW,QAAQ,WAAW,aAAa,QAAQ;AAEzD,MAAI,QAAQ,OAAO;AACjB,2BAAuB,UAAU;AAAA,EACnC;AAUA,QAAM,OAAO,qBAAqB,YAAY,KAAK;AACnD,SAAO,iBAAiB,MAAM,QAAQ;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AAO,MAAM;AACtB,QAAI,CAACA,UAAS;AACZ;AAAA,IACF;AACA,eAAW,MAAMA,UAAS;AACxB,eAAS,OAAO,EAAE;AAClB,UAAI,aAAa,IAAI,EAAE,GAAG;AACxB,yBAAiB,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAI,UAAU;AAEd,MAAM,kBAAkB;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,iBAAiB;AACnB;",
|
|
5
|
+
"names": ["curInternal", "key", "name", "getters"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useLayoutEffect } from "react";
|
|
2
|
+
const { ReactCurrentOwner } = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
3
|
+
const useCurrentComponent = () => {
|
|
4
|
+
return ReactCurrentOwner && ReactCurrentOwner.current && ReactCurrentOwner.current.elementType ? ReactCurrentOwner.current.elementType : {};
|
|
5
|
+
};
|
|
6
|
+
function useDebugStoreComponent(StoreCons) {
|
|
7
|
+
const cmp = useCurrentComponent();
|
|
8
|
+
DebugStores.add(StoreCons);
|
|
9
|
+
if (!DebugComponents.has(cmp)) {
|
|
10
|
+
DebugComponents.set(cmp, /* @__PURE__ */ new Set());
|
|
11
|
+
}
|
|
12
|
+
const stores = DebugComponents.get(cmp);
|
|
13
|
+
stores.add(StoreCons);
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
return () => {
|
|
16
|
+
DebugStores.delete(StoreCons);
|
|
17
|
+
stores.delete(StoreCons);
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
21
|
+
const shouldDebug = (component, info) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const StoreCons = (_a = info.storeInstance) == null ? void 0 : _a.constructor;
|
|
24
|
+
return (_b = DebugComponents.get(component)) == null ? void 0 : _b.has(StoreCons);
|
|
25
|
+
};
|
|
26
|
+
const DebugComponents = /* @__PURE__ */ new Map();
|
|
27
|
+
const DebugStores = /* @__PURE__ */ new Set();
|
|
28
|
+
export {
|
|
29
|
+
DebugComponents,
|
|
30
|
+
DebugStores,
|
|
31
|
+
shouldDebug,
|
|
32
|
+
useCurrentComponent,
|
|
33
|
+
useDebugStoreComponent
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useStoreDebug.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useStoreDebug.tsx"],
|
|
4
|
+
"mappings": "AAAA,OAAO,SAAS,uBAAuB;AAIvC,MAAM,EAAE,kBAAkB,IAAK,MAC5B;AACI,MAAM,sBAAsB,MAAM;AACvC,SAAO,qBACL,kBAAkB,WAClB,kBAAkB,QAAQ,cACxB,kBAAkB,QAAQ,cAC1B,CAAC;AACP;AAEO,SAAS,uBAAuB,WAAgB;AACrD,QAAM,MAAM,oBAAoB;AAGhC,cAAY,IAAI,SAAS;AACzB,MAAI,CAAC,gBAAgB,IAAI,GAAG,GAAG;AAC7B,oBAAgB,IAAI,KAAK,oBAAI,IAAI,CAAC;AAAA,EACpC;AACA,QAAM,SAAS,gBAAgB,IAAI,GAAG;AACtC,SAAO,IAAI,SAAS;AAEpB,kBAAgB,MAAM;AACpB,WAAO,MAAM;AACX,kBAAY,OAAO,SAAS;AAC5B,aAAO,OAAO,SAAS;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cAAc,CAAC,WAAgB,SAA2C;AAjCvF;AAkCE,QAAM,aAAY,UAAK,kBAAL,mBAAoB;AACtC,UAAO,qBAAgB,IAAI,SAAS,MAA7B,mBAAgC,IAAI;AAC7C;AAEO,MAAM,kBAAkB,oBAAI,IAAmB;AAC/C,MAAM,cAAc,oBAAI,IAAS;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useLayoutEffect } from "react";
|
|
2
|
+
const { ReactCurrentOwner } = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
3
|
+
const useCurrentComponent = () => {
|
|
4
|
+
return ReactCurrentOwner && ReactCurrentOwner.current && ReactCurrentOwner.current.elementType ? ReactCurrentOwner.current.elementType : {};
|
|
5
|
+
};
|
|
6
|
+
function useDebugStoreComponent(StoreCons) {
|
|
7
|
+
const cmp = useCurrentComponent();
|
|
8
|
+
DebugStores.add(StoreCons);
|
|
9
|
+
if (!DebugComponents.has(cmp)) {
|
|
10
|
+
DebugComponents.set(cmp, /* @__PURE__ */ new Set());
|
|
11
|
+
}
|
|
12
|
+
const stores = DebugComponents.get(cmp);
|
|
13
|
+
stores.add(StoreCons);
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
return () => {
|
|
16
|
+
DebugStores.delete(StoreCons);
|
|
17
|
+
stores.delete(StoreCons);
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
21
|
+
const shouldDebug = (component, info) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const StoreCons = (_a = info.storeInstance) == null ? void 0 : _a.constructor;
|
|
24
|
+
return (_b = DebugComponents.get(component)) == null ? void 0 : _b.has(StoreCons);
|
|
25
|
+
};
|
|
26
|
+
const DebugComponents = /* @__PURE__ */ new Map();
|
|
27
|
+
const DebugStores = /* @__PURE__ */ new Set();
|
|
28
|
+
export {
|
|
29
|
+
DebugComponents,
|
|
30
|
+
DebugStores,
|
|
31
|
+
shouldDebug,
|
|
32
|
+
useCurrentComponent,
|
|
33
|
+
useDebugStoreComponent
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useStoreDebug.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useStoreDebug.tsx"],
|
|
4
|
+
"mappings": "AAAA,OAAO,SAAS,uBAAuB;AAIvC,MAAM,EAAE,kBAAkB,IAAK,MAC5B;AACI,MAAM,sBAAsB,MAAM;AACvC,SAAO,qBACL,kBAAkB,WAClB,kBAAkB,QAAQ,cACxB,kBAAkB,QAAQ,cAC1B,CAAC;AACP;AAEO,SAAS,uBAAuB,WAAgB;AACrD,QAAM,MAAM,oBAAoB;AAGhC,cAAY,IAAI,SAAS;AACzB,MAAI,CAAC,gBAAgB,IAAI,GAAG,GAAG;AAC7B,oBAAgB,IAAI,KAAK,oBAAI,IAAI,CAAC;AAAA,EACpC;AACA,QAAM,SAAS,gBAAgB,IAAI,GAAG;AACtC,SAAO,IAAI,SAAS;AAEpB,kBAAgB,MAAM;AACpB,WAAO,MAAM;AACX,kBAAY,OAAO,SAAS;AAC5B,aAAO,OAAO,SAAS;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cAAc,CAAC,WAAgB,SAA2C;AAjCvF;AAkCE,QAAM,aAAY,UAAK,kBAAL,mBAAoB;AACtC,UAAO,qBAAgB,IAAI,SAAS,MAA7B,mBAAgC,IAAI;AAC7C;AAEO,MAAM,kBAAkB,oBAAI,IAAmB;AAC/C,MAAM,cAAc,oBAAI,IAAS;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/use-store",
|
|
3
|
+
"version": "1.15.40",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"main": "dist/cjs",
|
|
6
|
+
"module": "dist/esm",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"types",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tamagui-build",
|
|
14
|
+
"watch": "tamagui-build --watch",
|
|
15
|
+
"test": "TAMAGUI_TARGET=web vitest --config ../vite-plugin-internal/src/vite.config.ts --run",
|
|
16
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
17
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply src",
|
|
18
|
+
"clean": "tamagui-build clean",
|
|
19
|
+
"clean:build": "tamagui-build clean:build"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"import": "./dist/esm/index.mjs",
|
|
26
|
+
"require": "./dist/cjs/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@tamagui/web": "1.15.40"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@tamagui/build": "1.15.40",
|
|
34
|
+
"@testing-library/react": "^13.4.0",
|
|
35
|
+
"react": "^18.2.0",
|
|
36
|
+
"vitest": "^0.26.3"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "*"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|