react-shared-states 1.0.7 → 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 +3 -0
- package/README.md +118 -64
- package/dist/SharedData.d.ts +5 -4
- package/dist/context/SharedStatesContext.d.ts +5 -4
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/use-shared-function.d.ts +9 -7
- package/dist/hooks/use-shared-state.d.ts +8 -4
- package/dist/hooks/use-shared-subscription.d.ts +9 -8
- package/dist/lib/utils.d.ts +2 -2
- package/dist/main.esm.js +333 -280
- package/dist/main.min.js +5 -5
- package/dist/types.d.ts +4 -1
- package/package.json +6 -2
- 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: {} }, O = {};
|
|
|
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 (f !== void 0 && (
|
|
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
27
|
f = {};
|
|
28
|
-
for (var
|
|
29
|
-
|
|
30
|
-
} else f =
|
|
31
|
-
return
|
|
32
|
-
$$typeof:
|
|
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:
|
|
34
|
+
key: o,
|
|
35
|
+
ref: s !== void 0 ? s : null,
|
|
36
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
|
|
51
|
+
var Q;
|
|
52
52
|
function Ee() {
|
|
53
|
-
return
|
|
54
|
-
function
|
|
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 oe:
|
|
67
|
-
return "Suspense";
|
|
68
66
|
case ie:
|
|
69
|
-
return "
|
|
67
|
+
return "Suspense";
|
|
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
|
|
81
|
+
case se:
|
|
82
82
|
return (n._context.displayName || "Context") + ".Consumer";
|
|
83
|
-
case
|
|
84
|
-
var
|
|
85
|
-
return n = n.displayName, n || (n =
|
|
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
86
|
case ce:
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
|
|
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 Ee() {
|
|
|
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
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,147 +181,146 @@ function Ee() {
|
|
|
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
|
-
|
|
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
|
|
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
|
-
h,
|
|
218
217
|
g,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
p,
|
|
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
|
-
function
|
|
243
|
-
typeof n == "object" && n !== null && n.$$typeof ===
|
|
242
|
+
function c(n) {
|
|
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
|
-
|
|
253
|
+
var J, z = {}, X = S.react_stack_bottom_frame.bind(
|
|
254
|
+
S,
|
|
255
255
|
f
|
|
256
|
-
)(),
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
return
|
|
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
|
-
const je = (s) => {
|
|
295
|
-
k = s;
|
|
296
|
-
}, I = (...s) => {
|
|
297
|
-
k && console.log(
|
|
288
|
+
var xe = ve();
|
|
289
|
+
let te = !1;
|
|
290
|
+
const Le = (a) => {
|
|
291
|
+
te = a;
|
|
292
|
+
}, D = (...a) => {
|
|
293
|
+
te && console.log(
|
|
298
294
|
"%c[react-shared-states]",
|
|
299
295
|
"color: #007acc; font-weight: bold",
|
|
300
|
-
...
|
|
296
|
+
...a
|
|
301
297
|
);
|
|
302
|
-
},
|
|
303
|
-
if (!
|
|
304
|
-
return
|
|
305
|
-
}
|
|
306
|
-
|
|
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 {
|
|
307
306
|
data = /* @__PURE__ */ new Map();
|
|
308
307
|
defaultValue() {
|
|
309
308
|
return {};
|
|
310
309
|
}
|
|
311
310
|
addListener(e, r, t) {
|
|
312
|
-
this.data.has(
|
|
311
|
+
this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
|
|
313
312
|
...this.defaultValue,
|
|
314
313
|
listeners: []
|
|
315
|
-
}), this.data.get(
|
|
314
|
+
}), this.data.get(u.prefix(e, r)).listeners.push(t);
|
|
316
315
|
}
|
|
317
316
|
removeListener(e, r, t) {
|
|
318
|
-
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));
|
|
319
318
|
}
|
|
320
319
|
callListeners(e, r) {
|
|
321
|
-
this.data.has(
|
|
320
|
+
this.data.has(u.prefix(e, r)) && this.data.get(u.prefix(e, r)).listeners.forEach((t) => t());
|
|
322
321
|
}
|
|
323
322
|
init(e, r, t) {
|
|
324
|
-
this.data.has(
|
|
323
|
+
this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
|
|
325
324
|
...t,
|
|
326
325
|
listeners: []
|
|
327
326
|
});
|
|
@@ -332,7 +331,7 @@ class c {
|
|
|
332
331
|
}), this.data.clear();
|
|
333
332
|
}
|
|
334
333
|
clear(e, r, t = !1) {
|
|
335
|
-
t || this.callListeners(e, r), this.data.delete(
|
|
334
|
+
t || this.callListeners(e, r), this.data.delete(u.prefix(e, r));
|
|
336
335
|
}
|
|
337
336
|
get(e, r) {
|
|
338
337
|
let t = this.has(e, r);
|
|
@@ -340,13 +339,13 @@ class c {
|
|
|
340
339
|
return this.data.get(t);
|
|
341
340
|
}
|
|
342
341
|
setValue(e, r, t) {
|
|
343
|
-
this.data.has(
|
|
344
|
-
...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)),
|
|
345
344
|
...t
|
|
346
345
|
});
|
|
347
346
|
}
|
|
348
347
|
has(e, r) {
|
|
349
|
-
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;
|
|
350
349
|
}
|
|
351
350
|
static prefix(e, r) {
|
|
352
351
|
if (e.includes("//")) throw new Error("key cannot contain '//'");
|
|
@@ -356,12 +355,12 @@ class c {
|
|
|
356
355
|
return e.split("//");
|
|
357
356
|
}
|
|
358
357
|
useEffect(e, r, t = null) {
|
|
359
|
-
|
|
360
|
-
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);
|
|
361
360
|
}, []);
|
|
362
361
|
}
|
|
363
362
|
}
|
|
364
|
-
class
|
|
363
|
+
class W {
|
|
365
364
|
constructor(e) {
|
|
366
365
|
this.sharedData = e;
|
|
367
366
|
}
|
|
@@ -371,7 +370,7 @@ class D {
|
|
|
371
370
|
* @param scopeName
|
|
372
371
|
*/
|
|
373
372
|
get(e, r) {
|
|
374
|
-
e =
|
|
373
|
+
e = R(e);
|
|
375
374
|
const t = r || "_global";
|
|
376
375
|
return this.sharedData.get(e, t);
|
|
377
376
|
}
|
|
@@ -382,9 +381,9 @@ class D {
|
|
|
382
381
|
* @param scopeName
|
|
383
382
|
*/
|
|
384
383
|
set(e, r, t) {
|
|
385
|
-
e =
|
|
386
|
-
const
|
|
387
|
-
this.sharedData.setValue(e,
|
|
384
|
+
e = R(e);
|
|
385
|
+
const s = t || "_global";
|
|
386
|
+
this.sharedData.setValue(e, s, r);
|
|
388
387
|
}
|
|
389
388
|
/**
|
|
390
389
|
* clear all values from the shared data
|
|
@@ -398,22 +397,30 @@ class D {
|
|
|
398
397
|
*/
|
|
399
398
|
clearScope(e) {
|
|
400
399
|
const r = e || "_global";
|
|
401
|
-
this.sharedData.data.forEach((t,
|
|
402
|
-
const [f] =
|
|
400
|
+
this.sharedData.data.forEach((t, s) => {
|
|
401
|
+
const [f] = u.extractPrefix(s);
|
|
403
402
|
if (f === r) {
|
|
404
|
-
this.sharedData.clear(
|
|
403
|
+
this.sharedData.clear(s, f);
|
|
405
404
|
return;
|
|
406
405
|
}
|
|
407
406
|
});
|
|
408
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
|
+
}
|
|
409
416
|
/**
|
|
410
417
|
* clear a value from the shared data
|
|
411
418
|
* @param key
|
|
412
419
|
* @param scopeName
|
|
413
420
|
*/
|
|
414
421
|
clear(e, r) {
|
|
415
|
-
|
|
416
|
-
this.sharedData.clear(
|
|
422
|
+
let t, s;
|
|
423
|
+
typeof e == "string" ? (t = e, s = r || "_global") : (t = e.key, s = e.prefix), this.sharedData.clear(t, s);
|
|
417
424
|
}
|
|
418
425
|
/**
|
|
419
426
|
* check if a value exists in the shared data
|
|
@@ -430,18 +437,18 @@ class D {
|
|
|
430
437
|
getAll() {
|
|
431
438
|
const e = {};
|
|
432
439
|
return this.sharedData.data.forEach((r, t) => {
|
|
433
|
-
const [
|
|
434
|
-
e[
|
|
440
|
+
const [s, f] = u.extractPrefix(t);
|
|
441
|
+
e[s] = e[s] || {}, e[s][f] = r;
|
|
435
442
|
}), e;
|
|
436
443
|
}
|
|
437
444
|
}
|
|
438
|
-
const
|
|
445
|
+
const U = (a) => {
|
|
439
446
|
const e = me();
|
|
440
447
|
return {
|
|
441
|
-
prefix:
|
|
448
|
+
prefix: a ?? e?.scopeName ?? "_global"
|
|
442
449
|
};
|
|
443
450
|
};
|
|
444
|
-
class
|
|
451
|
+
class _e extends u {
|
|
445
452
|
defaultValue() {
|
|
446
453
|
return { value: void 0 };
|
|
447
454
|
}
|
|
@@ -455,34 +462,47 @@ class xe extends c {
|
|
|
455
462
|
super.removeListener(e, r, t);
|
|
456
463
|
}
|
|
457
464
|
}
|
|
458
|
-
class
|
|
465
|
+
class Re extends W {
|
|
459
466
|
get(e, r = "_global") {
|
|
460
|
-
e =
|
|
467
|
+
e = R(e);
|
|
461
468
|
const t = r || "_global";
|
|
462
469
|
return m.get(e, t)?.value;
|
|
463
470
|
}
|
|
464
471
|
set(e, r, t = "_global") {
|
|
465
|
-
e =
|
|
466
|
-
const
|
|
467
|
-
m.setValue(e,
|
|
472
|
+
e = R(e);
|
|
473
|
+
const s = t || "_global";
|
|
474
|
+
m.setValue(e, s, { value: r });
|
|
468
475
|
}
|
|
469
476
|
}
|
|
470
|
-
const m = new
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}), []), f = w(() => () => m.get(s, t)?.value, []), E = M(o, f), S = (d) => {
|
|
477
|
-
const T = typeof d == "function" ? d(m.get(s, t)?.value) : d;
|
|
478
|
-
T !== E && (m.setValue(s, t, T), m.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
|
|
479
483
|
};
|
|
480
|
-
return m.useEffect(s, t), [
|
|
481
|
-
E,
|
|
482
|
-
S
|
|
483
|
-
];
|
|
484
484
|
};
|
|
485
|
-
|
|
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 {
|
|
486
506
|
defaultValue() {
|
|
487
507
|
return {
|
|
488
508
|
fnState: {
|
|
@@ -499,56 +519,70 @@ class Re extends c {
|
|
|
499
519
|
super.setValue(e, r, t);
|
|
500
520
|
}
|
|
501
521
|
}
|
|
502
|
-
class
|
|
522
|
+
class Ae extends W {
|
|
503
523
|
get(e, r = "_global") {
|
|
504
|
-
e =
|
|
524
|
+
e = R(e);
|
|
505
525
|
const t = r || "_global";
|
|
506
526
|
return x.get(e, t)?.fnState;
|
|
507
527
|
}
|
|
508
528
|
set(e, r, t = "_global") {
|
|
509
|
-
e =
|
|
510
|
-
const
|
|
511
|
-
x.setValue(e,
|
|
529
|
+
e = R(e);
|
|
530
|
+
const s = t || "_global";
|
|
531
|
+
x.setValue(e, s, r);
|
|
512
532
|
}
|
|
513
533
|
}
|
|
514
|
-
const x = new
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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);
|
|
521
554
|
}),
|
|
522
555
|
[]
|
|
523
|
-
),
|
|
524
|
-
() => () => x.get(
|
|
556
|
+
), O = L(
|
|
557
|
+
() => () => x.get(t, o).fnState,
|
|
525
558
|
[]
|
|
526
|
-
),
|
|
527
|
-
const
|
|
528
|
-
if (!
|
|
529
|
-
|
|
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());
|
|
530
563
|
try {
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
} catch (
|
|
534
|
-
|
|
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 };
|
|
535
568
|
}
|
|
536
|
-
|
|
569
|
+
h.listeners.forEach((d) => d());
|
|
537
570
|
};
|
|
538
|
-
return x.useEffect(
|
|
539
|
-
state:
|
|
540
|
-
trigger: (...
|
|
541
|
-
|
|
571
|
+
return x.useEffect(t, o), {
|
|
572
|
+
state: w,
|
|
573
|
+
trigger: (...c) => {
|
|
574
|
+
A(!1, ...c);
|
|
542
575
|
},
|
|
543
|
-
forceTrigger: (...
|
|
544
|
-
|
|
576
|
+
forceTrigger: (...c) => {
|
|
577
|
+
A(!0, ...c);
|
|
545
578
|
},
|
|
546
579
|
clear: () => {
|
|
547
|
-
|
|
580
|
+
const c = x.get(t, o);
|
|
581
|
+
c && (c.fnState = x.defaultValue().fnState, x.callListeners(t, o));
|
|
548
582
|
}
|
|
549
583
|
};
|
|
550
|
-
}
|
|
551
|
-
class
|
|
584
|
+
}
|
|
585
|
+
class we extends u {
|
|
552
586
|
defaultValue() {
|
|
553
587
|
return {
|
|
554
588
|
fnState: {
|
|
@@ -566,80 +600,99 @@ class Ae extends c {
|
|
|
566
600
|
super.setValue(e, r, t);
|
|
567
601
|
}
|
|
568
602
|
useEffect(e, r) {
|
|
569
|
-
|
|
570
|
-
|
|
603
|
+
ee(() => () => {
|
|
604
|
+
D(`[${u.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
|
|
571
605
|
}, []), super.useEffect(e, r);
|
|
572
606
|
}
|
|
573
607
|
async unsubscribe(e, r) {
|
|
574
608
|
const t = this.get(e, r);
|
|
575
|
-
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));
|
|
576
610
|
}
|
|
577
611
|
}
|
|
578
|
-
class
|
|
612
|
+
class Pe extends W {
|
|
579
613
|
get(e, r = "_global") {
|
|
580
|
-
e =
|
|
614
|
+
e = R(e);
|
|
581
615
|
const t = r || "_global";
|
|
582
|
-
return
|
|
616
|
+
return E.get(e, t)?.fnState;
|
|
583
617
|
}
|
|
584
618
|
set(e, r, t = "_global") {
|
|
585
|
-
e =
|
|
586
|
-
const
|
|
587
|
-
|
|
619
|
+
e = R(e);
|
|
620
|
+
const s = t || "_global";
|
|
621
|
+
E.setValue(e, s, r);
|
|
588
622
|
}
|
|
589
623
|
}
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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);
|
|
597
644
|
}),
|
|
598
645
|
[]
|
|
599
|
-
),
|
|
600
|
-
() => () =>
|
|
646
|
+
), O = L(
|
|
647
|
+
() => () => E.get(t, o).fnState,
|
|
601
648
|
[]
|
|
602
|
-
),
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
},
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
},
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
614
|
-
|
|
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());
|
|
615
662
|
try {
|
|
616
|
-
|
|
663
|
+
l.unsubscribe = await s(A, c, S), l.fnState.subscribed = !0;
|
|
617
664
|
} catch (v) {
|
|
618
|
-
|
|
665
|
+
l.fnState = { ...l.fnState, isLoading: !1, error: v };
|
|
619
666
|
}
|
|
620
|
-
|
|
667
|
+
l.listeners.forEach((v) => v());
|
|
621
668
|
};
|
|
622
|
-
return
|
|
623
|
-
state:
|
|
669
|
+
return E.useEffect(t, o), {
|
|
670
|
+
state: w,
|
|
624
671
|
trigger: () => {
|
|
625
|
-
|
|
672
|
+
h(!1);
|
|
626
673
|
},
|
|
627
674
|
forceTrigger: () => {
|
|
628
|
-
|
|
675
|
+
h(!0);
|
|
629
676
|
},
|
|
630
677
|
unsubscribe: () => {
|
|
631
|
-
|
|
678
|
+
E.unsubscribe(t, o);
|
|
632
679
|
}
|
|
633
680
|
};
|
|
634
|
-
}
|
|
681
|
+
}
|
|
635
682
|
export {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
je as
|
|
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,
|
|
639
692
|
Ne as sharedFunctionsApi,
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
693
|
+
Ve as sharedStatesApi,
|
|
694
|
+
$e as sharedSubscriptionsApi,
|
|
695
|
+
Ye as useSharedFunction,
|
|
696
|
+
ye as useSharedState,
|
|
697
|
+
Me as useSharedSubscription
|
|
645
698
|
};
|