Skip to content

Commit

Permalink
Performance optimization (#23)
Browse files Browse the repository at this point in the history
* avoid useless await, optimize validate performance

* v1.0.10
  • Loading branch information
nighca authored Apr 20, 2020
1 parent 2df5ad6 commit 0680aea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formstate-x",
"version": "1.0.9",
"version": "1.0.10",
"description": "Extended alternative for formstate",
"repository": {
"type": "git",
Expand Down
8 changes: 6 additions & 2 deletions src/fieldState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { observable, computed, action, reaction, autorun, runInAction, when } from 'mobx'
import { ComposibleValidatable, Validator, Validated, ValidationResponse, ValidateStatus } from './types'
import { applyValidators, debounce } from './utils'
import { applyValidators, debounce, isPromiseLike } from './utils'
import Disposable from './disposable'

/**
Expand Down Expand Up @@ -206,7 +206,11 @@ export default class FieldState<TValue> extends Disposable implements Composible
return
}

const error = await validation.response
const error = (
isPromiseLike(validation.response)
? await validation.response
: validation.response
)

if (
validation !== this.validation // 如果 validation 已过期,则不生效
Expand Down
8 changes: 6 additions & 2 deletions src/formState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { observable, computed, isArrayLike, isObservable, action, autorun, runInAction, when, reaction } from 'mobx'
import { ComposibleValidatable, ValueOfFields, ValidationResponse, Validator, Validated, ValidateStatus } from './types'
import { applyValidators } from './utils'
import { applyValidators, isPromiseLike } from './utils'
import Disposable from './disposable'

/** Mode: object */
Expand Down Expand Up @@ -251,7 +251,11 @@ export default class FormState<TFields extends ValidatableFields, TValue = Value
return
}

const error = await validation.response
const error = (
isPromiseLike(validation.response)
? await validation.response
: validation.response
)

// 如果 validation 已过期,则不生效
if (validation !== this.validation) {
Expand Down

0 comments on commit 0680aea

Please sign in to comment.