From 7954c8dfa3c85d12780949c75f1448c8d783a8cf Mon Sep 17 00:00:00 2001 From: arturovt Date: Fri, 4 Dec 2020 13:06:48 +0200 Subject: [PATCH] perf(forms): use `ngDevMode` to tree-shake `_ngModelWarning` (#39964) This commit adds `ngDevMode` guard to call `_ngModelWarning` only in dev mode (similar to how things work in other parts of Ivy runtime code). The `ngDevMode` flag helps to tree-shake this function from production builds (since it will act as no-op, in dev mode everything will work as it works right now) to decrease production bundle size. PR Close #39964 --- .../reactive_directives/form_control_directive.ts | 4 +++- .../directives/reactive_directives/form_control_name.ts | 4 +++- packages/forms/src/directives/shared.ts | 8 ++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/forms/src/directives/reactive_directives/form_control_directive.ts b/packages/forms/src/directives/reactive_directives/form_control_directive.ts index 547ea216d1..d64cd1e5f9 100644 --- a/packages/forms/src/directives/reactive_directives/form_control_directive.ts +++ b/packages/forms/src/directives/reactive_directives/form_control_directive.ts @@ -125,7 +125,9 @@ export class FormControlDirective extends NgControl implements OnChanges { this.form.updateValueAndValidity({emitEvent: false}); } if (isPropertyUpdated(changes, this.viewModel)) { - _ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig); + if (typeof ngDevMode === 'undefined' || ngDevMode) { + _ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig); + } this.form.setValue(this.model); this.viewModel = this.model; } diff --git a/packages/forms/src/directives/reactive_directives/form_control_name.ts b/packages/forms/src/directives/reactive_directives/form_control_name.ts index 9e76a3f91a..fe5044c6ed 100644 --- a/packages/forms/src/directives/reactive_directives/form_control_name.ts +++ b/packages/forms/src/directives/reactive_directives/form_control_name.ts @@ -145,7 +145,9 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy { ngOnChanges(changes: SimpleChanges) { if (!this._added) this._setUpControl(); if (isPropertyUpdated(changes, this.viewModel)) { - _ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig); + if (typeof ngDevMode === 'undefined' || ngDevMode) { + _ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig); + } this.viewModel = this.model; this.formDirective.updateModel(this, this.model); } diff --git a/packages/forms/src/directives/shared.ts b/packages/forms/src/directives/shared.ts index 3a69960447..a66893ec0b 100644 --- a/packages/forms/src/directives/shared.ts +++ b/packages/forms/src/directives/shared.ts @@ -6,8 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {isDevMode} from '@angular/core'; - import {AbstractControl, FormArray, FormControl, FormGroup} from '../model'; import {getControlAsyncValidators, getControlValidators, mergeValidators} from '../validators'; @@ -324,13 +322,11 @@ export function removeListItem(list: T[], el: T): void { export function _ngModelWarning( name: string, type: {_ngModelWarningSentOnce: boolean}, instance: {_ngModelWarningSent: boolean}, warningConfig: string|null) { - if (!isDevMode() || warningConfig === 'never') return; + if (warningConfig === 'never') return; if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) || (warningConfig === 'always' && !instance._ngModelWarningSent)) { - if (typeof ngDevMode === 'undefined' || ngDevMode) { - ReactiveErrors.ngModelWarning(name); - } + ReactiveErrors.ngModelWarning(name); type._ngModelWarningSentOnce = true; instance._ngModelWarningSent = true; }