@tamagui/use-store 1.26.0 → 1.26.1
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/package.json +2 -5
- package/dist/esm/Store.mjs +0 -69
- package/dist/esm/Store.mjs.map +0 -6
- package/dist/esm/comparators.mjs +0 -21
- package/dist/esm/comparators.mjs.map +0 -6
- package/dist/esm/configureUseStore.mjs +0 -9
- package/dist/esm/configureUseStore.mjs.map +0 -6
- package/dist/esm/constants.mjs +0 -10
- package/dist/esm/constants.mjs.map +0 -6
- package/dist/esm/decorators.mjs +0 -10
- package/dist/esm/decorators.mjs.map +0 -6
- package/dist/esm/helpers.mjs +0 -70
- package/dist/esm/helpers.mjs.map +0 -6
- package/dist/esm/index.mjs +0 -14
- package/dist/esm/index.mjs.map +0 -6
- package/dist/esm/interfaces.mjs +0 -1
- package/dist/esm/interfaces.mjs.map +0 -6
- package/dist/esm/reaction.mjs +0 -53
- package/dist/esm/reaction.mjs.map +0 -6
- package/dist/esm/selector.mjs +0 -114
- package/dist/esm/selector.mjs.map +0 -6
- package/dist/esm/useAsyncExternalStore.mjs +0 -16
- package/dist/esm/useAsyncExternalStore.mjs.map +0 -6
- package/dist/esm/useStore.mjs +0 -524
- package/dist/esm/useStore.mjs.map +0 -6
- package/dist/esm/useStoreDebug.mjs +0 -35
- package/dist/esm/useStoreDebug.mjs.map +0 -6
- package/types/fastCompare.d.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-store",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.1",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -26,11 +26,8 @@
|
|
|
26
26
|
"require": "./dist/cjs/index.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"@tamagui/web": "1.26.0"
|
|
31
|
-
},
|
|
32
29
|
"devDependencies": {
|
|
33
|
-
"@tamagui/build": "1.26.
|
|
30
|
+
"@tamagui/build": "1.26.1",
|
|
34
31
|
"@testing-library/react": "^13.4.0",
|
|
35
32
|
"react": "^18.2.0",
|
|
36
33
|
"vitest": "^0.26.3"
|
package/dist/esm/Store.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { UNWRAP_PROXY } from "./constants";
|
|
2
|
-
import { shouldDebug } from "./useStoreDebug";
|
|
3
|
-
const TRIGGER_UPDATE = Symbol();
|
|
4
|
-
const ADD_TRACKER = Symbol();
|
|
5
|
-
const TRACK = Symbol();
|
|
6
|
-
const SHOULD_DEBUG = Symbol();
|
|
7
|
-
const disableTracking = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
const setDisableStoreTracking = (storeInstance, val) => {
|
|
9
|
-
const store = storeInstance[UNWRAP_PROXY] ?? storeInstance;
|
|
10
|
-
disableTracking.set(store, val);
|
|
11
|
-
};
|
|
12
|
-
class Store {
|
|
13
|
-
constructor(props) {
|
|
14
|
-
this.props = props;
|
|
15
|
-
this._listeners = /* @__PURE__ */ new Set();
|
|
16
|
-
this._trackers = /* @__PURE__ */ new Set();
|
|
17
|
-
this._version = 0;
|
|
18
|
-
this.subscribe = (onChanged) => {
|
|
19
|
-
this._listeners.add(onChanged);
|
|
20
|
-
return () => {
|
|
21
|
-
this._listeners.delete(onChanged);
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
[TRIGGER_UPDATE]() {
|
|
26
|
-
this._version = (this._version + 1) % Number.MAX_SAFE_INTEGER;
|
|
27
|
-
for (const cb of this._listeners) {
|
|
28
|
-
cb();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
[ADD_TRACKER](tracker) {
|
|
32
|
-
this._trackers.add(tracker);
|
|
33
|
-
return () => {
|
|
34
|
-
this._trackers.delete(tracker);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
[TRACK](key, debug) {
|
|
38
|
-
if (key[0] === "_" || key[0] === "$" || key === "props" || key === "toJSON") {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (debug) {
|
|
42
|
-
console.log("(debug) CHECK TRACKERS FOR", key);
|
|
43
|
-
}
|
|
44
|
-
for (const tracker of this._trackers) {
|
|
45
|
-
if (tracker.isTracking) {
|
|
46
|
-
tracker.tracked.add(key);
|
|
47
|
-
if (debug) {
|
|
48
|
-
console.log("(debug) TRACK", key, tracker);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
[SHOULD_DEBUG]() {
|
|
54
|
-
const info = { storeInstance: this };
|
|
55
|
-
return [...this._trackers].some(
|
|
56
|
-
(tracker) => tracker.component && shouldDebug(tracker.component, info)
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
61
|
-
ADD_TRACKER,
|
|
62
|
-
SHOULD_DEBUG,
|
|
63
|
-
Store,
|
|
64
|
-
TRACK,
|
|
65
|
-
TRIGGER_UPDATE,
|
|
66
|
-
disableTracking,
|
|
67
|
-
setDisableStoreTracking
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=Store.mjs.map
|
package/dist/esm/Store.mjs.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/Store.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAErB,MAAM,iBAAiB,OAAO;AAC9B,MAAM,cAAc,OAAO;AAC3B,MAAM,QAAQ,OAAO;AACrB,MAAM,eAAe,OAAO;AAY5B,MAAM,kBAAkB,oBAAI,QAAQ;AAEpC,MAAM,0BAA0B,CAAC,eAAoB,QAAiB;AAC3E,QAAM,QAAQ,cAAc,YAAY,KAAK;AAC7C,kBAAgB,IAAI,OAA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 -1,21 +0,0 @@
|
|
|
1
|
-
const isEqualSubsetShallow = (a, b, opts) => {
|
|
2
|
-
var _a;
|
|
3
|
-
if (b == null || a == null)
|
|
4
|
-
return a === b;
|
|
5
|
-
if (typeof a !== typeof b)
|
|
6
|
-
return false;
|
|
7
|
-
if (typeof b === "object") {
|
|
8
|
-
for (const key in b) {
|
|
9
|
-
const compare = (_a = opts == null ? void 0 : opts.keyComparators) == null ? void 0 : _a[key];
|
|
10
|
-
if (compare ? !compare(a[key], b[key]) : b[key] !== a[key]) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return a === b;
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
isEqualSubsetShallow
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=comparators.mjs.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/comparators.tsx"],
|
|
4
|
-
"mappings": "AAAO,MAAM,uBAAuB,CAClC,GACA,GACA,SACG;AAJL;AAKE,MAAI,KAAK,QAAQ,KAAK;AAAM,WAAO,MAAM;AACzC,MAAI,OAAO,MAAM,OAAO;AAAG,WAAO;AAClC,MAAI,OAAO,MAAM,UAAU;AACzB,eAAW,OAAO,GAAG;AACnB,YAAM,WAAU,kCAAM,mBAAN,mBAAuB;AACvC,UAAI,UAAU,CAAC,QAAQ,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO,MAAM;AACf;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/esm/constants.mjs
DELETED
package/dist/esm/decorators.mjs
DELETED
package/dist/esm/helpers.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useRef } from "react";
|
|
2
|
-
const wkm = /* @__PURE__ */ new WeakMap();
|
|
3
|
-
const weakKey = (obj, prefix = "") => {
|
|
4
|
-
if (wkm.has(obj))
|
|
5
|
-
return wkm.get(obj);
|
|
6
|
-
const key = `${prefix}-${Math.random()}`;
|
|
7
|
-
wkm.set(obj, key);
|
|
8
|
-
return key;
|
|
9
|
-
};
|
|
10
|
-
function getStoreUid(Constructor, props) {
|
|
11
|
-
const storeName = process.env.NODE_ENV === "development" ? Constructor.name : weakKey(Constructor);
|
|
12
|
-
return `${storeName}${!props ? "" : typeof props === "string" ? props : getKey(props)}`;
|
|
13
|
-
}
|
|
14
|
-
const UNWRAP_STORE_INFO = Symbol("UNWRAP_STORE_INFO");
|
|
15
|
-
const cache = /* @__PURE__ */ new Map();
|
|
16
|
-
function getStoreDescriptors(storeInstance) {
|
|
17
|
-
const proto = Object.getPrototypeOf(storeInstance);
|
|
18
|
-
const instanceDescriptors = Object.getOwnPropertyDescriptors(storeInstance);
|
|
19
|
-
const protoDescriptors = Object.getOwnPropertyDescriptors(proto);
|
|
20
|
-
const descriptors = {
|
|
21
|
-
...protoDescriptors,
|
|
22
|
-
...instanceDescriptors
|
|
23
|
-
};
|
|
24
|
-
delete descriptors.constructor;
|
|
25
|
-
return descriptors;
|
|
26
|
-
}
|
|
27
|
-
function get(_, b) {
|
|
28
|
-
return _;
|
|
29
|
-
}
|
|
30
|
-
function getKey(props) {
|
|
31
|
-
let s = "";
|
|
32
|
-
const sorted = Object.keys(props).sort();
|
|
33
|
-
for (const key of sorted) {
|
|
34
|
-
const v = props[key];
|
|
35
|
-
if (v && typeof v === "object") {
|
|
36
|
-
s += getKey(v);
|
|
37
|
-
} else {
|
|
38
|
-
s += `.${key}:${v}`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return s;
|
|
42
|
-
}
|
|
43
|
-
function useConstant(fn) {
|
|
44
|
-
const ref = useRef();
|
|
45
|
-
if (!ref.current) {
|
|
46
|
-
ref.current = { v: fn() };
|
|
47
|
-
}
|
|
48
|
-
return ref.current.v;
|
|
49
|
-
}
|
|
50
|
-
function simpleStr(arg) {
|
|
51
|
-
if (process.env.NODE_ENV === "development") {
|
|
52
|
-
return typeof arg === "function" ? "fn" : typeof arg === "string" ? `"${arg}"` : !arg ? arg : typeof arg !== "object" ? arg : Array.isArray(arg) ? "[...]" : `{...}`;
|
|
53
|
-
}
|
|
54
|
-
return arg;
|
|
55
|
-
}
|
|
56
|
-
function getStoreDebugInfo(store) {
|
|
57
|
-
return store[UNWRAP_STORE_INFO] ?? cache.get(getStoreUid(store.constructor, store.props));
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
UNWRAP_STORE_INFO,
|
|
61
|
-
cache,
|
|
62
|
-
useConstant as default,
|
|
63
|
-
get,
|
|
64
|
-
getKey,
|
|
65
|
-
getStoreDebugInfo,
|
|
66
|
-
getStoreDescriptors,
|
|
67
|
-
getStoreUid,
|
|
68
|
-
simpleStr
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=helpers.mjs.map
|
package/dist/esm/helpers.mjs.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,cAAc;AAIvB,MAAM,MAAM,oBAAI,QAAqB;AACrC,MAAM,UAAU,CAAC,KAAU,SAAS,OAAO;AACzC,MAAI,IAAI,IAAI,GAAG;AAAG,WAAO,IAAI,IAAI,GAAG;AACpC,QAAM,MAAM,GAAG,UAAU,KAAK,OAAO;AACrC,MAAI,IAAI,KAAK,GAAG;AAChB,SAAO;AACT;AAEO,SAAS,YAAY,aAAkB,OAA+B;AAG3E,QAAM,YACJ,QAAQ,IAAI,aAAa,gBAAgB,YAAY,OAAO,QAAQ,WAAW;AACjF,SAAO,GAAG,YAAY,CAAC,QAAQ,KAAK,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK;AACtF;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@@
|
|
|
1
|
-
export * from "./useStore";
|
|
2
|
-
import { configureUseStore } from "./configureUseStore";
|
|
3
|
-
export * from "./interfaces";
|
|
4
|
-
export * from "./selector";
|
|
5
|
-
export * from "./reaction";
|
|
6
|
-
export * from "./Store";
|
|
7
|
-
import { UNWRAP_PROXY } from "./constants";
|
|
8
|
-
export * from "./comparators";
|
|
9
|
-
export * from "./decorators";
|
|
10
|
-
export {
|
|
11
|
-
UNWRAP_PROXY,
|
|
12
|
-
configureUseStore
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
DELETED
package/dist/esm/interfaces.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=interfaces.mjs.map
|
package/dist/esm/reaction.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { isEqualSubsetShallow } from "./comparators";
|
|
3
|
-
import { UNWRAP_PROXY } from "./constants";
|
|
4
|
-
import { setIsInReaction } from "./useStore";
|
|
5
|
-
const dispose = (d) => {
|
|
6
|
-
if (typeof d === "function") {
|
|
7
|
-
d();
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
function useReaction(store, selector, receiver, equalityFn = isEqualSubsetShallow, memoArgs) {
|
|
11
|
-
return useMemo(() => reaction(store, selector, receiver, equalityFn), [memoArgs]);
|
|
12
|
-
}
|
|
13
|
-
function reaction(store, selector, receiver, equalityFn = isEqualSubsetShallow) {
|
|
14
|
-
let last = void 0;
|
|
15
|
-
let innerDispose;
|
|
16
|
-
function updateReaction() {
|
|
17
|
-
var _a;
|
|
18
|
-
try {
|
|
19
|
-
setIsInReaction(true);
|
|
20
|
-
const storeInstance = store[UNWRAP_PROXY] || store;
|
|
21
|
-
const next = selector(storeInstance);
|
|
22
|
-
if (!equalityFn(last, next)) {
|
|
23
|
-
if (process.env.NODE_ENV === "development") {
|
|
24
|
-
console.groupCollapsed(
|
|
25
|
-
`\u{1F311} \u23ED %c${receiver.name.padStart(24)} (${storeInstance.constructor.name}${((_a = store.props) == null ? void 0 : _a.id) ? `:${store.props.id}` : ""}) ${last} => ${next}`,
|
|
26
|
-
"color: chocolate;"
|
|
27
|
-
);
|
|
28
|
-
console.groupCollapsed("trace >");
|
|
29
|
-
console.trace();
|
|
30
|
-
console.groupEnd();
|
|
31
|
-
console.log(" ARG", next);
|
|
32
|
-
console.groupEnd();
|
|
33
|
-
}
|
|
34
|
-
dispose(innerDispose);
|
|
35
|
-
last = next;
|
|
36
|
-
innerDispose = receiver(next);
|
|
37
|
-
}
|
|
38
|
-
} finally {
|
|
39
|
-
setIsInReaction(false);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const disposeSubscribe = store.subscribe(updateReaction);
|
|
43
|
-
updateReaction();
|
|
44
|
-
return () => {
|
|
45
|
-
disposeSubscribe();
|
|
46
|
-
dispose(innerDispose);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
reaction,
|
|
51
|
-
useReaction
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=reaction.mjs.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/reaction.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAEhC,MAAM,UAAU,CAAC,MAAW;AAC1B,MAAI,OAAO,MAAM,YAAY;AAC3B,MAAE;AAAA,EACJ;AACF;AAEO,SAAS,YAId,OACA,UACA,UAGA,aAA0C,sBAC1C,UACA;AACA,SAAO,QAAQ,MAAM,SAAS,OAAO,UAAU,UAAU,UAAU,GAAG,CAAC,QAAQ,CAAC;AAClF;AAEO,SAAS,SAId,OACA,UACA,UAGA,aAA0C,sBAC1C;AACA,MAAI,OAAY;AAChB,MAAI;AAEJ,WAAS,iBAAiB;AA1C5B;AA2CI,QAAI;AACF,sBAAgB,IAAI;AACpB,YAAM,gBAAgB,MAAM,YAAY,KAAK;AAC7C,YAAM,OAAO,SAAS,aAAa;AACnC,UAAI,CAAC,WAAW,MAAM,IAAI,GAAG;AAC3B,YAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,kBAAQ;AAAA,YACN,uBAAW,SAAS,KAAK,SAAS,EAAE,MAAM,cAAc,YAAY,SAClE,WAAM,UAAN,mBAAa,MAAK,IAAI,MAAM,MAAM,OAAO,OACtC,WAAW;AAAA,YAChB;AAAA,UACF;AACA,kBAAQ,eAAe,SAAS;AAChC,kBAAQ,MAAM;AACd,kBAAQ,SAAS;AAEjB,kBAAQ,IAAI,SAAS,IAAI;AACzB,kBAAQ,SAAS;AAAA,QACnB;AACA,gBAAQ,YAAY;AACpB,eAAO;AACP,uBAAe,SAAS,IAAI;AAAA,MAC9B;AAAA,IACF,UAAE;AACA,sBAAgB,KAAK;AAAA,IACvB;AAAA,EACF;AAEA,QAAM,mBAAmB,MAAM,UAAU,cAAc;AACvD,iBAAe;AAEf,SAAO,MAAM;AACX,qBAAiB;AACjB,YAAQ,YAAY;AAAA,EACtB;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/esm/selector.mjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { isEqualSubsetShallow } from "./comparators";
|
|
3
|
-
import { UNWRAP_PROXY } from "./constants";
|
|
4
|
-
import { setIsInReaction, trackStoresAccess } from "./useStore";
|
|
5
|
-
const logUpdate = process.env.NODE_ENV === "development" ? (fn, stores, last, next) => {
|
|
6
|
-
const getStoreLogName = (store) => {
|
|
7
|
-
var _a;
|
|
8
|
-
const str = store[UNWRAP_PROXY] ?? store;
|
|
9
|
-
return `${str.constructor.name}${((_a = store.props) == null ? void 0 : _a.id) ? `:${store.props.id}` : ""}`;
|
|
10
|
-
};
|
|
11
|
-
const storeNames = stores.map(getStoreLogName).join(", ");
|
|
12
|
-
const name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
|
|
13
|
-
console.groupCollapsed(name, "color: tomato;");
|
|
14
|
-
console.groupCollapsed("trace >");
|
|
15
|
-
console.trace();
|
|
16
|
-
console.groupEnd();
|
|
17
|
-
console.log(" next", next);
|
|
18
|
-
console.groupEnd();
|
|
19
|
-
} : null;
|
|
20
|
-
function selector(fn) {
|
|
21
|
-
let prev = runStoreSelector(fn);
|
|
22
|
-
let disposeValue = null;
|
|
23
|
-
const subscribe = () => {
|
|
24
|
-
return subscribeToStores([...prev.stores], () => {
|
|
25
|
-
try {
|
|
26
|
-
disposeValue == null ? void 0 : disposeValue();
|
|
27
|
-
setIsInReaction(true);
|
|
28
|
-
const next = runStoreSelector(fn);
|
|
29
|
-
if (typeof next.value === "function") {
|
|
30
|
-
disposeValue = next.value;
|
|
31
|
-
if (process.env.NODE_ENV === "development") {
|
|
32
|
-
logUpdate(fn, [...next.stores], "(fn)", "(fn)");
|
|
33
|
-
}
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (isEqualSubsetShallow(prev.stores, next.stores) && isEqualSubsetShallow(prev.value, next.value)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (process.env.NODE_ENV === "development") {
|
|
40
|
-
logUpdate(fn, [...next.stores], prev.value, next.value);
|
|
41
|
-
}
|
|
42
|
-
prev = next;
|
|
43
|
-
dispose();
|
|
44
|
-
dispose = subscribe();
|
|
45
|
-
} finally {
|
|
46
|
-
setIsInReaction(false);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
let dispose = subscribe();
|
|
51
|
-
return () => {
|
|
52
|
-
dispose();
|
|
53
|
-
disposeValue == null ? void 0 : disposeValue();
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function useSelector(fn) {
|
|
57
|
-
const [state, setState] = useState(() => {
|
|
58
|
-
return runStoreSelector(fn);
|
|
59
|
-
});
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
let dispose;
|
|
62
|
-
const unsub = subscribeToStores([...state.stores], () => {
|
|
63
|
-
dispose == null ? void 0 : dispose();
|
|
64
|
-
const next = runStoreSelector(fn);
|
|
65
|
-
if (typeof next.value === "function") {
|
|
66
|
-
if (process.env.NODE_ENV === "development") {
|
|
67
|
-
logUpdate(fn, [...next.stores], "(fn)", "(fn)");
|
|
68
|
-
}
|
|
69
|
-
dispose = next.value;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
setState((prev) => {
|
|
73
|
-
if (isEqualSubsetShallow(prev.stores, next.stores) && isEqualSubsetShallow(prev.value, next.value)) {
|
|
74
|
-
return prev;
|
|
75
|
-
}
|
|
76
|
-
if (process.env.NODE_ENV === "development") {
|
|
77
|
-
logUpdate(fn, [...next.stores], prev.value, next.value);
|
|
78
|
-
}
|
|
79
|
-
return next;
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
return () => {
|
|
83
|
-
unsub();
|
|
84
|
-
dispose == null ? void 0 : dispose();
|
|
85
|
-
};
|
|
86
|
-
}, [...state.stores]);
|
|
87
|
-
return state.value;
|
|
88
|
-
}
|
|
89
|
-
function runStoreSelector(selector2) {
|
|
90
|
-
const stores = /* @__PURE__ */ new Set();
|
|
91
|
-
const dispose = trackStoresAccess((store) => {
|
|
92
|
-
stores.add(store);
|
|
93
|
-
});
|
|
94
|
-
const value = selector2();
|
|
95
|
-
dispose();
|
|
96
|
-
return {
|
|
97
|
-
value,
|
|
98
|
-
stores
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function subscribeToStores(stores, onUpdate) {
|
|
102
|
-
const disposes = [];
|
|
103
|
-
for (const store of stores) {
|
|
104
|
-
disposes.push(store.subscribe(onUpdate));
|
|
105
|
-
}
|
|
106
|
-
return () => {
|
|
107
|
-
disposes.forEach((x) => x());
|
|
108
|
-
};
|
|
109
|
-
}
|
|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,GAAG,MAAM,MAAM,CAAC;AAEpB,SAAO,MAAM;AACf;AAEA,SAAS,iBAAoBA,WAAmD;AAC9E,QAAM,SAAS,oBAAI,IAAI;AACvB,QAAM,UAAU,kBAAkB,CAAC,UAAU;AAC3C,WAAO,IAAI,KAAK;AAAA,EAClB,CAAC;AACD,QAAM,QAAQA,UAAS;AACvB,UAAQ;AACR,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,kBAAkB,QAAe,UAAqB;AAC7D,QAAM,WAAuB,CAAC;AAC9B,aAAW,SAAS,QAAQ;AAC1B,aAAS,KAAK,MAAM,UAAU,QAAQ,CAAC;AAAA,EACzC;AACA,SAAO,MAAM;AACX,aAAS,QAAQ,CAAC,MAAM,EAAE,CAAC;AAAA,EAC7B;AACF;",
|
|
5
|
-
"names": ["selector"]
|
|
6
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { startTransition, useLayoutEffect, useState } from "react";
|
|
2
|
-
function useAsyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
3
|
-
const [storeState, setStoreState] = useState(getServerSnapshot);
|
|
4
|
-
useLayoutEffect(() => {
|
|
5
|
-
return subscribe((next) => {
|
|
6
|
-
startTransition(() => {
|
|
7
|
-
setStoreState(getSnapshot(next));
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
}, [subscribe]);
|
|
11
|
-
return storeState;
|
|
12
|
-
}
|
|
13
|
-
export {
|
|
14
|
-
useAsyncExternalStore
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=useAsyncExternalStore.mjs.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useAsyncExternalStore.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,iBAAiB,iBAAiB,gBAAgB;AAEpD,SAAS,sBACd,WACA,aACA,mBACA;AACA,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,iBAAiB;AAE9D,kBAAgB,MAAM;AACpB,WAAO,UAAU,CAAC,SAAc;AAC9B,sBAAgB,MAAM;AACpB,sBAAc,YAAY,IAAI,CAAC;AAAA,MACjC,CAAC;AAAA,IACH,CAAC;AAAA,EACH,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO;AACT;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/esm/useStore.mjs
DELETED
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useLayoutEffect,
|
|
5
|
-
useRef,
|
|
6
|
-
useSyncExternalStore
|
|
7
|
-
} from "react";
|
|
8
|
-
import { isEqualSubsetShallow } from "./comparators";
|
|
9
|
-
import { configureOpts } from "./configureUseStore";
|
|
10
|
-
import { UNWRAP_PROXY, defaultOptions } from "./constants";
|
|
11
|
-
import {
|
|
12
|
-
UNWRAP_STORE_INFO,
|
|
13
|
-
cache,
|
|
14
|
-
getStoreDescriptors,
|
|
15
|
-
getStoreUid,
|
|
16
|
-
simpleStr
|
|
17
|
-
} from "./helpers";
|
|
18
|
-
import {
|
|
19
|
-
ADD_TRACKER,
|
|
20
|
-
SHOULD_DEBUG,
|
|
21
|
-
TRACK,
|
|
22
|
-
TRIGGER_UPDATE,
|
|
23
|
-
disableTracking,
|
|
24
|
-
setDisableStoreTracking
|
|
25
|
-
} from "./Store";
|
|
26
|
-
import { useAsyncExternalStore } from "./useAsyncExternalStore";
|
|
27
|
-
import {
|
|
28
|
-
DebugStores,
|
|
29
|
-
shouldDebug,
|
|
30
|
-
useCurrentComponent,
|
|
31
|
-
useDebugStoreComponent
|
|
32
|
-
} from "./useStoreDebug";
|
|
33
|
-
const idFn = (_) => _;
|
|
34
|
-
const shouldUseSyncDefault = typeof window !== "undefined" && window.location.hash.includes(`sync-store`);
|
|
35
|
-
function useStore(StoreKlass, props, options = defaultOptions) {
|
|
36
|
-
const selectorCb = useCallback(options.selector || idFn, []);
|
|
37
|
-
const selector = options.selector ? selectorCb : options.selector;
|
|
38
|
-
if (options.debug) {
|
|
39
|
-
useDebugStoreComponent(StoreKlass);
|
|
40
|
-
}
|
|
41
|
-
const info = getOrCreateStoreInfo(StoreKlass, props);
|
|
42
|
-
return useStoreFromInfo(info, selector);
|
|
43
|
-
}
|
|
44
|
-
function useStoreDebug(StoreKlass, props, selector) {
|
|
45
|
-
useDebugStoreComponent(StoreKlass);
|
|
46
|
-
return useStore(StoreKlass, props, selector);
|
|
47
|
-
}
|
|
48
|
-
function createStore(StoreKlass, props) {
|
|
49
|
-
return getOrCreateStoreInfo(StoreKlass, props).store;
|
|
50
|
-
}
|
|
51
|
-
function useGlobalStore(instance, debug) {
|
|
52
|
-
const store = instance[UNWRAP_PROXY];
|
|
53
|
-
const uid = getStoreUid(store.constructor, store.props);
|
|
54
|
-
const info = cache.get(uid);
|
|
55
|
-
if (!info) {
|
|
56
|
-
throw new Error(`This store not created using createStore()`);
|
|
57
|
-
}
|
|
58
|
-
if (debug) {
|
|
59
|
-
useDebugStoreComponent(store.constructor);
|
|
60
|
-
}
|
|
61
|
-
return useStoreFromInfo(info);
|
|
62
|
-
}
|
|
63
|
-
function useGlobalStoreSelector(instance, selector, debug) {
|
|
64
|
-
const store = instance[UNWRAP_PROXY];
|
|
65
|
-
const uid = getStoreUid(store.constructor, store.props);
|
|
66
|
-
const info = cache.get(uid);
|
|
67
|
-
if (!info) {
|
|
68
|
-
throw new Error(`This store not created using createStore()`);
|
|
69
|
-
}
|
|
70
|
-
if (debug) {
|
|
71
|
-
useDebugStoreComponent(store.constructor);
|
|
72
|
-
}
|
|
73
|
-
return useStoreFromInfo(info, selector);
|
|
74
|
-
}
|
|
75
|
-
function createUseStore(StoreKlass) {
|
|
76
|
-
return function(props, options) {
|
|
77
|
-
return useStore(StoreKlass, props, options);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function createUseStoreSelector(StoreKlass, selector) {
|
|
81
|
-
return (props) => {
|
|
82
|
-
return useStore(StoreKlass, props, { selector });
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function useStoreSelector(StoreKlass, selector, props) {
|
|
86
|
-
return useStore(StoreKlass, props, { selector });
|
|
87
|
-
}
|
|
88
|
-
const storeAccessTrackers = /* @__PURE__ */ new Set();
|
|
89
|
-
function trackStoresAccess(cb) {
|
|
90
|
-
storeAccessTrackers.add(cb);
|
|
91
|
-
return () => {
|
|
92
|
-
storeAccessTrackers.delete(cb);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function useStoreOnce(StoreKlass, props, selector) {
|
|
96
|
-
return useStore(StoreKlass, props, { selector, once: true });
|
|
97
|
-
}
|
|
98
|
-
function getStore(StoreKlass, props) {
|
|
99
|
-
return getOrCreateStoreInfo(StoreKlass, props).store;
|
|
100
|
-
}
|
|
101
|
-
function getOrCreateStoreInfo(StoreKlass, props, opts, propsKeyCalculated) {
|
|
102
|
-
var _a;
|
|
103
|
-
const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props);
|
|
104
|
-
if (!(opts == null ? void 0 : opts.avoidCache)) {
|
|
105
|
-
const cached = cache.get(uid);
|
|
106
|
-
if (cached) {
|
|
107
|
-
if (cached.storeInstance.constructor.toString() !== StoreKlass.toString()) {
|
|
108
|
-
console.warn(
|
|
109
|
-
"Error: Stores must have a unique name (ignore if this is a hot reload)"
|
|
110
|
-
);
|
|
111
|
-
} else {
|
|
112
|
-
return cached;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const storeInstance = new StoreKlass(props);
|
|
117
|
-
const getters = {};
|
|
118
|
-
const actions = {};
|
|
119
|
-
const stateKeys = [];
|
|
120
|
-
const descriptors = getStoreDescriptors(storeInstance);
|
|
121
|
-
for (const key in descriptors) {
|
|
122
|
-
const descriptor = descriptors[key];
|
|
123
|
-
if (typeof descriptor.value === "function") {
|
|
124
|
-
actions[key] = descriptor.value;
|
|
125
|
-
} else if (typeof descriptor.get === "function") {
|
|
126
|
-
getters[key] = descriptor.get;
|
|
127
|
-
} else {
|
|
128
|
-
if (key !== "props" && key[0] !== "_") {
|
|
129
|
-
stateKeys.push(key);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const keyComparators = storeInstance["_comparators"];
|
|
134
|
-
const storeInfo = {
|
|
135
|
-
keyComparators,
|
|
136
|
-
storeInstance,
|
|
137
|
-
getters,
|
|
138
|
-
stateKeys,
|
|
139
|
-
actions,
|
|
140
|
-
gettersState: {
|
|
141
|
-
getCache: /* @__PURE__ */ new Map(),
|
|
142
|
-
depsToGetter: /* @__PURE__ */ new Map(),
|
|
143
|
-
curGetKeys: /* @__PURE__ */ new Set(),
|
|
144
|
-
isGetting: false
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
const store = createProxiedStore(storeInfo);
|
|
148
|
-
if (process.env.NODE_ENV === "development") {
|
|
149
|
-
allStores[uid] = store;
|
|
150
|
-
}
|
|
151
|
-
(_a = store.mount) == null ? void 0 : _a.call(store);
|
|
152
|
-
const value = {
|
|
153
|
-
...storeInfo,
|
|
154
|
-
store
|
|
155
|
-
};
|
|
156
|
-
if (!(opts == null ? void 0 : opts.avoidCache)) {
|
|
157
|
-
cache.set(uid, value);
|
|
158
|
-
}
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
const allStores = {};
|
|
162
|
-
const emptyObj = {};
|
|
163
|
-
const selectKeys = (obj, keys) => {
|
|
164
|
-
if (!keys.length) {
|
|
165
|
-
return emptyObj;
|
|
166
|
-
}
|
|
167
|
-
const res = {};
|
|
168
|
-
for (const key of keys) {
|
|
169
|
-
res[key] = obj[key];
|
|
170
|
-
}
|
|
171
|
-
return res;
|
|
172
|
-
};
|
|
173
|
-
let isInReaction = false;
|
|
174
|
-
const setIsInReaction = (val) => {
|
|
175
|
-
isInReaction = val;
|
|
176
|
-
};
|
|
177
|
-
function useStoreFromInfo(info, userSelector) {
|
|
178
|
-
const { store } = info;
|
|
179
|
-
if (!store) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
const internal = useRef();
|
|
183
|
-
const component = useCurrentComponent();
|
|
184
|
-
if (!internal.current) {
|
|
185
|
-
internal.current = {
|
|
186
|
-
component,
|
|
187
|
-
isTracking: false,
|
|
188
|
-
firstRun: true,
|
|
189
|
-
tracked: /* @__PURE__ */ new Set(),
|
|
190
|
-
dispose: null,
|
|
191
|
-
last: null,
|
|
192
|
-
lastKeys: null
|
|
193
|
-
};
|
|
194
|
-
const dispose = store[ADD_TRACKER](internal.current);
|
|
195
|
-
internal.current.dispose = dispose;
|
|
196
|
-
}
|
|
197
|
-
const curInternal = internal.current;
|
|
198
|
-
const shouldPrintDebug = !!process.env.LOG_LEVEL && (configureOpts.logLevel === "debug" || shouldDebug(component, info));
|
|
199
|
-
const getSnapshot = useCallback(() => {
|
|
200
|
-
const curInternal2 = internal.current;
|
|
201
|
-
const keys = curInternal2.firstRun ? info.stateKeys : [...curInternal2.tracked];
|
|
202
|
-
const nextKeys = `${store._version}${keys.join("")}${(userSelector == null ? void 0 : userSelector.toString()) || ""}`;
|
|
203
|
-
if (nextKeys === curInternal2.lastKeys) {
|
|
204
|
-
if (shouldPrintDebug) {
|
|
205
|
-
console.log("avoid update", nextKeys, curInternal2.lastKeys);
|
|
206
|
-
}
|
|
207
|
-
return curInternal2.last;
|
|
208
|
-
}
|
|
209
|
-
curInternal2.lastKeys = nextKeys;
|
|
210
|
-
let snap;
|
|
211
|
-
setDisableStoreTracking(store, true);
|
|
212
|
-
const last = curInternal2.last;
|
|
213
|
-
if (userSelector) {
|
|
214
|
-
snap = userSelector(store);
|
|
215
|
-
} else {
|
|
216
|
-
snap = selectKeys(store, keys);
|
|
217
|
-
}
|
|
218
|
-
setDisableStoreTracking(store, false);
|
|
219
|
-
const isUnchanged = typeof last !== "undefined" && isEqualSubsetShallow(last, snap, {
|
|
220
|
-
keyComparators: info.keyComparators
|
|
221
|
-
});
|
|
222
|
-
if (shouldPrintDebug) {
|
|
223
|
-
console.log("\u{1F311} getSnapshot", { userSelector, info, isUnchanged, component, keys, snap, curInternal: curInternal2 });
|
|
224
|
-
}
|
|
225
|
-
if (isUnchanged) {
|
|
226
|
-
return last;
|
|
227
|
-
}
|
|
228
|
-
curInternal2.last = snap;
|
|
229
|
-
return snap;
|
|
230
|
-
}, []);
|
|
231
|
-
const state = shouldUseSyncDefault ? useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot) : useAsyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
|
|
232
|
-
useEffect(() => {
|
|
233
|
-
return curInternal.dispose;
|
|
234
|
-
}, []);
|
|
235
|
-
if (!userSelector) {
|
|
236
|
-
curInternal.isTracking = true;
|
|
237
|
-
useLayoutEffect(() => {
|
|
238
|
-
curInternal.isTracking = false;
|
|
239
|
-
curInternal.firstRun = false;
|
|
240
|
-
if (shouldPrintDebug) {
|
|
241
|
-
console.log("\u{1F311} finish render, tracking", [...curInternal.tracked]);
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
return state;
|
|
246
|
-
}
|
|
247
|
-
return new Proxy(store, {
|
|
248
|
-
get(target, key) {
|
|
249
|
-
const curVal = Reflect.get(target, key);
|
|
250
|
-
if (isInReaction) {
|
|
251
|
-
return curVal;
|
|
252
|
-
}
|
|
253
|
-
if (Reflect.has(state, key)) {
|
|
254
|
-
return Reflect.get(state, key);
|
|
255
|
-
}
|
|
256
|
-
return curVal;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
let setters = /* @__PURE__ */ new Set();
|
|
261
|
-
const logStack = /* @__PURE__ */ new Set();
|
|
262
|
-
function createProxiedStore(storeInfo) {
|
|
263
|
-
const { actions, storeInstance, getters, gettersState } = storeInfo;
|
|
264
|
-
const { getCache, curGetKeys, depsToGetter } = gettersState;
|
|
265
|
-
const constr = storeInstance.constructor;
|
|
266
|
-
let didSet = false;
|
|
267
|
-
let isInAction = false;
|
|
268
|
-
const wrappedActions = {};
|
|
269
|
-
for (const key in actions) {
|
|
270
|
-
if (key === "subscribe") {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
const actionFn = actions[key];
|
|
274
|
-
const isGetFn = key.startsWith("get");
|
|
275
|
-
wrappedActions[key] = function useStoreAction(...args) {
|
|
276
|
-
let res;
|
|
277
|
-
if (isGetFn || gettersState.isGetting) {
|
|
278
|
-
return Reflect.apply(actionFn, proxiedStore, args);
|
|
279
|
-
}
|
|
280
|
-
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
281
|
-
console.log("(debug) startAction", key, { isInAction });
|
|
282
|
-
}
|
|
283
|
-
isInAction = true;
|
|
284
|
-
res = Reflect.apply(actionFn, proxiedStore, args);
|
|
285
|
-
if (res instanceof Promise) {
|
|
286
|
-
return res.then(finishAction);
|
|
287
|
-
}
|
|
288
|
-
finishAction();
|
|
289
|
-
return res;
|
|
290
|
-
};
|
|
291
|
-
if (process.env.NODE_ENV === "development") {
|
|
292
|
-
if (!key.startsWith("get") && !key.startsWith("_") && key !== "subscribe") {
|
|
293
|
-
const ogAction = wrappedActions[key];
|
|
294
|
-
wrappedActions[key] = new Proxy(ogAction, {
|
|
295
|
-
apply(target, thisArg, args) {
|
|
296
|
-
const isDebugging = DebugStores.has(constr);
|
|
297
|
-
const shouldLog = process.env.LOG_LEVEL !== "0" && (isDebugging || configureOpts.logLevel !== "error");
|
|
298
|
-
if (!shouldLog) {
|
|
299
|
-
return Reflect.apply(target, thisArg, args);
|
|
300
|
-
}
|
|
301
|
-
setters = /* @__PURE__ */ new Set();
|
|
302
|
-
const curSetters = setters;
|
|
303
|
-
const isTopLevelLogger = logStack.size == 0;
|
|
304
|
-
const logs = /* @__PURE__ */ new Set();
|
|
305
|
-
logStack.add(logs);
|
|
306
|
-
let res;
|
|
307
|
-
const id = counter++;
|
|
308
|
-
try {
|
|
309
|
-
res = Reflect.apply(target, thisArg, args);
|
|
310
|
-
} catch (err) {
|
|
311
|
-
console.error("Error", err);
|
|
312
|
-
throw err;
|
|
313
|
-
} finally {
|
|
314
|
-
logStack.add("end");
|
|
315
|
-
const name = constr.name;
|
|
316
|
-
const color = strColor(name);
|
|
317
|
-
const simpleArgs = args.map(simpleStr);
|
|
318
|
-
logs.add([
|
|
319
|
-
`%c \u{1F311} ${id} ${name.padStart(
|
|
320
|
-
isTopLevelLogger ? 8 : 4
|
|
321
|
-
)}%c.${key}(${simpleArgs.join(", ")})${isTopLevelLogger && logStack.size > 1 ? ` (+${logStack.size - 1})` : ""}`,
|
|
322
|
-
`color: ${color};`,
|
|
323
|
-
"color: black;"
|
|
324
|
-
]);
|
|
325
|
-
if (curSetters.size) {
|
|
326
|
-
curSetters.forEach(({ key: key2, value }) => {
|
|
327
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
328
|
-
logs.add([` SET ${key2} ${value}`, value]);
|
|
329
|
-
} else {
|
|
330
|
-
logs.add([` SET ${key2}`, value]);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
if (isTopLevelLogger) {
|
|
335
|
-
let error = null;
|
|
336
|
-
try {
|
|
337
|
-
for (const item of [...logStack]) {
|
|
338
|
-
if (item === "end") {
|
|
339
|
-
console.groupEnd();
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
const [head, ...rest] = item;
|
|
343
|
-
if (head) {
|
|
344
|
-
console.groupCollapsed(...head);
|
|
345
|
-
console.groupCollapsed("...");
|
|
346
|
-
console.log("args", args);
|
|
347
|
-
console.log("response", res);
|
|
348
|
-
console.groupCollapsed("trace");
|
|
349
|
-
console.trace();
|
|
350
|
-
console.groupEnd();
|
|
351
|
-
console.groupEnd();
|
|
352
|
-
for (const [name2, ...log] of rest) {
|
|
353
|
-
console.groupCollapsed(name2);
|
|
354
|
-
console.log(...log);
|
|
355
|
-
console.groupEnd();
|
|
356
|
-
}
|
|
357
|
-
} else {
|
|
358
|
-
console.log("Weird log", head, ...rest);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
} catch (err) {
|
|
362
|
-
error = err;
|
|
363
|
-
}
|
|
364
|
-
for (const _ of [...logStack]) {
|
|
365
|
-
console.groupEnd();
|
|
366
|
-
}
|
|
367
|
-
if (error) {
|
|
368
|
-
console.error(`error loggin`, error);
|
|
369
|
-
}
|
|
370
|
-
logStack.clear();
|
|
371
|
-
}
|
|
372
|
-
return res;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
function hashCode(str) {
|
|
380
|
-
let hash = 0;
|
|
381
|
-
for (let i = 0; i < str.length; i++) {
|
|
382
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
383
|
-
}
|
|
384
|
-
return hash;
|
|
385
|
-
}
|
|
386
|
-
function strColor(str) {
|
|
387
|
-
return `hsl(${hashCode(str) % 360}, 90%, 40%)`;
|
|
388
|
-
}
|
|
389
|
-
const finishAction = (val) => {
|
|
390
|
-
var _a;
|
|
391
|
-
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
392
|
-
console.log("(debug) finishAction", { didSet });
|
|
393
|
-
}
|
|
394
|
-
isInAction = false;
|
|
395
|
-
if (didSet) {
|
|
396
|
-
(_a = storeInstance[TRIGGER_UPDATE]) == null ? void 0 : _a.call(storeInstance);
|
|
397
|
-
didSet = false;
|
|
398
|
-
}
|
|
399
|
-
return val;
|
|
400
|
-
};
|
|
401
|
-
const proxiedStore = new Proxy(storeInstance, {
|
|
402
|
-
// GET
|
|
403
|
-
get(_, key) {
|
|
404
|
-
if (key in wrappedActions) {
|
|
405
|
-
return wrappedActions[key];
|
|
406
|
-
}
|
|
407
|
-
if (key in passThroughKeys) {
|
|
408
|
-
return Reflect.get(storeInstance, key);
|
|
409
|
-
}
|
|
410
|
-
if (key === UNWRAP_PROXY) {
|
|
411
|
-
return storeInstance;
|
|
412
|
-
}
|
|
413
|
-
if (key === UNWRAP_STORE_INFO) {
|
|
414
|
-
return storeInfo;
|
|
415
|
-
}
|
|
416
|
-
const trackingDisabled = disableTracking.get(storeInstance);
|
|
417
|
-
if (!trackingDisabled) {
|
|
418
|
-
if (storeAccessTrackers.size && !storeAccessTrackers.has(storeInstance)) {
|
|
419
|
-
for (const t of storeAccessTrackers) {
|
|
420
|
-
t(storeInstance);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (typeof key !== "string") {
|
|
425
|
-
return Reflect.get(storeInstance, key);
|
|
426
|
-
}
|
|
427
|
-
const shouldPrintDebug = process.env.NODE_ENV === "development" && DebugStores.has(constr);
|
|
428
|
-
if (!trackingDisabled) {
|
|
429
|
-
if (gettersState.isGetting) {
|
|
430
|
-
gettersState.curGetKeys.add(key);
|
|
431
|
-
} else {
|
|
432
|
-
storeInstance[TRACK](key, shouldPrintDebug);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if (key in getters) {
|
|
436
|
-
if (getCache.has(key)) {
|
|
437
|
-
return getCache.get(key);
|
|
438
|
-
}
|
|
439
|
-
curGetKeys.clear();
|
|
440
|
-
const isSubGetter = gettersState.isGetting;
|
|
441
|
-
gettersState.isGetting = true;
|
|
442
|
-
const res = getters[key].call(proxiedStore);
|
|
443
|
-
if (!isSubGetter) {
|
|
444
|
-
gettersState.isGetting = false;
|
|
445
|
-
}
|
|
446
|
-
for (const gk of curGetKeys) {
|
|
447
|
-
if (!depsToGetter.has(gk)) {
|
|
448
|
-
depsToGetter.set(gk, /* @__PURE__ */ new Set());
|
|
449
|
-
}
|
|
450
|
-
const cur = depsToGetter.get(gk);
|
|
451
|
-
cur.add(key);
|
|
452
|
-
}
|
|
453
|
-
getCache.set(key, res);
|
|
454
|
-
return res;
|
|
455
|
-
}
|
|
456
|
-
return Reflect.get(storeInstance, key);
|
|
457
|
-
},
|
|
458
|
-
// SET
|
|
459
|
-
set(target, key, value, receiver) {
|
|
460
|
-
var _a;
|
|
461
|
-
const cur = Reflect.get(target, key);
|
|
462
|
-
const res = Reflect.set(target, key, value, receiver);
|
|
463
|
-
if (res && cur !== value) {
|
|
464
|
-
if (typeof key === "string") {
|
|
465
|
-
clearGetterCache(key);
|
|
466
|
-
}
|
|
467
|
-
if (process.env.LOG_LEVEL && configureOpts.logLevel !== "error") {
|
|
468
|
-
setters.add({ key, value });
|
|
469
|
-
if (storeInstance[SHOULD_DEBUG]()) {
|
|
470
|
-
console.log("(debug) SET", res, key, value);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if (process.env.NODE_ENV === "development" && DebugStores.has(constr)) {
|
|
474
|
-
console.log("SET...", { key, value, isInAction });
|
|
475
|
-
}
|
|
476
|
-
if (isInAction) {
|
|
477
|
-
didSet = true;
|
|
478
|
-
} else {
|
|
479
|
-
(_a = storeInstance[TRIGGER_UPDATE]) == null ? void 0 : _a.call(storeInstance);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return res;
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
function clearGetterCache(setKey) {
|
|
486
|
-
const getters2 = depsToGetter.get(setKey);
|
|
487
|
-
getCache.delete(setKey);
|
|
488
|
-
if (!getters2) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
for (const gk of getters2) {
|
|
492
|
-
getCache.delete(gk);
|
|
493
|
-
if (depsToGetter.has(gk)) {
|
|
494
|
-
clearGetterCache(gk);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return proxiedStore;
|
|
499
|
-
}
|
|
500
|
-
let counter = 0;
|
|
501
|
-
const passThroughKeys = {
|
|
502
|
-
subscribe: true,
|
|
503
|
-
_version: true,
|
|
504
|
-
_trackers: true,
|
|
505
|
-
$$typeof: true,
|
|
506
|
-
_listeners: true,
|
|
507
|
-
_enableTracking: true
|
|
508
|
-
};
|
|
509
|
-
export {
|
|
510
|
-
allStores,
|
|
511
|
-
createStore,
|
|
512
|
-
createUseStore,
|
|
513
|
-
createUseStoreSelector,
|
|
514
|
-
getStore,
|
|
515
|
-
setIsInReaction,
|
|
516
|
-
trackStoresAccess,
|
|
517
|
-
useGlobalStore,
|
|
518
|
-
useGlobalStoreSelector,
|
|
519
|
-
useStore,
|
|
520
|
-
useStoreDebug,
|
|
521
|
-
useStoreOnce,
|
|
522
|
-
useStoreSelector
|
|
523
|
-
};
|
|
524
|
-
//# sourceMappingURL=useStore.mjs.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useStore.tsx"],
|
|
4
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,cAAc,sBAAsB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,MAAM,OAAO,CAAC,MAAM;AACpB,MAAM,uBACJ,OAAO,WAAW,eAAe,OAAO,SAAS,KAAK,SAAS,YAAY;AAGtE,SAAS,SACd,YACA,OACA,UAAmC,gBAChC;AACH,QAAM,aAAa,YAAY,QAAQ,YAAY,MAAM,CAAC,CAAC;AAC3D,QAAM,WAAW,QAAQ,WAAW,aAAa,QAAQ;AAEzD,MAAI,QAAQ,OAAO;AACjB,2BAAuB,UAAU;AAAA,EACnC;AAUA,QAAM,OAAO,qBAAqB,YAAY,KAAK;AACnD,SAAO,iBAAiB,MAAM,QAAQ;AACxC;AAEO,SAAS,cACd,YACA,OACA,UACG;AACH,yBAAuB,U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;AACvC,aAAS,OAAO,MAAM;AACtB,QAAI,CAACA,UAAS;AACZ;AAAA,IACF;AACA,eAAW,MAAMA,UAAS;AACxB,eAAS,OAAO,EAAE;AAClB,UAAI,aAAa,IAAI,EAAE,GAAG;AACxB,yBAAiB,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAI,UAAU;AAEd,MAAM,kBAAkB;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,iBAAiB;AACnB;",
|
|
5
|
-
"names": ["curInternal", "key", "name", "getters"]
|
|
6
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React, { useLayoutEffect } from "react";
|
|
2
|
-
const { ReactCurrentOwner } = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
3
|
-
const useCurrentComponent = () => {
|
|
4
|
-
return ReactCurrentOwner && ReactCurrentOwner.current && ReactCurrentOwner.current.elementType ? ReactCurrentOwner.current.elementType : {};
|
|
5
|
-
};
|
|
6
|
-
function useDebugStoreComponent(StoreCons) {
|
|
7
|
-
const cmp = useCurrentComponent();
|
|
8
|
-
DebugStores.add(StoreCons);
|
|
9
|
-
if (!DebugComponents.has(cmp)) {
|
|
10
|
-
DebugComponents.set(cmp, /* @__PURE__ */ new Set());
|
|
11
|
-
}
|
|
12
|
-
const stores = DebugComponents.get(cmp);
|
|
13
|
-
stores.add(StoreCons);
|
|
14
|
-
useLayoutEffect(() => {
|
|
15
|
-
return () => {
|
|
16
|
-
DebugStores.delete(StoreCons);
|
|
17
|
-
stores.delete(StoreCons);
|
|
18
|
-
};
|
|
19
|
-
}, []);
|
|
20
|
-
}
|
|
21
|
-
const shouldDebug = (component, info) => {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
const StoreCons = (_a = info.storeInstance) == null ? void 0 : _a.constructor;
|
|
24
|
-
return (_b = DebugComponents.get(component)) == null ? void 0 : _b.has(StoreCons);
|
|
25
|
-
};
|
|
26
|
-
const DebugComponents = /* @__PURE__ */ new Map();
|
|
27
|
-
const DebugStores = /* @__PURE__ */ new Set();
|
|
28
|
-
export {
|
|
29
|
-
DebugComponents,
|
|
30
|
-
DebugStores,
|
|
31
|
-
shouldDebug,
|
|
32
|
-
useCurrentComponent,
|
|
33
|
-
useDebugStoreComponent
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=useStoreDebug.mjs.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useStoreDebug.tsx"],
|
|
4
|
-
"mappings": "AAAA,OAAO,SAAS,uBAAuB;AAIvC,MAAM,EAAE,kBAAkB,IAAK,MAC5B;AACI,MAAM,sBAAsB,MAAM;AACvC,SAAO,qBACL,kBAAkB,WAClB,kBAAkB,QAAQ,cACxB,kBAAkB,QAAQ,cAC1B,CAAC;AACP;AAEO,SAAS,uBAAuB,WAAgB;AACrD,QAAM,MAAM,oBAAoB;AAGhC,cAAY,IAAI,SAAS;AACzB,MAAI,CAAC,gBAAgB,IAAI,GAAG,GAAG;AAC7B,oBAAgB,IAAI,KAAK,oBAAI,IAAI,CAAC;AAAA,EACpC;AACA,QAAM,SAAS,gBAAgB,IAAI,GAAG;AACtC,SAAO,IAAI,SAAS;AAEpB,kBAAgB,MAAM;AACpB,WAAO,MAAM;AACX,kBAAY,OAAO,SAAS;AAC5B,aAAO,OAAO,SAAS;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cAAc,CAAC,WAAgB,SAA2C;AAjCvF;AAkCE,QAAM,aAAY,UAAK,kBAAL,mBAAoB;AACtC,UAAO,qBAAgB,IAAI,SAAS,MAA7B,mBAAgC,IAAI;AAC7C;AAEO,MAAM,kBAAkB,oBAAI,IAAmB;AAC/C,MAAM,cAAc,oBAAI,IAAS;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/types/fastCompare.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const EQUALITY_KEY: unique symbol;
|
|
2
|
-
export type IsEqualOptions = {
|
|
3
|
-
ignoreKeys?: {
|
|
4
|
-
[key: string]: boolean;
|
|
5
|
-
};
|
|
6
|
-
keyComparators?: {
|
|
7
|
-
[key: string]: (a: any, b: any) => boolean;
|
|
8
|
-
};
|
|
9
|
-
log?: boolean;
|
|
10
|
-
maxDepth?: number;
|
|
11
|
-
};
|
|
12
|
-
export declare function isEqual(a: any, b: any, options?: IsEqualOptions): boolean;
|
|
13
|
-
//# sourceMappingURL=fastCompare.d.ts.map
|