2015-11-06 17:34:07 -08:00
|
|
|
import {Type, isPresent} from 'angular2/src/facade/lang';
|
2015-07-07 15:44:29 -07:00
|
|
|
import {RouteLifecycleHook, CanActivate} from './lifecycle_annotations_impl';
|
2015-08-20 14:28:25 -07:00
|
|
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
2015-07-07 15:44:29 -07:00
|
|
|
|
|
|
|
|
export function hasLifecycleHook(e: RouteLifecycleHook, type): boolean {
|
|
|
|
|
if (!(type instanceof Type)) return false;
|
|
|
|
|
return e.name in(<any>type).prototype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCanActivateHook(type): Function {
|
|
|
|
|
var annotations = reflector.annotations(type);
|
|
|
|
|
for (let i = 0; i < annotations.length; i += 1) {
|
|
|
|
|
let annotation = annotations[i];
|
|
|
|
|
if (annotation instanceof CanActivate) {
|
|
|
|
|
return annotation.fn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|