create-packer 1.24.7 → 1.24.8
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
|
@@ -19,16 +19,13 @@ export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
|
19
19
|
export type defGetterStateType<S> = Record<string, (state: S) => any>
|
|
20
20
|
export interface optionsType<S, G, OptionAction> {
|
|
21
21
|
state: () => S
|
|
22
|
-
getter:
|
|
22
|
+
getter: G
|
|
23
23
|
actions: actionsType<S, OptionAction>
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
? Record<K, V>
|
|
31
|
-
: unknown
|
|
26
|
+
type ExtraGetterStateType<S, G extends defGetterStateType<S>> = {
|
|
27
|
+
[key in keyof G]: ReturnType<G[key]>
|
|
28
|
+
}
|
|
32
29
|
|
|
33
30
|
export function define<
|
|
34
31
|
S extends Record<string, any>,
|
|
@@ -37,10 +34,10 @@ export function define<
|
|
|
37
34
|
>(options: optionsType<S, G, OptionActions>) {
|
|
38
35
|
function createDefState() {
|
|
39
36
|
const state: any = options.state()
|
|
40
|
-
forEach(options.getter
|
|
37
|
+
forEach(options.getter, (getter, k) => {
|
|
41
38
|
state[k] = getter(state)
|
|
42
39
|
})
|
|
43
|
-
return state as S &
|
|
40
|
+
return state as S & ExtraGetterStateType<S, G>
|
|
44
41
|
}
|
|
45
42
|
return create(
|
|
46
43
|
combine(createDefState(), (set, get, store) => {
|
|
@@ -49,7 +46,7 @@ export function define<
|
|
|
49
46
|
store.subscribe((state, prevState) => {
|
|
50
47
|
let equalledLen = 0
|
|
51
48
|
const newGetterState: any = {}
|
|
52
|
-
forEach(options.getter
|
|
49
|
+
forEach(options.getter, (getter, k) => {
|
|
53
50
|
const value = getter(state)
|
|
54
51
|
if (isEqual(value, prevState[k])) {
|
|
55
52
|
equalledLen += 1
|
|
@@ -57,7 +54,7 @@ export function define<
|
|
|
57
54
|
newGetterState[k] = getter(state)
|
|
58
55
|
}
|
|
59
56
|
})
|
|
60
|
-
if (size(options.getter
|
|
57
|
+
if (size(options.getter) > equalledLen) {
|
|
61
58
|
set(newGetterState)
|
|
62
59
|
}
|
|
63
60
|
})
|
|
@@ -19,16 +19,13 @@ export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
|
19
19
|
export type defGetterStateType<S> = Record<string, (state: S) => any>
|
|
20
20
|
export interface optionsType<S, G, OptionAction> {
|
|
21
21
|
state: () => S
|
|
22
|
-
getter:
|
|
22
|
+
getter: G
|
|
23
23
|
actions: actionsType<S, OptionAction>
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
? Record<K, V>
|
|
31
|
-
: unknown
|
|
26
|
+
type ExtraGetterStateType<S, G extends defGetterStateType<S>> = {
|
|
27
|
+
[key in keyof G]: ReturnType<G[key]>
|
|
28
|
+
}
|
|
32
29
|
|
|
33
30
|
export function define<
|
|
34
31
|
S extends Record<string, any>,
|
|
@@ -37,10 +34,10 @@ export function define<
|
|
|
37
34
|
>(options: optionsType<S, G, OptionActions>) {
|
|
38
35
|
function createDefState() {
|
|
39
36
|
const state: any = options.state()
|
|
40
|
-
forEach(options.getter
|
|
37
|
+
forEach(options.getter, (getter, k) => {
|
|
41
38
|
state[k] = getter(state)
|
|
42
39
|
})
|
|
43
|
-
return state as S &
|
|
40
|
+
return state as S & ExtraGetterStateType<S, G>
|
|
44
41
|
}
|
|
45
42
|
return create(
|
|
46
43
|
combine(createDefState(), (set, get, store) => {
|
|
@@ -49,7 +46,7 @@ export function define<
|
|
|
49
46
|
store.subscribe((state, prevState) => {
|
|
50
47
|
let equalledLen = 0
|
|
51
48
|
const newGetterState: any = {}
|
|
52
|
-
forEach(options.getter
|
|
49
|
+
forEach(options.getter, (getter, k) => {
|
|
53
50
|
const value = getter(state)
|
|
54
51
|
if (isEqual(value, prevState[k])) {
|
|
55
52
|
equalledLen += 1
|
|
@@ -57,7 +54,7 @@ export function define<
|
|
|
57
54
|
newGetterState[k] = getter(state)
|
|
58
55
|
}
|
|
59
56
|
})
|
|
60
|
-
if (size(options.getter
|
|
57
|
+
if (size(options.getter) > equalledLen) {
|
|
61
58
|
set(newGetterState)
|
|
62
59
|
}
|
|
63
60
|
})
|