From 43f97a951c99683e1119dae12b323f70ded61296 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Fri, 18 Sep 2015 15:41:02 -0700 Subject: [PATCH] refactor(router): move assertComponentExists into facade This is to make way for a refactor to the ng 1.x router directives, which will use strings rather than controller functions in route configs. --- modules/angular2/src/router/route_config_nomalizer.dart | 7 +++++++ modules/angular2/src/router/route_config_nomalizer.ts | 8 +++++++- modules/angular2/src/router/route_registry.ts | 8 +------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/angular2/src/router/route_config_nomalizer.dart b/modules/angular2/src/router/route_config_nomalizer.dart index dc0e3597a1..c28f7027f2 100644 --- a/modules/angular2/src/router/route_config_nomalizer.dart +++ b/modules/angular2/src/router/route_config_nomalizer.dart @@ -1,7 +1,14 @@ library angular2.src.router.route_config_normalizer; import "route_config_decorator.dart"; +import "package:angular2/src/core/facade/exceptions.dart" show BaseException; RouteDefinition normalizeRouteConfig(RouteDefinition config) { return config; } + +void assertComponentExists(Type component, String path) { + if (component == null) { + throw new BaseException('Component for route "${path}" is not defined, or is not a class.'); + } +} diff --git a/modules/angular2/src/router/route_config_nomalizer.ts b/modules/angular2/src/router/route_config_nomalizer.ts index 7661a191d5..d3eca00ad0 100644 --- a/modules/angular2/src/router/route_config_nomalizer.ts +++ b/modules/angular2/src/router/route_config_nomalizer.ts @@ -1,6 +1,6 @@ import {AsyncRoute, AuxRoute, Route, Redirect, RouteDefinition} from './route_config_decorator'; import {ComponentDefinition} from './route_definition'; -import {Type} from 'angular2/src/core/facade/lang'; +import {isType, Type} from 'angular2/src/core/facade/lang'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; @@ -47,3 +47,9 @@ export function normalizeRouteConfig(config: RouteDefinition): RouteDefinition { return config; } + +export function assertComponentExists(component: Type, path: string): void { + if (!isType(component)) { + throw new BaseException(`Component for route "${path}" is not defined, or is not a class.`); + } +} diff --git a/modules/angular2/src/router/route_registry.ts b/modules/angular2/src/router/route_registry.ts index 5b8793bd53..33756a43b6 100644 --- a/modules/angular2/src/router/route_registry.ts +++ b/modules/angular2/src/router/route_registry.ts @@ -31,7 +31,7 @@ import { } from './route_config_impl'; import {reflector} from 'angular2/src/core/reflection/reflection'; import {Injectable} from 'angular2/src/core/di'; -import {normalizeRouteConfig} from './route_config_nomalizer'; +import {normalizeRouteConfig, assertComponentExists} from './route_config_nomalizer'; import {parser, Url, pathSegmentsToUrl} from './url_parser'; var _resolveToNull = PromiseWrapper.resolve(null); @@ -318,9 +318,3 @@ function assertTerminalComponent(component, path) { } } } - -function assertComponentExists(component: Type, path: string): void { - if (!isType(component)) { - throw new BaseException(`Component for route "${path}" is not defined, or is not a class.`); - } -}