Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(forms): avoid direct references to the Validators class #41189

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,12 @@
{
"name": "collectStylingFromTAttrs"
},
{
"name": "compose"
},
{
"name": "composeAsync"
},
{
"name": "composeAsyncValidators"
},
Expand Down Expand Up @@ -1343,6 +1349,9 @@
{
"name": "notFoundValueOrThrow"
},
{
"name": "nullValidator"
},
{
"name": "observable"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@
{
"name": "DomSharedStylesHost"
},
{
"name": "EMAIL_REGEXP"
},
{
"name": "EMPTY_ARRAY"
},
Expand Down Expand Up @@ -563,9 +560,6 @@
{
"name": "VE_ViewContainerRef"
},
{
"name": "Validators"
},
{
"name": "Version"
},
Expand Down Expand Up @@ -1046,9 +1040,6 @@
{
"name": "hasTagAndTypeMatch"
},
{
"name": "hasValidLength"
},
{
"name": "hostReportError"
},
Expand Down Expand Up @@ -1130,9 +1121,6 @@
{
"name": "isDirectiveHost"
},
{
"name": "isEmptyInputValue"
},
{
"name": "isForwardRef"
},
Expand Down
26 changes: 13 additions & 13 deletions packages/forms/src/directives/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Directive, forwardRef, Input, OnChanges, SimpleChanges, StaticProvider}
import {Observable} from 'rxjs';

import {AbstractControl} from '../model';
import {NG_VALIDATORS, Validators} from '../validators';
import {emailValidator, maxLengthValidator, maxValidator, minLengthValidator, minValidator, NG_VALIDATORS, nullValidator, patternValidator, requiredTrueValidator, requiredValidator} from '../validators';


/**
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface Validator {
*/
@Directive()
abstract class AbstractValidatorDirective implements Validator {
private _validator: ValidatorFn = Validators.nullValidator;
private _validator: ValidatorFn = nullValidator;
private _onChange!: () => void;

/**
Expand Down Expand Up @@ -180,7 +180,7 @@ export class MaxValidator extends AbstractValidatorDirective implements OnChange
/** @internal */
normalizeInput = (input: string): number => parseInt(input, 10);
/** @internal */
createValidator = (max: number): ValidatorFn => Validators.max(max);
createValidator = (max: number): ValidatorFn => maxValidator(max);
/**
* Declare `ngOnChanges` lifecycle hook at the main directive level (vs keeping it in base class)
* to avoid differences in handling inheritance of lifecycle hooks between Ivy and ViewEngine in
Expand Down Expand Up @@ -240,7 +240,7 @@ export class MinValidator extends AbstractValidatorDirective implements OnChange
/** @internal */
normalizeInput = (input: string): number => parseInt(input, 10);
/** @internal */
createValidator = (min: number): ValidatorFn => Validators.min(min);
createValidator = (min: number): ValidatorFn => minValidator(min);
/**
* Declare `ngOnChanges` lifecycle hook at the main directive level (vs keeping it in base class)
* to avoid differences in handling inheritance of lifecycle hooks between Ivy and ViewEngine in
Expand Down Expand Up @@ -364,7 +364,7 @@ export class RequiredValidator implements Validator {
* @nodoc
*/
validate(control: AbstractControl): ValidationErrors|null {
return this.required ? Validators.required(control) : null;
return this.required ? requiredValidator(control) : null;
}

/**
Expand Down Expand Up @@ -411,7 +411,7 @@ export class CheckboxRequiredValidator extends RequiredValidator {
* @nodoc
*/
validate(control: AbstractControl): ValidationErrors|null {
return this.required ? Validators.requiredTrue(control) : null;
return this.required ? requiredTrueValidator(control) : null;
}
}

Expand Down Expand Up @@ -472,7 +472,7 @@ export class EmailValidator implements Validator {
* @nodoc
*/
validate(control: AbstractControl): ValidationErrors|null {
return this._enabled ? Validators.email(control) : null;
return this._enabled ? emailValidator(control) : null;
}

/**
Expand Down Expand Up @@ -543,7 +543,7 @@ export const MIN_LENGTH_VALIDATOR: any = {
host: {'[attr.minlength]': 'minlength ? minlength : null'}
})
export class MinLengthValidator implements Validator, OnChanges {
private _validator: ValidatorFn = Validators.nullValidator;
private _validator: ValidatorFn = nullValidator;
private _onChange?: () => void;

/**
Expand Down Expand Up @@ -579,7 +579,7 @@ export class MinLengthValidator implements Validator, OnChanges {
}

private _createValidator(): void {
this._validator = Validators.minLength(
this._validator = minLengthValidator(
typeof this.minlength === 'number' ? this.minlength : parseInt(this.minlength, 10));
}
}
Expand Down Expand Up @@ -621,7 +621,7 @@ export const MAX_LENGTH_VALIDATOR: any = {
host: {'[attr.maxlength]': 'maxlength ? maxlength : null'}
})
export class MaxLengthValidator implements Validator, OnChanges {
private _validator: ValidatorFn = Validators.nullValidator;
private _validator: ValidatorFn = nullValidator;
private _onChange?: () => void;

/**
Expand Down Expand Up @@ -656,7 +656,7 @@ export class MaxLengthValidator implements Validator, OnChanges {
}

private _createValidator(): void {
this._validator = Validators.maxLength(
this._validator = maxLengthValidator(
typeof this.maxlength === 'number' ? this.maxlength : parseInt(this.maxlength, 10));
}
}
Expand Down Expand Up @@ -701,7 +701,7 @@ export const PATTERN_VALIDATOR: any = {
host: {'[attr.pattern]': 'pattern ? pattern : null'}
})
export class PatternValidator implements Validator, OnChanges {
private _validator: ValidatorFn = Validators.nullValidator;
private _validator: ValidatorFn = nullValidator;
private _onChange?: () => void;

/**
Expand Down Expand Up @@ -736,6 +736,6 @@ export class PatternValidator implements Validator, OnChanges {
}

private _createValidator(): void {
this._validator = Validators.pattern(this.pattern);
this._validator = patternValidator(this.pattern);
}
}