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
@@ -256,13 +256,13 @@ export function main() {
});
});
describe("onChanges", () => {
describe("ngOnChanges", () => {
it("should update dom values of all the directives", () => {
form.addControl(loginControlDir);
(<Control>formModel.find(["login"])).updateValue("new value");
form.onChanges({});
form.ngOnChanges({});
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("new value");
});
@@ -271,7 +271,7 @@ export function main() {
var formValidator = (c) => ({"custom": true});
var f = new NgFormModel([formValidator], []);
f.form = formModel;
f.onChanges({"form": new SimpleChange(null, null)});
f.ngOnChanges({"form": new SimpleChange(null, null)});
expect(formModel.errors).toEqual({"custom": true});
});
@@ -279,7 +279,7 @@ export function main() {
it("should set up an async validator", fakeAsync(() => {
var f = new NgFormModel([], [asyncValidator("expected")]);
f.form = formModel;
f.onChanges({"form": new SimpleChange(null, null)});
f.ngOnChanges({"form": new SimpleChange(null, null)});
tick();
@@ -417,7 +417,7 @@ export function main() {
it("should reexport new control properties", () => {
var newControl = new Control(null);
controlDir.form = newControl;
controlDir.onChanges({"form": new SimpleChange(control, newControl)});
controlDir.ngOnChanges({"form": new SimpleChange(control, newControl)});
checkProperties(newControl);
});
@@ -426,7 +426,7 @@ export function main() {
expect(control.valid).toBe(true);
// this will add the required validator and recalculate the validity
controlDir.onChanges({"form": new SimpleChange(null, control)});
controlDir.ngOnChanges({"form": new SimpleChange(null, control)});
expect(control.valid).toBe(false);
});
@@ -455,7 +455,7 @@ export function main() {
it("should set up validator", fakeAsync(() => {
// this will add the required validator and recalculate the validity
ngModel.onChanges({});
ngModel.ngOnChanges({});
tick();
expect(ngModel.control.errors).toEqual({"required": true});
@@ -153,13 +153,13 @@ export function main() {
expect(c.value).toEqual("newValue");
});
it("should invoke onChanges if it is present", () => {
var onChanges;
c.registerOnChange((v) => onChanges = ["invoked", v]);
it("should invoke ngOnChanges if it is present", () => {
var ngOnChanges;
c.registerOnChange((v) => ngOnChanges = ["invoked", v]);
c.updateValue("newValue");
expect(onChanges).toEqual(["invoked", "newValue"]);
expect(ngOnChanges).toEqual(["invoked", "newValue"]);
});
it("should not invoke on change when explicitly specified", () => {