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

View File

@ -1,6 +1,6 @@
// TODO (jteplitz602): This whole file is nearly identical to core/application.ts.
// There should be a way to refactor application so that this file is unnecessary. See #3277
import {Injector, bind, Binding} from "angular2/src/core/di";
import {Injector, provide, Provider} from "angular2/src/core/di";
import {DEFAULT_PIPES} from 'angular2/src/core/pipes';
import {AnimationBuilder} from 'angular2/src/animate/animation_builder';
import {BrowserDetails} from 'angular2/src/animate/browser_details';
@ -19,7 +19,7 @@ import {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view
import {Renderer} from 'angular2/src/core/render/api';
import {AppRootUrl} from 'angular2/src/core/compiler/app_root_url';
import {DomRenderer, DomRenderer_, DOCUMENT} from 'angular2/src/core/render/render';
import {APP_ID_RANDOM_BINDING} from 'angular2/src/core/application_tokens';
import {APP_ID_RANDOM_PROVIDER} from 'angular2/src/core/application_tokens';
import {ElementSchemaRegistry} from 'angular2/src/core/compiler/schema/element_schema_registry';
import {
DomElementSchemaRegistry
@ -68,31 +68,30 @@ import {
var _rootInjector: Injector;
// Contains everything that is safe to share between applications.
var _rootBindings = [bind(Reflector).toValue(reflector)];
var _rootProviders = [provide(Reflector, {asValue: reflector})];
// TODO: This code is nearly identical to core/application. There should be a way to only write it
// once
function _injectorBindings(): any[] {
function _injectorProviders(): any[] {
return [
bind(DOCUMENT)
.toValue(DOM.defaultDoc()),
provide(DOCUMENT, {asValue: DOM.defaultDoc()}),
EventManager,
new Binding(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
new Binding(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
new Binding(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
bind(DomRenderer).toClass(DomRenderer_),
bind(Renderer).toAlias(DomRenderer),
APP_ID_RANDOM_BINDING,
new Provider(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
new Provider(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
new Provider(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
provide(DomRenderer, {asClass: DomRenderer_}),
provide(Renderer, {asAlias: DomRenderer}),
APP_ID_RANDOM_PROVIDER,
DomSharedStylesHost,
bind(SharedStylesHost).toAlias(DomSharedStylesHost),
provide(SharedStylesHost, {asAlias: DomSharedStylesHost}),
Serializer,
bind(ON_WEB_WORKER).toValue(false),
bind(ElementSchemaRegistry).toValue(new DomElementSchemaRegistry()),
provide(ON_WEB_WORKER, {asValue: false}),
provide(ElementSchemaRegistry, {asValue: new DomElementSchemaRegistry()}),
RenderViewWithFragmentsStore,
RenderProtoViewRefStore,
AppViewPool,
bind(APP_VIEW_POOL_CAPACITY).toValue(10000),
bind(AppViewManager).toClass(AppViewManager_),
provide(APP_VIEW_POOL_CAPACITY, {asValue: 10000}),
provide(AppViewManager, {asClass: AppViewManager_}),
AppViewManagerUtils,
AppViewListener,
ProtoViewFactory,
@ -101,28 +100,28 @@ function _injectorBindings(): any[] {
DirectiveResolver,
Parser,
Lexer,
bind(ExceptionHandler).toFactory(() => new ExceptionHandler(DOM), []),
bind(XHR).toValue(new XHRImpl()),
provide(ExceptionHandler, {asFactory: () => new ExceptionHandler(DOM), deps: []}),
provide(XHR, {asValue: new XHRImpl()}),
UrlResolver,
bind(DynamicComponentLoader).toClass(DynamicComponentLoader_),
provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}),
Testability,
AnchorBasedAppRootUrl,
bind(AppRootUrl).toAlias(AnchorBasedAppRootUrl),
provide(AppRootUrl, {asAlias: AnchorBasedAppRootUrl}),
WebWorkerApplication,
WebWorkerSetup,
MessageBasedXHRImpl,
MessageBasedRenderer,
bind(ServiceMessageBrokerFactory).toClass(ServiceMessageBrokerFactory_),
bind(ClientMessageBrokerFactory).toClass(ClientMessageBrokerFactory_),
provide(ServiceMessageBrokerFactory, {asClass: ServiceMessageBrokerFactory_}),
provide(ClientMessageBrokerFactory, {asClass: ClientMessageBrokerFactory_}),
BrowserDetails,
AnimationBuilder,
AnimationBuilder
];
}
export function createInjector(zone: NgZone, bus: MessageBus): Injector {
BrowserDomAdapter.makeCurrent();
_rootBindings.push(bind(NgZone).toValue(zone));
_rootBindings.push(bind(MessageBus).toValue(bus));
var injector: Injector = Injector.resolveAndCreate(_rootBindings);
return injector.resolveAndCreateChild(_injectorBindings());
_rootProviders.push(provide(NgZone, {asValue: zone}));
_rootProviders.push(provide(MessageBus, {asValue: bus}));
var injector: Injector = Injector.resolveAndCreate(_rootProviders);
return injector.resolveAndCreateChild(_injectorProviders());
}

View File

@ -24,7 +24,7 @@ import {
} from 'angular2/src/web_workers/shared/service_message_broker';
/**
* Creates a zone, sets up the DI bindings
* Creates a zone, sets up the DI providers
* And then creates a new WebWorkerMain object to handle messages from the worker
*/
export function bootstrapUICommon(bus: MessageBus): WebWorkerApplication {

View File

@ -4,7 +4,7 @@ import {
PostMessageBusSource
} from 'angular2/src/web_workers/shared/post_message_bus';
import {Type} from "angular2/src/core/facade/lang";
import {Binding, Injectable} from "angular2/src/core/di";
import {Provider, Injectable} from "angular2/src/core/di";
import {Map} from 'angular2/src/core/facade/collection';
import {Promise} from 'angular2/src/core/facade/async';
import {bootstrapWebWorkerCommon} from "angular2/src/web_workers/worker/application_common";
@ -28,7 +28,7 @@ var _postMessage: PostMessageInterface = <any>postMessage;
* See the bootstrap() docs for more details.
*/
export function bootstrapWebWorker(
appComponentType: Type, componentInjectableBindings: Array<Type | Binding | any[]> = null):
appComponentType: Type, componentInjectableProviders: Array<Type | Provider | any[]> = null):
Promise<ComponentRef> {
Parse5DomAdapter.makeCurrent();
var sink = new PostMessageBusSink({
@ -40,5 +40,5 @@ export function bootstrapWebWorker(
var source = new PostMessageBusSource();
var bus = new PostMessageBus(sink, source);
return bootstrapWebWorkerCommon(appComponentType, bus, componentInjectableBindings);
return bootstrapWebWorkerCommon(appComponentType, bus, componentInjectableProviders);
}

View File

@ -1,5 +1,5 @@
import {Injector, bind, OpaqueToken, Binding} from 'angular2/src/core/di';
import {FORM_BINDINGS} from 'angular2/src/core/forms';
import {Injector, provide, OpaqueToken, Provider} from 'angular2/src/core/di';
import {FORM_PROVIDERS} from 'angular2/src/core/forms';
import {
NumberWrapper,
Type,
@ -42,7 +42,7 @@ import {SETUP_CHANNEL} from 'angular2/src/web_workers/shared/messaging_api';
import {WebWorkerEventDispatcher} from 'angular2/src/web_workers/worker/event_dispatcher';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {compilerBindings} from 'angular2/src/core/compiler/compiler';
import {compilerProviders} from 'angular2/src/core/compiler/compiler';
/**
* Initialize the Angular 'platform' on the page in a manner suitable for applications
@ -51,25 +51,25 @@ import {compilerBindings} from 'angular2/src/core/compiler/compiler';
*
* See {@link PlatformRef} for details on the Angular platform.
*
* # Without specified bindings
* # Without specified providers
*
* If no bindings are specified, `platform`'s behavior depends on whether an existing
* If no providers are specified, `platform`'s behavior depends on whether an existing
* platform exists:
*
* If no platform exists, a new one will be created with the default {@link platformBindings}.
*
* If a platform already exists, it will be returned (regardless of what bindings it
* If a platform already exists, it will be returned (regardless of what providers it
* was created with). This is a convenience feature, allowing for multiple applications
* to be loaded into the same platform without awareness of each other.
*
* # With specified bindings
* # With specified providers
*
* It is also possible to specify bindings to be made in the new platform. These bindings
* It is also possible to specify providers to be made in the new platform. These providers
* will be shared between all applications on the page. For example, an abstraction for
* the browser cookie jar should be bound at the platform level, because there is only one
* cookie jar regardless of how many applications on the age will be accessing it.
*
* If bindings are specified directly, `platform` will create the Angular platform with
* If providers are specified directly, `platform` will create the Angular platform with
* them if a platform did not exist already. If it did exist, however, an error will be
* thrown.
*
@ -80,7 +80,7 @@ import {compilerBindings} from 'angular2/src/core/compiler/compiler';
* web worker context. Applications that need direct access to the DOM should
* use `platform` from `core/application_common` instead.
*/
export function platform(bindings?: Array<Type | Binding | any[]>): PlatformRef {
export function platform(bindings?: Array<Type | Provider | any[]>): PlatformRef {
return platformCommon(bindings);
}
@ -91,30 +91,30 @@ class PrintLogger {
logGroupEnd() {}
}
function webWorkerBindings(appComponentType, bus: MessageBus, initData: {[key: string]: any}):
Array<Type | Binding | any[]> {
function webWorkerProviders(appComponentType, bus: MessageBus, initData: {[key: string]: any}):
Array<Type | Provider | any[]> {
return [
compilerBindings(),
compilerProviders(),
Serializer,
bind(MessageBus).toValue(bus),
bind(ClientMessageBrokerFactory).toClass(ClientMessageBrokerFactory_),
bind(ServiceMessageBrokerFactory).toClass(ServiceMessageBrokerFactory_),
provide(MessageBus, {asValue: bus}),
provide(ClientMessageBrokerFactory, {asClass: ClientMessageBrokerFactory_}),
provide(ServiceMessageBrokerFactory, {asClass: ServiceMessageBrokerFactory_}),
WebWorkerRenderer,
bind(Renderer).toAlias(WebWorkerRenderer),
bind(ON_WEB_WORKER).toValue(true),
provide(Renderer, {asAlias: WebWorkerRenderer}),
provide(ON_WEB_WORKER, {asValue: true}),
RenderViewWithFragmentsStore,
RenderProtoViewRefStore,
bind(ExceptionHandler).toFactory(() => new ExceptionHandler(new PrintLogger()), []),
provide(ExceptionHandler, {asFactory: () => new ExceptionHandler(new PrintLogger()), deps: []}),
WebWorkerXHRImpl,
bind(XHR).toAlias(WebWorkerXHRImpl),
bind(AppRootUrl).toValue(new AppRootUrl(initData['rootUrl'])),
provide(XHR, {asAlias: WebWorkerXHRImpl}),
provide(AppRootUrl, {asValue: new AppRootUrl(initData['rootUrl'])}),
WebWorkerEventDispatcher,
FORM_BINDINGS
FORM_PROVIDERS
];
}
export function bootstrapWebWorkerCommon(appComponentType: Type, bus: MessageBus,
appBindings: Array<Type | Binding | any[]> = null):
appProviders: Array<Type | Provider | any[]> = null):
Promise<ComponentRef> {
var bootstrapProcess: PromiseCompleter<any> = PromiseWrapper.completer();
var appPromise = platform().asyncApplication((zone: NgZone) => {
@ -128,9 +128,9 @@ export function bootstrapWebWorkerCommon(appComponentType: Type, bus: MessageBus
var emitter = bus.from(SETUP_CHANNEL);
subscription = ObservableWrapper.subscribe(emitter, (message: {[key: string]: any}) => {
var bindings =
[applicationCommonBindings(), webWorkerBindings(appComponentType, bus, message)];
if (isPresent(appBindings)) {
bindings.push(appBindings);
[applicationCommonBindings(), webWorkerProviders(appComponentType, bus, message)];
if (isPresent(appProviders)) {
bindings.push(appProviders);
}
bootstrapProcess.resolve(bindings);
ObservableWrapper.dispose(subscription);