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
This commit is contained in:
parent
9ebe42370a
commit
7954c8dfa3
|
@ -125,7 +125,9 @@ export class FormControlDirective extends NgControl implements OnChanges {
|
||||||
this.form.updateValueAndValidity({emitEvent: false});
|
this.form.updateValueAndValidity({emitEvent: false});
|
||||||
}
|
}
|
||||||
if (isPropertyUpdated(changes, this.viewModel)) {
|
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.form.setValue(this.model);
|
||||||
this.viewModel = this.model;
|
this.viewModel = this.model;
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,9 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (!this._added) this._setUpControl();
|
if (!this._added) this._setUpControl();
|
||||||
if (isPropertyUpdated(changes, this.viewModel)) {
|
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.viewModel = this.model;
|
||||||
this.formDirective.updateModel(this, this.model);
|
this.formDirective.updateModel(this, this.model);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {isDevMode} from '@angular/core';
|
|
||||||
|
|
||||||
import {AbstractControl, FormArray, FormControl, FormGroup} from '../model';
|
import {AbstractControl, FormArray, FormControl, FormGroup} from '../model';
|
||||||
import {getControlAsyncValidators, getControlValidators, mergeValidators} from '../validators';
|
import {getControlAsyncValidators, getControlValidators, mergeValidators} from '../validators';
|
||||||
|
|
||||||
|
@ -324,13 +322,11 @@ export function removeListItem<T>(list: T[], el: T): void {
|
||||||
export function _ngModelWarning(
|
export function _ngModelWarning(
|
||||||
name: string, type: {_ngModelWarningSentOnce: boolean},
|
name: string, type: {_ngModelWarningSentOnce: boolean},
|
||||||
instance: {_ngModelWarningSent: boolean}, warningConfig: string|null) {
|
instance: {_ngModelWarningSent: boolean}, warningConfig: string|null) {
|
||||||
if (!isDevMode() || warningConfig === 'never') return;
|
if (warningConfig === 'never') return;
|
||||||
|
|
||||||
if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) ||
|
if (((warningConfig === null || warningConfig === 'once') && !type._ngModelWarningSentOnce) ||
|
||||||
(warningConfig === 'always' && !instance._ngModelWarningSent)) {
|
(warningConfig === 'always' && !instance._ngModelWarningSent)) {
|
||||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
ReactiveErrors.ngModelWarning(name);
|
||||||
ReactiveErrors.ngModelWarning(name);
|
|
||||||
}
|
|
||||||
type._ngModelWarningSentOnce = true;
|
type._ngModelWarningSentOnce = true;
|
||||||
instance._ngModelWarningSent = true;
|
instance._ngModelWarningSent = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue