@yaasl/react 0.11.0-alpha.2 → 0.11.0
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/@types/useAtom.d.ts +4 -4
- package/dist/cjs/useAtom.js +4 -4
- package/dist/cjs/useStateful.js +2 -1
- package/dist/esm/useAtom.js +4 -4
- package/dist/esm/useStateful.js +2 -1
- package/package.json +6 -11
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -9
package/dist/@types/useAtom.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type { Stateful } from "@yaasl/core";
|
|
2
|
-
/** Use an atom's value in the
|
|
2
|
+
/** Use an atom's value in the React lifecycle.
|
|
3
3
|
*
|
|
4
4
|
* @param atom Atom to be used.
|
|
5
5
|
*
|
|
6
6
|
* @returns The atom's value.
|
|
7
7
|
**/
|
|
8
8
|
export declare const useAtomValue: <ValueType>(atom: Stateful<ValueType>) => ValueType;
|
|
9
|
-
/** Set an atom's value in the
|
|
9
|
+
/** Set an atom's value in the React lifecycle.
|
|
10
10
|
*
|
|
11
11
|
* @param atom Atom to be used.
|
|
12
12
|
*
|
|
13
13
|
* @returns A setter function for the atom.
|
|
14
14
|
**/
|
|
15
15
|
export declare const useSetAtom: <ValueType>(atom: Stateful<ValueType>) => (next: import("react").SetStateAction<ValueType>) => void;
|
|
16
|
-
/** Use an atom's initialization state in the
|
|
16
|
+
/** Use an atom's initialization state in the React lifecycle.
|
|
17
17
|
*
|
|
18
18
|
* @param atom Atom to be used.
|
|
19
19
|
*
|
|
20
20
|
* @returns A boolean indicating if the atom has finished initializing yet.
|
|
21
21
|
**/
|
|
22
22
|
export declare const useAtomDidInit: <ValueType>(atom: Stateful<ValueType>) => boolean;
|
|
23
|
-
/** Use an atom's value and setter in the
|
|
23
|
+
/** Use an atom's value and setter in the React lifecycle.
|
|
24
24
|
*
|
|
25
25
|
* @param atom Atom to be used.
|
|
26
26
|
*
|
package/dist/cjs/useAtom.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useAtom = exports.useAtomDidInit = exports.useSetAtom = exports.useAtomValue = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useStateful_1 = require("./useStateful");
|
|
6
|
-
/** Use an atom's value in the
|
|
6
|
+
/** Use an atom's value in the React lifecycle.
|
|
7
7
|
*
|
|
8
8
|
* @param atom Atom to be used.
|
|
9
9
|
*
|
|
@@ -11,7 +11,7 @@ const useStateful_1 = require("./useStateful");
|
|
|
11
11
|
**/
|
|
12
12
|
const useAtomValue = (atom) => (0, useStateful_1.useStatefulValue)(atom);
|
|
13
13
|
exports.useAtomValue = useAtomValue;
|
|
14
|
-
/** Set an atom's value in the
|
|
14
|
+
/** Set an atom's value in the React lifecycle.
|
|
15
15
|
*
|
|
16
16
|
* @param atom Atom to be used.
|
|
17
17
|
*
|
|
@@ -19,7 +19,7 @@ exports.useAtomValue = useAtomValue;
|
|
|
19
19
|
**/
|
|
20
20
|
const useSetAtom = (atom) => (0, useStateful_1.useSetStateful)(atom);
|
|
21
21
|
exports.useSetAtom = useSetAtom;
|
|
22
|
-
/** Use an atom's initialization state in the
|
|
22
|
+
/** Use an atom's initialization state in the React lifecycle.
|
|
23
23
|
*
|
|
24
24
|
* @param atom Atom to be used.
|
|
25
25
|
*
|
|
@@ -35,7 +35,7 @@ const useAtomDidInit = (atom) => {
|
|
|
35
35
|
return didInit;
|
|
36
36
|
};
|
|
37
37
|
exports.useAtomDidInit = useAtomDidInit;
|
|
38
|
-
/** Use an atom's value and setter in the
|
|
38
|
+
/** Use an atom's value and setter in the React lifecycle.
|
|
39
39
|
*
|
|
40
40
|
* @param atom Atom to be used.
|
|
41
41
|
*
|
package/dist/cjs/useStateful.js
CHANGED
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useSetStateful = exports.useStatefulValue = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("@yaasl/utils");
|
|
6
|
-
const useStatefulValue = (stateful) => (0, react_1.useSyncExternalStore)(set => stateful.subscribe(set), () => stateful.get());
|
|
6
|
+
const useStatefulValue = (stateful) => (0, react_1.useSyncExternalStore)(set => stateful.subscribe(set), () => stateful.get(), () => stateful.get());
|
|
7
7
|
exports.useStatefulValue = useStatefulValue;
|
|
8
8
|
const useSetStateful = (stateful) => (0, react_1.useCallback)((next) => {
|
|
9
9
|
if (!("set" in stateful) || !(stateful.set instanceof Function)) {
|
|
10
10
|
throw new Error((0, utils_1.consoleMessage)("Atom does not have a set method"));
|
|
11
11
|
}
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
12
13
|
stateful.set(next);
|
|
13
14
|
}, [stateful]);
|
|
14
15
|
exports.useSetStateful = useSetStateful;
|
package/dist/esm/useAtom.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
2
|
import { useSetStateful, useStatefulValue } from "./useStateful";
|
|
3
|
-
/** Use an atom's value in the
|
|
3
|
+
/** Use an atom's value in the React lifecycle.
|
|
4
4
|
*
|
|
5
5
|
* @param atom Atom to be used.
|
|
6
6
|
*
|
|
7
7
|
* @returns The atom's value.
|
|
8
8
|
**/
|
|
9
9
|
export const useAtomValue = (atom) => useStatefulValue(atom);
|
|
10
|
-
/** Set an atom's value in the
|
|
10
|
+
/** Set an atom's value in the React lifecycle.
|
|
11
11
|
*
|
|
12
12
|
* @param atom Atom to be used.
|
|
13
13
|
*
|
|
14
14
|
* @returns A setter function for the atom.
|
|
15
15
|
**/
|
|
16
16
|
export const useSetAtom = (atom) => useSetStateful(atom);
|
|
17
|
-
/** Use an atom's initialization state in the
|
|
17
|
+
/** Use an atom's initialization state in the React lifecycle.
|
|
18
18
|
*
|
|
19
19
|
* @param atom Atom to be used.
|
|
20
20
|
*
|
|
@@ -29,7 +29,7 @@ export const useAtomDidInit = (atom) => {
|
|
|
29
29
|
}, [atom.didInit]);
|
|
30
30
|
return didInit;
|
|
31
31
|
};
|
|
32
|
-
/** Use an atom's value and setter in the
|
|
32
|
+
/** Use an atom's value and setter in the React lifecycle.
|
|
33
33
|
*
|
|
34
34
|
* @param atom Atom to be used.
|
|
35
35
|
*
|
package/dist/esm/useStateful.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useCallback, useSyncExternalStore } from "react";
|
|
2
2
|
import { consoleMessage } from "@yaasl/utils";
|
|
3
|
-
export const useStatefulValue = (stateful) => useSyncExternalStore(set => stateful.subscribe(set), () => stateful.get());
|
|
3
|
+
export const useStatefulValue = (stateful) => useSyncExternalStore(set => stateful.subscribe(set), () => stateful.get(), () => stateful.get());
|
|
4
4
|
export const useSetStateful = (stateful) => useCallback((next) => {
|
|
5
5
|
if (!("set" in stateful) || !(stateful.set instanceof Function)) {
|
|
6
6
|
throw new Error(consoleMessage("Atom does not have a set method"));
|
|
7
7
|
}
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
8
9
|
stateful.set(next);
|
|
9
10
|
}, [stateful]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaasl/react",
|
|
3
|
-
"version": "0.11.0
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "yet another atomic store library (react)",
|
|
5
5
|
"author": "PrettyCoffee",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,23 +40,18 @@
|
|
|
40
40
|
"validate": "run-s lint test build"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"react": "
|
|
43
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@yaasl/core": "0.11.0
|
|
47
|
-
"@yaasl/utils": "0.11.0
|
|
46
|
+
"@yaasl/core": "0.11.0",
|
|
47
|
+
"@yaasl/utils": "0.11.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@testing-library/react": "^
|
|
50
|
+
"@testing-library/react": "^16.2.0",
|
|
51
51
|
"@types/react": "^18.3.18",
|
|
52
|
+
"react-dom": "^18.3.1",
|
|
52
53
|
"react": "^18.3.1"
|
|
53
54
|
},
|
|
54
|
-
"eslintConfig": {
|
|
55
|
-
"extends": [
|
|
56
|
-
"../../.eslintrc",
|
|
57
|
-
"@pretty-cozy/eslint-config/react"
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
55
|
"lint-staged": {
|
|
61
56
|
"*.{ts,tsx}": [
|
|
62
57
|
"npm run lint:fix"
|
package/tsconfig.json
DELETED