Skip to content

Commit 43f97a9

Browse files
committed
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.
1 parent a443ea6 commit 43f97a9

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
library angular2.src.router.route_config_normalizer;
22

33
import "route_config_decorator.dart";
4+
import "package:angular2/src/core/facade/exceptions.dart" show BaseException;
45

56
RouteDefinition normalizeRouteConfig(RouteDefinition config) {
67
return config;
78
}
9+
10+
void assertComponentExists(Type component, String path) {
11+
if (component == null) {
12+
throw new BaseException('Component for route "${path}" is not defined, or is not a class.');
13+
}
14+
}

modules/angular2/src/router/route_config_nomalizer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {AsyncRoute, AuxRoute, Route, Redirect, RouteDefinition} from './route_config_decorator';
22
import {ComponentDefinition} from './route_definition';
3-
import {Type} from 'angular2/src/core/facade/lang';
3+
import {isType, Type} from 'angular2/src/core/facade/lang';
44
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
55

66

@@ -47,3 +47,9 @@ export function normalizeRouteConfig(config: RouteDefinition): RouteDefinition {
4747

4848
return config;
4949
}
50+
51+
export function assertComponentExists(component: Type, path: string): void {
52+
if (!isType(component)) {
53+
throw new BaseException(`Component for route "${path}" is not defined, or is not a class.`);
54+
}
55+
}

modules/angular2/src/router/route_registry.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
} from './route_config_impl';
3232
import {reflector} from 'angular2/src/core/reflection/reflection';
3333
import {Injectable} from 'angular2/src/core/di';
34-
import {normalizeRouteConfig} from './route_config_nomalizer';
34+
import {normalizeRouteConfig, assertComponentExists} from './route_config_nomalizer';
3535
import {parser, Url, pathSegmentsToUrl} from './url_parser';
3636

3737
var _resolveToNull = PromiseWrapper.resolve(null);
@@ -318,9 +318,3 @@ function assertTerminalComponent(component, path) {
318318
}
319319
}
320320
}
321-
322-
function assertComponentExists(component: Type, path: string): void {
323-
if (!isType(component)) {
324-
throw new BaseException(`Component for route "${path}" is not defined, or is not a class.`);
325-
}
326-
}

0 commit comments

Comments
 (0)