From deba80467141812a30408ab967ca80694f96d547 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 29 Apr 2016 18:05:06 -0700 Subject: [PATCH] feat(router): add CanDeactivate --- modules/angular2/src/alt_router/interfaces.ts | 5 +++++ modules/angular2/src/alt_router/lifecycle_reflector.dart | 1 + modules/angular2/src/alt_router/lifecycle_reflector.ts | 3 ++- .../src/router/lifecycle/route_lifecycle_reflector.ts | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/alt_router/interfaces.ts b/modules/angular2/src/alt_router/interfaces.ts index 136e8a0034..8d5a35aae4 100644 --- a/modules/angular2/src/alt_router/interfaces.ts +++ b/modules/angular2/src/alt_router/interfaces.ts @@ -3,4 +3,9 @@ import {RouteSegment, Tree} from './segments'; export interface OnActivate { routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: Tree, prevTree?: Tree): void; +} + +export interface CanDeactivate { + routerCanDeactivate(currTree?: Tree, + futureTree?: Tree): Promise; } \ No newline at end of file diff --git a/modules/angular2/src/alt_router/lifecycle_reflector.dart b/modules/angular2/src/alt_router/lifecycle_reflector.dart index 2a5546def5..197df5fd48 100644 --- a/modules/angular2/src/alt_router/lifecycle_reflector.dart +++ b/modules/angular2/src/alt_router/lifecycle_reflector.dart @@ -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; } diff --git a/modules/angular2/src/alt_router/lifecycle_reflector.ts b/modules/angular2/src/alt_router/lifecycle_reflector.ts index 7d50894692..781ca86965 100644 --- a/modules/angular2/src/alt_router/lifecycle_reflector.ts +++ b/modules/angular2/src/alt_router/lifecycle_reflector.ts @@ -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(type).prototype; diff --git a/modules/angular2/src/router/lifecycle/route_lifecycle_reflector.ts b/modules/angular2/src/router/lifecycle/route_lifecycle_reflector.ts index d8345dedfc..3f90dadb79 100644 --- a/modules/angular2/src/router/lifecycle/route_lifecycle_reflector.ts +++ b/modules/angular2/src/router/lifecycle/route_lifecycle_reflector.ts @@ -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';