@hanzogui/use-store 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/cjs/comparators.cjs +37 -0
- package/dist/cjs/comparators.native.js +46 -0
- package/dist/cjs/comparators.native.js.map +1 -0
- package/dist/cjs/configureUseStore.cjs +30 -0
- package/dist/cjs/configureUseStore.native.js +33 -0
- package/dist/cjs/configureUseStore.native.js.map +1 -0
- package/dist/cjs/constants.cjs +31 -0
- package/dist/cjs/constants.native.js +34 -0
- package/dist/cjs/constants.native.js.map +1 -0
- package/dist/cjs/decorators.cjs +30 -0
- package/dist/cjs/decorators.native.js +33 -0
- package/dist/cjs/decorators.native.js.map +1 -0
- package/dist/cjs/helpers.cjs +55 -0
- package/dist/cjs/helpers.native.js +65 -0
- package/dist/cjs/helpers.native.js.map +1 -0
- package/dist/cjs/index.cjs +40 -0
- package/dist/cjs/index.native.js +54 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/interfaces.cjs +16 -0
- package/dist/cjs/interfaces.native.js +19 -0
- package/dist/cjs/interfaces.native.js.map +1 -0
- package/dist/cjs/observe.cjs +120 -0
- package/dist/cjs/observe.native.js +186 -0
- package/dist/cjs/observe.native.js.map +1 -0
- package/dist/cjs/useStore.cjs +390 -0
- package/dist/cjs/useStore.native.js +544 -0
- package/dist/cjs/useStore.native.js.map +1 -0
- package/dist/cjs/useStoreDebug.cjs +56 -0
- package/dist/cjs/useStoreDebug.native.js +65 -0
- package/dist/cjs/useStoreDebug.native.js.map +1 -0
- package/dist/esm/comparators.mjs +14 -0
- package/dist/esm/comparators.mjs.map +1 -0
- package/dist/esm/comparators.native.js +20 -0
- package/dist/esm/comparators.native.js.map +1 -0
- package/dist/esm/configureUseStore.mjs +6 -0
- package/dist/esm/configureUseStore.mjs.map +1 -0
- package/dist/esm/configureUseStore.native.js +6 -0
- package/dist/esm/configureUseStore.native.js.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/constants.native.js +7 -0
- package/dist/esm/constants.native.js.map +1 -0
- package/dist/esm/decorators.mjs +7 -0
- package/dist/esm/decorators.mjs.map +1 -0
- package/dist/esm/decorators.native.js +7 -0
- package/dist/esm/decorators.native.js.map +1 -0
- package/dist/esm/helpers.mjs +26 -0
- package/dist/esm/helpers.mjs.map +1 -0
- package/dist/esm/helpers.native.js +33 -0
- package/dist/esm/helpers.native.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +25 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/interfaces.mjs +2 -0
- package/dist/esm/interfaces.mjs.map +1 -0
- package/dist/esm/interfaces.native.js +2 -0
- package/dist/esm/interfaces.native.js.map +1 -0
- package/dist/esm/observe.mjs +85 -0
- package/dist/esm/observe.mjs.map +1 -0
- package/dist/esm/observe.native.js +148 -0
- package/dist/esm/observe.native.js.map +1 -0
- package/dist/esm/useStore.mjs +342 -0
- package/dist/esm/useStore.mjs.map +1 -0
- package/dist/esm/useStore.native.js +493 -0
- package/dist/esm/useStore.native.js.map +1 -0
- package/dist/esm/useStoreDebug.mjs +18 -0
- package/dist/esm/useStoreDebug.mjs.map +1 -0
- package/dist/esm/useStoreDebug.native.js +24 -0
- package/dist/esm/useStoreDebug.native.js.map +1 -0
- package/package.json +47 -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 +56 -0
- package/src/index.ts +12 -0
- package/src/interfaces.tsx +46 -0
- package/src/observe.tsx +160 -0
- package/src/useStore.tsx +705 -0
- package/src/useStoreDebug.tsx +41 -0
|
@@ -0,0 +1,493 @@
|
|
|
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
|
+
function _instanceof(left, right) {
|
|
8
|
+
return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
|
|
9
|
+
}
|
|
10
|
+
var idFn = function (_) {
|
|
11
|
+
return _;
|
|
12
|
+
};
|
|
13
|
+
function useStore(StoreKlass, props) {
|
|
14
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions,
|
|
15
|
+
info = getOrCreateStoreInfo(StoreKlass, props, options);
|
|
16
|
+
return useStoreFromInfo(info, options.selector, options);
|
|
17
|
+
}
|
|
18
|
+
function useStoreDebug(StoreKlass, props) {
|
|
19
|
+
return useStore(StoreKlass, props, {
|
|
20
|
+
debug: !0
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function createStore(StoreKlass, props, options) {
|
|
24
|
+
var _getOrCreateStoreInfo;
|
|
25
|
+
return (_getOrCreateStoreInfo = getOrCreateStoreInfo(StoreKlass, props, options)) === null || _getOrCreateStoreInfo === void 0 ? void 0 : _getOrCreateStoreInfo.store;
|
|
26
|
+
}
|
|
27
|
+
function useGlobalStore(instance, debug) {
|
|
28
|
+
var store = instance[UNWRAP_PROXY],
|
|
29
|
+
uid = getStoreUid(store.constructor, store.props),
|
|
30
|
+
info = cache.get(uid);
|
|
31
|
+
if (!info) throw new Error("This store not created using createStore()");
|
|
32
|
+
return useStoreFromInfo(info, void 0, {
|
|
33
|
+
debug
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function useGlobalStoreSelector(instance, selector, debug) {
|
|
37
|
+
var store = instance[UNWRAP_PROXY],
|
|
38
|
+
uid = getStoreUid(store.constructor, store.props),
|
|
39
|
+
info = cache.get(uid);
|
|
40
|
+
if (!info) throw new Error("This store not created using createStore()");
|
|
41
|
+
return useStoreFromInfo(info, selector, {
|
|
42
|
+
debug
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function createUseStore(StoreKlass) {
|
|
46
|
+
return function (props, options) {
|
|
47
|
+
return useStore(StoreKlass, props, options);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createUseStoreSelector(StoreKlass, selector) {
|
|
51
|
+
return function (props) {
|
|
52
|
+
return useStore(StoreKlass, props, {
|
|
53
|
+
selector
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function useStoreSelector(StoreKlass, selector, props) {
|
|
58
|
+
return useStore(StoreKlass, props, {
|
|
59
|
+
selector
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
var storeAccessTrackers = /* @__PURE__ */new Set();
|
|
63
|
+
function trackStoresAccess(cb) {
|
|
64
|
+
return storeAccessTrackers.add(cb), function () {
|
|
65
|
+
storeAccessTrackers.delete(cb);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function getStore(StoreKlass, props) {
|
|
69
|
+
var _getStoreInfo;
|
|
70
|
+
return (_getStoreInfo = getStoreInfo(StoreKlass, props)) === null || _getStoreInfo === void 0 ? void 0 : _getStoreInfo.store;
|
|
71
|
+
}
|
|
72
|
+
function getOrCreateStore(StoreKlass, props) {
|
|
73
|
+
var _getOrCreateStoreInfo;
|
|
74
|
+
return (_getOrCreateStoreInfo = getOrCreateStoreInfo(StoreKlass, props, {
|
|
75
|
+
refuseCreation: !1
|
|
76
|
+
})) === null || _getOrCreateStoreInfo === void 0 ? void 0 : _getOrCreateStoreInfo.store;
|
|
77
|
+
}
|
|
78
|
+
function getStoreInfo(StoreKlass, props) {
|
|
79
|
+
return getOrCreateStoreInfo(StoreKlass, props, {
|
|
80
|
+
refuseCreation: !0
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
var onCreateListeners = /* @__PURE__ */new Set();
|
|
84
|
+
function onCreateStore(cb) {
|
|
85
|
+
return onCreateListeners.add(cb), function () {
|
|
86
|
+
onCreateListeners.delete(cb);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
90
|
+
var _store_mount;
|
|
91
|
+
if (!StoreKlass) return null;
|
|
92
|
+
var uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
|
|
93
|
+
if (!options?.avoidCache && cache.has(uid)) return cache.get(uid);
|
|
94
|
+
if (options?.refuseCreation) throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
|
|
95
|
+
var storeInstance = new StoreKlass(props);
|
|
96
|
+
storeInstance.props = props;
|
|
97
|
+
var getters = {},
|
|
98
|
+
actions = {},
|
|
99
|
+
stateKeys = /* @__PURE__ */new Set(),
|
|
100
|
+
descriptors = getStoreDescriptors(storeInstance);
|
|
101
|
+
for (var key in descriptors) {
|
|
102
|
+
var descriptor = descriptors[key];
|
|
103
|
+
typeof descriptor.value == "function" ? actions[key] = descriptor.value : typeof descriptor.get == "function" ? getters[key] = descriptor.get : key !== "props" && key[0] !== "_" && stateKeys.add(key);
|
|
104
|
+
}
|
|
105
|
+
var keyComparators = storeInstance._comparators,
|
|
106
|
+
listeners = /* @__PURE__ */new Set(),
|
|
107
|
+
storeInfo = {
|
|
108
|
+
uid,
|
|
109
|
+
keyComparators,
|
|
110
|
+
storeInstance,
|
|
111
|
+
getters,
|
|
112
|
+
stateKeys,
|
|
113
|
+
props,
|
|
114
|
+
actions,
|
|
115
|
+
debug: options?.debug,
|
|
116
|
+
disableTracking: !1,
|
|
117
|
+
gettersState: {
|
|
118
|
+
getCache: /* @__PURE__ */new Map(),
|
|
119
|
+
depsToGetter: /* @__PURE__ */new Map(),
|
|
120
|
+
curGetKeys: /* @__PURE__ */new Set(),
|
|
121
|
+
isGetting: !1
|
|
122
|
+
},
|
|
123
|
+
listeners,
|
|
124
|
+
trackers: /* @__PURE__ */new Set(),
|
|
125
|
+
version: 0,
|
|
126
|
+
subscribe: function (onChanged) {
|
|
127
|
+
return listeners.add(onChanged), function () {
|
|
128
|
+
listeners.delete(onChanged);
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
triggerUpdate: function () {
|
|
132
|
+
storeInfo.version = (storeInfo.version + 1) % Number.MAX_SAFE_INTEGER;
|
|
133
|
+
var _iteratorNormalCompletion = !0,
|
|
134
|
+
_didIteratorError = !1,
|
|
135
|
+
_iteratorError = void 0;
|
|
136
|
+
try {
|
|
137
|
+
for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
138
|
+
var cb = _step.value;
|
|
139
|
+
cb();
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
143
|
+
} finally {
|
|
144
|
+
try {
|
|
145
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
146
|
+
} finally {
|
|
147
|
+
if (_didIteratorError) throw _iteratorError;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
store = createProxiedStore(
|
|
153
|
+
// we assign store right after and proxiedStore never accesses it until later on
|
|
154
|
+
storeInfo);
|
|
155
|
+
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;
|
|
156
|
+
var result = storeInfo;
|
|
157
|
+
return cache.set(uid, result), onCreateListeners.forEach(function (cb) {
|
|
158
|
+
return cb(result);
|
|
159
|
+
}), result;
|
|
160
|
+
}
|
|
161
|
+
var allStores = {};
|
|
162
|
+
if (process.env.NODE_ENV === "development") {
|
|
163
|
+
var _globalThis, _Store;
|
|
164
|
+
(_globalThis = globalThis)[_Store = "Store"] || (_globalThis[_Store] = allStores);
|
|
165
|
+
}
|
|
166
|
+
var emptyObj = {},
|
|
167
|
+
selectKeys = function (obj, keys) {
|
|
168
|
+
if (!keys.length) return emptyObj;
|
|
169
|
+
var res = {},
|
|
170
|
+
_iteratorNormalCompletion = !0,
|
|
171
|
+
_didIteratorError = !1,
|
|
172
|
+
_iteratorError = void 0;
|
|
173
|
+
try {
|
|
174
|
+
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
175
|
+
var key = _step.value;
|
|
176
|
+
res[key] = obj[key];
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
180
|
+
} finally {
|
|
181
|
+
try {
|
|
182
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
183
|
+
} finally {
|
|
184
|
+
if (_didIteratorError) throw _iteratorError;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return res;
|
|
188
|
+
},
|
|
189
|
+
isInReaction = !1,
|
|
190
|
+
setIsInReaction = function (val) {
|
|
191
|
+
isInReaction = val;
|
|
192
|
+
};
|
|
193
|
+
function useStoreFromInfo(info, userSelector, options) {
|
|
194
|
+
var store = info?.store,
|
|
195
|
+
internal = React.useRef(void 0),
|
|
196
|
+
component = useCurrentComponent();
|
|
197
|
+
internal.current || (internal.current = {
|
|
198
|
+
component,
|
|
199
|
+
tracked: /* @__PURE__ */new Set(),
|
|
200
|
+
last: null,
|
|
201
|
+
lastKeys: null
|
|
202
|
+
});
|
|
203
|
+
var curInternal = internal.current,
|
|
204
|
+
shouldPrintDebug = options?.debug,
|
|
205
|
+
getSnapshot = React.useCallback(function () {
|
|
206
|
+
if (!(!info || !store)) {
|
|
207
|
+
var curInternal2 = internal.current,
|
|
208
|
+
isTracking = curInternal2.tracked.size,
|
|
209
|
+
keys = [...(isTracking ? curInternal2.tracked : info.stateKeys)],
|
|
210
|
+
nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`,
|
|
211
|
+
lastKeys = curInternal2.lastKeys;
|
|
212
|
+
if (nextKeys === curInternal2.lastKeys) return curInternal2.last;
|
|
213
|
+
curInternal2.lastKeys = nextKeys;
|
|
214
|
+
var snap;
|
|
215
|
+
info.disableTracking = !0;
|
|
216
|
+
var last = curInternal2.last;
|
|
217
|
+
userSelector ? snap = userSelector(store) : snap = selectKeys(store, keys), info.disableTracking = !1;
|
|
218
|
+
var isUnchanged = !userSelector && !isTracking && last || typeof last < "u" && isEqualSubsetShallow(last, snap, {
|
|
219
|
+
keyComparators: info.keyComparators
|
|
220
|
+
});
|
|
221
|
+
return shouldPrintDebug && console.info("\u{1F311} getSnapshot", {
|
|
222
|
+
storeState: selectKeys(store, Object.keys(store)),
|
|
223
|
+
userSelector,
|
|
224
|
+
info,
|
|
225
|
+
isUnchanged,
|
|
226
|
+
component,
|
|
227
|
+
keys,
|
|
228
|
+
last,
|
|
229
|
+
snap,
|
|
230
|
+
curInternal: curInternal2,
|
|
231
|
+
nextKeys,
|
|
232
|
+
lastKeys
|
|
233
|
+
}), isUnchanged ? last : (curInternal2.last = snap, snap);
|
|
234
|
+
}
|
|
235
|
+
}, [store]),
|
|
236
|
+
state = React.useSyncExternalStore(info?.subscribe || idFn, getSnapshot, getSnapshot);
|
|
237
|
+
return !info || !store || !state || userSelector ? state : new Proxy(store, {
|
|
238
|
+
get(target, key) {
|
|
239
|
+
var curVal = Reflect.get(target, key);
|
|
240
|
+
if (isInReaction) return curVal;
|
|
241
|
+
var keyString = key;
|
|
242
|
+
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;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
var setters = /* @__PURE__ */new Set(),
|
|
247
|
+
logStack = /* @__PURE__ */new Set();
|
|
248
|
+
function createProxiedStore(storeInfo) {
|
|
249
|
+
var _loop = function (key2) {
|
|
250
|
+
if (key2 === "subscribe") return "continue";
|
|
251
|
+
var actionFn = actions[key2],
|
|
252
|
+
isGetFn = key2.startsWith("get");
|
|
253
|
+
if (wrappedActions[key2] = function () {
|
|
254
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
255
|
+
var res;
|
|
256
|
+
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), _instanceof(res, Promise) ? res.then(finishAction) : (finishAction(), res));
|
|
257
|
+
}, process.env.NODE_ENV === "development") {
|
|
258
|
+
let hashCode2 = function (str) {
|
|
259
|
+
for (var hash = 0, i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
260
|
+
return hash;
|
|
261
|
+
},
|
|
262
|
+
strColor2 = function (str) {
|
|
263
|
+
return `hsl(${hashCode2(str) % 360}, 90%, 40%)`;
|
|
264
|
+
};
|
|
265
|
+
var hashCode = hashCode2,
|
|
266
|
+
strColor = strColor2;
|
|
267
|
+
if (!key2.startsWith("get") && !key2.startsWith("_") && key2 !== "subscribe") {
|
|
268
|
+
var ogAction = wrappedActions[key2];
|
|
269
|
+
wrappedActions[key2] = new Proxy(ogAction, {
|
|
270
|
+
apply(target, thisArg, args) {
|
|
271
|
+
var isDebugging = shouldDebug2 || storeInfo.debug,
|
|
272
|
+
shouldLog = process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error");
|
|
273
|
+
if (!shouldLog) return Reflect.apply(target, thisArg, args);
|
|
274
|
+
setters = /* @__PURE__ */new Set();
|
|
275
|
+
var curSetters = setters,
|
|
276
|
+
isTopLevelLogger = logStack.size == 0,
|
|
277
|
+
logs = /* @__PURE__ */new Set();
|
|
278
|
+
logStack.add(logs);
|
|
279
|
+
var res,
|
|
280
|
+
id = counter++;
|
|
281
|
+
try {
|
|
282
|
+
res = Reflect.apply(target, thisArg, args);
|
|
283
|
+
} catch (err) {
|
|
284
|
+
throw console.error("Error", err), err;
|
|
285
|
+
} finally {
|
|
286
|
+
logStack.add("end");
|
|
287
|
+
var name = constr.name,
|
|
288
|
+
color = strColor2(name),
|
|
289
|
+
simpleArgs = args.map(simpleStr);
|
|
290
|
+
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) {
|
|
291
|
+
var {
|
|
292
|
+
key: key3,
|
|
293
|
+
value
|
|
294
|
+
} = param;
|
|
295
|
+
typeof value == "string" || typeof value == "number" || typeof value == "boolean" ? logs.add([` SET ${key3} ${value}`, value]) : logs.add([` SET ${key3}`, value]);
|
|
296
|
+
}), isTopLevelLogger) {
|
|
297
|
+
var error = null;
|
|
298
|
+
try {
|
|
299
|
+
var _iteratorNormalCompletion = !0,
|
|
300
|
+
_didIteratorError = !1,
|
|
301
|
+
_iteratorError = void 0;
|
|
302
|
+
try {
|
|
303
|
+
for (var _iterator = logStack[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
304
|
+
var item = _step.value;
|
|
305
|
+
if (item === "end") {
|
|
306
|
+
console.groupEnd();
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
var [head, ...rest] = item;
|
|
310
|
+
if (head) {
|
|
311
|
+
console.groupCollapsed(...head), console.groupCollapsed("..."), console.info("args", args), console.info("response", res), console.groupCollapsed("trace"), console.trace(), console.groupEnd(), console.groupEnd();
|
|
312
|
+
var _iteratorNormalCompletion1 = !0,
|
|
313
|
+
_didIteratorError1 = !1,
|
|
314
|
+
_iteratorError1 = void 0;
|
|
315
|
+
try {
|
|
316
|
+
for (var _iterator1 = rest[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
|
|
317
|
+
var [name1, ...log] = _step1.value;
|
|
318
|
+
console.groupCollapsed(name1), console.info(...log), console.groupEnd();
|
|
319
|
+
}
|
|
320
|
+
} catch (err) {
|
|
321
|
+
_didIteratorError1 = !0, _iteratorError1 = err;
|
|
322
|
+
} finally {
|
|
323
|
+
try {
|
|
324
|
+
!_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
|
|
325
|
+
} finally {
|
|
326
|
+
if (_didIteratorError1) throw _iteratorError1;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} else console.info("Weird log", head, ...rest);
|
|
330
|
+
}
|
|
331
|
+
} catch (err) {
|
|
332
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
333
|
+
} finally {
|
|
334
|
+
try {
|
|
335
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
336
|
+
} finally {
|
|
337
|
+
if (_didIteratorError) throw _iteratorError;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} catch (err) {
|
|
341
|
+
error = err;
|
|
342
|
+
}
|
|
343
|
+
var _iteratorNormalCompletion2 = !0,
|
|
344
|
+
_didIteratorError2 = !1,
|
|
345
|
+
_iteratorError2 = void 0;
|
|
346
|
+
try {
|
|
347
|
+
for (var _iterator2 = logStack[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
|
|
348
|
+
var _ = _step2.value;
|
|
349
|
+
console.groupEnd();
|
|
350
|
+
}
|
|
351
|
+
} catch (err) {
|
|
352
|
+
_didIteratorError2 = !0, _iteratorError2 = err;
|
|
353
|
+
} finally {
|
|
354
|
+
try {
|
|
355
|
+
!_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
|
|
356
|
+
} finally {
|
|
357
|
+
if (_didIteratorError2) throw _iteratorError2;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
error && console.error("error loggin", error), logStack.clear();
|
|
361
|
+
}
|
|
362
|
+
return res;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
actions,
|
|
371
|
+
storeInstance,
|
|
372
|
+
getters,
|
|
373
|
+
gettersState
|
|
374
|
+
} = storeInfo,
|
|
375
|
+
{
|
|
376
|
+
getCache,
|
|
377
|
+
curGetKeys,
|
|
378
|
+
depsToGetter
|
|
379
|
+
} = gettersState,
|
|
380
|
+
constr = storeInstance.constructor,
|
|
381
|
+
_storeInfo_debug,
|
|
382
|
+
shouldDebug2 = (_storeInfo_debug = storeInfo.debug) !== null && _storeInfo_debug !== void 0 ? _storeInfo_debug : DebugStores.has(constr),
|
|
383
|
+
didSet = !1,
|
|
384
|
+
wrappedActions = {};
|
|
385
|
+
for (var key in actions) _loop(key);
|
|
386
|
+
var finishAction = function (val) {
|
|
387
|
+
return process.env.NODE_ENV === "development" && shouldDebug2 && console.info("(debug) finishAction", {
|
|
388
|
+
didSet
|
|
389
|
+
}), didSet && (storeInfo.triggerUpdate(), didSet = !1), val;
|
|
390
|
+
},
|
|
391
|
+
isTriggering = !1,
|
|
392
|
+
proxiedStore = new Proxy(storeInstance, {
|
|
393
|
+
// GET
|
|
394
|
+
get(_, key2) {
|
|
395
|
+
if (key2 in wrappedActions) return wrappedActions[key2];
|
|
396
|
+
if (key2 in passThroughKeys) return Reflect.get(storeInstance, key2);
|
|
397
|
+
if (key2 === UNWRAP_PROXY) return storeInstance;
|
|
398
|
+
if (key2 === UNWRAP_STORE_INFO) return storeInfo;
|
|
399
|
+
if (storeAccessTrackers.size && storeAccessTrackers.forEach(function (cb) {
|
|
400
|
+
return cb(storeInfo);
|
|
401
|
+
}), typeof key2 != "string") return Reflect.get(storeInstance, key2);
|
|
402
|
+
if (storeInfo.disableTracking || gettersState.isGetting && gettersState.curGetKeys.add(key2), key2 in getters) {
|
|
403
|
+
if (getCache.has(key2)) return getCache.get(key2);
|
|
404
|
+
curGetKeys.clear();
|
|
405
|
+
var isSubGetter = gettersState.isGetting;
|
|
406
|
+
gettersState.isGetting = !0;
|
|
407
|
+
var res = getters[key2].call(proxiedStore);
|
|
408
|
+
isSubGetter || (gettersState.isGetting = !1);
|
|
409
|
+
var _iteratorNormalCompletion = !0,
|
|
410
|
+
_didIteratorError = !1,
|
|
411
|
+
_iteratorError = void 0;
|
|
412
|
+
try {
|
|
413
|
+
for (var _iterator = curGetKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
414
|
+
var gk = _step.value;
|
|
415
|
+
depsToGetter.has(gk) || depsToGetter.set(gk, /* @__PURE__ */new Set());
|
|
416
|
+
var cur = depsToGetter.get(gk);
|
|
417
|
+
cur.add(key2);
|
|
418
|
+
}
|
|
419
|
+
} catch (err) {
|
|
420
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
421
|
+
} finally {
|
|
422
|
+
try {
|
|
423
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
424
|
+
} finally {
|
|
425
|
+
if (_didIteratorError) throw _iteratorError;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return getCache.set(key2, res), res;
|
|
429
|
+
}
|
|
430
|
+
return Reflect.get(storeInstance, key2);
|
|
431
|
+
},
|
|
432
|
+
// SET
|
|
433
|
+
set(target, key2, value, receiver) {
|
|
434
|
+
var cur = Reflect.get(target, key2),
|
|
435
|
+
res = Reflect.set(target, key2, value, receiver);
|
|
436
|
+
return res && cur !== value && (typeof key2 == "string" && (clearGetterCache(key2), shouldDebug2 && (setters.add({
|
|
437
|
+
key: key2,
|
|
438
|
+
value
|
|
439
|
+
}), getShouldDebug(storeInfo) && console.info("(debug) SET", res, key2, value)), process.env.NODE_ENV === "development" && shouldDebug2 && console.info("SET...", {
|
|
440
|
+
key: key2,
|
|
441
|
+
value
|
|
442
|
+
})), isTriggering || (isTriggering = !0, waitForEventLoop(function () {
|
|
443
|
+
storeInfo.triggerUpdate(), isTriggering = !1;
|
|
444
|
+
}))), res;
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
function clearGetterCache(setKey) {
|
|
448
|
+
var parentGetters = depsToGetter.get(setKey);
|
|
449
|
+
if (getCache.delete(setKey), !!parentGetters) {
|
|
450
|
+
var _iteratorNormalCompletion = !0,
|
|
451
|
+
_didIteratorError = !1,
|
|
452
|
+
_iteratorError = void 0;
|
|
453
|
+
try {
|
|
454
|
+
for (var _iterator = parentGetters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
455
|
+
var gk = _step.value;
|
|
456
|
+
getCache.delete(gk), depsToGetter.has(gk) && clearGetterCache(gk);
|
|
457
|
+
}
|
|
458
|
+
} catch (err) {
|
|
459
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
460
|
+
} finally {
|
|
461
|
+
try {
|
|
462
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
463
|
+
} finally {
|
|
464
|
+
if (_didIteratorError) throw _iteratorError;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return proxiedStore;
|
|
470
|
+
}
|
|
471
|
+
var waitForEventLoop = (process.env.NODE_ENV, function (cb) {
|
|
472
|
+
return cb();
|
|
473
|
+
}),
|
|
474
|
+
counter = 0,
|
|
475
|
+
passThroughKeys = {
|
|
476
|
+
subscribe: !0,
|
|
477
|
+
_version: !0,
|
|
478
|
+
_trackers: !0,
|
|
479
|
+
$$typeof: !0,
|
|
480
|
+
_listeners: !0,
|
|
481
|
+
_enableTracking: !0
|
|
482
|
+
};
|
|
483
|
+
function getShouldDebug(storeInfo) {
|
|
484
|
+
var info = {
|
|
485
|
+
storeInstance: storeInfo.store
|
|
486
|
+
},
|
|
487
|
+
trackers = storeInfo.trackers;
|
|
488
|
+
return [...trackers].some(function (tracker) {
|
|
489
|
+
return tracker.component && shouldDebug(tracker.component, info);
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
export { allStores, createStore, createUseStore, createUseStoreSelector, getOrCreateStore, getStore, getStoreInfo, onCreateStore, setIsInReaction, trackStoresAccess, useGlobalStore, useGlobalStoreSelector, useStore, useStoreDebug, useStoreSelector };
|
|
493
|
+
//# sourceMappingURL=useStore.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","isEqualSubsetShallow","configureOpts","UNWRAP_PROXY","defaultOptions","UNWRAP_STORE_INFO","cache","getStoreDescriptors","getStoreUid","simpleStr","DebugStores","shouldDebug","useCurrentComponent","_instanceof","left","right","Symbol","hasInstance","idFn","_","useStore","StoreKlass","props","options","arguments","length","info","getOrCreateStoreInfo","useStoreFromInfo","selector","useStoreDebug","debug","createStore","_getOrCreateStoreInfo","store","useGlobalStore","instance","uid","constructor","get","Error","useGlobalStoreSelector","createUseStore","createUseStoreSelector","useStoreSelector","storeAccessTrackers","Set","trackStoresAccess","cb","add","delete","getStore","_getStoreInfo","getStoreInfo","getOrCreateStore","refuseCreation","onCreateListeners","onCreateStore","propsKeyCalculated","_store_mount","avoidCache","has","name","storeInstance","getters","actions","stateKeys","descriptors","key","descriptor","value","keyComparators","_comparators","listeners","storeInfo","disableTracking","gettersState","getCache","Map","depsToGetter","curGetKeys","isGetting","trackers","version","subscribe","onChanged","triggerUpdate","Number","MAX_SAFE_INTEGER","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","iterator","_step","next","done","err","return","createProxiedStore","process","env","NODE_ENV","allStores","mount","call","result","set","forEach","_globalThis","_Store","globalThis","emptyObj","selectKeys","obj","keys","res","isInReaction","setIsInReaction","val","userSelector","internal","useRef","component","current","tracked","last","lastKeys","curInternal","shouldPrintDebug","getSnapshot","useCallback","curInternal2","isTracking","size","nextKeys","join","snap","isUnchanged","console","storeState","Object","state","useSyncExternalStore","Proxy","target","curVal","Reflect","keyString","setters","logStack","_loop","key2","actionFn","isGetFn","startsWith","wrappedActions","_len","args","Array","_key","apply","proxiedStore","shouldDebug2","Promise","then","finishAction","hashCode2","str","hash","i","charCodeAt","strColor2","hashCode","strColor","ogAction","thisArg","isDebugging","shouldLog","LOG_LEVEL","logLevel","curSetters","isTopLevelLogger","logs","id","counter","error","constr","color","simpleArgs","map","padStart","param","key3","item","groupEnd","head","rest","groupCollapsed","trace","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","name1","log"],"sources":["../../src/useStore.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAElB,SAASC,oBAAA,QAA4B;AACrC,SAASC,aAAA,QAAqB;AAC9B,SAASC,YAAA,EAAcC,cAAA,QAAsB;AAC7C,SAAAC,iBAAA,EAAAC,KAAA,EAAAC,mBAAA,EAAAC,WAAA,EAAAC,SAAA;AAAA,SACEC,WAAA,EAAAC,WAAA,EAAAC,mBAAA;AAAA,SACAC,YAAAC,IAAA,EAAAC,KAAA;EACA,OAAAA,KAAA,mBAAAC,MAAA,UAAAD,KAAA,CAAAC,MAAA,CAAAC,WAAA,MAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA,IAAAA,IAAA,YAAAC,KAAA;AAAA;AACA,IACAG,IAAA,YAAAA,CAAAC,CAAA;EAAA,OACKA,CAAA;AAEP;AAEA,SAAMC,QAAQA,CAAAC,UAAM,EAAAC,KAAA;EAGb,IAAAC,OAAS,GAAAC,SACd,CAAAC,MACA,QACAD,SAAmC,cAChC,GAAAA,SAAA,MAAApB,cAAA;IAAAsB,IAAA,GAAAC,oBAAA,CAAAN,UAAA,EA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H,IAAA,aAAA0F,GAAA,GAAAuB,OAAA,CAAA2D,cAAA,WAAA3D,OAAA,CAAA4D,KAAA,IAAA5D,OAAA,CAAAwD,QAAA,IAAAxD,OAAA,CAAAwD,QAAA;0BACD,IAAAK,0BAAA;4BAAAC,kBAAA;4BAAAC,eAAA;0BAEQ,IAAiB;4BACF,SAAAC,UAAiB,GAAAN,IAAM,CAAArL,MAAA,CAAA6E,QAAA,KAAA+G,MAAA,IAAAJ,0BAAA,IAAAI,MAAA,GAAAD,UAAA,CAAA5G,IAAA,IAAAC,IAAA,GAAAwG,0BAAA;8BAC7B,IAAM,CAElBK,KAAC,KAAAC,GAAA,IAAAF,MAAA,CAAAtI,KAAA;8BAGYqE,OAAA,CAAA2D,cAAA,CAAAO,KAAA,GAAAlE,OAAA,CAAAjH,IAAA,IAAAoL,GAAA,GAAAnE,OAAA,CAAAwD,QAAA;4BACG;0BAKtB,SAAAlG,GAAA;4BAEOwG,kBAAA,OAAAC,eAAA,GAAAzG,GAAA;0BACT;4BAGE;8BAIY,CAAAuG,0BAAA,IAAAG,UAAA,CAAAzG,MAAA,YAAAyG,UAAA,CAAAzG,MAAA;4BAEU;8BACX,IAAAuG,kBAAA,EACD,MAAAC,eAAA;4BACC;0BACD;wBACE,OACK/D,OAAA,CAAAjH,IAAA,cAAA0K,IAAA,KAAAC,IAAA;sBACnB;oBASS,SAAepG,GAAA;sBACPP,iBAAe,KAAU,EAAAC,cAAM,GAAAM,GAAA;oBAC7B,UAAU;sBAEZ;wBACf,CAAAR,yBAAA,IAAAG,SAAA,CAAAM,MAAA,YAAAN,SAAA,CAAAM,MAAA;sBACF","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
const useCurrentComponent = () => ({});
|
|
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), React.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
|
+
},
|
|
15
|
+
DebugComponents = /* @__PURE__ */new Map(),
|
|
16
|
+
DebugStores = /* @__PURE__ */new Set();
|
|
17
|
+
export { DebugComponents, DebugStores, shouldDebug, useCurrentComponent, useDebugStoreComponent };
|
|
18
|
+
//# sourceMappingURL=useStoreDebug.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCurrentComponent","useDebugStoreComponent","StoreCons","cmp","DebugStores","add","DebugComponents","has","set","Set","stores","get","useLayoutEffect","delete","shouldDebug","component","info","storeInstance","constructor","Map"],"sources":["../../src/useStoreDebug.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAMX,MAAMC,mBAAA,GAAsBA,CAAA,MAC1B,CAAC;AAQH,SAASC,uBAAuBC,SAAA,EAAgB;EACrD,MAAMC,GAAA,GAAMH,mBAAA,CAAoB;EAGhCI,WAAA,CAAYC,GAAA,CAAIH,SAAS,GACpBI,eAAA,CAAgBC,GAAA,CAAIJ,GAAG,KAC1BG,eAAA,CAAgBE,GAAA,CAAIL,GAAA,EAAK,mBAAIM,GAAA,CAAI,CAAC;EAEpC,MAAMC,MAAA,GAASJ,eAAA,CAAgBK,GAAA,CAAIR,GAAG;EACtCO,MAAA,CAAOL,GAAA,CAAIH,SAAS,GAEpBH,KAAA,CAAMa,eAAA,CAAgB,MACb,MAAM;IACXR,WAAA,CAAYS,MAAA,CAAOX,SAAS,GAC5BQ,MAAA,CAAOG,MAAA,CAAOX,SAAS;EACzB,GACC,EAAE;AACP;AAEO,MAAMY,WAAA,GAAcA,CAACC,SAAA,EAAgBC,IAAA,KAA2C;IACrF,MAAMd,SAAA,GAAYc,IAAA,CAAKC,aAAA,EAAeC,WAAA;IACtC,OAAOZ,eAAA,CAAgBK,GAAA,CAAII,SAAS,GAAGR,GAAA,CAAIL,SAAS;EACtD;EAEaI,eAAA,GAAkB,mBAAIa,GAAA,CAAmB;EACzCf,WAAA,GAAc,mBAAIK,GAAA,CAAS","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
var useCurrentComponent = function () {
|
|
3
|
+
return {};
|
|
4
|
+
};
|
|
5
|
+
function useDebugStoreComponent(StoreCons) {
|
|
6
|
+
var cmp = useCurrentComponent();
|
|
7
|
+
DebugStores.add(StoreCons), DebugComponents.has(cmp) || DebugComponents.set(cmp, /* @__PURE__ */new Set());
|
|
8
|
+
var stores = DebugComponents.get(cmp);
|
|
9
|
+
stores.add(StoreCons), React.useLayoutEffect(function () {
|
|
10
|
+
return function () {
|
|
11
|
+
DebugStores.delete(StoreCons), stores.delete(StoreCons);
|
|
12
|
+
};
|
|
13
|
+
}, []);
|
|
14
|
+
}
|
|
15
|
+
var shouldDebug = function (component, info) {
|
|
16
|
+
var _info_storeInstance,
|
|
17
|
+
_DebugComponents_get,
|
|
18
|
+
StoreCons = (_info_storeInstance = info.storeInstance) === null || _info_storeInstance === void 0 ? void 0 : _info_storeInstance.constructor;
|
|
19
|
+
return (_DebugComponents_get = DebugComponents.get(component)) === null || _DebugComponents_get === void 0 ? void 0 : _DebugComponents_get.has(StoreCons);
|
|
20
|
+
},
|
|
21
|
+
DebugComponents = /* @__PURE__ */new Map(),
|
|
22
|
+
DebugStores = /* @__PURE__ */new Set();
|
|
23
|
+
export { DebugComponents, DebugStores, shouldDebug, useCurrentComponent, useDebugStoreComponent };
|
|
24
|
+
//# sourceMappingURL=useStoreDebug.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCurrentComponent","useDebugStoreComponent","StoreCons","cmp","DebugStores","add","DebugComponents","has","set","Set","stores","get","useLayoutEffect","delete"],"sources":["../../src/useStoreDebug.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAMX,IAAAC,mBAAM,YAAAA,CAAA,EACH;EAQH,OAAS;AACd;AAGA,SAAAC,sBACKA,CAAAC,SAAA;EAGL,IAAAC,GAAM,GAAAH,mBAAS,EAAgB;EAC/BI,WAAW,CAAAC,GAAA,CAAAH,SAEX,GAAAI,eAAM,CAAAC,GAAgB,CAAAJ,GACb,KAAAG,eAAM,CAAAE,GAAA,CAAAL,GAAA,qBAAAM,GAAA;EACX,IAAAC,MAAA,GAAAJ,eAAmB,CAAAK,GAAS,CAC5BR,GAAA;EACFO,MACG,CAAAL,GAAA,CAAAH,SAAA,GAAAH,KAAA,CAAAa,eAAA;IACP;MAEaR,WAAA,CAAAS,MAAe,CAAAX,SAAgB,GAAAQ,MAA2C,CAAAG,MAAA,CAAAX,SAAA;IACrF;EACA;AACF","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/use-store",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"src",
|
|
6
|
+
"types",
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "dist/cjs",
|
|
12
|
+
"module": "dist/esm",
|
|
13
|
+
"types": "./src",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/index.ts",
|
|
18
|
+
"react-native": "./dist/esm/index.native.js",
|
|
19
|
+
"browser": "./dist/esm/index.mjs",
|
|
20
|
+
"module": "./dist/esm/index.mjs",
|
|
21
|
+
"import": "./dist/esm/index.mjs",
|
|
22
|
+
"require": "./dist/cjs/index.cjs",
|
|
23
|
+
"default": "./dist/esm/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "hanzo-gui-build --skip-types",
|
|
31
|
+
"watch": "hanzo-gui-build --skip-types --watch",
|
|
32
|
+
"clean": "hanzo-gui-build clean",
|
|
33
|
+
"clean:build": "hanzo-gui-build clean:build"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@hanzogui/simple-hash": "workspace:*"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@hanzogui/build": "workspace:*",
|
|
40
|
+
"@testing-library/react": "^16.1.0",
|
|
41
|
+
"react": ">=19",
|
|
42
|
+
"vitest": "4.0.4"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": ">=19"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const isEqualSubsetShallow = (
|
|
2
|
+
a: any,
|
|
3
|
+
b: any,
|
|
4
|
+
opts?: { keyComparators?: { [key: string]: (a: any, b: any) => boolean } }
|
|
5
|
+
) => {
|
|
6
|
+
if (b == null || a == null) return a === b
|
|
7
|
+
if (typeof a !== typeof b) return false
|
|
8
|
+
if (typeof b === 'object') {
|
|
9
|
+
for (const key in b) {
|
|
10
|
+
const compare = opts?.keyComparators?.[key]
|
|
11
|
+
if (compare ? !compare(a[key], b[key]) : b[key] !== a[key]) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
return a === b
|
|
18
|
+
}
|