@t8/react-store 1.0.32 → 1.0.34
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/index.d.ts +2 -0
- package/dist/src/useStore.d.ts +25 -0
- package/index.ts +1 -1
- package/package.json +7 -5
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +7 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Store } from "@t8/store";
|
|
2
|
+
export type SetStoreState<T> = Store<T>["setState"];
|
|
3
|
+
export type ShouldUpdateCallback<T> = (nextState: T, prevState: T) => boolean;
|
|
4
|
+
export type ShouldUpdate<T> = boolean | ShouldUpdateCallback<T>;
|
|
5
|
+
export declare function useStore<T>(store: Store<T>,
|
|
6
|
+
/**
|
|
7
|
+
* Controls whether the component should be updated in response
|
|
8
|
+
* to the store updates.
|
|
9
|
+
*
|
|
10
|
+
* @defaultValue `true`
|
|
11
|
+
*
|
|
12
|
+
* `shouldUpdate` can be set to `false` to prevent subscription
|
|
13
|
+
* to the store updates. Use case: when the component only requires
|
|
14
|
+
* the store state setter but not the store state value, the
|
|
15
|
+
* component may not need to respond to the store updates:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* let [, setValue] = useStore(store, false);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* `shouldUpdate` can be set to a function `(nextState, prevState) => boolean`
|
|
22
|
+
* to make the component respond only to specific store state changes,
|
|
23
|
+
* when this function returns `true`.
|
|
24
|
+
*/
|
|
25
|
+
shouldUpdate?: ShouldUpdate<T>): [T, SetStoreState<T>];
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "@t8/store";
|
|
2
|
-
export * from "./src/useStore";
|
|
2
|
+
export * from "./src/useStore.ts";
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t8/react-store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "Concise shared state management for React apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
|
-
"build": "npx npm-run-all clean compile",
|
|
9
|
+
"build": "npx npm-run-all clean compile types",
|
|
9
10
|
"clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
|
|
10
11
|
"compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral --external:react",
|
|
11
12
|
"demo": "npx @t8/serve 3000 * tests/counter -b src/index.tsx",
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
"shape": "npx codeshape",
|
|
15
16
|
"test": "npx playwright test --project=chromium",
|
|
16
17
|
"tic-tac-toe": "npx @t8/serve 3000 * tests/tic-tac-toe -b src/index.tsx",
|
|
17
|
-
"typecheck": "tsc --noEmit"
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"types": "tsc -p tsconfig.build.json"
|
|
18
20
|
},
|
|
19
21
|
"repository": {
|
|
20
22
|
"type": "git",
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@playwright/test": "^1.56.0",
|
|
38
|
-
"@t8/serve": "^0.1.
|
|
40
|
+
"@t8/serve": "^0.1.34",
|
|
39
41
|
"@types/node": "^24.5.2",
|
|
40
42
|
"@types/react": "^19.1.10",
|
|
41
43
|
"@types/react-dom": "^19.1.9",
|
|
@@ -44,6 +46,6 @@
|
|
|
44
46
|
"typescript": "^5.9.3"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
|
-
"@t8/store": "^1.1.
|
|
49
|
+
"@t8/store": "^1.1.8"
|
|
48
50
|
}
|
|
49
51
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"include": ["index.ts", "playwright.config.ts", "src", "tests"],
|
|
2
|
+
"include": ["./index.ts", "./playwright.config.ts", "./src", "./tests"],
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
4
6
|
"jsx": "react-jsx",
|
|
5
7
|
"lib": ["ESNext", "DOM"],
|
|
6
|
-
"target": "
|
|
8
|
+
"target": "esnext",
|
|
7
9
|
"outDir": "dist",
|
|
8
|
-
"
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"moduleResolution": "nodenext",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
9
13
|
"strict": true,
|
|
10
14
|
"noUnusedLocals": true,
|
|
11
15
|
"noUnusedParameters": true
|