@yaasl/preact 0.10.0 → 0.10.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Stateful } from "@yaasl/core";
|
|
2
2
|
import { Updater } from "@yaasl/utils";
|
|
3
|
-
export declare const useStatefulValue: <
|
|
3
|
+
export declare const useStatefulValue: <ValueType>(stateful: Stateful<ValueType>) => ValueType;
|
|
4
4
|
export declare const useSetStateful: <State>(stateful: Stateful<State>) => (next: Updater<State>) => void;
|
package/dist/cjs/useStateful.js
CHANGED
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSetStateful = exports.useStatefulValue = void 0;
|
|
4
4
|
const utils_1 = require("@yaasl/utils");
|
|
5
|
+
const compat_1 = require("preact/compat");
|
|
5
6
|
const hooks_1 = require("preact/hooks");
|
|
6
|
-
const useStatefulValue = (
|
|
7
|
-
const [state, setState] = (0, hooks_1.useState)(atom.get());
|
|
8
|
-
const unsubscribe = (0, hooks_1.useRef)(() => true);
|
|
9
|
-
(0, hooks_1.useEffect)(() => {
|
|
10
|
-
unsubscribe.current();
|
|
11
|
-
unsubscribe.current = atom.subscribe(setState);
|
|
12
|
-
return () => unsubscribe.current();
|
|
13
|
-
}, [atom]);
|
|
14
|
-
return state;
|
|
15
|
-
};
|
|
7
|
+
const useStatefulValue = (stateful) => (0, compat_1.useSyncExternalStore)(set => stateful.subscribe(set), () => stateful.get());
|
|
16
8
|
exports.useStatefulValue = useStatefulValue;
|
|
17
9
|
const useSetStateful = (stateful) => (0, hooks_1.useCallback)((next) => {
|
|
18
10
|
if (!("set" in stateful) || !(stateful.set instanceof Function)) {
|
package/dist/mjs/useStateful.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { consoleMessage } from "@yaasl/utils";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const unsubscribe = useRef(() => true);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
unsubscribe.current();
|
|
8
|
-
unsubscribe.current = atom.subscribe(setState);
|
|
9
|
-
return () => unsubscribe.current();
|
|
10
|
-
}, [atom]);
|
|
11
|
-
return state;
|
|
12
|
-
};
|
|
2
|
+
import { useSyncExternalStore } from "preact/compat";
|
|
3
|
+
import { useCallback } from "preact/hooks";
|
|
4
|
+
export const useStatefulValue = (stateful) => useSyncExternalStore(set => stateful.subscribe(set), () => stateful.get());
|
|
13
5
|
export const useSetStateful = (stateful) => useCallback((next) => {
|
|
14
6
|
if (!("set" in stateful) || !(stateful.set instanceof Function)) {
|
|
15
7
|
throw new Error(consoleMessage("Atom does not have a set method"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaasl/preact",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "yet another atomic store library (preact)",
|
|
5
5
|
"author": "PrettyCoffee",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"preact": ">=10"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@yaasl/core": "0.10.
|
|
45
|
-
"@yaasl/utils": "0.10.
|
|
44
|
+
"@yaasl/core": "0.10.2",
|
|
45
|
+
"@yaasl/utils": "0.10.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@testing-library/preact": "^3.2.
|
|
49
|
-
"preact": "^10.
|
|
48
|
+
"@testing-library/preact": "^3.2.4",
|
|
49
|
+
"preact": "^10.24.2"
|
|
50
50
|
},
|
|
51
51
|
"eslintConfig": {
|
|
52
52
|
"extends": [
|