refactor: make bindings/directives names consistent

BREAKING CHANGE

- `routerDirectives` => `ROUTER_DIRECTIVES`
- `routerInjectables` => `ROUTER_BINDINGS`
- `ELEMENT_PROBE_CONFIG` => `ELEMENT_PROBE_BINDINGS`
This commit is contained in:
Misko Hevery 2015-08-18 14:46:35 -07:00
parent 8dc509f688
commit ccfadb9b47
8 changed files with 50 additions and 42 deletions

View File

@ -1,2 +1,5 @@
export * from './src/debug/debug_element'; 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';

View File

@ -32,19 +32,25 @@ import {RouteRegistry} from './src/router/route_registry';
import {Pipeline} from './src/router/pipeline'; import {Pipeline} from './src/router/pipeline';
import {Location} from './src/router/location'; import {Location} from './src/router/location';
import {APP_COMPONENT} from './src/core/application_tokens'; import {APP_COMPONENT} from './src/core/application_tokens';
import {bind} from './di'; import {Binding} from './di';
import {CONST_EXPR} from './src/facade/lang'; import {CONST_EXPR} from './src/facade/lang';
import {List} from './src/facade/collection'; import {List} from './src/facade/collection';
export const routerDirectives: List<any> = CONST_EXPR([RouterOutlet, RouterLink]); export const ROUTER_DIRECTIVES: List<any> = CONST_EXPR([RouterOutlet, RouterLink]);
export var routerInjectables: List<any> = [ export const ROUTER_BINDINGS: List<any> = CONST_EXPR([
RouteRegistry, RouteRegistry,
Pipeline, Pipeline,
bind(LocationStrategy).toClass(HTML5LocationStrategy), CONST_EXPR(new Binding(LocationStrategy, {toClass: HTML5LocationStrategy})),
Location, Location,
bind(Router) CONST_EXPR(
.toFactory((registry, pipeline, location, new Binding(Router,
appRoot) => { return new RootRouter(registry, pipeline, location, appRoot);}, {
[RouteRegistry, Pipeline, Location, APP_COMPONENT]) toFactory: routerFactory,
]; deps: CONST_EXPR([RouteRegistry, Pipeline, Location, APP_COMPONENT])
}))
]);
function routerFactory(registry, pipeline, location, appRoot) {
return new RootRouter(registry, pipeline, location, appRoot);
}

View File

@ -68,7 +68,7 @@ export class DebugElementViewListener implements AppViewListener {
} }
} }
export var ELEMENT_PROBE_CONFIG = [ export const ELEMENT_PROBE_BINDINGS = CONST_EXPR([
DebugElementViewListener, DebugElementViewListener,
bind(AppViewListener).toAlias(DebugElementViewListener), CONST_EXPR(new Binding(AppViewListener, {toAlias: DebugElementViewListener})),
]; ]);

View File

@ -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 {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager'; import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils'; 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 {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
import {RenderCompiler, Renderer} from 'angular2/src/render/api'; import {RenderCompiler, Renderer} from 'angular2/src/render/api';
import { import {
@ -117,7 +117,7 @@ function _getAppBindings() {
AppViewManager, AppViewManager,
AppViewManagerUtils, AppViewManagerUtils,
Serializer, Serializer,
ELEMENT_PROBE_CONFIG, ELEMENT_PROBE_BINDINGS,
bind(APP_VIEW_POOL_CAPACITY).toValue(500), bind(APP_VIEW_POOL_CAPACITY).toValue(500),
Compiler, Compiler,
CompilerCache, CompilerCache,

View File

@ -19,11 +19,11 @@ import {DOCUMENT} from 'angular2/src/render/render';
import {Type} from 'angular2/src/facade/lang'; import {Type} from 'angular2/src/facade/lang';
import { import {
routerInjectables, ROUTER_BINDINGS,
Router, Router,
RouteConfig, RouteConfig,
APP_BASE_HREF, APP_BASE_HREF,
routerDirectives ROUTER_DIRECTIVES
} from 'angular2/router'; } from 'angular2/router';
import {ExceptionHandler} from 'angular2/src/core/exception_handler'; import {ExceptionHandler} from 'angular2/src/core/exception_handler';
@ -47,7 +47,7 @@ export function main() {
var logger = new _ArrayLogger(); var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, true); var exceptionHandler = new ExceptionHandler(logger, true);
testBindings = [ testBindings = [
routerInjectables, ROUTER_BINDINGS,
bind(LocationStrategy).toClass(MockLocationStrategy), bind(LocationStrategy).toClass(MockLocationStrategy),
bind(DOCUMENT).toValue(fakeDoc), bind(DOCUMENT).toValue(fakeDoc),
bind(ExceptionHandler).toValue(exceptionHandler) bind(ExceptionHandler).toValue(exceptionHandler)
@ -145,7 +145,7 @@ class HelloCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([{path: '/before', redirectTo: '/after'}, {path: '/after', component: HelloCmp}]) @RouteConfig([{path: '/before', redirectTo: '/after'}, {path: '/after', component: HelloCmp}])
class RedirectAppCmp { class RedirectAppCmp {
constructor(public router: Router, public location: LocationStrategy) {} constructor(public router: Router, public location: LocationStrategy) {}
@ -156,7 +156,7 @@ function HelloLoader(): Promise<any> {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([ @RouteConfig([
{path: '/hello', component: {type: 'loader', loader: HelloLoader}}, {path: '/hello', component: {type: 'loader', loader: HelloLoader}},
]) ])
@ -165,7 +165,7 @@ class AsyncAppCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([ @RouteConfig([
{path: '/hello', component: {type: 'constructor', constructor: HelloCmp}}, {path: '/hello', component: {type: 'constructor', constructor: HelloCmp}},
]) ])
@ -174,26 +174,26 @@ class ExplicitConstructorAppCmp {
} }
@Component({selector: 'parent-cmp'}) @Component({selector: 'parent-cmp'})
@View({template: `parent { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `parent { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([{path: '/child', component: HelloCmp}]) @RouteConfig([{path: '/child', component: HelloCmp}])
class ParentCmp { class ParentCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([{path: '/parent/...', component: ParentCmp}]) @RouteConfig([{path: '/parent/...', component: ParentCmp}])
class HierarchyAppCmp { class HierarchyAppCmp {
constructor(public router: Router, public location: LocationStrategy) {} constructor(public router: Router, public location: LocationStrategy) {}
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([{path: '/hello'}]) @RouteConfig([{path: '/hello'}])
class WrongConfigCmp { class WrongConfigCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([ @RouteConfig([
{path: '/hello', component: {type: 'intentionallyWrongComponentType', constructor: HelloCmp}}, {path: '/hello', component: {type: 'intentionallyWrongComponentType', constructor: HelloCmp}},
]) ])

View File

@ -23,11 +23,11 @@ import {RouteConfig, Route, Redirect} from 'angular2/src/router/route_config_dec
import {PromiseWrapper} from 'angular2/src/facade/async'; import {PromiseWrapper} from 'angular2/src/facade/async';
import {BaseException} from 'angular2/src/facade/lang'; import {BaseException} from 'angular2/src/facade/lang';
import { import {
routerInjectables, ROUTER_BINDINGS,
RouteParams, RouteParams,
Router, Router,
APP_BASE_HREF, APP_BASE_HREF,
routerDirectives, ROUTER_DIRECTIVES,
HashLocationStrategy HashLocationStrategy
} from 'angular2/router'; } from 'angular2/router';
@ -37,9 +37,8 @@ import {APP_COMPONENT} from 'angular2/src/core/application_tokens';
export function main() { export function main() {
describe('router injectables', () => { describe('router injectables', () => {
beforeEachBindings(() => { beforeEachBindings(
return [routerInjectables, bind(LocationStrategy).toClass(MockLocationStrategy)]; () => { return [ROUTER_BINDINGS, bind(LocationStrategy).toClass(MockLocationStrategy)]; });
});
// do not refactor out the `bootstrap` functionality. We still want to // do not refactor out the `bootstrap` functionality. We still want to
// keep this test around so we can ensure that bootstrapping a router works // keep this test around so we can ensure that bootstrapping a router works
@ -51,7 +50,7 @@ export function main() {
bootstrap(AppCmp, bootstrap(AppCmp,
[ [
routerInjectables, ROUTER_BINDINGS,
bind(LocationStrategy).toClass(MockLocationStrategy), bind(LocationStrategy).toClass(MockLocationStrategy),
bind(DOCUMENT).toValue(fakeDoc) bind(DOCUMENT).toValue(fakeDoc)
]) ])
@ -210,26 +209,26 @@ class Hello2Cmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: "outer { <router-outlet></router-outlet> }", directives: routerDirectives}) @View({template: "outer { <router-outlet></router-outlet> }", directives: ROUTER_DIRECTIVES})
@RouteConfig([new Route({path: '/', component: HelloCmp})]) @RouteConfig([new Route({path: '/', component: HelloCmp})])
class AppCmp { class AppCmp {
constructor(public router: Router, public location: LocationStrategy) {} constructor(public router: Router, public location: LocationStrategy) {}
} }
@Component({selector: 'parent-cmp'}) @Component({selector: 'parent-cmp'})
@View({template: `parent { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `parent { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([new Route({path: '/child', component: HelloCmp})]) @RouteConfig([new Route({path: '/child', component: HelloCmp})])
class ParentCmp { class ParentCmp {
} }
@Component({selector: 'super-parent-cmp'}) @Component({selector: 'super-parent-cmp'})
@View({template: `super-parent { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `super-parent { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([new Route({path: '/child', component: Hello2Cmp})]) @RouteConfig([new Route({path: '/child', component: Hello2Cmp})])
class SuperParentCmp { class SuperParentCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `root { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([ @RouteConfig([
new Route({path: '/parent/...', component: ParentCmp}), new Route({path: '/parent/...', component: ParentCmp}),
new Route({path: '/super-parent/...', component: SuperParentCmp}) new Route({path: '/super-parent/...', component: SuperParentCmp})
@ -246,7 +245,7 @@ class QSCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `<router-outlet></router-outlet>`, directives: routerDirectives}) @View({template: `<router-outlet></router-outlet>`, directives: ROUTER_DIRECTIVES})
@RouteConfig([new Route({path: '/qs', component: QSCmp})]) @RouteConfig([new Route({path: '/qs', component: QSCmp})])
class QueryStringAppCmp { class QueryStringAppCmp {
constructor(public router: Router, public location: LocationStrategy) {} constructor(public router: Router, public location: LocationStrategy) {}
@ -259,7 +258,7 @@ class BrokenCmp {
} }
@Component({selector: 'app-cmp'}) @Component({selector: 'app-cmp'})
@View({template: `outer { <router-outlet></router-outlet> }`, directives: routerDirectives}) @View({template: `outer { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
@RouteConfig([new Route({path: '/cause-error', component: BrokenCmp})]) @RouteConfig([new Route({path: '/cause-error', component: BrokenCmp})])
class BrokenAppCmp { class BrokenAppCmp {
constructor(public router: Router, public location: LocationStrategy) {} constructor(public router: Router, public location: LocationStrategy) {}

View File

@ -1,12 +1,12 @@
import {InboxApp} from './inbox-app'; import {InboxApp} from './inbox-app';
import {bind} from 'angular2/angular2'; import {bind} from 'angular2/angular2';
import {bootstrap} from 'angular2/bootstrap'; 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 {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
export function main() { export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities(); reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(InboxApp, [routerInjectables, bind(LocationStrategy).toClass(HashLocationStrategy)]); bootstrap(InboxApp, [ROUTER_BINDINGS, bind(LocationStrategy).toClass(HashLocationStrategy)]);
} }

View File

@ -2,7 +2,7 @@
///<reference path="../dist/docs/typings/angular2/router.d.ts"/> ///<reference path="../dist/docs/typings/angular2/router.d.ts"/>
import {Component, bootstrap, View} from 'angular2/angular2'; import {Component, bootstrap, View} from 'angular2/angular2';
import {RouteConfig, routerDirectives, routerInjectables} from 'angular2/router'; import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_BINDINGS} from 'angular2/router';
@Component({ @Component({
selector: 'my-app' selector: 'my-app'
@ -19,7 +19,7 @@ class FooCmp {
}) })
@View({ @View({
template: '<h1>Hello {{ name }}</h1><router-outlet></router-outlet>', template: '<h1>Hello {{ name }}</h1><router-outlet></router-outlet>',
directives: routerDirectives directives: ROUTER_DIRECTIVES
}) })
@RouteConfig([ @RouteConfig([
{path: '/home', component: FooCmp} {path: '/home', component: FooCmp}
@ -30,4 +30,4 @@ class MyAppComponent {
constructor() { this.name = 'Alice'; } constructor() { this.name = 'Alice'; }
} }
bootstrap(MyAppComponent, routerInjectables); bootstrap(MyAppComponent, ROUTER_BINDINGS);