create-packer 1.19.2 → 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,32 +1,38 @@
|
|
|
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,
|
|
12
15
|
actions: insideActionsType<S> & InsideActions,
|
|
13
16
|
store: StoreApi<S>
|
|
14
17
|
) => OptionAction
|
|
18
|
+
|
|
19
|
+
export type defGetterStateType<S> = Record<string, (state: S) => any>
|
|
15
20
|
export interface optionsType<S, G, OptionAction> {
|
|
16
21
|
state: () => S
|
|
17
22
|
getter: () => G
|
|
18
23
|
actions: actionsType<S, OptionAction>
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
type GenGetterStateType<S, G extends
|
|
26
|
+
type GenGetterStateType<S, G extends defGetterStateType<S>> = G extends Record<
|
|
22
27
|
infer K,
|
|
23
28
|
(state: S) => infer V
|
|
24
29
|
>
|
|
25
30
|
? Record<K, V>
|
|
26
31
|
: unknown
|
|
32
|
+
|
|
27
33
|
export function define<
|
|
28
34
|
S extends Record<string, any>,
|
|
29
|
-
G extends
|
|
35
|
+
G extends defGetterStateType<S>,
|
|
30
36
|
OptionActions extends Record<string, any>
|
|
31
37
|
>(options: optionsType<S, G, OptionActions>) {
|
|
32
38
|
function createDefState() {
|
|
@@ -58,21 +64,23 @@ export function define<
|
|
|
58
64
|
})
|
|
59
65
|
// actions
|
|
60
66
|
// ----------------------------------------------------------------------
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}) as any
|
|
66
|
-
)
|
|
67
|
+
store.setState = (updater, replace) => {
|
|
68
|
+
const nextState = typeof updater === 'function' ? produce(updater as any) : updater
|
|
69
|
+
|
|
70
|
+
return set(nextState as any, replace)
|
|
67
71
|
}
|
|
68
72
|
const reset: insideActionsType<S>['reset'] = () => {
|
|
69
73
|
set(() => options.state() as never)
|
|
70
74
|
}
|
|
71
75
|
return {
|
|
72
76
|
reset,
|
|
73
|
-
setState,
|
|
77
|
+
setState: store.setState as StoreApi<S>['setState'],
|
|
74
78
|
subscribe: store.subscribe,
|
|
75
|
-
...options.actions(
|
|
79
|
+
...options.actions(
|
|
80
|
+
get,
|
|
81
|
+
{ reset, setState: store.setState as StoreApi<S>['setState'] },
|
|
82
|
+
store as StoreApi<S>
|
|
83
|
+
)
|
|
76
84
|
}
|
|
77
85
|
})
|
|
78
86
|
)
|
|
@@ -1,32 +1,38 @@
|
|
|
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,
|
|
12
15
|
actions: insideActionsType<S> & InsideActions,
|
|
13
16
|
store: StoreApi<S>
|
|
14
17
|
) => OptionAction
|
|
18
|
+
|
|
19
|
+
export type defGetterStateType<S> = Record<string, (state: S) => any>
|
|
15
20
|
export interface optionsType<S, G, OptionAction> {
|
|
16
21
|
state: () => S
|
|
17
22
|
getter: () => G
|
|
18
23
|
actions: actionsType<S, OptionAction>
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
type GenGetterStateType<S, G extends
|
|
26
|
+
type GenGetterStateType<S, G extends defGetterStateType<S>> = G extends Record<
|
|
22
27
|
infer K,
|
|
23
28
|
(state: S) => infer V
|
|
24
29
|
>
|
|
25
30
|
? Record<K, V>
|
|
26
31
|
: unknown
|
|
32
|
+
|
|
27
33
|
export function define<
|
|
28
34
|
S extends Record<string, any>,
|
|
29
|
-
G extends
|
|
35
|
+
G extends defGetterStateType<S>,
|
|
30
36
|
OptionActions extends Record<string, any>
|
|
31
37
|
>(options: optionsType<S, G, OptionActions>) {
|
|
32
38
|
function createDefState() {
|
|
@@ -58,21 +64,23 @@ export function define<
|
|
|
58
64
|
})
|
|
59
65
|
// actions
|
|
60
66
|
// ----------------------------------------------------------------------
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}) as any
|
|
66
|
-
)
|
|
67
|
+
store.setState = (updater, replace) => {
|
|
68
|
+
const nextState = typeof updater === 'function' ? produce(updater as any) : updater
|
|
69
|
+
|
|
70
|
+
return set(nextState as any, replace)
|
|
67
71
|
}
|
|
68
72
|
const reset: insideActionsType<S>['reset'] = () => {
|
|
69
73
|
set(() => options.state() as never)
|
|
70
74
|
}
|
|
71
75
|
return {
|
|
72
76
|
reset,
|
|
73
|
-
setState,
|
|
77
|
+
setState: store.setState as StoreApi<S>['setState'],
|
|
74
78
|
subscribe: store.subscribe,
|
|
75
|
-
...options.actions(
|
|
79
|
+
...options.actions(
|
|
80
|
+
get,
|
|
81
|
+
{ reset, setState: store.setState as StoreApi<S>['setState'] },
|
|
82
|
+
store as StoreApi<S>
|
|
83
|
+
)
|
|
76
84
|
}
|
|
77
85
|
})
|
|
78
86
|
)
|