@hanzogui/use-store 8.3.0 → 8.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/comparators.js +21 -0
- package/dist/cjs/comparators.js.map +1 -0
- package/dist/cjs/configureUseStore.js +9 -0
- package/dist/cjs/configureUseStore.js.map +1 -0
- package/dist/cjs/constants.js +9 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/decorators.js +10 -0
- package/dist/cjs/decorators.js.map +1 -0
- package/dist/cjs/helpers.js +50 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces.js +3 -0
- package/dist/cjs/interfaces.js.map +1 -0
- package/dist/cjs/observe.js +141 -0
- package/dist/cjs/observe.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/useStore.js +574 -0
- package/dist/cjs/useStore.js.map +1 -0
- package/dist/cjs/useStoreDebug.js +41 -0
- package/dist/cjs/useStoreDebug.js.map +1 -0
- package/dist/esm/comparators.js +17 -0
- package/dist/esm/comparators.js.map +1 -0
- package/dist/esm/configureUseStore.js +5 -0
- package/dist/esm/configureUseStore.js.map +1 -0
- package/dist/esm/constants.js +6 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/decorators.js +7 -0
- package/dist/esm/decorators.js.map +1 -0
- package/dist/esm/helpers.js +42 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.js +13 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.js +2 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/esm/observe.js +136 -0
- package/dist/esm/observe.js.map +1 -0
- package/dist/esm/useStore.js +556 -0
- package/dist/esm/useStore.js.map +1 -0
- package/dist/esm/useStoreDebug.js +34 -0
- package/dist/esm/useStoreDebug.js.map +1 -0
- package/package.json +18 -18
- package/src/configureUseStore.tsx +1 -1
- package/src/helpers.tsx +1 -1
- package/src/index.ts +7 -7
- package/src/interfaces.tsx +1 -1
- package/src/observe.tsx +4 -4
- package/src/useStore.tsx +6 -6
- package/src/useStoreDebug.tsx +1 -1
- 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/helpers.d.ts +11 -0
- package/types/helpers.d.ts.map +1 -0
- package/types/index.d.ts +12 -0
- package/types/index.d.ts.map +1 -0
- package/types/interfaces.d.ts +43 -0
- package/types/interfaces.d.ts.map +1 -0
- package/types/observe.d.ts +6 -0
- package/types/observe.d.ts.map +1 -0
- package/types/useStore.d.ts +26 -0
- package/types/useStore.d.ts.map +1 -0
- package/types/useStoreDebug.d.ts +7 -0
- package/types/useStoreDebug.d.ts.map +1 -0
- package/dist/cjs/comparators.cjs +0 -41
- package/dist/cjs/comparators.native.js +0 -50
- package/dist/cjs/comparators.native.js.map +0 -1
- package/dist/cjs/configureUseStore.cjs +0 -32
- package/dist/cjs/configureUseStore.native.js +0 -35
- package/dist/cjs/configureUseStore.native.js.map +0 -1
- package/dist/cjs/constants.cjs +0 -33
- package/dist/cjs/constants.native.js +0 -36
- package/dist/cjs/constants.native.js.map +0 -1
- package/dist/cjs/decorators.cjs +0 -33
- package/dist/cjs/decorators.native.js +0 -36
- package/dist/cjs/decorators.native.js.map +0 -1
- package/dist/cjs/helpers.cjs +0 -62
- package/dist/cjs/helpers.native.js +0 -71
- package/dist/cjs/helpers.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -43
- package/dist/cjs/index.native.js +0 -65
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/cjs/interfaces.cjs +0 -18
- package/dist/cjs/interfaces.native.js +0 -21
- package/dist/cjs/interfaces.native.js.map +0 -1
- package/dist/cjs/observe.cjs +0 -166
- package/dist/cjs/observe.native.js +0 -234
- package/dist/cjs/observe.native.js.map +0 -1
- package/dist/cjs/useStore.cjs +0 -467
- package/dist/cjs/useStore.native.js +0 -608
- package/dist/cjs/useStore.native.js.map +0 -1
- package/dist/cjs/useStoreDebug.cjs +0 -67
- package/dist/cjs/useStoreDebug.native.js +0 -71
- package/dist/cjs/useStoreDebug.native.js.map +0 -1
- package/dist/esm/comparators.mjs +0 -16
- package/dist/esm/comparators.mjs.map +0 -1
- package/dist/esm/comparators.native.js +0 -22
- package/dist/esm/comparators.native.js.map +0 -1
- package/dist/esm/configureUseStore.mjs +0 -6
- package/dist/esm/configureUseStore.mjs.map +0 -1
- package/dist/esm/configureUseStore.native.js +0 -6
- package/dist/esm/configureUseStore.native.js.map +0 -1
- package/dist/esm/constants.mjs +0 -7
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/constants.native.js +0 -7
- package/dist/esm/constants.native.js.map +0 -1
- package/dist/esm/decorators.mjs +0 -8
- package/dist/esm/decorators.mjs.map +0 -1
- package/dist/esm/decorators.native.js +0 -8
- package/dist/esm/decorators.native.js.map +0 -1
- package/dist/esm/helpers.mjs +0 -31
- package/dist/esm/helpers.mjs.map +0 -1
- package/dist/esm/helpers.native.js +0 -37
- package/dist/esm/helpers.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -34
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/interfaces.mjs +0 -2
- package/dist/esm/interfaces.mjs.map +0 -1
- package/dist/esm/interfaces.native.js +0 -2
- package/dist/esm/interfaces.native.js.map +0 -1
- package/dist/esm/observe.mjs +0 -129
- package/dist/esm/observe.mjs.map +0 -1
- package/dist/esm/observe.native.js +0 -194
- package/dist/esm/observe.native.js.map +0 -1
- package/dist/esm/useStore.mjs +0 -415
- package/dist/esm/useStore.mjs.map +0 -1
- package/dist/esm/useStore.native.js +0 -553
- package/dist/esm/useStore.native.js.map +0 -1
- package/dist/esm/useStoreDebug.mjs +0 -27
- package/dist/esm/useStoreDebug.mjs.map +0 -1
- package/dist/esm/useStoreDebug.native.js +0 -28
- package/dist/esm/useStoreDebug.native.js.map +0 -1
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { isEqualSubsetShallow } from "./comparators.native.js";
|
|
3
|
-
import { UNWRAP_PROXY } from "./constants.native.js";
|
|
4
|
-
import { trackStoresAccess } from "./useStore.native.js";
|
|
5
|
-
var logUpdate = process.env.NODE_ENV === "development" ? function (fn, stores, last, next) {
|
|
6
|
-
var getStoreLogName = function (store) {
|
|
7
|
-
var _store_props;
|
|
8
|
-
var _store_UNWRAP_PROXY;
|
|
9
|
-
var str = (_store_UNWRAP_PROXY = store[UNWRAP_PROXY]) !== null && _store_UNWRAP_PROXY !== void 0 ? _store_UNWRAP_PROXY : store;
|
|
10
|
-
return `${str.constructor.name}${((_store_props = store.props) === null || _store_props === void 0 ? void 0 : _store_props.id) ? `:${store.props.id}` : ""}`;
|
|
11
|
-
};
|
|
12
|
-
var storeNames = stores.map(getStoreLogName).join(", ");
|
|
13
|
-
var name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
|
|
14
|
-
console.groupCollapsed(name, "color: tomato;");
|
|
15
|
-
console.groupCollapsed("trace >");
|
|
16
|
-
console.trace();
|
|
17
|
-
console.groupEnd();
|
|
18
|
-
console.info(" next", next);
|
|
19
|
-
console.groupEnd();
|
|
20
|
-
} : null;
|
|
21
|
-
function observe(fn) {
|
|
22
|
-
var prev = getObserverValueAndStoresAccessed(fn);
|
|
23
|
-
var disposeValue = null;
|
|
24
|
-
var subscribe = function () {
|
|
25
|
-
var stores = [...prev.storeInfos];
|
|
26
|
-
return subscribeToStores(stores, function () {
|
|
27
|
-
disposeValue === null || disposeValue === void 0 ? void 0 : disposeValue();
|
|
28
|
-
var next = getObserverValueAndStoresAccessed(fn);
|
|
29
|
-
if (typeof next.value === "function") {
|
|
30
|
-
disposeValue = next.value;
|
|
31
|
-
if (process.env.NODE_ENV === "development") {
|
|
32
|
-
logUpdate(fn, [...next.storeInfos], "(fn)", "(fn)");
|
|
33
|
-
}
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (isEqualSubsetShallow(prev.storeInfos, next.storeInfos) && isEqualSubsetShallow(prev.value, next.value)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (process.env.NODE_ENV === "development") {
|
|
40
|
-
logUpdate(fn, [...next.storeInfos], prev.value, next.value);
|
|
41
|
-
}
|
|
42
|
-
prev = next;
|
|
43
|
-
dispose();
|
|
44
|
-
dispose = subscribe();
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
var dispose = subscribe();
|
|
48
|
-
return {
|
|
49
|
-
dispose: function () {
|
|
50
|
-
dispose();
|
|
51
|
-
disposeValue === null || disposeValue === void 0 ? void 0 : disposeValue();
|
|
52
|
-
},
|
|
53
|
-
getValue: function () {
|
|
54
|
-
return prev.value;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function useObserve(fn) {
|
|
59
|
-
var [state, setState] = React.useState(function () {
|
|
60
|
-
return getObserverValueAndStoresAccessed(fn);
|
|
61
|
-
});
|
|
62
|
-
React.useEffect(function () {
|
|
63
|
-
var dispose;
|
|
64
|
-
var unsub = subscribeToStores([...state.storeInfos], function () {
|
|
65
|
-
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
66
|
-
var next = getObserverValueAndStoresAccessed(fn);
|
|
67
|
-
var nextStoreInfos = [...next.storeInfos];
|
|
68
|
-
var prevStoreInfos = [...state.storeInfos];
|
|
69
|
-
if (typeof next.value === "function") {
|
|
70
|
-
if (process.env.NODE_ENV === "development") {
|
|
71
|
-
logUpdate(fn, nextStoreInfos, "(fn)", "(fn)");
|
|
72
|
-
}
|
|
73
|
-
dispose = next.value;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
setState(function (prev) {
|
|
77
|
-
if (isEqualSubsetShallow(prevStoreInfos, nextStoreInfos) && isEqualSubsetShallow(prev.value, next.value)) {
|
|
78
|
-
return prev;
|
|
79
|
-
}
|
|
80
|
-
if (process.env.NODE_ENV === "development") {
|
|
81
|
-
logUpdate(fn, nextStoreInfos, prev.value, next.value);
|
|
82
|
-
}
|
|
83
|
-
return next;
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
return function () {
|
|
87
|
-
unsub();
|
|
88
|
-
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
89
|
-
};
|
|
90
|
-
}, [[...state.storeInfos].map(function (i) {
|
|
91
|
-
return i.uid;
|
|
92
|
-
}).join(",")]);
|
|
93
|
-
return state.value;
|
|
94
|
-
}
|
|
95
|
-
function getObserverValueAndStoresAccessed(selector) {
|
|
96
|
-
var storeInfos = /* @__PURE__ */new Set();
|
|
97
|
-
var dispose = trackStoresAccess(function (storeInfo) {
|
|
98
|
-
storeInfos.add(storeInfo);
|
|
99
|
-
});
|
|
100
|
-
var value = selector();
|
|
101
|
-
dispose();
|
|
102
|
-
return {
|
|
103
|
-
value,
|
|
104
|
-
storeInfos
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function subscribeToStores(storeInfos, onUpdate) {
|
|
108
|
-
var disposes = [];
|
|
109
|
-
var isUpdating = false;
|
|
110
|
-
var onUpdateDebouncedWithoutTracking = function () {
|
|
111
|
-
if (isUpdating) return;
|
|
112
|
-
isUpdating = true;
|
|
113
|
-
queueMicrotask(function () {
|
|
114
|
-
try {
|
|
115
|
-
var _iteratorNormalCompletion2 = true,
|
|
116
|
-
_didIteratorError2 = false,
|
|
117
|
-
_iteratorError2 = void 0;
|
|
118
|
-
try {
|
|
119
|
-
for (var _iterator2 = storeInfos[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
120
|
-
var storeInfo2 = _step2.value;
|
|
121
|
-
storeInfo2.disableTracking = true;
|
|
122
|
-
}
|
|
123
|
-
} catch (err) {
|
|
124
|
-
_didIteratorError2 = true;
|
|
125
|
-
_iteratorError2 = err;
|
|
126
|
-
} finally {
|
|
127
|
-
try {
|
|
128
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
129
|
-
_iterator2.return();
|
|
130
|
-
}
|
|
131
|
-
} finally {
|
|
132
|
-
if (_didIteratorError2) {
|
|
133
|
-
throw _iteratorError2;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
onUpdate();
|
|
138
|
-
} finally {
|
|
139
|
-
isUpdating = false;
|
|
140
|
-
var _iteratorNormalCompletion1 = true,
|
|
141
|
-
_didIteratorError1 = false,
|
|
142
|
-
_iteratorError1 = void 0;
|
|
143
|
-
try {
|
|
144
|
-
for (var _iterator1 = storeInfos[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
145
|
-
var storeInfo1 = _step1.value;
|
|
146
|
-
storeInfo1.disableTracking = false;
|
|
147
|
-
}
|
|
148
|
-
} catch (err) {
|
|
149
|
-
_didIteratorError1 = true;
|
|
150
|
-
_iteratorError1 = err;
|
|
151
|
-
} finally {
|
|
152
|
-
try {
|
|
153
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
154
|
-
_iterator1.return();
|
|
155
|
-
}
|
|
156
|
-
} finally {
|
|
157
|
-
if (_didIteratorError1) {
|
|
158
|
-
throw _iteratorError1;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
var _iteratorNormalCompletion = true,
|
|
166
|
-
_didIteratorError = false,
|
|
167
|
-
_iteratorError = void 0;
|
|
168
|
-
try {
|
|
169
|
-
for (var _iterator = storeInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
170
|
-
var storeInfo = _step.value;
|
|
171
|
-
disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
|
|
172
|
-
}
|
|
173
|
-
} catch (err) {
|
|
174
|
-
_didIteratorError = true;
|
|
175
|
-
_iteratorError = err;
|
|
176
|
-
} finally {
|
|
177
|
-
try {
|
|
178
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
179
|
-
_iterator.return();
|
|
180
|
-
}
|
|
181
|
-
} finally {
|
|
182
|
-
if (_didIteratorError) {
|
|
183
|
-
throw _iteratorError;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return function () {
|
|
188
|
-
disposes.forEach(function (x) {
|
|
189
|
-
return x();
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
export { observe, useObserve };
|
|
194
|
-
//# sourceMappingURL=observe.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","isEqualSubsetShallow","UNWRAP_PROXY","trackStoresAccess","logUpdate","process","env","NODE_ENV","fn","stores","last","next","getStoreLogName","store","_store_props","_store_UNWRAP_PROXY","str","constructor","name","props","id","storeNames","map","join","console","groupCollapsed","trace","groupEnd","info","observe","prev","getObserverValueAndStoresAccessed","disposeValue","subscribe","storeInfos","subscribeToStores","value","dispose","getValue","useObserve","state","setState","useState","useEffect","unsub","nextStoreInfos","prevStoreInfos","i","uid","selector","Set","storeInfo","add","onUpdate","disposes","isUpdating","onUpdateDebouncedWithoutTracking"],"sources":["../../src/observe.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAElB,SAASC,oBAAA,QAA4B;AACrC,SAASC,YAAA,QAAoB;AAE7B,SAASC,iBAAA,QAAyB;AAElC,IAAAC,SAAM,GAAAC,OACJ,CAAAC,GAAQ,CAAAC,QAAI,kBAAa,aACXC,EAAA,EAAAC,MA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setShallow } from "./comparators.mjs";
|
|
3
|
-
import { configureOpts } from "./configureUseStore.mjs";
|
|
4
|
-
import { UNWRAP_PROXY, defaultOptions } from "./constants.mjs";
|
|
5
|
-
import { UNWRAP_STORE_INFO, cache, getStoreDescriptors, getStoreUid, simpleStr } from "./helpers.mjs";
|
|
6
|
-
import { DebugStores, shouldDebug, useCurrentComponent } from "./useStoreDebug.mjs";
|
|
7
|
-
const idFn = _ => _;
|
|
8
|
-
function useStore(StoreKlass, props, options = defaultOptions) {
|
|
9
|
-
return useStoreFromInfo(getOrCreateStoreInfo(StoreKlass, props, options), options.selector, options);
|
|
10
|
-
}
|
|
11
|
-
function useStoreDebug(StoreKlass, props) {
|
|
12
|
-
return useStore(StoreKlass, props, {
|
|
13
|
-
debug: true
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function createStore(StoreKlass, props, options) {
|
|
17
|
-
return getOrCreateStoreInfo(StoreKlass, props, options)?.store;
|
|
18
|
-
}
|
|
19
|
-
function useGlobalStore(instance, debug) {
|
|
20
|
-
const store = instance[UNWRAP_PROXY];
|
|
21
|
-
const uid = getStoreUid(store.constructor, store.props);
|
|
22
|
-
const info = cache.get(uid);
|
|
23
|
-
if (!info) throw new Error(`This store not created using createStore()`);
|
|
24
|
-
return useStoreFromInfo(info, void 0, {
|
|
25
|
-
debug
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function useGlobalStoreSelector(instance, selector, debug) {
|
|
29
|
-
const store = instance[UNWRAP_PROXY];
|
|
30
|
-
const uid = getStoreUid(store.constructor, store.props);
|
|
31
|
-
const info = cache.get(uid);
|
|
32
|
-
if (!info) throw new Error(`This store not created using createStore()`);
|
|
33
|
-
return useStoreFromInfo(info, selector, {
|
|
34
|
-
debug
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function createUseStore(StoreKlass) {
|
|
38
|
-
return (props, options) => useStore(StoreKlass, props, options);
|
|
39
|
-
}
|
|
40
|
-
function createUseStoreSelector(StoreKlass, selector) {
|
|
41
|
-
return props => {
|
|
42
|
-
return useStore(StoreKlass, props, {
|
|
43
|
-
selector
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function useStoreSelector(StoreKlass, selector, props) {
|
|
48
|
-
return useStore(StoreKlass, props, {
|
|
49
|
-
selector
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const storeAccessTrackers = /* @__PURE__ */new Set();
|
|
53
|
-
function trackStoresAccess(cb) {
|
|
54
|
-
storeAccessTrackers.add(cb);
|
|
55
|
-
return () => {
|
|
56
|
-
storeAccessTrackers.delete(cb);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function getStore(StoreKlass, props) {
|
|
60
|
-
return getStoreInfo(StoreKlass, props)?.store;
|
|
61
|
-
}
|
|
62
|
-
function getOrCreateStore(StoreKlass, props) {
|
|
63
|
-
return getOrCreateStoreInfo(StoreKlass, props, {
|
|
64
|
-
refuseCreation: false
|
|
65
|
-
})?.store;
|
|
66
|
-
}
|
|
67
|
-
function getStoreInfo(StoreKlass, props) {
|
|
68
|
-
return getOrCreateStoreInfo(StoreKlass, props, {
|
|
69
|
-
refuseCreation: true
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
const onCreateListeners = /* @__PURE__ */new Set();
|
|
73
|
-
function onCreateStore(cb) {
|
|
74
|
-
onCreateListeners.add(cb);
|
|
75
|
-
return () => {
|
|
76
|
-
onCreateListeners.delete(cb);
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function getOrCreateStoreInfo(StoreKlass, props, options, propsKeyCalculated) {
|
|
80
|
-
if (!StoreKlass) return null;
|
|
81
|
-
const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
|
|
82
|
-
if (!options?.avoidCache && cache.has(uid)) return cache.get(uid);
|
|
83
|
-
if (options?.refuseCreation) throw new Error(`No store exists (${StoreKlass.name}) with props: ${props}`);
|
|
84
|
-
const storeInstance = new StoreKlass(props);
|
|
85
|
-
storeInstance.props = props;
|
|
86
|
-
const getters = {};
|
|
87
|
-
const actions = {};
|
|
88
|
-
const stateKeys = /* @__PURE__ */new Set();
|
|
89
|
-
const descriptors = getStoreDescriptors(storeInstance);
|
|
90
|
-
for (const key in descriptors) {
|
|
91
|
-
const descriptor = descriptors[key];
|
|
92
|
-
if (typeof descriptor.value === "function") actions[key] = descriptor.value;else if (typeof descriptor.get === "function") getters[key] = descriptor.get;else if (key !== "props" && key[0] !== "_") stateKeys.add(key);
|
|
93
|
-
}
|
|
94
|
-
const keyComparators = storeInstance["_comparators"];
|
|
95
|
-
const listeners = /* @__PURE__ */new Set();
|
|
96
|
-
const storeInfo = {
|
|
97
|
-
uid,
|
|
98
|
-
keyComparators,
|
|
99
|
-
storeInstance,
|
|
100
|
-
getters,
|
|
101
|
-
stateKeys,
|
|
102
|
-
props,
|
|
103
|
-
actions,
|
|
104
|
-
debug: options?.debug,
|
|
105
|
-
disableTracking: false,
|
|
106
|
-
gettersState: {
|
|
107
|
-
getCache: /* @__PURE__ */new Map(),
|
|
108
|
-
depsToGetter: /* @__PURE__ */new Map(),
|
|
109
|
-
curGetKeys: /* @__PURE__ */new Set(),
|
|
110
|
-
isGetting: false
|
|
111
|
-
},
|
|
112
|
-
listeners,
|
|
113
|
-
trackers: /* @__PURE__ */new Set(),
|
|
114
|
-
version: 0,
|
|
115
|
-
subscribe: onChanged => {
|
|
116
|
-
listeners.add(onChanged);
|
|
117
|
-
return () => {
|
|
118
|
-
listeners.delete(onChanged);
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
triggerUpdate: () => {
|
|
122
|
-
storeInfo.version = (storeInfo.version + 1) % Number.MAX_SAFE_INTEGER;
|
|
123
|
-
for (const cb of listeners) cb();
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
const store = createProxiedStore(storeInfo);
|
|
127
|
-
if (process.env.NODE_ENV === "development") allStores[StoreKlass.name + uid] = store;
|
|
128
|
-
store.mount?.();
|
|
129
|
-
storeInfo.store = store;
|
|
130
|
-
const result = storeInfo;
|
|
131
|
-
cache.set(uid, result);
|
|
132
|
-
onCreateListeners.forEach(cb => cb(result));
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
const allStores = {};
|
|
136
|
-
if (process.env.NODE_ENV === "development") globalThis["Store"] ||= allStores;
|
|
137
|
-
const emptyObj = {};
|
|
138
|
-
const selectKeys = (obj, keys) => {
|
|
139
|
-
if (!keys.length) return emptyObj;
|
|
140
|
-
const res = {};
|
|
141
|
-
for (const key of keys) res[key] = obj[key];
|
|
142
|
-
return res;
|
|
143
|
-
};
|
|
144
|
-
let isInReaction = false;
|
|
145
|
-
const setIsInReaction = val => {
|
|
146
|
-
isInReaction = val;
|
|
147
|
-
};
|
|
148
|
-
function useStoreFromInfo(info, userSelector, options) {
|
|
149
|
-
const store = info?.store;
|
|
150
|
-
const internal = React.useRef(void 0);
|
|
151
|
-
const component = useCurrentComponent();
|
|
152
|
-
if (!internal.current) internal.current = {
|
|
153
|
-
component,
|
|
154
|
-
tracked: /* @__PURE__ */new Set(),
|
|
155
|
-
last: null,
|
|
156
|
-
lastKeys: null
|
|
157
|
-
};
|
|
158
|
-
const curInternal = internal.current;
|
|
159
|
-
const shouldPrintDebug = options?.debug;
|
|
160
|
-
const getSnapshot = React.useCallback(() => {
|
|
161
|
-
if (!info || !store) return;
|
|
162
|
-
const curInternal2 = internal.current;
|
|
163
|
-
const isTracking = curInternal2.tracked.size;
|
|
164
|
-
const keys = [...(!isTracking ? info.stateKeys : curInternal2.tracked)];
|
|
165
|
-
const nextKeys = `${info.version}${keys.join("")}${userSelector || ""}`;
|
|
166
|
-
const lastKeys = curInternal2.lastKeys;
|
|
167
|
-
if (nextKeys === curInternal2.lastKeys) return curInternal2.last;
|
|
168
|
-
curInternal2.lastKeys = nextKeys;
|
|
169
|
-
let snap;
|
|
170
|
-
info.disableTracking = true;
|
|
171
|
-
const last = curInternal2.last;
|
|
172
|
-
if (userSelector) snap = userSelector(store);else snap = selectKeys(store, keys);
|
|
173
|
-
info.disableTracking = false;
|
|
174
|
-
const isUnchanged = !userSelector && !isTracking && last || typeof last !== "undefined" && isEqualSubsetShallow(last, snap, {
|
|
175
|
-
keyComparators: info.keyComparators
|
|
176
|
-
});
|
|
177
|
-
if (shouldPrintDebug) console.info("🌑 getSnapshot", {
|
|
178
|
-
storeState: selectKeys(store, Object.keys(store)),
|
|
179
|
-
userSelector,
|
|
180
|
-
info,
|
|
181
|
-
isUnchanged,
|
|
182
|
-
component,
|
|
183
|
-
keys,
|
|
184
|
-
last,
|
|
185
|
-
snap,
|
|
186
|
-
curInternal: curInternal2,
|
|
187
|
-
nextKeys,
|
|
188
|
-
lastKeys
|
|
189
|
-
});
|
|
190
|
-
if (isUnchanged) return last;
|
|
191
|
-
curInternal2.last = snap;
|
|
192
|
-
return snap;
|
|
193
|
-
}, [store]);
|
|
194
|
-
const state = React.useSyncExternalStore(info?.subscribe || idFn, getSnapshot, getSnapshot);
|
|
195
|
-
if (!info || !store || !state) return state;
|
|
196
|
-
if (userSelector) return state;
|
|
197
|
-
return new Proxy(store, {
|
|
198
|
-
get(target, key) {
|
|
199
|
-
const curVal = Reflect.get(target, key);
|
|
200
|
-
if (isInReaction) return curVal;
|
|
201
|
-
const keyString = key;
|
|
202
|
-
if (info.stateKeys.has(keyString) || keyString in info.getters) {
|
|
203
|
-
if (shouldPrintDebug) console.info("👀 tracking", keyString);
|
|
204
|
-
curInternal.tracked.add(keyString);
|
|
205
|
-
}
|
|
206
|
-
if (Reflect.has(state, key)) return Reflect.get(state, key);
|
|
207
|
-
return curVal;
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
let setters = /* @__PURE__ */new Set();
|
|
212
|
-
const logStack = /* @__PURE__ */new Set();
|
|
213
|
-
function createProxiedStore(storeInfo) {
|
|
214
|
-
const {
|
|
215
|
-
actions,
|
|
216
|
-
storeInstance,
|
|
217
|
-
getters,
|
|
218
|
-
gettersState
|
|
219
|
-
} = storeInfo;
|
|
220
|
-
const {
|
|
221
|
-
getCache,
|
|
222
|
-
curGetKeys,
|
|
223
|
-
depsToGetter
|
|
224
|
-
} = gettersState;
|
|
225
|
-
const constr = storeInstance.constructor;
|
|
226
|
-
const shouldDebug2 = storeInfo.debug ?? DebugStores.has(constr);
|
|
227
|
-
let didSet = false;
|
|
228
|
-
const wrappedActions = {};
|
|
229
|
-
for (const key in actions) {
|
|
230
|
-
if (key === "subscribe") continue;
|
|
231
|
-
const actionFn = actions[key];
|
|
232
|
-
const isGetFn = key.startsWith("get");
|
|
233
|
-
wrappedActions[key] = function useStoreAction(...args) {
|
|
234
|
-
let res;
|
|
235
|
-
if (isGetFn || gettersState.isGetting) return Reflect.apply(actionFn, proxiedStore, args);
|
|
236
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("(debug) startAction", key);
|
|
237
|
-
res = Reflect.apply(actionFn, proxiedStore, args);
|
|
238
|
-
if (res instanceof Promise) return res.then(finishAction);
|
|
239
|
-
finishAction();
|
|
240
|
-
return res;
|
|
241
|
-
};
|
|
242
|
-
if (process.env.NODE_ENV === "development") {
|
|
243
|
-
let hashCode = function (str) {
|
|
244
|
-
let hash = 0;
|
|
245
|
-
for (let i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
246
|
-
return hash;
|
|
247
|
-
},
|
|
248
|
-
strColor = function (str) {
|
|
249
|
-
return `hsl(${hashCode(str) % 360}, 90%, 40%)`;
|
|
250
|
-
};
|
|
251
|
-
if (!key.startsWith("get") && !key.startsWith("_") && key !== "subscribe") {
|
|
252
|
-
const ogAction = wrappedActions[key];
|
|
253
|
-
wrappedActions[key] = new Proxy(ogAction, {
|
|
254
|
-
apply(target, thisArg, args) {
|
|
255
|
-
const isDebugging = shouldDebug2 || storeInfo.debug;
|
|
256
|
-
if (!(process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error"))) return Reflect.apply(target, thisArg, args);
|
|
257
|
-
setters = /* @__PURE__ */new Set();
|
|
258
|
-
const curSetters = setters;
|
|
259
|
-
const isTopLevelLogger = logStack.size == 0;
|
|
260
|
-
const logs = /* @__PURE__ */new Set();
|
|
261
|
-
logStack.add(logs);
|
|
262
|
-
let res;
|
|
263
|
-
const id = counter++;
|
|
264
|
-
try {
|
|
265
|
-
res = Reflect.apply(target, thisArg, args);
|
|
266
|
-
} catch (err) {
|
|
267
|
-
console.error("Error", err);
|
|
268
|
-
throw err;
|
|
269
|
-
} finally {
|
|
270
|
-
logStack.add("end");
|
|
271
|
-
const name = constr.name;
|
|
272
|
-
const color = strColor(name);
|
|
273
|
-
const simpleArgs = args.map(simpleStr);
|
|
274
|
-
logs.add([`%c \u{1F311} ${id} ${name.padStart(isTopLevelLogger ? 8 : 4)}%c.${key}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`, `color: ${color};`, "color: black;"]);
|
|
275
|
-
if (curSetters.size) curSetters.forEach(({
|
|
276
|
-
key: key2,
|
|
277
|
-
value
|
|
278
|
-
}) => {
|
|
279
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") logs.add([` SET ${key2} ${value}`, value]);else logs.add([` SET ${key2}`, value]);
|
|
280
|
-
});
|
|
281
|
-
if (isTopLevelLogger) {
|
|
282
|
-
let error = null;
|
|
283
|
-
try {
|
|
284
|
-
for (const item of logStack) {
|
|
285
|
-
if (item === "end") {
|
|
286
|
-
console.groupEnd();
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
const [head, ...rest] = item;
|
|
290
|
-
if (head) {
|
|
291
|
-
console.groupCollapsed(...head);
|
|
292
|
-
console.groupCollapsed("...");
|
|
293
|
-
console.info("args", args);
|
|
294
|
-
console.info("response", res);
|
|
295
|
-
console.groupCollapsed("trace");
|
|
296
|
-
console.trace();
|
|
297
|
-
console.groupEnd();
|
|
298
|
-
console.groupEnd();
|
|
299
|
-
for (const [name2, ...log] of rest) {
|
|
300
|
-
console.groupCollapsed(name2);
|
|
301
|
-
console.info(...log);
|
|
302
|
-
console.groupEnd();
|
|
303
|
-
}
|
|
304
|
-
} else console.info("Weird log", head, ...rest);
|
|
305
|
-
}
|
|
306
|
-
} catch (err) {
|
|
307
|
-
error = err;
|
|
308
|
-
}
|
|
309
|
-
for (const _ of logStack) console.groupEnd();
|
|
310
|
-
if (error) console.error(`error loggin`, error);
|
|
311
|
-
logStack.clear();
|
|
312
|
-
}
|
|
313
|
-
return res;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
const finishAction = val => {
|
|
321
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("(debug) finishAction", {
|
|
322
|
-
didSet
|
|
323
|
-
});
|
|
324
|
-
if (didSet) {
|
|
325
|
-
storeInfo.triggerUpdate();
|
|
326
|
-
didSet = false;
|
|
327
|
-
}
|
|
328
|
-
return val;
|
|
329
|
-
};
|
|
330
|
-
let isTriggering = false;
|
|
331
|
-
const proxiedStore = new Proxy(storeInstance, {
|
|
332
|
-
get(_, key) {
|
|
333
|
-
if (key in wrappedActions) return wrappedActions[key];
|
|
334
|
-
if (key in passThroughKeys) return Reflect.get(storeInstance, key);
|
|
335
|
-
if (key === UNWRAP_PROXY) return storeInstance;
|
|
336
|
-
if (key === UNWRAP_STORE_INFO) return storeInfo;
|
|
337
|
-
if (storeAccessTrackers.size) storeAccessTrackers.forEach(cb => cb(storeInfo));
|
|
338
|
-
if (typeof key !== "string") return Reflect.get(storeInstance, key);
|
|
339
|
-
if (!storeInfo.disableTracking) {
|
|
340
|
-
if (gettersState.isGetting) gettersState.curGetKeys.add(key);
|
|
341
|
-
}
|
|
342
|
-
if (key in getters) {
|
|
343
|
-
if (getCache.has(key)) return getCache.get(key);
|
|
344
|
-
curGetKeys.clear();
|
|
345
|
-
const isSubGetter = gettersState.isGetting;
|
|
346
|
-
gettersState.isGetting = true;
|
|
347
|
-
const res = getters[key].call(proxiedStore);
|
|
348
|
-
if (!isSubGetter) gettersState.isGetting = false;
|
|
349
|
-
for (const gk of curGetKeys) {
|
|
350
|
-
if (!depsToGetter.has(gk)) depsToGetter.set(gk, /* @__PURE__ */new Set());
|
|
351
|
-
depsToGetter.get(gk).add(key);
|
|
352
|
-
}
|
|
353
|
-
getCache.set(key, res);
|
|
354
|
-
return res;
|
|
355
|
-
}
|
|
356
|
-
return Reflect.get(storeInstance, key);
|
|
357
|
-
},
|
|
358
|
-
set(target, key, value, receiver) {
|
|
359
|
-
const cur = Reflect.get(target, key);
|
|
360
|
-
const res = Reflect.set(target, key, value, receiver);
|
|
361
|
-
if (res && cur !== value) {
|
|
362
|
-
if (typeof key === "string") {
|
|
363
|
-
clearGetterCache(key);
|
|
364
|
-
if (shouldDebug2) {
|
|
365
|
-
setters.add({
|
|
366
|
-
key,
|
|
367
|
-
value
|
|
368
|
-
});
|
|
369
|
-
if (getShouldDebug(storeInfo)) console.info("(debug) SET", res, key, value);
|
|
370
|
-
}
|
|
371
|
-
if (process.env.NODE_ENV === "development" && shouldDebug2) console.info("SET...", {
|
|
372
|
-
key,
|
|
373
|
-
value
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
if (!isTriggering) {
|
|
377
|
-
isTriggering = true;
|
|
378
|
-
waitForEventLoop(() => {
|
|
379
|
-
storeInfo.triggerUpdate();
|
|
380
|
-
isTriggering = false;
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return res;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
function clearGetterCache(setKey) {
|
|
388
|
-
const parentGetters = depsToGetter.get(setKey);
|
|
389
|
-
getCache.delete(setKey);
|
|
390
|
-
if (!parentGetters) return;
|
|
391
|
-
for (const gk of parentGetters) {
|
|
392
|
-
getCache.delete(gk);
|
|
393
|
-
if (depsToGetter.has(gk)) clearGetterCache(gk);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return proxiedStore;
|
|
397
|
-
}
|
|
398
|
-
const waitForEventLoop = process.env.NODE_ENV === "test" || false ? cb => cb() : queueMicrotask;
|
|
399
|
-
let counter = 0;
|
|
400
|
-
const passThroughKeys = {
|
|
401
|
-
subscribe: true,
|
|
402
|
-
_version: true,
|
|
403
|
-
_trackers: true,
|
|
404
|
-
$$typeof: true,
|
|
405
|
-
_listeners: true,
|
|
406
|
-
_enableTracking: true
|
|
407
|
-
};
|
|
408
|
-
function getShouldDebug(storeInfo) {
|
|
409
|
-
const info = {
|
|
410
|
-
storeInstance: storeInfo.store
|
|
411
|
-
};
|
|
412
|
-
return [...storeInfo.trackers].some(tracker => tracker.component && shouldDebug(tracker.component, info));
|
|
413
|
-
}
|
|
414
|
-
export { allStores, createStore, createUseStore, createUseStoreSelector, getOrCreateStore, getStore, getStoreInfo, onCreateStore, setIsInReaction, trackStoresAccess, useGlobalStore, useGlobalStoreSelector, useStore, useStoreDebug, useStoreSelector };
|
|
415
|
-
//# sourceMappingURL=useStore.mjs.map
|