angular-cn/modules/@angular/compiler/src/directive_lifecycle_reflect...

30 lines
951 B
TypeScript
Raw Normal View History

import {Type} from 'angular2/src/facade/lang';
import {LifecycleHooks} from 'angular2/src/core/metadata/lifecycle_hooks';
2015-09-11 17:23:24 -04:00
export function hasLifecycleHook(lcInterface: LifecycleHooks, token): boolean {
if (!(token instanceof Type)) return false;
2015-09-11 17:23:24 -04:00
var proto = (<any>token).prototype;
switch (lcInterface) {
2015-09-11 17:23:24 -04:00
case LifecycleHooks.AfterContentInit:
return !!proto.ngAfterContentInit;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.AfterContentChecked:
return !!proto.ngAfterContentChecked;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.AfterViewInit:
return !!proto.ngAfterViewInit;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.AfterViewChecked:
return !!proto.ngAfterViewChecked;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.OnChanges:
return !!proto.ngOnChanges;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.DoCheck:
return !!proto.ngDoCheck;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.OnDestroy:
return !!proto.ngOnDestroy;
2015-09-11 17:23:24 -04:00
case LifecycleHooks.OnInit:
return !!proto.ngOnInit;
default:
return false;
}
}