react-hook-core 0.4.5 → 0.4.7
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/lib/com.js +33 -11
- package/lib/core.js +103 -157
- package/lib/diff.js +28 -30
- package/lib/edit.js +54 -112
- package/lib/error.js +53 -0
- package/lib/formutil.js +58 -72
- package/lib/index.js +110 -95
- package/lib/input.js +31 -32
- package/lib/merge.js +26 -16
- package/lib/reflect.js +140 -147
- package/lib/route.js +45 -53
- package/lib/search.js +233 -475
- package/lib/state.js +159 -168
- package/lib/update.js +69 -64
- package/lib/useEdit.js +421 -348
- package/lib/useMessage.js +20 -20
- package/lib/useSearch.js +437 -246
- package/lib/useView.js +127 -120
- package/lib/util.js +74 -85
- package/package.json +1 -1
- package/src/com.ts +44 -30
- package/src/core.ts +147 -321
- package/src/diff.ts +54 -24
- package/src/edit.ts +42 -121
- package/src/error.ts +55 -0
- package/src/formutil.ts +51 -62
- package/src/index.ts +129 -114
- package/src/input.ts +44 -38
- package/src/merge.ts +16 -13
- package/src/reflect.ts +100 -101
- package/src/route.ts +40 -40
- package/src/search.ts +130 -316
- package/src/state.ts +135 -124
- package/src/update.ts +41 -41
- package/src/useEdit.ts +450 -319
- package/src/useMessage.ts +21 -21
- package/src/useSearch.ts +493 -277
- package/src/useView.ts +122 -97
- package/src/util.ts +67 -66
package/src/state.ts
CHANGED
|
@@ -1,194 +1,205 @@
|
|
|
1
|
-
import {Locale
|
|
2
|
-
import {setValue} from
|
|
3
|
-
import {valueOf} from
|
|
1
|
+
import { Locale } from "./core"
|
|
2
|
+
import { setValue } from "./reflect"
|
|
3
|
+
import { valueOf } from "./util"
|
|
4
4
|
|
|
5
5
|
export const enLocale = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
6
|
+
id: "en-US",
|
|
7
|
+
countryCode: "US",
|
|
8
|
+
dateFormat: "M/d/yyyy",
|
|
9
|
+
firstDayOfWeek: 1,
|
|
10
|
+
decimalSeparator: ".",
|
|
11
|
+
groupSeparator: ",",
|
|
12
|
+
decimalDigits: 2,
|
|
13
|
+
currencyCode: "USD",
|
|
14
|
+
currencySymbol: "$",
|
|
15
|
+
currencyPattern: 0,
|
|
16
|
+
}
|
|
17
17
|
export function localeOf(lc?: Locale, glc?: (() => Locale) | Locale): Locale {
|
|
18
|
-
let l: Locale|undefined = lc
|
|
18
|
+
let l: Locale | undefined = lc
|
|
19
19
|
if (!l) {
|
|
20
20
|
if (glc) {
|
|
21
|
-
if (typeof glc ===
|
|
22
|
-
l = glc()
|
|
21
|
+
if (typeof glc === "function") {
|
|
22
|
+
l = glc()
|
|
23
23
|
} else {
|
|
24
|
-
l = glc
|
|
24
|
+
l = glc
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
if (!l) {
|
|
28
|
-
l = enLocale
|
|
28
|
+
l = enLocale
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
return l
|
|
31
|
+
return l
|
|
32
32
|
}
|
|
33
33
|
export function handleEvent(e: any, removeErr?: (ctrl: HTMLInputElement) => void) {
|
|
34
|
-
const ctrl = e.currentTarget as HTMLInputElement
|
|
35
|
-
const type = ctrl.getAttribute(
|
|
36
|
-
const isPreventDefault = type && ([
|
|
34
|
+
const ctrl = e.currentTarget as HTMLInputElement
|
|
35
|
+
const type = ctrl.getAttribute("type")
|
|
36
|
+
const isPreventDefault = type && (["checkbox", "radio"].indexOf(type.toLowerCase()) >= 0 ? false : true)
|
|
37
37
|
if (isPreventDefault) {
|
|
38
|
-
e.preventDefault()
|
|
38
|
+
e.preventDefault()
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
41
|
-
removeErr
|
|
42
|
-
ctrl.nodeName === 'SELECT' &&
|
|
43
|
-
ctrl.value &&
|
|
44
|
-
ctrl.classList.contains('invalid')) {
|
|
45
|
-
removeErr(ctrl);
|
|
40
|
+
if (removeErr && ctrl.nodeName === "SELECT" && ctrl.value && ctrl.classList.contains("invalid")) {
|
|
41
|
+
removeErr(ctrl)
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
|
-
|
|
44
|
+
|
|
45
|
+
export interface ModelMap {
|
|
46
|
+
[key: string]: any
|
|
47
|
+
}
|
|
48
|
+
export interface ModelProps {
|
|
49
|
+
setGlobalState?: (m: ModelMap) => void
|
|
50
|
+
shouldBeCustomized?: boolean
|
|
51
|
+
}
|
|
52
|
+
export function handleProps<P extends ModelProps>(
|
|
53
|
+
e: any,
|
|
54
|
+
props: P,
|
|
55
|
+
ctrl: HTMLInputElement,
|
|
56
|
+
modelName: string,
|
|
57
|
+
tloc: Locale,
|
|
58
|
+
prepareData?: (data: any) => void,
|
|
59
|
+
) {
|
|
49
60
|
if (props.setGlobalState) {
|
|
50
|
-
const res = valueOf(ctrl, tloc, e.type)
|
|
61
|
+
const res = valueOf(ctrl, tloc, e.type)
|
|
51
62
|
if (res.mustChange) {
|
|
52
|
-
const dataField = ctrl.getAttribute(
|
|
53
|
-
const field =
|
|
54
|
-
const propsDataForm = (props as any)[modelName]
|
|
55
|
-
const form = ctrl.form
|
|
63
|
+
const dataField = ctrl.getAttribute("data-field")
|
|
64
|
+
const field = dataField ? dataField : ctrl.name
|
|
65
|
+
const propsDataForm = (props as any)[modelName]
|
|
66
|
+
const form = ctrl.form
|
|
56
67
|
if (form) {
|
|
57
|
-
const formName = form.name
|
|
58
|
-
if (field.indexOf(
|
|
59
|
-
const data = props.shouldBeCustomized && prepareData ? prepareData({ [ctrl.name]: res.value }) : { [ctrl.name]: res.value }
|
|
60
|
-
props.setGlobalState({ [formName]: { ...propsDataForm, ...data } })
|
|
68
|
+
const formName = form.name
|
|
69
|
+
if (field.indexOf(".") < 0 && field.indexOf("[") < 0) {
|
|
70
|
+
const data = props.shouldBeCustomized && prepareData ? prepareData({ [ctrl.name]: res.value }) : { [ctrl.name]: res.value }
|
|
71
|
+
props.setGlobalState({ [formName]: { ...propsDataForm, ...data } })
|
|
61
72
|
} else {
|
|
62
|
-
setValue(propsDataForm, field, ctrl.value)
|
|
63
|
-
props.setGlobalState({ [formName]: { ...propsDataForm } })
|
|
73
|
+
setValue(propsDataForm, field, ctrl.value)
|
|
74
|
+
props.setGlobalState({ [formName]: { ...propsDataForm } })
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
|
-
export function buildState<S, K extends keyof S>(e: any, state: Readonly<S>, ctrl: HTMLInputElement, modelName: string, tloc: Locale): K|undefined {
|
|
70
|
-
const form = ctrl.form
|
|
80
|
+
export function buildState<S, K extends keyof S>(e: any, state: Readonly<S>, ctrl: HTMLInputElement, modelName: string, tloc: Locale): K | undefined {
|
|
81
|
+
const form = ctrl.form
|
|
71
82
|
if (form) {
|
|
72
|
-
if (modelName && modelName !==
|
|
73
|
-
const type = ctrl.getAttribute(
|
|
74
|
-
const ex = (state as any)[modelName]
|
|
75
|
-
const dataField = ctrl.getAttribute(
|
|
76
|
-
const field =
|
|
77
|
-
const model = Object.assign({}, ex)
|
|
78
|
-
if (type && type.toLowerCase() ===
|
|
79
|
-
let value = model[field]
|
|
83
|
+
if (modelName && modelName !== "") {
|
|
84
|
+
const type = ctrl.getAttribute("type")
|
|
85
|
+
const ex = (state as any)[modelName]
|
|
86
|
+
const dataField = ctrl.getAttribute("data-field")
|
|
87
|
+
const field = dataField ? dataField : ctrl.name
|
|
88
|
+
const model = Object.assign({}, ex)
|
|
89
|
+
if (type && type.toLowerCase() === "checkbox") {
|
|
90
|
+
let value = model[field]
|
|
80
91
|
if (ctrl.id && ctrl.name !== ctrl.id) {
|
|
81
92
|
if (!value || !Array.isArray(value)) {
|
|
82
|
-
value = []
|
|
93
|
+
value = []
|
|
83
94
|
}
|
|
84
|
-
value.includes(ctrl.value) ? value = value.filter((v: string) => v !== ctrl.value) : value.push(ctrl.value)
|
|
95
|
+
value.includes(ctrl.value) ? (value = value.filter((v: string) => v !== ctrl.value)) : value.push(ctrl.value)
|
|
85
96
|
// if (dType == 'array'){
|
|
86
97
|
// if (value === 'string'){
|
|
87
98
|
// value = [value]
|
|
88
99
|
// }
|
|
89
100
|
// }
|
|
90
|
-
model[field] = value
|
|
101
|
+
model[field] = value
|
|
91
102
|
// console.log(model, modelName, model, model[field], field, value )
|
|
92
103
|
// setValue(model, field, value);
|
|
93
104
|
} else {
|
|
94
|
-
const v = valueOfCheckbox(ctrl)
|
|
95
|
-
model[field] = v
|
|
105
|
+
const v = valueOfCheckbox(ctrl)
|
|
106
|
+
model[field] = v
|
|
96
107
|
}
|
|
97
|
-
const objSet: any = {}
|
|
98
|
-
objSet[modelName] = model
|
|
99
|
-
return objSet
|
|
100
|
-
} else if (type && type.toLowerCase() ===
|
|
101
|
-
if (field.indexOf(
|
|
102
|
-
model[field] = ctrl.value
|
|
108
|
+
const objSet: any = {}
|
|
109
|
+
objSet[modelName] = model
|
|
110
|
+
return objSet
|
|
111
|
+
} else if (type && type.toLowerCase() === "radio") {
|
|
112
|
+
if (field.indexOf(".") < 0 && field.indexOf("[") < 0) {
|
|
113
|
+
model[field] = ctrl.value
|
|
103
114
|
} else {
|
|
104
|
-
setValue(model, field, ctrl.value)
|
|
115
|
+
setValue(model, field, ctrl.value)
|
|
105
116
|
}
|
|
106
|
-
const objSet: any = {}
|
|
107
|
-
objSet[modelName] = model
|
|
108
|
-
return objSet
|
|
109
|
-
} else if (type && (type.toLowerCase() ===
|
|
110
|
-
const objSet: any = {}
|
|
117
|
+
const objSet: any = {}
|
|
118
|
+
objSet[modelName] = model
|
|
119
|
+
return objSet
|
|
120
|
+
} else if (type && (type.toLowerCase() === "date" || type.toLowerCase() === "datetime-local")) {
|
|
121
|
+
const objSet: any = {}
|
|
111
122
|
try {
|
|
112
|
-
const selectedDate = new Date(ctrl.value)
|
|
113
|
-
setValue(model, field, ctrl.value && ctrl.value!==
|
|
114
|
-
objSet[modelName] = model
|
|
115
|
-
return objSet
|
|
123
|
+
const selectedDate = new Date(ctrl.value)
|
|
124
|
+
setValue(model, field, ctrl.value && ctrl.value !== "" ? selectedDate.toISOString() : null)
|
|
125
|
+
objSet[modelName] = model
|
|
126
|
+
return objSet
|
|
116
127
|
} catch (error) {
|
|
117
|
-
console.error(
|
|
128
|
+
console.error("Error occurred while formatting date:", error)
|
|
118
129
|
}
|
|
119
|
-
return objSet
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (ctrl.tagName ===
|
|
133
|
-
if (ctrl.value ===
|
|
134
|
-
ctrl.removeAttribute(
|
|
130
|
+
return objSet
|
|
131
|
+
} else if (type && type.toLowerCase() === "time") {
|
|
132
|
+
const objSet: any = {}
|
|
133
|
+
try {
|
|
134
|
+
const selectedDate = new Date(ctrl.value)
|
|
135
|
+
setValue(model, field, selectedDate.getTime())
|
|
136
|
+
objSet[modelName] = model
|
|
137
|
+
return objSet
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("Error occurred while formatting time:", error)
|
|
140
|
+
}
|
|
141
|
+
return objSet
|
|
142
|
+
} else {
|
|
143
|
+
if (ctrl.tagName === "SELECT") {
|
|
144
|
+
if (ctrl.value === "" || !ctrl.value) {
|
|
145
|
+
ctrl.removeAttribute("data-value")
|
|
135
146
|
} else {
|
|
136
|
-
ctrl.setAttribute(
|
|
147
|
+
ctrl.setAttribute("data-value", "data-value")
|
|
137
148
|
}
|
|
138
149
|
}
|
|
139
|
-
const data = valueOf(ctrl, tloc, e.type)
|
|
150
|
+
const data = valueOf(ctrl, tloc, e.type)
|
|
140
151
|
if (data.mustChange) {
|
|
141
|
-
if (field.indexOf(
|
|
142
|
-
model[field] = data.value
|
|
152
|
+
if (field.indexOf(".") < 0 && field.indexOf("[") < 0) {
|
|
153
|
+
model[field] = data.value
|
|
143
154
|
} else {
|
|
144
|
-
setValue(model, field, data.value)
|
|
155
|
+
setValue(model, field, data.value)
|
|
145
156
|
}
|
|
146
|
-
const objSet: any = {}
|
|
147
|
-
objSet[modelName] = model
|
|
148
|
-
return objSet
|
|
157
|
+
const objSet: any = {}
|
|
158
|
+
objSet[modelName] = model
|
|
159
|
+
return objSet
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
} else {
|
|
152
|
-
return buildFlatState(e, state, tloc)
|
|
163
|
+
return buildFlatState(e, state, tloc)
|
|
153
164
|
}
|
|
154
165
|
} else {
|
|
155
|
-
buildFlatState(e, state, tloc)
|
|
166
|
+
buildFlatState(e, state, tloc)
|
|
156
167
|
}
|
|
157
168
|
}
|
|
158
|
-
export function valueOfCheckbox(ctrl: HTMLInputElement): string|number|boolean {
|
|
159
|
-
const ctrlOnValue = ctrl.getAttribute(
|
|
160
|
-
const ctrlOffValue = ctrl.getAttribute(
|
|
169
|
+
export function valueOfCheckbox(ctrl: HTMLInputElement): string | number | boolean {
|
|
170
|
+
const ctrlOnValue = ctrl.getAttribute("data-on-value")
|
|
171
|
+
const ctrlOffValue = ctrl.getAttribute("data-off-value")
|
|
161
172
|
if (ctrlOnValue && ctrlOffValue) {
|
|
162
|
-
const onValue = ctrlOnValue ? ctrlOnValue : true
|
|
163
|
-
const offValue = ctrlOffValue ? ctrlOffValue : false
|
|
164
|
-
return ctrl.checked === true ? onValue : offValue
|
|
173
|
+
const onValue = ctrlOnValue ? ctrlOnValue : true
|
|
174
|
+
const offValue = ctrlOffValue ? ctrlOffValue : false
|
|
175
|
+
return ctrl.checked === true ? onValue : offValue
|
|
165
176
|
} else {
|
|
166
|
-
return ctrl.checked === true
|
|
177
|
+
return ctrl.checked === true
|
|
167
178
|
}
|
|
168
179
|
}
|
|
169
|
-
export function buildFlatState<S, K extends keyof S>(e: any, state: Readonly<S>, l?: Locale): K|undefined {
|
|
170
|
-
const ctrl = e.currentTarget as HTMLInputElement
|
|
171
|
-
const stateName = ctrl.name
|
|
172
|
-
const objSet: any = {}
|
|
173
|
-
const type = ctrl.getAttribute(
|
|
174
|
-
if (type && type.toLowerCase() ===
|
|
180
|
+
export function buildFlatState<S, K extends keyof S>(e: any, state: Readonly<S>, l?: Locale): K | undefined {
|
|
181
|
+
const ctrl = e.currentTarget as HTMLInputElement
|
|
182
|
+
const stateName = ctrl.name
|
|
183
|
+
const objSet: any = {}
|
|
184
|
+
const type = ctrl.getAttribute("type")
|
|
185
|
+
if (type && type.toLowerCase() === "checkbox") {
|
|
175
186
|
if (ctrl.id && stateName === ctrl.id) {
|
|
176
|
-
const v = valueOfCheckbox(ctrl)
|
|
177
|
-
objSet[stateName] = v
|
|
178
|
-
return objSet
|
|
187
|
+
const v = valueOfCheckbox(ctrl)
|
|
188
|
+
objSet[stateName] = v
|
|
189
|
+
return objSet
|
|
179
190
|
} else {
|
|
180
|
-
let value = (state as any)[stateName]
|
|
181
|
-
value.includes(ctrl.value) ? value = value.filter((v: string) => v !== ctrl.value) : value.push(ctrl.value)
|
|
182
|
-
const objSet2: any = {[ctrl.name]: value}
|
|
183
|
-
return objSet2
|
|
191
|
+
let value = (state as any)[stateName]
|
|
192
|
+
value.includes(ctrl.value) ? (value = value.filter((v: string) => v !== ctrl.value)) : value.push(ctrl.value)
|
|
193
|
+
const objSet2: any = { [ctrl.name]: value }
|
|
194
|
+
return objSet2
|
|
184
195
|
}
|
|
185
196
|
} else {
|
|
186
|
-
const data = valueOf(ctrl, l, e.type)
|
|
197
|
+
const data = valueOf(ctrl, l, e.type)
|
|
187
198
|
if (data.mustChange) {
|
|
188
|
-
objSet[stateName] = data.value
|
|
189
|
-
return objSet
|
|
199
|
+
objSet[stateName] = data.value
|
|
200
|
+
return objSet
|
|
190
201
|
} else {
|
|
191
|
-
return undefined
|
|
202
|
+
return undefined
|
|
192
203
|
}
|
|
193
204
|
}
|
|
194
205
|
}
|
package/src/update.ts
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { useEffect, useState } from "react"
|
|
2
|
+
import { getModelName as getModelName2, Locale, removePhoneFormat } from "./core"
|
|
3
|
+
import { useMergeState } from "./merge"
|
|
4
|
+
import { buildFlatState, buildState, handleEvent, localeOf } from "./state"
|
|
5
5
|
|
|
6
|
-
const m = "model"
|
|
6
|
+
const m = "model"
|
|
7
7
|
const _getModelName = (f2?: HTMLFormElement | null): string => {
|
|
8
|
-
return getModelName2(f2, m)
|
|
9
|
-
}
|
|
8
|
+
return getModelName2(f2, m)
|
|
9
|
+
}
|
|
10
10
|
export const useUpdate = <T>(
|
|
11
11
|
initialState: T,
|
|
12
12
|
getName?: ((f?: HTMLFormElement | null) => string) | string,
|
|
13
13
|
getLocale?: (() => Locale) | Locale,
|
|
14
|
-
removeErr?: (ctrl: HTMLInputElement) => void
|
|
14
|
+
removeErr?: (ctrl: HTMLInputElement) => void,
|
|
15
15
|
) => {
|
|
16
|
-
const [state, setState] = useMergeState<T>(initialState)
|
|
17
|
-
const [rerender, setRerender] = useState(false)
|
|
16
|
+
const [state, setState] = useMergeState<T>(initialState)
|
|
17
|
+
const [rerender, setRerender] = useState(false)
|
|
18
18
|
|
|
19
19
|
// trigger re-render page when change state in useSearch
|
|
20
20
|
useEffect(() => {
|
|
21
|
-
setRerender(!rerender)
|
|
22
|
-
}, [state])
|
|
21
|
+
setRerender(!rerender)
|
|
22
|
+
}, [state])
|
|
23
23
|
|
|
24
24
|
const updatePhoneState = (event: any) => {
|
|
25
|
-
const re = /^[0-9\b]
|
|
26
|
-
const target = event.currentTarget as HTMLInputElement
|
|
27
|
-
const value = removePhoneFormat(target.value)
|
|
25
|
+
const re = /^[0-9\b]+$/
|
|
26
|
+
const target = event.currentTarget as HTMLInputElement
|
|
27
|
+
const value = removePhoneFormat(target.value)
|
|
28
28
|
if (re.test(value) || !value) {
|
|
29
|
-
updateState(event)
|
|
29
|
+
updateState(event)
|
|
30
30
|
} else {
|
|
31
|
-
const splitArr = value.split("")
|
|
32
|
-
let responseStr = ""
|
|
31
|
+
const splitArr = value.split("")
|
|
32
|
+
let responseStr = ""
|
|
33
33
|
splitArr.forEach((element) => {
|
|
34
34
|
if (re.test(element)) {
|
|
35
|
-
responseStr += element
|
|
35
|
+
responseStr += element
|
|
36
36
|
}
|
|
37
|
-
})
|
|
38
|
-
target.value = responseStr
|
|
39
|
-
updateState(event)
|
|
37
|
+
})
|
|
38
|
+
target.value = responseStr
|
|
39
|
+
updateState(event)
|
|
40
40
|
}
|
|
41
|
-
}
|
|
42
|
-
const getModelName: (f2?: HTMLFormElement | null) => string = typeof getName === "function" ? getName : _getModelName
|
|
41
|
+
}
|
|
42
|
+
const getModelName: (f2?: HTMLFormElement | null) => string = typeof getName === "function" ? getName : _getModelName
|
|
43
43
|
|
|
44
44
|
const updateState = (e: any, callback?: (prev: any) => void, lc?: Locale) => {
|
|
45
|
-
const ctrl = e.currentTarget as HTMLInputElement
|
|
46
|
-
let mn: string = m
|
|
45
|
+
const ctrl = e.currentTarget as HTMLInputElement
|
|
46
|
+
let mn: string = m
|
|
47
47
|
if (getName) {
|
|
48
48
|
if (typeof getName === "string") {
|
|
49
|
-
mn = getName
|
|
49
|
+
mn = getName
|
|
50
50
|
} else {
|
|
51
|
-
mn = getName(ctrl.form)
|
|
51
|
+
mn = getName(ctrl.form)
|
|
52
52
|
}
|
|
53
53
|
} else {
|
|
54
|
-
mn = _getModelName(ctrl.form)
|
|
54
|
+
mn = _getModelName(ctrl.form)
|
|
55
55
|
}
|
|
56
|
-
const l = localeOf(lc, getLocale)
|
|
57
|
-
handleEvent(e, removeErr)
|
|
58
|
-
const objSet = buildState<T, any>(e, state, ctrl, mn, l)
|
|
56
|
+
const l = localeOf(lc, getLocale)
|
|
57
|
+
handleEvent(e, removeErr)
|
|
58
|
+
const objSet = buildState<T, any>(e, state, ctrl, mn, l)
|
|
59
59
|
if (objSet) {
|
|
60
60
|
if (callback) {
|
|
61
|
-
setState({ ...objSet }, callback)
|
|
61
|
+
setState({ ...objSet }, callback)
|
|
62
62
|
} else {
|
|
63
|
-
setState(objSet)
|
|
63
|
+
setState(objSet)
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
67
|
const updateFlatState = (e: any, callback?: () => void, lc?: Locale) => {
|
|
68
|
-
const objSet = buildFlatState<T, any>(e, state, lc)
|
|
68
|
+
const objSet = buildFlatState<T, any>(e, state, lc)
|
|
69
69
|
if (objSet) {
|
|
70
70
|
if (callback) {
|
|
71
|
-
setState(objSet, callback)
|
|
71
|
+
setState(objSet, callback)
|
|
72
72
|
} else {
|
|
73
|
-
setState(objSet)
|
|
73
|
+
setState(objSet)
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
return {
|
|
78
78
|
getModelName,
|
|
79
79
|
updateState,
|
|
@@ -82,5 +82,5 @@ export const useUpdate = <T>(
|
|
|
82
82
|
getLocale,
|
|
83
83
|
setState,
|
|
84
84
|
state,
|
|
85
|
-
}
|
|
86
|
-
}
|
|
85
|
+
}
|
|
86
|
+
}
|