feat(router): add CanDeactivate

This commit is contained in:
vsavkin 2016-04-29 18:05:06 -07:00
parent e5b87e55da
commit deba804671
4 changed files with 9 additions and 2 deletions

View File

@ -3,4 +3,9 @@ import {RouteSegment, Tree} from './segments';
export interface OnActivate {
routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: Tree<RouteSegment>,
prevTree?: Tree<RouteSegment>): void;
}
export interface CanDeactivate {
routerCanDeactivate(currTree?: Tree<RouteSegment>,
futureTree?: Tree<RouteSegment>): Promise<boolean>;
}

View File

@ -1,5 +1,6 @@
import './interfaces.dart';
bool hasLifecycleHook(String name, Object obj) {
if (name == "routerOnActivate") return obj is OnActivate;
if (name == "routerCanDeactivate") return obj is CanDeactivate;
return false;
}

View File

@ -1,6 +1,7 @@
import {Type} from 'angular2/src/facade/lang';
import {Type, isBlank} from 'angular2/src/facade/lang';
export function hasLifecycleHook(name: string, obj: Object): boolean {
if (isBlank(obj)) return false;
let type = obj.constructor;
if (!(type instanceof Type)) return false;
return name in(<any>type).prototype;

View File

@ -1,4 +1,4 @@
import {Type, isPresent} from 'angular2/src/facade/lang';
import {Type, isBlank} from 'angular2/src/facade/lang';
import {RouteLifecycleHook, CanActivate} from './lifecycle_annotations_impl';
import {reflector} from 'angular2/src/core/reflection/reflection';