diff --git a/goldens/size-tracking/integration-payloads.json b/goldens/size-tracking/integration-payloads.json index 67d5b5b588a..b529c1581ea 100644 --- a/goldens/size-tracking/integration-payloads.json +++ b/goldens/size-tracking/integration-payloads.json @@ -52,7 +52,7 @@ "master": { "uncompressed": { "runtime": 1063, - "main": 156654, + "main": 157357, "polyfills": 33804 } } diff --git a/packages/forms/src/directives/ng_control_status.ts b/packages/forms/src/directives/ng_control_status.ts index 02417f44a30..55bebc64451 100644 --- a/packages/forms/src/directives/ng_control_status.ts +++ b/packages/forms/src/directives/ng_control_status.ts @@ -12,9 +12,10 @@ import {AbstractControlDirective} from './abstract_control_directive'; import {ControlContainer} from './control_container'; import {NgControl} from './ng_control'; -type AnyControlStatus = - 'untouched'|'touched'|'pristine'|'dirty'|'valid'|'invalid'|'pending'|'submitted'; - +// DO NOT REFACTOR! +// Each status is represented by a separate function to make sure that +// advanced Closure Compiler optimizations related to property renaming +// can work correctly. export class AbstractControlStatus { private _cd: AbstractControlDirective|null; @@ -22,41 +23,54 @@ export class AbstractControlStatus { this._cd = cd; } - is(status: AnyControlStatus): boolean { - // Currently with ViewEngine (in AOT mode) it's not possible to use private methods in host - // bindings. - // TODO: once ViewEngine is removed, this function should be refactored: - // - make the `is` method `protected`, so it's not accessible publicly - // - move the `submitted` status logic to the `NgControlStatusGroup` class - // and make it `private` or `protected` too. - if (status === 'submitted') { - // We check for the `submitted` field from `NgForm` and `FormGroupDirective` classes, but - // we avoid instanceof checks to prevent non-tree-shakable references to those types. - return !!(this._cd as unknown as {submitted: boolean} | null)?.submitted; - } - return !!this._cd?.control?.[status]; + protected get isTouched() { + return !!this._cd?.control?.touched; + } + + protected get isUntouched() { + return !!this._cd?.control?.untouched; + } + + protected get isPristine() { + return !!this._cd?.control?.pristine; + } + + protected get isDirty() { + return !!this._cd?.control?.dirty; + } + + protected get isValid() { + return !!this._cd?.control?.valid; + } + + protected get isInvalid() { + return !!this._cd?.control?.invalid; + } + + protected get isPending() { + return !!this._cd?.control?.pending; + } + + protected get isSubmitted() { + // We check for the `submitted` field from `NgForm` and `FormGroupDirective` classes, but + // we avoid instanceof checks to prevent non-tree-shakable references to those types. + return !!(this._cd as unknown as {submitted: boolean} | null)?.submitted; } } export const ngControlStatusHost = { - '[class.ng-untouched]': 'is("untouched")', - '[class.ng-touched]': 'is("touched")', - '[class.ng-pristine]': 'is("pristine")', - '[class.ng-dirty]': 'is("dirty")', - '[class.ng-valid]': 'is("valid")', - '[class.ng-invalid]': 'is("invalid")', - '[class.ng-pending]': 'is("pending")', + '[class.ng-untouched]': 'isUntouched', + '[class.ng-touched]': 'isTouched', + '[class.ng-pristine]': 'isPristine', + '[class.ng-dirty]': 'isDirty', + '[class.ng-valid]': 'isValid', + '[class.ng-invalid]': 'isInvalid', + '[class.ng-pending]': 'isPending', }; export const ngGroupStatusHost = { - '[class.ng-untouched]': 'is("untouched")', - '[class.ng-touched]': 'is("touched")', - '[class.ng-pristine]': 'is("pristine")', - '[class.ng-dirty]': 'is("dirty")', - '[class.ng-valid]': 'is("valid")', - '[class.ng-invalid]': 'is("invalid")', - '[class.ng-pending]': 'is("pending")', - '[class.ng-submitted]': 'is("submitted")', + ...ngControlStatusHost, + '[class.ng-submitted]': 'isSubmitted', }; /**