refactor(lifecycle): prefix lifecycle methods with "ng"

BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.

To fix, just rename these methods:
 * onInit
 * onDestroy
 * doCheck
 * onChanges
 * afterContentInit
 * afterContentChecked
 * afterViewInit
 * afterViewChecked
 * _Router Hooks_
 * onActivate
 * onReuse
 * onDeactivate
 * canReuse
 * canDeactivate

To:
 * ngOnInit,
 * ngOnDestroy,
 * ngDoCheck,
 * ngOnChanges,
 * ngAfterContentInit,
 * ngAfterContentChecked,
 * ngAfterViewInit,
 * ngAfterViewChecked
 * _Router Hooks_
 * routerOnActivate
 * routerOnReuse
 * routerOnDeactivate
 * routerCanReuse
 * routerCanDeactivate

The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.

Closes #5036
This commit is contained in:
Jeff Cross
2015-11-16 17:04:36 -08:00
committed by vsavkin
parent 4215afc639
commit 604c8bbad5
63 changed files with 618 additions and 583 deletions
@@ -108,7 +108,7 @@ export class NgClass implements DoCheck, OnDestroy {
}
}
doCheck(): void {
ngDoCheck(): void {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._rawClass);
if (isPresent(changes)) {
@@ -121,7 +121,7 @@ export class NgClass implements DoCheck, OnDestroy {
}
}
onDestroy(): void { this._cleanupClasses(this._rawClass); }
ngOnDestroy(): void { this._cleanupClasses(this._rawClass); }
private _cleanupClasses(rawClassVal): void {
this._applyClasses(rawClassVal, true);
@@ -81,7 +81,7 @@ export class NgFor implements DoCheck {
}
}
doCheck() {
ngDoCheck() {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._ngForOf);
if (isPresent(changes)) this._applyChanges(changes);
@@ -75,7 +75,7 @@ export class NgStyle implements DoCheck {
}
}
doCheck() {
ngDoCheck() {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._rawStyle);
if (isPresent(changes)) {
@@ -87,9 +87,9 @@ export class NgControlGroup extends ControlContainer implements OnInit,
this._parent = parent;
}
onInit(): void { this.formDirective.addControlGroup(this); }
ngOnInit(): void { this.formDirective.addControlGroup(this); }
onDestroy(): void { this.formDirective.removeControlGroup(this); }
ngOnDestroy(): void { this.formDirective.removeControlGroup(this); }
/**
* Get the {@link ControlGroup} backing this binding.
@@ -114,7 +114,7 @@ export class NgControlName extends NgControl implements OnChanges,
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
onChanges(changes: {[key: string]: SimpleChange}) {
ngOnChanges(changes: {[key: string]: SimpleChange}) {
if (!this._added) {
this.formDirective.addControl(this);
this._added = true;
@@ -125,7 +125,7 @@ export class NgControlName extends NgControl implements OnChanges,
}
}
onDestroy(): void { this.formDirective.removeControl(this); }
ngOnDestroy(): void { this.formDirective.removeControl(this); }
viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
@@ -97,7 +97,7 @@ export class NgFormControl extends NgControl implements OnChanges {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
onChanges(changes: {[key: string]: SimpleChange}): void {
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
if (this._isControlChanged(changes)) {
setUpControl(this.form, this);
this.form.updateValueAndValidity({emitEvent: false});
@@ -113,7 +113,7 @@ export class NgFormModel extends ControlContainer implements Form,
super();
}
onChanges(changes: {[key: string]: SimpleChange}): void {
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
if (StringMapWrapper.contains(changes, "form")) {
var sync = composeValidators(this._validators);
this.form.validator = Validators.compose([this.form.validator, sync]);
@@ -71,7 +71,7 @@ export class NgModel extends NgControl implements OnChanges {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
onChanges(changes: {[key: string]: SimpleChange}) {
ngOnChanges(changes: {[key: string]: SimpleChange}) {
if (!this._added) {
setUpControl(this._control, this);
this._control.updateValueAndValidity({emitEvent: false});