@tamagui/use-store 1.74.3 → 1.74.5

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.
@@ -0,0 +1,19 @@
1
+ const isEqualSubsetShallow = (a, b, opts) => {
2
+ if (b == null || a == null)
3
+ return a === b;
4
+ if (typeof a != typeof b)
5
+ return !1;
6
+ if (typeof b == "object") {
7
+ for (const key in b) {
8
+ const compare = opts?.keyComparators?.[key];
9
+ if (compare ? !compare(a[key], b[key]) : b[key] !== a[key])
10
+ return !1;
11
+ }
12
+ return !0;
13
+ }
14
+ return a === b;
15
+ };
16
+ export {
17
+ isEqualSubsetShallow
18
+ };
19
+ //# sourceMappingURL=comparators.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/comparators.tsx"],
4
+ "mappings": "AAAO,MAAM,uBAAuB,CAClC,GACA,GACA,SACG;AACH,MAAI,KAAK,QAAQ,KAAK;AAAM,WAAO,MAAM;AACzC,MAAI,OAAO,KAAM,OAAO;AAAG,WAAO;AAClC,MAAI,OAAO,KAAM,UAAU;AACzB,eAAW,OAAO,GAAG;AACnB,YAAM,UAAU,MAAM,iBAAiB,GAAG;AAC1C,UAAI,UAAU,CAAC,QAAQ,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,GAAG;AACvD,eAAO;AAAA,IAEX;AACA,WAAO;AAAA,EACT;AACA,SAAO,MAAM;AACf;",
5
+ "names": []
6
+ }
@@ -0,0 +1,9 @@
1
+ let configureOpts = {};
2
+ function configureUseStore(opts) {
3
+ configureOpts = opts;
4
+ }
5
+ export {
6
+ configureOpts,
7
+ configureUseStore
8
+ };
9
+ //# sourceMappingURL=configureUseStore.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/configureUseStore.tsx"],
4
+ "mappings": "AAEO,IAAI,gBAAgC,CAAC;AAErC,SAAS,kBAAkB,MAAsB;AACtD,kBAAgB;AAClB;",
5
+ "names": []
6
+ }
@@ -0,0 +1,9 @@
1
+ const UNWRAP_PROXY = Symbol(), defaultOptions = {
2
+ once: !1,
3
+ selector: void 0
4
+ };
5
+ export {
6
+ UNWRAP_PROXY,
7
+ defaultOptions
8
+ };
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/constants.tsx"],
4
+ "mappings": "AAAO,MAAM,eAAe,OAAO,GAEtB,iBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,UAAU;AACZ;",
5
+ "names": []
6
+ }
@@ -0,0 +1,9 @@
1
+ function compare(comparator) {
2
+ return (target, propertyKey) => {
3
+ target._comparators = target._comparators || {}, target._comparators[propertyKey] = comparator;
4
+ };
5
+ }
6
+ export {
7
+ compare
8
+ };
9
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/decorators.tsx"],
4
+ "mappings": "AAEO,SAAS,QAAQ,YAA0B;AAChD,SAAO,CAAC,QAAa,gBAA6B;AAChD,WAAO,eAAkB,OAAO,gBAAmB,CAAC,GACpD,OAAO,aAAgB,WAAW,IAAI;AAAA,EACxC;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,40 @@
1
+ import { simpleHash } from "@tamagui/simple-hash";
2
+ import { useRef } from "react";
3
+ function getStoreUid(Constructor, props) {
4
+ return simpleHash(
5
+ `${Constructor}${props ? typeof props == "string" ? props : JSON.stringify(props) : ""}`,
6
+ "strict"
7
+ );
8
+ }
9
+ const UNWRAP_STORE_INFO = Symbol("UNWRAP_STORE_INFO"), cache = /* @__PURE__ */ new Map();
10
+ function getStoreDescriptors(storeInstance) {
11
+ const proto = Object.getPrototypeOf(storeInstance), instanceDescriptors = Object.getOwnPropertyDescriptors(storeInstance), descriptors = {
12
+ ...Object.getOwnPropertyDescriptors(proto),
13
+ ...instanceDescriptors
14
+ };
15
+ return delete descriptors.constructor, descriptors;
16
+ }
17
+ function get(_, b) {
18
+ return _;
19
+ }
20
+ function useConstant(fn) {
21
+ const ref = useRef();
22
+ return ref.current || (ref.current = { v: fn() }), ref.current.v;
23
+ }
24
+ function simpleStr(arg) {
25
+ return process.env.NODE_ENV === "development" ? typeof arg == "function" ? "fn" : typeof arg == "string" ? `"${arg}"` : arg && (typeof arg != "object" ? arg : Array.isArray(arg) ? "[...]" : "{...}") : arg;
26
+ }
27
+ function getStoreDebugInfo(store) {
28
+ return store[UNWRAP_STORE_INFO] ?? cache.get(getStoreUid(store.constructor, store.props));
29
+ }
30
+ export {
31
+ UNWRAP_STORE_INFO,
32
+ cache,
33
+ useConstant as default,
34
+ get,
35
+ getStoreDebugInfo,
36
+ getStoreDescriptors,
37
+ getStoreUid,
38
+ simpleStr
39
+ };
40
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers.tsx"],
4
+ "mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAIhB,SAAS,YAAY,aAAkB,OAA+B;AAC3E,SAAO;AAAA,IACL,GAAG,WAAW,GACX,QAAa,OAAO,SAAU,WAAW,QAAQ,KAAK,UAAU,KAAK,IAA7D,EACX;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,OAAO,mBAAmB,GAC9C,QAAQ,oBAAI,IAAuB;AAEzC,SAAS,oBAAoB,eAAoB;AACtD,QAAM,QAAQ,OAAO,eAAe,aAAa,GAC3C,sBAAsB,OAAO,0BAA0B,aAAa,GAEpE,cAAc;AAAA,IAClB,GAFuB,OAAO,0BAA0B,KAAK;AAAA,IAG7D,GAAG;AAAA,EACL;AAEA,gBAAO,YAAY,aACZ;AACT;AAEO,SAAS,IAAO,GAAM,GAAyD;AACpF,SAAO;AACT;AAIe,SAAR,YAAgC,IAAgB;AACrD,QAAM,MAAM,OAAqB;AACjC,SAAK,IAAI,YACP,IAAI,UAAU,EAAE,GAAG,GAAG,EAAE,IAEnB,IAAI,QAAQ;AACrB;AAEO,SAAS,UAAU,KAAU;AAClC,SAAI,QAAQ,IAAI,aAAa,gBACpB,OAAO,OAAQ,aAClB,OACA,OAAO,OAAQ,WACf,IAAI,GAAG,MACN,QAED,OAAO,OAAQ,WACf,MACA,MAAM,QAAQ,GAAG,IACjB,UACA,WAEC;AACT;AAGO,SAAS,kBAAkB,OAAY;AAC5C,SACE,MAAM,iBAAiB,KAAK,MAAM,IAAI,YAAY,MAAM,aAAa,MAAM,KAAK,CAAC;AAErF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,18 @@
1
+ export * from "./useStore";
2
+ import { configureUseStore } from "./configureUseStore";
3
+ export * from "./interfaces";
4
+ export * from "./observe";
5
+ import { UNWRAP_PROXY } from "./constants";
6
+ export * from "./comparators";
7
+ export * from "./decorators";
8
+ class Store {
9
+ constructor(props) {
10
+ this.props = props;
11
+ }
12
+ }
13
+ export {
14
+ Store,
15
+ UNWRAP_PROXY,
16
+ configureUseStore
17
+ };
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;AACd,SAAS,yBAAyB;AAClC,cAAc;AACd,cAAc;AACd,SAAS,oBAAoB;AAC7B,cAAc;AACd,cAAc;AAGP,MAAM,MAAyC;AAAA,EACpD,YAAmB,OAAc;AAAd;AAAA,EAAe;AACpC;",
5
+ "names": []
6
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "mappings": "",
5
+ "names": []
6
+ }
@@ -0,0 +1,84 @@
1
+ import { useEffect, useState } from "react";
2
+ import { isEqualSubsetShallow } from "./comparators";
3
+ import { UNWRAP_PROXY } from "./constants";
4
+ import { trackStoresAccess } from "./useStore";
5
+ const logUpdate = process.env.NODE_ENV === "development" ? (fn, stores, last, next) => {
6
+ const getStoreLogName = (store) => `${(store[UNWRAP_PROXY] ?? store).constructor.name}${store.props?.id ? `:${store.props.id}` : ""}`, storeNames = stores.map(getStoreLogName).join(", "), name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
7
+ console.groupCollapsed(name, "color: tomato;"), console.groupCollapsed("trace >"), console.trace(), console.groupEnd(), console.log(" next", next), console.groupEnd();
8
+ } : null;
9
+ function observe(fn) {
10
+ let prev = getObserverValueAndStoresAccessed(fn), disposeValue = null;
11
+ const subscribe = () => {
12
+ const stores = [...prev.storeInfos];
13
+ return subscribeToStores(stores, () => {
14
+ disposeValue?.();
15
+ const next = getObserverValueAndStoresAccessed(fn);
16
+ if (typeof next.value == "function") {
17
+ disposeValue = next.value, process.env.NODE_ENV === "development" && logUpdate(fn, [...next.storeInfos], "(fn)", "(fn)");
18
+ return;
19
+ }
20
+ isEqualSubsetShallow(prev.storeInfos, next.storeInfos) && isEqualSubsetShallow(prev.value, next.value) || (process.env.NODE_ENV === "development" && logUpdate(fn, [...next.storeInfos], prev.value, next.value), prev = next, dispose(), dispose = subscribe());
21
+ });
22
+ };
23
+ let dispose = subscribe();
24
+ return {
25
+ dispose: () => {
26
+ dispose(), disposeValue?.();
27
+ },
28
+ getValue: () => prev.value
29
+ };
30
+ }
31
+ function useObserve(fn) {
32
+ const [state, setState] = useState(() => getObserverValueAndStoresAccessed(fn));
33
+ return useEffect(() => {
34
+ let dispose;
35
+ const unsub = subscribeToStores([...state.storeInfos], () => {
36
+ dispose?.();
37
+ const next = getObserverValueAndStoresAccessed(fn), nextStoreInfos = [...next.storeInfos], prevStoreInfos = [...state.storeInfos];
38
+ if (typeof next.value == "function") {
39
+ process.env.NODE_ENV === "development" && logUpdate(fn, nextStoreInfos, "(fn)", "(fn)"), dispose = next.value;
40
+ return;
41
+ }
42
+ setState((prev) => isEqualSubsetShallow(prevStoreInfos, nextStoreInfos) && isEqualSubsetShallow(prev.value, next.value) ? prev : (process.env.NODE_ENV === "development" && logUpdate(fn, nextStoreInfos, prev.value, next.value), next));
43
+ });
44
+ return () => {
45
+ unsub(), dispose?.();
46
+ };
47
+ }, [[...state.storeInfos].map((i) => i.uid).join(",")]), state.value;
48
+ }
49
+ function getObserverValueAndStoresAccessed(selector) {
50
+ const storeInfos = /* @__PURE__ */ new Set(), dispose = trackStoresAccess((storeInfo) => {
51
+ storeInfos.add(storeInfo);
52
+ }), value = selector();
53
+ return dispose(), {
54
+ value,
55
+ storeInfos
56
+ };
57
+ }
58
+ function subscribeToStores(storeInfos, onUpdate) {
59
+ const disposes = [];
60
+ let isUpdating = !1;
61
+ const onUpdateDebouncedWithoutTracking = () => {
62
+ isUpdating || (isUpdating = !0, queueMicrotask(() => {
63
+ try {
64
+ for (const storeInfo of storeInfos)
65
+ storeInfo.disableTracking = !0;
66
+ onUpdate();
67
+ } finally {
68
+ isUpdating = !1;
69
+ for (const storeInfo of storeInfos)
70
+ storeInfo.disableTracking = !1;
71
+ }
72
+ }));
73
+ };
74
+ for (const storeInfo of storeInfos)
75
+ disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
76
+ return () => {
77
+ disposes.forEach((x) => x());
78
+ };
79
+ }
80
+ export {
81
+ observe,
82
+ useObserve
83
+ };
84
+ //# sourceMappingURL=observe.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/observe.tsx"],
4
+ "mappings": "AAAA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAE7B,SAAS,yBAAyB;AAElC,MAAM,YACJ,QAAQ,IAAI,aAAa,gBACrB,CAAC,IAAS,QAAe,MAAW,SAAc;AAChD,QAAM,kBAAkB,CAAC,UAEhB,IADK,MAAM,YAAY,KAAK,OACrB,YAAY,IAAI,GAAG,MAAM,OAAO,KAAK,IAAI,MAAM,MAAM,EAAE,KAAK,EAAE,IAExE,aA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gCAAgC,CAAC;AAErE,SAAO,MAAM;AACX,aAAS,QAAQ,CAAC,MAAM,EAAE,CAAC;AAAA,EAC7B;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,340 @@
1
+ import { useCallback, useRef, useSyncExternalStore } from "react";
2
+ import { isEqualSubsetShallow } from "./comparators";
3
+ import { configureOpts } from "./configureUseStore";
4
+ import { UNWRAP_PROXY, defaultOptions } from "./constants";
5
+ import {
6
+ UNWRAP_STORE_INFO,
7
+ cache,
8
+ getStoreDescriptors,
9
+ getStoreUid,
10
+ simpleStr
11
+ } from "./helpers";
12
+ import { DebugStores, shouldDebug, useCurrentComponent } from "./useStoreDebug";
13
+ const idFn = (_) => _;
14
+ function useStore(StoreKlass, props, options = defaultOptions) {
15
+ const selectorCb = useCallback(options.selector || idFn, []), selector = options.selector ? selectorCb : options.selector, info = getOrCreateStoreInfo(StoreKlass, props, options);
16
+ return useStoreFromInfo(info, selector, options);
17
+ }
18
+ function useStoreDebug(StoreKlass, props) {
19
+ return useStore(StoreKlass, props, { debug: !0 });
20
+ }
21
+ function createStore(StoreKlass, props, options) {
22
+ return getOrCreateStoreInfo(StoreKlass, props, options)?.store;
23
+ }
24
+ function useGlobalStore(instance, debug) {
25
+ const store = instance[UNWRAP_PROXY], uid = getStoreUid(store.constructor, store.props), info = cache.get(uid);
26
+ if (!info)
27
+ throw new Error("This store not created using createStore()");
28
+ return useStoreFromInfo(info, void 0, { debug });
29
+ }
30
+ function useGlobalStoreSelector(instance, selector, debug) {
31
+ const store = instance[UNWRAP_PROXY], uid = getStoreUid(store.constructor, store.props), info = cache.get(uid);
32
+ if (!info)
33
+ throw new Error("This store not created using createStore()");
34
+ return useStoreFromInfo(info, selector, { debug });
35
+ }
36
+ function createUseStore(StoreKlass) {
37
+ return function(props, options) {
38
+ return useStore(StoreKlass, props, options);
39
+ };
40
+ }
41
+ function createUseStoreSelector(StoreKlass, selector) {
42
+ return (props) => useStore(StoreKlass, props, { selector });
43
+ }
44
+ function useStoreSelector(StoreKlass, selector, props) {
45
+ return useStore(StoreKlass, props, { selector });
46
+ }
47
+ const storeAccessTrackers = /* @__PURE__ */ new Set();
48
+ function trackStoresAccess(cb) {
49
+ return storeAccessTrackers.add(cb), () => {
50
+ storeAccessTrackers.delete(cb);
51
+ };
52
+ }
53
+ function getStore(StoreKlass, props) {
54
+ return getStoreInfo(StoreKlass, props)?.store;
55
+ }
56
+ function getOrCreateStore(StoreKlass, props) {
57
+ return getOrCreateStoreInfo(StoreKlass, props, {
58
+ refuseCreation: !1
59
+ })?.store;
60
+ }
61
+ function getStoreInfo(StoreKlass, props) {
62
+ return getOrCreateStoreInfo(StoreKlass, props, {
63
+ refuseCreation: !0
64
+ });
65
+ }
66
+ const onCreateListeners = /* @__PURE__ */ new Set();
67
+ function onCreateStore(cb) {
68
+ return onCreateListeners.add(cb), () => {
69
+ onCreateListeners.delete(cb);
70
+ };
71
+ }
72
+ function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
73
+ if (!StoreKlass)
74
+ return null;
75
+ const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
76
+ if (!options?.avoidCache && cache.has(uid))
77
+ return cache.get(uid);
78
+ if (options?.refuseCreation)
79
+ throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
80
+ const storeInstance = new StoreKlass(props);
81
+ storeInstance.props = props;
82
+ const getters = {}, actions = {}, stateKeys = /* @__PURE__ */ new Set(), descriptors = getStoreDescriptors(storeInstance);
83
+ for (const key in descriptors) {
84
+ const descriptor = descriptors[key];
85
+ typeof descriptor.value == "function" ? actions[key] = descriptor.value : typeof descriptor.get == "function" ? getters[key] = descriptor.get : key !== "props" && key[0] !== "_" && stateKeys.add(key);
86
+ }
87
+ const keyComparators = storeInstance._comparators, listeners = /* @__PURE__ */ new Set(), storeInfo = {
88
+ uid,
89
+ keyComparators,
90
+ storeInstance,
91
+ getters,
92
+ stateKeys,
93
+ props,
94
+ actions,
95
+ debug: options?.debug,
96
+ disableTracking: !1,
97
+ gettersState: {
98
+ getCache: /* @__PURE__ */ new Map(),
99
+ depsToGetter: /* @__PURE__ */ new Map(),
100
+ curGetKeys: /* @__PURE__ */ new Set(),
101
+ isGetting: !1
102
+ },
103
+ listeners,
104
+ trackers: /* @__PURE__ */ new Set(),
105
+ version: 0,
106
+ subscribe: (onChanged) => (listeners.add(onChanged), () => {
107
+ listeners.delete(onChanged);
108
+ }),
109
+ triggerUpdate: () => {
110
+ storeInfo.version = (storeInfo.version + 1) % Number.MAX_SAFE_INTEGER;
111
+ for (const cb of listeners)
112
+ cb();
113
+ }
114
+ }, store = createProxiedStore(
115
+ // we assign store right after and proxiedStore never accesses it until later on
116
+ storeInfo
117
+ );
118
+ process.env.NODE_ENV === "development" && (allStores[StoreKlass.name + uid] = store), store.mount?.(), storeInfo.store = store;
119
+ const result = storeInfo;
120
+ return cache.set(uid, result), onCreateListeners.forEach((cb) => cb(result)), result;
121
+ }
122
+ const allStores = {};
123
+ process.env.NODE_ENV === "development" && (globalThis.Store ||= allStores);
124
+ const emptyObj = {}, selectKeys = (obj, keys) => {
125
+ if (!keys.length)
126
+ return emptyObj;
127
+ const res = {};
128
+ for (const key of keys)
129
+ res[key] = obj[key];
130
+ return res;
131
+ };
132
+ let isInReaction = !1;
133
+ const setIsInReaction = (val) => {
134
+ isInReaction = val;
135
+ };
136
+ function useStoreFromInfo(info, userSelector, options) {
137
+ const store = info?.store, internal = useRef(), component = useCurrentComponent();
138
+ internal.current || (internal.current = {
139
+ component,
140
+ tracked: /* @__PURE__ */ new Set(),
141
+ last: null,
142
+ lastKeys: null
143
+ });
144
+ const curInternal = internal.current, shouldPrintDebug = options?.debug, getSnapshot = useCallback(() => {
145
+ if (!info || !store)
146
+ return;
147
+ const curInternal2 = internal.current, isTracking = curInternal2.tracked.size, keys = [...isTracking ? curInternal2.tracked : info.stateKeys], nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`, lastKeys = curInternal2.lastKeys;
148
+ if (nextKeys === curInternal2.lastKeys)
149
+ return curInternal2.last;
150
+ curInternal2.lastKeys = nextKeys;
151
+ let snap;
152
+ info.disableTracking = !0;
153
+ const last = curInternal2.last;
154
+ userSelector ? snap = userSelector(store) : snap = selectKeys(store, keys), info.disableTracking = !1;
155
+ const isUnchanged = !isTracking && last || typeof last < "u" && isEqualSubsetShallow(last, snap, {
156
+ keyComparators: info.keyComparators
157
+ });
158
+ return shouldPrintDebug && console.log("\u{1F311} getSnapshot", {
159
+ storeState: selectKeys(store, Object.keys(store)),
160
+ userSelector,
161
+ info,
162
+ isUnchanged,
163
+ component,
164
+ keys,
165
+ last,
166
+ snap,
167
+ curInternal: curInternal2,
168
+ nextKeys,
169
+ lastKeys
170
+ }), isUnchanged ? last : (curInternal2.last = snap, snap);
171
+ }, [store]), state = useSyncExternalStore(info?.subscribe || idFn, getSnapshot, getSnapshot);
172
+ return !info || !store || !state || userSelector ? state : new Proxy(store, {
173
+ get(target, key) {
174
+ const curVal = Reflect.get(target, key);
175
+ if (isInReaction)
176
+ return curVal;
177
+ const keyString = key;
178
+ return (info.stateKeys.has(keyString) || keyString in info.getters) && (shouldPrintDebug && console.log("\u{1F440} tracking", keyString), curInternal.tracked.add(keyString)), Reflect.has(state, key) ? Reflect.get(state, key) : curVal;
179
+ }
180
+ });
181
+ }
182
+ let setters = /* @__PURE__ */ new Set();
183
+ const logStack = /* @__PURE__ */ new Set();
184
+ function createProxiedStore(storeInfo) {
185
+ const { actions, storeInstance, getters, gettersState } = storeInfo, { getCache, curGetKeys, depsToGetter } = gettersState, constr = storeInstance.constructor, shouldDebug2 = storeInfo.debug ?? DebugStores.has(constr);
186
+ let didSet = !1;
187
+ const wrappedActions = {};
188
+ for (const key in actions) {
189
+ if (key === "subscribe")
190
+ continue;
191
+ const actionFn = actions[key], isGetFn = key.startsWith("get");
192
+ if (wrappedActions[key] = function(...args) {
193
+ let res;
194
+ return isGetFn || gettersState.isGetting ? Reflect.apply(actionFn, proxiedStore, args) : (process.env.NODE_ENV === "development" && shouldDebug2 && console.log("(debug) startAction", key), res = Reflect.apply(actionFn, proxiedStore, args), res instanceof Promise ? res.then(finishAction) : (finishAction(), res));
195
+ }, process.env.NODE_ENV === "development") {
196
+ let hashCode2 = function(str) {
197
+ let hash = 0;
198
+ for (let i = 0; i < str.length; i++)
199
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
200
+ return hash;
201
+ }, strColor2 = function(str) {
202
+ return `hsl(${hashCode2(str) % 360}, 90%, 40%)`;
203
+ };
204
+ var hashCode = hashCode2, strColor = strColor2;
205
+ if (!key.startsWith("get") && !key.startsWith("_") && key !== "subscribe") {
206
+ const ogAction = wrappedActions[key];
207
+ wrappedActions[key] = new Proxy(ogAction, {
208
+ apply(target, thisArg, args) {
209
+ const isDebugging = shouldDebug2 || storeInfo.debug;
210
+ if (!(process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error")))
211
+ return Reflect.apply(target, thisArg, args);
212
+ setters = /* @__PURE__ */ new Set();
213
+ const curSetters = setters, isTopLevelLogger = logStack.size == 0, logs = /* @__PURE__ */ new Set();
214
+ logStack.add(logs);
215
+ let res;
216
+ const id = counter++;
217
+ try {
218
+ res = Reflect.apply(target, thisArg, args);
219
+ } catch (err) {
220
+ throw console.error("Error", err), err;
221
+ } finally {
222
+ logStack.add("end");
223
+ const name = constr.name, color = strColor2(name), simpleArgs = args.map(simpleStr);
224
+ if (logs.add([
225
+ `%c \u{1F311} ${id} ${name.padStart(
226
+ isTopLevelLogger ? 8 : 4
227
+ )}%c.${key}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`,
228
+ `color: ${color};`,
229
+ "color: black;"
230
+ ]), curSetters.size && curSetters.forEach(({ key: key2, value }) => {
231
+ typeof value == "string" || typeof value == "number" || typeof value == "boolean" ? logs.add([` SET ${key2} ${value}`, value]) : logs.add([` SET ${key2}`, value]);
232
+ }), isTopLevelLogger) {
233
+ let error = null;
234
+ try {
235
+ for (const item of [...logStack]) {
236
+ if (item === "end") {
237
+ console.groupEnd();
238
+ continue;
239
+ }
240
+ const [head, ...rest] = item;
241
+ if (head) {
242
+ console.groupCollapsed(...head), console.groupCollapsed("..."), console.log("args", args), console.log("response", res), console.groupCollapsed("trace"), console.trace(), console.groupEnd(), console.groupEnd();
243
+ for (const [name2, ...log] of rest)
244
+ console.groupCollapsed(name2), console.log(...log), console.groupEnd();
245
+ } else
246
+ console.log("Weird log", head, ...rest);
247
+ }
248
+ } catch (err) {
249
+ error = err;
250
+ }
251
+ for (const _ of [...logStack])
252
+ console.groupEnd();
253
+ error && console.error("error loggin", error), logStack.clear();
254
+ }
255
+ return res;
256
+ }
257
+ }
258
+ });
259
+ }
260
+ }
261
+ }
262
+ const finishAction = (val) => (process.env.NODE_ENV === "development" && shouldDebug2 && console.log("(debug) finishAction", { didSet }), didSet && (storeInfo.triggerUpdate(), didSet = !1), val);
263
+ let isTriggering = !1;
264
+ const proxiedStore = new Proxy(storeInstance, {
265
+ // GET
266
+ get(_, key) {
267
+ if (key in wrappedActions)
268
+ return wrappedActions[key];
269
+ if (key in passThroughKeys)
270
+ return Reflect.get(storeInstance, key);
271
+ if (key === UNWRAP_PROXY)
272
+ return storeInstance;
273
+ if (key === UNWRAP_STORE_INFO)
274
+ return storeInfo;
275
+ if (storeAccessTrackers.size && storeAccessTrackers.forEach((cb) => cb(storeInfo)), typeof key != "string")
276
+ return Reflect.get(storeInstance, key);
277
+ if (storeInfo.disableTracking || gettersState.isGetting && gettersState.curGetKeys.add(key), key in getters) {
278
+ if (getCache.has(key))
279
+ return getCache.get(key);
280
+ curGetKeys.clear();
281
+ const isSubGetter = gettersState.isGetting;
282
+ gettersState.isGetting = !0;
283
+ const res = getters[key].call(proxiedStore);
284
+ isSubGetter || (gettersState.isGetting = !1);
285
+ for (const gk of curGetKeys)
286
+ depsToGetter.has(gk) || depsToGetter.set(gk, /* @__PURE__ */ new Set()), depsToGetter.get(gk).add(key);
287
+ return getCache.set(key, res), res;
288
+ }
289
+ return Reflect.get(storeInstance, key);
290
+ },
291
+ // SET
292
+ set(target, key, value, receiver) {
293
+ const cur = Reflect.get(target, key), res = Reflect.set(target, key, value, receiver);
294
+ return res && cur !== value && (typeof key == "string" && clearGetterCache(key), shouldDebug2 && (setters.add({ key, value }), getShouldDebug(storeInfo) && console.log("(debug) SET", res, key, value)), process.env.NODE_ENV === "development" && shouldDebug2 && console.log("SET...", { key, value }), isTriggering || (isTriggering = !0, waitForEventLoop(() => {
295
+ storeInfo.triggerUpdate(), isTriggering = !1;
296
+ }))), res;
297
+ }
298
+ });
299
+ function clearGetterCache(setKey) {
300
+ const parentGetters = depsToGetter.get(setKey);
301
+ if (getCache.delete(setKey), !!parentGetters)
302
+ for (const gk of parentGetters)
303
+ getCache.delete(gk), depsToGetter.has(gk) && clearGetterCache(gk);
304
+ }
305
+ return proxiedStore;
306
+ }
307
+ const waitForEventLoop = process.env.NODE_ENV === "test" ? (cb) => cb() : queueMicrotask;
308
+ let counter = 0;
309
+ const passThroughKeys = {
310
+ subscribe: !0,
311
+ _version: !0,
312
+ _trackers: !0,
313
+ $$typeof: !0,
314
+ _listeners: !0,
315
+ _enableTracking: !0
316
+ };
317
+ function getShouldDebug(storeInfo) {
318
+ const info = { storeInstance: storeInfo.store };
319
+ return [...storeInfo.trackers].some(
320
+ (tracker) => tracker.component && shouldDebug(tracker.component, info)
321
+ );
322
+ }
323
+ export {
324
+ allStores,
325
+ createStore,
326
+ createUseStore,
327
+ createUseStoreSelector,
328
+ getOrCreateStore,
329
+ getStore,
330
+ getStoreInfo,
331
+ onCreateStore,
332
+ setIsInReaction,
333
+ trackStoresAccess,
334
+ useGlobalStore,
335
+ useGlobalStoreSelector,
336
+ useStore,
337
+ useStoreDebug,
338
+ useStoreSelector
339
+ };
340
+ //# sourceMappingURL=useStore.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useStore.tsx"],
4
+ "mappings": "AAA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B,MAAM,QAAQ,IAAI,QAAQ,KAAK,OAAO,QAAQ;AAGpD,aAAI,OAAO,QAAQ,UAEb,OAAO,OAAQ,YACjB,iBAAiB,GAAG,GAElBA,iBACF,QAAQ,IAAI,EAAE,KAAK,MAAM,CAAC,GACtB,eAAe,SAAS,KAE1B,QAAQ,IAAI,eAAe,KAAK,KAAK,KAAK,IAG1C,QAAQ,IAAI,aAAa,iBAAiBA,gBAE5C,QAAQ,IAAI,UAAU,EAAE,KAAK,MAAM,CAAC,GAGjC,iBAEH,eAAe,IACf,iBAAiB,MAAM;AACrB,kBAAU,cAAc,GACxB,eAAe;AAAA,MACjB,CAAC,KAGE;AAAA,IACT;AAAA,EACF,CAAC;AAED,WAAS,iBAAiB,QAAgB;AACxC,UAAM,gBAAgB,aAAa,IAAI,MAAM;AAE7C,QADA,SAAS,OAAO,MAAM,GAClB,EAAC;AAGL,iBAAW,MAAM;AACf,iBAAS,OAAO,EAAE,GACd,aAAa,IAAI,EAAE,KACrB,iBAAiB,EAAE;AAAA,EAGzB;AAEA,SAAO;AACT;AAEA,MAAM,mBACJ,QAAQ,IAAI,aAAa,SAAS,CAAC,OAAiB,GAAG,IAAI;AAE7D,IAAI,UAAU;AAEd,MAAM,kBAAkB;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,iBAAiB;AACnB;AASA,SAAS,eAAe,WAAsB;AAC5C,QAAM,OAAO,EAAE,eAAe,UAAU,MAAM;AAE9C,SAAO,CAAC,GADS,UAAU,QACR,EAAE;AAAA,IACnB,CAAC,YAAY,QAAQ,aAAa,YAAY,QAAQ,WAAW,IAAI;AAAA,EACvE;AACF;",
5
+ "names": ["curInternal", "shouldDebug", "hashCode", "strColor", "key", "name"]
6
+ }
@@ -0,0 +1,22 @@
1
+ import React, { useLayoutEffect } from "react";
2
+ const { ReactCurrentOwner } = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, useCurrentComponent = () => ReactCurrentOwner && ReactCurrentOwner.current && ReactCurrentOwner.current.elementType ? ReactCurrentOwner.current.elementType : {};
3
+ function useDebugStoreComponent(StoreCons) {
4
+ const cmp = useCurrentComponent();
5
+ DebugStores.add(StoreCons), DebugComponents.has(cmp) || DebugComponents.set(cmp, /* @__PURE__ */ new Set());
6
+ const stores = DebugComponents.get(cmp);
7
+ stores.add(StoreCons), useLayoutEffect(() => () => {
8
+ DebugStores.delete(StoreCons), stores.delete(StoreCons);
9
+ }, []);
10
+ }
11
+ const shouldDebug = (component, info) => {
12
+ const StoreCons = info.storeInstance?.constructor;
13
+ return DebugComponents.get(component)?.has(StoreCons);
14
+ }, DebugComponents = /* @__PURE__ */ new Map(), DebugStores = /* @__PURE__ */ new Set();
15
+ export {
16
+ DebugComponents,
17
+ DebugStores,
18
+ shouldDebug,
19
+ useCurrentComponent,
20
+ useDebugStoreComponent
21
+ };
22
+ //# 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,oDACU,sBAAsB,MAC1B,qBACL,kBAAkB,WAClB,kBAAkB,QAAQ,cACxB,kBAAkB,QAAQ,cAC1B,CAAC;AAGA,SAAS,uBAAuB,WAAgB;AACrD,QAAM,MAAM,oBAAoB;AAGhC,cAAY,IAAI,SAAS,GACpB,gBAAgB,IAAI,GAAG,KAC1B,gBAAgB,IAAI,KAAK,oBAAI,IAAI,CAAC;AAEpC,QAAM,SAAS,gBAAgB,IAAI,GAAG;AACtC,SAAO,IAAI,SAAS,GAEpB,gBAAgB,MACP,MAAM;AACX,gBAAY,OAAO,SAAS,GAC5B,OAAO,OAAO,SAAS;AAAA,EACzB,GACC,CAAC,CAAC;AACP;AAEO,MAAM,cAAc,CAAC,WAAgB,SAA2C;AACrF,QAAM,YAAY,KAAK,eAAe;AACtC,SAAO,gBAAgB,IAAI,SAAS,GAAG,IAAI,SAAS;AACtD,GAEa,kBAAkB,oBAAI,IAAmB,GACzC,cAAc,oBAAI,IAAS;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-store",
3
- "version": "1.74.3",
3
+ "version": "1.74.5",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -27,10 +27,10 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@tamagui/simple-hash": "1.74.3"
30
+ "@tamagui/simple-hash": "1.74.5"
31
31
  },
32
32
  "devDependencies": {
33
- "@tamagui/build": "1.74.3",
33
+ "@tamagui/build": "1.74.5",
34
34
  "@testing-library/react": "^14.0.0",
35
35
  "react": "^18.2.0",
36
36
  "vitest": "^0.34.3"