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

View File

@ -10,40 +10,40 @@ The class constructor is called before any other lifecycle hook. Use it to injec
@cheatsheetItem
`onChanges(changeRecord) { ... }`|`onChanges(changeRecord)`
`ngOnChanges(changeRecord) { ... }`|`ngOnChanges(changeRecord)`
Called after every change to input properties and before processing content or child views.
@cheatsheetItem
`onInit() { ... }`|`onInit()`
Called after the constructor, initializing input properties, and the first call to onChanges.
`ngOnInit() { ... }`|`ngOnInit()`
Called after the constructor, initializing input properties, and the first call to ngOnChanges.
@cheatsheetItem
`doCheck() { ... }`|`doCheck()`
`ngDoCheck() { ... }`|`ngDoCheck()`
Called every time that the input properties of a component or a directive are checked. Use it to extend change detection by performing a custom check.
@cheatsheetItem
`afterContentInit() { ... }`|`afterContentInit()`
Called after onInit when the component's or directive's content has been initialized.
`ngAfterContentInit() { ... }`|`ngAfterContentInit()`
Called after ngOnInit when the component's or directive's content has been initialized.
@cheatsheetItem
`afterContentChecked() { ... }`|`afterContentChecked()`
`ngAfterContentChecked() { ... }`|`ngAfterContentChecked()`
Called after every check of the component's or directive's content.
@cheatsheetItem
`afterViewInit() { ... }`|`afterViewInit()`
Called after afterContentInit when the component's view has been initialized. Applies to components only.
`ngAfterViewInit() { ... }`|`ngAfterViewInit()`
Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
@cheatsheetItem
`afterViewChecked() { ... }`|`afterViewChecked()`
`ngAfterViewChecked() { ... }`|`ngAfterViewChecked()`
Called after every check of the component's view. Applies to components only.
@cheatsheetItem
`onDestroy() { ... }`|`onDestroy()`
`ngOnDestroy() { ... }`|`ngOnDestroy()`
Called once, before the instance is destroyed.

View File

@ -31,25 +31,25 @@ A component decorator defining a function that the router should call first to d
@cheatsheetItem
`onActivate(nextInstruction, prevInstruction) { ... }`|`onActivate`
After navigating to a component, the router calls component's onActivate method (if defined).
`routerOnActivate(nextInstruction, prevInstruction) { ... }`|`routerOnActivate`
After navigating to a component, the router calls component's routerOnActivate method (if defined).
@cheatsheetItem
`canReuse(nextInstruction, prevInstruction) { ... }`|`canReuse`
The router calls a component's canReuse method (if defined) to determine whether to reuse the instance or destroy it and create a new instance. Should return a boolean or a promise.
`routerCanReuse(nextInstruction, prevInstruction) { ... }`|`routerCanReuse`
The router calls a component's routerCanReuse method (if defined) to determine whether to reuse the instance or destroy it and create a new instance. Should return a boolean or a promise.
@cheatsheetItem
`onReuse(nextInstruction, prevInstruction) { ... }`|`onReuse`
The router calls the component's onReuse method (if defined) when it re-uses a component instance.
`routerOnReuse(nextInstruction, prevInstruction) { ... }`|`routerOnReuse`
The router calls the component's routerOnReuse method (if defined) when it re-uses a component instance.
@cheatsheetItem
`canDeactivate(nextInstruction, prevInstruction) { ... }`|`canDeactivate`
The router calls the canDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a promise that is resolved.
`routerCanDeactivate(nextInstruction, prevInstruction) { ... }`|`routerCanDeactivate`
The router calls the routerCanDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a promise that is resolved.
@cheatsheetItem
`onDeactivate(nextInstruction, prevInstruction) { ... }`|`onDeactivate`
`routerOnDeactivate(nextInstruction, prevInstruction) { ... }`|`routerOnDeactivate`
Called before the directive is removed as the result of a route change. May return a promise that pauses removing the directive until the promise resolves.