Skip to content

Commit 735556d

Browse files
arturovtmhevery
authored andcommitted
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
1 parent 72aad32 commit 735556d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/forms/src/directives/reactive_directives/form_control_directive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export class FormControlDirective extends NgControl implements OnChanges {
125125
this.form.updateValueAndValidity({emitEvent: false});
126126
}
127127
if (isPropertyUpdated(changes, this.viewModel)) {
128-
_ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig);
128+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
129+
_ngModelWarning('formControl', FormControlDirective, this, this._ngModelWarningConfig);
130+
}
129131
this.form.setValue(this.model);
130132
this.viewModel = this.model;
131133
}

packages/forms/src/directives/reactive_directives/form_control_name.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
145145
ngOnChanges(changes: SimpleChanges) {
146146
if (!this._added) this._setUpControl();
147147
if (isPropertyUpdated(changes, this.viewModel)) {
148-
_ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig);
148+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
149+
_ngModelWarning('formControlName', FormControlName, this, this._ngModelWarningConfig);
150+
}
149151
this.viewModel = this.model;
150152
this.formDirective.updateModel(this, this.model);
151153
}

packages/forms/src/directives/shared.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {isDevMode} from '@angular/core';
10-
119
import {AbstractControl, FormArray, FormControl, FormGroup} from '../model';
1210
import {getControlAsyncValidators, getControlValidators, mergeValidators} from '../validators';
1311

@@ -324,13 +322,11 @@ export function removeListItem<T>(list: T[], el: T): void {
324322
export function _ngModelWarning(
325323
name: string, type: {_ngModelWarningSentOnce: boolean},
326324
instance: {_ngModelWarningSent: boolean}, warningConfig: string|null) {
327-
if (!isDevMode() || warningConfig === 'never') return;
325+
if (warningConfig === 'never') return;
328326

329327
if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) ||
330328
(warningConfig === 'always' && !instance._ngModelWarningSent)) {
331-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
332-
ReactiveErrors.ngModelWarning(name);
333-
}
329+
ReactiveErrors.ngModelWarning(name);
334330
type._ngModelWarningSentOnce = true;
335331
instance._ngModelWarningSent = true;
336332
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy