define-zustand 3.1.0 → 3.1.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.
Files changed (2) hide show
  1. package/README.md +79 -66
  2. package/package.json +8 -9
package/README.md CHANGED
@@ -1,66 +1,79 @@
1
- # define-zustand
2
-
3
- > Quickly define [zustand](https://github.com/pmndrs/zustand) state
4
-
5
- ## Install
6
-
7
- ```shell
8
- pnpm i define-zustand
9
- npm i define-zustand
10
- ```
11
-
12
- ## Use
13
-
14
- ```tsx
15
- import { defineStore, defineContext, defineStateFactory } from 'define-zustand'
16
-
17
- const stateFatory = defineStateFactory({
18
- state: () => ({
19
- a: 1,
20
- b: 1
21
- }),
22
- action: () => ({}),
23
- getter: {
24
- count: state => state.a + state.b
25
- }
26
- })
27
- /**
28
- * @return zustand hooks
29
- */
30
- const useStore = defineStore(stateFatory())
31
- const { Provider, useContext } = defineContext(stateFatory())
32
-
33
- function Child() {
34
- const count = useContext(state => state.count)
35
- return <div>{count}</div>
36
- }
37
- function ReactComponent() {
38
- const count = useStore(state => state.count)
39
- const setState = useStore(state => state.setState)
40
- const reset = useStore(state => state.reset)
41
-
42
- useEffect(() => {
43
- return () => {
44
- reset()
45
- }
46
- }, [])
47
-
48
- return (
49
- <Provider>
50
- <div>
51
- <button onClick={() => setState({ a: 2 })}>setA</button>
52
- <button
53
- onClick={() =>
54
- setState(state => {
55
- state.b += 1
56
- })
57
- }>
58
- setB
59
- </button>
60
- <div>{count}</div>
61
- </div>
62
- <Child />
63
- </Provider>
64
- )
65
- }
66
- ```
1
+ # define-zustand
2
+
3
+ > Quickly define [zustand](https://github.com/pmndrs/zustand) state
4
+
5
+ ## Install
6
+
7
+ ```shell
8
+ pnpm i define-zustand
9
+ npm i define-zustand
10
+ ```
11
+
12
+ ## Use
13
+
14
+ ```tsx
15
+ import { defineStore, defineContext, defineStateFactory } from 'define-zustand'
16
+
17
+ /**
18
+ * @return zustand hooks
19
+ */
20
+ const useStore = defineStore({
21
+ state: () => ({
22
+ a: 1,
23
+ b: 1
24
+ }),
25
+ action: () => ({}),
26
+ getter: {
27
+ count: state => state.a + state.b
28
+ }
29
+ })
30
+
31
+ // Use defineModelFactory
32
+ const stateFactory = defineStateFactory({
33
+ state: () => ({
34
+ a: 1,
35
+ b: 1
36
+ }),
37
+ action: () => ({}),
38
+ getter: {
39
+ count: state => state.a + state.b
40
+ }
41
+ })
42
+ const useStore = defineStore(stateFactory())
43
+ const { Provider, useContext } = defineContext(stateFactory())
44
+
45
+ function Child() {
46
+ const count = useContext(state => state.count)
47
+ return <div>{count}</div>
48
+ }
49
+ function ReactComponent() {
50
+ const count = useStore(state => state.count)
51
+ const setState = useStore(state => state.setState)
52
+ const reset = useStore(state => state.reset)
53
+
54
+ useEffect(() => {
55
+ return () => {
56
+ reset()
57
+ }
58
+ }, [])
59
+
60
+ return (
61
+ <Provider>
62
+ <div>
63
+ <button onClick={() => setState({ a: 2 })}>setA</button>
64
+ <button
65
+ onClick={() =>
66
+ setState(state => {
67
+ state.b += 1
68
+ })
69
+ }
70
+ >
71
+ setB
72
+ </button>
73
+ <div>{count}</div>
74
+ </div>
75
+ <Child />
76
+ </Provider>
77
+ )
78
+ }
79
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "define-zustand",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,6 @@
9
9
  ],
10
10
  "license": "ISC",
11
11
  "devDependencies": {
12
- "1k-tasks": "^3.6.0",
13
12
  "@types/jest": "^29.5.2",
14
13
  "@types/lodash-es": "^4.17.8",
15
14
  "@typescript-eslint/eslint-plugin": "5.60.1",
@@ -20,21 +19,21 @@
20
19
  "eslint-plugin-prettier": "4.2.1",
21
20
  "jest": "^29.5.0",
22
21
  "prettier": "2.8.8",
23
- "react": "~18.2.0",
22
+ "react": "~18.3.1",
24
23
  "stylelint": "15.9.0",
25
24
  "stylelint-config-standard": "33.0.0",
26
25
  "ts-jest": "29.0.5",
27
26
  "typescript": "5.1.3",
28
- "zustand": "^4.4.1"
27
+ "zustand": "4.4.1"
29
28
  },
30
29
  "dependencies": {
31
- "@types/react": "~18.2.28",
32
- "immer": "^10.0.2",
33
- "lodash-es": "^4.17.21"
30
+ "@types/react": "18.3.3",
31
+ "immer": "10.0.2",
32
+ "lodash-es": "4.17.21"
34
33
  },
35
34
  "peerDependencies": {
36
- "react": "~18.2.0",
37
- "zustand": "^4.4.1"
35
+ "react": "~18.3.1",
36
+ "zustand": "~4.4.1"
38
37
  },
39
38
  "scripts": {
40
39
  "build": "node scripts/build.js",