diff --git a/modules/angular2/debug.ts b/modules/angular2/debug.ts index c175b989bd..1add8b72ac 100644 --- a/modules/angular2/debug.ts +++ b/modules/angular2/debug.ts @@ -1,2 +1,5 @@ export * from './src/debug/debug_element'; -export {inspectNativeElement, ELEMENT_PROBE_CONFIG} from './src/debug/debug_element_view_listener'; +export { + inspectNativeElement, + ELEMENT_PROBE_BINDINGS +} from './src/debug/debug_element_view_listener'; diff --git a/modules/angular2/router.ts b/modules/angular2/router.ts index d3c168949a..e47435e654 100644 --- a/modules/angular2/router.ts +++ b/modules/angular2/router.ts @@ -32,19 +32,25 @@ import {RouteRegistry} from './src/router/route_registry'; import {Pipeline} from './src/router/pipeline'; import {Location} from './src/router/location'; import {APP_COMPONENT} from './src/core/application_tokens'; -import {bind} from './di'; +import {Binding} from './di'; import {CONST_EXPR} from './src/facade/lang'; import {List} from './src/facade/collection'; -export const routerDirectives: List = CONST_EXPR([RouterOutlet, RouterLink]); +export const ROUTER_DIRECTIVES: List = CONST_EXPR([RouterOutlet, RouterLink]); -export var routerInjectables: List = [ +export const ROUTER_BINDINGS: List = CONST_EXPR([ RouteRegistry, Pipeline, - bind(LocationStrategy).toClass(HTML5LocationStrategy), + CONST_EXPR(new Binding(LocationStrategy, {toClass: HTML5LocationStrategy})), Location, - bind(Router) - .toFactory((registry, pipeline, location, - appRoot) => { return new RootRouter(registry, pipeline, location, appRoot);}, - [RouteRegistry, Pipeline, Location, APP_COMPONENT]) -]; + CONST_EXPR( + new Binding(Router, + { + toFactory: routerFactory, + deps: CONST_EXPR([RouteRegistry, Pipeline, Location, APP_COMPONENT]) + })) +]); + +function routerFactory(registry, pipeline, location, appRoot) { + return new RootRouter(registry, pipeline, location, appRoot); +} diff --git a/modules/angular2/src/debug/debug_element_view_listener.ts b/modules/angular2/src/debug/debug_element_view_listener.ts index abe6e88d4e..8dd109de2c 100644 --- a/modules/angular2/src/debug/debug_element_view_listener.ts +++ b/modules/angular2/src/debug/debug_element_view_listener.ts @@ -68,7 +68,7 @@ export class DebugElementViewListener implements AppViewListener { } } -export var ELEMENT_PROBE_CONFIG = [ +export const ELEMENT_PROBE_BINDINGS = CONST_EXPR([ DebugElementViewListener, - bind(AppViewListener).toAlias(DebugElementViewListener), -]; + CONST_EXPR(new Binding(AppViewListener, {toAlias: DebugElementViewListener})), +]); diff --git a/modules/angular2/src/test_lib/test_injector.ts b/modules/angular2/src/test_lib/test_injector.ts index f66db83694..bbd1c6d3dd 100644 --- a/modules/angular2/src/test_lib/test_injector.ts +++ b/modules/angular2/src/test_lib/test_injector.ts @@ -48,7 +48,7 @@ import {FunctionWrapper, Type} from 'angular2/src/facade/lang'; import {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool'; import {AppViewManager} from 'angular2/src/core/compiler/view_manager'; import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils'; -import {ELEMENT_PROBE_CONFIG} from 'angular2/debug'; +import {ELEMENT_PROBE_BINDINGS} from 'angular2/debug'; import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory'; import {RenderCompiler, Renderer} from 'angular2/src/render/api'; import { @@ -117,7 +117,7 @@ function _getAppBindings() { AppViewManager, AppViewManagerUtils, Serializer, - ELEMENT_PROBE_CONFIG, + ELEMENT_PROBE_BINDINGS, bind(APP_VIEW_POOL_CAPACITY).toValue(500), Compiler, CompilerCache, diff --git a/modules/angular2/test/router/route_config_spec.ts b/modules/angular2/test/router/route_config_spec.ts index 3731cdba82..07aa58c5a2 100644 --- a/modules/angular2/test/router/route_config_spec.ts +++ b/modules/angular2/test/router/route_config_spec.ts @@ -19,11 +19,11 @@ import {DOCUMENT} from 'angular2/src/render/render'; import {Type} from 'angular2/src/facade/lang'; import { - routerInjectables, + ROUTER_BINDINGS, Router, RouteConfig, APP_BASE_HREF, - routerDirectives + ROUTER_DIRECTIVES } from 'angular2/router'; import {ExceptionHandler} from 'angular2/src/core/exception_handler'; @@ -47,7 +47,7 @@ export function main() { var logger = new _ArrayLogger(); var exceptionHandler = new ExceptionHandler(logger, true); testBindings = [ - routerInjectables, + ROUTER_BINDINGS, bind(LocationStrategy).toClass(MockLocationStrategy), bind(DOCUMENT).toValue(fakeDoc), bind(ExceptionHandler).toValue(exceptionHandler) @@ -145,7 +145,7 @@ class HelloCmp { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([{path: '/before', redirectTo: '/after'}, {path: '/after', component: HelloCmp}]) class RedirectAppCmp { constructor(public router: Router, public location: LocationStrategy) {} @@ -156,7 +156,7 @@ function HelloLoader(): Promise { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([ {path: '/hello', component: {type: 'loader', loader: HelloLoader}}, ]) @@ -165,7 +165,7 @@ class AsyncAppCmp { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([ {path: '/hello', component: {type: 'constructor', constructor: HelloCmp}}, ]) @@ -174,26 +174,26 @@ class ExplicitConstructorAppCmp { } @Component({selector: 'parent-cmp'}) -@View({template: `parent { }`, directives: routerDirectives}) +@View({template: `parent { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([{path: '/child', component: HelloCmp}]) class ParentCmp { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([{path: '/parent/...', component: ParentCmp}]) class HierarchyAppCmp { constructor(public router: Router, public location: LocationStrategy) {} } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([{path: '/hello'}]) class WrongConfigCmp { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([ {path: '/hello', component: {type: 'intentionallyWrongComponentType', constructor: HelloCmp}}, ]) diff --git a/modules/angular2/test/router/router_integration_spec.ts b/modules/angular2/test/router/router_integration_spec.ts index 95fbc4e10e..49dc72d53b 100644 --- a/modules/angular2/test/router/router_integration_spec.ts +++ b/modules/angular2/test/router/router_integration_spec.ts @@ -23,11 +23,11 @@ import {RouteConfig, Route, Redirect} from 'angular2/src/router/route_config_dec import {PromiseWrapper} from 'angular2/src/facade/async'; import {BaseException} from 'angular2/src/facade/lang'; import { - routerInjectables, + ROUTER_BINDINGS, RouteParams, Router, APP_BASE_HREF, - routerDirectives, + ROUTER_DIRECTIVES, HashLocationStrategy } from 'angular2/router'; @@ -37,9 +37,8 @@ import {APP_COMPONENT} from 'angular2/src/core/application_tokens'; export function main() { describe('router injectables', () => { - beforeEachBindings(() => { - return [routerInjectables, bind(LocationStrategy).toClass(MockLocationStrategy)]; - }); + beforeEachBindings( + () => { return [ROUTER_BINDINGS, bind(LocationStrategy).toClass(MockLocationStrategy)]; }); // do not refactor out the `bootstrap` functionality. We still want to // keep this test around so we can ensure that bootstrapping a router works @@ -51,7 +50,7 @@ export function main() { bootstrap(AppCmp, [ - routerInjectables, + ROUTER_BINDINGS, bind(LocationStrategy).toClass(MockLocationStrategy), bind(DOCUMENT).toValue(fakeDoc) ]) @@ -210,26 +209,26 @@ class Hello2Cmp { } @Component({selector: 'app-cmp'}) -@View({template: "outer { }", directives: routerDirectives}) +@View({template: "outer { }", directives: ROUTER_DIRECTIVES}) @RouteConfig([new Route({path: '/', component: HelloCmp})]) class AppCmp { constructor(public router: Router, public location: LocationStrategy) {} } @Component({selector: 'parent-cmp'}) -@View({template: `parent { }`, directives: routerDirectives}) +@View({template: `parent { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([new Route({path: '/child', component: HelloCmp})]) class ParentCmp { } @Component({selector: 'super-parent-cmp'}) -@View({template: `super-parent { }`, directives: routerDirectives}) +@View({template: `super-parent { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([new Route({path: '/child', component: Hello2Cmp})]) class SuperParentCmp { } @Component({selector: 'app-cmp'}) -@View({template: `root { }`, directives: routerDirectives}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([ new Route({path: '/parent/...', component: ParentCmp}), new Route({path: '/super-parent/...', component: SuperParentCmp}) @@ -246,7 +245,7 @@ class QSCmp { } @Component({selector: 'app-cmp'}) -@View({template: ``, directives: routerDirectives}) +@View({template: ``, directives: ROUTER_DIRECTIVES}) @RouteConfig([new Route({path: '/qs', component: QSCmp})]) class QueryStringAppCmp { constructor(public router: Router, public location: LocationStrategy) {} @@ -259,7 +258,7 @@ class BrokenCmp { } @Component({selector: 'app-cmp'}) -@View({template: `outer { }`, directives: routerDirectives}) +@View({template: `outer { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([new Route({path: '/cause-error', component: BrokenCmp})]) class BrokenAppCmp { constructor(public router: Router, public location: LocationStrategy) {} diff --git a/modules/examples/src/routing/index.ts b/modules/examples/src/routing/index.ts index eb0969ba70..f77ab4c146 100644 --- a/modules/examples/src/routing/index.ts +++ b/modules/examples/src/routing/index.ts @@ -1,12 +1,12 @@ import {InboxApp} from './inbox-app'; import {bind} from 'angular2/angular2'; import {bootstrap} from 'angular2/bootstrap'; -import {routerInjectables, HashLocationStrategy, LocationStrategy} from 'angular2/router'; +import {ROUTER_BINDINGS, HashLocationStrategy, LocationStrategy} from 'angular2/router'; import {reflector} from 'angular2/src/reflection/reflection'; import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; export function main() { reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(InboxApp, [routerInjectables, bind(LocationStrategy).toClass(HashLocationStrategy)]); + bootstrap(InboxApp, [ROUTER_BINDINGS, bind(LocationStrategy).toClass(HashLocationStrategy)]); } diff --git a/typing_spec/router_spec.ts b/typing_spec/router_spec.ts index ea6ca0154a..a33d71dc06 100644 --- a/typing_spec/router_spec.ts +++ b/typing_spec/router_spec.ts @@ -2,7 +2,7 @@ /// import {Component, bootstrap, View} from 'angular2/angular2'; -import {RouteConfig, routerDirectives, routerInjectables} from 'angular2/router'; +import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_BINDINGS} from 'angular2/router'; @Component({ selector: 'my-app' @@ -19,7 +19,7 @@ class FooCmp { }) @View({ template: '

Hello {{ name }}

', - directives: routerDirectives + directives: ROUTER_DIRECTIVES }) @RouteConfig([ {path: '/home', component: FooCmp} @@ -30,4 +30,4 @@ class MyAppComponent { constructor() { this.name = 'Alice'; } } -bootstrap(MyAppComponent, routerInjectables); +bootstrap(MyAppComponent, ROUTER_BINDINGS);