react-shared-states 1.0.13 → 1.0.14
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 +5 -5
- package/dist/SharedValuesManager.d.ts +8 -0
- package/dist/hooks/use-shared-function.d.ts +6 -0
- package/dist/hooks/use-shared-state.d.ts +2 -0
- package/dist/hooks/use-shared-subscription.d.ts +6 -0
- package/dist/main.esm.js +244 -220
- package/dist/main.min.js +5 -5
- package/package.json +1 -1
- package/tests/index.test.tsx +50 -0
package/README.md
CHANGED
|
@@ -519,11 +519,11 @@ const subStateScoped = sharedSubscriptionsApi.get('live-chat', 'myScope');
|
|
|
519
519
|
|
|
520
520
|
## API summary:
|
|
521
521
|
|
|
522
|
-
| API | Methods
|
|
523
|
-
|
|
524
|
-
| `sharedStatesApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
525
|
-
| `sharedFunctionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
526
|
-
| `sharedSubscriptionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
522
|
+
| API | Methods |
|
|
523
|
+
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
524
|
+
| `sharedStatesApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
525
|
+
| `sharedFunctionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
526
|
+
| `sharedSubscriptionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
527
527
|
|
|
528
528
|
`scopeName` defaults to `"_global"`. Internally, keys are stored as `${scope}//${key}`. The `.getAll()` method returns a nested object: `{ [scope]: { [key]: value } }`.
|
|
529
529
|
|
|
@@ -39,6 +39,14 @@ export declare class SharedValuesApi<T extends SharedValue, V, R = T> {
|
|
|
39
39
|
*/
|
|
40
40
|
set<S extends string = string>(key: S, value: V, scopeName: Prefix): void;
|
|
41
41
|
set<S extends string = string>(sharedCreated: SharedCreated, value: V): void;
|
|
42
|
+
/**
|
|
43
|
+
* update a value in the shared data
|
|
44
|
+
* @param key
|
|
45
|
+
* @param updater
|
|
46
|
+
* @param scopeName
|
|
47
|
+
*/
|
|
48
|
+
update<S extends string = string>(key: S, updater: (prev: R) => V, scopeName: Prefix): void;
|
|
49
|
+
update<S extends string = string>(sharedCreated: SharedCreated, updater: (prev: R) => V): void;
|
|
42
50
|
/**
|
|
43
51
|
* clear all values from the shared data
|
|
44
52
|
*/
|
|
@@ -35,6 +35,12 @@ export declare class SharedFunctionsApi extends SharedValuesApi<SharedFunction<u
|
|
|
35
35
|
set<T, Args extends unknown[]>(sharedFunctionCreated: SharedFunctionCreated<T, Args>, value: {
|
|
36
36
|
fnState: SharedFunctionValue<T>;
|
|
37
37
|
}): void;
|
|
38
|
+
update<T, Args extends unknown[], S extends string = string>(key: S, updater: (prev: SharedFunctionValue<T>) => {
|
|
39
|
+
fnState: SharedFunctionValue<T>;
|
|
40
|
+
}, scopeName?: Prefix): void;
|
|
41
|
+
update<T, Args extends unknown[]>(sharedFunctionCreated: SharedFunctionCreated<T, Args>, updater: (prev: SharedFunctionValue<T>) => {
|
|
42
|
+
fnState: SharedFunctionValue<T>;
|
|
43
|
+
}): void;
|
|
38
44
|
}
|
|
39
45
|
export declare const sharedFunctionsApi: SharedFunctionsApi;
|
|
40
46
|
interface SharedFunctionCreated<T, Args extends unknown[]> extends SharedCreated {
|
|
@@ -20,6 +20,8 @@ export declare class SharedStatesApi extends SharedValuesApi<SharedState<unknown
|
|
|
20
20
|
get<T>(sharedStateCreated: SharedStateCreated<T>): T;
|
|
21
21
|
set<T, S extends string = string>(key: S, value: T, scopeName?: Prefix): void;
|
|
22
22
|
set<T>(sharedStateCreated: SharedStateCreated<T>, value: T): void;
|
|
23
|
+
update<T, S extends string = string>(key: S, updater: (prev: T) => T, scopeName?: Prefix): void;
|
|
24
|
+
update<T>(sharedStateCreated: SharedStateCreated<T>, updater: (prev: T) => T): void;
|
|
23
25
|
}
|
|
24
26
|
export declare const sharedStatesApi: SharedStatesApi;
|
|
25
27
|
export interface SharedStateCreated<T> extends SharedCreated {
|
|
@@ -47,6 +47,12 @@ export declare class SharedSubscriptionsApi extends SharedValuesApi<SharedSubscr
|
|
|
47
47
|
set<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>, value: {
|
|
48
48
|
fnState: SharedSubscriptionValue<T>;
|
|
49
49
|
}): void;
|
|
50
|
+
update<T, S extends string = string>(key: S, updater: (prev: SharedSubscriptionValue<T>) => {
|
|
51
|
+
fnState: SharedSubscriptionValue<T>;
|
|
52
|
+
}, scopeName?: Prefix): void;
|
|
53
|
+
update<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>, updater: (prev: SharedSubscriptionValue<T>) => {
|
|
54
|
+
fnState: SharedSubscriptionValue<T>;
|
|
55
|
+
}): void;
|
|
50
56
|
}
|
|
51
57
|
export declare const sharedSubscriptionsApi: SharedSubscriptionsApi;
|
|
52
58
|
interface SharedSubscriptionCreated<T> extends SharedCreated {
|
package/dist/main.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.14
|
|
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 ve, { createContext as be, useMemo as
|
|
9
|
-
function me(
|
|
10
|
-
return
|
|
8
|
+
import ve, { createContext as be, useMemo as A, useContext as xe, useEffect as ne, useSyncExternalStore as V, useRef as Ee } from "react";
|
|
9
|
+
function me(o) {
|
|
10
|
+
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
11
11
|
}
|
|
12
12
|
var F = { exports: {} }, C = {};
|
|
13
13
|
/**
|
|
@@ -20,22 +20,22 @@ var F = { exports: {} }, C = {};
|
|
|
20
20
|
* LICENSE file in the root directory of this source tree.
|
|
21
21
|
*/
|
|
22
22
|
var Q;
|
|
23
|
-
function
|
|
23
|
+
function _e() {
|
|
24
24
|
if (Q) return C;
|
|
25
25
|
Q = 1;
|
|
26
|
-
var
|
|
27
|
-
function r(t,
|
|
26
|
+
var o = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
27
|
+
function r(t, i, a) {
|
|
28
28
|
var n = null;
|
|
29
|
-
if (a !== void 0 && (n = "" + a),
|
|
29
|
+
if (a !== void 0 && (n = "" + a), i.key !== void 0 && (n = "" + i.key), "key" in i) {
|
|
30
30
|
a = {};
|
|
31
|
-
for (var f in
|
|
32
|
-
f !== "key" && (a[f] =
|
|
33
|
-
} else a =
|
|
34
|
-
return
|
|
35
|
-
$$typeof:
|
|
31
|
+
for (var f in i)
|
|
32
|
+
f !== "key" && (a[f] = i[f]);
|
|
33
|
+
} else a = i;
|
|
34
|
+
return i = a.ref, {
|
|
35
|
+
$$typeof: o,
|
|
36
36
|
type: t,
|
|
37
37
|
key: n,
|
|
38
|
-
ref:
|
|
38
|
+
ref: i !== void 0 ? i : null,
|
|
39
39
|
props: a
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -52,9 +52,9 @@ var D = {};
|
|
|
52
52
|
* LICENSE file in the root directory of this source tree.
|
|
53
53
|
*/
|
|
54
54
|
var K;
|
|
55
|
-
function
|
|
55
|
+
function Re() {
|
|
56
56
|
return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
57
|
-
function
|
|
57
|
+
function o(s) {
|
|
58
58
|
if (s == null) return null;
|
|
59
59
|
if (typeof s == "function")
|
|
60
60
|
return s.$$typeof === he ? null : s.displayName || s.name || null;
|
|
@@ -81,17 +81,17 @@ function _e() {
|
|
|
81
81
|
return "Portal";
|
|
82
82
|
case ce:
|
|
83
83
|
return (s.displayName || "Context") + ".Provider";
|
|
84
|
-
case
|
|
84
|
+
case oe:
|
|
85
85
|
return (s._context.displayName || "Context") + ".Consumer";
|
|
86
86
|
case ue:
|
|
87
87
|
var u = s.render;
|
|
88
88
|
return s = s.displayName, s || (s = u.displayName || u.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
|
|
89
89
|
case de:
|
|
90
|
-
return u = s.displayName || null, u !== null ? u :
|
|
91
|
-
case
|
|
90
|
+
return u = s.displayName || null, u !== null ? u : o(s.type) || "Memo";
|
|
91
|
+
case B:
|
|
92
92
|
u = s._payload, s = s._init;
|
|
93
93
|
try {
|
|
94
|
-
return
|
|
94
|
+
return o(s(u));
|
|
95
95
|
} catch {
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -119,16 +119,16 @@ function _e() {
|
|
|
119
119
|
}
|
|
120
120
|
function t(s) {
|
|
121
121
|
if (s === x) return "<>";
|
|
122
|
-
if (typeof s == "object" && s !== null && s.$$typeof ===
|
|
122
|
+
if (typeof s == "object" && s !== null && s.$$typeof === B)
|
|
123
123
|
return "<...>";
|
|
124
124
|
try {
|
|
125
|
-
var u =
|
|
125
|
+
var u = o(s);
|
|
126
126
|
return u ? "<" + u + ">" : "<...>";
|
|
127
127
|
} catch {
|
|
128
128
|
return "<...>";
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function i() {
|
|
132
132
|
var s = $.A;
|
|
133
133
|
return s === null ? null : s.getOwner();
|
|
134
134
|
}
|
|
@@ -136,7 +136,7 @@ function _e() {
|
|
|
136
136
|
return Error("react-stack-top-frame");
|
|
137
137
|
}
|
|
138
138
|
function n(s) {
|
|
139
|
-
if (
|
|
139
|
+
if (J.call(s, "key")) {
|
|
140
140
|
var u = Object.getOwnPropertyDescriptor(s, "key").get;
|
|
141
141
|
if (u && u.isReactWarning) return !1;
|
|
142
142
|
}
|
|
@@ -144,7 +144,7 @@ function _e() {
|
|
|
144
144
|
}
|
|
145
145
|
function f(s, u) {
|
|
146
146
|
function h() {
|
|
147
|
-
|
|
147
|
+
M || (M = !0, console.error(
|
|
148
148
|
"%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)",
|
|
149
149
|
u
|
|
150
150
|
));
|
|
@@ -155,18 +155,18 @@ function _e() {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
function c() {
|
|
158
|
-
var s =
|
|
159
|
-
return
|
|
158
|
+
var s = o(this.type);
|
|
159
|
+
return X[s] || (X[s] = !0, console.error(
|
|
160
160
|
"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."
|
|
161
161
|
)), s = this.props.ref, s !== void 0 ? s : null;
|
|
162
162
|
}
|
|
163
|
-
function
|
|
164
|
-
return h =
|
|
163
|
+
function S(s, u, h, E, y, T, I, q) {
|
|
164
|
+
return h = T.ref, s = {
|
|
165
165
|
$$typeof: b,
|
|
166
166
|
type: s,
|
|
167
167
|
key: u,
|
|
168
|
-
props:
|
|
169
|
-
_owner:
|
|
168
|
+
props: T,
|
|
169
|
+
_owner: y
|
|
170
170
|
}, (h !== void 0 ? h : null) !== null ? Object.defineProperty(s, "ref", {
|
|
171
171
|
enumerable: !1,
|
|
172
172
|
get: c
|
|
@@ -184,19 +184,19 @@ function _e() {
|
|
|
184
184
|
configurable: !1,
|
|
185
185
|
enumerable: !1,
|
|
186
186
|
writable: !0,
|
|
187
|
-
value:
|
|
187
|
+
value: I
|
|
188
188
|
}), Object.defineProperty(s, "_debugTask", {
|
|
189
189
|
configurable: !1,
|
|
190
190
|
enumerable: !1,
|
|
191
191
|
writable: !0,
|
|
192
|
-
value:
|
|
192
|
+
value: q
|
|
193
193
|
}), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
|
|
194
194
|
}
|
|
195
|
-
function p(s, u, h, E,
|
|
195
|
+
function p(s, u, h, E, y, T, I, q) {
|
|
196
196
|
var m = u.children;
|
|
197
197
|
if (m !== void 0)
|
|
198
198
|
if (E)
|
|
199
|
-
if (
|
|
199
|
+
if (ge(m)) {
|
|
200
200
|
for (E = 0; E < m.length; E++)
|
|
201
201
|
l(m[E]);
|
|
202
202
|
Object.freeze && Object.freeze(m);
|
|
@@ -205,10 +205,10 @@ function _e() {
|
|
|
205
205
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
206
206
|
);
|
|
207
207
|
else l(m);
|
|
208
|
-
if (
|
|
209
|
-
m =
|
|
210
|
-
var L = Object.keys(u).filter(function(
|
|
211
|
-
return
|
|
208
|
+
if (J.call(u, "key")) {
|
|
209
|
+
m = o(s);
|
|
210
|
+
var L = Object.keys(u).filter(function(Se) {
|
|
211
|
+
return Se !== "key";
|
|
212
212
|
});
|
|
213
213
|
E = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", Z[m + E] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
214
214
|
`A props object containing a "key" prop is being spread into JSX:
|
|
@@ -225,86 +225,86 @@ React keys must be passed directly to JSX without using spread:
|
|
|
225
225
|
}
|
|
226
226
|
if (m = null, h !== void 0 && (r(h), m = "" + h), n(u) && (r(u.key), m = "" + u.key), "key" in u) {
|
|
227
227
|
h = {};
|
|
228
|
-
for (var
|
|
229
|
-
|
|
228
|
+
for (var W in u)
|
|
229
|
+
W !== "key" && (h[W] = u[W]);
|
|
230
230
|
} else h = u;
|
|
231
231
|
return m && f(
|
|
232
232
|
h,
|
|
233
233
|
typeof s == "function" ? s.displayName || s.name || "Unknown" : s
|
|
234
|
-
),
|
|
234
|
+
), S(
|
|
235
235
|
s,
|
|
236
236
|
m,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
T,
|
|
238
|
+
y,
|
|
239
|
+
i(),
|
|
240
240
|
h,
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
I,
|
|
242
|
+
q
|
|
243
243
|
);
|
|
244
244
|
}
|
|
245
245
|
function l(s) {
|
|
246
246
|
typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
|
|
247
247
|
}
|
|
248
|
-
var
|
|
248
|
+
var _ = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), oe = Symbol.for("react.consumer"), ce = Symbol.for("react.context"), ue = Symbol.for("react.forward_ref"), fe = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), de = Symbol.for("react.memo"), B = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ge = Array.isArray, Y = console.createTask ? console.createTask : function() {
|
|
249
249
|
return null;
|
|
250
250
|
};
|
|
251
|
-
|
|
251
|
+
_ = {
|
|
252
252
|
react_stack_bottom_frame: function(s) {
|
|
253
253
|
return s();
|
|
254
254
|
}
|
|
255
255
|
};
|
|
256
|
-
var
|
|
257
|
-
|
|
256
|
+
var M, X = {}, k = _.react_stack_bottom_frame.bind(
|
|
257
|
+
_,
|
|
258
258
|
a
|
|
259
|
-
)(), H =
|
|
260
|
-
D.Fragment = x, D.jsx = function(s, u, h, E,
|
|
261
|
-
var
|
|
259
|
+
)(), H = Y(t(a)), Z = {};
|
|
260
|
+
D.Fragment = x, D.jsx = function(s, u, h, E, y) {
|
|
261
|
+
var T = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
262
262
|
return p(
|
|
263
263
|
s,
|
|
264
264
|
u,
|
|
265
265
|
h,
|
|
266
266
|
!1,
|
|
267
267
|
E,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
y,
|
|
269
|
+
T ? Error("react-stack-top-frame") : k,
|
|
270
|
+
T ? Y(t(s)) : H
|
|
271
271
|
);
|
|
272
|
-
}, D.jsxs = function(s, u, h, E,
|
|
273
|
-
var
|
|
272
|
+
}, D.jsxs = function(s, u, h, E, y) {
|
|
273
|
+
var T = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
274
274
|
return p(
|
|
275
275
|
s,
|
|
276
276
|
u,
|
|
277
277
|
h,
|
|
278
278
|
!0,
|
|
279
279
|
E,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
y,
|
|
281
|
+
T ? Error("react-stack-top-frame") : k,
|
|
282
|
+
T ? Y(t(s)) : H
|
|
283
283
|
);
|
|
284
284
|
};
|
|
285
285
|
})()), D;
|
|
286
286
|
}
|
|
287
287
|
var ee;
|
|
288
|
-
function
|
|
289
|
-
return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports =
|
|
288
|
+
function we() {
|
|
289
|
+
return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = _e() : F.exports = Re()), F.exports;
|
|
290
290
|
}
|
|
291
|
-
var
|
|
291
|
+
var Te = we();
|
|
292
292
|
let se = !1;
|
|
293
|
-
const $e = (
|
|
294
|
-
se =
|
|
295
|
-
},
|
|
293
|
+
const $e = (o) => {
|
|
294
|
+
se = o;
|
|
295
|
+
}, G = (...o) => {
|
|
296
296
|
se && console.log(
|
|
297
297
|
"%c[react-shared-states]",
|
|
298
298
|
"color: #007acc; font-weight: bold",
|
|
299
|
-
...
|
|
299
|
+
...o
|
|
300
300
|
);
|
|
301
|
-
}, j = (
|
|
302
|
-
if (!
|
|
303
|
-
return
|
|
304
|
-
}, ae = () => Math.random().toString(36).substring(2, 15),
|
|
301
|
+
}, j = (o) => {
|
|
302
|
+
if (!o) throw new Error("Value is empty");
|
|
303
|
+
return o;
|
|
304
|
+
}, ae = () => Math.random().toString(36).substring(2, 15), ie = be(void 0), Ye = ({ children: o, scopeName: e }) => {
|
|
305
305
|
if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
|
|
306
|
-
return e || (e =
|
|
307
|
-
},
|
|
306
|
+
return e || (e = A(() => ae(), [])), /* @__PURE__ */ Te.jsx(ie.Provider, { value: { scopeName: e }, children: o });
|
|
307
|
+
}, Ae = () => xe(ie), te = [];
|
|
308
308
|
class d {
|
|
309
309
|
data = /* @__PURE__ */ new Map();
|
|
310
310
|
defaultValue() {
|
|
@@ -317,42 +317,42 @@ class d {
|
|
|
317
317
|
}), this.data.get(d.prefix(e, r)).listeners.push(t);
|
|
318
318
|
}
|
|
319
319
|
removeListener(e, r, t) {
|
|
320
|
-
this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((
|
|
320
|
+
this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((i) => i !== t));
|
|
321
321
|
}
|
|
322
322
|
callListeners(e, r) {
|
|
323
323
|
this.data.has(d.prefix(e, r)) && this.data.get(d.prefix(e, r)).listeners.forEach((t) => t());
|
|
324
324
|
}
|
|
325
|
-
init(e, r, t,
|
|
325
|
+
init(e, r, t, i = !1) {
|
|
326
326
|
this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
|
|
327
327
|
...t,
|
|
328
|
-
isStatic:
|
|
328
|
+
isStatic: i,
|
|
329
329
|
listeners: []
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
createStatic(e, r) {
|
|
333
|
-
const t = r ?? r ?? "_global",
|
|
333
|
+
const t = r ?? r ?? "_global", i = {
|
|
334
334
|
key: ae(),
|
|
335
335
|
prefix: t,
|
|
336
336
|
...e
|
|
337
337
|
};
|
|
338
|
-
return te.push(
|
|
338
|
+
return te.push(i), this.initStatic(i), i;
|
|
339
339
|
}
|
|
340
340
|
initStatic(e) {
|
|
341
341
|
const { key: r, prefix: t } = e;
|
|
342
342
|
this.init(r, t, this.defaultValue(), !0);
|
|
343
343
|
}
|
|
344
344
|
clearAll(e = !1, r = !1) {
|
|
345
|
-
this.data.forEach((t,
|
|
346
|
-
const [a, n] = d.extractPrefix(
|
|
345
|
+
this.data.forEach((t, i) => {
|
|
346
|
+
const [a, n] = d.extractPrefix(i);
|
|
347
347
|
this.clear(n, a, e, r);
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
|
-
clear(e, r, t = !1,
|
|
350
|
+
clear(e, r, t = !1, i = !1) {
|
|
351
351
|
t || this.callListeners(e, r);
|
|
352
352
|
const a = this.data.get(d.prefix(e, r));
|
|
353
353
|
if (!a) return;
|
|
354
354
|
const n = { ...a };
|
|
355
|
-
if (this.data.delete(d.prefix(e, r)), n.isStatic && !
|
|
355
|
+
if (this.data.delete(d.prefix(e, r)), n.isStatic && !i) {
|
|
356
356
|
const f = te.find((c) => c.key === e && c.prefix === r);
|
|
357
357
|
f && this.initStatic(f);
|
|
358
358
|
}
|
|
@@ -380,33 +380,39 @@ class d {
|
|
|
380
380
|
}
|
|
381
381
|
useEffect(e, r, t = null) {
|
|
382
382
|
ne(() => () => {
|
|
383
|
-
t?.(),
|
|
383
|
+
t?.(), G(`[${d.prefix(e, r)}]`, "unmount effect"), this.data.get(d.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
|
|
384
384
|
}, []);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
|
-
class
|
|
387
|
+
class U {
|
|
388
388
|
constructor(e) {
|
|
389
389
|
this.sharedData = e;
|
|
390
390
|
}
|
|
391
391
|
get(e, r) {
|
|
392
|
-
let t,
|
|
392
|
+
let t, i = r;
|
|
393
393
|
if (typeof e != "string") {
|
|
394
394
|
const { key: f, prefix: c } = e;
|
|
395
|
-
t = f,
|
|
395
|
+
t = f, i = c;
|
|
396
396
|
} else
|
|
397
397
|
t = j(e);
|
|
398
|
-
const a =
|
|
398
|
+
const a = i || "_global";
|
|
399
399
|
return this.sharedData.get(t, a);
|
|
400
400
|
}
|
|
401
401
|
set(e, r, t) {
|
|
402
|
-
let
|
|
402
|
+
let i, a = t;
|
|
403
403
|
if (typeof e != "string") {
|
|
404
404
|
const { key: f, prefix: c } = e;
|
|
405
|
-
|
|
405
|
+
i = f, a = c;
|
|
406
406
|
} else
|
|
407
|
-
|
|
407
|
+
i = j(e);
|
|
408
408
|
const n = a || "_global";
|
|
409
|
-
this.sharedData.init(
|
|
409
|
+
this.sharedData.init(i, n, r), this.sharedData.setValue(i, n, r), this.sharedData.callListeners(i, n);
|
|
410
|
+
}
|
|
411
|
+
update(e, r, t) {
|
|
412
|
+
let i;
|
|
413
|
+
typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
|
|
414
|
+
const a = r(i);
|
|
415
|
+
typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
|
|
410
416
|
}
|
|
411
417
|
/**
|
|
412
418
|
* clear all values from the shared data
|
|
@@ -420,8 +426,8 @@ class G {
|
|
|
420
426
|
*/
|
|
421
427
|
clearScope(e) {
|
|
422
428
|
const r = e || "_global";
|
|
423
|
-
this.sharedData.data.forEach((t,
|
|
424
|
-
const [a, n] = d.extractPrefix(
|
|
429
|
+
this.sharedData.data.forEach((t, i) => {
|
|
430
|
+
const [a, n] = d.extractPrefix(i);
|
|
425
431
|
if (a === r) {
|
|
426
432
|
this.sharedData.clear(n, a), this.sharedData.callListeners(n, a);
|
|
427
433
|
return;
|
|
@@ -437,8 +443,8 @@ class G {
|
|
|
437
443
|
return this.get(r, t);
|
|
438
444
|
}
|
|
439
445
|
clear(e, r) {
|
|
440
|
-
let t,
|
|
441
|
-
typeof e == "string" ? (t = e,
|
|
446
|
+
let t, i;
|
|
447
|
+
typeof e == "string" ? (t = e, i = r || "_global") : (t = e.key, i = e.prefix), this.sharedData.clear(t, i);
|
|
442
448
|
}
|
|
443
449
|
/**
|
|
444
450
|
* check if a value exists in the shared data
|
|
@@ -455,31 +461,31 @@ class G {
|
|
|
455
461
|
getAll() {
|
|
456
462
|
const e = {};
|
|
457
463
|
return this.sharedData.data.forEach((r, t) => {
|
|
458
|
-
const [
|
|
459
|
-
e[
|
|
464
|
+
const [i, a] = d.extractPrefix(t);
|
|
465
|
+
e[i] = e[i] || {}, e[i][a] = r;
|
|
460
466
|
}), e;
|
|
461
467
|
}
|
|
462
468
|
}
|
|
463
|
-
const
|
|
464
|
-
const e =
|
|
469
|
+
const N = (o) => {
|
|
470
|
+
const e = Ae();
|
|
465
471
|
return {
|
|
466
|
-
prefix:
|
|
472
|
+
prefix: o ?? e?.scopeName ?? "_global"
|
|
467
473
|
};
|
|
468
474
|
};
|
|
469
|
-
var
|
|
470
|
-
function
|
|
471
|
-
if (re) return
|
|
475
|
+
var z, re;
|
|
476
|
+
function ye() {
|
|
477
|
+
if (re) return z;
|
|
472
478
|
re = 1;
|
|
473
|
-
var
|
|
474
|
-
function
|
|
479
|
+
var o = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
|
|
480
|
+
function i(a, n) {
|
|
475
481
|
if (a === n) return !0;
|
|
476
482
|
if (a && n && typeof a == "object" && typeof n == "object") {
|
|
477
483
|
if (a.constructor !== n.constructor) return !1;
|
|
478
|
-
var f, c,
|
|
484
|
+
var f, c, S;
|
|
479
485
|
if (Array.isArray(a)) {
|
|
480
486
|
if (f = a.length, f != n.length) return !1;
|
|
481
487
|
for (c = f; c-- !== 0; )
|
|
482
|
-
if (!
|
|
488
|
+
if (!i(a[c], n[c])) return !1;
|
|
483
489
|
return !0;
|
|
484
490
|
}
|
|
485
491
|
var p;
|
|
@@ -488,7 +494,7 @@ function Ae() {
|
|
|
488
494
|
for (p = a.entries(); !(c = p.next()).done; )
|
|
489
495
|
if (!n.has(c.value[0])) return !1;
|
|
490
496
|
for (p = a.entries(); !(c = p.next()).done; )
|
|
491
|
-
if (!
|
|
497
|
+
if (!i(c.value[1], n.get(c.value[0]))) return !1;
|
|
492
498
|
return !0;
|
|
493
499
|
}
|
|
494
500
|
if (r && a instanceof Set && n instanceof Set) {
|
|
@@ -506,42 +512,42 @@ function Ae() {
|
|
|
506
512
|
if (a.constructor === RegExp) return a.source === n.source && a.flags === n.flags;
|
|
507
513
|
if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof n.valueOf == "function") return a.valueOf() === n.valueOf();
|
|
508
514
|
if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof n.toString == "function") return a.toString() === n.toString();
|
|
509
|
-
if (
|
|
515
|
+
if (S = Object.keys(a), f = S.length, f !== Object.keys(n).length) return !1;
|
|
510
516
|
for (c = f; c-- !== 0; )
|
|
511
|
-
if (!Object.prototype.hasOwnProperty.call(n,
|
|
512
|
-
if (
|
|
517
|
+
if (!Object.prototype.hasOwnProperty.call(n, S[c])) return !1;
|
|
518
|
+
if (o && a instanceof Element) return !1;
|
|
513
519
|
for (c = f; c-- !== 0; )
|
|
514
|
-
if (!((
|
|
520
|
+
if (!((S[c] === "_owner" || S[c] === "__v" || S[c] === "__o") && a.$$typeof) && !i(a[S[c]], n[S[c]]))
|
|
515
521
|
return !1;
|
|
516
522
|
return !0;
|
|
517
523
|
}
|
|
518
524
|
return a !== a && n !== n;
|
|
519
525
|
}
|
|
520
|
-
return
|
|
526
|
+
return z = function(n, f) {
|
|
521
527
|
try {
|
|
522
|
-
return
|
|
528
|
+
return i(n, f);
|
|
523
529
|
} catch (c) {
|
|
524
530
|
if ((c.message || "").match(/stack|recursion/i))
|
|
525
531
|
return console.warn("react-fast-compare cannot handle circular refs"), !1;
|
|
526
532
|
throw c;
|
|
527
533
|
}
|
|
528
|
-
},
|
|
534
|
+
}, z;
|
|
529
535
|
}
|
|
530
|
-
var Oe =
|
|
536
|
+
var Oe = ye();
|
|
531
537
|
const Pe = /* @__PURE__ */ me(Oe);
|
|
532
538
|
class Le extends d {
|
|
533
539
|
defaultValue() {
|
|
534
540
|
return { value: void 0 };
|
|
535
541
|
}
|
|
536
|
-
initValue(e, r, t,
|
|
537
|
-
super.init(e, r, { value: t },
|
|
542
|
+
initValue(e, r, t, i = !1) {
|
|
543
|
+
super.init(e, r, { value: t }, i);
|
|
538
544
|
}
|
|
539
545
|
initStatic(e) {
|
|
540
|
-
const { key: r, prefix: t, initialValue:
|
|
541
|
-
this.initValue(r, t,
|
|
546
|
+
const { key: r, prefix: t, initialValue: i } = e;
|
|
547
|
+
this.initValue(r, t, i, !0);
|
|
542
548
|
}
|
|
543
549
|
}
|
|
544
|
-
class je extends
|
|
550
|
+
class je extends U {
|
|
545
551
|
constructor(e) {
|
|
546
552
|
super(e);
|
|
547
553
|
}
|
|
@@ -555,42 +561,48 @@ class je extends G {
|
|
|
555
561
|
}
|
|
556
562
|
super.set(e, { value: r }, t);
|
|
557
563
|
}
|
|
564
|
+
update(e, r, t = "_global") {
|
|
565
|
+
let i;
|
|
566
|
+
typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
|
|
567
|
+
const a = r(i);
|
|
568
|
+
typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
|
|
569
|
+
}
|
|
558
570
|
}
|
|
559
|
-
const
|
|
560
|
-
function
|
|
561
|
-
let t,
|
|
562
|
-
if (typeof
|
|
563
|
-
const { key: l, initialValue:
|
|
564
|
-
t = l,
|
|
571
|
+
const R = new Le(), Ie = new je(R), qe = (o, e) => R.createStatic({ initialValue: o }, e);
|
|
572
|
+
function We(o, e, r) {
|
|
573
|
+
let t, i, a = r;
|
|
574
|
+
if (typeof o != "string") {
|
|
575
|
+
const { key: l, initialValue: _, prefix: b } = o;
|
|
576
|
+
t = l, i = _, a = b;
|
|
565
577
|
} else
|
|
566
|
-
t = j(
|
|
567
|
-
const { prefix: n } =
|
|
568
|
-
|
|
569
|
-
const f =
|
|
570
|
-
|
|
571
|
-
}), []), c =
|
|
572
|
-
const
|
|
573
|
-
|
|
578
|
+
t = j(o), i = e;
|
|
579
|
+
const { prefix: n } = N(a);
|
|
580
|
+
R.initValue(t, n, i);
|
|
581
|
+
const f = A(() => (l) => (R.initValue(t, n, e), R.addListener(t, n, l), () => {
|
|
582
|
+
R.removeListener(t, n, l);
|
|
583
|
+
}), []), c = A(() => () => R.get(t, n)?.value, []), S = V(f, c), p = (l) => {
|
|
584
|
+
const _ = typeof l == "function" ? l(R.get(t, n)?.value) : l;
|
|
585
|
+
_ !== S && (R.setValue(t, n, { value: _ }), R.callListeners(t, n));
|
|
574
586
|
};
|
|
575
|
-
return
|
|
576
|
-
|
|
587
|
+
return R.useEffect(t, n), [
|
|
588
|
+
S,
|
|
577
589
|
p
|
|
578
590
|
];
|
|
579
591
|
}
|
|
580
|
-
function
|
|
581
|
-
let t,
|
|
582
|
-
if (typeof
|
|
583
|
-
const { key: p, prefix: l } =
|
|
584
|
-
t = p,
|
|
592
|
+
function ze(o, e, r) {
|
|
593
|
+
let t, i = r;
|
|
594
|
+
if (typeof o != "string") {
|
|
595
|
+
const { key: p, prefix: l } = o;
|
|
596
|
+
t = p, i = l;
|
|
585
597
|
} else
|
|
586
|
-
t = j(
|
|
587
|
-
const { prefix: a } =
|
|
588
|
-
|
|
589
|
-
}), []), c =
|
|
590
|
-
const p =
|
|
598
|
+
t = j(o);
|
|
599
|
+
const { prefix: a } = N(i), n = Ee(void 0), f = A(() => (p) => (R.addListener(t, a, p), () => {
|
|
600
|
+
R.removeListener(t, a, p);
|
|
601
|
+
}), []), c = A(() => () => {
|
|
602
|
+
const p = R.get(t, a)?.value, l = e(p);
|
|
591
603
|
return Pe(n.current, l) ? n.current : l;
|
|
592
|
-
}, []),
|
|
593
|
-
return
|
|
604
|
+
}, []), S = V(f, c);
|
|
605
|
+
return R.useEffect(t, a), S;
|
|
594
606
|
}
|
|
595
607
|
class Ce extends d {
|
|
596
608
|
defaultValue() {
|
|
@@ -609,7 +621,7 @@ class Ce extends d {
|
|
|
609
621
|
super.setValue(e, r, t);
|
|
610
622
|
}
|
|
611
623
|
}
|
|
612
|
-
class De extends
|
|
624
|
+
class De extends U {
|
|
613
625
|
constructor(e) {
|
|
614
626
|
super(e);
|
|
615
627
|
}
|
|
@@ -623,39 +635,45 @@ class De extends G {
|
|
|
623
635
|
}
|
|
624
636
|
super.set(e, r, t);
|
|
625
637
|
}
|
|
638
|
+
update(e, r, t = "_global") {
|
|
639
|
+
let i;
|
|
640
|
+
typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
|
|
641
|
+
const a = r(i);
|
|
642
|
+
typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
|
|
643
|
+
}
|
|
626
644
|
}
|
|
627
|
-
const
|
|
628
|
-
function
|
|
629
|
-
let t,
|
|
630
|
-
if (typeof
|
|
631
|
-
const { key: l, fn:
|
|
632
|
-
t = l,
|
|
645
|
+
const w = new Ce(), Ge = new De(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
|
|
646
|
+
function Be(o, e, r) {
|
|
647
|
+
let t, i, a = r;
|
|
648
|
+
if (typeof o != "string") {
|
|
649
|
+
const { key: l, fn: _, prefix: b } = o;
|
|
650
|
+
t = l, i = _, a = b;
|
|
633
651
|
} else
|
|
634
|
-
t = j(
|
|
635
|
-
const { prefix: n } =
|
|
636
|
-
|
|
637
|
-
const f =
|
|
638
|
-
() => (l) => (
|
|
639
|
-
|
|
652
|
+
t = j(o), i = e;
|
|
653
|
+
const { prefix: n } = N(a);
|
|
654
|
+
w.initValue(t, n);
|
|
655
|
+
const f = A(
|
|
656
|
+
() => (l) => (w.initValue(t, n), w.addListener(t, n, l), () => {
|
|
657
|
+
w.removeListener(t, n, l);
|
|
640
658
|
}),
|
|
641
659
|
[]
|
|
642
|
-
), c =
|
|
643
|
-
() => () =>
|
|
660
|
+
), c = A(
|
|
661
|
+
() => () => w.get(t, n).fnState,
|
|
644
662
|
[]
|
|
645
|
-
),
|
|
646
|
-
const b =
|
|
663
|
+
), S = V(f, c), p = async (l, ..._) => {
|
|
664
|
+
const b = w.get(t, n);
|
|
647
665
|
if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
|
|
648
|
-
b.fnState = { ...b.fnState, isLoading: !0, error: void 0 },
|
|
666
|
+
b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, w.callListeners(t, n);
|
|
649
667
|
try {
|
|
650
|
-
const v = await
|
|
668
|
+
const v = await i(..._);
|
|
651
669
|
b.fnState = { results: v, isLoading: !1, error: void 0 };
|
|
652
670
|
} catch (v) {
|
|
653
671
|
b.fnState = { ...b.fnState, isLoading: !1, error: v };
|
|
654
672
|
}
|
|
655
|
-
|
|
673
|
+
w.callListeners(t, n);
|
|
656
674
|
};
|
|
657
|
-
return
|
|
658
|
-
state:
|
|
675
|
+
return w.useEffect(t, n), {
|
|
676
|
+
state: S,
|
|
659
677
|
trigger: (...l) => {
|
|
660
678
|
p(!1, ...l);
|
|
661
679
|
},
|
|
@@ -663,8 +681,8 @@ function Ue(i, e, r) {
|
|
|
663
681
|
p(!0, ...l);
|
|
664
682
|
},
|
|
665
683
|
clear: () => {
|
|
666
|
-
const l =
|
|
667
|
-
l && (l.fnState =
|
|
684
|
+
const l = w.get(t, n);
|
|
685
|
+
l && (l.fnState = w.defaultValue().fnState, w.callListeners(t, n));
|
|
668
686
|
}
|
|
669
687
|
};
|
|
670
688
|
}
|
|
@@ -687,7 +705,7 @@ class Fe extends d {
|
|
|
687
705
|
}
|
|
688
706
|
useEffect(e, r) {
|
|
689
707
|
ne(() => () => {
|
|
690
|
-
|
|
708
|
+
G(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
|
|
691
709
|
}, []), super.useEffect(e, r);
|
|
692
710
|
}
|
|
693
711
|
async unsubscribe(e, r) {
|
|
@@ -695,7 +713,7 @@ class Fe extends d {
|
|
|
695
713
|
t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
|
|
696
714
|
}
|
|
697
715
|
}
|
|
698
|
-
class
|
|
716
|
+
class Ve extends U {
|
|
699
717
|
constructor(e) {
|
|
700
718
|
super(e);
|
|
701
719
|
}
|
|
@@ -709,49 +727,55 @@ class Ne extends G {
|
|
|
709
727
|
}
|
|
710
728
|
super.set(e, r, t);
|
|
711
729
|
}
|
|
730
|
+
update(e, r, t = "_global") {
|
|
731
|
+
let i;
|
|
732
|
+
typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
|
|
733
|
+
const a = r(i);
|
|
734
|
+
typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
|
|
735
|
+
}
|
|
712
736
|
}
|
|
713
|
-
const
|
|
714
|
-
function
|
|
715
|
-
let t,
|
|
716
|
-
if (typeof
|
|
717
|
-
const { key: v, subscriber: x, prefix: O } =
|
|
718
|
-
t = v,
|
|
737
|
+
const g = new Fe(), Je = new Ve(g), Me = (o, e) => g.createStatic({ subscriber: o }, e);
|
|
738
|
+
function Xe(o, e, r) {
|
|
739
|
+
let t, i, a = r;
|
|
740
|
+
if (typeof o != "string") {
|
|
741
|
+
const { key: v, subscriber: x, prefix: O } = o;
|
|
742
|
+
t = v, i = x, a = O;
|
|
719
743
|
} else
|
|
720
|
-
t = j(
|
|
721
|
-
const { prefix: n } =
|
|
722
|
-
|
|
723
|
-
const f =
|
|
724
|
-
() => (v) => (
|
|
725
|
-
|
|
744
|
+
t = j(o), i = e;
|
|
745
|
+
const { prefix: n } = N(a);
|
|
746
|
+
g.initValue(t, n);
|
|
747
|
+
const f = A(
|
|
748
|
+
() => (v) => (g.initValue(t, n), g.addListener(t, n, v), () => {
|
|
749
|
+
g.removeListener(t, n, v);
|
|
726
750
|
}),
|
|
727
751
|
[]
|
|
728
|
-
), c =
|
|
729
|
-
() => () =>
|
|
752
|
+
), c = A(
|
|
753
|
+
() => () => g.get(t, n).fnState,
|
|
730
754
|
[]
|
|
731
|
-
),
|
|
732
|
-
const x =
|
|
733
|
-
x.fnState = { ...x.fnState, data: v },
|
|
755
|
+
), S = V(f, c), p = (v) => {
|
|
756
|
+
const x = g.get(t, n);
|
|
757
|
+
x.fnState = { ...x.fnState, data: v }, g.callListeners(t, n);
|
|
734
758
|
}, l = (v) => {
|
|
735
|
-
const x =
|
|
736
|
-
x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v },
|
|
737
|
-
},
|
|
738
|
-
const v =
|
|
739
|
-
v.fnState = { ...v.fnState, isLoading: !1 },
|
|
759
|
+
const x = g.get(t, n);
|
|
760
|
+
x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, g.callListeners(t, n);
|
|
761
|
+
}, _ = () => {
|
|
762
|
+
const v = g.get(t, n);
|
|
763
|
+
v.fnState = { ...v.fnState, isLoading: !1 }, g.callListeners(t, n);
|
|
740
764
|
}, b = async (v) => {
|
|
741
|
-
const x =
|
|
742
|
-
if (v && (await
|
|
743
|
-
|
|
765
|
+
const x = g.get(t, n);
|
|
766
|
+
if (v && (await g.unsubscribe(t, n), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
|
|
767
|
+
G("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, g.callListeners(t, n);
|
|
744
768
|
try {
|
|
745
|
-
const O = await
|
|
769
|
+
const O = await i(p, l, _), P = g.get(t, n);
|
|
746
770
|
P.unsubscribe = O, P.fnState.subscribed = !0;
|
|
747
771
|
} catch (O) {
|
|
748
|
-
const P =
|
|
772
|
+
const P = g.get(t, n);
|
|
749
773
|
P.fnState = { ...P.fnState, isLoading: !1, error: O };
|
|
750
774
|
}
|
|
751
|
-
|
|
775
|
+
g.callListeners(t, n);
|
|
752
776
|
};
|
|
753
|
-
return
|
|
754
|
-
state:
|
|
777
|
+
return g.useEffect(t, n), {
|
|
778
|
+
state: S,
|
|
755
779
|
trigger: () => {
|
|
756
780
|
b(!1);
|
|
757
781
|
},
|
|
@@ -759,25 +783,25 @@ function Me(i, e, r) {
|
|
|
759
783
|
b(!0);
|
|
760
784
|
},
|
|
761
785
|
unsubscribe: () => {
|
|
762
|
-
|
|
786
|
+
g.unsubscribe(t, n);
|
|
763
787
|
}
|
|
764
788
|
};
|
|
765
789
|
}
|
|
766
790
|
export {
|
|
767
791
|
De as SharedFunctionsApi,
|
|
768
792
|
je as SharedStatesApi,
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
793
|
+
Ye as SharedStatesProvider,
|
|
794
|
+
Ve as SharedSubscriptionsApi,
|
|
795
|
+
Ue as createSharedFunction,
|
|
796
|
+
qe as createSharedState,
|
|
797
|
+
Me as createSharedSubscription,
|
|
774
798
|
se as isDevMode,
|
|
775
799
|
$e as setDevMode,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
800
|
+
Ge as sharedFunctionsApi,
|
|
801
|
+
Ie as sharedStatesApi,
|
|
802
|
+
Je as sharedSubscriptionsApi,
|
|
803
|
+
Be as useSharedFunction,
|
|
804
|
+
We as useSharedState,
|
|
805
|
+
ze as useSharedStateSelector,
|
|
806
|
+
Xe as useSharedSubscription
|
|
783
807
|
};
|
package/dist/main.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.14
|
|
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
|
-
(function(p,
|
|
8
|
+
(function(p,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],h):(p=typeof globalThis<"u"?globalThis:p||self,h(p.ReactSharedStates={},p.React))})(this,(function(p,h){"use strict";function ce(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var V={exports:{}},C={};/**
|
|
9
9
|
* @license React
|
|
10
10
|
* react-jsx-runtime.production.js
|
|
11
11
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the MIT license found in the
|
|
15
15
|
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/var
|
|
16
|
+
*/var J;function ue(){if(J)return C;J=1;var o=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,i,a){var n=null;if(a!==void 0&&(n=""+a),i.key!==void 0&&(n=""+i.key),"key"in i){a={};for(var f in i)f!=="key"&&(a[f]=i[f])}else a=i;return i=a.ref,{$$typeof:o,type:t,key:n,ref:i!==void 0?i:null,props:a}}return C.Fragment=e,C.jsx=r,C.jsxs=r,C}var F={};/**
|
|
17
17
|
* @license React
|
|
18
18
|
* react-jsx-runtime.development.js
|
|
19
19
|
*
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
*
|
|
22
22
|
* This source code is licensed under the MIT license found in the
|
|
23
23
|
* LICENSE file in the root directory of this source tree.
|
|
24
|
-
*/var
|
|
24
|
+
*/var X;function fe(){return X||(X=1,process.env.NODE_ENV!=="production"&&(function(){function o(s){if(s==null)return null;if(typeof s=="function")return s.$$typeof===Ie?null:s.displayName||s.name||null;if(typeof s=="string")return s;switch(s){case x:return"Fragment";case j:return"Profiler";case P:return"StrictMode";case Ve:return"Suspense";case Ne:return"SuspenseList";case Me:return"Activity"}if(typeof s=="object")switch(typeof s.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),s.$$typeof){case m:return"Portal";case Ce:return(s.displayName||"Context")+".Provider";case De:return(s._context.displayName||"Context")+".Consumer";case Fe:var u=s.render;return s=s.displayName,s||(s=u.displayName||u.name||"",s=s!==""?"ForwardRef("+s+")":"ForwardRef"),s;case Ye:return u=s.displayName||null,u!==null?u:o(s.type)||"Memo";case te:u=s._payload,s=s._init;try{return o(s(u))}catch{}}return null}function e(s){return""+s}function r(s){try{e(s);var u=!1}catch{u=!0}if(u){u=console;var g=u.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&s[Symbol.toStringTag]||s.constructor.name||"Object";return g.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),e(s)}}function t(s){if(s===x)return"<>";if(typeof s=="object"&&s!==null&&s.$$typeof===te)return"<...>";try{var u=o(s);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function i(){var s=W.A;return s===null?null:s.getOwner()}function a(){return Error("react-stack-top-frame")}function n(s){if(re.call(s,"key")){var u=Object.getOwnPropertyDescriptor(s,"key").get;if(u&&u.isReactWarning)return!1}return s.key!==void 0}function f(s,u){function g(){ne||(ne=!0,console.error("%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)",u))}g.isReactWarning=!0,Object.defineProperty(s,"key",{get:g,configurable:!0})}function c(){var s=o(this.type);return se[s]||(se[s]=!0,console.error("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.")),s=this.props.ref,s!==void 0?s:null}function b(s,u,g,R,O,y,G,U){return g=y.ref,s={$$typeof:E,type:s,key:u,props:y,_owner:O},(g!==void 0?g:null)!==null?Object.defineProperty(s,"ref",{enumerable:!1,get:c}):Object.defineProperty(s,"ref",{enumerable:!1,value:null}),s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(s,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(s,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(s,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s}function S(s,u,g,R,O,y,G,U){var _=u.children;if(_!==void 0)if(R)if(We(_)){for(R=0;R<_.length;R++)l(_[R]);Object.freeze&&Object.freeze(_)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(_);if(re.call(u,"key")){_=o(s);var D=Object.keys(u).filter(function(ze){return ze!=="key"});R=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",oe[_+R]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
25
25
|
let props = %s;
|
|
26
26
|
<%s {...props} />
|
|
27
27
|
React keys must be passed directly to JSX without using spread:
|
|
28
28
|
let props = %s;
|
|
29
|
-
<%s key={someKey} {...props} />`,R,y,D,y),ie[y+R]=!0)}if(y=null,g!==void 0&&(r(g),y=""+g),n(u)&&(r(u.key),y=""+u.key),"key"in u){g={};for(var U in u)U!=="key"&&(g[U]=u[U])}else g=u;return y&&f(g,typeof s=="function"?s.displayName||s.name||"Unknown":s),b(s,y,w,O,o(),g,z,G)}function l(s){typeof s=="object"&&s!==null&&s.$$typeof===E&&s._store&&(s._store.validated=1)}var A=S,E=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),De=Symbol.for("react.consumer"),Ce=Symbol.for("react.context"),Fe=Symbol.for("react.forward_ref"),Ne=Symbol.for("react.suspense"),ke=Symbol.for("react.suspense_list"),Ve=Symbol.for("react.memo"),te=Symbol.for("react.lazy"),Ye=Symbol.for("react.activity"),Me=Symbol.for("react.client.reference"),I=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,re=Object.prototype.hasOwnProperty,Ie=Array.isArray,W=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(s){return s()}};var ne,se={},ae=A.react_stack_bottom_frame.bind(A,a)(),oe=W(t(a)),ie={};F.Fragment=x,F.jsx=function(s,u,g,R,O){var w=1e4>I.recentlyCreatedOwnerStacks++;return h(s,u,g,!1,R,O,w?Error("react-stack-top-frame"):ae,w?W(t(s)):oe)},F.jsxs=function(s,u,g,R,O){var w=1e4>I.recentlyCreatedOwnerStacks++;return h(s,u,g,!0,R,O,w?Error("react-stack-top-frame"):ae,w?W(t(s)):oe)}})()),F}var X;function le(){return X||(X=1,process.env.NODE_ENV==="production"?N.exports=ue():N.exports=fe()),N.exports}var de=le();p.isDevMode=!1;const pe=i=>{p.isDevMode=i},V=(...i)=>{p.isDevMode&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...i)},L=i=>{if(!i)throw new Error("Value is empty");return i},H=()=>Math.random().toString(36).substring(2,15),Z=S.createContext(void 0),Se=({children:i,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=S.useMemo(()=>H(),[])),de.jsx(Z.Provider,{value:{scopeName:e},children:i})},he=()=>S.useContext(Z),Q=[];class d{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...this.defaultValue(),listeners:[]}),this.data.get(d.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(d.prefix(e,r))&&(this.data.get(d.prefix(e,r)).listeners=this.data.get(d.prefix(e,r)).listeners.filter(o=>o!==t))}callListeners(e,r){this.data.has(d.prefix(e,r))&&this.data.get(d.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t,o=!1){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...t,isStatic:o,listeners:[]})}createStatic(e,r){const t=r??r??"_global",o={key:H(),prefix:t,...e};return Q.push(o),this.initStatic(o),o}initStatic(e){const{key:r,prefix:t}=e;this.init(r,t,this.defaultValue(),!0)}clearAll(e=!1,r=!1){this.data.forEach((t,o)=>{const[a,n]=d.extractPrefix(o);this.clear(n,a,e,r)})}clear(e,r,t=!1,o=!1){t||this.callListeners(e,r);const a=this.data.get(d.prefix(e,r));if(!a)return;const n={...a};if(this.data.delete(d.prefix(e,r)),n.isStatic&&!o){const f=Q.find(c=>c.key===e&&c.prefix===r);f&&this.initStatic(f)}}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(d.prefix(e,r))&&this.data.set(d.prefix(e,r),{...this.data.get(d.prefix(e,r)),...t})}has(e,r){return this.data.has(d.prefix(e,r))?d.prefix(e,r):this.data.has(d.prefix(e,"_global"))?d.prefix(e,"_global"):void 0}static prefix(e,r){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${r}//${e}`}static extractPrefix(e){return e.split("//")}useEffect(e,r,t=null){S.useEffect(()=>()=>{t?.(),V(`[${d.prefix(e,r)}]`,"unmount effect"),this.data.get(d.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}class Y{constructor(e){this.sharedData=e}get(e,r){let t,o=r;if(typeof e!="string"){const{key:f,prefix:c}=e;t=f,o=c}else t=L(e);const a=o||"_global";return this.sharedData.get(t,a)}set(e,r,t){let o,a=t;if(typeof e!="string"){const{key:f,prefix:c}=e;o=f,a=c}else o=L(e);const n=a||"_global";this.sharedData.init(o,n,r),this.sharedData.setValue(o,n,r),this.sharedData.callListeners(o,n)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,o)=>{const[a,n]=d.extractPrefix(o);if(a===r){this.sharedData.clear(n,a),this.sharedData.callListeners(n,a);return}})}resolve(e){const{key:r,prefix:t}=e;return this.get(r,t)}clear(e,r){let t,o;typeof e=="string"?(t=e,o=r||"_global"):(t=e.key,o=e.prefix),this.sharedData.clear(t,o)}has(e,r="_global"){const t=r||"_global";return!!this.sharedData.has(e,t)}getAll(){const e={};return this.sharedData.data.forEach((r,t)=>{const[o,a]=d.extractPrefix(t);e[o]=e[o]||{},e[o][a]=r}),e}}const k=i=>{const e=he();return{prefix:i??e?.scopeName??"_global"}};var M,K;function ge(){if(K)return M;K=1;var i=typeof Element<"u",e=typeof Map=="function",r=typeof Set=="function",t=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function o(a,n){if(a===n)return!0;if(a&&n&&typeof a=="object"&&typeof n=="object"){if(a.constructor!==n.constructor)return!1;var f,c,b;if(Array.isArray(a)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(!o(a[c],n[c]))return!1;return!0}var h;if(e&&a instanceof Map&&n instanceof Map){if(a.size!==n.size)return!1;for(h=a.entries();!(c=h.next()).done;)if(!n.has(c.value[0]))return!1;for(h=a.entries();!(c=h.next()).done;)if(!o(c.value[1],n.get(c.value[0])))return!1;return!0}if(r&&a instanceof Set&&n instanceof Set){if(a.size!==n.size)return!1;for(h=a.entries();!(c=h.next()).done;)if(!n.has(c.value[0]))return!1;return!0}if(t&&ArrayBuffer.isView(a)&&ArrayBuffer.isView(n)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(a[c]!==n[c])return!1;return!0}if(a.constructor===RegExp)return a.source===n.source&&a.flags===n.flags;if(a.valueOf!==Object.prototype.valueOf&&typeof a.valueOf=="function"&&typeof n.valueOf=="function")return a.valueOf()===n.valueOf();if(a.toString!==Object.prototype.toString&&typeof a.toString=="function"&&typeof n.toString=="function")return a.toString()===n.toString();if(b=Object.keys(a),f=b.length,f!==Object.keys(n).length)return!1;for(c=f;c--!==0;)if(!Object.prototype.hasOwnProperty.call(n,b[c]))return!1;if(i&&a instanceof Element)return!1;for(c=f;c--!==0;)if(!((b[c]==="_owner"||b[c]==="__v"||b[c]==="__o")&&a.$$typeof)&&!o(a[b[c]],n[b[c]]))return!1;return!0}return a!==a&&n!==n}return M=function(n,f){try{return o(n,f)}catch(c){if((c.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw c}},M}var ve=ge();const be=ce(ve);class me extends d{defaultValue(){return{value:void 0}}initValue(e,r,t,o=!1){super.init(e,r,{value:t},o)}initStatic(e){const{key:r,prefix:t,initialValue:o}=e;this.initValue(r,t,o,!0)}}class q extends Y{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.value:super.get(e,r)?.value}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,{value:r});return}super.set(e,{value:r},t)}}const _=new me,Ee=new q(_),xe=(i,e)=>_.createStatic({initialValue:i},e);function Re(i,e,r){let t,o,a=r;if(typeof i!="string"){const{key:l,initialValue:A,prefix:E}=i;t=l,o=A,a=E}else t=L(i),o=e;const{prefix:n}=k(a);_.initValue(t,n,o);const f=S.useMemo(()=>l=>(_.initValue(t,n,e),_.addListener(t,n,l),()=>{_.removeListener(t,n,l)}),[]),c=S.useMemo(()=>()=>_.get(t,n)?.value,[]),b=S.useSyncExternalStore(f,c),h=l=>{const A=typeof l=="function"?l(_.get(t,n)?.value):l;A!==b&&(_.setValue(t,n,{value:A}),_.callListeners(t,n))};return _.useEffect(t,n),[b,h]}function ye(i,e,r){let t,o=r;if(typeof i!="string"){const{key:h,prefix:l}=i;t=h,o=l}else t=L(i);const{prefix:a}=k(o),n=S.useRef(void 0),f=S.useMemo(()=>h=>(_.addListener(t,a,h),()=>{_.removeListener(t,a,h)}),[]),c=S.useMemo(()=>()=>{const h=_.get(t,a)?.value,l=e(h);return be(n.current,l)?n.current:l},[]),b=S.useSyncExternalStore(f,c);return _.useEffect(t,a),b}class _e extends d{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}}class $ extends Y{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}}const T=new _e,Ae=new $(T),Te=(i,e)=>T.createStatic({fn:i},e);function we(i,e,r){let t,o,a=r;if(typeof i!="string"){const{key:l,fn:A,prefix:E}=i;t=l,o=A,a=E}else t=L(i),o=e;const{prefix:n}=k(a);T.initValue(t,n);const f=S.useMemo(()=>l=>(T.initValue(t,n),T.addListener(t,n,l),()=>{T.removeListener(t,n,l)}),[]),c=S.useMemo(()=>()=>T.get(t,n).fnState,[]),b=S.useSyncExternalStore(f,c),h=async(l,...A)=>{const E=T.get(t,n);if(!l&&(E.fnState.isLoading||E.fnState.results!==void 0))return E.fnState;E.fnState={...E.fnState,isLoading:!0,error:void 0},T.callListeners(t,n);try{const m=await o(...A);E.fnState={results:m,isLoading:!1,error:void 0}}catch(m){E.fnState={...E.fnState,isLoading:!1,error:m}}T.callListeners(t,n)};return T.useEffect(t,n),{state:b,trigger:(...l)=>{h(!1,...l)},forceTrigger:(...l)=>{h(!0,...l)},clear:()=>{const l=T.get(t,n);l&&(l.fnState=T.defaultValue().fnState,T.callListeners(t,n))}}}class Oe extends d{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){S.useEffect(()=>()=>{V(`[${d.prefix(e,r)}]`,"unmount effect2"),this.get(e,r)?.listeners.length===0&&this.unsubscribe(e,r)},[]),super.useEffect(e,r)}async unsubscribe(e,r){const t=this.get(e,r);t&&(t.unsubscribe&&(t.unsubscribe(),t.unsubscribe=void 0),t.fnState={...t.fnState,subscribed:!1},this.callListeners(e,r))}}class ee extends Y{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}}const v=new Oe,Pe=new ee(v),je=(i,e)=>v.createStatic({subscriber:i},e);function Le(i,e,r){let t,o,a=r;if(typeof i!="string"){const{key:m,subscriber:x,prefix:P}=i;t=m,o=x,a=P}else t=L(i),o=e;const{prefix:n}=k(a);v.initValue(t,n);const f=S.useMemo(()=>m=>(v.initValue(t,n),v.addListener(t,n,m),()=>{v.removeListener(t,n,m)}),[]),c=S.useMemo(()=>()=>v.get(t,n).fnState,[]),b=S.useSyncExternalStore(f,c),h=m=>{const x=v.get(t,n);x.fnState={...x.fnState,data:m},v.callListeners(t,n)},l=m=>{const x=v.get(t,n);x.fnState={...x.fnState,isLoading:!1,data:void 0,error:m},v.callListeners(t,n)},A=()=>{const m=v.get(t,n);m.fnState={...m.fnState,isLoading:!1},v.callListeners(t,n)},E=async m=>{const x=v.get(t,n);if(m&&(await v.unsubscribe(t,n),x.fnState={...x.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),x.fnState.subscribed)return x.fnState;V("triggered !!"),x.fnState={...x.fnState,isLoading:!0,error:void 0},v.callListeners(t,n);try{const P=await o(h,l,A),j=v.get(t,n);j.unsubscribe=P,j.fnState.subscribed=!0}catch(P){const j=v.get(t,n);j.fnState={...j.fnState,isLoading:!1,error:P}}v.callListeners(t,n)};return v.useEffect(t,n),{state:b,trigger:()=>{E(!1)},forceTrigger:()=>{E(!0)},unsubscribe:()=>{v.unsubscribe(t,n)}}}p.SharedFunctionsApi=$,p.SharedStatesApi=q,p.SharedStatesProvider=Se,p.SharedSubscriptionsApi=ee,p.createSharedFunction=Te,p.createSharedState=xe,p.createSharedSubscription=je,p.setDevMode=pe,p.sharedFunctionsApi=Ae,p.sharedStatesApi=Ee,p.sharedSubscriptionsApi=Pe,p.useSharedFunction=we,p.useSharedState=Re,p.useSharedStateSelector=ye,p.useSharedSubscription=Le,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
|
29
|
+
<%s key={someKey} {...props} />`,R,_,D,_),oe[_+R]=!0)}if(_=null,g!==void 0&&(r(g),_=""+g),n(u)&&(r(u.key),_=""+u.key),"key"in u){g={};for(var B in u)B!=="key"&&(g[B]=u[B])}else g=u;return _&&f(g,typeof s=="function"?s.displayName||s.name||"Unknown":s),b(s,_,y,O,i(),g,G,U)}function l(s){typeof s=="object"&&s!==null&&s.$$typeof===E&&s._store&&(s._store.validated=1)}var A=h,E=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),De=Symbol.for("react.consumer"),Ce=Symbol.for("react.context"),Fe=Symbol.for("react.forward_ref"),Ve=Symbol.for("react.suspense"),Ne=Symbol.for("react.suspense_list"),Ye=Symbol.for("react.memo"),te=Symbol.for("react.lazy"),Me=Symbol.for("react.activity"),Ie=Symbol.for("react.client.reference"),W=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,re=Object.prototype.hasOwnProperty,We=Array.isArray,z=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(s){return s()}};var ne,se={},ae=A.react_stack_bottom_frame.bind(A,a)(),ie=z(t(a)),oe={};F.Fragment=x,F.jsx=function(s,u,g,R,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(s,u,g,!1,R,O,y?Error("react-stack-top-frame"):ae,y?z(t(s)):ie)},F.jsxs=function(s,u,g,R,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(s,u,g,!0,R,O,y?Error("react-stack-top-frame"):ae,y?z(t(s)):ie)}})()),F}var k;function le(){return k||(k=1,process.env.NODE_ENV==="production"?V.exports=ue():V.exports=fe()),V.exports}var de=le();p.isDevMode=!1;const pe=o=>{p.isDevMode=o},Y=(...o)=>{p.isDevMode&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...o)},L=o=>{if(!o)throw new Error("Value is empty");return o},H=()=>Math.random().toString(36).substring(2,15),Z=h.createContext(void 0),he=({children:o,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=h.useMemo(()=>H(),[])),de.jsx(Z.Provider,{value:{scopeName:e},children:o})},Se=()=>h.useContext(Z),Q=[];class d{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...this.defaultValue(),listeners:[]}),this.data.get(d.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(d.prefix(e,r))&&(this.data.get(d.prefix(e,r)).listeners=this.data.get(d.prefix(e,r)).listeners.filter(i=>i!==t))}callListeners(e,r){this.data.has(d.prefix(e,r))&&this.data.get(d.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t,i=!1){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...t,isStatic:i,listeners:[]})}createStatic(e,r){const t=r??r??"_global",i={key:H(),prefix:t,...e};return Q.push(i),this.initStatic(i),i}initStatic(e){const{key:r,prefix:t}=e;this.init(r,t,this.defaultValue(),!0)}clearAll(e=!1,r=!1){this.data.forEach((t,i)=>{const[a,n]=d.extractPrefix(i);this.clear(n,a,e,r)})}clear(e,r,t=!1,i=!1){t||this.callListeners(e,r);const a=this.data.get(d.prefix(e,r));if(!a)return;const n={...a};if(this.data.delete(d.prefix(e,r)),n.isStatic&&!i){const f=Q.find(c=>c.key===e&&c.prefix===r);f&&this.initStatic(f)}}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(d.prefix(e,r))&&this.data.set(d.prefix(e,r),{...this.data.get(d.prefix(e,r)),...t})}has(e,r){return this.data.has(d.prefix(e,r))?d.prefix(e,r):this.data.has(d.prefix(e,"_global"))?d.prefix(e,"_global"):void 0}static prefix(e,r){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${r}//${e}`}static extractPrefix(e){return e.split("//")}useEffect(e,r,t=null){h.useEffect(()=>()=>{t?.(),Y(`[${d.prefix(e,r)}]`,"unmount effect"),this.data.get(d.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}class M{constructor(e){this.sharedData=e}get(e,r){let t,i=r;if(typeof e!="string"){const{key:f,prefix:c}=e;t=f,i=c}else t=L(e);const a=i||"_global";return this.sharedData.get(t,a)}set(e,r,t){let i,a=t;if(typeof e!="string"){const{key:f,prefix:c}=e;i=f,a=c}else i=L(e);const n=a||"_global";this.sharedData.init(i,n,r),this.sharedData.setValue(i,n,r),this.sharedData.callListeners(i,n)}update(e,r,t){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,i)=>{const[a,n]=d.extractPrefix(i);if(a===r){this.sharedData.clear(n,a),this.sharedData.callListeners(n,a);return}})}resolve(e){const{key:r,prefix:t}=e;return this.get(r,t)}clear(e,r){let t,i;typeof e=="string"?(t=e,i=r||"_global"):(t=e.key,i=e.prefix),this.sharedData.clear(t,i)}has(e,r="_global"){const t=r||"_global";return!!this.sharedData.has(e,t)}getAll(){const e={};return this.sharedData.data.forEach((r,t)=>{const[i,a]=d.extractPrefix(t);e[i]=e[i]||{},e[i][a]=r}),e}}const N=o=>{const e=Se();return{prefix:o??e?.scopeName??"_global"}};var I,K;function ge(){if(K)return I;K=1;var o=typeof Element<"u",e=typeof Map=="function",r=typeof Set=="function",t=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function i(a,n){if(a===n)return!0;if(a&&n&&typeof a=="object"&&typeof n=="object"){if(a.constructor!==n.constructor)return!1;var f,c,b;if(Array.isArray(a)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(!i(a[c],n[c]))return!1;return!0}var S;if(e&&a instanceof Map&&n instanceof Map){if(a.size!==n.size)return!1;for(S=a.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;for(S=a.entries();!(c=S.next()).done;)if(!i(c.value[1],n.get(c.value[0])))return!1;return!0}if(r&&a instanceof Set&&n instanceof Set){if(a.size!==n.size)return!1;for(S=a.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;return!0}if(t&&ArrayBuffer.isView(a)&&ArrayBuffer.isView(n)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(a[c]!==n[c])return!1;return!0}if(a.constructor===RegExp)return a.source===n.source&&a.flags===n.flags;if(a.valueOf!==Object.prototype.valueOf&&typeof a.valueOf=="function"&&typeof n.valueOf=="function")return a.valueOf()===n.valueOf();if(a.toString!==Object.prototype.toString&&typeof a.toString=="function"&&typeof n.toString=="function")return a.toString()===n.toString();if(b=Object.keys(a),f=b.length,f!==Object.keys(n).length)return!1;for(c=f;c--!==0;)if(!Object.prototype.hasOwnProperty.call(n,b[c]))return!1;if(o&&a instanceof Element)return!1;for(c=f;c--!==0;)if(!((b[c]==="_owner"||b[c]==="__v"||b[c]==="__o")&&a.$$typeof)&&!i(a[b[c]],n[b[c]]))return!1;return!0}return a!==a&&n!==n}return I=function(n,f){try{return i(n,f)}catch(c){if((c.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw c}},I}var ve=ge();const be=ce(ve);class me extends d{defaultValue(){return{value:void 0}}initValue(e,r,t,i=!1){super.init(e,r,{value:t},i)}initStatic(e){const{key:r,prefix:t,initialValue:i}=e;this.initValue(r,t,i,!0)}}class q extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.value:super.get(e,r)?.value}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,{value:r});return}super.set(e,{value:r},t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const w=new me,Ee=new q(w),xe=(o,e)=>w.createStatic({initialValue:o},e);function Re(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:l,initialValue:A,prefix:E}=o;t=l,i=A,a=E}else t=L(o),i=e;const{prefix:n}=N(a);w.initValue(t,n,i);const f=h.useMemo(()=>l=>(w.initValue(t,n,e),w.addListener(t,n,l),()=>{w.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>w.get(t,n)?.value,[]),b=h.useSyncExternalStore(f,c),S=l=>{const A=typeof l=="function"?l(w.get(t,n)?.value):l;A!==b&&(w.setValue(t,n,{value:A}),w.callListeners(t,n))};return w.useEffect(t,n),[b,S]}function _e(o,e,r){let t,i=r;if(typeof o!="string"){const{key:S,prefix:l}=o;t=S,i=l}else t=L(o);const{prefix:a}=N(i),n=h.useRef(void 0),f=h.useMemo(()=>S=>(w.addListener(t,a,S),()=>{w.removeListener(t,a,S)}),[]),c=h.useMemo(()=>()=>{const S=w.get(t,a)?.value,l=e(S);return be(n.current,l)?n.current:l},[]),b=h.useSyncExternalStore(f,c);return w.useEffect(t,a),b}class we extends d{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}}class $ extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const T=new we,Ae=new $(T),Te=(o,e)=>T.createStatic({fn:o},e);function ye(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:l,fn:A,prefix:E}=o;t=l,i=A,a=E}else t=L(o),i=e;const{prefix:n}=N(a);T.initValue(t,n);const f=h.useMemo(()=>l=>(T.initValue(t,n),T.addListener(t,n,l),()=>{T.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>T.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=async(l,...A)=>{const E=T.get(t,n);if(!l&&(E.fnState.isLoading||E.fnState.results!==void 0))return E.fnState;E.fnState={...E.fnState,isLoading:!0,error:void 0},T.callListeners(t,n);try{const m=await i(...A);E.fnState={results:m,isLoading:!1,error:void 0}}catch(m){E.fnState={...E.fnState,isLoading:!1,error:m}}T.callListeners(t,n)};return T.useEffect(t,n),{state:b,trigger:(...l)=>{S(!1,...l)},forceTrigger:(...l)=>{S(!0,...l)},clear:()=>{const l=T.get(t,n);l&&(l.fnState=T.defaultValue().fnState,T.callListeners(t,n))}}}class Oe extends d{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){h.useEffect(()=>()=>{Y(`[${d.prefix(e,r)}]`,"unmount effect2"),this.get(e,r)?.listeners.length===0&&this.unsubscribe(e,r)},[]),super.useEffect(e,r)}async unsubscribe(e,r){const t=this.get(e,r);t&&(t.unsubscribe&&(t.unsubscribe(),t.unsubscribe=void 0),t.fnState={...t.fnState,subscribed:!1},this.callListeners(e,r))}}class ee extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const v=new Oe,Pe=new ee(v),je=(o,e)=>v.createStatic({subscriber:o},e);function Le(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:m,subscriber:x,prefix:P}=o;t=m,i=x,a=P}else t=L(o),i=e;const{prefix:n}=N(a);v.initValue(t,n);const f=h.useMemo(()=>m=>(v.initValue(t,n),v.addListener(t,n,m),()=>{v.removeListener(t,n,m)}),[]),c=h.useMemo(()=>()=>v.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=m=>{const x=v.get(t,n);x.fnState={...x.fnState,data:m},v.callListeners(t,n)},l=m=>{const x=v.get(t,n);x.fnState={...x.fnState,isLoading:!1,data:void 0,error:m},v.callListeners(t,n)},A=()=>{const m=v.get(t,n);m.fnState={...m.fnState,isLoading:!1},v.callListeners(t,n)},E=async m=>{const x=v.get(t,n);if(m&&(await v.unsubscribe(t,n),x.fnState={...x.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),x.fnState.subscribed)return x.fnState;Y("triggered !!"),x.fnState={...x.fnState,isLoading:!0,error:void 0},v.callListeners(t,n);try{const P=await i(S,l,A),j=v.get(t,n);j.unsubscribe=P,j.fnState.subscribed=!0}catch(P){const j=v.get(t,n);j.fnState={...j.fnState,isLoading:!1,error:P}}v.callListeners(t,n)};return v.useEffect(t,n),{state:b,trigger:()=>{E(!1)},forceTrigger:()=>{E(!0)},unsubscribe:()=>{v.unsubscribe(t,n)}}}p.SharedFunctionsApi=$,p.SharedStatesApi=q,p.SharedStatesProvider=he,p.SharedSubscriptionsApi=ee,p.createSharedFunction=Te,p.createSharedState=xe,p.createSharedSubscription=je,p.setDevMode=pe,p.sharedFunctionsApi=Ae,p.sharedStatesApi=Ee,p.sharedSubscriptionsApi=Pe,p.useSharedFunction=ye,p.useSharedState=Re,p.useSharedStateSelector=_e,p.useSharedSubscription=Le,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
package/tests/index.test.tsx
CHANGED
|
@@ -159,6 +159,14 @@ describe('useSharedState', () => {
|
|
|
159
159
|
// Get updated value
|
|
160
160
|
expect(sharedStatesApi.get(sharedCounter)).toBe(200);
|
|
161
161
|
|
|
162
|
+
// Update the value
|
|
163
|
+
act(() => {
|
|
164
|
+
sharedStatesApi.update(sharedCounter, (prev) => prev + 50);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Get updated value after update
|
|
168
|
+
expect(sharedStatesApi.get(sharedCounter)).toBe(250);
|
|
169
|
+
|
|
162
170
|
// Clear the value
|
|
163
171
|
act(() => {
|
|
164
172
|
sharedStatesApi.clear(sharedCounter);
|
|
@@ -310,6 +318,20 @@ describe('useSharedFunction', () => {
|
|
|
310
318
|
expect(updatedState.isLoading).toBe(true);
|
|
311
319
|
expect(updatedState.error).toBe('test error');
|
|
312
320
|
|
|
321
|
+
// Update the state
|
|
322
|
+
act(() => {
|
|
323
|
+
sharedFunctionsApi.update(sharedFunction, (prev) => ({
|
|
324
|
+
fnState: {
|
|
325
|
+
...prev,
|
|
326
|
+
results: 'updated data',
|
|
327
|
+
}
|
|
328
|
+
}));
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Get updated state after update
|
|
332
|
+
const updatedState2 = sharedFunctionsApi.get(sharedFunction);
|
|
333
|
+
expect(updatedState2.results).toBe('updated data');
|
|
334
|
+
|
|
313
335
|
// Clear the value
|
|
314
336
|
act(() => {
|
|
315
337
|
sharedFunctionsApi.clear(sharedFunction);
|
|
@@ -374,6 +396,20 @@ describe('useSharedSubscription', () => {
|
|
|
374
396
|
expect(updatedState.isLoading).toBe(true);
|
|
375
397
|
expect(updatedState.error).toBe('test error');
|
|
376
398
|
|
|
399
|
+
// Update the state
|
|
400
|
+
act(() => {
|
|
401
|
+
sharedSubscriptionsApi.update(sharedSubscription, (prev) => ({
|
|
402
|
+
fnState: {
|
|
403
|
+
...prev,
|
|
404
|
+
data: 'updated data',
|
|
405
|
+
}
|
|
406
|
+
}));
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// Get updated state after update
|
|
410
|
+
const updatedState2 = sharedSubscriptionsApi.get(sharedSubscription);
|
|
411
|
+
expect(updatedState2.data).toBe('updated data');
|
|
412
|
+
|
|
377
413
|
// Clear the value
|
|
378
414
|
act(() => {
|
|
379
415
|
sharedSubscriptionsApi.clear(sharedSubscription);
|
|
@@ -513,6 +549,20 @@ describe('useSharedSubscription', () => {
|
|
|
513
549
|
expect(updatedState.isLoading).toBe(true);
|
|
514
550
|
expect(updatedState.error).toBe('test error');
|
|
515
551
|
|
|
552
|
+
// Update the state
|
|
553
|
+
act(() => {
|
|
554
|
+
sharedSubscriptionsApi.update(sharedSubscription, (prev) => ({
|
|
555
|
+
fnState: {
|
|
556
|
+
...prev,
|
|
557
|
+
data: 'updated data',
|
|
558
|
+
}
|
|
559
|
+
}));
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
// Get updated state after update
|
|
563
|
+
const updatedState2 = sharedSubscriptionsApi.get(sharedSubscription);
|
|
564
|
+
expect(updatedState2.data).toBe('updated data');
|
|
565
|
+
|
|
516
566
|
// Clear the value
|
|
517
567
|
act(() => {
|
|
518
568
|
sharedSubscriptionsApi.clear(sharedSubscription);
|