define-zustand 2.0.0 → 2.0.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/README.md +0 -46
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface optionsType<S, G, OptionAction> {
|
|
|
16
16
|
getter: G;
|
|
17
17
|
actions: actionsType<S, OptionAction>;
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export default function defineZustand<S extends Record<string, any>, G extends defGetterStateType<S>, OptionActions extends Record<string, any>>(options: optionsType<S, G, OptionActions>): import("zustand").UseBoundStore<ZStoreApi<Omit<S & ExtraGetterState<S, G>, "reset" | "setState" | "subscribe" | keyof OptionActions> & {
|
|
20
20
|
reset: () => void;
|
|
21
21
|
setState: (updater: Partial<S> | ((state: S) => void), replace?: boolean) => void;
|
|
22
22
|
subscribe: (listener: (state: S & ExtraGetterState<S, G>, prevState: S & ExtraGetterState<S, G>) => void) => () => void;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { combine } from 'zustand/middleware';
|
|
|
3
3
|
import { produce } from 'immer';
|
|
4
4
|
import { keys, isEqualWith, omit, some, pick, forEach, isEqual } from 'lodash-es';
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function defineZustand(options) {
|
|
7
7
|
function createDefState() {
|
|
8
8
|
const state = options.state();
|
|
9
9
|
forEach(options.getter, (getter, k) => {
|
|
@@ -49,4 +49,4 @@ function define(options) {
|
|
|
49
49
|
}));
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export {
|
|
52
|
+
export { defineZustand as default };
|
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# define-zustand
|
|
2
|
-
> Quickly define [zustand](https://github.com/pmndrs/zustand) state
|
|
3
|
-
|
|
4
|
-
## Install
|
|
5
|
-
```shell
|
|
6
|
-
pnpm i define-zustand
|
|
7
|
-
npm i define-zustand
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
## Use
|
|
11
|
-
```tsx
|
|
12
|
-
import defineStore from 'define-zustand'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @return zustand hooks
|
|
16
|
-
*/
|
|
17
|
-
const useStore = defineStore({
|
|
18
|
-
state: () => ({
|
|
19
|
-
a: 1,
|
|
20
|
-
b: 1
|
|
21
|
-
}),
|
|
22
|
-
action: () => ({}),
|
|
23
|
-
getter: {
|
|
24
|
-
count: state => state.a + state.b
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
function ReactComponent() {
|
|
28
|
-
const { count, setState, reset } = useStore(state => ({
|
|
29
|
-
count: state.count,
|
|
30
|
-
setState: state.setState,
|
|
31
|
-
reset: state.reset
|
|
32
|
-
}))
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
return () => {
|
|
36
|
-
reset()
|
|
37
|
-
}
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
return <div>
|
|
41
|
-
<button onClick={() => setState({ a: 2 })}>setA</button>
|
|
42
|
-
<button onClick={() => setState(state => {state.b += 1})}>setB</button>
|
|
43
|
-
<div>{count}</div>
|
|
44
|
-
</div>
|
|
45
|
-
}
|
|
46
|
-
```
|