Skip to content

Commit 400e5b9

Browse files
committed
perf: 🎉 make some change to the codes
1 parent b3c3e7d commit 400e5b9

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/core/BaseService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class BaseService {
9797
this.$http(config)
9898
.then((response: AxiosResponse) => {
9999
this.onSuccess()
100-
resolve(response.data || {})
100+
resolve(response.data)
101101
})
102102
.catch((error: AxiosError<AxiosResponseData>) => {
103103
this.errors.processing = false

src/core/Validator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ class Validator {
3333
first(field: string | string[]): string | Record<string, any> | undefined {
3434
if (Array.isArray(field)) {
3535
const fields = this.fields(field)
36+
let fd = ''
3637
for (const f of fields) {
37-
if (!has(this.errors, f)) continue
38-
return this.first(f)
38+
if (has(this.errors, f)) {
39+
fd = f
40+
break
41+
}
3942
}
43+
return this.first(fd)
4044
} else {
4145
const value = this.get(field)
4246
if (Array.isArray(value)) return value[0]

src/util/formData.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,24 @@ function appendToFormData(formData: FormData, key: string, value: any) {
4848
objectToFormData(value, formData, key)
4949
}
5050

51-
export function hasFilesDeep(object: any): boolean {
52-
if (object === null) {
53-
return false
54-
}
55-
if (typeof object === 'object') {
56-
for (const key in object) {
57-
if (hasOwnProperty(object, key)) {
58-
if (isFile(object[key])) {
59-
return true
60-
}
61-
}
51+
export function hasFilesDeep(obj: any): boolean {
52+
if (obj === null) return false
53+
if (typeof obj === 'object') {
54+
for (const key in obj) {
55+
if (hasOwnProperty(obj, key) && isFile(obj[key])) return true
6256
}
6357
}
64-
if (isArray(object)) {
65-
for (const key in object) {
66-
if (hasOwnProperty(object, key)) {
67-
return hasFilesDeep(object[key])
58+
if (isArray(obj)) {
59+
let f = ''
60+
for (const key in obj) {
61+
if (hasOwnProperty(obj, key)) {
62+
f = key
63+
break
6864
}
6965
}
66+
return hasFilesDeep(obj[f])
7067
}
71-
return isFile(object)
68+
return isFile(obj)
7269
}
7370

7471
export function hasFiles(form: any): boolean {

0 commit comments

Comments
 (0)