react-hook-core 0.4.8 → 0.4.10
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/common.js +30 -0
- package/lib/core.js +0 -118
- package/lib/formutil.js +0 -28
- package/lib/index.js +25 -0
- package/lib/input.js +57 -0
- package/lib/reflect.js +38 -48
- package/lib/route.js +11 -0
- package/lib/search.js +11 -28
- package/lib/update.js +56 -4
- package/lib/useEdit.js +38 -41
- package/lib/useSearch.js +44 -11
- package/lib/util.js +3 -3
- package/package.json +1 -1
- package/src/common.ts +28 -0
- package/src/core.ts +14 -134
- package/src/formutil.ts +0 -27
- package/src/index.ts +26 -0
- package/src/input.ts +55 -15
- package/src/reflect.ts +38 -56
- package/src/route.ts +19 -0
- package/src/search.ts +12 -33
- package/src/update.ts +56 -4
- package/src/useEdit.ts +28 -44
- package/src/useSearch.ts +43 -19
- package/src/util.ts +3 -3
- package/lib/error.js +0 -53
- package/lib/merge.js +0 -28
- package/src/error.ts +0 -55
- package/src/merge.ts +0 -26
package/lib/error.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
function getString(key, gv) {
|
|
4
|
-
if (typeof gv === "function") {
|
|
5
|
-
return gv(key)
|
|
6
|
-
} else {
|
|
7
|
-
return gv[key]
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.getString = getString
|
|
11
|
-
function message(gv, msg, title, yes, no) {
|
|
12
|
-
var m2 = msg && msg.length > 0 ? getString(msg, gv) : ""
|
|
13
|
-
var m = { message: m2, title: "" }
|
|
14
|
-
if (title && title.length > 0) {
|
|
15
|
-
m.title = getString(title, gv)
|
|
16
|
-
}
|
|
17
|
-
if (yes && yes.length > 0) {
|
|
18
|
-
m.yes = getString(yes, gv)
|
|
19
|
-
}
|
|
20
|
-
if (no && no.length > 0) {
|
|
21
|
-
m.no = getString(no, gv)
|
|
22
|
-
}
|
|
23
|
-
return m
|
|
24
|
-
}
|
|
25
|
-
exports.message = message
|
|
26
|
-
function messageByHttpStatus(status, gv) {
|
|
27
|
-
var k = "error_" + status
|
|
28
|
-
var msg = getString(k, gv)
|
|
29
|
-
if (!msg || msg.length === 0) {
|
|
30
|
-
msg = getString("error_500", gv)
|
|
31
|
-
}
|
|
32
|
-
return msg
|
|
33
|
-
}
|
|
34
|
-
exports.messageByHttpStatus = messageByHttpStatus
|
|
35
|
-
function error(err, gv, ae) {
|
|
36
|
-
var title = getString("error", gv)
|
|
37
|
-
var msg = getString("error_internal", gv)
|
|
38
|
-
if (!err) {
|
|
39
|
-
ae(msg, undefined, title)
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
var data = err && err.response ? err.response : err
|
|
43
|
-
if (data) {
|
|
44
|
-
var status_1 = data.status
|
|
45
|
-
if (status_1 && !isNaN(status_1)) {
|
|
46
|
-
msg = messageByHttpStatus(status_1, gv)
|
|
47
|
-
}
|
|
48
|
-
ae(msg, undefined, title)
|
|
49
|
-
} else {
|
|
50
|
-
ae(msg, undefined, title)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.error = error
|
package/lib/merge.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
var react_1 = require("react")
|
|
4
|
-
function useMergeState(initialState) {
|
|
5
|
-
var _a = react_1.useState(initialState ? initialState : {}),
|
|
6
|
-
state = _a[0],
|
|
7
|
-
_setState = _a[1]
|
|
8
|
-
var callbackRef = react_1.useRef()
|
|
9
|
-
var setState = react_1.useCallback(
|
|
10
|
-
function (newState, callback) {
|
|
11
|
-
callbackRef.current = callback
|
|
12
|
-
_setState(function (prevState) {
|
|
13
|
-
return Object.assign({}, prevState, newState)
|
|
14
|
-
})
|
|
15
|
-
},
|
|
16
|
-
[state],
|
|
17
|
-
)
|
|
18
|
-
react_1.useEffect(
|
|
19
|
-
function () {
|
|
20
|
-
if (callbackRef.current) {
|
|
21
|
-
callbackRef.current(state)
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
[state],
|
|
25
|
-
)
|
|
26
|
-
return [state, setState]
|
|
27
|
-
}
|
|
28
|
-
exports.useMergeState = useMergeState
|
package/src/error.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { StringMap } from "./core"
|
|
2
|
-
|
|
3
|
-
export interface Message {
|
|
4
|
-
message: string
|
|
5
|
-
title: string
|
|
6
|
-
yes?: string
|
|
7
|
-
no?: string
|
|
8
|
-
}
|
|
9
|
-
export function getString(key: string, gv: StringMap | ((key: string) => string)): string {
|
|
10
|
-
if (typeof gv === "function") {
|
|
11
|
-
return gv(key)
|
|
12
|
-
} else {
|
|
13
|
-
return gv[key]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function message(gv: StringMap | ((key: string) => string), msg: string, title?: string, yes?: string, no?: string): Message {
|
|
17
|
-
const m2 = msg && msg.length > 0 ? getString(msg, gv) : ""
|
|
18
|
-
const m: Message = { message: m2, title: "" }
|
|
19
|
-
if (title && title.length > 0) {
|
|
20
|
-
m.title = getString(title, gv)
|
|
21
|
-
}
|
|
22
|
-
if (yes && yes.length > 0) {
|
|
23
|
-
m.yes = getString(yes, gv)
|
|
24
|
-
}
|
|
25
|
-
if (no && no.length > 0) {
|
|
26
|
-
m.no = getString(no, gv)
|
|
27
|
-
}
|
|
28
|
-
return m
|
|
29
|
-
}
|
|
30
|
-
export function messageByHttpStatus(status: number, gv: StringMap | ((key: string) => string)): string {
|
|
31
|
-
const k = "error_" + status
|
|
32
|
-
let msg = getString(k, gv)
|
|
33
|
-
if (!msg || msg.length === 0) {
|
|
34
|
-
msg = getString("error_500", gv)
|
|
35
|
-
}
|
|
36
|
-
return msg
|
|
37
|
-
}
|
|
38
|
-
export function error(err: any, gv: StringMap | ((key: string) => string), ae: (msg: string, callback?: () => void, header?: string) => void) {
|
|
39
|
-
const title = getString("error", gv)
|
|
40
|
-
let msg = getString("error_internal", gv)
|
|
41
|
-
if (!err) {
|
|
42
|
-
ae(msg, undefined, title)
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
const data = err && err.response ? err.response : err
|
|
46
|
-
if (data) {
|
|
47
|
-
const status = data.status
|
|
48
|
-
if (status && !isNaN(status)) {
|
|
49
|
-
msg = messageByHttpStatus(status, gv)
|
|
50
|
-
}
|
|
51
|
-
ae(msg, undefined, title)
|
|
52
|
-
} else {
|
|
53
|
-
ae(msg, undefined, title)
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/merge.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "react"
|
|
2
|
-
|
|
3
|
-
export type Callback<T> = (value?: T) => void
|
|
4
|
-
export type DispatchWithCallback<T> = (value: T, callback?: Callback<T>) => void
|
|
5
|
-
|
|
6
|
-
export function useMergeState<T>(initialState?: T | (() => T)): [T, DispatchWithCallback<Partial<T>>] {
|
|
7
|
-
const [state, _setState] = useState(initialState ? initialState : ({} as any))
|
|
8
|
-
|
|
9
|
-
const callbackRef = useRef<Callback<T>>()
|
|
10
|
-
|
|
11
|
-
const setState = useCallback(
|
|
12
|
-
(newState: Partial<T>, callback?: Callback<T>): void => {
|
|
13
|
-
callbackRef.current = callback
|
|
14
|
-
_setState((prevState: any) => Object.assign({}, prevState, newState))
|
|
15
|
-
},
|
|
16
|
-
[state],
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (callbackRef.current) {
|
|
21
|
-
callbackRef.current(state)
|
|
22
|
-
}
|
|
23
|
-
}, [state])
|
|
24
|
-
|
|
25
|
-
return [state, setState]
|
|
26
|
-
}
|