2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
import {CompileReflector} from './compile_reflector';
|
2016-04-28 20:50:03 -04:00
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
export enum LifecycleHooks {
|
|
|
|
OnInit,
|
|
|
|
OnDestroy,
|
|
|
|
DoCheck,
|
|
|
|
OnChanges,
|
|
|
|
AfterContentInit,
|
|
|
|
AfterContentChecked,
|
|
|
|
AfterViewInit,
|
|
|
|
AfterViewChecked
|
|
|
|
}
|
|
|
|
|
|
|
|
export const LIFECYCLE_HOOKS_VALUES = [
|
|
|
|
LifecycleHooks.OnInit, LifecycleHooks.OnDestroy, LifecycleHooks.DoCheck, LifecycleHooks.OnChanges,
|
|
|
|
LifecycleHooks.AfterContentInit, LifecycleHooks.AfterContentChecked, LifecycleHooks.AfterViewInit,
|
|
|
|
LifecycleHooks.AfterViewChecked
|
|
|
|
];
|
|
|
|
|
|
|
|
export function hasLifecycleHook(
|
|
|
|
reflector: CompileReflector, hook: LifecycleHooks, token: any): boolean {
|
|
|
|
return reflector.hasLifecycleHook(token, getHookName(hook));
|
|
|
|
}
|
2015-08-31 21:32:32 -04:00
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
export function getAllLifecycleHooks(reflector: CompileReflector, token: any): LifecycleHooks[] {
|
|
|
|
return LIFECYCLE_HOOKS_VALUES.filter(hook => hasLifecycleHook(reflector, hook, token));
|
2016-10-11 21:42:00 -04:00
|
|
|
}
|
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
function getHookName(hook: LifecycleHooks): string {
|
2016-10-11 21:42:00 -04:00
|
|
|
switch (hook) {
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.OnInit:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngOnInit';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.OnDestroy:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngOnDestroy';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.DoCheck:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngDoCheck';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.OnChanges:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngOnChanges';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.AfterContentInit:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngAfterContentInit';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.AfterContentChecked:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngAfterContentChecked';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.AfterViewInit:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngAfterViewInit';
|
2017-05-18 16:46:51 -04:00
|
|
|
case LifecycleHooks.AfterViewChecked:
|
2016-10-11 21:42:00 -04:00
|
|
|
return 'ngAfterViewChecked';
|
|
|
|
}
|
2017-02-17 15:55:55 -05:00
|
|
|
}
|