@yaasl/react 0.7.0 → 0.8.0-alpha.1
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 +3 -2
- package/dist/cjs/useAtom.js +4 -3
- package/dist/mjs/useAtom.js +5 -4
- package/package.json +5 -9
package/dist/@types/useAtom.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SetStateAction } from "react";
|
|
2
2
|
import { Atom, Stateful } from "@yaasl/core";
|
|
3
|
+
import { SettableDerive } from "@yaasl/core/src";
|
|
3
4
|
/** Use an atom's value in the react lifecycle.
|
|
4
5
|
*
|
|
5
6
|
* @param atom Atom to be used.
|
|
@@ -13,7 +14,7 @@ export declare const useAtomValue: <ValueType>(atom: Stateful<ValueType>) => Val
|
|
|
13
14
|
*
|
|
14
15
|
* @returns A setter function for the atom.
|
|
15
16
|
**/
|
|
16
|
-
export declare const useSetAtom: <ValueType>(atom: Atom<ValueType>) => (next: SetStateAction<ValueType>) => void;
|
|
17
|
+
export declare const useSetAtom: <ValueType>(atom: Atom<ValueType> | SettableDerive<ValueType>) => (next: SetStateAction<ValueType>) => void;
|
|
17
18
|
/** Use an atom's initialization state in the react lifecycle.
|
|
18
19
|
*
|
|
19
20
|
* @param atom Atom to be used.
|
|
@@ -29,4 +30,4 @@ export declare const useAtomDidInit: <ValueType>(atom: Atom<ValueType>) => boole
|
|
|
29
30
|
*
|
|
30
31
|
* @returns [value, setValue, didInit]
|
|
31
32
|
**/
|
|
32
|
-
export declare const useAtom: <ValueType>(atom: Atom<ValueType>) => readonly [ValueType, (next: SetStateAction<ValueType>) => void, boolean];
|
|
33
|
+
export declare const useAtom: <ValueType>(atom: Atom<ValueType> | SettableDerive<ValueType>) => readonly [ValueType, (next: SetStateAction<ValueType>) => void, boolean];
|
package/dist/cjs/useAtom.js
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
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
|
-
const useStatefulValue_1 = require("./useStatefulValue");
|
|
6
5
|
/** Use an atom's value in the react lifecycle.
|
|
7
6
|
*
|
|
8
7
|
* @param atom Atom to be used.
|
|
9
8
|
*
|
|
10
9
|
* @returns A stateful value.
|
|
11
10
|
**/
|
|
12
|
-
const useAtomValue = (atom) => (0,
|
|
11
|
+
const useAtomValue = (atom) => (0, react_1.useSyncExternalStore)(set => atom.subscribe(set), () => atom.get());
|
|
13
12
|
exports.useAtomValue = useAtomValue;
|
|
14
13
|
/** Set an atom's value in the react lifecycle.
|
|
15
14
|
*
|
|
@@ -17,7 +16,9 @@ exports.useAtomValue = useAtomValue;
|
|
|
17
16
|
*
|
|
18
17
|
* @returns A setter function for the atom.
|
|
19
18
|
**/
|
|
20
|
-
const useSetAtom = (atom) =>
|
|
19
|
+
const useSetAtom = (atom) => {
|
|
20
|
+
return (0, react_1.useCallback)((next) => atom.set(next), [atom]);
|
|
21
|
+
};
|
|
21
22
|
exports.useSetAtom = useSetAtom;
|
|
22
23
|
/** Use an atom's initialization state in the react lifecycle.
|
|
23
24
|
*
|
package/dist/mjs/useAtom.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { useCallback, useState, useEffect } from "react";
|
|
2
|
-
import { useStatefulValue } from "./useStatefulValue";
|
|
1
|
+
import { useCallback, useState, useEffect, useSyncExternalStore, } from "react";
|
|
3
2
|
/** Use an atom's value in the react lifecycle.
|
|
4
3
|
*
|
|
5
4
|
* @param atom Atom to be used.
|
|
6
5
|
*
|
|
7
6
|
* @returns A stateful value.
|
|
8
7
|
**/
|
|
9
|
-
export const useAtomValue = (atom) =>
|
|
8
|
+
export const useAtomValue = (atom) => useSyncExternalStore(set => atom.subscribe(set), () => atom.get());
|
|
10
9
|
/** Set an atom's value in the react lifecycle.
|
|
11
10
|
*
|
|
12
11
|
* @param atom Atom to be used.
|
|
13
12
|
*
|
|
14
13
|
* @returns A setter function for the atom.
|
|
15
14
|
**/
|
|
16
|
-
export const useSetAtom = (atom) =>
|
|
15
|
+
export const useSetAtom = (atom) => {
|
|
16
|
+
return useCallback((next) => atom.set(next), [atom]);
|
|
17
|
+
};
|
|
17
18
|
/** Use an atom's initialization state in the react lifecycle.
|
|
18
19
|
*
|
|
19
20
|
* @param atom Atom to be used.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaasl/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-alpha.1",
|
|
4
4
|
"description": "yet another atomic store library (react)",
|
|
5
5
|
"author": "PrettyCoffee",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"compile:mjs": "tsc -p ./tsconfig.node.json --outDir ./dist/mjs -m es2020 -t es2020",
|
|
32
32
|
"compile:cjs": "tsc -p ./tsconfig.node.json --outDir ./dist/cjs -m commonjs -t es2015",
|
|
33
33
|
"compile:types": "tsc -p ./tsconfig.node.json --outDir ./dist/@types --declaration --emitDeclarationOnly",
|
|
34
|
-
"test": "
|
|
35
|
-
"test:watch": "
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest watch",
|
|
36
36
|
"lint": "eslint ./src",
|
|
37
37
|
"lint:fix": "eslint ./src --fix",
|
|
38
38
|
"validate": "run-s lint test build"
|
|
@@ -41,17 +41,13 @@
|
|
|
41
41
|
"react": ">=17"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@yaasl/core": "0.
|
|
44
|
+
"@yaasl/core": "0.8.0-alpha.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@testing-library/react": "^14.2.1",
|
|
48
|
-
"@types/react": "^18.2.
|
|
48
|
+
"@types/react": "^18.2.56",
|
|
49
49
|
"react": "^18.2.0"
|
|
50
50
|
},
|
|
51
|
-
"jest": {
|
|
52
|
-
"preset": "ts-jest",
|
|
53
|
-
"testEnvironment": "jsdom"
|
|
54
|
-
},
|
|
55
51
|
"eslintConfig": {
|
|
56
52
|
"extends": [
|
|
57
53
|
"../../.eslintrc",
|