create-packer 1.19.3 → 1.19.4
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
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { create, StoreApi } from 'zustand'
|
|
1
|
+
import { create, StoreApi as ZStoreApi } from 'zustand'
|
|
2
2
|
import { combine } from 'zustand/middleware'
|
|
3
3
|
import { produce } from 'immer'
|
|
4
4
|
import { forEach, size } from 'lodash-es'
|
|
5
5
|
|
|
6
|
+
export type StoreApi<S> = Omit<ZStoreApi<S>, 'setState'> & {
|
|
7
|
+
setState: (updater: ((state: S) => void) | Partial<S>, replace?: boolean) => void
|
|
8
|
+
}
|
|
6
9
|
export interface insideActionsType<S> {
|
|
7
10
|
reset: () => void
|
|
8
|
-
setState:
|
|
11
|
+
setState: StoreApi<S>['setState']
|
|
9
12
|
}
|
|
10
13
|
export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
11
14
|
getState: () => S,
|
|
@@ -26,6 +29,7 @@ type GenGetterStateType<S, G extends defGetterStateType<S>> = G extends Record<
|
|
|
26
29
|
>
|
|
27
30
|
? Record<K, V>
|
|
28
31
|
: unknown
|
|
32
|
+
|
|
29
33
|
export function define<
|
|
30
34
|
S extends Record<string, any>,
|
|
31
35
|
G extends defGetterStateType<S>,
|
|
@@ -60,21 +64,23 @@ export function define<
|
|
|
60
64
|
})
|
|
61
65
|
// actions
|
|
62
66
|
// ----------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}) as any
|
|
68
|
-
)
|
|
67
|
+
store.setState = (updater, replace) => {
|
|
68
|
+
const nextState = typeof updater === 'function' ? produce(updater as any) : updater
|
|
69
|
+
|
|
70
|
+
return set(nextState as any, replace)
|
|
69
71
|
}
|
|
70
72
|
const reset: insideActionsType<S>['reset'] = () => {
|
|
71
73
|
set(() => options.state() as never)
|
|
72
74
|
}
|
|
73
75
|
return {
|
|
74
76
|
reset,
|
|
75
|
-
setState,
|
|
77
|
+
setState: store.setState as StoreApi<S>['setState'],
|
|
76
78
|
subscribe: store.subscribe,
|
|
77
|
-
...options.actions(
|
|
79
|
+
...options.actions(
|
|
80
|
+
get,
|
|
81
|
+
{ reset, setState: store.setState as StoreApi<S>['setState'] },
|
|
82
|
+
store as StoreApi<S>
|
|
83
|
+
)
|
|
78
84
|
}
|
|
79
85
|
})
|
|
80
86
|
)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { create, StoreApi } from 'zustand'
|
|
1
|
+
import { create, StoreApi as ZStoreApi } from 'zustand'
|
|
2
2
|
import { combine } from 'zustand/middleware'
|
|
3
3
|
import { produce } from 'immer'
|
|
4
4
|
import { forEach, size } from 'lodash-es'
|
|
5
5
|
|
|
6
|
+
export type StoreApi<S> = Omit<ZStoreApi<S>, 'setState'> & {
|
|
7
|
+
setState: (updater: ((state: S) => void) | Partial<S>, replace?: boolean) => void
|
|
8
|
+
}
|
|
6
9
|
export interface insideActionsType<S> {
|
|
7
10
|
reset: () => void
|
|
8
|
-
setState:
|
|
11
|
+
setState: StoreApi<S>['setState']
|
|
9
12
|
}
|
|
10
13
|
export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
11
14
|
getState: () => S,
|
|
@@ -26,6 +29,7 @@ type GenGetterStateType<S, G extends defGetterStateType<S>> = G extends Record<
|
|
|
26
29
|
>
|
|
27
30
|
? Record<K, V>
|
|
28
31
|
: unknown
|
|
32
|
+
|
|
29
33
|
export function define<
|
|
30
34
|
S extends Record<string, any>,
|
|
31
35
|
G extends defGetterStateType<S>,
|
|
@@ -60,21 +64,23 @@ export function define<
|
|
|
60
64
|
})
|
|
61
65
|
// actions
|
|
62
66
|
// ----------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}) as any
|
|
68
|
-
)
|
|
67
|
+
store.setState = (updater, replace) => {
|
|
68
|
+
const nextState = typeof updater === 'function' ? produce(updater as any) : updater
|
|
69
|
+
|
|
70
|
+
return set(nextState as any, replace)
|
|
69
71
|
}
|
|
70
72
|
const reset: insideActionsType<S>['reset'] = () => {
|
|
71
73
|
set(() => options.state() as never)
|
|
72
74
|
}
|
|
73
75
|
return {
|
|
74
76
|
reset,
|
|
75
|
-
setState,
|
|
77
|
+
setState: store.setState as StoreApi<S>['setState'],
|
|
76
78
|
subscribe: store.subscribe,
|
|
77
|
-
...options.actions(
|
|
79
|
+
...options.actions(
|
|
80
|
+
get,
|
|
81
|
+
{ reset, setState: store.setState as StoreApi<S>['setState'] },
|
|
82
|
+
store as StoreApi<S>
|
|
83
|
+
)
|
|
78
84
|
}
|
|
79
85
|
})
|
|
80
86
|
)
|