create-packer 1.24.10 → 1.24.13
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 +1 -1
- package/template/web-app/react/domain/app/app.model.ts +3 -3
- package/template/web-app/react/package.json +2 -1
- package/template/web-app/react/providers/index.ts +0 -1
- package/template/workspace/pnpm/package.json +1 -1
- package/template/web-app/react/providers/modelUtils.ts +0 -83
package/package.json
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"axios": "1.3.6",
|
|
21
|
+
"define-zustand": "1.0.1",
|
|
21
22
|
"immer": "10.0.1",
|
|
22
23
|
"lodash-es": "4.17.21",
|
|
23
24
|
"qs": "6.11.2",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"react-dom": "18.2.0",
|
|
26
27
|
"react-router-dom": "6.14.0",
|
|
27
28
|
"react-use": "17.4.0",
|
|
28
|
-
"zustand": "4.
|
|
29
|
+
"zustand": "4.4.1"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@commitlint/cli": "17.6.1",
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { create, StoreApi as ZStoreApi } from 'zustand'
|
|
2
|
-
import { combine } from 'zustand/middleware'
|
|
3
|
-
import { produce } from 'immer'
|
|
4
|
-
import { forEach, isEqual, size } from 'lodash-es'
|
|
5
|
-
|
|
6
|
-
export type StoreApi<S> = Omit<ZStoreApi<S>, 'setState'> & {
|
|
7
|
-
setState: (updater: ((state: S) => void) | Partial<S>, replace?: boolean) => void
|
|
8
|
-
}
|
|
9
|
-
export interface insideActionsType<S> {
|
|
10
|
-
reset: () => void
|
|
11
|
-
setState: StoreApi<S>['setState']
|
|
12
|
-
}
|
|
13
|
-
export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
14
|
-
getState: () => S,
|
|
15
|
-
actions: insideActionsType<S> & InsideActions,
|
|
16
|
-
store: StoreApi<S>
|
|
17
|
-
) => OptionAction
|
|
18
|
-
|
|
19
|
-
export type defGetterStateType<S> = Record<string, (state: S) => any>
|
|
20
|
-
export interface optionsType<S, G, OptionAction> {
|
|
21
|
-
state: () => S
|
|
22
|
-
getter: G
|
|
23
|
-
actions: actionsType<S, OptionAction>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type ExtraGetterStateType<S, G extends defGetterStateType<S>> = {
|
|
27
|
-
[key in keyof G]: ReturnType<G[key]>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function define<
|
|
31
|
-
S extends Record<string, any>,
|
|
32
|
-
G extends defGetterStateType<S>,
|
|
33
|
-
OptionActions extends Record<string, any>
|
|
34
|
-
>(options: optionsType<S, G, OptionActions>) {
|
|
35
|
-
function createDefState() {
|
|
36
|
-
const state: any = options.state()
|
|
37
|
-
forEach(options.getter, (getter, k) => {
|
|
38
|
-
state[k] = getter(state)
|
|
39
|
-
})
|
|
40
|
-
return state as S & ExtraGetterStateType<S, G>
|
|
41
|
-
}
|
|
42
|
-
return create(
|
|
43
|
-
combine(createDefState(), (set, get, store) => {
|
|
44
|
-
// getterListener
|
|
45
|
-
// ----------------------------------------------------------------------
|
|
46
|
-
store.subscribe((state, prevState) => {
|
|
47
|
-
let equalledLen = 0
|
|
48
|
-
const newGetterState: any = {}
|
|
49
|
-
forEach(options.getter, (getter, k) => {
|
|
50
|
-
const value = getter(state)
|
|
51
|
-
if (isEqual(value, prevState[k])) {
|
|
52
|
-
equalledLen += 1
|
|
53
|
-
} else {
|
|
54
|
-
newGetterState[k] = getter(state)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
if (size(options.getter) > equalledLen) {
|
|
58
|
-
set(newGetterState)
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
// actions
|
|
62
|
-
// ----------------------------------------------------------------------
|
|
63
|
-
store.setState = (updater, replace) => {
|
|
64
|
-
const nextState = typeof updater === 'function' ? produce(updater as any) : updater
|
|
65
|
-
|
|
66
|
-
return set(nextState as any, replace)
|
|
67
|
-
}
|
|
68
|
-
const reset: insideActionsType<S>['reset'] = () => {
|
|
69
|
-
set(() => options.state() as never)
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
reset,
|
|
73
|
-
setState: store.setState as StoreApi<S>['setState'],
|
|
74
|
-
subscribe: store.subscribe,
|
|
75
|
-
...options.actions(
|
|
76
|
-
get,
|
|
77
|
-
{ reset, setState: store.setState as StoreApi<S>['setState'] },
|
|
78
|
-
store as StoreApi<S>
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
)
|
|
83
|
-
}
|