Skip to content

Commit

Permalink
Merge pull request #2 from nighca/master
Browse files Browse the repository at this point in the history
debug FormState `validated`
  • Loading branch information
nighca authored Oct 18, 2019
2 parents 791754d + ae86873 commit 21bf62d
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 90 deletions.
26 changes: 13 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

Ƭ **FieldsArray**: *[ComposibleValidatable](interfaces/composiblevalidatable.md)‹any›[]*

*Defined in [formState.ts:9](https://github.com/qiniu/formstate-x/blob/f0b789c/src/formState.ts#L9)*
*Defined in [formState.ts:9](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/formState.ts#L9)*

Mode: array

Expand All @@ -57,7 +57,7 @@ ___

Ƭ **FieldsObject**: *object*

*Defined in [formState.ts:7](https://github.com/qiniu/formstate-x/blob/f0b789c/src/formState.ts#L7)*
*Defined in [formState.ts:7](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/formState.ts#L7)*

Mode: object

Expand All @@ -71,7 +71,7 @@ ___

Ƭ **ValidatableFields**: *[FieldsObject](README.md#fieldsobject) | [FieldsArray](README.md#fieldsarray)*

*Defined in [formState.ts:11](https://github.com/qiniu/formstate-x/blob/f0b789c/src/formState.ts#L11)*
*Defined in [formState.ts:11](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/formState.ts#L11)*

Each key of the object is a validatable

Expand All @@ -81,7 +81,7 @@ ___

Ƭ **Validated**: *object*

*Defined in [types.ts:16](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L16)*
*Defined in [types.ts:16](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L16)*

#### Type declaration:

Expand All @@ -91,7 +91,7 @@ ___

Ƭ **ValidationResponse**: *string | null | undefined | false*

*Defined in [types.ts:5](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L5)*
*Defined in [types.ts:5](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L5)*

A truthy string or falsy values.

Expand All @@ -101,7 +101,7 @@ ___

Ƭ **ValidatorResponse**: *[ValidationResponse](README.md#validationresponse) | Promise‹[ValidationResponse](README.md#validationresponse)*

*Defined in [types.ts:12](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L12)*
*Defined in [types.ts:12](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L12)*

The return value of a validator.

Expand All @@ -111,7 +111,7 @@ ___

Ƭ **ValueOf**: *State extends FormState<infer Fields, infer Fields extends { [key: string]: ComposibleValidatable<any, any>; } ? ValueOfObjectFields<infer Fields> : infer Fields extends (infer Field)[] ? ValueArrayOf<Field> : never> ? Fields extends { ...; } ? ValueOfObjectFields<...> : Fields extends (infer Field)[] ? ValueArrayOf...*

*Defined in [types.ts:90](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L90)*
*Defined in [types.ts:91](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L91)*

Value of state (`FormState` or `FieldState`)

Expand All @@ -121,7 +121,7 @@ ___

Ƭ **ValueOfArrayFields**: *Fields extends (infer Field)[] ? ValueArrayOf<Field> : never*

*Defined in [types.ts:76](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L76)*
*Defined in [types.ts:77](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L77)*

Value of array-fields.

Expand All @@ -131,7 +131,7 @@ ___

Ƭ **ValueOfFieldState**: *State extends FieldState<infer FieldType> ? FieldType : never*

*Defined in [types.ts:59](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L59)*
*Defined in [types.ts:60](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L60)*

Value of `FieldState`.

Expand All @@ -141,7 +141,7 @@ ___

Ƭ **ValueOfFields**: *Fields extends { [key: string]: ComposibleValidatable<any, any>; } ? ValueOfObjectFields<Fields> : Fields extends (infer Field)[] ? ValueArrayOf<Field> : never*

*Defined in [types.ts:83](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L83)*
*Defined in [types.ts:84](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L84)*

Value of fields.

Expand All @@ -151,7 +151,7 @@ ___

Ƭ **ValueOfObjectFields**: *object*

*Defined in [types.ts:71](https://github.com/qiniu/formstate-x/blob/f0b789c/src/types.ts#L71)*
*Defined in [types.ts:72](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/types.ts#L72)*

Value of object-fields.

Expand All @@ -163,7 +163,7 @@ Value of object-fields.

**bindInput**<**T**>(`state`: [FieldState](classes/fieldstate.md)‹T›): *[InputBindings](interfaces/inputbindings.md)‹T›*

*Defined in [bind.ts:16](https://github.com/qiniu/formstate-x/blob/f0b789c/src/bind.ts#L16)*
*Defined in [bind.ts:16](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/bind.ts#L16)*

Helper method to bind state to your input component.
You can define your own bindInput by specifying `getValue`.
Expand All @@ -182,7 +182,7 @@ Name | Type |

**bindInput**<**T**, **E**>(`state`: [FieldState](classes/fieldstate.md)‹T›, `getValue`: function): *[InputBindings](interfaces/inputbindings.md)‹T, E›*

*Defined in [bind.ts:17](https://github.com/qiniu/formstate-x/blob/f0b789c/src/bind.ts#L17)*
*Defined in [bind.ts:17](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/bind.ts#L17)*

**Type parameters:**

Expand Down
4 changes: 2 additions & 2 deletions docs/classes/disposable.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Class that collects side-effects and dispose them on demand.

\+ **new Disposable**(): *[Disposable](disposable.md)*

*Defined in [disposable.ts:28](https://github.com/qiniu/formstate-x/blob/f0b789c/src/disposable.ts#L28)*
*Defined in [disposable.ts:28](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/disposable.ts#L28)*

**Returns:** *[Disposable](disposable.md)*

Expand All @@ -38,7 +38,7 @@ Class that collects side-effects and dispose them on demand.

**dispose**(): *void*

*Defined in [disposable.ts:23](https://github.com/qiniu/formstate-x/blob/f0b789c/src/disposable.ts#L23)*
*Defined in [disposable.ts:23](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/disposable.ts#L23)*

Do dispose by calling all disposer functions.

Expand Down
53 changes: 33 additions & 20 deletions docs/classes/fieldstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The state for a field.
* [hasError](fieldstate.md#haserror)
* [validated](fieldstate.md#validated)
* [validating](fieldstate.md#validating)
* [validationDisabled](fieldstate.md#validationdisabled)

### Methods

Expand All @@ -60,7 +61,7 @@ The state for a field.

*Overrides [Disposable](disposable.md).[constructor](disposable.md#constructor)*

*Defined in [fieldState.ts:230](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L230)*
*Defined in [fieldState.ts:235](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L235)*

**Parameters:**

Expand All @@ -79,7 +80,7 @@ Name | Type | Default |

*Implementation of [ComposibleValidatable](../interfaces/composiblevalidatable.md).[$](../interfaces/composiblevalidatable.md#$)*

*Defined in [fieldState.ts:39](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L39)*
*Defined in [fieldState.ts:39](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L39)*

Value that has bean validated with no error, AKA "safe".

Expand All @@ -91,7 +92,7 @@ ___

*Implementation of [ComposibleValidatable](../interfaces/composiblevalidatable.md).[_activated](../interfaces/composiblevalidatable.md#_activated)*

*Defined in [fieldState.ts:15](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L15)*
*Defined in [fieldState.ts:15](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L15)*

If activated (with auto validation).
Field will only be activated when `validate()` or `onChange()` called.
Expand All @@ -102,7 +103,7 @@ ___

**_error**? : *undefined | string*

*Defined in [fieldState.ts:64](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L64)*
*Defined in [fieldState.ts:64](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L64)*

The original error info of validation.

Expand All @@ -114,7 +115,7 @@ ___

*Implementation of [ComposibleValidatable](../interfaces/composiblevalidatable.md).[_validateStatus](../interfaces/composiblevalidatable.md#_validatestatus)*

*Defined in [fieldState.ts:52](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L52)*
*Defined in [fieldState.ts:52](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L52)*

The validate status.

Expand All @@ -124,7 +125,7 @@ ___

**_value**: *TValue*

*Defined in [fieldState.ts:28](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L28)*
*Defined in [fieldState.ts:28](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L28)*

Value that reacts to `onChange` immediately.
You should only use it to bind with UI input componnet.
Expand All @@ -137,7 +138,7 @@ ___

*Implementation of [ComposibleValidatable](../interfaces/composiblevalidatable.md).[value](../interfaces/composiblevalidatable.md#value)*

*Defined in [fieldState.ts:34](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L34)*
*Defined in [fieldState.ts:34](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L34)*

Value that can be consumed by your code.
It's synced from `_value` with debounce of 200ms.
Expand All @@ -148,7 +149,7 @@ It's synced from `_value` with debounce of 200ms.

**get dirty**(): *boolean*

*Defined in [fieldState.ts:20](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L20)*
*Defined in [fieldState.ts:20](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L20)*

If value has been touched (different with `initialValue`)

Expand All @@ -160,7 +161,7 @@ ___

**get error**(): *undefined | string*

*Defined in [fieldState.ts:69](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L69)*
*Defined in [fieldState.ts:69](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L69)*

The error info of validation.

Expand All @@ -172,7 +173,7 @@ ___

**get hasError**(): *boolean*

*Defined in [fieldState.ts:76](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L76)*
*Defined in [fieldState.ts:76](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L76)*

If the state contains error.

Expand All @@ -184,7 +185,7 @@ ___

**get validated**(): *boolean*

*Defined in [fieldState.ts:84](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L84)*
*Defined in [fieldState.ts:84](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L84)*

If the validation has been done.
It does not means validation passed.
Expand All @@ -197,19 +198,31 @@ ___

**get validating**(): *boolean*

*Defined in [fieldState.ts:57](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L57)*
*Defined in [fieldState.ts:57](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L57)*

If the state is doing a validation.

**Returns:** *boolean*

___

### validationDisabled

**get validationDisabled**(): *boolean*

*Defined in [fieldState.ts:197](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L197)*

If validation disabled.

**Returns:** *boolean*

## Methods

### disableValidationWhen

**disableValidationWhen**(`predict`: function): *this*

*Defined in [fieldState.ts:199](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L199)*
*Defined in [fieldState.ts:204](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L204)*

Configure when to disable validation.

Expand All @@ -229,7 +242,7 @@ ___

*Inherited from [Disposable](disposable.md).[dispose](disposable.md#dispose)*

*Defined in [disposable.ts:23](https://github.com/qiniu/formstate-x/blob/f0b789c/src/disposable.ts#L23)*
*Defined in [disposable.ts:23](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/disposable.ts#L23)*

Do dispose by calling all disposer functions.

Expand All @@ -241,7 +254,7 @@ ___

**onChange**(`value`: TValue): *void*

*Defined in [fieldState.ts:119](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L119)*
*Defined in [fieldState.ts:119](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L119)*

Set `_value` on change event.

Expand All @@ -259,7 +272,7 @@ ___

**reset**(): *void*

*Defined in [fieldState.ts:134](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L134)*
*Defined in [fieldState.ts:134](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L134)*

Reset to initial status.

Expand All @@ -271,7 +284,7 @@ ___

**set**(`value`: TValue): *void*

*Defined in [fieldState.ts:126](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L126)*
*Defined in [fieldState.ts:126](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L126)*

Set `value` (& `_value`) synchronously.

Expand All @@ -289,7 +302,7 @@ ___

**setError**(`error`: [ValidationResponse](../README.md#validationresponse)): *void*

*Defined in [fieldState.ts:91](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L91)*
*Defined in [fieldState.ts:91](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L91)*

Set error info.

Expand All @@ -309,7 +322,7 @@ ___

*Implementation of [ComposibleValidatable](../interfaces/composiblevalidatable.md)*

*Defined in [fieldState.ts:171](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L171)*
*Defined in [fieldState.ts:171](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L171)*

Fire a validation behavior.

Expand All @@ -321,7 +334,7 @@ ___

**validators**(...`validators`: [Validator](../interfaces/validator.md)‹TValue›[]): *this*

*Defined in [fieldState.ts:103](https://github.com/qiniu/formstate-x/blob/f0b789c/src/fieldState.ts#L103)*
*Defined in [fieldState.ts:103](https://github.com/qiniu/formstate-x/blob/d29c1fc/src/fieldState.ts#L103)*

Add validator function.

Expand Down
Loading

0 comments on commit 21bf62d

Please sign in to comment.