feat(forms): AbstractControl to store raw validators in addition to combined validators function (#37881)

This commit refactors the way we store validators in AbstractControl-based classes:
in addition to the combined validators function that we have, we also store the original list of validators.
This is needed to have an ability to clean them up later at destroy time (currently it's problematic since
they are combined in a single function).

The change preserves backwards compatibility by making sure public APIs stay the same.
The only public API update is the change to the `AbstractControl` class constructor to extend the set
of possible types that it can accept and process (which should not be breaking).

PR Close #37881
This commit is contained in:
Andrew Kushnir
2020-07-01 18:16:49 -07:00
parent d72b1e44c6
commit ad7046b934
3 changed files with 212 additions and 27 deletions

View File

@ -1,5 +1,6 @@
export declare abstract class AbstractControl {
asyncValidator: AsyncValidatorFn | null;
get asyncValidator(): AsyncValidatorFn | null;
set asyncValidator(asyncValidatorFn: AsyncValidatorFn | null);
get dirty(): boolean;
get disabled(): boolean;
get enabled(): boolean;
@ -15,10 +16,11 @@ export declare abstract class AbstractControl {
get untouched(): boolean;
get updateOn(): FormHooks;
get valid(): boolean;
validator: ValidatorFn | null;
get validator(): ValidatorFn | null;
set validator(validatorFn: ValidatorFn | null);
readonly value: any;
readonly valueChanges: Observable<any>;
constructor(validator: ValidatorFn | null, asyncValidator: AsyncValidatorFn | null);
constructor(validators: ValidatorFn | ValidatorFn[] | null, asyncValidators: AsyncValidatorFn | AsyncValidatorFn[] | null);
clearAsyncValidators(): void;
clearValidators(): void;
disable(opts?: {