feat(di): rename Binding into Provider

Closes #4416

Closes #4654
This commit is contained in:
vsavkin
2015-10-10 22:11:13 -07:00
committed by Victor Savkin
parent 7c6130c2c5
commit 1eb0162cde
190 changed files with 2071 additions and 1816 deletions
@@ -15,7 +15,7 @@ import {
xit
} from 'angular2/test_lib';
import {bind, Component, Injector, Inject, View} from 'angular2/core';
import {provide, Component, Injector, Inject, View} from 'angular2/core';
import {isPresent} from 'angular2/src/core/facade/lang';
import {
Promise,
@@ -64,10 +64,13 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
bind(Location).toClass(SpyLocation),
bind(Router)
.toFactory((registry, location) => { return new RootRouter(registry, location, MyComp); },
[RouteRegistry, Location])
provide(Location, {asClass: SpyLocation}),
provide(Router,
{
asFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})
]);
beforeEach(inject([TestComponentBuilder, Router], (tcBuilder, router) => {
@@ -15,7 +15,7 @@ import {
xit
} from 'angular2/test_lib';
import {bind, Component, View, Injector, Inject} from 'angular2/core';
import {provide, Component, View, Injector, Inject} from 'angular2/core';
import {CONST, NumberWrapper, isPresent, Json} from 'angular2/src/core/facade/lang';
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
@@ -48,10 +48,13 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
bind(Location).toClass(SpyLocation),
bind(Router)
.toFactory((registry, location) => { return new RootRouter(registry, location, MyComp); },
[RouteRegistry, Location])
provide(Location, {asClass: SpyLocation}),
provide(Router,
{
asFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})
]);
beforeEach(inject([TestComponentBuilder, Router], (tcBuilder, router) => {
@@ -17,13 +17,13 @@ import {
import {bootstrap} from 'angular2/bootstrap';
import {Component, Directive, View} from 'angular2/src/core/metadata';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {bind} from 'angular2/core';
import {provide} from 'angular2/core';
import {DOCUMENT} from 'angular2/src/core/render/render';
import {RouteConfig, Route, Redirect} from 'angular2/src/router/route_config_decorator';
import {PromiseWrapper} from 'angular2/src/core/facade/async';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {
ROUTER_BINDINGS,
ROUTER_PROVIDERS,
ROUTER_PRIMARY_COMPONENT,
RouteParams,
Router,
@@ -37,8 +37,9 @@ import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
export function main() {
describe('router injectables', () => {
beforeEachBindings(
() => { return [ROUTER_BINDINGS, bind(LocationStrategy).toClass(MockLocationStrategy)]; });
beforeEachBindings(() => {
return [ROUTER_PROVIDERS, provide(LocationStrategy, {asClass: 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
@@ -50,10 +51,10 @@ export function main() {
bootstrap(AppCmp,
[
ROUTER_BINDINGS,
bind(ROUTER_PRIMARY_COMPONENT).toValue(AppCmp),
bind(LocationStrategy).toClass(MockLocationStrategy),
bind(DOCUMENT).toValue(fakeDoc)
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {asValue: AppCmp}),
provide(LocationStrategy, {asClass: MockLocationStrategy}),
provide(DOCUMENT, {asValue: fakeDoc})
])
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
@@ -67,7 +68,8 @@ export function main() {
});
describe('broken app', () => {
beforeEachBindings(() => { return [bind(ROUTER_PRIMARY_COMPONENT).toValue(BrokenAppCmp)]; });
beforeEachBindings(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: BrokenAppCmp})]; });
it('should rethrow exceptions from component constructors',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@@ -84,7 +86,7 @@ export function main() {
describe('back button app', () => {
beforeEachBindings(
() => { return [bind(ROUTER_PRIMARY_COMPONENT).toValue(HierarchyAppCmp)]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: HierarchyAppCmp})]; });
it('should change the url without pushing a new history state for back navigations',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@@ -136,7 +138,7 @@ export function main() {
describe('hierarchical app', () => {
beforeEachBindings(
() => { return [bind(ROUTER_PRIMARY_COMPONENT).toValue(HierarchyAppCmp)]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: HierarchyAppCmp})]; });
it('should bootstrap an app with a hierarchy',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@@ -156,7 +158,7 @@ export function main() {
}));
describe('custom app base ref', () => {
beforeEachBindings(() => { return [bind(APP_BASE_HREF).toValue('/my/app')]; });
beforeEachBindings(() => { return [provide(APP_BASE_HREF, {asValue: '/my/app'})]; });
it('should bootstrap',
inject([AsyncTestCompleter, TestComponentBuilder],
(async, tcb: TestComponentBuilder) => {
@@ -180,7 +182,7 @@ export function main() {
describe('querystring params app', () => {
beforeEachBindings(
() => { return [bind(ROUTER_PRIMARY_COMPONENT).toValue(QueryStringAppCmp)]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: QueryStringAppCmp})]; });
it('should recognize and return querystring params with the injected RouteParams',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@@ -20,7 +20,7 @@ import {
import {NumberWrapper} from 'angular2/src/core/facade/lang';
import {PromiseWrapper} from 'angular2/src/core/facade/async';
import {bind, Component, DirectiveResolver, View} from 'angular2/core';
import {provide, Component, DirectiveResolver, View} from 'angular2/core';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {
@@ -48,10 +48,13 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
bind(Location).toClass(SpyLocation),
bind(Router)
.toFactory((registry, location) => { return new RootRouter(registry, location, MyComp); },
[RouteRegistry, Location])
provide(Location, {asClass: SpyLocation}),
provide(Router,
{
asFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})
]);
beforeEach(inject([TestComponentBuilder, Router, Location], (tcBuilder, rtr, loc) => {
@@ -12,7 +12,7 @@ import {
SpyObject
} from 'angular2/test_lib';
import {Injector, bind} from 'angular2/core';
import {Injector, provide} from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {Location, APP_BASE_HREF} from 'angular2/src/router/location';
import {LocationStrategy} from 'angular2/src/router/location_strategy';
@@ -23,11 +23,11 @@ export function main() {
var locationStrategy, location;
function makeLocation(baseHref: string = '/my/app', binding: any = CONST_EXPR([])): Location {
function makeLocation(baseHref: string = '/my/app', provider: any = CONST_EXPR([])): Location {
locationStrategy = new MockLocationStrategy();
locationStrategy.internalBaseHref = baseHref;
let injector = Injector.resolveAndCreate(
[Location, bind(LocationStrategy).toValue(locationStrategy), binding]);
[Location, provide(LocationStrategy, {asValue: locationStrategy}), provider]);
return location = injector.get(Location);
}
@@ -71,7 +71,7 @@ export function main() {
});
it('should use optional base href param', () => {
let location = makeLocation('/', bind(APP_BASE_HREF).toValue('/my/custom/href'));
let location = makeLocation('/', provide(APP_BASE_HREF, {asValue: '/my/custom/href'}));
location.go('user/btford');
expect(locationStrategy.path()).toEqual('/my/custom/href/user/btford');
});
@@ -81,7 +81,7 @@ export function main() {
locationStrategy.internalBaseHref = null;
expect(() => new Location(locationStrategy))
.toThrowError(
`No base href set. Either provide a binding for the APP_BASE_HREF token or add a base element to the document.`);
`No base href set. Either provide a provider for the APP_BASE_HREF token or add a base element to the document.`);
});
it('should revert to the previous path when a back() operation is executed', () => {
@@ -14,12 +14,12 @@ import {
import {bootstrap} from 'angular2/bootstrap';
import {Component, Directive, View} from 'angular2/src/core/metadata';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {bind} from 'angular2/core';
import {provide} from 'angular2/core';
import {DOCUMENT} from 'angular2/src/core/render/render';
import {Type} from 'angular2/src/core/facade/lang';
import {
ROUTER_BINDINGS,
ROUTER_PROVIDERS,
Router,
RouteConfig,
APP_BASE_HREF,
@@ -48,10 +48,10 @@ export function main() {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, true);
testBindings = [
ROUTER_BINDINGS,
bind(LocationStrategy).toClass(MockLocationStrategy),
bind(DOCUMENT).toValue(fakeDoc),
bind(ExceptionHandler).toValue(exceptionHandler)
ROUTER_PROVIDERS,
provide(LocationStrategy, {asClass: MockLocationStrategy}),
provide(DOCUMENT, {asValue: fakeDoc}),
provide(ExceptionHandler, {asValue: exceptionHandler})
];
});
@@ -16,7 +16,7 @@ import {
import {SpyRouter, SpyLocation} from './spies';
import {bind, Component, View} from 'angular2/core';
import {provide, Component, View} from 'angular2/core';
import {By} from 'angular2/src/core/debug';
import {
@@ -40,9 +40,10 @@ export function main() {
describe('router-link directive', function() {
var tcb: TestComponentBuilder;
beforeEachBindings(
() =>
[bind(Location).toValue(makeDummyLocation()), bind(Router).toValue(makeDummyRouter())]);
beforeEachBindings(() => [
provide(Location, {asValue: makeDummyLocation()}),
provide(Router, {asValue: makeDummyRouter()})
]);
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));
+8 -5
View File
@@ -24,7 +24,7 @@ import {RouteRegistry} from 'angular2/src/router/route_registry';
import {RouteConfig, AsyncRoute, Route} from 'angular2/src/router/route_config_decorator';
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
import {bind} from 'angular2/core';
import {provide} from 'angular2/core';
export function main() {
describe('Router', () => {
@@ -33,10 +33,13 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
bind(Location).toClass(SpyLocation),
bind(Router)
.toFactory((registry, location) => { return new RootRouter(registry, location, AppCmp); },
[RouteRegistry, Location])
provide(Location, {asClass: SpyLocation}),
provide(Router,
{
asFactory:
(registry, location) => { return new RootRouter(registry, location, AppCmp); },
deps: [RouteRegistry, Location]
})
]);