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 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<import("./types").modelStateType<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<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: import("./types").modelStateType<S, G, Actions>) => T) => T;
9
+ useContext: <T>(selector: (state: modelStateType<S, G, Actions>) => T) => T;
10
10
  };
@@ -39,7 +39,7 @@ export function storeMiddleware(options) {
39
39
  reset,
40
40
  setState: store.setState,
41
41
  subscribe: store.subscribe,
42
- ...options.actions(get, { reset, setState: store.setState }, store)
42
+ ...options.actions(store.setState, get, store)
43
43
  };
44
44
  };
45
45
  }
@@ -2,4 +2,4 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
  declare const meta: Meta;
3
3
  export default meta;
4
4
  type Story = StoryObj;
5
- export declare const Primary: Story;
5
+ export declare const Demo: Story;
@@ -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: get => ({
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 Primary = {
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> & OptionAction, actions: Omit<insideActionsType<S>, 'subscribe'>, store: StoreApi<S>) => OptionAction;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "define-zustand",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",