signalium 0.3.6 → 0.3.7
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/cjs/react/signal-value.d.ts.map +1 -1
- package/dist/cjs/react/signal-value.js +25 -14
- package/dist/cjs/react/signal-value.js.map +1 -1
- package/dist/esm/react/signal-value.d.ts.map +1 -1
- package/dist/esm/react/signal-value.js +25 -14
- package/dist/esm/react/signal-value.js.map +1 -1
- package/package.json +1 -1
- package/src/react/signal-value.ts +35 -19
package/.turbo/turbo-build.log
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
|
-
> signalium@0.3.
|
2
|
+
> signalium@0.3.7 build
|
3
3
|
> npm run build:esm && npm run build:cjs
|
4
4
|
|
5
5
|
|
6
|
-
> signalium@0.3.
|
6
|
+
> signalium@0.3.7 build:esm
|
7
7
|
> tsc
|
8
8
|
|
9
9
|
|
10
|
-
> signalium@0.3.
|
10
|
+
> signalium@0.3.7 build:cjs
|
11
11
|
> tsc --module commonjs --outDir dist/cjs --moduleResolution node
|
12
12
|
|
package/CHANGELOG.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"signal-value.d.ts","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"signal-value.d.ts","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"AAuBA,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAqE7D"}
|
@@ -43,11 +43,10 @@ const hooks_js_1 = require("../hooks.js");
|
|
43
43
|
// and production, and it doesn't appear that the React team wants to add one. This
|
44
44
|
// should be checked on every major React version upgrade.
|
45
45
|
const REACT_INTERNALS = react_1.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ||
|
46
|
-
react_1.default.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
|
47
|
-
react_1.default.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
46
|
+
react_1.default.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
48
47
|
const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
|
49
48
|
const getReactCurrentDispatcher = () => {
|
50
|
-
return ReactCurrentDispatcher
|
49
|
+
return ReactCurrentDispatcher?.current || ReactCurrentDispatcher?.A || null;
|
51
50
|
};
|
52
51
|
function isRendering() {
|
53
52
|
return getReactCurrentDispatcher() !== null;
|
@@ -60,6 +59,7 @@ function useSignalValue(key, fn) {
|
|
60
59
|
const scope = (0, react_1.useContext)(context_js_1.ScopeContext);
|
61
60
|
const ref = (0, react_1.useRef)({
|
62
61
|
value: undefined,
|
62
|
+
sub: undefined,
|
63
63
|
unsub: undefined,
|
64
64
|
key: undefined,
|
65
65
|
});
|
@@ -67,20 +67,31 @@ function useSignalValue(key, fn) {
|
|
67
67
|
if (key !== currentKey) {
|
68
68
|
ref.current.unsub?.();
|
69
69
|
const w = (0, hooks_js_1.watcher)(fn, { scope });
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
// Trigger an update to the component
|
74
|
-
if (initialized) {
|
75
|
-
setVersion(v => v + 1);
|
70
|
+
ref.current.sub = () => {
|
71
|
+
if (ref.current.unsub) {
|
72
|
+
return ref.current.unsub;
|
76
73
|
}
|
77
|
-
initialized =
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
let initialized = false;
|
75
|
+
const unsub = w.addListener(value => {
|
76
|
+
ref.current.value = value;
|
77
|
+
// Trigger an update to the component
|
78
|
+
if (initialized) {
|
79
|
+
setVersion(v => v + 1);
|
80
|
+
}
|
81
|
+
initialized = true;
|
82
|
+
}, {
|
83
|
+
immediate: true,
|
84
|
+
});
|
85
|
+
ref.current.unsub = () => {
|
86
|
+
ref.current.unsub = undefined;
|
87
|
+
unsub();
|
88
|
+
};
|
89
|
+
return ref.current.unsub;
|
90
|
+
};
|
91
|
+
ref.current.sub();
|
81
92
|
ref.current.key = key;
|
82
93
|
}
|
83
|
-
(0, react_1.useSyncExternalStore)(
|
94
|
+
(0, react_1.useSyncExternalStore)(ref.current.sub, () => ref.current.value, () => ref.current.value);
|
84
95
|
return ref.current.value;
|
85
96
|
}
|
86
97
|
//# sourceMappingURL=signal-value.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"signal-value.js","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"signal-value.js","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,wCAqEC;AA5FD,+CAA+C;AAC/C,+CAA+F;AAC/F,6CAA4C;AAC5C,0CAAsC;AAEtC,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,eAAa,CAAC,kDAAkD;IAChE,eAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,MAAM,yBAAyB,GAAG,GAAG,EAAE;IACrC,OAAO,sBAAsB,EAAE,OAAO,IAAI,sBAAsB,EAAE,CAAC,IAAI,IAAI,CAAC;AAC9E,CAAC,CAAC;AAEF,SAAS,WAAW;IAClB,OAAO,yBAAyB,EAAE,KAAK,IAAI,CAAC;AAC9C,CAAC;AAED,SAAgB,cAAc,CAAI,GAAW,EAAE,EAAW;IACxD,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,CAAC;IACd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YACV,CAAC,CAAC;YAEF,OAAO,GAAG,CAAC,OAAO,CAAC,KAAM,CAAC;QAC5B,CAAC,CAAC;QAEF,GAAG,CAAC,OAAO,CAAC,GAAI,EAAE,CAAC;QAEnB,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,IAAA,4BAAoB,EAClB,GAAG,CAAC,OAAO,CAAC,GAAI,EAChB,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAM,EACxB,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAM,CACzB,CAAC;IAEF,OAAO,GAAG,CAAC,OAAO,CAAC,KAAM,CAAC;AAC5B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"signal-value.d.ts","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"signal-value.d.ts","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"AAuBA,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAqE7D"}
|
@@ -7,11 +7,10 @@ import { watcher } from '../hooks.js';
|
|
7
7
|
// and production, and it doesn't appear that the React team wants to add one. This
|
8
8
|
// should be checked on every major React version upgrade.
|
9
9
|
const REACT_INTERNALS = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ||
|
10
|
-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
|
11
|
-
React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
10
|
+
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
12
11
|
const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
|
13
12
|
const getReactCurrentDispatcher = () => {
|
14
|
-
return ReactCurrentDispatcher
|
13
|
+
return ReactCurrentDispatcher?.current || ReactCurrentDispatcher?.A || null;
|
15
14
|
};
|
16
15
|
function isRendering() {
|
17
16
|
return getReactCurrentDispatcher() !== null;
|
@@ -24,6 +23,7 @@ export function useSignalValue(key, fn) {
|
|
24
23
|
const scope = useContext(ScopeContext);
|
25
24
|
const ref = useRef({
|
26
25
|
value: undefined,
|
26
|
+
sub: undefined,
|
27
27
|
unsub: undefined,
|
28
28
|
key: undefined,
|
29
29
|
});
|
@@ -31,20 +31,31 @@ export function useSignalValue(key, fn) {
|
|
31
31
|
if (key !== currentKey) {
|
32
32
|
ref.current.unsub?.();
|
33
33
|
const w = watcher(fn, { scope });
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
// Trigger an update to the component
|
38
|
-
if (initialized) {
|
39
|
-
setVersion(v => v + 1);
|
34
|
+
ref.current.sub = () => {
|
35
|
+
if (ref.current.unsub) {
|
36
|
+
return ref.current.unsub;
|
40
37
|
}
|
41
|
-
initialized =
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
let initialized = false;
|
39
|
+
const unsub = w.addListener(value => {
|
40
|
+
ref.current.value = value;
|
41
|
+
// Trigger an update to the component
|
42
|
+
if (initialized) {
|
43
|
+
setVersion(v => v + 1);
|
44
|
+
}
|
45
|
+
initialized = true;
|
46
|
+
}, {
|
47
|
+
immediate: true,
|
48
|
+
});
|
49
|
+
ref.current.unsub = () => {
|
50
|
+
ref.current.unsub = undefined;
|
51
|
+
unsub();
|
52
|
+
};
|
53
|
+
return ref.current.unsub;
|
54
|
+
};
|
55
|
+
ref.current.sub();
|
45
56
|
ref.current.key = key;
|
46
57
|
}
|
47
|
-
useSyncExternalStore(
|
58
|
+
useSyncExternalStore(ref.current.sub, () => ref.current.value, () => ref.current.value);
|
48
59
|
return ref.current.value;
|
49
60
|
}
|
50
61
|
//# sourceMappingURL=signal-value.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"signal-value.js","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"signal-value.js","sourceRoot":"","sources":["../../../src/react/signal-value.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,EAAE,EAAe,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,wFAAwF;AACxF,oFAAoF;AACpF,mFAAmF;AACnF,0DAA0D;AAC1D,MAAM,eAAe,GAClB,KAAa,CAAC,kDAAkD;IAChE,KAAa,CAAC,+DAA+D,CAAC;AAEjF,MAAM,sBAAsB,GAAG,eAAe,CAAC,sBAAsB,IAAI,eAAe,CAAC;AAEzF,MAAM,yBAAyB,GAAG,GAAG,EAAE;IACrC,OAAO,sBAAsB,EAAE,OAAO,IAAI,sBAAsB,EAAE,CAAC,IAAI,IAAI,CAAC;AAC9E,CAAC,CAAC;AAEF,SAAS,WAAW;IAClB,OAAO,yBAAyB,EAAE,KAAK,IAAI,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,cAAc,CAAI,GAAW,EAAE,EAAW;IACxD,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAED,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,MAAM,CAKf;QACD,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEH,M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AAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAM,CACzB,CAAC;IAEF,OAAO,GAAG,CAAC,OAAO,CAAC,KAAM,CAAC;AAC5B,CAAC"}
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/* eslint-disable react-hooks/rules-of-hooks */
|
2
|
-
import React, {
|
2
|
+
import React, { useCallback, useContext, useRef, useState, useSyncExternalStore } from 'react';
|
3
3
|
import { ScopeContext } from './context.js';
|
4
4
|
import { watcher } from '../hooks.js';
|
5
5
|
|
@@ -9,13 +9,12 @@ import { watcher } from '../hooks.js';
|
|
9
9
|
// should be checked on every major React version upgrade.
|
10
10
|
const REACT_INTERNALS =
|
11
11
|
(React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ||
|
12
|
-
(React as any).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
|
13
|
-
(React as any).__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
12
|
+
(React as any).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
14
13
|
|
15
14
|
const ReactCurrentDispatcher = REACT_INTERNALS.ReactCurrentDispatcher || REACT_INTERNALS;
|
16
15
|
|
17
16
|
const getReactCurrentDispatcher = () => {
|
18
|
-
return ReactCurrentDispatcher
|
17
|
+
return ReactCurrentDispatcher?.current || ReactCurrentDispatcher?.A || null;
|
19
18
|
};
|
20
19
|
|
21
20
|
function isRendering() {
|
@@ -31,10 +30,12 @@ export function useSignalValue<T>(key: string, fn: () => T): T {
|
|
31
30
|
const scope = useContext(ScopeContext);
|
32
31
|
const ref = useRef<{
|
33
32
|
value: T | undefined;
|
33
|
+
sub: (() => () => void) | undefined;
|
34
34
|
unsub: (() => void) | undefined;
|
35
35
|
key: string | undefined;
|
36
36
|
}>({
|
37
37
|
value: undefined,
|
38
|
+
sub: undefined,
|
38
39
|
unsub: undefined,
|
39
40
|
key: undefined,
|
40
41
|
});
|
@@ -46,29 +47,44 @@ export function useSignalValue<T>(key: string, fn: () => T): T {
|
|
46
47
|
|
47
48
|
const w = watcher(fn, { scope });
|
48
49
|
|
49
|
-
|
50
|
+
ref.current.sub = () => {
|
51
|
+
if (ref.current.unsub) {
|
52
|
+
return ref.current.unsub;
|
53
|
+
}
|
50
54
|
|
51
|
-
|
52
|
-
value => {
|
53
|
-
ref.current.value = value;
|
55
|
+
let initialized = false;
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
57
|
+
const unsub = w.addListener(
|
58
|
+
value => {
|
59
|
+
ref.current.value = value;
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
// Trigger an update to the component
|
62
|
+
if (initialized) {
|
63
|
+
setVersion(v => v + 1);
|
64
|
+
}
|
65
|
+
|
66
|
+
initialized = true;
|
67
|
+
},
|
68
|
+
{
|
69
|
+
immediate: true,
|
70
|
+
},
|
71
|
+
);
|
72
|
+
|
73
|
+
ref.current.unsub = () => {
|
74
|
+
ref.current.unsub = undefined;
|
75
|
+
unsub();
|
76
|
+
};
|
77
|
+
|
78
|
+
return ref.current.unsub!;
|
79
|
+
};
|
80
|
+
|
81
|
+
ref.current.sub!();
|
66
82
|
|
67
83
|
ref.current.key = key;
|
68
84
|
}
|
69
85
|
|
70
86
|
useSyncExternalStore(
|
71
|
-
|
87
|
+
ref.current.sub!,
|
72
88
|
() => ref.current.value!,
|
73
89
|
() => ref.current.value!,
|
74
90
|
);
|