Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
abstract error
  • Loading branch information
Luncher committed May 23, 2022
commit ba4b45e4b5559a12ca7c9ae265252b0c56a66075
7 changes: 1 addition & 6 deletions src/debouncedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { action, computed, makeObservable, observable, override, reaction } from
import { FieldState } from './fieldState'
import { ValidatableState } from './state'
import { IState, ValidateStatus, ValueOf } from './types'
import { debounce, isPassed } from './utils'
import { debounce } from './utils'

const defaultDelay = 200 // ms

Expand Down Expand Up @@ -64,11 +64,6 @@ export class DebouncedState<S extends IState<V>, V = ValueOf<S>> extends Validat
return this.original.error
}

@override override get hasError() {
if (this.disabled) return false
return !isPassed(this.rawError) || this.original.hasError
}

@override override get validateStatus() {
if (this.disabled) return ValidateStatus.WontValidate
if (
Expand Down
16 changes: 0 additions & 16 deletions src/formState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { observable, computed, isObservable, action, reaction, makeObservable, override } from 'mobx'
import { IState, ValidateStatus, ValidateResult, ValueOfStatesObject } from './types'
import { ValidatableState } from './state'
import { isPassed } from './utils'

abstract class AbstractFormState<T, V> extends ValidatableState<V> implements IState<V> {

Expand Down Expand Up @@ -48,21 +47,6 @@ abstract class AbstractFormState<T, V> extends ValidatableState<V> implements IS
}
}

@override override get hasError() {
if (this.disabled) {
return false
}
if (!isPassed(this.rawError)) {
return true
}
for (const state of this.childStates) {
if (state.hasError) {
return true
}
}
return false
}

/** If reference of child states has been touched. */
@observable protected ownTouched = false

Expand Down
8 changes: 5 additions & 3 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action, autorun, computed, makeObservable, observable, when } from 'mobx'
import { ValidationResult, IState, Validation, ValidateResult, ValidateStatus, Validator } from './types'
import { ValidationResult, IState, Validation, ValidateResult, ValidationError, ValidateStatus, Validator } from './types'
import Disposable from './disposable'
import { applyValidators, isPromiseLike, isPassed, normalizeError } from './utils'
import { applyValidators, isPromiseLike, normalizeError } from './utils'

/** Extraction for some basic features of State */
export abstract class BaseState extends Disposable implements Pick<
Expand All @@ -10,8 +10,10 @@ export abstract class BaseState extends Disposable implements Pick<

abstract rawError: ValidationResult
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rawErrorValidationResult 是对的吗?
后面还有类似的这种

Copy link
Contributor Author

@Luncher Luncher May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rawError 对 ValidationResult 是对的吗?

是预期的

后面还有类似的这种

啥?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没啥,是预期的就好
我只是看到 error 对 result 感觉怪怪的


abstract error: ValidationError

@computed get hasError() {
return !isPassed(this.rawError)
return !!this.error
}

@computed get ownError() {
Expand Down
6 changes: 1 addition & 5 deletions src/transformedState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { override, computed } from 'mobx'
import { computed } from 'mobx'
import { BaseState } from './state'
import { IState, Validator, ValueOf } from './types'

Expand Down Expand Up @@ -27,10 +27,6 @@ export class TransformedState<S extends IState<$V>, V, $V = ValueOf<S>> extends
return this.$.rawError
}

@override override get hasError() {
return this.$.hasError
}

@computed get error() {
return this.$.error
}
Expand Down