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
|
|
|
|
*/
|
|
|
|
|
2016-08-10 21:21:28 -04:00
|
|
|
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit, Type} from '@angular/core';
|
2016-08-02 18:53:34 -04:00
|
|
|
|
2016-08-30 21:07:40 -04:00
|
|
|
import {LifecycleHooks, reflector} from './private_import_core';
|
2016-04-28 20:50:03 -04:00
|
|
|
|
2015-08-31 21:32:32 -04:00
|
|
|
|
2016-06-28 14:35:59 -04:00
|
|
|
export function hasLifecycleHook(hook: LifecycleHooks, token: any): boolean {
|
2016-10-11 21:42:00 -04:00
|
|
|
return reflector.hasLifecycleHook(token, getInterface(hook), getHookName(hook));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHookName(hook: LifecycleHooks): string {
|
|
|
|
switch (hook) {
|
|
|
|
case LifecycleHooks.OnInit:
|
|
|
|
return 'ngOnInit';
|
|
|
|
case LifecycleHooks.OnDestroy:
|
|
|
|
return 'ngOnDestroy';
|
|
|
|
case LifecycleHooks.DoCheck:
|
|
|
|
return 'ngDoCheck';
|
|
|
|
case LifecycleHooks.OnChanges:
|
|
|
|
return 'ngOnChanges';
|
|
|
|
case LifecycleHooks.AfterContentInit:
|
|
|
|
return 'ngAfterContentInit';
|
|
|
|
case LifecycleHooks.AfterContentChecked:
|
|
|
|
return 'ngAfterContentChecked';
|
|
|
|
case LifecycleHooks.AfterViewInit:
|
|
|
|
return 'ngAfterViewInit';
|
|
|
|
case LifecycleHooks.AfterViewChecked:
|
|
|
|
return 'ngAfterViewChecked';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getInterface(hook: LifecycleHooks): any {
|
|
|
|
switch (hook) {
|
|
|
|
case LifecycleHooks.OnInit:
|
|
|
|
return OnInit;
|
|
|
|
case LifecycleHooks.OnDestroy:
|
|
|
|
return OnDestroy;
|
|
|
|
case LifecycleHooks.DoCheck:
|
|
|
|
return DoCheck;
|
|
|
|
case LifecycleHooks.OnChanges:
|
|
|
|
return OnChanges;
|
|
|
|
case LifecycleHooks.AfterContentInit:
|
|
|
|
return AfterContentInit;
|
|
|
|
case LifecycleHooks.AfterContentChecked:
|
|
|
|
return AfterContentChecked;
|
|
|
|
case LifecycleHooks.AfterViewInit:
|
|
|
|
return AfterViewInit;
|
|
|
|
case LifecycleHooks.AfterViewChecked:
|
|
|
|
return AfterViewChecked;
|
|
|
|
}
|
2015-07-04 09:04:50 -04:00
|
|
|
}
|