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