react-shared-states 1.0.3 → 1.0.5
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 +174 -17
- package/dist/SharedData.d.ts +4 -3
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/use-shared-function.d.ts +4 -4
- package/dist/hooks/use-shared-state.d.ts +4 -4
- package/dist/hooks/use-shared-subscription.d.ts +39 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/main.esm.js +397 -268
- package/dist/main.min.js +5 -5
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/main.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.5
|
|
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 fe, { createContext as de, useMemo as w, useContext as be, useEffect as Q, useSyncExternalStore as I } from "react";
|
|
9
|
+
var L = { exports: {} }, P = {};
|
|
10
10
|
/**
|
|
11
11
|
* @license React
|
|
12
12
|
* react-jsx-runtime.production.js
|
|
@@ -16,29 +16,29 @@ var S = { exports: {} }, R = {};
|
|
|
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 s = Symbol.for("react.transitional.element"),
|
|
24
|
-
function t
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
|
|
19
|
+
var D;
|
|
20
|
+
function ge() {
|
|
21
|
+
if (D) return P;
|
|
22
|
+
D = 1;
|
|
23
|
+
var s = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
24
|
+
function r(t, i, b) {
|
|
25
|
+
var S = null;
|
|
26
|
+
if (b !== void 0 && (S = "" + b), i.key !== void 0 && (S = "" + i.key), "key" in i) {
|
|
27
|
+
b = {};
|
|
28
28
|
for (var m in i)
|
|
29
|
-
m !== "key" && (
|
|
30
|
-
} else
|
|
31
|
-
return i =
|
|
29
|
+
m !== "key" && (b[m] = i[m]);
|
|
30
|
+
} else b = i;
|
|
31
|
+
return i = b.ref, {
|
|
32
32
|
$$typeof: s,
|
|
33
|
-
type:
|
|
34
|
-
key:
|
|
33
|
+
type: t,
|
|
34
|
+
key: S,
|
|
35
35
|
ref: i !== void 0 ? i : null,
|
|
36
|
-
props:
|
|
36
|
+
props: b
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
return
|
|
39
|
+
return P.Fragment = e, P.jsx = r, P.jsxs = r, P;
|
|
40
40
|
}
|
|
41
|
-
var
|
|
41
|
+
var j = {};
|
|
42
42
|
/**
|
|
43
43
|
* @license React
|
|
44
44
|
* react-jsx-runtime.development.js
|
|
@@ -48,350 +48,370 @@ var x = {};
|
|
|
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 s(
|
|
55
|
-
if (
|
|
56
|
-
if (typeof
|
|
57
|
-
return
|
|
58
|
-
if (typeof
|
|
59
|
-
switch (
|
|
60
|
-
case
|
|
51
|
+
var H;
|
|
52
|
+
function pe() {
|
|
53
|
+
return H || (H = 1, process.env.NODE_ENV !== "production" && function() {
|
|
54
|
+
function s(n) {
|
|
55
|
+
if (n == null) return null;
|
|
56
|
+
if (typeof n == "function")
|
|
57
|
+
return n.$$typeof === le ? null : n.displayName || n.name || null;
|
|
58
|
+
if (typeof n == "string") return n;
|
|
59
|
+
switch (n) {
|
|
60
|
+
case N:
|
|
61
61
|
return "Fragment";
|
|
62
|
-
case
|
|
62
|
+
case ee:
|
|
63
63
|
return "Profiler";
|
|
64
|
-
case
|
|
64
|
+
case k:
|
|
65
65
|
return "StrictMode";
|
|
66
|
-
case
|
|
66
|
+
case se:
|
|
67
67
|
return "Suspense";
|
|
68
|
-
case
|
|
68
|
+
case ae:
|
|
69
69
|
return "SuspenseList";
|
|
70
|
-
case
|
|
70
|
+
case ie:
|
|
71
71
|
return "Activity";
|
|
72
72
|
}
|
|
73
|
-
if (typeof
|
|
74
|
-
switch (typeof
|
|
73
|
+
if (typeof n == "object")
|
|
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
|
-
),
|
|
77
|
-
case
|
|
76
|
+
), n.$$typeof) {
|
|
77
|
+
case y:
|
|
78
78
|
return "Portal";
|
|
79
|
-
case Z:
|
|
80
|
-
return (e.displayName || "Context") + ".Provider";
|
|
81
|
-
case H:
|
|
82
|
-
return (e._context.displayName || "Context") + ".Consumer";
|
|
83
|
-
case Q:
|
|
84
|
-
var a = e.render;
|
|
85
|
-
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
86
79
|
case re:
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
|
|
80
|
+
return (n.displayName || "Context") + ".Provider";
|
|
81
|
+
case te:
|
|
82
|
+
return (n._context.displayName || "Context") + ".Consumer";
|
|
83
|
+
case ne:
|
|
84
|
+
var a = n.render;
|
|
85
|
+
return n = n.displayName, n || (n = a.displayName || a.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
|
|
86
|
+
case oe:
|
|
87
|
+
return a = n.displayName || null, a !== null ? a : s(n.type) || "Memo";
|
|
88
|
+
case U:
|
|
89
|
+
a = n._payload, n = n._init;
|
|
90
90
|
try {
|
|
91
|
-
return s(
|
|
91
|
+
return s(n(a));
|
|
92
92
|
} catch {
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
return "" +
|
|
97
|
+
function e(n) {
|
|
98
|
+
return "" + n;
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function r(n) {
|
|
101
101
|
try {
|
|
102
|
-
|
|
102
|
+
e(n);
|
|
103
103
|
var a = !1;
|
|
104
104
|
} catch {
|
|
105
105
|
a = !0;
|
|
106
106
|
}
|
|
107
107
|
if (a) {
|
|
108
108
|
a = console;
|
|
109
|
-
var
|
|
110
|
-
return
|
|
109
|
+
var u = a.error, p = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
|
|
110
|
+
return u.call(
|
|
111
111
|
a,
|
|
112
112
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
113
|
-
|
|
114
|
-
),
|
|
113
|
+
p
|
|
114
|
+
), e(n);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
function n
|
|
118
|
-
if (
|
|
119
|
-
if (typeof
|
|
117
|
+
function t(n) {
|
|
118
|
+
if (n === N) return "<>";
|
|
119
|
+
if (typeof n == "object" && n !== null && n.$$typeof === U)
|
|
120
120
|
return "<...>";
|
|
121
121
|
try {
|
|
122
|
-
var a = s(
|
|
122
|
+
var a = s(n);
|
|
123
123
|
return a ? "<" + a + ">" : "<...>";
|
|
124
124
|
} catch {
|
|
125
125
|
return "<...>";
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function i() {
|
|
129
|
-
var
|
|
130
|
-
return
|
|
129
|
+
var n = C.A;
|
|
130
|
+
return n === null ? null : n.getOwner();
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function b() {
|
|
133
133
|
return Error("react-stack-top-frame");
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
if (
|
|
137
|
-
var a = Object.getOwnPropertyDescriptor(
|
|
135
|
+
function S(n) {
|
|
136
|
+
if (G.call(n, "key")) {
|
|
137
|
+
var a = Object.getOwnPropertyDescriptor(n, "key").get;
|
|
138
138
|
if (a && a.isReactWarning) return !1;
|
|
139
139
|
}
|
|
140
|
-
return
|
|
140
|
+
return n.key !== void 0;
|
|
141
141
|
}
|
|
142
|
-
function m(
|
|
143
|
-
function
|
|
144
|
-
|
|
142
|
+
function m(n, a) {
|
|
143
|
+
function u() {
|
|
144
|
+
q || (q = !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
|
a
|
|
147
147
|
));
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
get:
|
|
149
|
+
u.isReactWarning = !0, Object.defineProperty(n, "key", {
|
|
150
|
+
get: u,
|
|
151
151
|
configurable: !0
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
var
|
|
156
|
-
return
|
|
154
|
+
function f() {
|
|
155
|
+
var n = s(this.type);
|
|
156
|
+
return J[n] || (J[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:
|
|
163
|
-
type:
|
|
160
|
+
function T(n, a, u, p, A, x, Y, F) {
|
|
161
|
+
return u = x.ref, n = {
|
|
162
|
+
$$typeof: _,
|
|
163
|
+
type: n,
|
|
164
164
|
key: a,
|
|
165
|
-
props:
|
|
166
|
-
_owner:
|
|
167
|
-
}, (
|
|
165
|
+
props: x,
|
|
166
|
+
_owner: A
|
|
167
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(n, "ref", {
|
|
168
168
|
enumerable: !1,
|
|
169
|
-
get:
|
|
170
|
-
}) : Object.defineProperty(
|
|
169
|
+
get: f
|
|
170
|
+
}) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
|
|
171
171
|
configurable: !1,
|
|
172
172
|
enumerable: !1,
|
|
173
173
|
writable: !0,
|
|
174
174
|
value: 0
|
|
175
|
-
}), Object.defineProperty(
|
|
175
|
+
}), Object.defineProperty(n, "_debugInfo", {
|
|
176
176
|
configurable: !1,
|
|
177
177
|
enumerable: !1,
|
|
178
178
|
writable: !0,
|
|
179
179
|
value: null
|
|
180
|
-
}), Object.defineProperty(
|
|
180
|
+
}), Object.defineProperty(n, "_debugStack", {
|
|
181
181
|
configurable: !1,
|
|
182
182
|
enumerable: !1,
|
|
183
183
|
writable: !0,
|
|
184
|
-
value:
|
|
185
|
-
}), Object.defineProperty(
|
|
184
|
+
value: Y
|
|
185
|
+
}), Object.defineProperty(n, "_debugTask", {
|
|
186
186
|
configurable: !1,
|
|
187
187
|
enumerable: !1,
|
|
188
188
|
writable: !0,
|
|
189
|
-
value:
|
|
190
|
-
}), Object.freeze && (Object.freeze(
|
|
189
|
+
value: F
|
|
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 g(n, a, u, p, A, x, Y, F) {
|
|
193
|
+
var h = a.children;
|
|
194
|
+
if (h !== void 0)
|
|
195
|
+
if (p)
|
|
196
|
+
if (ce(h)) {
|
|
197
|
+
for (p = 0; p < h.length; p++)
|
|
198
|
+
c(h[p]);
|
|
199
|
+
Object.freeze && Object.freeze(h);
|
|
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(h);
|
|
205
|
+
if (G.call(a, "key")) {
|
|
206
|
+
h = s(n);
|
|
207
|
+
var O = Object.keys(a).filter(function(ue) {
|
|
208
|
+
return ue !== "key";
|
|
209
209
|
});
|
|
210
|
-
|
|
210
|
+
p = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", X[h + p] || (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} />
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
),
|
|
217
|
+
p,
|
|
218
|
+
h,
|
|
219
|
+
O,
|
|
220
|
+
h
|
|
221
|
+
), X[h + p] = !0);
|
|
222
222
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
for (var
|
|
226
|
-
|
|
227
|
-
} else
|
|
228
|
-
return
|
|
229
|
-
|
|
230
|
-
typeof
|
|
231
|
-
),
|
|
232
|
-
|
|
233
|
-
f,
|
|
234
|
-
E,
|
|
223
|
+
if (h = null, u !== void 0 && (r(u), h = "" + u), S(a) && (r(a.key), h = "" + a.key), "key" in a) {
|
|
224
|
+
u = {};
|
|
225
|
+
for (var $ in a)
|
|
226
|
+
$ !== "key" && (u[$] = a[$]);
|
|
227
|
+
} else u = a;
|
|
228
|
+
return h && m(
|
|
229
|
+
u,
|
|
230
|
+
typeof n == "function" ? n.displayName || n.name || "Unknown" : n
|
|
231
|
+
), T(
|
|
232
|
+
n,
|
|
235
233
|
h,
|
|
234
|
+
x,
|
|
235
|
+
A,
|
|
236
236
|
i(),
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
u,
|
|
238
|
+
Y,
|
|
239
|
+
F
|
|
240
240
|
);
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
typeof
|
|
242
|
+
function c(n) {
|
|
243
|
+
typeof n == "object" && n !== null && n.$$typeof === _ && n._store && (n._store.validated = 1);
|
|
244
244
|
}
|
|
245
|
-
var
|
|
245
|
+
var o = fe, _ = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), N = Symbol.for("react.fragment"), k = Symbol.for("react.strict_mode"), ee = Symbol.for("react.profiler"), te = Symbol.for("react.consumer"), re = Symbol.for("react.context"), ne = Symbol.for("react.forward_ref"), se = Symbol.for("react.suspense"), ae = Symbol.for("react.suspense_list"), oe = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), ie = Symbol.for("react.activity"), le = Symbol.for("react.client.reference"), C = o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, ce = Array.isArray, V = console.createTask ? console.createTask : function() {
|
|
246
246
|
return null;
|
|
247
247
|
};
|
|
248
|
-
|
|
249
|
-
react_stack_bottom_frame: function(
|
|
250
|
-
return
|
|
248
|
+
o = {
|
|
249
|
+
react_stack_bottom_frame: function(n) {
|
|
250
|
+
return n();
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
-
var
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
)(),
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
return
|
|
260
|
-
|
|
253
|
+
var q, J = {}, z = o.react_stack_bottom_frame.bind(
|
|
254
|
+
o,
|
|
255
|
+
b
|
|
256
|
+
)(), B = V(t(b)), X = {};
|
|
257
|
+
j.Fragment = N, j.jsx = function(n, a, u, p, A) {
|
|
258
|
+
var x = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
259
|
+
return g(
|
|
260
|
+
n,
|
|
261
261
|
a,
|
|
262
|
-
|
|
262
|
+
u,
|
|
263
263
|
!1,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
p,
|
|
265
|
+
A,
|
|
266
|
+
x ? Error("react-stack-top-frame") : z,
|
|
267
|
+
x ? V(t(n)) : B
|
|
268
268
|
);
|
|
269
|
-
},
|
|
270
|
-
var
|
|
271
|
-
return
|
|
272
|
-
|
|
269
|
+
}, j.jsxs = function(n, a, u, p, A) {
|
|
270
|
+
var x = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
271
|
+
return g(
|
|
272
|
+
n,
|
|
273
273
|
a,
|
|
274
|
-
|
|
274
|
+
u,
|
|
275
275
|
!0,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
p,
|
|
277
|
+
A,
|
|
278
|
+
x ? Error("react-stack-top-frame") : z,
|
|
279
|
+
x ? V(t(n)) : B
|
|
280
280
|
);
|
|
281
281
|
};
|
|
282
|
-
}()),
|
|
282
|
+
}()), j;
|
|
283
283
|
}
|
|
284
|
-
var
|
|
285
|
-
function
|
|
286
|
-
return
|
|
284
|
+
var Z;
|
|
285
|
+
function he() {
|
|
286
|
+
return Z || (Z = 1, process.env.NODE_ENV === "production" ? L.exports = ge() : L.exports = pe()), L.exports;
|
|
287
287
|
}
|
|
288
|
-
var
|
|
289
|
-
const
|
|
290
|
-
|
|
288
|
+
var Ee = he();
|
|
289
|
+
const K = de(void 0), we = ({ children: s, scopeName: e }) => (e || (e = w(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ Ee.jsx(K.Provider, { value: { scopeName: e }, children: s })), ve = () => be(K), M = (...s) => {
|
|
290
|
+
process.env.NODE_ENV === "development" && console.log(
|
|
291
|
+
"%c[react-shared-states]",
|
|
292
|
+
"color: #007acc; font-weight: bold",
|
|
293
|
+
...s
|
|
294
|
+
);
|
|
295
|
+
}, R = (s) => {
|
|
296
|
+
if (!s) throw new Error("Value is empty");
|
|
297
|
+
return s;
|
|
298
|
+
};
|
|
299
|
+
class l {
|
|
291
300
|
data = /* @__PURE__ */ new Map();
|
|
292
301
|
defaultValue() {
|
|
293
302
|
return {};
|
|
294
303
|
}
|
|
295
|
-
addListener(r, t
|
|
296
|
-
this.data.has(
|
|
304
|
+
addListener(e, r, t) {
|
|
305
|
+
this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
|
|
297
306
|
...this.defaultValue,
|
|
298
307
|
listeners: []
|
|
299
|
-
}), this.data.get(
|
|
308
|
+
}), this.data.get(l.prefix(e, r)).listeners.push(t);
|
|
300
309
|
}
|
|
301
|
-
removeListener(r, t
|
|
302
|
-
this.data.has(
|
|
310
|
+
removeListener(e, r, t) {
|
|
311
|
+
this.data.has(l.prefix(e, r)) && (this.data.get(l.prefix(e, r)).listeners = this.data.get(l.prefix(e, r)).listeners.filter((i) => i !== t));
|
|
303
312
|
}
|
|
304
|
-
callListeners(
|
|
305
|
-
this.data.has(
|
|
313
|
+
callListeners(e, r) {
|
|
314
|
+
this.data.has(l.prefix(e, r)) && this.data.get(l.prefix(e, r)).listeners.forEach((t) => t());
|
|
306
315
|
}
|
|
307
|
-
init(r, t
|
|
308
|
-
this.data.has(
|
|
309
|
-
...
|
|
316
|
+
init(e, r, t) {
|
|
317
|
+
this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
|
|
318
|
+
...t,
|
|
310
319
|
listeners: []
|
|
311
320
|
});
|
|
312
321
|
}
|
|
313
|
-
clearAll(
|
|
314
|
-
|
|
315
|
-
|
|
322
|
+
clearAll(e = !1) {
|
|
323
|
+
e || this.data.forEach((r) => {
|
|
324
|
+
r.listeners.forEach((t) => t());
|
|
316
325
|
}), this.data.clear();
|
|
317
326
|
}
|
|
318
|
-
clear(r, t
|
|
319
|
-
|
|
327
|
+
clear(e, r, t = !1) {
|
|
328
|
+
t || this.callListeners(e, r), this.data.delete(l.prefix(e, r));
|
|
320
329
|
}
|
|
321
|
-
get(
|
|
322
|
-
let
|
|
323
|
-
if (
|
|
324
|
-
return this.data.get(
|
|
330
|
+
get(e, r) {
|
|
331
|
+
let t = this.has(e, r);
|
|
332
|
+
if (t)
|
|
333
|
+
return this.data.get(t);
|
|
325
334
|
}
|
|
326
|
-
setValue(r, t
|
|
327
|
-
this.data.has(
|
|
328
|
-
...this.data.get(
|
|
329
|
-
...
|
|
335
|
+
setValue(e, r, t) {
|
|
336
|
+
this.data.has(l.prefix(e, r)) && this.data.set(l.prefix(e, r), {
|
|
337
|
+
...this.data.get(l.prefix(e, r)),
|
|
338
|
+
...t
|
|
330
339
|
});
|
|
331
340
|
}
|
|
332
|
-
has(
|
|
333
|
-
return this.data.has(
|
|
341
|
+
has(e, r) {
|
|
342
|
+
return this.data.has(l.prefix(e, r)) ? l.prefix(e, r) : this.data.has(l.prefix(e, "_global")) ? l.prefix(e, "_global") : void 0;
|
|
343
|
+
}
|
|
344
|
+
static prefix(e, r) {
|
|
345
|
+
return `${r}_${e}`;
|
|
334
346
|
}
|
|
335
|
-
|
|
336
|
-
|
|
347
|
+
useEffect(e, r, t = null) {
|
|
348
|
+
Q(() => () => {
|
|
349
|
+
t?.(), M(`[${l.prefix(e, r)}]`, "unmount effect"), this.data.get(l.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
|
|
350
|
+
}, []);
|
|
337
351
|
}
|
|
338
352
|
}
|
|
339
|
-
const
|
|
340
|
-
const
|
|
353
|
+
const W = (s) => {
|
|
354
|
+
const e = ve();
|
|
341
355
|
return {
|
|
342
|
-
prefix: s ??
|
|
356
|
+
prefix: s ?? e?.scopeName ?? "_global"
|
|
343
357
|
};
|
|
344
358
|
};
|
|
345
|
-
class
|
|
359
|
+
class Se extends l {
|
|
346
360
|
defaultValue() {
|
|
347
361
|
return { value: void 0 };
|
|
348
362
|
}
|
|
349
|
-
init(r, t
|
|
350
|
-
super.init(
|
|
363
|
+
init(e, r, t) {
|
|
364
|
+
super.init(e, r, { value: t });
|
|
365
|
+
}
|
|
366
|
+
setValue(e, r, t) {
|
|
367
|
+
super.setValue(e, r, { value: t });
|
|
351
368
|
}
|
|
352
|
-
|
|
353
|
-
super.
|
|
369
|
+
removeListener(e, r, t) {
|
|
370
|
+
super.removeListener(e, r, t);
|
|
354
371
|
}
|
|
355
372
|
}
|
|
356
373
|
class me {
|
|
357
|
-
get(
|
|
358
|
-
|
|
359
|
-
|
|
374
|
+
get(e, r = "_global") {
|
|
375
|
+
e = R(e);
|
|
376
|
+
const t = r || "_global";
|
|
377
|
+
return E.get(e, t)?.value;
|
|
360
378
|
}
|
|
361
|
-
set(r, t
|
|
362
|
-
|
|
363
|
-
|
|
379
|
+
set(e, r, t = "_global") {
|
|
380
|
+
e = R(e);
|
|
381
|
+
const i = t || "_global";
|
|
382
|
+
E.setValue(e, i, { value: r });
|
|
364
383
|
}
|
|
365
384
|
clearAll() {
|
|
366
|
-
|
|
385
|
+
E.clearAll();
|
|
367
386
|
}
|
|
368
|
-
clear(
|
|
369
|
-
const
|
|
370
|
-
|
|
387
|
+
clear(e, r = "_global") {
|
|
388
|
+
const t = r || "_global";
|
|
389
|
+
E.clear(e, t);
|
|
371
390
|
}
|
|
372
|
-
has(
|
|
373
|
-
const
|
|
374
|
-
return !!
|
|
391
|
+
has(e, r = "_global") {
|
|
392
|
+
const t = r || "_global";
|
|
393
|
+
return !!E.has(e, t);
|
|
375
394
|
}
|
|
376
395
|
getAll() {
|
|
377
|
-
return
|
|
396
|
+
return E.data;
|
|
378
397
|
}
|
|
379
398
|
}
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
399
|
+
const Oe = new me(), E = new Se(), Pe = (s, e, r) => {
|
|
400
|
+
s = R(s);
|
|
401
|
+
const { prefix: t } = W(r);
|
|
402
|
+
E.init(s, t, e);
|
|
403
|
+
const i = w(() => (f) => (E.init(s, t, e), E.addListener(s, t, f), () => {
|
|
404
|
+
E.removeListener(s, t, f);
|
|
405
|
+
}), []), b = w(() => () => E.get(s, t)?.value, []), S = I(i, b), m = (f) => {
|
|
406
|
+
const T = typeof f == "function" ? f(E.get(s, t)?.value) : f;
|
|
407
|
+
T !== S && (E.setValue(s, t, T), E.callListeners(s, t));
|
|
408
|
+
};
|
|
409
|
+
return E.useEffect(s, t), [
|
|
410
|
+
S,
|
|
411
|
+
m
|
|
392
412
|
];
|
|
393
413
|
};
|
|
394
|
-
class
|
|
414
|
+
class _e extends l {
|
|
395
415
|
defaultValue() {
|
|
396
416
|
return {
|
|
397
417
|
fnState: {
|
|
@@ -401,71 +421,180 @@ class Ee extends u {
|
|
|
401
421
|
}
|
|
402
422
|
};
|
|
403
423
|
}
|
|
404
|
-
init(
|
|
405
|
-
super.init(
|
|
424
|
+
init(e, r) {
|
|
425
|
+
super.init(e, r, this.defaultValue());
|
|
406
426
|
}
|
|
407
|
-
setValue(r, t
|
|
408
|
-
super.setValue(r, t
|
|
427
|
+
setValue(e, r, t) {
|
|
428
|
+
super.setValue(e, r, t);
|
|
409
429
|
}
|
|
410
430
|
}
|
|
411
|
-
class
|
|
412
|
-
get(
|
|
413
|
-
|
|
414
|
-
|
|
431
|
+
class xe {
|
|
432
|
+
get(e, r = "_global") {
|
|
433
|
+
e = R(e);
|
|
434
|
+
const t = r || "_global";
|
|
435
|
+
return v.get(e, t)?.fnState;
|
|
415
436
|
}
|
|
416
|
-
set(r, t
|
|
417
|
-
|
|
418
|
-
|
|
437
|
+
set(e, r, t = "_global") {
|
|
438
|
+
e = R(e);
|
|
439
|
+
const i = t || "_global";
|
|
440
|
+
v.setValue(e, i, r);
|
|
441
|
+
}
|
|
442
|
+
clearAll() {
|
|
443
|
+
v.clearAll();
|
|
444
|
+
}
|
|
445
|
+
clear(e, r = "_global") {
|
|
446
|
+
const t = r || "_global";
|
|
447
|
+
v.clear(e, t);
|
|
448
|
+
}
|
|
449
|
+
has(e, r = "_global") {
|
|
450
|
+
const t = r || "_global";
|
|
451
|
+
return !!v.has(e, t);
|
|
452
|
+
}
|
|
453
|
+
getAll() {
|
|
454
|
+
return v.data;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const je = new xe(), v = new _e(), Le = (s, e, r) => {
|
|
458
|
+
s = R(s);
|
|
459
|
+
const { prefix: t } = W(r);
|
|
460
|
+
v.init(s, t);
|
|
461
|
+
const i = w(
|
|
462
|
+
() => (f) => (v.init(s, t), v.addListener(s, t, f), () => {
|
|
463
|
+
v.removeListener(s, t, f);
|
|
464
|
+
}),
|
|
465
|
+
[]
|
|
466
|
+
), b = w(
|
|
467
|
+
() => () => v.get(s, t).fnState,
|
|
468
|
+
[]
|
|
469
|
+
), S = I(i, b), m = async (f, ...T) => {
|
|
470
|
+
const g = v.get(s, t);
|
|
471
|
+
if (!f && (g.fnState.isLoading || g.fnState.results !== void 0)) return g.fnState;
|
|
472
|
+
g.fnState = { ...g.fnState, isLoading: !0, error: void 0 }, g.listeners.forEach((c) => c());
|
|
473
|
+
try {
|
|
474
|
+
const c = await e(...T);
|
|
475
|
+
g.fnState = { results: c, isLoading: !1, error: void 0 };
|
|
476
|
+
} catch (c) {
|
|
477
|
+
g.fnState = { ...g.fnState, isLoading: !1, error: c };
|
|
478
|
+
}
|
|
479
|
+
g.listeners.forEach((c) => c());
|
|
480
|
+
};
|
|
481
|
+
return v.useEffect(s, t), {
|
|
482
|
+
state: S,
|
|
483
|
+
trigger: (...f) => {
|
|
484
|
+
m(!1, ...f);
|
|
485
|
+
},
|
|
486
|
+
forceTrigger: (...f) => {
|
|
487
|
+
m(!0, ...f);
|
|
488
|
+
},
|
|
489
|
+
clear: () => {
|
|
490
|
+
v.clear(s, t), v.init(s, t);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
class Re extends l {
|
|
495
|
+
defaultValue() {
|
|
496
|
+
return {
|
|
497
|
+
fnState: {
|
|
498
|
+
data: void 0,
|
|
499
|
+
isLoading: !1,
|
|
500
|
+
error: void 0,
|
|
501
|
+
subscribed: !1
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
init(e, r) {
|
|
506
|
+
super.init(e, r, this.defaultValue());
|
|
507
|
+
}
|
|
508
|
+
setValue(e, r, t) {
|
|
509
|
+
super.setValue(e, r, t);
|
|
510
|
+
}
|
|
511
|
+
useEffect(e, r) {
|
|
512
|
+
Q(() => () => {
|
|
513
|
+
M(`[${l.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
|
|
514
|
+
}, []), super.useEffect(e, r);
|
|
515
|
+
}
|
|
516
|
+
async unsubscribe(e, r) {
|
|
517
|
+
const t = this.get(e, r);
|
|
518
|
+
t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState.subscribed = !1);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
class Te {
|
|
522
|
+
get(e, r = "_global") {
|
|
523
|
+
e = R(e);
|
|
524
|
+
const t = r || "_global";
|
|
525
|
+
return d.get(e, t)?.fnState;
|
|
526
|
+
}
|
|
527
|
+
set(e, r, t = "_global") {
|
|
528
|
+
e = R(e);
|
|
529
|
+
const i = t || "_global";
|
|
530
|
+
d.setValue(e, i, r);
|
|
419
531
|
}
|
|
420
532
|
clearAll() {
|
|
421
533
|
d.clearAll();
|
|
422
534
|
}
|
|
423
|
-
clear(
|
|
424
|
-
const
|
|
425
|
-
d.clear(
|
|
535
|
+
clear(e, r = "_global") {
|
|
536
|
+
const t = r || "_global";
|
|
537
|
+
d.clear(e, t);
|
|
426
538
|
}
|
|
427
|
-
has(
|
|
428
|
-
const
|
|
429
|
-
return !!d.has(
|
|
539
|
+
has(e, r = "_global") {
|
|
540
|
+
const t = r || "_global";
|
|
541
|
+
return !!d.has(e, t);
|
|
430
542
|
}
|
|
431
543
|
getAll() {
|
|
432
544
|
return d.data;
|
|
433
545
|
}
|
|
434
546
|
}
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
547
|
+
const Ne = new Te(), d = new Re(), Ce = (s, e, r) => {
|
|
548
|
+
s = R(s);
|
|
549
|
+
const { prefix: t } = W(r);
|
|
550
|
+
d.init(s, t);
|
|
551
|
+
const i = w(
|
|
552
|
+
() => (c) => (d.init(s, t), d.addListener(s, t, c), () => {
|
|
553
|
+
d.removeListener(s, t, c);
|
|
554
|
+
}),
|
|
555
|
+
[]
|
|
556
|
+
), b = w(
|
|
557
|
+
() => () => d.get(s, t).fnState,
|
|
558
|
+
[]
|
|
559
|
+
), S = I(i, b), m = (c) => {
|
|
560
|
+
const o = d.get(s, t);
|
|
561
|
+
o.fnState = { ...o.fnState, data: c }, o.listeners.forEach((_) => _());
|
|
562
|
+
}, f = (c) => {
|
|
563
|
+
const o = d.get(s, t);
|
|
564
|
+
o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: c }, o.listeners.forEach((_) => _());
|
|
565
|
+
}, T = () => {
|
|
566
|
+
const c = d.get(s, t);
|
|
567
|
+
c.fnState = { ...c.fnState, isLoading: !1 }, c.listeners.forEach((o) => o());
|
|
568
|
+
}, g = async (c) => {
|
|
569
|
+
const o = d.get(s, t);
|
|
570
|
+
if (c && (await d.unsubscribe(s, t), o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), o.fnState.subscribed) return o.fnState;
|
|
571
|
+
M("triggered !!"), o.fnState = { ...o.fnState, isLoading: !0, error: void 0 }, o.listeners.forEach((_) => _());
|
|
444
572
|
try {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
b.fnState = { ...b.fnState, isLoading: !1, error: v };
|
|
573
|
+
o.unsubscribe = await e(m, f, T), o.fnState.subscribed = !0;
|
|
574
|
+
} catch (_) {
|
|
575
|
+
o.fnState = { ...o.fnState, isLoading: !1, error: _ };
|
|
449
576
|
}
|
|
450
|
-
|
|
577
|
+
o.listeners.forEach((_) => _());
|
|
451
578
|
};
|
|
452
|
-
return {
|
|
453
|
-
state:
|
|
454
|
-
trigger: (
|
|
455
|
-
g(!1
|
|
579
|
+
return d.useEffect(s, t), {
|
|
580
|
+
state: S,
|
|
581
|
+
trigger: () => {
|
|
582
|
+
g(!1);
|
|
456
583
|
},
|
|
457
|
-
forceTrigger: (
|
|
458
|
-
g(!0
|
|
584
|
+
forceTrigger: () => {
|
|
585
|
+
g(!0);
|
|
459
586
|
},
|
|
460
|
-
|
|
461
|
-
d.
|
|
587
|
+
unsubscribe: () => {
|
|
588
|
+
d.unsubscribe(s, t);
|
|
462
589
|
}
|
|
463
590
|
};
|
|
464
591
|
};
|
|
465
592
|
export {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
593
|
+
we as SharedStatesProvider,
|
|
594
|
+
je as sharedFunctionsApi,
|
|
595
|
+
Oe as sharedStatesApi,
|
|
596
|
+
Ne as sharedSubscriptionsApi,
|
|
597
|
+
Le as useSharedFunction,
|
|
598
|
+
Pe as useSharedState,
|
|
599
|
+
Ce as useSharedSubscription
|
|
471
600
|
};
|