From 608cdc40773989f392b2a56c13b90957f5a40250 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 26 Oct 2015 10:45:56 -0700 Subject: [PATCH] cleanup(forms): clean up NgFormControl Closes #4912 --- .../src/core/forms/directives/ng_form_control.ts | 9 +++++++-- modules/angular2/src/core/forms/directives/shared.ts | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/angular2/src/core/forms/directives/ng_form_control.ts b/modules/angular2/src/core/forms/directives/ng_form_control.ts index 4c6fbe60a6..610d5e3ecd 100644 --- a/modules/angular2/src/core/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/core/forms/directives/ng_form_control.ts @@ -1,4 +1,5 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; +import {StringMapWrapper} from 'angular2/src/core/facade/collection'; import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; import {OnChanges} from 'angular2/lifecycle_hooks'; import {SimpleChange} from 'angular2/src/core/change_detection'; @@ -8,7 +9,7 @@ import {NgControl} from './ng_control'; import {Control} from '../model'; import {Validators, NG_VALIDATORS} from '../validators'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; -import {setUpControl, isPropertyUpdated, isControlChanged, selectValueAccessor} from './shared'; +import {setUpControl, isPropertyUpdated, selectValueAccessor} from './shared'; const formControlBinding = CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgFormControl)})); @@ -82,7 +83,7 @@ export class NgFormControl extends NgControl implements OnChanges { } onChanges(changes: {[key: string]: SimpleChange}): void { - if (isControlChanged(changes)) { + if (this._isControlChanged(changes)) { setUpControl(this.form, this); this.form.updateValidity(); } @@ -102,4 +103,8 @@ export class NgFormControl extends NgControl implements OnChanges { this.viewModel = newValue; ObservableWrapper.callNext(this.update, newValue); } + + private _isControlChanged(changes: {[key: string]: any}): boolean { + return StringMapWrapper.contains(changes, "form"); + } } diff --git a/modules/angular2/src/core/forms/directives/shared.ts b/modules/angular2/src/core/forms/directives/shared.ts index 8cf4b73ab1..127dea54d6 100644 --- a/modules/angular2/src/core/forms/directives/shared.ts +++ b/modules/angular2/src/core/forms/directives/shared.ts @@ -60,12 +60,6 @@ export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any) return !looseIdentical(viewModel, change.currentValue); } -export function isControlChanged(changes: {[key: string]: any}): boolean { - if (!StringMapWrapper.contains(changes, "form")) return false; - var change = changes["form"]; - return change.previousValue !== change.currentValue; -} - // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented export function selectValueAccessor(dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor {