define-zustand 3.3.0 → 3.4.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/dist/define.d.ts +3 -3
- package/dist/store-middleware.js +1 -1
- package/dist/test.stories.d.ts +1 -1
- package/dist/test.stories.js +5 -8
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/define.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FunctionComponent, ReactNode } from 'react';
|
|
2
|
-
import { gettersStateType, optionsType } from './types';
|
|
2
|
+
import { gettersStateType, modelStateType, optionsType } from './types';
|
|
3
3
|
export declare function defineStateFactory<S extends Record<string, any>, G extends gettersStateType<S>, Actions extends Record<string, any>>(options: optionsType<S, G, Actions>): () => optionsType<S, G, Actions>;
|
|
4
|
-
export declare function defineStore<S extends Record<string, any>, G extends gettersStateType<S>, Actions extends Record<string, any>>(options: optionsType<S, G, Actions>): import("zustand").UseBoundStore<import("zustand").StoreApi<
|
|
4
|
+
export declare function defineStore<S extends Record<string, any>, G extends gettersStateType<S>, Actions extends Record<string, any>>(options: optionsType<S, G, Actions>): import("zustand").UseBoundStore<import("zustand").StoreApi<modelStateType<S, G, Actions>>>;
|
|
5
5
|
export declare function defineContext<S extends Record<string, any>, G extends gettersStateType<S>, Actions extends Record<string, any>>(options: optionsType<S, G, Actions>): {
|
|
6
6
|
Provider: FunctionComponent<{
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
}>;
|
|
9
|
-
useContext: <T>(selector: (state:
|
|
9
|
+
useContext: <T>(selector: (state: modelStateType<S, G, Actions>) => T) => T;
|
|
10
10
|
};
|
package/dist/store-middleware.js
CHANGED
package/dist/test.stories.d.ts
CHANGED
package/dist/test.stories.js
CHANGED
|
@@ -15,23 +15,20 @@ const useStore = defineStore({
|
|
|
15
15
|
a: state => state.count + 1,
|
|
16
16
|
b: state => state.count2 + 2
|
|
17
17
|
},
|
|
18
|
-
actions:
|
|
19
|
-
test: () =>
|
|
20
|
-
console.log('1', 1);
|
|
21
|
-
},
|
|
22
|
-
t: () => {
|
|
23
|
-
get();
|
|
24
|
-
}
|
|
18
|
+
actions: (setState, getState, store) => ({
|
|
19
|
+
test: () => getState()
|
|
25
20
|
})
|
|
26
21
|
});
|
|
27
22
|
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
|
|
28
|
-
export const
|
|
23
|
+
export const Demo = {
|
|
29
24
|
render: () => {
|
|
30
25
|
const a = useStore(state => state.a);
|
|
31
26
|
const b = useStore(state => state.b);
|
|
32
27
|
const setState = useStore(state => state.setState);
|
|
28
|
+
const test = useStore(state => state.test);
|
|
33
29
|
console.log('a', a);
|
|
34
30
|
console.log('b', b);
|
|
31
|
+
console.log('test', test());
|
|
35
32
|
return (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => {
|
|
36
33
|
setState(state => {
|
|
37
34
|
state.count += 1;
|
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface insideActionsType<S> {
|
|
|
13
13
|
setState: StoreApi<S>['setState'];
|
|
14
14
|
subscribe: StoreApi<S>['subscribe'];
|
|
15
15
|
}
|
|
16
|
-
export type actionsType<S, G extends gettersStateType<any>, OptionAction> = (getState: () => stateType<S, G> &
|
|
16
|
+
export type actionsType<S, G extends gettersStateType<any>, OptionAction> = (setState: insideActionsType<S>['setState'], getState: () => stateType<S, G> & insideActionsType<S>, store: StoreApi<S>) => OptionAction;
|
|
17
17
|
export interface optionsType<S, G extends gettersStateType<any>, Actions> {
|
|
18
18
|
state: () => S;
|
|
19
19
|
getters: G;
|