cleanup(forms): clean up NgFormControl

Closes #4912
This commit is contained in:
vsavkin 2015-10-26 10:45:56 -07:00 committed by Victor Savkin
parent d29a9a99aa
commit 608cdc4077
2 changed files with 7 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import {CONST_EXPR} from 'angular2/src/core/facade/lang'; 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 {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {OnChanges} from 'angular2/lifecycle_hooks'; import {OnChanges} from 'angular2/lifecycle_hooks';
import {SimpleChange} from 'angular2/src/core/change_detection'; import {SimpleChange} from 'angular2/src/core/change_detection';
@ -8,7 +9,7 @@ import {NgControl} from './ng_control';
import {Control} from '../model'; import {Control} from '../model';
import {Validators, NG_VALIDATORS} from '../validators'; import {Validators, NG_VALIDATORS} from '../validators';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; 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 formControlBinding =
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgFormControl)})); 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 { onChanges(changes: {[key: string]: SimpleChange}): void {
if (isControlChanged(changes)) { if (this._isControlChanged(changes)) {
setUpControl(this.form, this); setUpControl(this.form, this);
this.form.updateValidity(); this.form.updateValidity();
} }
@ -102,4 +103,8 @@ export class NgFormControl extends NgControl implements OnChanges {
this.viewModel = newValue; this.viewModel = newValue;
ObservableWrapper.callNext(this.update, newValue); ObservableWrapper.callNext(this.update, newValue);
} }
private _isControlChanged(changes: {[key: string]: any}): boolean {
return StringMapWrapper.contains(changes, "form");
}
} }

View File

@ -60,12 +60,6 @@ export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any)
return !looseIdentical(viewModel, change.currentValue); 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 // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented
export function selectValueAccessor(dir: NgControl, valueAccessors: ControlValueAccessor[]): export function selectValueAccessor(dir: NgControl, valueAccessors: ControlValueAccessor[]):
ControlValueAccessor { ControlValueAccessor {