@yaasl/react 0.11.0-alpha.3 → 0.12.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.
@@ -1,2 +1,2 @@
1
- export { useAtom, useSetAtom, useAtomValue, useAtomDidInit } from "./useAtom";
1
+ export { useAtom, useSetAtom, useAtomValue, useAtomDidInit } from "./use-atom";
2
2
  export * from "@yaasl/core";
@@ -2,11 +2,10 @@ import type { Stateful } from "@yaasl/core";
2
2
  /** Use an atom's value in the React lifecycle.
3
3
  *
4
4
  * @param atom Atom to be used.
5
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
6
5
  *
7
6
  * @returns The atom's value.
8
7
  **/
9
- export declare const useAtomValue: <ValueType>(atom: Stateful<ValueType>, getServerSnapshot?: () => ValueType) => ValueType;
8
+ export declare const useAtomValue: <ValueType>(atom: Stateful<ValueType>) => ValueType;
10
9
  /** Set an atom's value in the React lifecycle.
11
10
  *
12
11
  * @param atom Atom to be used.
@@ -24,8 +23,7 @@ export declare const useAtomDidInit: <ValueType>(atom: Stateful<ValueType>) => b
24
23
  /** Use an atom's value and setter in the React lifecycle.
25
24
  *
26
25
  * @param atom Atom to be used.
27
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
28
26
  *
29
27
  * @returns [value, setValue, didInit]
30
28
  **/
31
- export declare const useAtom: <ValueType>(atom: Stateful<ValueType>, getServerSnapshot?: () => ValueType) => readonly [ValueType, (next: import("react").SetStateAction<ValueType>) => void, boolean];
29
+ export declare const useAtom: <ValueType>(atom: Stateful<ValueType>) => readonly [ValueType, (next: import("react").SetStateAction<ValueType>) => void, boolean];
@@ -1,4 +1,4 @@
1
1
  import { SetStateAction } from "react";
2
- import { Stateful } from "@yaasl/core";
3
- export declare const useStatefulValue: <ValueType>(stateful: Stateful<ValueType>, getServerSnapshot?: () => ValueType) => ValueType;
2
+ import type { Stateful } from "@yaasl/core";
3
+ export declare const useStatefulValue: <ValueType>(stateful: Stateful<ValueType>) => ValueType;
4
4
  export declare const useSetStateful: <ValueType>(stateful: Stateful<ValueType>) => (next: SetStateAction<ValueType>) => void;
package/dist/cjs/index.js CHANGED
@@ -15,9 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.useAtomDidInit = exports.useAtomValue = exports.useSetAtom = exports.useAtom = void 0;
18
- var useAtom_1 = require("./useAtom");
19
- Object.defineProperty(exports, "useAtom", { enumerable: true, get: function () { return useAtom_1.useAtom; } });
20
- Object.defineProperty(exports, "useSetAtom", { enumerable: true, get: function () { return useAtom_1.useSetAtom; } });
21
- Object.defineProperty(exports, "useAtomValue", { enumerable: true, get: function () { return useAtom_1.useAtomValue; } });
22
- Object.defineProperty(exports, "useAtomDidInit", { enumerable: true, get: function () { return useAtom_1.useAtomDidInit; } });
18
+ var use_atom_1 = require("./use-atom");
19
+ Object.defineProperty(exports, "useAtom", { enumerable: true, get: function () { return use_atom_1.useAtom; } });
20
+ Object.defineProperty(exports, "useSetAtom", { enumerable: true, get: function () { return use_atom_1.useSetAtom; } });
21
+ Object.defineProperty(exports, "useAtomValue", { enumerable: true, get: function () { return use_atom_1.useAtomValue; } });
22
+ Object.defineProperty(exports, "useAtomDidInit", { enumerable: true, get: function () { return use_atom_1.useAtomDidInit; } });
23
23
  __exportStar(require("@yaasl/core"), exports);
@@ -2,15 +2,14 @@
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 useStateful_1 = require("./useStateful");
5
+ const use_stateful_1 = require("./use-stateful");
6
6
  /** Use an atom's value in the React lifecycle.
7
7
  *
8
8
  * @param atom Atom to be used.
9
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
10
9
  *
11
10
  * @returns The atom's value.
12
11
  **/
13
- const useAtomValue = (atom, getServerSnapshot) => (0, useStateful_1.useStatefulValue)(atom, getServerSnapshot);
12
+ const useAtomValue = (atom) => (0, use_stateful_1.useStatefulValue)(atom);
14
13
  exports.useAtomValue = useAtomValue;
15
14
  /** Set an atom's value in the React lifecycle.
16
15
  *
@@ -18,7 +17,7 @@ exports.useAtomValue = useAtomValue;
18
17
  *
19
18
  * @returns A setter function for the atom.
20
19
  **/
21
- const useSetAtom = (atom) => (0, useStateful_1.useSetStateful)(atom);
20
+ const useSetAtom = (atom) => (0, use_stateful_1.useSetStateful)(atom);
22
21
  exports.useSetAtom = useSetAtom;
23
22
  /** Use an atom's initialization state in the React lifecycle.
24
23
  *
@@ -39,12 +38,11 @@ exports.useAtomDidInit = useAtomDidInit;
39
38
  /** Use an atom's value and setter in the React lifecycle.
40
39
  *
41
40
  * @param atom Atom to be used.
42
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
43
41
  *
44
42
  * @returns [value, setValue, didInit]
45
43
  **/
46
- const useAtom = (atom, getServerSnapshot) => {
47
- const state = (0, exports.useAtomValue)(atom, getServerSnapshot);
44
+ const useAtom = (atom) => {
45
+ const state = (0, exports.useAtomValue)(atom);
48
46
  const setState = (0, exports.useSetAtom)(atom);
49
47
  const didInit = (0, exports.useAtomDidInit)(atom);
50
48
  return [state, setState, didInit];
@@ -3,7 +3,7 @@ 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, getServerSnapshot = () => stateful.get()) => (0, react_1.useSyncExternalStore)(set => stateful.subscribe(set), () => stateful.get(), getServerSnapshot);
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)) {
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { useAtom, useSetAtom, useAtomValue, useAtomDidInit } from "./useAtom";
1
+ export { useAtom, useSetAtom, useAtomValue, useAtomDidInit } from "./use-atom";
2
2
  export * from "@yaasl/core";
@@ -1,13 +1,12 @@
1
1
  import { useState, useEffect } from "react";
2
- import { useSetStateful, useStatefulValue } from "./useStateful";
2
+ import { useSetStateful, useStatefulValue } from "./use-stateful";
3
3
  /** Use an atom's value in the React lifecycle.
4
4
  *
5
5
  * @param atom Atom to be used.
6
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
7
6
  *
8
7
  * @returns The atom's value.
9
8
  **/
10
- export const useAtomValue = (atom, getServerSnapshot) => useStatefulValue(atom, getServerSnapshot);
9
+ export const useAtomValue = (atom) => useStatefulValue(atom);
11
10
  /** Set an atom's value in the React lifecycle.
12
11
  *
13
12
  * @param atom Atom to be used.
@@ -33,12 +32,11 @@ export const useAtomDidInit = (atom) => {
33
32
  /** Use an atom's value and setter in the React lifecycle.
34
33
  *
35
34
  * @param atom Atom to be used.
36
- * @param getServerSnapshot Function to retrieve a value that should be used for SSR.
37
35
  *
38
36
  * @returns [value, setValue, didInit]
39
37
  **/
40
- export const useAtom = (atom, getServerSnapshot) => {
41
- const state = useAtomValue(atom, getServerSnapshot);
38
+ export const useAtom = (atom) => {
39
+ const state = useAtomValue(atom);
42
40
  const setState = useSetAtom(atom);
43
41
  const didInit = useAtomDidInit(atom);
44
42
  return [state, setState, didInit];
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useSyncExternalStore } from "react";
2
2
  import { consoleMessage } from "@yaasl/utils";
3
- export const useStatefulValue = (stateful, getServerSnapshot = () => stateful.get()) => useSyncExternalStore(set => stateful.subscribe(set), () => stateful.get(), getServerSnapshot);
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"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaasl/react",
3
- "version": "0.11.0-alpha.3",
3
+ "version": "0.12.0",
4
4
  "description": "yet another atomic store library (react)",
5
5
  "author": "PrettyCoffee",
6
6
  "license": "MIT",
@@ -43,12 +43,12 @@
43
43
  "react": "^18.0.0 || ^19.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@yaasl/core": "0.11.0-alpha.3",
47
- "@yaasl/utils": "0.11.0-alpha.3"
46
+ "@yaasl/core": "0.12.0",
47
+ "@yaasl/utils": "0.11.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@testing-library/react": "^16.2.0",
51
- "@types/react": "^18.3.18",
50
+ "@testing-library/react": "^16.3.0",
51
+ "@types/react": "^18.3.23",
52
52
  "react-dom": "^18.3.1",
53
53
  "react": "^18.3.1"
54
54
  },