create-packer 1.17.13 → 1.17.14
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/package.json
CHANGED
|
@@ -2,20 +2,20 @@ import { create } from 'zustand'
|
|
|
2
2
|
import { produce } from 'immer'
|
|
3
3
|
|
|
4
4
|
export type setStateType<S> = (updater: (state: S) => void) => void
|
|
5
|
-
export interface modelActionsType {
|
|
5
|
+
export interface modelActionsType<S extends Record<string, any>> {
|
|
6
6
|
reset: () => void
|
|
7
|
+
setState: setStateType<S>
|
|
7
8
|
}
|
|
8
9
|
export interface modelOptionsType<S extends Record<string, any>, A extends Record<string, any>> {
|
|
9
10
|
state: () => S
|
|
10
|
-
actions: (
|
|
11
|
+
actions: (getState: () => S, actions: modelActionsType<S>) => A
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export function defineModel<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const _setState: setStateType<S> = updater => {
|
|
14
|
+
export function defineModel<S extends Record<string, any>, A extends Record<string, any>>(
|
|
15
|
+
options: modelOptionsType<S, A>
|
|
16
|
+
) {
|
|
17
|
+
return create<{ state: S; actions: modelActionsType<S> & A }>()((setState, getState, store) => {
|
|
18
|
+
const _setState: modelActionsType<S>['setState'] = updater => {
|
|
19
19
|
setState(
|
|
20
20
|
produce((store: { state: S }) => {
|
|
21
21
|
updater(store.state)
|
|
@@ -23,7 +23,7 @@ export function defineModel<
|
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
25
|
const _getState = () => getState().state
|
|
26
|
-
const reset: modelActionsType['reset'] = () => {
|
|
26
|
+
const reset: modelActionsType<S>['reset'] = () => {
|
|
27
27
|
setState({ state: options.state() })
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
@@ -32,7 +32,10 @@ export function defineModel<
|
|
|
32
32
|
reset,
|
|
33
33
|
setState: _setState,
|
|
34
34
|
subscribe: store.subscribe,
|
|
35
|
-
...options.actions(
|
|
35
|
+
...options.actions(_getState, {
|
|
36
|
+
reset,
|
|
37
|
+
setState: _setState
|
|
38
|
+
})
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
})
|