@yoltra/react 0.1.0 → 0.3.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.
@@ -53,22 +53,7 @@ export declare function useStore<EM extends EventMapBase, R extends string, S ex
53
53
  * @public
54
54
  */
55
55
  export declare function useEmit<EM extends EventMapBase>(): Emit<EM>;
56
- /**
57
- * Shallow object equality using `Object.is` per-key.
58
- *
59
- * Useful as the `isEqual` argument for `useAtomicProp` and `useAtomicProps`
60
- * when the derived value is a plain object. Also available from the object
61
- * returned by {@link createHooks}.
62
- *
63
- * @example
64
- * ```ts
65
- * shallowEqual({ a: 1 }, { a: 1 }); // true
66
- * shallowEqual({ a: 1 }, { a: 2 }); // false
67
- * ```
68
- *
69
- * @public
70
- */
71
- export declare function shallowEqual<T extends Record<string, any>>(a: T, b: T): boolean;
56
+ export { shallowEqual } from '../utils/shallowEqual';
72
57
  /**
73
58
  * Selects a derived value from the store using an external-store subscription.
74
59
  * Re-renders when the selected value changes per `isEqual`.
@@ -28,7 +28,12 @@ export declare const suspenseCache: SuspenseCache;
28
28
  export interface SuspenseAtomicPropOptions<T, S> {
29
29
  /** Async loader that receives the value at the path and the full slice. */
30
30
  load: (valueAtPath: any, slice: S[keyof S]) => Promise<T> | T;
31
- /** Time in ms before the cached value is considered stale (default: 0). */
31
+ /**
32
+ * Extra wall-clock TTL (ms) for a resolved value. `0` (the default) or omitted
33
+ * means the cached value is served until the subscribed path changes or you
34
+ * invalidate it explicitly; a positive value additionally expires it after that
35
+ * many ms. Cached errors ignore this and are re-thrown until invalidated.
36
+ */
32
37
  staleTime?: number;
33
38
  /** Optional extra key to differentiate cache entries for the same path. */
34
39
  key?: string;
@@ -40,6 +45,12 @@ export interface SuspenseAtomicPropOptions<T, S> {
40
45
  * resolved value. While the promise is pending, React Suspense catches it and
41
46
  * renders the nearest `<Suspense>` fallback.
42
47
  *
48
+ * @remarks
49
+ * **Client-only loading.** During server rendering this hook does not suspend
50
+ * (throwing a promise would crash `renderToString`): `getServerSnapshot` returns
51
+ * the current value at the path **without** invoking `options.load`. Perform the
52
+ * actual load on the client.
53
+ *
43
54
  * @typeParam R - Reducer name union.
44
55
  * @typeParam S - State record keyed by `R`.
45
56
  * @typeParam P - Dotted path within `S[R]`.
@@ -89,7 +100,12 @@ export declare function useSuspenseAtomicProp<R extends string, S extends Record
89
100
  export interface SuspenseAtomicPropsOptions<T, S> {
90
101
  /** Async loader that receives the full store state. */
91
102
  load: (state: S) => Promise<T> | T;
92
- /** Time in ms before the cached value is considered stale (default: 0). */
103
+ /**
104
+ * Extra wall-clock TTL (ms) for a resolved value. `0` (the default) or omitted
105
+ * means the cached value is served until the subscribed path changes or you
106
+ * invalidate it explicitly; a positive value additionally expires it after that
107
+ * many ms. Cached errors ignore this and are re-thrown until invalidated.
108
+ */
93
109
  staleTime?: number;
94
110
  /** Optional extra key to differentiate cache entries. */
95
111
  key?: string;
@@ -101,6 +117,12 @@ export interface SuspenseAtomicPropsOptions<T, S> {
101
117
  * to produce the resolved value. While the promise is pending, React Suspense
102
118
  * renders the nearest `<Suspense>` fallback.
103
119
  *
120
+ * @remarks
121
+ * **Client-only loading.** During server rendering this hook does not suspend
122
+ * (throwing a promise would crash `renderToString`): `getServerSnapshot` uses a
123
+ * synchronous `options.load` result if one is available, otherwise `undefined`.
124
+ * Perform the actual load on the client.
125
+ *
104
126
  * @typeParam R - Reducer name union.
105
127
  * @typeParam S - State record keyed by `R`.
106
128
  * @typeParam T - Resolved value type.
@@ -6,6 +6,8 @@ export { StoreProvider } from './context/StoreProvider';
6
6
  export { shallowEqual, useAtomicProp, useAtomicProps, useEmit, useEvent, useSelector, useStore, } from './hooks/hooks';
7
7
  export { clearSuspenseCache, invalidateAtomicProp, invalidateAtomicPropsByReducer, suspenseCache, useSuspenseAtomicProp, useSuspenseAtomicProps, } from './hooks/suspense';
8
8
  export { createHooks } from './hooks/createHooks';
9
- export type { UseAtomicProp, UseAtomicProps, UseEvent } from './hooks/createHooks';
9
+ export type { UseAtomicProp, UseAtomicProps, UseEvent, YoltraHooks } from './hooks/createHooks';
10
+ export { createYoltra } from './createYoltra';
11
+ export type { Yoltra } from './createYoltra';
10
12
  export type { OneOrMany, PathValue } from './hooks/hooks';
11
13
  export type { SuspenseAtomicPropOptions, SuspenseAtomicPropsOptions } from './hooks/suspense';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module @yoltra/react
3
+ */
4
+ /**
5
+ * Shallow object equality using `Object.is` per-key.
6
+ *
7
+ * Useful as the `isEqual` argument for `useAtomicProp` and `useAtomicProps`
8
+ * when the derived value is a plain object. Also available from the object
9
+ * returned by {@link createHooks} and {@link createYoltra}.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * shallowEqual({ a: 1 }, { a: 1 }); // true
14
+ * shallowEqual({ a: 1 }, { a: 2 }); // false
15
+ * ```
16
+ *
17
+ * @public
18
+ */
19
+ export declare function shallowEqual<T extends Record<string, unknown>>(a: T, b: T): boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @module @yoltra/react
3
+ */
4
+ export {};
package/package.json CHANGED
@@ -1,18 +1,7 @@
1
1
  {
2
2
  "name": "@yoltra/react",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "React bindings for Yoltra",
5
- "scripts": {
6
- "build": "tsc -p tsconfig.build.json && vite build",
7
- "lint": "node ../../tools/repo-tools/bin/repo-eslint.cjs --report-unused-disable-directives --max-warnings 0",
8
- "lint:fix": "node ../../tools/repo-tools/bin/repo-eslint.cjs --fix",
9
- "test": "pnpm vitest --coverage --watch=false",
10
- "test:watch": "vitest --coverage",
11
- "prepublishOnly": "node ../../common/scripts/copy-license.cjs",
12
- "docs": "rushx docs:js && rushx docs:md",
13
- "docs:md": "pnpm typedoc --options ./typedoc.react.json",
14
- "docs:js": "pnpm typedoc --options ./typedoc.react.json --json ./.typedoc/react-en.json"
15
- },
16
5
  "license": "MIT",
17
6
  "author": {
18
7
  "name": "Manu Ramirez <@pixerael>",
@@ -51,7 +40,7 @@
51
40
  "node": ">=18.18"
52
41
  },
53
42
  "peerDependencies": {
54
- "@yoltra/core": "^0.1.0",
43
+ "@yoltra/core": "^0.3.0",
55
44
  "react": "^18 || ^19",
56
45
  "react-dom": "^18 || ^19"
57
46
  },
@@ -64,7 +53,6 @@
64
53
  "tslib": "^2.8.1"
65
54
  },
66
55
  "devDependencies": {
67
- "@yoltra/core": "workspace:^0.1.0",
68
56
  "@eslint/js": "^9.30.1",
69
57
  "@rollup/plugin-commonjs": "^25.0.7",
70
58
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -95,7 +83,8 @@
95
83
  "vite-plugin-dts": "^4.5.4",
96
84
  "vite-tsconfig-paths": "^4.3.2",
97
85
  "vite": "^7.1.11",
98
- "vitest": "3.2.4"
86
+ "vitest": "3.2.4",
87
+ "@yoltra/core": "0.3.0"
99
88
  },
100
89
  "exports": {
101
90
  ".": {
@@ -106,5 +95,15 @@
106
95
  "default": "./dist/index.mjs"
107
96
  },
108
97
  "./package.json": "./package.json"
98
+ },
99
+ "scripts": {
100
+ "build": "tsc -p tsconfig.build.json && vite build",
101
+ "lint": "node ../../tools/repo-tools/bin/repo-eslint.cjs --report-unused-disable-directives --max-warnings 0",
102
+ "lint:fix": "node ../../tools/repo-tools/bin/repo-eslint.cjs --fix",
103
+ "test": "vitest --coverage --watch=false",
104
+ "test:watch": "vitest --coverage",
105
+ "docs": "rushx docs:js && rushx docs:md",
106
+ "docs:md": "pnpm typedoc --options ./typedoc.react.json",
107
+ "docs:js": "pnpm typedoc --options ./typedoc.react.json --json ./.typedoc/react-en.json"
109
108
  }
110
- }
109
+ }