@tamagui/use-store 1.15.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/dist/cjs/Store.js +99 -0
- package/dist/cjs/Store.js.map +6 -0
- package/dist/cjs/comparators.js +45 -0
- package/dist/cjs/comparators.js.map +6 -0
- package/dist/cjs/configureUseStore.js +34 -0
- package/dist/cjs/configureUseStore.js.map +6 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/constants.js.map +6 -0
- package/dist/cjs/decorators.js +34 -0
- package/dist/cjs/decorators.js.map +6 -0
- package/dist/cjs/fastCompare.js +168 -0
- package/dist/cjs/fastCompare.js.map +6 -0
- package/dist/cjs/helpers.js +101 -0
- package/dist/cjs/helpers.js.map +6 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/interfaces.js +17 -0
- package/dist/cjs/interfaces.js.map +6 -0
- package/dist/cjs/reaction.js +78 -0
- package/dist/cjs/reaction.js.map +6 -0
- package/dist/cjs/selector.js +139 -0
- package/dist/cjs/selector.js.map +6 -0
- package/dist/cjs/useStore.js +534 -0
- package/dist/cjs/useStore.js.map +6 -0
- package/dist/cjs/useStoreDebug.js +73 -0
- package/dist/cjs/useStoreDebug.js.map +6 -0
- package/dist/esm/Store.js +69 -0
- package/dist/esm/Store.js.map +6 -0
- package/dist/esm/Store.mjs +69 -0
- package/dist/esm/Store.mjs.map +6 -0
- package/dist/esm/comparators.js +21 -0
- package/dist/esm/comparators.js.map +6 -0
- package/dist/esm/comparators.mjs +21 -0
- package/dist/esm/comparators.mjs.map +6 -0
- package/dist/esm/configureUseStore.js +9 -0
- package/dist/esm/configureUseStore.js.map +6 -0
- package/dist/esm/configureUseStore.mjs +9 -0
- package/dist/esm/configureUseStore.mjs.map +6 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +6 -0
- package/dist/esm/constants.mjs +10 -0
- package/dist/esm/constants.mjs.map +6 -0
- package/dist/esm/decorators.js +10 -0
- package/dist/esm/decorators.js.map +6 -0
- package/dist/esm/decorators.mjs +10 -0
- package/dist/esm/decorators.mjs.map +6 -0
- package/dist/esm/fastCompare.js +143 -0
- package/dist/esm/fastCompare.js.map +6 -0
- package/dist/esm/fastCompare.mjs +143 -0
- package/dist/esm/fastCompare.mjs.map +6 -0
- package/dist/esm/helpers.js +70 -0
- package/dist/esm/helpers.js.map +6 -0
- package/dist/esm/helpers.mjs +70 -0
- package/dist/esm/helpers.mjs.map +6 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/index.mjs.map +6 -0
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/interfaces.js.map +6 -0
- package/dist/esm/interfaces.mjs +1 -0
- package/dist/esm/interfaces.mjs.map +6 -0
- package/dist/esm/reaction.js +53 -0
- package/dist/esm/reaction.js.map +6 -0
- package/dist/esm/reaction.mjs +53 -0
- package/dist/esm/reaction.mjs.map +6 -0
- package/dist/esm/selector.js +114 -0
- package/dist/esm/selector.js.map +6 -0
- package/dist/esm/selector.mjs +114 -0
- package/dist/esm/selector.mjs.map +6 -0
- package/dist/esm/useStore.js +516 -0
- package/dist/esm/useStore.js.map +6 -0
- package/dist/esm/useStore.mjs +516 -0
- package/dist/esm/useStore.mjs.map +6 -0
- package/dist/esm/useStoreDebug.js +35 -0
- package/dist/esm/useStoreDebug.js.map +6 -0
- package/dist/esm/useStoreDebug.mjs +35 -0
- package/dist/esm/useStoreDebug.mjs.map +6 -0
- package/package.json +44 -0
- package/src/Store.tsx +77 -0
- package/src/comparators.tsx +18 -0
- package/src/configureUseStore.tsx +7 -0
- package/src/constants.tsx +6 -0
- package/src/decorators.tsx +8 -0
- package/src/helpers.tsx +87 -0
- package/src/index.ts +9 -0
- package/src/interfaces.tsx +32 -0
- package/src/reaction.tsx +109 -0
- package/src/selector.tsx +129 -0
- package/src/useStore.tsx +705 -0
- package/src/useStoreDebug.tsx +40 -0
- package/types/Store.d.ts +28 -0
- package/types/Store.d.ts.map +1 -0
- package/types/comparators.d.ts +6 -0
- package/types/comparators.d.ts.map +1 -0
- package/types/configureUseStore.d.ts +4 -0
- package/types/configureUseStore.d.ts.map +1 -0
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/decorators.d.ts +3 -0
- package/types/decorators.d.ts.map +1 -0
- package/types/fastCompare.d.ts +13 -0
- package/types/fastCompare.d.ts.map +1 -0
- package/types/helpers.d.ts +13 -0
- package/types/helpers.d.ts.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -0
- package/types/interfaces.d.ts +30 -0
- package/types/interfaces.d.ts.map +1 -0
- package/types/reaction.d.ts +4 -0
- package/types/reaction.d.ts.map +1 -0
- package/types/selector.d.ts +3 -0
- package/types/selector.d.ts.map +1 -0
- package/types/useStore.d.ts +18 -0
- package/types/useStore.d.ts.map +1 -0
- package/types/useStoreDebug.d.ts +7 -0
- package/types/useStoreDebug.d.ts.map +1 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
UNWRAP_PROXY: () => import_constants.UNWRAP_PROXY,
|
|
23
|
+
configureUseStore: () => import_configureUseStore.configureUseStore
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
__reExport(src_exports, require("./useStore"), module.exports);
|
|
27
|
+
var import_configureUseStore = require("./configureUseStore");
|
|
28
|
+
__reExport(src_exports, require("./interfaces"), module.exports);
|
|
29
|
+
__reExport(src_exports, require("./selector"), module.exports);
|
|
30
|
+
__reExport(src_exports, require("./reaction"), module.exports);
|
|
31
|
+
__reExport(src_exports, require("./Store"), module.exports);
|
|
32
|
+
var import_constants = require("./constants");
|
|
33
|
+
__reExport(src_exports, require("./comparators"), module.exports);
|
|
34
|
+
__reExport(src_exports, require("./decorators"), module.exports);
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
UNWRAP_PROXY,
|
|
38
|
+
configureUseStore,
|
|
39
|
+
...require("./useStore"),
|
|
40
|
+
...require("./interfaces"),
|
|
41
|
+
...require("./selector"),
|
|
42
|
+
...require("./reaction"),
|
|
43
|
+
...require("./Store"),
|
|
44
|
+
...require("./comparators"),
|
|
45
|
+
...require("./decorators")
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,uBAAd;AACA,+BAAkC;AAClC,wBAAc,yBAFd;AAGA,wBAAc,uBAHd;AAIA,wBAAc,uBAJd;AAKA,wBAAc,oBALd;AAMA,uBAA6B;AAC7B,wBAAc,0BAPd;AAQA,wBAAc,yBARd;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var interfaces_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(interfaces_exports);
|
|
17
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var reaction_exports = {};
|
|
20
|
+
__export(reaction_exports, {
|
|
21
|
+
reaction: () => reaction,
|
|
22
|
+
useReaction: () => useReaction
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(reaction_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_comparators = require("./comparators");
|
|
27
|
+
var import_constants = require("./constants");
|
|
28
|
+
var import_useStore = require("./useStore");
|
|
29
|
+
const dispose = (d) => {
|
|
30
|
+
if (typeof d === "function") {
|
|
31
|
+
d();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function useReaction(store, selector, receiver, equalityFn = import_comparators.isEqualSubsetShallow, memoArgs) {
|
|
35
|
+
return (0, import_react.useMemo)(() => reaction(store, selector, receiver, equalityFn), [memoArgs]);
|
|
36
|
+
}
|
|
37
|
+
function reaction(store, selector, receiver, equalityFn = import_comparators.isEqualSubsetShallow) {
|
|
38
|
+
let last = void 0;
|
|
39
|
+
let innerDispose;
|
|
40
|
+
function updateReaction() {
|
|
41
|
+
var _a;
|
|
42
|
+
try {
|
|
43
|
+
(0, import_useStore.setIsInReaction)(true);
|
|
44
|
+
const storeInstance = store[import_constants.UNWRAP_PROXY] || store;
|
|
45
|
+
const next = selector(storeInstance);
|
|
46
|
+
if (!equalityFn(last, next)) {
|
|
47
|
+
if (process.env.NODE_ENV === "development") {
|
|
48
|
+
console.groupCollapsed(
|
|
49
|
+
`\u{1F311} \u23ED %c${receiver.name.padStart(24)} (${storeInstance.constructor.name}${((_a = store.props) == null ? void 0 : _a.id) ? `:${store.props.id}` : ""}) ${last} => ${next}`,
|
|
50
|
+
"color: chocolate;"
|
|
51
|
+
);
|
|
52
|
+
console.groupCollapsed("trace >");
|
|
53
|
+
console.trace();
|
|
54
|
+
console.groupEnd();
|
|
55
|
+
console.log(" ARG", next);
|
|
56
|
+
console.groupEnd();
|
|
57
|
+
}
|
|
58
|
+
dispose(innerDispose);
|
|
59
|
+
last = next;
|
|
60
|
+
innerDispose = receiver(next);
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
(0, import_useStore.setIsInReaction)(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const disposeSubscribe = store.subscribe(updateReaction);
|
|
67
|
+
updateReaction();
|
|
68
|
+
return () => {
|
|
69
|
+
disposeSubscribe();
|
|
70
|
+
dispose(innerDispose);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
reaction,
|
|
76
|
+
useReaction
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=reaction.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/reaction.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAExB,yBAAqC;AACrC,uBAA6B;AAE7B,sBAAgC;AAEhC,MAAM,UAAU,CAAC,MAAW;AAC1B,MAAI,OAAO,MAAM,YAAY;AAC3B,MAAE;AAAA,EACJ;AACF;AAEO,SAAS,YAId,OACA,UACA,UAGA,aAA0C,yCAC1C,UACA;AACA,aAAO,sBAAQ,MAAM,SAAS,OAAO,UAAU,UAAU,UAAU,GAAG,CAAC,QAAQ,CAAC;AAClF;AAEO,SAAS,SAId,OACA,UACA,UAGA,aAA0C,yCAC1C;AACA,MAAI,OAAY;AAChB,MAAI;AAEJ,WAAS,iBAAiB;AA1C5B;AA2CI,QAAI;AACF,2CAAgB,IAAI;AACpB,YAAM,gBAAgB,MAAM,6BAAY,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;AACjB,kBAAQ,IAAI,SAAS,IAAI;AACzB,kBAAQ,SAAS;AAAA,QACnB;AACA,gBAAQ,YAAY;AACpB,eAAO;AACP,uBAAe,SAAS,IAAI;AAAA,MAC9B;AAAA,IACF,UAAE;AACA,2CAAgB,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
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var selector_exports = {};
|
|
20
|
+
__export(selector_exports, {
|
|
21
|
+
selector: () => selector,
|
|
22
|
+
useSelector: () => useSelector
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(selector_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_comparators = require("./comparators");
|
|
27
|
+
var import_constants = require("./constants");
|
|
28
|
+
var import_useStore = require("./useStore");
|
|
29
|
+
const logUpdate = process.env.NODE_ENV === "development" ? (fn, stores, last, next) => {
|
|
30
|
+
const getStoreLogName = (store) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const str = store[import_constants.UNWRAP_PROXY] ?? store;
|
|
33
|
+
return `${str.constructor.name}${((_a = store.props) == null ? void 0 : _a.id) ? `:${store.props.id}` : ""}`;
|
|
34
|
+
};
|
|
35
|
+
const storeNames = stores.map(getStoreLogName).join(", ");
|
|
36
|
+
const name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
|
|
37
|
+
console.groupCollapsed(name, "color: tomato;");
|
|
38
|
+
console.groupCollapsed("trace >");
|
|
39
|
+
console.trace();
|
|
40
|
+
console.groupEnd();
|
|
41
|
+
console.log(" next", next);
|
|
42
|
+
console.groupEnd();
|
|
43
|
+
} : null;
|
|
44
|
+
function selector(fn) {
|
|
45
|
+
let prev = runStoreSelector(fn);
|
|
46
|
+
let disposeValue = null;
|
|
47
|
+
const subscribe = () => {
|
|
48
|
+
return subscribeToStores([...prev.stores], () => {
|
|
49
|
+
try {
|
|
50
|
+
disposeValue == null ? void 0 : disposeValue();
|
|
51
|
+
(0, import_useStore.setIsInReaction)(true);
|
|
52
|
+
const next = runStoreSelector(fn);
|
|
53
|
+
if (typeof next.value === "function") {
|
|
54
|
+
disposeValue = next.value;
|
|
55
|
+
if (process.env.NODE_ENV === "development") {
|
|
56
|
+
logUpdate(fn, [...next.stores], "(fn)", "(fn)");
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prev.stores, next.stores) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (process.env.NODE_ENV === "development") {
|
|
64
|
+
logUpdate(fn, [...next.stores], prev.value, next.value);
|
|
65
|
+
}
|
|
66
|
+
prev = next;
|
|
67
|
+
dispose();
|
|
68
|
+
dispose = subscribe();
|
|
69
|
+
} finally {
|
|
70
|
+
(0, import_useStore.setIsInReaction)(false);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
let dispose = subscribe();
|
|
75
|
+
return () => {
|
|
76
|
+
dispose();
|
|
77
|
+
disposeValue == null ? void 0 : disposeValue();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function useSelector(fn) {
|
|
81
|
+
const [state, setState] = (0, import_react.useState)(() => {
|
|
82
|
+
return runStoreSelector(fn);
|
|
83
|
+
});
|
|
84
|
+
(0, import_react.useEffect)(() => {
|
|
85
|
+
let dispose;
|
|
86
|
+
const unsub = subscribeToStores([...state.stores], () => {
|
|
87
|
+
dispose == null ? void 0 : dispose();
|
|
88
|
+
const next = runStoreSelector(fn);
|
|
89
|
+
if (typeof next.value === "function") {
|
|
90
|
+
if (process.env.NODE_ENV === "development") {
|
|
91
|
+
logUpdate(fn, [...next.stores], "(fn)", "(fn)");
|
|
92
|
+
}
|
|
93
|
+
dispose = next.value;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
setState((prev) => {
|
|
97
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prev.stores, next.stores) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
98
|
+
return prev;
|
|
99
|
+
}
|
|
100
|
+
if (process.env.NODE_ENV === "development") {
|
|
101
|
+
logUpdate(fn, [...next.stores], prev.value, next.value);
|
|
102
|
+
}
|
|
103
|
+
return next;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return () => {
|
|
107
|
+
unsub();
|
|
108
|
+
dispose == null ? void 0 : dispose();
|
|
109
|
+
};
|
|
110
|
+
}, [...state.stores]);
|
|
111
|
+
return state.value;
|
|
112
|
+
}
|
|
113
|
+
function runStoreSelector(selector2) {
|
|
114
|
+
const stores = /* @__PURE__ */ new Set();
|
|
115
|
+
const dispose = (0, import_useStore.trackStoresAccess)((store) => {
|
|
116
|
+
stores.add(store);
|
|
117
|
+
});
|
|
118
|
+
const value = selector2();
|
|
119
|
+
dispose();
|
|
120
|
+
return {
|
|
121
|
+
value,
|
|
122
|
+
stores
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function subscribeToStores(stores, onUpdate) {
|
|
126
|
+
const disposes = [];
|
|
127
|
+
for (const store of stores) {
|
|
128
|
+
disposes.push(store.subscribe(onUpdate));
|
|
129
|
+
}
|
|
130
|
+
return () => {
|
|
131
|
+
disposes.forEach((x) => x());
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
selector,
|
|
137
|
+
useSelector
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=selector.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/selector.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoC;AAEpC,yBAAqC;AACrC,uBAA6B;AAC7B,sBAAmD;AAInD,MAAM,YACJ,QAAQ,IAAI,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