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
@@ -85,7 +85,7 @@ export class MdAnchor extends MdButton implements OnChanges {
}
/** Invoked when a change is detected. */
onChanges(_) {
ngOnChanges(_) {
// A disabled anchor should not be in the tab flow.
this.tabIndex = this.disabled ? -1 : 0;
}
@@ -86,7 +86,7 @@ export class MdGridList implements AfterContentChecked {
}
}
afterContentChecked() {
ngAfterContentChecked() {
this.layoutTiles();
}
@@ -267,7 +267,7 @@ export class MdGridTile implements OnDestroy,
* Change handler invoked when bindings are resolved or when bindings have changed.
* Notifies grid-list that a re-layout is required.
*/
onChanges(_) {
ngOnChanges(_) {
if (!this.isRegisteredWithGridList) {
this.gridList.addTile(this);
this.isRegisteredWithGridList = true;
@@ -277,7 +277,7 @@ export class MdGridTile implements OnDestroy,
/**
* Destructor function. Deregisters this tile from the containing grid-list.
*/
onDestroy() {
ngOnDestroy() {
this.gridList.removeTile(this);
}
}
@@ -30,7 +30,7 @@ export class MdInputContainer implements AfterContentChecked {
this.inputHasFocus = false;
}
afterContentChecked() {
ngAfterContentChecked() {
// Enforce that this directive actually contains a text input.
if (this._input == null) {
throw 'No <input> or <textarea> found inside of <md-input-container>';
@@ -60,7 +60,7 @@ export class MdProgressLinear implements OnChanges {
}
}
onChanges(_) {
ngOnChanges(_) {
// If the mode does not use a value, or if there is no value, do nothing.
if (this.mode == ProgressMode.QUERY || this.mode == ProgressMode.INDETERMINATE ||
isBlank(this.value)) {
@@ -102,7 +102,7 @@ export class MdRadioGroup implements OnChanges {
}
/** Change handler invoked when bindings are resolved or when bindings have changed. */
onChanges(_) {
ngOnChanges(_) {
// If the component has a disabled attribute with no value, it will set disabled = ''.
this.disabled = isPresent(this.disabled) && this.disabled !== false;
@@ -263,7 +263,7 @@ export class MdRadioButton implements OnInit {
}
/** Change handler invoked when bindings are resolved or when bindings have changed. */
onInit() {
ngOnInit() {
if (isPresent(this.radioGroup)) {
this.name = this.radioGroup.getName();
}