define-zustand 3.0.1 → 3.0.3

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/types.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { StoreApi as ZStoreApi } from 'zustand';
2
+ export type defGetterStateType<S> = Record<string, (state: S) => any>;
3
+ export type ExtraGetterState<S, G extends defGetterStateType<S>> = {
4
+ [key in keyof G]: ReturnType<G[key]>;
5
+ };
2
6
  export type StoreApi<S> = Omit<ZStoreApi<S>, 'setState'> & {
3
7
  setState: (updater: ((state: S) => void) | Partial<S>, replace?: boolean) => void;
4
8
  };
@@ -7,13 +11,9 @@ export interface insideActionsType<S> {
7
11
  setState: StoreApi<S>['setState'];
8
12
  subscribe: StoreApi<S>['subscribe'];
9
13
  }
10
- export type actionsType<S, OptionAction, InsideActions = unknown> = (getState: () => S, actions: Omit<insideActionsType<S>, 'subscribe'> & InsideActions, store: StoreApi<S>) => OptionAction;
11
- export type defGetterStateType<S> = Record<string, (state: S) => any>;
12
- export type ExtraGetterState<S, G extends defGetterStateType<S>> = {
13
- [key in keyof G]: ReturnType<G[key]>;
14
- };
15
- export interface optionsType<S, G, OptionAction> {
14
+ export type actionsType<S, G extends defGetterStateType<S>, OptionAction, InsideActions = unknown> = (getState: () => S & ExtraGetterState<S, G>, actions: Omit<insideActionsType<S>, 'subscribe'> & InsideActions, store: StoreApi<S>) => OptionAction;
15
+ export interface optionsType<S, G extends defGetterStateType<S>, OptionAction> {
16
16
  state: () => S;
17
17
  getter: G;
18
- actions: actionsType<S, OptionAction>;
18
+ actions: actionsType<S, G, OptionAction>;
19
19
  }
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useRef, useContext, createContext } from 'react';
2
- import { create, createStore, useStore } from 'zustand';
2
+ import { create, useStore, createStore } from 'zustand';
3
3
  import { produce } from 'immer';
4
4
  import { keys, isEqualWith, omit, some, pick, forEach, isEqual } from 'lodash-es';
5
5
  import { jsx } from 'react/jsx-runtime';
@@ -55,12 +55,12 @@ function defineStore(options) {
55
55
  }
56
56
  function defineContext(options) {
57
57
  const creatorResult = creator(options);
58
- const store = createStore()(creatorResult);
58
+ const $createStore = () => createStore()(creatorResult);
59
59
  const Context = /*#__PURE__*/createContext(null);
60
60
  const Provider = ({
61
61
  children
62
62
  }) => {
63
- const storeRef = useRef(store);
63
+ const storeRef = useRef($createStore());
64
64
  return /*#__PURE__*/jsx(Context.Provider, {
65
65
  value: storeRef.current,
66
66
  children: children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "define-zustand",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",