Skip to content

Commit

Permalink
refactor(forms): eagerly initialize data members (#44292)
Browse files Browse the repository at this point in the history
Data members in AbstractControl should be eagerly
initialized to address issue/24571. This eliminates the need to
constantly check for truthiness and makes code much more readable.

More PRs to follow to address issue/24571.

PR Close #44292
  • Loading branch information
theruslanusmanov authored and dylhunn committed Nov 30, 2021
1 parent f058109 commit ca5b9b5
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/forms/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ function isOptionsObj(validatorOrOpts?: ValidatorFn|ValidatorFn[]|AbstractContro
*/
export abstract class AbstractControl {
/** @internal */
// TODO(issue/24571): remove '!'.
_pendingDirty!: boolean;
_pendingDirty = false;

/**
* Indicates that a control has its own pending asynchronous validation in progress.
Expand All @@ -179,15 +178,13 @@ export abstract class AbstractControl {
_hasOwnPendingAsyncValidator = false;

/** @internal */
// TODO(issue/24571): remove '!'.
_pendingTouched!: boolean;
_pendingTouched = false;

/** @internal */
_onCollectionChange = () => {};

/** @internal */
// TODO(issue/24571): remove '!'.
_updateOn!: FormHooks;
_updateOn?: FormHooks;

private _parent: FormGroup|FormArray|null = null;
private _asyncValidationSubscription: any;
Expand Down Expand Up @@ -298,7 +295,6 @@ export abstract class AbstractControl {
* These status values are mutually exclusive, so a control cannot be
* both valid AND invalid or invalid AND disabled.
*/
// TODO(issue/24571): remove '!'.
public readonly status!: FormControlStatus;

/**
Expand Down Expand Up @@ -369,7 +365,6 @@ export abstract class AbstractControl {
* An object containing any errors generated by failing validation,
* or null if there are no errors.
*/
// TODO(issue/24571): remove '!'.
public readonly errors!: ValidationErrors|null;

/**
Expand Down Expand Up @@ -415,7 +410,6 @@ export abstract class AbstractControl {
* the UI or programmatically. It also emits an event each time you call enable() or disable()
* without passing along {emitEvent: false} as a function argument.
*/
// TODO(issue/24571): remove '!'.
public readonly valueChanges!: Observable<any>;

/**
Expand All @@ -426,7 +420,6 @@ export abstract class AbstractControl {
* @see {@link AbstractControl.status}
*
*/
// TODO(issue/24571): remove '!'.
public readonly statusChanges!: Observable<FormControlStatus>;

/**
Expand Down

0 comments on commit ca5b9b5

Please sign in to comment.