@@ -77,30 +77,42 @@ const { create: actualCreate, createStore: actualCreateStore } =
77
77
// a variable to hold reset functions for all stores declared in the app
78
78
export const storeResetFns = new Set <() => void >()
79
79
80
+ const createUncurried = <T >(stateCreator : zustand .StateCreator <T >) => {
81
+ const store = actualCreate (stateCreator )
82
+ const initialState = store .getState ()
83
+ storeResetFns .add (() => {
84
+ store .setState (initialState , true )
85
+ })
86
+ return store
87
+ }
88
+
80
89
// when creating a store, we get its initial state, create a reset function and add it in the set
81
90
export const create = (<T >() => {
82
91
console .log (' zustand create mock' )
83
92
84
- return (stateCreator : zustand .StateCreator <T >) => {
85
- const store = actualCreate (stateCreator )
86
- const initialState = store .getState ()
87
- storeResetFns .add (() => {
88
- store .setState (initialState , true )
89
- })
90
- return store
91
- }
93
+ // to support curried version of create
94
+ return typeof stateCreator === ' function'
95
+ ? createUncurried (stateCreator )
96
+ : createUncurried
92
97
}) as typeof zustand .create
93
98
94
- // when creating a store, we get its initial state, create a reset function and add it in the set
95
- export const createStore = (<T >(stateCreator : zustand .StateCreator <T >) => {
96
- console .log (' zustand createStore mock' )
97
-
99
+ const createStoreUncurried = <T >(stateCreator : zustand .StateCreator <T >) => {
98
100
const store = actualCreateStore (stateCreator )
99
101
const initialState = store .getState ()
100
102
storeResetFns .add (() => {
101
103
store .setState (initialState , true )
102
104
})
103
105
return store
106
+ }
107
+
108
+ // when creating a store, we get its initial state, create a reset function and add it in the set
109
+ export const createStore = (<T >(stateCreator : zustand .StateCreator <T >) => {
110
+ console .log (' zustand createStore mock' )
111
+
112
+ // to support curried version of createStore
113
+ return typeof stateCreator === ' function'
114
+ ? createStoreUncurried (stateCreator )
115
+ : createStoreUncurried
104
116
}) as typeof zustand .createStore
105
117
106
118
// reset all stores after each test run
@@ -154,30 +166,42 @@ const { create: actualCreate, createStore: actualCreateStore } =
154
166
// a variable to hold reset functions for all stores declared in the app
155
167
export const storeResetFns = new Set <() => void >()
156
168
169
+ const createUncurried = <T >(stateCreator : zustand .StateCreator <T >) => {
170
+ const store = actualCreate (stateCreator )
171
+ const initialState = store .getState ()
172
+ storeResetFns .add (() => {
173
+ store .setState (initialState , true )
174
+ })
175
+ return store
176
+ }
177
+
157
178
// when creating a store, we get its initial state, create a reset function and add it in the set
158
179
export const create = (<T >() => {
159
180
console .log (' zustand create mock' )
160
181
161
- return (stateCreator : zustand .StateCreator <T >) => {
162
- const store = actualCreate (stateCreator )
163
- const initialState = store .getState ()
164
- storeResetFns .add (() => {
165
- store .setState (initialState , true )
166
- })
167
- return store
168
- }
182
+ // to support curried version of create
183
+ return typeof stateCreator === ' function'
184
+ ? createUncurried (stateCreator )
185
+ : createUncurried
169
186
}) as typeof zustand .create
170
187
171
- // when creating a store, we get its initial state, create a reset function and add it in the set
172
- export const createStore = (<T >(stateCreator : zustand .StateCreator <T >) => {
173
- console .log (' zustand createStore mock' )
174
-
188
+ const createStoreUncurried = <T >(stateCreator : zustand .StateCreator <T >) => {
175
189
const store = actualCreateStore (stateCreator )
176
190
const initialState = store .getState ()
177
191
storeResetFns .add (() => {
178
192
store .setState (initialState , true )
179
193
})
180
194
return store
195
+ }
196
+
197
+ // when creating a store, we get its initial state, create a reset function and add it in the set
198
+ export const createStore = (<T >(stateCreator : zustand .StateCreator <T >) => {
199
+ console .log (' zustand createStore mock' )
200
+
201
+ // to support curried version of createStore
202
+ return typeof stateCreator === ' function'
203
+ ? createStoreUncurried (stateCreator )
204
+ : createStoreUncurried
181
205
}) as typeof zustand .createStore
182
206
183
207
// reset all stores after each test run
0 commit comments