react-shared-states 1.0.6 → 1.0.8
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/.editorconfig +6 -0
- package/README.md +118 -64
- package/dist/SharedData.d.ts +44 -8
- package/dist/context/SharedStatesContext.d.ts +5 -4
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/use-shared-function.d.ts +10 -12
- package/dist/hooks/use-shared-state.d.ts +8 -10
- package/dist/hooks/use-shared-subscription.d.ts +10 -13
- package/dist/lib/utils.d.ts +2 -2
- package/dist/main.esm.js +404 -312
- package/dist/main.min.js +5 -5
- package/dist/types.d.ts +4 -1
- package/package.json +7 -2
- package/scripts/bumper.js +24 -0
- package/tests/index.test.tsx +358 -0
- package/vitest.config.ts +8 -0
package/dist/main.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.8
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-shared-states
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
var
|
|
8
|
+
import he, { createContext as ge, useMemo as L, useContext as pe, useEffect as ee, useSyncExternalStore as I } from "react";
|
|
9
|
+
var y = { exports: {} }, V = {};
|
|
10
10
|
/**
|
|
11
11
|
* @license React
|
|
12
12
|
* react-jsx-runtime.production.js
|
|
@@ -16,29 +16,29 @@ var L = { exports: {} }, P = {};
|
|
|
16
16
|
* This source code is licensed under the MIT license found in the
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*/
|
|
19
|
-
var
|
|
20
|
-
function
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
function r(t,
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
for (var
|
|
29
|
-
|
|
30
|
-
} else
|
|
31
|
-
return
|
|
32
|
-
$$typeof:
|
|
19
|
+
var Z;
|
|
20
|
+
function Se() {
|
|
21
|
+
if (Z) return V;
|
|
22
|
+
Z = 1;
|
|
23
|
+
var a = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
24
|
+
function r(t, s, f) {
|
|
25
|
+
var o = null;
|
|
26
|
+
if (f !== void 0 && (o = "" + f), s.key !== void 0 && (o = "" + s.key), "key" in s) {
|
|
27
|
+
f = {};
|
|
28
|
+
for (var _ in s)
|
|
29
|
+
_ !== "key" && (f[_] = s[_]);
|
|
30
|
+
} else f = s;
|
|
31
|
+
return s = f.ref, {
|
|
32
|
+
$$typeof: a,
|
|
33
33
|
type: t,
|
|
34
|
-
key:
|
|
35
|
-
ref:
|
|
36
|
-
props:
|
|
34
|
+
key: o,
|
|
35
|
+
ref: s !== void 0 ? s : null,
|
|
36
|
+
props: f
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
return
|
|
39
|
+
return V.Fragment = e, V.jsx = r, V.jsxs = r, V;
|
|
40
40
|
}
|
|
41
|
-
var
|
|
41
|
+
var C = {};
|
|
42
42
|
/**
|
|
43
43
|
* @license React
|
|
44
44
|
* react-jsx-runtime.development.js
|
|
@@ -48,47 +48,47 @@ var j = {};
|
|
|
48
48
|
* This source code is licensed under the MIT license found in the
|
|
49
49
|
* LICENSE file in the root directory of this source tree.
|
|
50
50
|
*/
|
|
51
|
-
var
|
|
52
|
-
function
|
|
53
|
-
return
|
|
54
|
-
function
|
|
51
|
+
var Q;
|
|
52
|
+
function Ee() {
|
|
53
|
+
return Q || (Q = 1, process.env.NODE_ENV !== "production" && function() {
|
|
54
|
+
function a(n) {
|
|
55
55
|
if (n == null) return null;
|
|
56
56
|
if (typeof n == "function")
|
|
57
|
-
return n.$$typeof ===
|
|
57
|
+
return n.$$typeof === fe ? null : n.displayName || n.name || null;
|
|
58
58
|
if (typeof n == "string") return n;
|
|
59
59
|
switch (n) {
|
|
60
|
-
case
|
|
60
|
+
case l:
|
|
61
61
|
return "Fragment";
|
|
62
|
-
case
|
|
62
|
+
case ne:
|
|
63
63
|
return "Profiler";
|
|
64
|
-
case
|
|
64
|
+
case v:
|
|
65
65
|
return "StrictMode";
|
|
66
|
-
case
|
|
66
|
+
case ie:
|
|
67
67
|
return "Suspense";
|
|
68
|
-
case oe:
|
|
69
|
-
return "SuspenseList";
|
|
70
68
|
case le:
|
|
69
|
+
return "SuspenseList";
|
|
70
|
+
case ue:
|
|
71
71
|
return "Activity";
|
|
72
72
|
}
|
|
73
73
|
if (typeof n == "object")
|
|
74
74
|
switch (typeof n.tag == "number" && console.error(
|
|
75
75
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
76
76
|
), n.$$typeof) {
|
|
77
|
-
case
|
|
77
|
+
case d:
|
|
78
78
|
return "Portal";
|
|
79
|
-
case
|
|
79
|
+
case ae:
|
|
80
80
|
return (n.displayName || "Context") + ".Provider";
|
|
81
|
-
case re:
|
|
82
|
-
return (n._context.displayName || "Context") + ".Consumer";
|
|
83
81
|
case se:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
|
|
82
|
+
return (n._context.displayName || "Context") + ".Consumer";
|
|
83
|
+
case oe:
|
|
84
|
+
var i = n.render;
|
|
85
|
+
return n = n.displayName, n || (n = i.displayName || i.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
|
|
86
|
+
case ce:
|
|
87
|
+
return i = n.displayName || null, i !== null ? i : a(n.type) || "Memo";
|
|
88
|
+
case G:
|
|
89
|
+
i = n._payload, n = n._init;
|
|
90
90
|
try {
|
|
91
|
-
return
|
|
91
|
+
return a(n(i));
|
|
92
92
|
} catch {
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -100,73 +100,73 @@ function he() {
|
|
|
100
100
|
function r(n) {
|
|
101
101
|
try {
|
|
102
102
|
e(n);
|
|
103
|
-
var
|
|
103
|
+
var i = !1;
|
|
104
104
|
} catch {
|
|
105
|
-
|
|
105
|
+
i = !0;
|
|
106
106
|
}
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
return
|
|
111
|
-
|
|
107
|
+
if (i) {
|
|
108
|
+
i = console;
|
|
109
|
+
var b = i.error, g = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
|
|
110
|
+
return b.call(
|
|
111
|
+
i,
|
|
112
112
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
113
|
-
|
|
113
|
+
g
|
|
114
114
|
), e(n);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
function t(n) {
|
|
118
|
-
if (n ===
|
|
119
|
-
if (typeof n == "object" && n !== null && n.$$typeof ===
|
|
118
|
+
if (n === l) return "<>";
|
|
119
|
+
if (typeof n == "object" && n !== null && n.$$typeof === G)
|
|
120
120
|
return "<...>";
|
|
121
121
|
try {
|
|
122
|
-
var
|
|
123
|
-
return
|
|
122
|
+
var i = a(n);
|
|
123
|
+
return i ? "<" + i + ">" : "<...>";
|
|
124
124
|
} catch {
|
|
125
125
|
return "<...>";
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
var n =
|
|
128
|
+
function s() {
|
|
129
|
+
var n = F.A;
|
|
130
130
|
return n === null ? null : n.getOwner();
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function f() {
|
|
133
133
|
return Error("react-stack-top-frame");
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
if (
|
|
137
|
-
var
|
|
138
|
-
if (
|
|
135
|
+
function o(n) {
|
|
136
|
+
if (q.call(n, "key")) {
|
|
137
|
+
var i = Object.getOwnPropertyDescriptor(n, "key").get;
|
|
138
|
+
if (i && i.isReactWarning) return !1;
|
|
139
139
|
}
|
|
140
140
|
return n.key !== void 0;
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
function
|
|
144
|
-
|
|
142
|
+
function _(n, i) {
|
|
143
|
+
function b() {
|
|
144
|
+
J || (J = !0, console.error(
|
|
145
145
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
146
|
-
|
|
146
|
+
i
|
|
147
147
|
));
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
get:
|
|
149
|
+
b.isReactWarning = !0, Object.defineProperty(n, "key", {
|
|
150
|
+
get: b,
|
|
151
151
|
configurable: !0
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
var n =
|
|
156
|
-
return
|
|
154
|
+
function O() {
|
|
155
|
+
var n = a(this.type);
|
|
156
|
+
return z[n] || (z[n] = !0, console.error(
|
|
157
157
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
158
158
|
)), n = this.props.ref, n !== void 0 ? n : null;
|
|
159
159
|
}
|
|
160
|
-
function
|
|
161
|
-
return
|
|
162
|
-
$$typeof:
|
|
160
|
+
function w(n, i, b, g, P, T, $, k) {
|
|
161
|
+
return b = T.ref, n = {
|
|
162
|
+
$$typeof: h,
|
|
163
163
|
type: n,
|
|
164
|
-
key:
|
|
165
|
-
props:
|
|
166
|
-
_owner:
|
|
167
|
-
}, (
|
|
164
|
+
key: i,
|
|
165
|
+
props: T,
|
|
166
|
+
_owner: P
|
|
167
|
+
}, (b !== void 0 ? b : null) !== null ? Object.defineProperty(n, "ref", {
|
|
168
168
|
enumerable: !1,
|
|
169
|
-
get:
|
|
169
|
+
get: O
|
|
170
170
|
}) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
|
|
171
171
|
configurable: !1,
|
|
172
172
|
enumerable: !1,
|
|
@@ -181,144 +181,146 @@ function he() {
|
|
|
181
181
|
configurable: !1,
|
|
182
182
|
enumerable: !1,
|
|
183
183
|
writable: !0,
|
|
184
|
-
value:
|
|
184
|
+
value: $
|
|
185
185
|
}), Object.defineProperty(n, "_debugTask", {
|
|
186
186
|
configurable: !1,
|
|
187
187
|
enumerable: !1,
|
|
188
188
|
writable: !0,
|
|
189
|
-
value:
|
|
189
|
+
value: k
|
|
190
190
|
}), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
var
|
|
194
|
-
if (
|
|
195
|
-
if (
|
|
196
|
-
if (
|
|
197
|
-
for (
|
|
198
|
-
c(
|
|
199
|
-
Object.freeze && Object.freeze(
|
|
192
|
+
function A(n, i, b, g, P, T, $, k) {
|
|
193
|
+
var p = i.children;
|
|
194
|
+
if (p !== void 0)
|
|
195
|
+
if (g)
|
|
196
|
+
if (de(p)) {
|
|
197
|
+
for (g = 0; g < p.length; g++)
|
|
198
|
+
c(p[g]);
|
|
199
|
+
Object.freeze && Object.freeze(p);
|
|
200
200
|
} else
|
|
201
201
|
console.error(
|
|
202
202
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
203
203
|
);
|
|
204
|
-
else c(
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
var
|
|
208
|
-
return
|
|
204
|
+
else c(p);
|
|
205
|
+
if (q.call(i, "key")) {
|
|
206
|
+
p = a(n);
|
|
207
|
+
var j = Object.keys(i).filter(function(be) {
|
|
208
|
+
return be !== "key";
|
|
209
209
|
});
|
|
210
|
-
|
|
210
|
+
g = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", H[p + g] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
211
211
|
`A props object containing a "key" prop is being spread into JSX:
|
|
212
212
|
let props = %s;
|
|
213
213
|
<%s {...props} />
|
|
214
214
|
React keys must be passed directly to JSX without using spread:
|
|
215
215
|
let props = %s;
|
|
216
216
|
<%s key={someKey} {...props} />`,
|
|
217
|
+
g,
|
|
217
218
|
p,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
), X[h + p] = !0);
|
|
219
|
+
j,
|
|
220
|
+
p
|
|
221
|
+
), H[p + g] = !0);
|
|
222
222
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
for (var
|
|
226
|
-
|
|
227
|
-
} else
|
|
228
|
-
return
|
|
229
|
-
|
|
223
|
+
if (p = null, b !== void 0 && (r(b), p = "" + b), o(i) && (r(i.key), p = "" + i.key), "key" in i) {
|
|
224
|
+
b = {};
|
|
225
|
+
for (var M in i)
|
|
226
|
+
M !== "key" && (b[M] = i[M]);
|
|
227
|
+
} else b = i;
|
|
228
|
+
return p && _(
|
|
229
|
+
b,
|
|
230
230
|
typeof n == "function" ? n.displayName || n.name || "Unknown" : n
|
|
231
|
-
),
|
|
231
|
+
), w(
|
|
232
232
|
n,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
p,
|
|
234
|
+
T,
|
|
235
|
+
P,
|
|
236
|
+
s(),
|
|
237
|
+
b,
|
|
238
|
+
$,
|
|
239
|
+
k
|
|
240
240
|
);
|
|
241
241
|
}
|
|
242
242
|
function c(n) {
|
|
243
|
-
typeof n == "object" && n !== null && n.$$typeof ===
|
|
243
|
+
typeof n == "object" && n !== null && n.$$typeof === h && n._store && (n._store.validated = 1);
|
|
244
244
|
}
|
|
245
|
-
var
|
|
245
|
+
var S = he, h = Symbol.for("react.transitional.element"), d = Symbol.for("react.portal"), l = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), ne = Symbol.for("react.profiler"), se = Symbol.for("react.consumer"), ae = Symbol.for("react.context"), oe = Symbol.for("react.forward_ref"), ie = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), ce = Symbol.for("react.memo"), G = Symbol.for("react.lazy"), ue = Symbol.for("react.activity"), fe = Symbol.for("react.client.reference"), F = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, de = Array.isArray, Y = console.createTask ? console.createTask : function() {
|
|
246
246
|
return null;
|
|
247
247
|
};
|
|
248
|
-
|
|
248
|
+
S = {
|
|
249
249
|
react_stack_bottom_frame: function(n) {
|
|
250
250
|
return n();
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
-
var
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
)(), B =
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
return
|
|
253
|
+
var J, z = {}, X = S.react_stack_bottom_frame.bind(
|
|
254
|
+
S,
|
|
255
|
+
f
|
|
256
|
+
)(), B = Y(t(f)), H = {};
|
|
257
|
+
C.Fragment = l, C.jsx = function(n, i, b, g, P) {
|
|
258
|
+
var T = 1e4 > F.recentlyCreatedOwnerStacks++;
|
|
259
|
+
return A(
|
|
260
260
|
n,
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
i,
|
|
262
|
+
b,
|
|
263
263
|
!1,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
g,
|
|
265
|
+
P,
|
|
266
|
+
T ? Error("react-stack-top-frame") : X,
|
|
267
|
+
T ? Y(t(n)) : B
|
|
268
268
|
);
|
|
269
|
-
},
|
|
270
|
-
var
|
|
271
|
-
return
|
|
269
|
+
}, C.jsxs = function(n, i, b, g, P) {
|
|
270
|
+
var T = 1e4 > F.recentlyCreatedOwnerStacks++;
|
|
271
|
+
return A(
|
|
272
272
|
n,
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
i,
|
|
274
|
+
b,
|
|
275
275
|
!0,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
g,
|
|
277
|
+
P,
|
|
278
|
+
T ? Error("react-stack-top-frame") : X,
|
|
279
|
+
T ? Y(t(n)) : B
|
|
280
280
|
);
|
|
281
281
|
};
|
|
282
|
-
}()),
|
|
282
|
+
}()), C;
|
|
283
283
|
}
|
|
284
|
-
var
|
|
285
|
-
function
|
|
286
|
-
return
|
|
284
|
+
var K;
|
|
285
|
+
function ve() {
|
|
286
|
+
return K || (K = 1, process.env.NODE_ENV === "production" ? y.exports = Se() : y.exports = Ee()), y.exports;
|
|
287
287
|
}
|
|
288
|
-
var
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
y && console.log(
|
|
288
|
+
var xe = ve();
|
|
289
|
+
let te = !1;
|
|
290
|
+
const Le = (a) => {
|
|
291
|
+
te = a;
|
|
292
|
+
}, D = (...a) => {
|
|
293
|
+
te && console.log(
|
|
295
294
|
"%c[react-shared-states]",
|
|
296
295
|
"color: #007acc; font-weight: bold",
|
|
297
|
-
...
|
|
296
|
+
...a
|
|
298
297
|
);
|
|
299
|
-
}, R = (
|
|
300
|
-
if (!
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
|
|
298
|
+
}, R = (a) => {
|
|
299
|
+
if (!a) throw new Error("Value is empty");
|
|
300
|
+
return a;
|
|
301
|
+
}, N = () => Math.random().toString(36).substring(2, 15), re = ge(void 0), je = ({ children: a, scopeName: e }) => {
|
|
302
|
+
if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
|
|
303
|
+
return e || (e = L(() => N(), [])), /* @__PURE__ */ xe.jsx(re.Provider, { value: { scopeName: e }, children: a });
|
|
304
|
+
}, me = () => pe(re);
|
|
305
|
+
class u {
|
|
304
306
|
data = /* @__PURE__ */ new Map();
|
|
305
307
|
defaultValue() {
|
|
306
308
|
return {};
|
|
307
309
|
}
|
|
308
310
|
addListener(e, r, t) {
|
|
309
|
-
this.data.has(
|
|
311
|
+
this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
|
|
310
312
|
...this.defaultValue,
|
|
311
313
|
listeners: []
|
|
312
|
-
}), this.data.get(
|
|
314
|
+
}), this.data.get(u.prefix(e, r)).listeners.push(t);
|
|
313
315
|
}
|
|
314
316
|
removeListener(e, r, t) {
|
|
315
|
-
this.data.has(
|
|
317
|
+
this.data.has(u.prefix(e, r)) && (this.data.get(u.prefix(e, r)).listeners = this.data.get(u.prefix(e, r)).listeners.filter((s) => s !== t));
|
|
316
318
|
}
|
|
317
319
|
callListeners(e, r) {
|
|
318
|
-
this.data.has(
|
|
320
|
+
this.data.has(u.prefix(e, r)) && this.data.get(u.prefix(e, r)).listeners.forEach((t) => t());
|
|
319
321
|
}
|
|
320
322
|
init(e, r, t) {
|
|
321
|
-
this.data.has(
|
|
323
|
+
this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
|
|
322
324
|
...t,
|
|
323
325
|
listeners: []
|
|
324
326
|
});
|
|
@@ -329,7 +331,7 @@ class l {
|
|
|
329
331
|
}), this.data.clear();
|
|
330
332
|
}
|
|
331
333
|
clear(e, r, t = !1) {
|
|
332
|
-
t || this.callListeners(e, r), this.data.delete(
|
|
334
|
+
t || this.callListeners(e, r), this.data.delete(u.prefix(e, r));
|
|
333
335
|
}
|
|
334
336
|
get(e, r) {
|
|
335
337
|
let t = this.has(e, r);
|
|
@@ -337,30 +339,116 @@ class l {
|
|
|
337
339
|
return this.data.get(t);
|
|
338
340
|
}
|
|
339
341
|
setValue(e, r, t) {
|
|
340
|
-
this.data.has(
|
|
341
|
-
...this.data.get(
|
|
342
|
+
this.data.has(u.prefix(e, r)) && this.data.set(u.prefix(e, r), {
|
|
343
|
+
...this.data.get(u.prefix(e, r)),
|
|
342
344
|
...t
|
|
343
345
|
});
|
|
344
346
|
}
|
|
345
347
|
has(e, r) {
|
|
346
|
-
return this.data.has(
|
|
348
|
+
return this.data.has(u.prefix(e, r)) ? u.prefix(e, r) : this.data.has(u.prefix(e, "_global")) ? u.prefix(e, "_global") : void 0;
|
|
347
349
|
}
|
|
348
350
|
static prefix(e, r) {
|
|
349
|
-
|
|
351
|
+
if (e.includes("//")) throw new Error("key cannot contain '//'");
|
|
352
|
+
return `${r}//${e}`;
|
|
353
|
+
}
|
|
354
|
+
static extractPrefix(e) {
|
|
355
|
+
return e.split("//");
|
|
350
356
|
}
|
|
351
357
|
useEffect(e, r, t = null) {
|
|
352
|
-
|
|
353
|
-
t?.(),
|
|
358
|
+
ee(() => () => {
|
|
359
|
+
t?.(), D(`[${u.prefix(e, r)}]`, "unmount effect"), this.data.get(u.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
|
|
354
360
|
}, []);
|
|
355
361
|
}
|
|
356
362
|
}
|
|
357
|
-
|
|
358
|
-
|
|
363
|
+
class W {
|
|
364
|
+
constructor(e) {
|
|
365
|
+
this.sharedData = e;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* get a value from the shared data
|
|
369
|
+
* @param key
|
|
370
|
+
* @param scopeName
|
|
371
|
+
*/
|
|
372
|
+
get(e, r) {
|
|
373
|
+
e = R(e);
|
|
374
|
+
const t = r || "_global";
|
|
375
|
+
return this.sharedData.get(e, t);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* set a value in the shared data
|
|
379
|
+
* @param key
|
|
380
|
+
* @param value
|
|
381
|
+
* @param scopeName
|
|
382
|
+
*/
|
|
383
|
+
set(e, r, t) {
|
|
384
|
+
e = R(e);
|
|
385
|
+
const s = t || "_global";
|
|
386
|
+
this.sharedData.setValue(e, s, r);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* clear all values from the shared data
|
|
390
|
+
*/
|
|
391
|
+
clearAll() {
|
|
392
|
+
this.sharedData.clearAll();
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* clear all values from the shared data in a scope
|
|
396
|
+
* @param scopeName
|
|
397
|
+
*/
|
|
398
|
+
clearScope(e) {
|
|
399
|
+
const r = e || "_global";
|
|
400
|
+
this.sharedData.data.forEach((t, s) => {
|
|
401
|
+
const [f] = u.extractPrefix(s);
|
|
402
|
+
if (f === r) {
|
|
403
|
+
this.sharedData.clear(s, f);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* resolve a shared created object to a value
|
|
410
|
+
* @param sharedCreated
|
|
411
|
+
*/
|
|
412
|
+
resolve(e) {
|
|
413
|
+
const { key: r, prefix: t } = e;
|
|
414
|
+
return this.get(r, t);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* clear a value from the shared data
|
|
418
|
+
* @param key
|
|
419
|
+
* @param scopeName
|
|
420
|
+
*/
|
|
421
|
+
clear(e, r) {
|
|
422
|
+
let t, s;
|
|
423
|
+
typeof e == "string" ? (t = e, s = r || "_global") : (t = e.key, s = e.prefix), this.sharedData.clear(t, s);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* check if a value exists in the shared data
|
|
427
|
+
* @param key
|
|
428
|
+
* @param scopeName
|
|
429
|
+
*/
|
|
430
|
+
has(e, r = "_global") {
|
|
431
|
+
const t = r || "_global";
|
|
432
|
+
return !!this.sharedData.has(e, t);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* get all values from the shared data
|
|
436
|
+
*/
|
|
437
|
+
getAll() {
|
|
438
|
+
const e = {};
|
|
439
|
+
return this.sharedData.data.forEach((r, t) => {
|
|
440
|
+
const [s, f] = u.extractPrefix(t);
|
|
441
|
+
e[s] = e[s] || {}, e[s][f] = r;
|
|
442
|
+
}), e;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const U = (a) => {
|
|
446
|
+
const e = me();
|
|
359
447
|
return {
|
|
360
|
-
prefix:
|
|
448
|
+
prefix: a ?? e?.scopeName ?? "_global"
|
|
361
449
|
};
|
|
362
450
|
};
|
|
363
|
-
class
|
|
451
|
+
class _e extends u {
|
|
364
452
|
defaultValue() {
|
|
365
453
|
return { value: void 0 };
|
|
366
454
|
}
|
|
@@ -374,48 +462,47 @@ class me extends l {
|
|
|
374
462
|
super.removeListener(e, r, t);
|
|
375
463
|
}
|
|
376
464
|
}
|
|
377
|
-
class
|
|
465
|
+
class Re extends W {
|
|
378
466
|
get(e, r = "_global") {
|
|
379
467
|
e = R(e);
|
|
380
468
|
const t = r || "_global";
|
|
381
|
-
return
|
|
469
|
+
return m.get(e, t)?.value;
|
|
382
470
|
}
|
|
383
471
|
set(e, r, t = "_global") {
|
|
384
472
|
e = R(e);
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
clearAll() {
|
|
389
|
-
E.clearAll();
|
|
390
|
-
}
|
|
391
|
-
clear(e, r = "_global") {
|
|
392
|
-
const t = r || "_global";
|
|
393
|
-
E.clear(e, t);
|
|
394
|
-
}
|
|
395
|
-
has(e, r = "_global") {
|
|
396
|
-
const t = r || "_global";
|
|
397
|
-
return !!E.has(e, t);
|
|
398
|
-
}
|
|
399
|
-
getAll() {
|
|
400
|
-
return E.data;
|
|
473
|
+
const s = t || "_global";
|
|
474
|
+
m.setValue(e, s, { value: r });
|
|
401
475
|
}
|
|
402
476
|
}
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}), []), b = w(() => () => E.get(s, t)?.value, []), S = M(i, b), m = (f) => {
|
|
410
|
-
const T = typeof f == "function" ? f(E.get(s, t)?.value) : f;
|
|
411
|
-
T !== S && (E.setValue(s, t, T), E.callListeners(s, t));
|
|
477
|
+
const m = new _e(), Ve = new Re(m), Ce = (a, e) => {
|
|
478
|
+
const r = e ?? e ?? "_global";
|
|
479
|
+
return {
|
|
480
|
+
key: N(),
|
|
481
|
+
prefix: r,
|
|
482
|
+
initialValue: a
|
|
412
483
|
};
|
|
413
|
-
return E.useEffect(s, t), [
|
|
414
|
-
S,
|
|
415
|
-
m
|
|
416
|
-
];
|
|
417
484
|
};
|
|
418
|
-
|
|
485
|
+
function ye(a, e, r) {
|
|
486
|
+
let t, s, f = r;
|
|
487
|
+
if (typeof a != "string") {
|
|
488
|
+
const { key: c, initialValue: S, prefix: h } = a;
|
|
489
|
+
t = c, s = S, f = h;
|
|
490
|
+
} else
|
|
491
|
+
t = R(a), s = e;
|
|
492
|
+
const { prefix: o } = U(f);
|
|
493
|
+
m.init(t, o, s);
|
|
494
|
+
const _ = L(() => (c) => (m.init(t, o, e), m.addListener(t, o, c), () => {
|
|
495
|
+
m.removeListener(t, o, c);
|
|
496
|
+
}), []), O = L(() => () => m.get(t, o)?.value, []), w = I(_, O), A = (c) => {
|
|
497
|
+
const S = typeof c == "function" ? c(m.get(t, o)?.value) : c;
|
|
498
|
+
S !== w && (m.setValue(t, o, S), m.callListeners(t, o));
|
|
499
|
+
};
|
|
500
|
+
return m.useEffect(t, o), [
|
|
501
|
+
w,
|
|
502
|
+
A
|
|
503
|
+
];
|
|
504
|
+
}
|
|
505
|
+
class Te extends u {
|
|
419
506
|
defaultValue() {
|
|
420
507
|
return {
|
|
421
508
|
fnState: {
|
|
@@ -432,70 +519,70 @@ class _e extends l {
|
|
|
432
519
|
super.setValue(e, r, t);
|
|
433
520
|
}
|
|
434
521
|
}
|
|
435
|
-
class
|
|
522
|
+
class Ae extends W {
|
|
436
523
|
get(e, r = "_global") {
|
|
437
524
|
e = R(e);
|
|
438
525
|
const t = r || "_global";
|
|
439
|
-
return
|
|
526
|
+
return x.get(e, t)?.fnState;
|
|
440
527
|
}
|
|
441
528
|
set(e, r, t = "_global") {
|
|
442
529
|
e = R(e);
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
clearAll() {
|
|
447
|
-
v.clearAll();
|
|
448
|
-
}
|
|
449
|
-
clear(e, r = "_global") {
|
|
450
|
-
const t = r || "_global";
|
|
451
|
-
v.clear(e, t);
|
|
452
|
-
}
|
|
453
|
-
has(e, r = "_global") {
|
|
454
|
-
const t = r || "_global";
|
|
455
|
-
return !!v.has(e, t);
|
|
456
|
-
}
|
|
457
|
-
getAll() {
|
|
458
|
-
return v.data;
|
|
530
|
+
const s = t || "_global";
|
|
531
|
+
x.setValue(e, s, r);
|
|
459
532
|
}
|
|
460
533
|
}
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
534
|
+
const x = new Te(), Ne = new Ae(x), Fe = (a, e) => {
|
|
535
|
+
const r = e ?? e ?? "_global";
|
|
536
|
+
return {
|
|
537
|
+
key: N(),
|
|
538
|
+
prefix: r,
|
|
539
|
+
fn: a
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
function Ye(a, e, r) {
|
|
543
|
+
let t, s, f = r;
|
|
544
|
+
if (typeof a != "string") {
|
|
545
|
+
const { key: c, fn: S, prefix: h } = a;
|
|
546
|
+
t = c, s = S, f = h;
|
|
547
|
+
} else
|
|
548
|
+
t = R(a), s = e;
|
|
549
|
+
const { prefix: o } = U(f);
|
|
550
|
+
x.init(t, o);
|
|
551
|
+
const _ = L(
|
|
552
|
+
() => (c) => (x.init(t, o), x.addListener(t, o, c), () => {
|
|
553
|
+
x.removeListener(t, o, c);
|
|
468
554
|
}),
|
|
469
555
|
[]
|
|
470
|
-
),
|
|
471
|
-
() => () =>
|
|
556
|
+
), O = L(
|
|
557
|
+
() => () => x.get(t, o).fnState,
|
|
472
558
|
[]
|
|
473
|
-
),
|
|
474
|
-
const
|
|
475
|
-
if (!
|
|
476
|
-
|
|
559
|
+
), w = I(_, O), A = async (c, ...S) => {
|
|
560
|
+
const h = x.get(t, o);
|
|
561
|
+
if (!c && (h.fnState.isLoading || h.fnState.results !== void 0)) return h.fnState;
|
|
562
|
+
h.fnState = { ...h.fnState, isLoading: !0, error: void 0 }, h.listeners.forEach((d) => d());
|
|
477
563
|
try {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
} catch (
|
|
481
|
-
|
|
564
|
+
const d = await s(...S);
|
|
565
|
+
h.fnState = { results: d, isLoading: !1, error: void 0 };
|
|
566
|
+
} catch (d) {
|
|
567
|
+
h.fnState = { ...h.fnState, isLoading: !1, error: d };
|
|
482
568
|
}
|
|
483
|
-
|
|
569
|
+
h.listeners.forEach((d) => d());
|
|
484
570
|
};
|
|
485
|
-
return
|
|
486
|
-
state:
|
|
487
|
-
trigger: (...
|
|
488
|
-
|
|
571
|
+
return x.useEffect(t, o), {
|
|
572
|
+
state: w,
|
|
573
|
+
trigger: (...c) => {
|
|
574
|
+
A(!1, ...c);
|
|
489
575
|
},
|
|
490
|
-
forceTrigger: (...
|
|
491
|
-
|
|
576
|
+
forceTrigger: (...c) => {
|
|
577
|
+
A(!0, ...c);
|
|
492
578
|
},
|
|
493
579
|
clear: () => {
|
|
494
|
-
|
|
580
|
+
const c = x.get(t, o);
|
|
581
|
+
c && (c.fnState = x.defaultValue().fnState, x.callListeners(t, o));
|
|
495
582
|
}
|
|
496
583
|
};
|
|
497
|
-
}
|
|
498
|
-
class
|
|
584
|
+
}
|
|
585
|
+
class we extends u {
|
|
499
586
|
defaultValue() {
|
|
500
587
|
return {
|
|
501
588
|
fnState: {
|
|
@@ -513,94 +600,99 @@ class Te extends l {
|
|
|
513
600
|
super.setValue(e, r, t);
|
|
514
601
|
}
|
|
515
602
|
useEffect(e, r) {
|
|
516
|
-
|
|
517
|
-
|
|
603
|
+
ee(() => () => {
|
|
604
|
+
D(`[${u.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
|
|
518
605
|
}, []), super.useEffect(e, r);
|
|
519
606
|
}
|
|
520
607
|
async unsubscribe(e, r) {
|
|
521
608
|
const t = this.get(e, r);
|
|
522
|
-
t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState.subscribed
|
|
609
|
+
t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
|
|
523
610
|
}
|
|
524
611
|
}
|
|
525
|
-
class
|
|
612
|
+
class Pe extends W {
|
|
526
613
|
get(e, r = "_global") {
|
|
527
614
|
e = R(e);
|
|
528
615
|
const t = r || "_global";
|
|
529
|
-
return
|
|
616
|
+
return E.get(e, t)?.fnState;
|
|
530
617
|
}
|
|
531
618
|
set(e, r, t = "_global") {
|
|
532
619
|
e = R(e);
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
clearAll() {
|
|
537
|
-
d.clearAll();
|
|
538
|
-
}
|
|
539
|
-
clear(e, r = "_global") {
|
|
540
|
-
const t = r || "_global";
|
|
541
|
-
d.clear(e, t);
|
|
542
|
-
}
|
|
543
|
-
has(e, r = "_global") {
|
|
544
|
-
const t = r || "_global";
|
|
545
|
-
return !!d.has(e, t);
|
|
546
|
-
}
|
|
547
|
-
getAll() {
|
|
548
|
-
return d.data;
|
|
620
|
+
const s = t || "_global";
|
|
621
|
+
E.setValue(e, s, r);
|
|
549
622
|
}
|
|
550
623
|
}
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
624
|
+
const E = new we(), $e = new Pe(E), ke = (a, e) => {
|
|
625
|
+
const r = e ?? e ?? "_global";
|
|
626
|
+
return {
|
|
627
|
+
key: N(),
|
|
628
|
+
prefix: r,
|
|
629
|
+
subscriber: a
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
function Me(a, e, r) {
|
|
633
|
+
let t, s, f = r;
|
|
634
|
+
if (typeof a != "string") {
|
|
635
|
+
const { key: d, subscriber: l, prefix: v } = a;
|
|
636
|
+
t = d, s = l, f = v;
|
|
637
|
+
} else
|
|
638
|
+
t = R(a), s = e;
|
|
639
|
+
const { prefix: o } = U(f);
|
|
640
|
+
E.init(t, o);
|
|
641
|
+
const _ = L(
|
|
642
|
+
() => (d) => (E.init(t, o), E.addListener(t, o, d), () => {
|
|
643
|
+
E.removeListener(t, o, d);
|
|
558
644
|
}),
|
|
559
645
|
[]
|
|
560
|
-
),
|
|
561
|
-
() => () =>
|
|
646
|
+
), O = L(
|
|
647
|
+
() => () => E.get(t, o).fnState,
|
|
562
648
|
[]
|
|
563
|
-
),
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
},
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
},
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
},
|
|
573
|
-
const
|
|
574
|
-
if (
|
|
575
|
-
|
|
649
|
+
), w = I(_, O), A = (d) => {
|
|
650
|
+
const l = E.get(t, o);
|
|
651
|
+
l.fnState = { ...l.fnState, data: d }, l.listeners.forEach((v) => v());
|
|
652
|
+
}, c = (d) => {
|
|
653
|
+
const l = E.get(t, o);
|
|
654
|
+
l.fnState = { ...l.fnState, isLoading: !1, data: void 0, error: d }, l.listeners.forEach((v) => v());
|
|
655
|
+
}, S = () => {
|
|
656
|
+
const d = E.get(t, o);
|
|
657
|
+
d.fnState = { ...d.fnState, isLoading: !1 }, d.listeners.forEach((l) => l());
|
|
658
|
+
}, h = async (d) => {
|
|
659
|
+
const l = E.get(t, o);
|
|
660
|
+
if (d && (await E.unsubscribe(t, o), l.fnState = { ...l.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), l.fnState.subscribed) return l.fnState;
|
|
661
|
+
D("triggered !!"), l.fnState = { ...l.fnState, isLoading: !0, error: void 0 }, l.listeners.forEach((v) => v());
|
|
576
662
|
try {
|
|
577
|
-
|
|
578
|
-
} catch (
|
|
579
|
-
|
|
663
|
+
l.unsubscribe = await s(A, c, S), l.fnState.subscribed = !0;
|
|
664
|
+
} catch (v) {
|
|
665
|
+
l.fnState = { ...l.fnState, isLoading: !1, error: v };
|
|
580
666
|
}
|
|
581
|
-
|
|
667
|
+
l.listeners.forEach((v) => v());
|
|
582
668
|
};
|
|
583
|
-
return
|
|
584
|
-
state:
|
|
669
|
+
return E.useEffect(t, o), {
|
|
670
|
+
state: w,
|
|
585
671
|
trigger: () => {
|
|
586
|
-
|
|
672
|
+
h(!1);
|
|
587
673
|
},
|
|
588
674
|
forceTrigger: () => {
|
|
589
|
-
|
|
675
|
+
h(!0);
|
|
590
676
|
},
|
|
591
677
|
unsubscribe: () => {
|
|
592
|
-
|
|
678
|
+
E.unsubscribe(t, o);
|
|
593
679
|
}
|
|
594
680
|
};
|
|
595
|
-
}
|
|
681
|
+
}
|
|
596
682
|
export {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
683
|
+
Ae as SharedFunctionsApi,
|
|
684
|
+
Re as SharedStatesApi,
|
|
685
|
+
je as SharedStatesProvider,
|
|
686
|
+
Pe as SharedSubscriptionsApi,
|
|
687
|
+
Fe as createSharedFunction,
|
|
688
|
+
Ce as createSharedState,
|
|
689
|
+
ke as createSharedSubscription,
|
|
690
|
+
te as isDevMode,
|
|
691
|
+
Le as setDevMode,
|
|
692
|
+
Ne as sharedFunctionsApi,
|
|
693
|
+
Ve as sharedStatesApi,
|
|
694
|
+
$e as sharedSubscriptionsApi,
|
|
695
|
+
Ye as useSharedFunction,
|
|
696
|
+
ye as useSharedState,
|
|
697
|
+
Me as useSharedSubscription
|
|
606
698
|
};
|