@yoltra/react 0.1.0 → 0.2.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/README.es.md +60 -55
- package/README.md +59 -57
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +483 -453
- package/dist/index.mjs.map +1 -1
- package/dist/types/createYoltra.d.ts +79 -0
- package/dist/types/hooks/createHooks.d.ts +27 -19
- package/dist/types/hooks/hooks.d.ts +1 -16
- package/dist/types/hooks/suspense.d.ts +24 -2
- package/dist/types/index.d.ts +3 -1
- package/dist/types/utils/shallowEqual.d.ts +19 -0
- package/dist/types/utils/useStableSnapshot.d.ts +4 -0
- package/package.json +4 -4
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoltra/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React bindings for Yoltra",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -p tsconfig.build.json && vite build",
|
|
7
7
|
"lint": "node ../../tools/repo-tools/bin/repo-eslint.cjs --report-unused-disable-directives --max-warnings 0",
|
|
8
8
|
"lint:fix": "node ../../tools/repo-tools/bin/repo-eslint.cjs --fix",
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "vitest --coverage --watch=false",
|
|
10
10
|
"test:watch": "vitest --coverage",
|
|
11
11
|
"prepublishOnly": "node ../../common/scripts/copy-license.cjs",
|
|
12
12
|
"docs": "rushx docs:js && rushx docs:md",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"node": ">=18.18"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@yoltra/core": "^0.
|
|
54
|
+
"@yoltra/core": "^0.2.0",
|
|
55
55
|
"react": "^18 || ^19",
|
|
56
56
|
"react-dom": "^18 || ^19"
|
|
57
57
|
},
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"tslib": "^2.8.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@yoltra/core": "workspace
|
|
67
|
+
"@yoltra/core": "workspace:*",
|
|
68
68
|
"@eslint/js": "^9.30.1",
|
|
69
69
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
70
70
|
"@rollup/plugin-node-resolve": "^15.2.3",
|