cross-state 0.6.6 → 0.6.7
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/_virtual/use-sync-external-store-with-selector.development.cjs +103 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs.map +1 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs +5 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs.map +1 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs +71 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs.map +1 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs +5 -0
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs.map +1 -0
- package/dist/cjs/_virtual/with-selector.cjs +12 -0
- package/dist/cjs/_virtual/with-selector.cjs.map +1 -0
- package/dist/cjs/_virtual/with-selector2.cjs +13 -0
- package/dist/cjs/_virtual/with-selector2.cjs.map +1 -0
- package/dist/cjs/core/cache.cjs +227 -0
- package/dist/cjs/core/cache.cjs.map +1 -0
- package/dist/cjs/core/resourceGroup.cjs +53 -0
- package/dist/cjs/core/resourceGroup.cjs.map +1 -0
- package/dist/cjs/core/store.cjs +259 -0
- package/dist/cjs/core/store.cjs.map +1 -0
- package/dist/cjs/immer/immerActions.cjs +10 -0
- package/dist/cjs/immer/immerActions.cjs.map +1 -0
- package/dist/cjs/immer.cjs +2 -7
- package/dist/cjs/immer.cjs.map +1 -1
- package/dist/cjs/index.cjs +19 -299
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/calcDuration.cjs +9 -0
- package/dist/cjs/lib/calcDuration.cjs.map +1 -0
- package/dist/cjs/lib/calculationHelper.cjs +140 -0
- package/dist/cjs/lib/calculationHelper.cjs.map +1 -0
- package/dist/cjs/lib/callable.cjs +11 -0
- package/dist/cjs/lib/callable.cjs.map +1 -0
- package/dist/cjs/lib/clone.cjs +19 -0
- package/dist/cjs/lib/clone.cjs.map +1 -0
- package/dist/cjs/lib/debounce.cjs +28 -0
- package/dist/cjs/lib/debounce.cjs.map +1 -0
- package/dist/cjs/lib/equals.cjs +5 -0
- package/dist/cjs/lib/equals.cjs.map +1 -0
- package/dist/cjs/lib/forwardError.cjs +9 -0
- package/dist/cjs/lib/forwardError.cjs.map +1 -0
- package/dist/cjs/lib/hash.cjs +19 -0
- package/dist/cjs/lib/hash.cjs.map +1 -0
- package/dist/cjs/lib/instanceCache.cjs +68 -0
- package/dist/cjs/lib/instanceCache.cjs.map +1 -0
- package/dist/cjs/lib/makeSelector.cjs +14 -0
- package/dist/cjs/lib/makeSelector.cjs.map +1 -0
- package/dist/cjs/lib/propAccess.cjs +66 -0
- package/dist/cjs/lib/propAccess.cjs.map +1 -0
- package/dist/cjs/lib/queue.cjs +61 -0
- package/dist/cjs/lib/queue.cjs.map +1 -0
- package/dist/cjs/lib/standardMethods.cjs +78 -0
- package/dist/cjs/lib/standardMethods.cjs.map +1 -0
- package/dist/cjs/lib/throttle.cjs +25 -0
- package/dist/cjs/lib/throttle.cjs.map +1 -0
- package/dist/cjs/lib/trackingProxy.cjs +39 -0
- package/dist/cjs/lib/trackingProxy.cjs.map +1 -0
- package/dist/cjs/react/read.cjs +15 -0
- package/dist/cjs/react/read.cjs.map +1 -0
- package/dist/cjs/react/storeScope.cjs +31 -0
- package/dist/cjs/react/storeScope.cjs.map +1 -0
- package/dist/cjs/react/useCache.cjs +31 -0
- package/dist/cjs/react/useCache.cjs.map +1 -0
- package/dist/cjs/react/useProp.cjs +9 -0
- package/dist/cjs/react/useProp.cjs.map +1 -0
- package/dist/cjs/react/useStore.cjs +51 -0
- package/dist/cjs/react/useStore.cjs.map +1 -0
- package/dist/cjs/react.cjs +11 -289
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js +103 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js.map +1 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js +5 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js.map +1 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js +71 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js.map +1 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js +5 -0
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js.map +1 -0
- package/dist/es/_virtual/with-selector.js +11 -0
- package/dist/es/_virtual/with-selector.js.map +1 -0
- package/dist/es/_virtual/with-selector2.js +14 -0
- package/dist/es/_virtual/with-selector2.js.map +1 -0
- package/dist/es/core/cache.js +227 -0
- package/dist/es/core/cache.js.map +1 -0
- package/dist/es/core/resourceGroup.js +53 -0
- package/dist/es/core/resourceGroup.js.map +1 -0
- package/dist/es/core/store.js +259 -0
- package/dist/es/core/store.js.map +1 -0
- package/dist/es/{immer.mjs → immer/immerActions.js} +1 -1
- package/dist/es/immer/immerActions.js.map +1 -0
- package/dist/es/immer.js +5 -0
- package/dist/es/immer.js.map +1 -0
- package/dist/es/index.js +22 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/lib/calcDuration.js +9 -0
- package/dist/es/lib/calcDuration.js.map +1 -0
- package/dist/es/lib/calculationHelper.js +140 -0
- package/dist/es/lib/calculationHelper.js.map +1 -0
- package/dist/es/lib/callable.js +11 -0
- package/dist/es/lib/callable.js.map +1 -0
- package/dist/es/lib/clone.js +19 -0
- package/dist/es/lib/clone.js.map +1 -0
- package/dist/es/lib/debounce.js +28 -0
- package/dist/es/lib/debounce.js.map +1 -0
- package/dist/es/lib/equals.js +5 -0
- package/dist/es/lib/equals.js.map +1 -0
- package/dist/es/lib/forwardError.js +9 -0
- package/dist/es/lib/forwardError.js.map +1 -0
- package/dist/es/lib/hash.js +19 -0
- package/dist/es/lib/hash.js.map +1 -0
- package/dist/es/lib/instanceCache.js +68 -0
- package/dist/es/lib/instanceCache.js.map +1 -0
- package/dist/es/lib/makeSelector.js +14 -0
- package/dist/es/lib/makeSelector.js.map +1 -0
- package/dist/es/lib/propAccess.js +66 -0
- package/dist/es/lib/propAccess.js.map +1 -0
- package/dist/es/lib/queue.js +61 -0
- package/dist/es/lib/queue.js.map +1 -0
- package/dist/es/lib/standardMethods.js +78 -0
- package/dist/es/lib/standardMethods.js.map +1 -0
- package/dist/es/lib/throttle.js +25 -0
- package/dist/es/lib/throttle.js.map +1 -0
- package/dist/es/lib/trackingProxy.js +39 -0
- package/dist/es/lib/trackingProxy.js.map +1 -0
- package/dist/es/react/read.js +15 -0
- package/dist/es/react/read.js.map +1 -0
- package/dist/es/react/storeScope.js +31 -0
- package/dist/es/react/storeScope.js.map +1 -0
- package/dist/es/react/useCache.js +31 -0
- package/dist/es/react/useCache.js.map +1 -0
- package/dist/es/react/useProp.js +9 -0
- package/dist/es/react/useProp.js.map +1 -0
- package/dist/es/react/useStore.js +51 -0
- package/dist/es/react/useStore.js.map +1 -0
- package/dist/es/react.js +14 -0
- package/dist/es/react.js.map +1 -0
- package/dist/types/core/cache.d.ts +13 -11
- package/dist/types/core/store.d.ts +5 -3
- package/dist/types/lib/callable.d.ts +4 -0
- package/dist/types/lib/instanceCache.d.ts +2 -2
- package/package.json +8 -8
- package/dist/cjs/hash.cjs +0 -718
- package/dist/cjs/hash.cjs.map +0 -1
- package/dist/es/hash.mjs +0 -719
- package/dist/es/hash.mjs.map +0 -1
- package/dist/es/immer.mjs.map +0 -1
- package/dist/es/index.mjs +0 -303
- package/dist/es/index.mjs.map +0 -1
- package/dist/es/react.mjs +0 -292
- package/dist/es/react.mjs.map +0 -1
- package/dist/types/lib/bind.d.ts +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createArrayAction = (prop) => function arrayAction(...args) {
|
|
4
|
+
const newArray = this.get().slice();
|
|
5
|
+
const result = newArray[prop](...args);
|
|
6
|
+
this.set(newArray);
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
const arrayMethods = {
|
|
10
|
+
splice: createArrayAction("splice"),
|
|
11
|
+
push: createArrayAction("push"),
|
|
12
|
+
pop: createArrayAction("pop"),
|
|
13
|
+
shift: createArrayAction("shift"),
|
|
14
|
+
unshift: createArrayAction("unshift"),
|
|
15
|
+
reverse: createArrayAction("reverse"),
|
|
16
|
+
sort: createArrayAction("sort")
|
|
17
|
+
};
|
|
18
|
+
const recordMethods = {
|
|
19
|
+
// set<T extends Record<any, any>, P extends Path<T>>(
|
|
20
|
+
// this: Store<T>,
|
|
21
|
+
// path: P,
|
|
22
|
+
// value: Update<Value<T, P>>,
|
|
23
|
+
// ) {
|
|
24
|
+
// if (value instanceof Function) {
|
|
25
|
+
// value = value(get(this.get(), path));
|
|
26
|
+
// }
|
|
27
|
+
// this.set(set(this.get(), path, value));
|
|
28
|
+
// return this;
|
|
29
|
+
// },
|
|
30
|
+
delete(key) {
|
|
31
|
+
const copy = { ...this.get() };
|
|
32
|
+
delete copy[key];
|
|
33
|
+
this.set(copy);
|
|
34
|
+
},
|
|
35
|
+
clear() {
|
|
36
|
+
this.set({});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const mapMethods = {
|
|
40
|
+
// set<K, V>(this: Store<Map<K, V>>, key: K, value: UpdateFrom<V, [V | undefined]>) {
|
|
41
|
+
// if (value instanceof Function) {
|
|
42
|
+
// value = value(this.get().get(key));
|
|
43
|
+
// }
|
|
44
|
+
// const newMap = new Map(this.get());
|
|
45
|
+
// newMap.set(key, value);
|
|
46
|
+
// this.set(newMap);
|
|
47
|
+
// return this;
|
|
48
|
+
// },
|
|
49
|
+
delete(key) {
|
|
50
|
+
const newMap = new Map(this.get());
|
|
51
|
+
const result = newMap.delete(key);
|
|
52
|
+
this.set(newMap);
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
clear() {
|
|
56
|
+
this.set(/* @__PURE__ */ new Map());
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const setMethods = {
|
|
60
|
+
add(value) {
|
|
61
|
+
const newSet = new Set(this.get());
|
|
62
|
+
newSet.add(value);
|
|
63
|
+
this.set(newSet);
|
|
64
|
+
},
|
|
65
|
+
delete(value) {
|
|
66
|
+
const newSet = new Set(this.get());
|
|
67
|
+
newSet.delete(value);
|
|
68
|
+
this.set(newSet);
|
|
69
|
+
},
|
|
70
|
+
clear() {
|
|
71
|
+
this.set(/* @__PURE__ */ new Set());
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.arrayMethods = arrayMethods;
|
|
75
|
+
exports.mapMethods = mapMethods;
|
|
76
|
+
exports.recordMethods = recordMethods;
|
|
77
|
+
exports.setMethods = setMethods;
|
|
78
|
+
//# sourceMappingURL=standardMethods.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardMethods.cjs","sources":["../../../src/lib/standardMethods.ts"],"sourcesContent":["import type { Store } from '../core/store';\nimport type { OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nconst createArrayAction = <P extends keyof Array<any>>(prop: P) =>\n function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n\nexport const arrayMethods = {\n splice: createArrayAction('splice'),\n push: createArrayAction('push'),\n pop: createArrayAction('pop'),\n shift: createArrayAction('shift'),\n unshift: createArrayAction('unshift'),\n reverse: createArrayAction('reverse'),\n sort: createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n // set<T extends Record<any, any>, P extends Path<T>>(\n // this: Store<T>,\n // path: P,\n // value: Update<Value<T, P>>,\n // ) {\n // if (value instanceof Function) {\n // value = value(get(this.get(), path));\n // }\n\n // this.set(set(this.get(), path, value));\n // return this;\n // },\n\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(this: Store<T>, key: K) {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(this: Store<Partial<T>>) {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n // set<K, V>(this: Store<Map<K, V>>, key: K, value: UpdateFrom<V, [V | undefined]>) {\n // if (value instanceof Function) {\n // value = value(this.get().get(key));\n // }\n\n // const newMap = new Map(this.get());\n // newMap.set(key, value);\n // this.set(newMap);\n // return this;\n // },\n\n delete<K, V>(this: Store<Map<K, V>>, key: K) {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>) {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T) {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T) {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>) {\n this.set(new Set());\n },\n};\n"],"names":[],"mappings":";;AAKA,MAAM,oBAAoB,CAA6B,SACrD,SAAS,eAEJ,MACgD;AACnD,QAAM,WAAW,KAAK,IAAI,EAAE,MAAM;AAClC,QAAM,SAAU,SAAS,IAAI,EAAgB,GAAI,IAAY;AAC7D,OAAK,IAAI,QAAQ;AACV,SAAA;AACT;AAEK,MAAM,eAAe;AAAA,EAC1B,QAAQ,kBAAkB,QAAQ;AAAA,EAClC,MAAM,kBAAkB,MAAM;AAAA,EAC9B,KAAK,kBAAkB,KAAK;AAAA,EAC5B,OAAO,kBAAkB,OAAO;AAAA,EAChC,SAAS,kBAAkB,SAAS;AAAA,EACpC,SAAS,kBAAkB,SAAS;AAAA,EACpC,MAAM,kBAAkB,MAAM;AAChC;AAEO,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc3B,OAAoF,KAAQ;AAC1F,UAAM,OAAO,EAAE,GAAG,KAAK,IAAM,EAAA;AAC7B,WAAO,KAAK,GAAG;AACf,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,QAA2D;AACpD,SAAA,IAAI,CAAA,CAAO;AAAA,EAClB;AACF;AAEO,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYxB,OAAqC,KAAQ;AAC3C,UAAM,SAAS,IAAI,IAAI,KAAK,IAAK,CAAA;AAC3B,UAAA,SAAS,OAAO,OAAO,GAAG;AAChC,SAAK,IAAI,MAAM;AACR,WAAA;AAAA,EACT;AAAA,EAEA,QAAoC;AAC7B,SAAA,IAAQ,oBAAA,IAAA,CAAK;AAAA,EACpB;AACF;AAEO,MAAM,aAAa;AAAA,EACxB,IAA4B,OAAU;AACpC,UAAM,SAAS,IAAI,IAAI,KAAK,IAAK,CAAA;AACjC,WAAO,IAAI,KAAK;AAChB,SAAK,IAAI,MAAM;AAAA,EACjB;AAAA,EAEA,OAA+B,OAAU;AACvC,UAAM,SAAS,IAAI,IAAI,KAAK,IAAK,CAAA;AACjC,WAAO,OAAO,KAAK;AACnB,SAAK,IAAI,MAAM;AAAA,EACjB;AAAA,EAEA,QAA8B;AACvB,SAAA,IAAQ,oBAAA,IAAA,CAAK;AAAA,EACpB;AACF;;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const calcDuration = require("./calcDuration.cjs");
|
|
4
|
+
function throttle(action, duration) {
|
|
5
|
+
const ms = calcDuration.calcDuration(duration);
|
|
6
|
+
let t = 0;
|
|
7
|
+
let timeout;
|
|
8
|
+
return (...args) => {
|
|
9
|
+
if (timeout !== void 0) {
|
|
10
|
+
clearTimeout(timeout);
|
|
11
|
+
}
|
|
12
|
+
const dt = t + ms - Date.now();
|
|
13
|
+
if (dt <= 0) {
|
|
14
|
+
action(...args);
|
|
15
|
+
t = Date.now();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
timeout = setTimeout(() => {
|
|
19
|
+
action(...args);
|
|
20
|
+
t = Date.now();
|
|
21
|
+
}, dt);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.throttle = throttle;
|
|
25
|
+
//# sourceMappingURL=throttle.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.cjs","sources":["../../../src/lib/throttle.ts"],"sourcesContent":["import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n"],"names":["calcDuration"],"mappings":";;;AAGgB,SAAA,SACd,QACA,UACyB;AACnB,QAAA,KAAKA,0BAAa,QAAQ;AAEhC,MAAI,IAAI;AACJ,MAAA;AAEJ,SAAO,IAAI,SAAe;AACxB,QAAI,YAAY,QAAW;AACzB,mBAAa,OAAO;AAAA,IACtB;AAEA,UAAM,KAAK,IAAI,KAAK,KAAK,IAAI;AAC7B,QAAI,MAAM,GAAG;AACX,aAAO,GAAG,IAAI;AACd,UAAI,KAAK;AACT;AAAA,IACF;AAEA,cAAU,WAAW,MAAM;AACzB,aAAO,GAAG,IAAI;AACd,UAAI,KAAK;OACR,EAAE;AAAA,EAAA;AAET;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ProxyKeys = [
|
|
4
|
+
"get",
|
|
5
|
+
"getOwnPropertyDescriptor",
|
|
6
|
+
"getPrototypeOf",
|
|
7
|
+
"has",
|
|
8
|
+
"isExtensible",
|
|
9
|
+
"ownKeys"
|
|
10
|
+
];
|
|
11
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
12
|
+
function trackingProxy(value) {
|
|
13
|
+
if (!isPlainObject(value) && !Array.isArray(value)) {
|
|
14
|
+
return [value, (other) => other === value];
|
|
15
|
+
}
|
|
16
|
+
const deps = new Array();
|
|
17
|
+
const proxy = new Proxy(
|
|
18
|
+
value,
|
|
19
|
+
Object.fromEntries(
|
|
20
|
+
ProxyKeys.map((key) => [
|
|
21
|
+
key,
|
|
22
|
+
(currentValue, ...args) => {
|
|
23
|
+
const function_ = Reflect[key];
|
|
24
|
+
const [proxiedValue, equals] = trackingProxy(function_(currentValue, ...args));
|
|
25
|
+
deps.push((otherValue) => {
|
|
26
|
+
if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return equals(function_(otherValue, ...args));
|
|
30
|
+
});
|
|
31
|
+
return proxiedValue;
|
|
32
|
+
}
|
|
33
|
+
])
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
return [proxy, (other) => !!other && deps.every((equals) => equals(other))];
|
|
37
|
+
}
|
|
38
|
+
exports.trackingProxy = trackingProxy;
|
|
39
|
+
//# sourceMappingURL=trackingProxy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackingProxy.cjs","sources":["../../../src/lib/trackingProxy.ts"],"sourcesContent":["export type TrackingProxy<T> = [value: T, equals: (newValue: T) => boolean];\ntype Object_ = Record<string | symbol, unknown>;\n\nconst ProxyKeys = [\n 'get',\n 'getOwnPropertyDescriptor',\n 'getPrototypeOf',\n 'has',\n 'isExtensible',\n 'ownKeys',\n] as const;\n\nconst isPlainObject = (value: unknown) =>\n typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype;\n\nexport function trackingProxy<T>(value: T): TrackingProxy<T> {\n if (!isPlainObject(value) && !Array.isArray(value)) {\n return [value, (other) => other === value];\n }\n\n const deps = new Array<TrackingProxy<any>[1]>();\n\n const proxy = new Proxy(\n value as T & Object_,\n Object.fromEntries(\n ProxyKeys.map((key) => [\n key,\n (currentValue: T & Object_, ...args: any[]) => {\n const function_ = Reflect[key] as any;\n const [proxiedValue, equals] = trackingProxy(function_(currentValue, ...args));\n\n deps.push((otherValue) => {\n if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {\n return false;\n }\n\n return equals(function_(otherValue, ...args));\n });\n\n return proxiedValue;\n },\n ]),\n ),\n );\n\n return [proxy, (other) => !!other && deps.every((equals) => equals(other))];\n}\n"],"names":[],"mappings":";;AAGA,MAAM,YAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,gBAAgB,CAAC,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,eAAe,KAAK,MAAM,OAAO;AAElF,SAAS,cAAiB,OAA4B;AACvD,MAAA,CAAC,cAAc,KAAK,KAAK,CAAC,MAAM,QAAQ,KAAK,GAAG;AAClD,WAAO,CAAC,OAAO,CAAC,UAAU,UAAU,KAAK;AAAA,EAC3C;AAEM,QAAA,OAAO,IAAI;AAEjB,QAAM,QAAQ,IAAI;AAAA,IAChB;AAAA,IACA,OAAO;AAAA,MACL,UAAU,IAAI,CAAC,QAAQ;AAAA,QACrB;AAAA,QACA,CAAC,iBAA8B,SAAgB;AACvC,gBAAA,YAAY,QAAQ,GAAG;AACvB,gBAAA,CAAC,cAAc,MAAM,IAAI,cAAc,UAAU,cAAc,GAAG,IAAI,CAAC;AAExE,eAAA,KAAK,CAAC,eAAe;AACpB,gBAAA,CAAC,cAAc,UAAU,KAAK,CAAC,MAAM,QAAQ,UAAU,GAAG;AACrD,qBAAA;AAAA,YACT;AAEA,mBAAO,OAAO,UAAU,YAAY,GAAG,IAAI,CAAC;AAAA,UAAA,CAC7C;AAEM,iBAAA;AAAA,QACT;AAAA,MAAA,CACD;AAAA,IACH;AAAA,EAAA;AAGF,SAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,SAAS,KAAK,MAAM,CAAC,WAAW,OAAO,KAAK,CAAC,CAAC;AAC5E;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const useCache = require("./useCache.cjs");
|
|
4
|
+
function read(cache, options) {
|
|
5
|
+
const { status, value, error } = useCache.useCache(cache, options);
|
|
6
|
+
if (status === "value") {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
if (status === "error") {
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
throw cache.state.once((state) => state.status !== "pending");
|
|
13
|
+
}
|
|
14
|
+
exports.read = read;
|
|
15
|
+
//# sourceMappingURL=read.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.cjs","sources":["../../../src/react/read.ts"],"sourcesContent":["import { useCache } from './useCache';\nimport type { UseStoreOptions } from './useStore';\nimport type { Cache } from '@core';\n\nexport function read<T>(cache: Cache<T>, options?: UseStoreOptions): T {\n const { status, value, error } = useCache(cache, options);\n\n if (status === 'value') {\n return value;\n }\n\n if (status === 'error') {\n throw error;\n }\n\n throw cache.state.once((state) => state.status !== 'pending');\n}\n"],"names":["useCache"],"mappings":";;;AAIgB,SAAA,KAAQ,OAAiB,SAA8B;AACrE,QAAM,EAAE,QAAQ,OAAO,MAAU,IAAAA,kBAAS,OAAO,OAAO;AAExD,MAAI,WAAW,SAAS;AACf,WAAA;AAAA,EACT;AAEA,MAAI,WAAW,SAAS;AAChB,UAAA;AAAA,EACR;AAEA,QAAM,MAAM,MAAM,KAAK,CAAC,UAAU,MAAM,WAAW,SAAS;AAC9D;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const store = require("../core/store.cjs");
|
|
6
|
+
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function getStoreScopeContext(scope) {
|
|
8
|
+
let context = contextMap.get(scope);
|
|
9
|
+
if (!context) {
|
|
10
|
+
context = require$$0.createContext(store.createStore(scope.defaultValue));
|
|
11
|
+
contextMap.set(scope, context);
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
function StoreScopeProvider({ scope, store: inputStore, children }) {
|
|
16
|
+
const context = getStoreScopeContext(scope);
|
|
17
|
+
const currentStore = require$$0.useMemo(
|
|
18
|
+
() => inputStore ?? store.createStore(scope.defaultValue),
|
|
19
|
+
[scope, inputStore]
|
|
20
|
+
);
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsx(context.Provider, { value: currentStore, children });
|
|
22
|
+
}
|
|
23
|
+
function useStoreScope(scope) {
|
|
24
|
+
const context = getStoreScopeContext(scope);
|
|
25
|
+
return require$$0.useContext(context);
|
|
26
|
+
}
|
|
27
|
+
exports.StoreScopeProvider = StoreScopeProvider;
|
|
28
|
+
exports.contextMap = contextMap;
|
|
29
|
+
exports.getStoreScopeContext = getStoreScopeContext;
|
|
30
|
+
exports.useStoreScope = useStoreScope;
|
|
31
|
+
//# sourceMappingURL=storeScope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeScope.cjs","sources":["../../../src/react/storeScope.tsx"],"sourcesContent":["import type { Context, ReactNode } from 'react';\nimport { createContext, useContext, useMemo } from 'react';\nimport type { Store } from '@core/store';\nimport { createStore } from '@core/store';\nimport type { StoreScope } from '@core/storeScope';\n\nexport type StoreScopeProps<T> = { scope: StoreScope<T>; store?: Store<T>; children?: ReactNode };\n\nexport const contextMap = new WeakMap<StoreScope<any>, Context<Store<any>>>();\n\nexport function getStoreScopeContext<T>(scope: StoreScope<T>): Context<Store<T>> {\n let context = contextMap.get(scope);\n\n if (!context) {\n context = createContext<Store<T>>(createStore(scope.defaultValue));\n contextMap.set(scope, context);\n }\n\n return context;\n}\n\nexport function StoreScopeProvider<T>({ scope, store: inputStore, children }: StoreScopeProps<T>) {\n const context = getStoreScopeContext(scope);\n const currentStore = useMemo(\n () => inputStore ?? createStore(scope.defaultValue),\n [scope, inputStore],\n );\n\n return <context.Provider value={currentStore}>{children}</context.Provider>;\n}\n\nexport function useStoreScope<T>(scope: StoreScope<T>): Store<T> {\n const context = getStoreScopeContext(scope);\n return useContext(context);\n}\n"],"names":["createContext","createStore","useMemo","useContext"],"mappings":";;;;;AAQa,MAAA,iCAAiB,QAA8C;AAErE,SAAS,qBAAwB,OAAyC;AAC3E,MAAA,UAAU,WAAW,IAAI,KAAK;AAElC,MAAI,CAAC,SAAS;AACZ,cAAUA,WAAAA,cAAwBC,MAAAA,YAAY,MAAM,YAAY,CAAC;AACtD,eAAA,IAAI,OAAO,OAAO;AAAA,EAC/B;AAEO,SAAA;AACT;AAEO,SAAS,mBAAsB,EAAE,OAAO,OAAO,YAAY,YAAgC;AAC1F,QAAA,UAAU,qBAAqB,KAAK;AAC1C,QAAM,eAAeC,WAAA;AAAA,IACnB,MAAM,cAAcD,MAAAA,YAAY,MAAM,YAAY;AAAA,IAClD,CAAC,OAAO,UAAU;AAAA,EAAA;AAGpB,wCAAQ,QAAQ,UAAR,EAAiB,OAAO,cAAe,SAAS,CAAA;AAC1D;AAEO,SAAS,cAAiB,OAAgC;AACzD,QAAA,UAAU,qBAAqB,KAAK;AAC1C,SAAOE,WAAAA,WAAW,OAAO;AAC3B;;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require$$0 = require("react");
|
|
4
|
+
const useStore = require("./useStore.cjs");
|
|
5
|
+
const makeSelector = require("../lib/makeSelector.cjs");
|
|
6
|
+
function useCache(cache, { passive, ...options } = {}) {
|
|
7
|
+
const mappedState = require$$0.useMemo(() => {
|
|
8
|
+
var _a;
|
|
9
|
+
const rootCache = ((_a = cache.derivedFromCache) == null ? void 0 : _a.cache) ?? cache;
|
|
10
|
+
let selector = (x) => x;
|
|
11
|
+
if (cache.derivedFromCache) {
|
|
12
|
+
selector = (value) => {
|
|
13
|
+
for (const s of cache.derivedFromCache.selectors) {
|
|
14
|
+
value = makeSelector.makeSelector(s)(value);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return rootCache.state.map((state) => {
|
|
20
|
+
const value = state.status === "value" ? selector(state.value) : void 0;
|
|
21
|
+
return Object.assign(
|
|
22
|
+
[value, state.error, state.isUpdating, state.isStale],
|
|
23
|
+
{ ...state, value }
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
}, [cache]);
|
|
27
|
+
require$$0.useEffect(() => !passive ? cache.sub(() => void 0) : void 0, [cache, passive]);
|
|
28
|
+
return useStore.useStore(mappedState, options);
|
|
29
|
+
}
|
|
30
|
+
exports.useCache = useCache;
|
|
31
|
+
//# sourceMappingURL=useCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCache.cjs","sources":["../../../src/react/useCache.ts"],"sourcesContent":["import { useEffect, useMemo } from 'react';\nimport type { UseStoreOptions } from './useStore';\nimport { useStore } from './useStore';\nimport type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\n\nexport type UseCacheArray<T> = [\n value: T | undefined,\n error: unknown | undefined,\n isUpdating: boolean,\n isStale: boolean,\n];\n\nexport type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;\n\nexport interface UseCacheOptions extends UseStoreOptions {\n passive?: boolean;\n}\n\nexport function useCache<T>(\n cache: Cache<T>,\n { passive, ...options }: UseCacheOptions = {},\n): UseCacheValue<T> {\n const mappedState = useMemo(() => {\n const rootCache: Cache<any> = cache.derivedFromCache?.cache ?? cache;\n let selector = (x: any) => x;\n\n if (cache.derivedFromCache) {\n selector = (value: any) => {\n for (const s of cache.derivedFromCache!.selectors) {\n value = makeSelector(s)(value);\n }\n return value;\n };\n }\n\n return rootCache.state.map((state) => {\n const value = state.status === 'value' ? selector(state.value) : undefined;\n\n return Object.assign<UseCacheArray<T>, CacheState<T>>(\n [value, state.error, state.isUpdating, state.isStale],\n { ...state, value },\n );\n });\n }, [cache]);\n\n useEffect(() => (!passive ? cache.sub(() => undefined) : undefined), [cache, passive]);\n\n return useStore(mappedState, options);\n}\n"],"names":["useMemo","makeSelector","useEffect","useStore"],"mappings":";;;;;AAoBgB,SAAA,SACd,OACA,EAAE,SAAS,GAAG,QAAQ,IAAqB,CAAA,GACzB;AACZ,QAAA,cAAcA,WAAAA,QAAQ,MAAM;;AAC1B,UAAA,cAAwB,WAAM,qBAAN,mBAAwB,UAAS;AAC3D,QAAA,WAAW,CAAC,MAAW;AAE3B,QAAI,MAAM,kBAAkB;AAC1B,iBAAW,CAAC,UAAe;AACd,mBAAA,KAAK,MAAM,iBAAkB,WAAW;AACzC,kBAAAC,aAAA,aAAa,CAAC,EAAE,KAAK;AAAA,QAC/B;AACO,eAAA;AAAA,MAAA;AAAA,IAEX;AAEA,WAAO,UAAU,MAAM,IAAI,CAAC,UAAU;AACpC,YAAM,QAAQ,MAAM,WAAW,UAAU,SAAS,MAAM,KAAK,IAAI;AAEjE,aAAO,OAAO;AAAA,QACZ,CAAC,OAAO,MAAM,OAAO,MAAM,YAAY,MAAM,OAAO;AAAA,QACpD,EAAE,GAAG,OAAO,MAAM;AAAA,MAAA;AAAA,IACpB,CACD;AAAA,EAAA,GACA,CAAC,KAAK,CAAC;AAEVC,aAAAA,UAAU,MAAO,CAAC,UAAU,MAAM,IAAI,MAAM,MAAS,IAAI,QAAY,CAAC,OAAO,OAAO,CAAC;AAE9E,SAAAC,SAAA,SAAS,aAAa,OAAO;AACtC;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const useStore = require("./useStore.cjs");
|
|
4
|
+
function useProp(store, options) {
|
|
5
|
+
const value = useStore.useStore(store, options);
|
|
6
|
+
return [value, store.set];
|
|
7
|
+
}
|
|
8
|
+
exports.useProp = useProp;
|
|
9
|
+
//# sourceMappingURL=useProp.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProp.cjs","sources":["../../../src/react/useProp.ts"],"sourcesContent":["import type { UseStoreOptions } from './useStore';\nimport { useStore } from './useStore';\nimport type { Store } from '@core/store';\nimport type { UpdateFunction } from '@core/commonTypes';\n\nexport function useProp<T>(\n store: Store<T>,\n options?: UseStoreOptions,\n): [value: T, setValue: UpdateFunction<T>] {\n const value = useStore(store, options);\n\n return [value, store.set];\n}\n"],"names":["useStore"],"mappings":";;;AAKgB,SAAA,QACd,OACA,SACyC;AACnC,QAAA,QAAQA,SAAAA,SAAS,OAAO,OAAO;AAE9B,SAAA,CAAC,OAAO,MAAM,GAAG;AAC1B;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require$$0 = require("react");
|
|
4
|
+
require("../_virtual/with-selector.cjs");
|
|
5
|
+
const hash = require("../lib/hash.cjs");
|
|
6
|
+
const makeSelector = require("../lib/makeSelector.cjs");
|
|
7
|
+
const trackingProxy = require("../lib/trackingProxy.cjs");
|
|
8
|
+
const withSelector = require("../_virtual/with-selector2.cjs");
|
|
9
|
+
function useStore(store, options) {
|
|
10
|
+
const lastEqualsRef = require$$0.useRef();
|
|
11
|
+
const { rootStore, selector } = require$$0.useMemo(() => {
|
|
12
|
+
var _a;
|
|
13
|
+
const rootStore2 = ((_a = store.derivedFrom) == null ? void 0 : _a.store) ?? store;
|
|
14
|
+
let selector2 = (x) => x;
|
|
15
|
+
if (store.derivedFrom) {
|
|
16
|
+
selector2 = (value2) => {
|
|
17
|
+
for (const s of store.derivedFrom.selectors) {
|
|
18
|
+
value2 = makeSelector.makeSelector(s)(value2);
|
|
19
|
+
}
|
|
20
|
+
return value2;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return { rootStore: rootStore2, selector: selector2 };
|
|
24
|
+
}, [store]);
|
|
25
|
+
const subOptions = { ...options, runNow: false, equals: void 0, passive: false };
|
|
26
|
+
const subscribe = require$$0.useCallback(
|
|
27
|
+
(listener) => {
|
|
28
|
+
return rootStore.sub(listener, subOptions);
|
|
29
|
+
},
|
|
30
|
+
[rootStore, hash.hash(subOptions)]
|
|
31
|
+
);
|
|
32
|
+
const value = withSelector.exports.useSyncExternalStoreWithSelector(
|
|
33
|
+
//
|
|
34
|
+
subscribe,
|
|
35
|
+
rootStore.get,
|
|
36
|
+
void 0,
|
|
37
|
+
selector,
|
|
38
|
+
(options == null ? void 0 : options.equals) ?? ((_v, newValue) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return ((_a = lastEqualsRef.current) == null ? void 0 : _a.call(lastEqualsRef, newValue)) ?? false;
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
const [proxiedValue, equals] = trackingProxy.trackingProxy(value);
|
|
44
|
+
require$$0.useLayoutEffect(() => {
|
|
45
|
+
lastEqualsRef.current = equals;
|
|
46
|
+
});
|
|
47
|
+
require$$0.useDebugValue(value);
|
|
48
|
+
return proxiedValue;
|
|
49
|
+
}
|
|
50
|
+
exports.useStore = useStore;
|
|
51
|
+
//# sourceMappingURL=useStore.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.cjs","sources":["../../../src/react/useStore.ts"],"sourcesContent":["import { useCallback, useDebugValue, useLayoutEffect, useMemo, useRef } from 'react';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js';\nimport type { SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { hash } from '@lib/hash';\nimport { makeSelector } from '@lib/makeSelector';\nimport { trackingProxy } from '@lib/trackingProxy';\n\nexport type UseStoreOptions = Omit<SubscribeOptions, 'runNow' | 'passive'>;\n\nexport function useStore<T>(store: Store<T>, options?: UseStoreOptions): T {\n const lastEqualsRef = useRef<(newValue: T) => boolean>();\n\n const { rootStore, selector } = useMemo(() => {\n const rootStore = store.derivedFrom?.store ?? store;\n let selector = (x: any) => x;\n\n if (store.derivedFrom) {\n selector = (value: any) => {\n for (const s of store.derivedFrom!.selectors) {\n value = makeSelector(s)(value);\n }\n return value;\n };\n }\n\n return { rootStore, selector };\n }, [store]);\n\n const subOptions = { ...options, runNow: false, equals: undefined, passive: false };\n const subscribe = useCallback(\n (listener: () => void) => {\n return rootStore.sub(listener, subOptions);\n },\n [rootStore, hash(subOptions)],\n );\n\n const value = useSyncExternalStoreWithSelector<unknown, T>(\n //\n subscribe,\n rootStore.get,\n undefined,\n selector,\n options?.equals ?? ((_v, newValue) => lastEqualsRef.current?.(newValue) ?? false),\n );\n const [proxiedValue, equals] = trackingProxy(value);\n\n useLayoutEffect(() => {\n lastEqualsRef.current = equals;\n });\n\n useDebugValue(value);\n return proxiedValue;\n}\n"],"names":["useRef","useMemo","rootStore","selector","value","makeSelector","useCallback","hash","useSyncExternalStoreWithSelector","trackingProxy","useLayoutEffect","useDebugValue"],"mappings":";;;;;;;;AAUgB,SAAA,SAAY,OAAiB,SAA8B;AACzE,QAAM,gBAAgBA,WAAAA;AAEtB,QAAM,EAAE,WAAW,SAAS,IAAIC,mBAAQ,MAAM;;AACtCC,UAAAA,eAAY,WAAM,gBAAN,mBAAmB,UAAS;AAC1CC,QAAAA,YAAW,CAAC,MAAW;AAE3B,QAAI,MAAM,aAAa;AACrBA,kBAAW,CAACC,WAAe;AACd,mBAAA,KAAK,MAAM,YAAa,WAAW;AAC5CA,mBAAQC,aAAA,aAAa,CAAC,EAAED,MAAK;AAAA,QAC/B;AACOA,eAAAA;AAAAA,MAAA;AAAA,IAEX;AAEA,WAAO,EAAE,WAAAF,YAAW,UAAAC,UAAS;AAAA,EAAA,GAC5B,CAAC,KAAK,CAAC;AAEJ,QAAA,aAAa,EAAE,GAAG,SAAS,QAAQ,OAAO,QAAQ,QAAW,SAAS;AAC5E,QAAM,YAAYG,WAAA;AAAA,IAChB,CAAC,aAAyB;AACjB,aAAA,UAAU,IAAI,UAAU,UAAU;AAAA,IAC3C;AAAA,IACA,CAAC,WAAWC,UAAK,UAAU,CAAC;AAAA,EAAA;AAG9B,QAAM,QAAQC,aAAA,QAAA;AAAA;AAAA,IAEZ;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,KACA,mCAAS,YAAW,CAAC,IAAI,aAAa;;AAAA,kCAAc,YAAd,uCAAwB,cAAa;AAAA;AAAA,EAAA;AAE7E,QAAM,CAAC,cAAc,MAAM,IAAIC,4BAAc,KAAK;AAElDC,aAAAA,gBAAgB,MAAM;AACpB,kBAAc,UAAU;AAAA,EAAA,CACzB;AAEDC,aAAA,cAAc,KAAK;AACZ,SAAA;AACT;;"}
|
package/dist/cjs/react.cjs
CHANGED
|
@@ -1,292 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
var useSyncExternalStoreWithSelector_production_min = {};
|
|
16
|
-
/**
|
|
17
|
-
* @license React
|
|
18
|
-
* use-sync-external-store-with-selector.production.min.js
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the MIT license found in the
|
|
23
|
-
* LICENSE file in the root directory of this source tree.
|
|
24
|
-
*/
|
|
25
|
-
var hasRequiredUseSyncExternalStoreWithSelector_production_min;
|
|
26
|
-
function requireUseSyncExternalStoreWithSelector_production_min() {
|
|
27
|
-
if (hasRequiredUseSyncExternalStoreWithSelector_production_min)
|
|
28
|
-
return useSyncExternalStoreWithSelector_production_min;
|
|
29
|
-
hasRequiredUseSyncExternalStoreWithSelector_production_min = 1;
|
|
30
|
-
var g = require$$0;
|
|
31
|
-
function n(a, b) {
|
|
32
|
-
return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
|
|
33
|
-
}
|
|
34
|
-
var p = "function" === typeof Object.is ? Object.is : n, q = g.useSyncExternalStore, r = g.useRef, t = g.useEffect, u = g.useMemo, v = g.useDebugValue;
|
|
35
|
-
useSyncExternalStoreWithSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, h) {
|
|
36
|
-
var c = r(null);
|
|
37
|
-
if (null === c.current) {
|
|
38
|
-
var f = { hasValue: false, value: null };
|
|
39
|
-
c.current = f;
|
|
40
|
-
} else
|
|
41
|
-
f = c.current;
|
|
42
|
-
c = u(function() {
|
|
43
|
-
function a2(a3) {
|
|
44
|
-
if (!c2) {
|
|
45
|
-
c2 = true;
|
|
46
|
-
d2 = a3;
|
|
47
|
-
a3 = l(a3);
|
|
48
|
-
if (void 0 !== h && f.hasValue) {
|
|
49
|
-
var b2 = f.value;
|
|
50
|
-
if (h(b2, a3))
|
|
51
|
-
return k = b2;
|
|
52
|
-
}
|
|
53
|
-
return k = a3;
|
|
54
|
-
}
|
|
55
|
-
b2 = k;
|
|
56
|
-
if (p(d2, a3))
|
|
57
|
-
return b2;
|
|
58
|
-
var e2 = l(a3);
|
|
59
|
-
if (void 0 !== h && h(b2, e2))
|
|
60
|
-
return b2;
|
|
61
|
-
d2 = a3;
|
|
62
|
-
return k = e2;
|
|
63
|
-
}
|
|
64
|
-
var c2 = false, d2, k, m = void 0 === e ? null : e;
|
|
65
|
-
return [function() {
|
|
66
|
-
return a2(b());
|
|
67
|
-
}, null === m ? void 0 : function() {
|
|
68
|
-
return a2(m());
|
|
69
|
-
}];
|
|
70
|
-
}, [b, e, l, h]);
|
|
71
|
-
var d = q(a, c[0], c[1]);
|
|
72
|
-
t(function() {
|
|
73
|
-
f.hasValue = true;
|
|
74
|
-
f.value = d;
|
|
75
|
-
}, [d]);
|
|
76
|
-
v(d);
|
|
77
|
-
return d;
|
|
78
|
-
};
|
|
79
|
-
return useSyncExternalStoreWithSelector_production_min;
|
|
80
|
-
}
|
|
81
|
-
var useSyncExternalStoreWithSelector_development = {};
|
|
82
|
-
/**
|
|
83
|
-
* @license React
|
|
84
|
-
* use-sync-external-store-with-selector.development.js
|
|
85
|
-
*
|
|
86
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
87
|
-
*
|
|
88
|
-
* This source code is licensed under the MIT license found in the
|
|
89
|
-
* LICENSE file in the root directory of this source tree.
|
|
90
|
-
*/
|
|
91
|
-
var hasRequiredUseSyncExternalStoreWithSelector_development;
|
|
92
|
-
function requireUseSyncExternalStoreWithSelector_development() {
|
|
93
|
-
if (hasRequiredUseSyncExternalStoreWithSelector_development)
|
|
94
|
-
return useSyncExternalStoreWithSelector_development;
|
|
95
|
-
hasRequiredUseSyncExternalStoreWithSelector_development = 1;
|
|
96
|
-
if (process.env.NODE_ENV !== "production") {
|
|
97
|
-
(function() {
|
|
98
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
99
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
100
|
-
}
|
|
101
|
-
var React = require$$0;
|
|
102
|
-
function is(x, y) {
|
|
103
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
104
|
-
}
|
|
105
|
-
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
106
|
-
var useSyncExternalStore = React.useSyncExternalStore;
|
|
107
|
-
var useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
|
|
108
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
109
|
-
var instRef = useRef(null);
|
|
110
|
-
var inst;
|
|
111
|
-
if (instRef.current === null) {
|
|
112
|
-
inst = {
|
|
113
|
-
hasValue: false,
|
|
114
|
-
value: null
|
|
115
|
-
};
|
|
116
|
-
instRef.current = inst;
|
|
117
|
-
} else {
|
|
118
|
-
inst = instRef.current;
|
|
119
|
-
}
|
|
120
|
-
var _useMemo = useMemo(function() {
|
|
121
|
-
var hasMemo = false;
|
|
122
|
-
var memoizedSnapshot;
|
|
123
|
-
var memoizedSelection;
|
|
124
|
-
var memoizedSelector = function(nextSnapshot) {
|
|
125
|
-
if (!hasMemo) {
|
|
126
|
-
hasMemo = true;
|
|
127
|
-
memoizedSnapshot = nextSnapshot;
|
|
128
|
-
var _nextSelection = selector(nextSnapshot);
|
|
129
|
-
if (isEqual !== void 0) {
|
|
130
|
-
if (inst.hasValue) {
|
|
131
|
-
var currentSelection = inst.value;
|
|
132
|
-
if (isEqual(currentSelection, _nextSelection)) {
|
|
133
|
-
memoizedSelection = currentSelection;
|
|
134
|
-
return currentSelection;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
memoizedSelection = _nextSelection;
|
|
139
|
-
return _nextSelection;
|
|
140
|
-
}
|
|
141
|
-
var prevSnapshot = memoizedSnapshot;
|
|
142
|
-
var prevSelection = memoizedSelection;
|
|
143
|
-
if (objectIs(prevSnapshot, nextSnapshot)) {
|
|
144
|
-
return prevSelection;
|
|
145
|
-
}
|
|
146
|
-
var nextSelection = selector(nextSnapshot);
|
|
147
|
-
if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
|
|
148
|
-
return prevSelection;
|
|
149
|
-
}
|
|
150
|
-
memoizedSnapshot = nextSnapshot;
|
|
151
|
-
memoizedSelection = nextSelection;
|
|
152
|
-
return nextSelection;
|
|
153
|
-
};
|
|
154
|
-
var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
|
|
155
|
-
var getSnapshotWithSelector = function() {
|
|
156
|
-
return memoizedSelector(getSnapshot());
|
|
157
|
-
};
|
|
158
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
159
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
160
|
-
};
|
|
161
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
162
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
|
|
163
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
164
|
-
useEffect(function() {
|
|
165
|
-
inst.hasValue = true;
|
|
166
|
-
inst.value = value;
|
|
167
|
-
}, [value]);
|
|
168
|
-
useDebugValue(value);
|
|
169
|
-
return value;
|
|
170
|
-
}
|
|
171
|
-
useSyncExternalStoreWithSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
172
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
173
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
174
|
-
}
|
|
175
|
-
})();
|
|
176
|
-
}
|
|
177
|
-
return useSyncExternalStoreWithSelector_development;
|
|
178
|
-
}
|
|
179
|
-
(function(module2) {
|
|
180
|
-
if (process.env.NODE_ENV === "production") {
|
|
181
|
-
module2.exports = requireUseSyncExternalStoreWithSelector_production_min();
|
|
182
|
-
} else {
|
|
183
|
-
module2.exports = requireUseSyncExternalStoreWithSelector_development();
|
|
184
|
-
}
|
|
185
|
-
})(withSelector);
|
|
186
|
-
function useStore(store, options) {
|
|
187
|
-
const lastEqualsRef = require$$0.useRef();
|
|
188
|
-
const { rootStore, selector } = require$$0.useMemo(() => {
|
|
189
|
-
var _a;
|
|
190
|
-
const rootStore2 = ((_a = store.derivedFrom) == null ? void 0 : _a.store) ?? store;
|
|
191
|
-
let selector2 = (x) => x;
|
|
192
|
-
if (store.derivedFrom) {
|
|
193
|
-
selector2 = (value2) => {
|
|
194
|
-
for (const s of store.derivedFrom.selectors) {
|
|
195
|
-
value2 = hash.makeSelector(s)(value2);
|
|
196
|
-
}
|
|
197
|
-
return value2;
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
return { rootStore: rootStore2, selector: selector2 };
|
|
201
|
-
}, [store]);
|
|
202
|
-
const subOptions = { ...options, runNow: false, equals: void 0, passive: false };
|
|
203
|
-
const subscribe = require$$0.useCallback(
|
|
204
|
-
(listener) => {
|
|
205
|
-
return rootStore.sub(listener, subOptions);
|
|
206
|
-
},
|
|
207
|
-
[rootStore, hash.hash(subOptions)]
|
|
208
|
-
);
|
|
209
|
-
const value = withSelectorExports.useSyncExternalStoreWithSelector(
|
|
210
|
-
//
|
|
211
|
-
subscribe,
|
|
212
|
-
rootStore.get,
|
|
213
|
-
void 0,
|
|
214
|
-
selector,
|
|
215
|
-
(options == null ? void 0 : options.equals) ?? ((_v, newValue) => {
|
|
216
|
-
var _a;
|
|
217
|
-
return ((_a = lastEqualsRef.current) == null ? void 0 : _a.call(lastEqualsRef, newValue)) ?? false;
|
|
218
|
-
})
|
|
219
|
-
);
|
|
220
|
-
const [proxiedValue, equals] = hash.trackingProxy(value);
|
|
221
|
-
require$$0.useLayoutEffect(() => {
|
|
222
|
-
lastEqualsRef.current = equals;
|
|
223
|
-
});
|
|
224
|
-
require$$0.useDebugValue(value);
|
|
225
|
-
return proxiedValue;
|
|
226
|
-
}
|
|
227
|
-
function useCache(cache, { passive, ...options } = {}) {
|
|
228
|
-
const mappedState = require$$0.useMemo(() => {
|
|
229
|
-
var _a;
|
|
230
|
-
const rootCache = ((_a = cache.derivedFromCache) == null ? void 0 : _a.cache) ?? cache;
|
|
231
|
-
let selector = (x) => x;
|
|
232
|
-
if (cache.derivedFromCache) {
|
|
233
|
-
selector = (value) => {
|
|
234
|
-
for (const s of cache.derivedFromCache.selectors) {
|
|
235
|
-
value = hash.makeSelector(s)(value);
|
|
236
|
-
}
|
|
237
|
-
return value;
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
return rootCache.state.map((state) => {
|
|
241
|
-
const value = state.status === "value" ? selector(state.value) : void 0;
|
|
242
|
-
return Object.assign(
|
|
243
|
-
[value, state.error, state.isUpdating, state.isStale],
|
|
244
|
-
{ ...state, value }
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
}, [cache]);
|
|
248
|
-
require$$0.useEffect(() => !passive ? cache.sub(() => void 0) : void 0, [cache, passive]);
|
|
249
|
-
return useStore(mappedState, options);
|
|
250
|
-
}
|
|
251
|
-
function read(cache, options) {
|
|
252
|
-
const { status, value, error } = useCache(cache, options);
|
|
253
|
-
if (status === "value") {
|
|
254
|
-
return value;
|
|
255
|
-
}
|
|
256
|
-
if (status === "error") {
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
throw cache.state.once((state) => state.status !== "pending");
|
|
260
|
-
}
|
|
261
|
-
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
262
|
-
function getStoreScopeContext(scope) {
|
|
263
|
-
let context = contextMap.get(scope);
|
|
264
|
-
if (!context) {
|
|
265
|
-
context = require$$0.createContext(hash.createStore(scope.defaultValue));
|
|
266
|
-
contextMap.set(scope, context);
|
|
267
|
-
}
|
|
268
|
-
return context;
|
|
269
|
-
}
|
|
270
|
-
function StoreScopeProvider({ scope, store: inputStore, children }) {
|
|
271
|
-
const context = getStoreScopeContext(scope);
|
|
272
|
-
const currentStore = require$$0.useMemo(
|
|
273
|
-
() => inputStore ?? hash.createStore(scope.defaultValue),
|
|
274
|
-
[scope, inputStore]
|
|
275
|
-
);
|
|
276
|
-
return /* @__PURE__ */ jsxRuntime.jsx(context.Provider, { value: currentStore, children });
|
|
277
|
-
}
|
|
278
|
-
function useStoreScope(scope) {
|
|
279
|
-
const context = getStoreScopeContext(scope);
|
|
280
|
-
return require$$0.useContext(context);
|
|
281
|
-
}
|
|
282
|
-
function useProp(store, options) {
|
|
283
|
-
const value = useStore(store, options);
|
|
284
|
-
return [value, store.set];
|
|
285
|
-
}
|
|
286
|
-
exports.StoreScopeProvider = StoreScopeProvider;
|
|
287
|
-
exports.read = read;
|
|
288
|
-
exports.useCache = useCache;
|
|
289
|
-
exports.useProp = useProp;
|
|
290
|
-
exports.useStore = useStore;
|
|
291
|
-
exports.useStoreScope = useStoreScope;
|
|
3
|
+
const read = require("./react/read.cjs");
|
|
4
|
+
const storeScope = require("./react/storeScope.cjs");
|
|
5
|
+
const useCache = require("./react/useCache.cjs");
|
|
6
|
+
const useProp = require("./react/useProp.cjs");
|
|
7
|
+
const useStore = require("./react/useStore.cjs");
|
|
8
|
+
exports.read = read.read;
|
|
9
|
+
exports.StoreScopeProvider = storeScope.StoreScopeProvider;
|
|
10
|
+
exports.useStoreScope = storeScope.useStoreScope;
|
|
11
|
+
exports.useCache = useCache.useCache;
|
|
12
|
+
exports.useProp = useProp.useProp;
|
|
13
|
+
exports.useStore = useStore.useStore;
|
|
292
14
|
//# sourceMappingURL=react.cjs.map
|