@hanzogui/use-store 2.0.0-rc.41-hanzoai.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/cjs/comparators.cjs +41 -0
- package/dist/cjs/comparators.native.js +50 -0
- package/dist/cjs/comparators.native.js.map +1 -0
- package/dist/cjs/configureUseStore.cjs +32 -0
- package/dist/cjs/configureUseStore.native.js +35 -0
- package/dist/cjs/configureUseStore.native.js.map +1 -0
- package/dist/cjs/constants.cjs +33 -0
- package/dist/cjs/constants.native.js +36 -0
- package/dist/cjs/constants.native.js.map +1 -0
- package/dist/cjs/decorators.cjs +33 -0
- package/dist/cjs/decorators.native.js +36 -0
- package/dist/cjs/decorators.native.js.map +1 -0
- package/dist/cjs/helpers.cjs +62 -0
- package/dist/cjs/helpers.native.js +71 -0
- package/dist/cjs/helpers.native.js.map +1 -0
- package/dist/cjs/index.cjs +43 -0
- package/dist/cjs/index.native.js +65 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/interfaces.cjs +18 -0
- package/dist/cjs/interfaces.native.js +21 -0
- package/dist/cjs/interfaces.native.js.map +1 -0
- package/dist/cjs/observe.cjs +166 -0
- package/dist/cjs/observe.native.js +234 -0
- package/dist/cjs/observe.native.js.map +1 -0
- package/dist/cjs/useStore.cjs +467 -0
- package/dist/cjs/useStore.native.js +608 -0
- package/dist/cjs/useStore.native.js.map +1 -0
- package/dist/cjs/useStoreDebug.cjs +67 -0
- package/dist/cjs/useStoreDebug.native.js +71 -0
- package/dist/cjs/useStoreDebug.native.js.map +1 -0
- package/dist/esm/comparators.mjs +16 -0
- package/dist/esm/comparators.mjs.map +1 -0
- package/dist/esm/comparators.native.js +22 -0
- package/dist/esm/comparators.native.js.map +1 -0
- package/dist/esm/configureUseStore.mjs +6 -0
- package/dist/esm/configureUseStore.mjs.map +1 -0
- package/dist/esm/configureUseStore.native.js +6 -0
- package/dist/esm/configureUseStore.native.js.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/constants.native.js +7 -0
- package/dist/esm/constants.native.js.map +1 -0
- package/dist/esm/decorators.mjs +8 -0
- package/dist/esm/decorators.mjs.map +1 -0
- package/dist/esm/decorators.native.js +8 -0
- package/dist/esm/decorators.native.js.map +1 -0
- package/dist/esm/helpers.mjs +31 -0
- package/dist/esm/helpers.mjs.map +1 -0
- package/dist/esm/helpers.native.js +37 -0
- package/dist/esm/helpers.native.js.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +15 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +34 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/interfaces.mjs +2 -0
- package/dist/esm/interfaces.mjs.map +1 -0
- package/dist/esm/interfaces.native.js +2 -0
- package/dist/esm/interfaces.native.js.map +1 -0
- package/dist/esm/observe.mjs +129 -0
- package/dist/esm/observe.mjs.map +1 -0
- package/dist/esm/observe.native.js +194 -0
- package/dist/esm/observe.native.js.map +1 -0
- package/dist/esm/useStore.mjs +417 -0
- package/dist/esm/useStore.mjs.map +1 -0
- package/dist/esm/useStore.native.js +555 -0
- package/dist/esm/useStore.native.js.map +1 -0
- package/dist/esm/useStoreDebug.mjs +27 -0
- package/dist/esm/useStoreDebug.mjs.map +1 -0
- package/dist/esm/useStoreDebug.native.js +28 -0
- package/dist/esm/useStoreDebug.native.js.map +1 -0
- package/package.json +47 -0
- package/src/comparators.tsx +18 -0
- package/src/configureUseStore.tsx +7 -0
- package/src/constants.tsx +6 -0
- package/src/decorators.tsx +8 -0
- package/src/helpers.tsx +56 -0
- package/src/index.ts +12 -0
- package/src/interfaces.tsx +46 -0
- package/src/observe.tsx +160 -0
- package/src/useStore.tsx +705 -0
- package/src/useStoreDebug.tsx +41 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
24
|
+
value: true
|
|
25
|
+
}), mod);
|
|
26
|
+
var index_exports = {};
|
|
27
|
+
__export(index_exports, {
|
|
28
|
+
Store: () => Store,
|
|
29
|
+
UNWRAP_PROXY: () => import_constants.UNWRAP_PROXY,
|
|
30
|
+
configureUseStore: () => import_configureUseStore.configureUseStore
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
__reExport(index_exports, require("./useStore.native.js"), module.exports);
|
|
34
|
+
var import_configureUseStore = require("./configureUseStore.native.js");
|
|
35
|
+
__reExport(index_exports, require("./interfaces.native.js"), module.exports);
|
|
36
|
+
__reExport(index_exports, require("./observe.native.js"), module.exports);
|
|
37
|
+
var import_constants = require("./constants.native.js");
|
|
38
|
+
__reExport(index_exports, require("./comparators.native.js"), module.exports);
|
|
39
|
+
__reExport(index_exports, require("./decorators.native.js"), module.exports);
|
|
40
|
+
function _class_call_check(instance, Constructor) {
|
|
41
|
+
if (!(instance instanceof Constructor)) {
|
|
42
|
+
throw new TypeError("Cannot call a class as a function");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _define_property(obj, key, value) {
|
|
46
|
+
if (key in obj) {
|
|
47
|
+
Object.defineProperty(obj, key, {
|
|
48
|
+
value,
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
obj[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return obj;
|
|
57
|
+
}
|
|
58
|
+
var Store = function Store2(props) {
|
|
59
|
+
"use strict";
|
|
60
|
+
|
|
61
|
+
_class_call_check(this, Store2);
|
|
62
|
+
_define_property(this, "props", void 0);
|
|
63
|
+
this.props = props;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","Store","UNWRAP_PROXY","import_constants","configureUseStore","import_configureUseStore","module","exports","__reExport","require","_class_call_check","instance","Constructor","TypeError"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,KAAA,EAAAA,CAAA,KAAAA,KAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAC,gBAAA,CAAAD,YAAA;EAAAE,iBAAA,EAAAA,CAAA,KAAAC,wBAAA,CAAAD;AAAA;AAAAE,MAAA,CAAAC,OAAA,GAAAb,YAAc,CAAAK,aAAA;AACdS,UAAA,CAAAT,aAAA,EAAAU,OAAkC,0BAAAH,MAAA,CAAAC,OAAA;AAClC,IAAAF,wBAAc,GAAAI,OAAA,gCAFd;AAGAD,UAAA,CAAAT,aAAA,EAAcU,OAAA,yBAHd,GAAAH,MAAA,CAAAC,OAAA;AAIAC,UAAA,CAAAT,aAA6B,EAAAU,OAAA,yBAAAH,MAAA,CAAAC,OAAA;AAC7B,IAAAJ,gBAAA,GAAAM,OAAc;AACdD,UAAA,CAAAT,aAAA,EAAcU,OAAA,6BANdH,MAAA,CAAAC,OAAA;AASOC,UAAM,CAAAT,aAAyC,EAAAU,OAAA,4BAAAH,MAAA,CAAAC,OAAA;AAAA,SACpDG,iBAAiCA,CAAAC,QAAA,EAAAC,WAAA;EAAd,MAAAD,QAAA,YAAAC,WAAA;IAAe,UAAAC,SAAA;EAAf;AACrB","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
}), mod);
|
|
17
|
+
var interfaces_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(interfaces_exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
}), mod);
|
|
19
|
+
var interfaces_exports = {};
|
|
20
|
+
module.exports = __toCommonJS(interfaces_exports);
|
|
21
|
+
//# sourceMappingURL=interfaces.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","interfaces_exports"],"sources":["../../src/interfaces.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var observe_exports = {};
|
|
35
|
+
__export(observe_exports, {
|
|
36
|
+
observe: () => observe,
|
|
37
|
+
useObserve: () => useObserve
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(observe_exports);
|
|
40
|
+
var import_react = __toESM(require("react"), 1);
|
|
41
|
+
var import_comparators = require("./comparators.cjs");
|
|
42
|
+
var import_constants = require("./constants.cjs");
|
|
43
|
+
var import_useStore = require("./useStore.cjs");
|
|
44
|
+
const logUpdate = process.env.NODE_ENV === "development" ? (fn, stores, last, next) => {
|
|
45
|
+
const getStoreLogName = store => {
|
|
46
|
+
const str = store[import_constants.UNWRAP_PROXY] ?? store;
|
|
47
|
+
return `${str.constructor.name}${store.props?.id ? `:${store.props.id}` : ""}`;
|
|
48
|
+
};
|
|
49
|
+
const storeNames = stores.map(getStoreLogName).join(", ");
|
|
50
|
+
const name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
|
|
51
|
+
console.groupCollapsed(name, "color: tomato;");
|
|
52
|
+
console.groupCollapsed("trace >");
|
|
53
|
+
console.trace();
|
|
54
|
+
console.groupEnd();
|
|
55
|
+
console.info(" next", next);
|
|
56
|
+
console.groupEnd();
|
|
57
|
+
} : null;
|
|
58
|
+
function observe(fn) {
|
|
59
|
+
let prev = getObserverValueAndStoresAccessed(fn);
|
|
60
|
+
let disposeValue = null;
|
|
61
|
+
const subscribe = () => {
|
|
62
|
+
const stores = [...prev.storeInfos];
|
|
63
|
+
return subscribeToStores(stores, () => {
|
|
64
|
+
disposeValue?.();
|
|
65
|
+
const next = getObserverValueAndStoresAccessed(fn);
|
|
66
|
+
if (typeof next.value === "function") {
|
|
67
|
+
disposeValue = next.value;
|
|
68
|
+
if (process.env.NODE_ENV === "development") {
|
|
69
|
+
logUpdate(fn, [...next.storeInfos], "(fn)", "(fn)");
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prev.storeInfos, next.storeInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (process.env.NODE_ENV === "development") {
|
|
77
|
+
logUpdate(fn, [...next.storeInfos], prev.value, next.value);
|
|
78
|
+
}
|
|
79
|
+
prev = next;
|
|
80
|
+
dispose();
|
|
81
|
+
dispose = subscribe();
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
let dispose = subscribe();
|
|
85
|
+
return {
|
|
86
|
+
dispose: () => {
|
|
87
|
+
dispose();
|
|
88
|
+
disposeValue?.();
|
|
89
|
+
},
|
|
90
|
+
getValue: () => prev.value
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function useObserve(fn) {
|
|
94
|
+
const [state, setState] = import_react.default.useState(() => {
|
|
95
|
+
return getObserverValueAndStoresAccessed(fn);
|
|
96
|
+
});
|
|
97
|
+
import_react.default.useEffect(() => {
|
|
98
|
+
let dispose;
|
|
99
|
+
const unsub = subscribeToStores([...state.storeInfos], () => {
|
|
100
|
+
dispose?.();
|
|
101
|
+
const next = getObserverValueAndStoresAccessed(fn);
|
|
102
|
+
const nextStoreInfos = [...next.storeInfos];
|
|
103
|
+
const prevStoreInfos = [...state.storeInfos];
|
|
104
|
+
if (typeof next.value === "function") {
|
|
105
|
+
if (process.env.NODE_ENV === "development") {
|
|
106
|
+
logUpdate(fn, nextStoreInfos, "(fn)", "(fn)");
|
|
107
|
+
}
|
|
108
|
+
dispose = next.value;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
setState(prev => {
|
|
112
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prevStoreInfos, nextStoreInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
113
|
+
return prev;
|
|
114
|
+
}
|
|
115
|
+
if (process.env.NODE_ENV === "development") {
|
|
116
|
+
logUpdate(fn, nextStoreInfos, prev.value, next.value);
|
|
117
|
+
}
|
|
118
|
+
return next;
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
return () => {
|
|
122
|
+
unsub();
|
|
123
|
+
dispose?.();
|
|
124
|
+
};
|
|
125
|
+
}, [[...state.storeInfos].map(i => i.uid).join(",")]);
|
|
126
|
+
return state.value;
|
|
127
|
+
}
|
|
128
|
+
function getObserverValueAndStoresAccessed(selector) {
|
|
129
|
+
const storeInfos = /* @__PURE__ */new Set();
|
|
130
|
+
const dispose = (0, import_useStore.trackStoresAccess)(storeInfo => {
|
|
131
|
+
storeInfos.add(storeInfo);
|
|
132
|
+
});
|
|
133
|
+
const value = selector();
|
|
134
|
+
dispose();
|
|
135
|
+
return {
|
|
136
|
+
value,
|
|
137
|
+
storeInfos
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function subscribeToStores(storeInfos, onUpdate) {
|
|
141
|
+
const disposes = [];
|
|
142
|
+
let isUpdating = false;
|
|
143
|
+
const onUpdateDebouncedWithoutTracking = () => {
|
|
144
|
+
if (isUpdating) return;
|
|
145
|
+
isUpdating = true;
|
|
146
|
+
queueMicrotask(() => {
|
|
147
|
+
try {
|
|
148
|
+
for (const storeInfo of storeInfos) {
|
|
149
|
+
storeInfo.disableTracking = true;
|
|
150
|
+
}
|
|
151
|
+
onUpdate();
|
|
152
|
+
} finally {
|
|
153
|
+
isUpdating = false;
|
|
154
|
+
for (const storeInfo of storeInfos) {
|
|
155
|
+
storeInfo.disableTracking = false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
for (const storeInfo of storeInfos) {
|
|
161
|
+
disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
|
|
162
|
+
}
|
|
163
|
+
return () => {
|
|
164
|
+
disposes.forEach(x => x());
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
36
|
+
var observe_exports = {};
|
|
37
|
+
__export(observe_exports, {
|
|
38
|
+
observe: () => observe,
|
|
39
|
+
useObserve: () => useObserve
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(observe_exports);
|
|
42
|
+
var import_react = __toESM(require("react"), 1);
|
|
43
|
+
var import_comparators = require("./comparators.native.js");
|
|
44
|
+
var import_constants = require("./constants.native.js");
|
|
45
|
+
var import_useStore = require("./useStore.native.js");
|
|
46
|
+
var logUpdate = process.env.NODE_ENV === "development" ? function (fn, stores, last, next) {
|
|
47
|
+
var getStoreLogName = function (store) {
|
|
48
|
+
var _store_props;
|
|
49
|
+
var _store_UNWRAP_PROXY;
|
|
50
|
+
var str = (_store_UNWRAP_PROXY = store[import_constants.UNWRAP_PROXY]) !== null && _store_UNWRAP_PROXY !== void 0 ? _store_UNWRAP_PROXY : store;
|
|
51
|
+
return `${str.constructor.name}${((_store_props = store.props) === null || _store_props === void 0 ? void 0 : _store_props.id) ? `:${store.props.id}` : ""}`;
|
|
52
|
+
};
|
|
53
|
+
var storeNames = stores.map(getStoreLogName).join(", ");
|
|
54
|
+
var name = `\u{1F311} \u25B6\uFE0F %c${fn.name} ${storeNames} () ${last} => ${next}`;
|
|
55
|
+
console.groupCollapsed(name, "color: tomato;");
|
|
56
|
+
console.groupCollapsed("trace >");
|
|
57
|
+
console.trace();
|
|
58
|
+
console.groupEnd();
|
|
59
|
+
console.info(" next", next);
|
|
60
|
+
console.groupEnd();
|
|
61
|
+
} : null;
|
|
62
|
+
function observe(fn) {
|
|
63
|
+
var prev = getObserverValueAndStoresAccessed(fn);
|
|
64
|
+
var disposeValue = null;
|
|
65
|
+
var subscribe = function () {
|
|
66
|
+
var stores = [...prev.storeInfos];
|
|
67
|
+
return subscribeToStores(stores, function () {
|
|
68
|
+
disposeValue === null || disposeValue === void 0 ? void 0 : disposeValue();
|
|
69
|
+
var next = getObserverValueAndStoresAccessed(fn);
|
|
70
|
+
if (typeof next.value === "function") {
|
|
71
|
+
disposeValue = next.value;
|
|
72
|
+
if (process.env.NODE_ENV === "development") {
|
|
73
|
+
logUpdate(fn, [...next.storeInfos], "(fn)", "(fn)");
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prev.storeInfos, next.storeInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (process.env.NODE_ENV === "development") {
|
|
81
|
+
logUpdate(fn, [...next.storeInfos], prev.value, next.value);
|
|
82
|
+
}
|
|
83
|
+
prev = next;
|
|
84
|
+
dispose();
|
|
85
|
+
dispose = subscribe();
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
var dispose = subscribe();
|
|
89
|
+
return {
|
|
90
|
+
dispose: function () {
|
|
91
|
+
dispose();
|
|
92
|
+
disposeValue === null || disposeValue === void 0 ? void 0 : disposeValue();
|
|
93
|
+
},
|
|
94
|
+
getValue: function () {
|
|
95
|
+
return prev.value;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function useObserve(fn) {
|
|
100
|
+
var [state, setState] = import_react.default.useState(function () {
|
|
101
|
+
return getObserverValueAndStoresAccessed(fn);
|
|
102
|
+
});
|
|
103
|
+
import_react.default.useEffect(function () {
|
|
104
|
+
var dispose;
|
|
105
|
+
var unsub = subscribeToStores([...state.storeInfos], function () {
|
|
106
|
+
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
107
|
+
var next = getObserverValueAndStoresAccessed(fn);
|
|
108
|
+
var nextStoreInfos = [...next.storeInfos];
|
|
109
|
+
var prevStoreInfos = [...state.storeInfos];
|
|
110
|
+
if (typeof next.value === "function") {
|
|
111
|
+
if (process.env.NODE_ENV === "development") {
|
|
112
|
+
logUpdate(fn, nextStoreInfos, "(fn)", "(fn)");
|
|
113
|
+
}
|
|
114
|
+
dispose = next.value;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
setState(function (prev) {
|
|
118
|
+
if ((0, import_comparators.isEqualSubsetShallow)(prevStoreInfos, nextStoreInfos) && (0, import_comparators.isEqualSubsetShallow)(prev.value, next.value)) {
|
|
119
|
+
return prev;
|
|
120
|
+
}
|
|
121
|
+
if (process.env.NODE_ENV === "development") {
|
|
122
|
+
logUpdate(fn, nextStoreInfos, prev.value, next.value);
|
|
123
|
+
}
|
|
124
|
+
return next;
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
return function () {
|
|
128
|
+
unsub();
|
|
129
|
+
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
130
|
+
};
|
|
131
|
+
}, [[...state.storeInfos].map(function (i) {
|
|
132
|
+
return i.uid;
|
|
133
|
+
}).join(",")]);
|
|
134
|
+
return state.value;
|
|
135
|
+
}
|
|
136
|
+
function getObserverValueAndStoresAccessed(selector) {
|
|
137
|
+
var storeInfos = /* @__PURE__ */new Set();
|
|
138
|
+
var dispose = (0, import_useStore.trackStoresAccess)(function (storeInfo) {
|
|
139
|
+
storeInfos.add(storeInfo);
|
|
140
|
+
});
|
|
141
|
+
var value = selector();
|
|
142
|
+
dispose();
|
|
143
|
+
return {
|
|
144
|
+
value,
|
|
145
|
+
storeInfos
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function subscribeToStores(storeInfos, onUpdate) {
|
|
149
|
+
var disposes = [];
|
|
150
|
+
var isUpdating = false;
|
|
151
|
+
var onUpdateDebouncedWithoutTracking = function () {
|
|
152
|
+
if (isUpdating) return;
|
|
153
|
+
isUpdating = true;
|
|
154
|
+
queueMicrotask(function () {
|
|
155
|
+
try {
|
|
156
|
+
var _iteratorNormalCompletion2 = true,
|
|
157
|
+
_didIteratorError2 = false,
|
|
158
|
+
_iteratorError2 = void 0;
|
|
159
|
+
try {
|
|
160
|
+
for (var _iterator2 = storeInfos[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
161
|
+
var storeInfo2 = _step2.value;
|
|
162
|
+
storeInfo2.disableTracking = true;
|
|
163
|
+
}
|
|
164
|
+
} catch (err) {
|
|
165
|
+
_didIteratorError2 = true;
|
|
166
|
+
_iteratorError2 = err;
|
|
167
|
+
} finally {
|
|
168
|
+
try {
|
|
169
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
170
|
+
_iterator2.return();
|
|
171
|
+
}
|
|
172
|
+
} finally {
|
|
173
|
+
if (_didIteratorError2) {
|
|
174
|
+
throw _iteratorError2;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
onUpdate();
|
|
179
|
+
} finally {
|
|
180
|
+
isUpdating = false;
|
|
181
|
+
var _iteratorNormalCompletion1 = true,
|
|
182
|
+
_didIteratorError1 = false,
|
|
183
|
+
_iteratorError1 = void 0;
|
|
184
|
+
try {
|
|
185
|
+
for (var _iterator1 = storeInfos[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
186
|
+
var storeInfo1 = _step1.value;
|
|
187
|
+
storeInfo1.disableTracking = false;
|
|
188
|
+
}
|
|
189
|
+
} catch (err) {
|
|
190
|
+
_didIteratorError1 = true;
|
|
191
|
+
_iteratorError1 = err;
|
|
192
|
+
} finally {
|
|
193
|
+
try {
|
|
194
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
195
|
+
_iterator1.return();
|
|
196
|
+
}
|
|
197
|
+
} finally {
|
|
198
|
+
if (_didIteratorError1) {
|
|
199
|
+
throw _iteratorError1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
var _iteratorNormalCompletion = true,
|
|
207
|
+
_didIteratorError = false,
|
|
208
|
+
_iteratorError = void 0;
|
|
209
|
+
try {
|
|
210
|
+
for (var _iterator = storeInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
211
|
+
var storeInfo = _step.value;
|
|
212
|
+
disposes.push(storeInfo.subscribe(onUpdateDebouncedWithoutTracking));
|
|
213
|
+
}
|
|
214
|
+
} catch (err) {
|
|
215
|
+
_didIteratorError = true;
|
|
216
|
+
_iteratorError = err;
|
|
217
|
+
} finally {
|
|
218
|
+
try {
|
|
219
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
220
|
+
_iterator.return();
|
|
221
|
+
}
|
|
222
|
+
} finally {
|
|
223
|
+
if (_didIteratorError) {
|
|
224
|
+
throw _iteratorError;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return function () {
|
|
229
|
+
disposes.forEach(function (x) {
|
|
230
|
+
return x();
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=observe.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","observe_exports","__export","observe","useObserve","module","exports","import_react","__toESM","require","import_comparators","import_constants","import_useStore","logUpdate","process","env","NODE_ENV","fn","stores","last","next","getStoreLogName","store","_store_props","_store_UNWRAP_PROXY","str","UNWRAP_PROXY","constructor","name","props","id","storeNames","map","join","console","groupCollapsed","trace","groupEnd","info","prev","getObserverValueAndStoresAccessed","disposeValue","subscribe","storeInfos","subscribeToStores","isEqualSubsetShallow","dispose","getValue","state","setState","default","useState","useEffect","unsub","nextStoreInfos","prevStoreInfos","i","uid","selector","Set","trackStoresAccess","storeInfo","add","onUpdate","disposes","isUpdating","onUpdateDebouncedWithoutTracking"],"sources":["../../src/observe.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,OAAA,EAAAA,CAAA,KAAAA,OAAA;EAAAC,UAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAAkB,CAAAK,eAAA;AAElB,IAAAM,YAAA,GAAAC,OAAqC,CAAAC,OAAA;AACrC,IAAAC,kBAAA,GAA6BD,OAAA;AAE7B,IAAAE,gBAAA,GAAkCF,OAAA;AAElC,IAAAG,eACE,GAAAH,OAAQ,CAAI,uBAAa;AAEnB,IAAAI,SAAM,GAAAC,OAAA,CAAAC,GAAmB,CAAAC,QAAA,KAAe,0BAAAC,EAAA,EAAAC,MAAA,EAAAC,IAAA,EAAAC,IAAA;EACtC,IAAAC,eAAY,GAAM,SAAAA,CAAAC,KAAA;IAClB,IAAAC,YAAc;IAChB,IAAAC,mBAAA;IACA,IAAMC,GAAA,IAAAD,mBAAwB,GAA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