react-use-singleton-hook 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/dist/main.d.ts +5 -2
- package/dist/main.js +14 -14
- package/dist/singletonHook.d.ts +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { singletonHook } from './singletonHook';
|
|
2
|
-
export { singletonHook as
|
|
2
|
+
export { singletonHook as createSingletonGlobalState };
|
|
3
3
|
declare const ReactSingletonHook: {
|
|
4
|
-
|
|
4
|
+
createSingletonGlobalState: <T>(initValue: T | (() => T), useHookBody: () => T, options?: {
|
|
5
|
+
mountId?: string;
|
|
6
|
+
unmountIfNoConsumers?: boolean;
|
|
7
|
+
}) => (() => T);
|
|
5
8
|
};
|
|
6
9
|
export default ReactSingletonHook;
|
package/dist/main.js
CHANGED
|
@@ -2,14 +2,14 @@ import i, { useEffect as v } from "react";
|
|
|
2
2
|
import { createRoot as E } from "react-dom/client";
|
|
3
3
|
const g = (t) => {
|
|
4
4
|
let e;
|
|
5
|
-
const u = /* @__PURE__ */ new Set(),
|
|
5
|
+
const u = /* @__PURE__ */ new Set(), l = (o, s) => {
|
|
6
6
|
const n = typeof o == "function" ? o(e) : o;
|
|
7
7
|
if (!Object.is(n, e)) {
|
|
8
8
|
const m = e;
|
|
9
9
|
e = s ?? (typeof n != "object" || n === null) ? n : Object.assign({}, e, n), u.forEach((b) => b(e, m));
|
|
10
10
|
}
|
|
11
|
-
}, a = () => e,
|
|
12
|
-
return
|
|
11
|
+
}, a = () => e, c = { setState: l, getState: a, getInitialState: () => r, subscribe: (o) => (u.add(o), () => u.delete(o)) }, r = e = t(l, a, c);
|
|
12
|
+
return c;
|
|
13
13
|
}, h = ((t) => t ? g(t) : g), k = (t) => t;
|
|
14
14
|
function C(t, e = k) {
|
|
15
15
|
const u = i.useSyncExternalStore(
|
|
@@ -19,10 +19,10 @@ function C(t, e = k) {
|
|
|
19
19
|
);
|
|
20
20
|
return i.useDebugValue(u), u;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
const { mountId:
|
|
24
|
-
let S = !f,
|
|
25
|
-
const r = h(() => ({ value:
|
|
22
|
+
const j = (t, e, u = {}) => {
|
|
23
|
+
const { mountId: l, unmountIfNoConsumers: a = !0 } = u, f = typeof t == "function";
|
|
24
|
+
let S = !f, c = f ? void 0 : t;
|
|
25
|
+
const r = h(() => ({ value: c }));
|
|
26
26
|
let o = 0, s = null, n = null;
|
|
27
27
|
function m() {
|
|
28
28
|
const d = e();
|
|
@@ -31,13 +31,13 @@ function j(t, e, u = {}) {
|
|
|
31
31
|
}, [d]), null;
|
|
32
32
|
}
|
|
33
33
|
function b() {
|
|
34
|
-
s || (n = document.createElement("div"), n.style.display = "none",
|
|
34
|
+
s || (n = document.createElement("div"), n.style.display = "none", l && (n.id = l), document.body.appendChild(n), s = E(n), s.render(i.createElement(m)));
|
|
35
35
|
}
|
|
36
36
|
function I() {
|
|
37
37
|
!s || !n || (s.unmount(), n.remove(), s = null, n = null);
|
|
38
38
|
}
|
|
39
39
|
function y() {
|
|
40
|
-
!S && f && (S = !0,
|
|
40
|
+
!S && f && (S = !0, c = t(), r.setState({ value: c }));
|
|
41
41
|
}
|
|
42
42
|
function R() {
|
|
43
43
|
y();
|
|
@@ -47,11 +47,11 @@ function j(t, e, u = {}) {
|
|
|
47
47
|
}), []), d;
|
|
48
48
|
}
|
|
49
49
|
return R;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
}, G = {
|
|
51
|
+
//This Generic Arrow Function is creating a hook, not calling one, so naming convention should not have use prefix
|
|
52
|
+
createSingletonGlobalState: j
|
|
53
53
|
};
|
|
54
54
|
export {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
j as createSingletonGlobalState,
|
|
56
|
+
G as default
|
|
57
57
|
};
|
package/dist/singletonHook.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ type Options = {
|
|
|
2
2
|
mountId?: string;
|
|
3
3
|
unmountIfNoConsumers?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare
|
|
5
|
+
export declare const singletonHook: <T>(initValue: T | (() => T), useHookBody: () => T, options?: Options) => (() => T);
|
|
6
6
|
export {};
|