diff --git a/modules/angular2/http.ts b/modules/angular2/http.ts index 09f7b2399c..20058d784a 100644 --- a/modules/angular2/http.ts +++ b/modules/angular2/http.ts @@ -107,7 +107,7 @@ export {URLSearchParams} from './src/http/url_search_params'; * search: string = 'coreTeam=true'; * } * - * bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})]) + * bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})]) * .catch(err => console.error(err)); * ``` * @@ -125,7 +125,7 @@ export {URLSearchParams} from './src/http/url_search_params'; * var injector = Injector.resolveAndCreate([ * HTTP_PROVIDERS, * MockBackend, - * provide(XHRBackend, {asAlias: MockBackend}) + * provide(XHRBackend, {useExisting: MockBackend}) * ]); * var http = injector.get(Http); * var backend = injector.get(MockBackend); @@ -153,12 +153,12 @@ export const HTTP_PROVIDERS: any[] = [ // issue: https://github.com/angular/angular/issues/3183 provide(Http, { - asFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions), + useFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions), deps: [XHRBackend, RequestOptions] }), BrowserXhr, - provide(RequestOptions, {asClass: BaseRequestOptions}), - provide(ResponseOptions, {asClass: BaseResponseOptions}), + provide(RequestOptions, {useClass: BaseRequestOptions}), + provide(ResponseOptions, {useClass: BaseResponseOptions}), XHRBackend ]; @@ -230,7 +230,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS; * search: string = 'coreTeam=true'; * } * - * bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})]) + * bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})]) * .catch(err => console.error(err)); * ``` * @@ -247,7 +247,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS; * var injector = Injector.resolveAndCreate([ * JSONP_PROVIDERS, * MockBackend, - * provide(JSONPBackend, {asAlias: MockBackend}) + * provide(JSONPBackend, {useExisting: MockBackend}) * ]); * var jsonp = injector.get(Jsonp); * var backend = injector.get(MockBackend); @@ -275,13 +275,13 @@ export const JSONP_PROVIDERS: any[] = [ // issue: https://github.com/angular/angular/issues/3183 provide(Jsonp, { - asFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions), + useFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions), deps: [JSONPBackend, RequestOptions] }), BrowserJsonp, - provide(RequestOptions, {asClass: BaseRequestOptions}), - provide(ResponseOptions, {asClass: BaseResponseOptions}), - provide(JSONPBackend, {asClass: JSONPBackend_}) + provide(RequestOptions, {useClass: BaseRequestOptions}), + provide(ResponseOptions, {useClass: BaseResponseOptions}), + provide(JSONPBackend, {useClass: JSONPBackend_}) ]; /** diff --git a/modules/angular2/router.ts b/modules/angular2/router.ts index 9ed197ed3d..38b6f48dad 100644 --- a/modules/angular2/router.ts +++ b/modules/angular2/router.ts @@ -111,17 +111,17 @@ export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]); */ export const ROUTER_PROVIDERS: any[] = CONST_EXPR([ RouteRegistry, - CONST_EXPR(new Provider(LocationStrategy, {toClass: PathLocationStrategy})), + CONST_EXPR(new Provider(LocationStrategy, {useClass: PathLocationStrategy})), Location, CONST_EXPR( new Provider(Router, { - toFactory: routerFactory, + useFactory: routerFactory, deps: CONST_EXPR([RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT]) })), CONST_EXPR(new Provider( ROUTER_PRIMARY_COMPONENT, - {toFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])})) + {useFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])})) ]); /** diff --git a/modules/angular2/src/core/application_common.ts b/modules/angular2/src/core/application_common.ts index fd0e2924eb..4a1bd02a4d 100644 --- a/modules/angular2/src/core/application_common.ts +++ b/modules/angular2/src/core/application_common.ts @@ -49,17 +49,17 @@ export function applicationDomBindings(): Array { throw "Must set a root DOM adapter first."; } return [ - provide(DOCUMENT, {asValue: DOM.defaultDoc()}), + provide(DOCUMENT, {useValue: DOM.defaultDoc()}), EventManager, - 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}), + new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}), + new Provider(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}), + new Provider(EVENT_MANAGER_PLUGINS, {useClass: HammerGesturesPlugin, multi: true}), + provide(DomRenderer, {useClass: DomRenderer_}), + provide(Renderer, {useExisting: DomRenderer}), DomSharedStylesHost, - provide(SharedStylesHost, {asAlias: DomSharedStylesHost}), + provide(SharedStylesHost, {useExisting: DomSharedStylesHost}), EXCEPTION_PROVIDER, - provide(XHR, {asValue: new XHRImpl()}), + provide(XHR, {useValue: new XHRImpl()}), Testability, BrowserDetails, AnimationBuilder, diff --git a/modules/angular2/src/core/application_ref.ts b/modules/angular2/src/core/application_ref.ts index 2f2a0a8cba..71211205f7 100644 --- a/modules/angular2/src/core/application_ref.ts +++ b/modules/angular2/src/core/application_ref.ts @@ -50,7 +50,7 @@ import {Compiler_} from "./linker/compiler"; * running on the page. */ export function platformBindings(): Array { - return [provide(Reflector, {asValue: reflector}), TestabilityRegistry]; + return [provide(Reflector, {useValue: reflector}), TestabilityRegistry]; } /** @@ -58,10 +58,10 @@ export function platformBindings(): Array { */ function _componentProviders(appComponentType: Type): Array { return [ - provide(APP_COMPONENT, {asValue: appComponentType}), + provide(APP_COMPONENT, {useValue: appComponentType}), provide(APP_COMPONENT_REF_PROMISE, { - asFactory: (dynamicComponentLoader, injector: Injector) => { + useFactory: (dynamicComponentLoader, injector: Injector) => { // TODO(rado): investigate whether to support bindings on root component. return dynamicComponentLoader.loadAsRoot(appComponentType, null, injector) .then((componentRef) => { @@ -77,7 +77,7 @@ function _componentProviders(appComponentType: Type): Array) => p.then(ref => ref.instance), + useFactory: (p: Promise) => p.then(ref => ref.instance), deps: [APP_COMPONENT_REF_PROMISE] }), ]; @@ -89,24 +89,24 @@ function _componentProviders(appComponentType: Type): Array { return [ - provide(Compiler, {asClass: Compiler_}), + provide(Compiler, {useClass: Compiler_}), APP_ID_RANDOM_PROVIDER, AppViewPool, - provide(APP_VIEW_POOL_CAPACITY, {asValue: 10000}), - provide(AppViewManager, {asClass: AppViewManager_}), + provide(APP_VIEW_POOL_CAPACITY, {useValue: 10000}), + provide(AppViewManager, {useClass: AppViewManager_}), AppViewManagerUtils, AppViewListener, ProtoViewFactory, ViewResolver, DEFAULT_PIPES, - provide(IterableDiffers, {asValue: defaultIterableDiffers}), - provide(KeyValueDiffers, {asValue: defaultKeyValueDiffers}), + provide(IterableDiffers, {useValue: defaultIterableDiffers}), + provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}), DirectiveResolver, PipeResolver, - provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}), + provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}), provide(LifeCycle, { - asFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()), + useFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()), deps: [ExceptionHandler] }) ]; @@ -236,8 +236,8 @@ export class PlatformRef_ extends PlatformRef { var injector: Injector; var app: ApplicationRef; zone.run(() => { - providers.push(provide(NgZone, {asValue: zone})); - providers.push(provide(ApplicationRef, {asFactory: (): ApplicationRef => app, deps: []})); + providers.push(provide(NgZone, {useValue: zone})); + providers.push(provide(ApplicationRef, {useFactory: (): ApplicationRef => app, deps: []})); var exceptionHandler; try { @@ -297,7 +297,7 @@ export abstract class ApplicationRef { * ``` * var app = platform.application([applicationCommonBindings(), applicationDomBindings()]; * app.bootstrap(FirstRootComponent); - * app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {asClass: OverriddenBinding})]); + * app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {useClass: OverriddenBinding})]); * ``` */ abstract bootstrap(componentType: Type, bindings?: Array): diff --git a/modules/angular2/src/core/application_tokens.ts b/modules/angular2/src/core/application_tokens.ts index 1021f60be2..23f15ca169 100644 --- a/modules/angular2/src/core/application_tokens.ts +++ b/modules/angular2/src/core/application_tokens.ts @@ -43,7 +43,7 @@ function _appIdRandomProviderFactory() { * Bindings that will generate a random APP_ID_TOKEN. */ export const APP_ID_RANDOM_PROVIDER: Provider = - CONST_EXPR(new Provider(APP_ID, {toFactory: _appIdRandomProviderFactory, deps: []})); + CONST_EXPR(new Provider(APP_ID, {useFactory: _appIdRandomProviderFactory, deps: []})); function _randomChar(): string { return StringWrapper.fromCharCode(97 + Math.floor(Math.random() * 25)); diff --git a/modules/angular2/src/core/change_detection/differs/iterable_differs.ts b/modules/angular2/src/core/change_detection/differs/iterable_differs.ts index 6ab03370e4..a2ed3d58de 100644 --- a/modules/angular2/src/core/change_detection/differs/iterable_differs.ts +++ b/modules/angular2/src/core/change_detection/differs/iterable_differs.ts @@ -56,7 +56,7 @@ export class IterableDiffers { */ static extend(factories: IterableDifferFactory[]): Provider { return new Provider(IterableDiffers, { - toFactory: (parent: IterableDiffers) => { + useFactory: (parent: IterableDiffers) => { if (isBlank(parent)) { // Typically would occur when calling IterableDiffers.extend inside of dependencies passed // to diff --git a/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts b/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts index 17ca4879e8..e14e13fb9d 100644 --- a/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts +++ b/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts @@ -56,7 +56,7 @@ export class KeyValueDiffers { */ static extend(factories: KeyValueDifferFactory[]): Provider { return new Provider(KeyValueDiffers, { - toFactory: (parent: KeyValueDiffers) => { + useFactory: (parent: KeyValueDiffers) => { if (isBlank(parent)) { // Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed // to diff --git a/modules/angular2/src/core/compiler/compiler.ts b/modules/angular2/src/core/compiler/compiler.ts index 8787a8bb44..09ac936f90 100644 --- a/modules/angular2/src/core/compiler/compiler.ts +++ b/modules/angular2/src/core/compiler/compiler.ts @@ -42,16 +42,16 @@ export function compilerProviders(): Array { ChangeDetectionCompiler, provide(ChangeDetectorGenConfig, { - asValue: + useValue: new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), false, true) }), TemplateCompiler, - provide(RuntimeCompiler, {asClass: RuntimeCompiler_}), - provide(Compiler, {asAlias: RuntimeCompiler}), + provide(RuntimeCompiler, {useClass: RuntimeCompiler_}), + provide(Compiler, {useExisting: RuntimeCompiler}), DomElementSchemaRegistry, - provide(ElementSchemaRegistry, {asAlias: DomElementSchemaRegistry}), + provide(ElementSchemaRegistry, {useExisting: DomElementSchemaRegistry}), AnchorBasedAppRootUrl, - provide(AppRootUrl, {asAlias: AnchorBasedAppRootUrl}), + provide(AppRootUrl, {useExisting: AnchorBasedAppRootUrl}), UrlResolver ]; } diff --git a/modules/angular2/src/core/debug/debug_element_view_listener.ts b/modules/angular2/src/core/debug/debug_element_view_listener.ts index c94128a889..7b56af56a5 100644 --- a/modules/angular2/src/core/debug/debug_element_view_listener.ts +++ b/modules/angular2/src/core/debug/debug_element_view_listener.ts @@ -69,7 +69,7 @@ export class DebugElementViewListener implements AppViewListener { export const ELEMENT_PROBE_PROVIDERS: any[] = CONST_EXPR([ DebugElementViewListener, - CONST_EXPR(new Provider(AppViewListener, {toAlias: DebugElementViewListener})), + CONST_EXPR(new Provider(AppViewListener, {useExisting: DebugElementViewListener})), ]); export const ELEMENT_PROBE_BINDINGS = ELEMENT_PROBE_PROVIDERS; \ No newline at end of file diff --git a/modules/angular2/src/core/di/exceptions.ts b/modules/angular2/src/core/di/exceptions.ts index 80fe0e7126..c6ed6c6752 100644 --- a/modules/angular2/src/core/di/exceptions.ts +++ b/modules/angular2/src/core/di/exceptions.ts @@ -91,8 +91,8 @@ export class NoProviderError extends AbstractProviderError { * * ```typescript * var injector = Injector.resolveAndCreate([ - * provide("one", {asFactory: (two) => "two", deps: [[new Inject("two")]]}), - * provide("two", {asFactory: (one) => "one", deps: [[new Inject("one")]]}) + * provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}), + * provide("two", {useFactory: (one) => "one", deps: [[new Inject("one")]]}) * ]); * * expect(() => injector.get("one")).toThrowError(); @@ -252,8 +252,8 @@ export class OutOfBoundsError extends BaseException { * * ```typescript * expect(() => Injector.resolveAndCreate([ - * new Provider("Strings", {toValue: "string1", multi: true}), - * new Provider("Strings", {toValue: "string2", multi: false}) + * new Provider("Strings", {useValue: "string1", multi: true}), + * new Provider("Strings", {useValue: "string2", multi: false}) * ])).toThrowError(); * ``` */ diff --git a/modules/angular2/src/core/di/injector.ts b/modules/angular2/src/core/di/injector.ts index 634a60668a..b6a7cb85bb 100644 --- a/modules/angular2/src/core/di/injector.ts +++ b/modules/angular2/src/core/di/injector.ts @@ -563,7 +563,7 @@ export class Injector { * * ```typescript * var injector = Injector.resolveAndCreate([ - * provide("validToken", {asValue: "Value"}) + * provide("validToken", {useValue: "Value"}) * ]); * expect(injector.get("validToken")).toEqual("Value"); * expect(() => injector.get("invalidToken")).toThrowError(); @@ -588,7 +588,7 @@ export class Injector { * * ```typescript * var injector = Injector.resolveAndCreate([ - * provide("validToken", {asValue: "Value"}) + * provide("validToken", {useValue: "Value"}) * ]); * expect(injector.getOptional("validToken")).toEqual("Value"); * expect(injector.getOptional("invalidToken")).toBe(null); diff --git a/modules/angular2/src/core/di/metadata.ts b/modules/angular2/src/core/di/metadata.ts index 8c9b9ca391..ca5e9db84d 100644 --- a/modules/angular2/src/core/di/metadata.ts +++ b/modules/angular2/src/core/di/metadata.ts @@ -17,7 +17,7 @@ import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/cor * } * * var injector = Injector.resolveAndCreate([ - * provide("MyEngine", {asClass: Engine}), + * provide("MyEngine", {useClass: Engine}), * Car * ]); * diff --git a/modules/angular2/src/core/di/opaque_token.ts b/modules/angular2/src/core/di/opaque_token.ts index e783b6329b..da4834a437 100644 --- a/modules/angular2/src/core/di/opaque_token.ts +++ b/modules/angular2/src/core/di/opaque_token.ts @@ -9,7 +9,7 @@ import {CONST} from 'angular2/src/core/facade/lang'; * var t = new OpaqueToken("value"); * * var injector = Injector.resolveAndCreate([ - * provide(t, {asValue: "providedValue"}) + * provide(t, {useValue: "providedValue"}) * ]); * * expect(injector.get(t)).toEqual("bindingValue"); diff --git a/modules/angular2/src/core/di/provider.ts b/modules/angular2/src/core/di/provider.ts index 3e0acd9510..2f4e849764 100644 --- a/modules/angular2/src/core/di/provider.ts +++ b/modules/angular2/src/core/di/provider.ts @@ -48,7 +48,7 @@ const _EMPTY_LIST = CONST_EXPR([]); * * ```javascript * var injector = Injector.resolveAndCreate([ - * new Provider("message", { toValue: 'Hello' }) + * new Provider("message", { useValue: 'Hello' }) * ]); * * expect(injector.get("message")).toEqual('Hello'); @@ -66,7 +66,8 @@ export class Provider { * * ### Example ([live demo](http://plnkr.co/edit/RSTG86qgmoxCyj9SWPwY?p=preview)) * - * Because `toAlias` and `toClass` are often confused, the example contains both use cases for + * Because `useExisting` and `useClass` are often confused, the example contains both use cases + * for * easy * comparison. * @@ -77,11 +78,11 @@ export class Provider { * * var injectorClass = Injector.resolveAndCreate([ * Car, - * new Provider(Vehicle, { toClass: Car }) + * new Provider(Vehicle, { useClass: Car }) * ]); * var injectorAlias = Injector.resolveAndCreate([ * Car, - * new Provider(Vehicle, { toAlias: Car }) + * new Provider(Vehicle, { useExisting: Car }) * ]); * * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car)); @@ -91,7 +92,7 @@ export class Provider { * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true); * ``` */ - toClass: Type; + useClass: Type; /** * Binds a DI token to a value. @@ -100,23 +101,24 @@ export class Provider { * * ```javascript * var injector = Injector.resolveAndCreate([ - * new Provider("message", { toValue: 'Hello' }) + * new Provider("message", { useValue: 'Hello' }) * ]); * * expect(injector.get("message")).toEqual('Hello'); * ``` */ - toValue; + useValue; /** - * Binds a DI token as an alias for an existing token. + * Binds a DI token to an existing token. * - * An alias means that {@link Injector} returns the same instance as if the alias token was used. - * This is in contrast to `toClass` where a separate instance of `toClass` is returned. + * {@link Injector} returns the same instance as if the provided token was used. + * This is in contrast to `useClass` where a separate instance of `useClass` is returned. * * ### Example ([live demo](http://plnkr.co/edit/QsatsOJJ6P8T2fMe9gr8?p=preview)) * - * Because `toAlias` and `toClass` are often confused the example contains both use cases for easy + * Because `useExisting` and `useClass` are often confused the example contains both use cases for + * easy * comparison. * * ```typescript @@ -126,11 +128,11 @@ export class Provider { * * var injectorAlias = Injector.resolveAndCreate([ * Car, - * new Provider(Vehicle, { toAlias: Car }) + * new Provider(Vehicle, { useExisting: Car }) * ]); * var injectorClass = Injector.resolveAndCreate([ * Car, - * new Provider(Vehicle, { toClass: Car }) + * new Provider(Vehicle, { useClass: Car }) * ]); * * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car)); @@ -140,7 +142,7 @@ export class Provider { * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true); * ``` */ - toAlias; + useExisting; /** * Binds a DI token to a function which computes the value. @@ -149,8 +151,8 @@ export class Provider { * * ```typescript * var injector = Injector.resolveAndCreate([ - * new Provider(Number, { toFactory: () => { return 1+2; }}), - * new Provider(String, { toFactory: (value) => { return "Value: " + value; }, + * new Provider(Number, { useFactory: () => { return 1+2; }}), + * new Provider(String, { useFactory: (value) => { return "Value: " + value; }, * deps: [Number] }) * ]); * @@ -160,7 +162,7 @@ export class Provider { * * Used in conjuction with dependencies. */ - toFactory: Function; + useFactory: Function; /** * Specifies a set of dependencies @@ -170,8 +172,8 @@ export class Provider { * * ```typescript * var injector = Injector.resolveAndCreate([ - * new Provider(Number, { toFactory: () => { return 1+2; }}), - * new Provider(String, { toFactory: (value) => { return "Value: " + value; }, + * new Provider(Number, { useFactory: () => { return 1+2; }}), + * new Provider(String, { useFactory: (value) => { return "Value: " + value; }, * deps: [Number] }) * ]); * @@ -179,26 +181,26 @@ export class Provider { * expect(injector.get(String)).toEqual('Value: 3'); * ``` * - * Used in conjunction with `toFactory`. + * Used in conjunction with `useFactory`. */ dependencies: Object[]; /** @internal */ _multi: boolean; - constructor(token, {toClass, toValue, toAlias, toFactory, deps, multi}: { - toClass?: Type, - toValue?: any, - toAlias?: any, - toFactory?: Function, + constructor(token, {useClass, useValue, useExisting, useFactory, deps, multi}: { + useClass?: Type, + useValue?: any, + useExisting?: any, + useFactory?: Function, deps?: Object[], multi?: boolean }) { this.token = token; - this.toClass = toClass; - this.toValue = toValue; - this.toAlias = toAlias; - this.toFactory = toFactory; + this.useClass = useClass; + this.useValue = useValue; + this.useExisting = useExisting; + this.useFactory = useFactory; this.dependencies = deps; this._multi = multi; } @@ -216,8 +218,8 @@ export class Provider { * * ```typescript * var injector = Injector.resolveAndCreate([ - * new Provider("Strings", { toValue: "String1", multi: true}), - * new Provider("Strings", { toValue: "String2", multi: true}) + * new Provider("Strings", { useValue: "String1", multi: true}), + * new Provider("Strings", { useValue: "String2", multi: true}) * ]); * * expect(injector.get("Strings")).toEqual(["String1", "String2"]); @@ -228,8 +230,8 @@ export class Provider { * * ```typescript * var injector = Injector.resolveAndCreate([ - * new Provider("Strings", { toValue: "String1", multi: true }), - * new Provider("Strings", { toValue: "String2"}) + * new Provider("Strings", { useValue: "String1", multi: true }), + * new Provider("Strings", { useValue: "String2"}) * ]); * ``` */ @@ -245,19 +247,37 @@ export class Binding extends Provider { toClass?: Type, toValue?: any, toAlias?: any, - toFactory?: Function, - deps?: Object[], - multi?: boolean + toFactory: Function, deps?: Object[], multi?: boolean }) { super(token, { - toClass: toClass, - toValue: toValue, - toAlias: toAlias, - toFactory: toFactory, + useClass: toClass, + useValue: toValue, + useExisting: toAlias, + useFactory: toFactory, deps: deps, multi: multi }); } + + /** + * @deprecated + */ + get toClass() { return this.useClass; } + + /** + * @deprecated + */ + get toAlias() { return this.useExisting; } + + /** + * @deprecated + */ + get toFactory() { return this.useFactory; } + + /** + * @deprecated + */ + get toValue() { return this.useValue; } } /** @@ -270,7 +290,7 @@ export class Binding extends Provider { * ### Example ([live demo](http://plnkr.co/edit/RfEnhh8kUEI0G3qsnIeT?p%3Dpreview&p=preview)) * * ```typescript - * var resolvedProviders = Injector.resolve([new Provider('message', {toValue: 'Hello'})]); + * var resolvedProviders = Injector.resolve([new Provider('message', {useValue: 'Hello'})]); * var injector = Injector.fromResolvedProviders(resolvedProviders); * * expect(injector.get('message')).toEqual('Hello'); @@ -327,7 +347,7 @@ export class ResolvedFactory { * * To construct a {@link Provider}, bind a `token` to either a class, a value, a factory function, * or - * to an alias to another `token`. + * to an existing `token`. * See {@link ProviderBuilder} for more details. * * The `token` is most commonly a class or {@link angular2/di/OpaqueToken}. @@ -343,19 +363,19 @@ export function bind(token): ProviderBuilder { * * */ -export function provide(token, {asClass, asValue, asAlias, asFactory, deps, multi}: { - asClass?: Type, - asValue?: any, - asAlias?: any, - asFactory?: Function, +export function provide(token, {useClass, useValue, useExisting, useFactory, deps, multi}: { + useClass?: Type, + useValue?: any, + useExisting?: any, + useFactory?: Function, deps?: Object[], multi?: boolean }): Provider { return new Provider(token, { - toClass: asClass, - toValue: asValue, - toAlias: asAlias, - toFactory: asFactory, + useClass: useClass, + useValue: useValue, + useExisting: useExisting, + useFactory: useFactory, deps: deps, multi: multi }); @@ -382,11 +402,11 @@ export class ProviderBuilder { * * var injectorClass = Injector.resolveAndCreate([ * Car, - * provide(Vehicle, {asClass: Car}) + * provide(Vehicle, {useClass: Car}) * ]); * var injectorAlias = Injector.resolveAndCreate([ * Car, - * provide(Vehicle, {asAlias: Car}) + * provide(Vehicle, {useExisting: Car}) * ]); * * expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car)); @@ -401,7 +421,7 @@ export class ProviderBuilder { throw new BaseException( `Trying to create a class provider but "${stringify(type)}" is not a class!`); } - return new Provider(this.token, {toClass: type}); + return new Provider(this.token, {useClass: type}); } /** @@ -411,19 +431,19 @@ export class ProviderBuilder { * * ```typescript * var injector = Injector.resolveAndCreate([ - * provide('message', {asValue: 'Hello'}) + * provide('message', {useValue: 'Hello'}) * ]); * * expect(injector.get('message')).toEqual('Hello'); * ``` */ - toValue(value: any): Provider { return new Provider(this.token, {toValue: value}); } + toValue(value: any): Provider { return new Provider(this.token, {useValue: value}); } /** - * Binds a DI token as an alias for an existing token. + * Binds a DI token to an existing token. * - * An alias means that we will return the same instance as if the alias token was used. (This is - * in contrast to `toClass` where a separate instance of `toClass` will be returned.) + * Angular will return the same instance as if the provided token was used. (This is + * in contrast to `useClass` where a separate instance of `useClass` will be returned.) * * ### Example ([live demo](http://plnkr.co/edit/uBaoF2pN5cfc5AfZapNw?p=preview)) * @@ -438,11 +458,11 @@ export class ProviderBuilder { * * var injectorAlias = Injector.resolveAndCreate([ * Car, - * provide(Vehicle, {asAlias: Car}) + * provide(Vehicle, {useExisting: Car}) * ]); * var injectorClass = Injector.resolveAndCreate([ * Car, - * provide(Vehicle, {asClass: Car}) + * provide(Vehicle, {useClass: Car}) * ]); * * expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car)); @@ -456,7 +476,7 @@ export class ProviderBuilder { if (isBlank(aliasToken)) { throw new BaseException(`Can not alias ${stringify(this.token)} to a blank value!`); } - return new Provider(this.token, {toAlias: aliasToken}); + return new Provider(this.token, {useExisting: aliasToken}); } /** @@ -466,8 +486,8 @@ export class ProviderBuilder { * * ```typescript * var injector = Injector.resolveAndCreate([ - * provide(Number, {asFactory: () => { return 1+2; }}), - * provide(String, {asFactory: (v) => { return "Value: " + v; }, deps: [Number]}) + * provide(Number, {useFactory: () => { return 1+2; }}), + * provide(String, {useFactory: (v) => { return "Value: " + v; }, deps: [Number]}) * ]); * * expect(injector.get(Number)).toEqual(3); @@ -479,7 +499,7 @@ export class ProviderBuilder { throw new BaseException( `Trying to create a factory provider but "${stringify(factory)}" is not a function!`); } - return new Provider(this.token, {toFactory: factory, deps: dependencies}); + return new Provider(this.token, {useFactory: factory, deps: dependencies}); } } @@ -489,18 +509,18 @@ export class ProviderBuilder { export function resolveFactory(provider: Provider): ResolvedFactory { var factoryFn: Function; var resolvedDeps; - if (isPresent(provider.toClass)) { - var toClass = resolveForwardRef(provider.toClass); - factoryFn = reflector.factory(toClass); - resolvedDeps = _dependenciesFor(toClass); - } else if (isPresent(provider.toAlias)) { + if (isPresent(provider.useClass)) { + var useClass = resolveForwardRef(provider.useClass); + factoryFn = reflector.factory(useClass); + resolvedDeps = _dependenciesFor(useClass); + } else if (isPresent(provider.useExisting)) { factoryFn = (aliasInstance) => aliasInstance; - resolvedDeps = [Dependency.fromKey(Key.get(provider.toAlias))]; - } else if (isPresent(provider.toFactory)) { - factoryFn = provider.toFactory; - resolvedDeps = _constructDependencies(provider.toFactory, provider.dependencies); + resolvedDeps = [Dependency.fromKey(Key.get(provider.useExisting))]; + } else if (isPresent(provider.useFactory)) { + factoryFn = provider.useFactory; + resolvedDeps = _constructDependencies(provider.useFactory, provider.dependencies); } else { - factoryFn = () => provider.toValue; + factoryFn = () => provider.useValue; resolvedDeps = _EMPTY_LIST; } return new ResolvedFactory(factoryFn, resolvedDeps); @@ -553,7 +573,7 @@ function _normalizeProviders(providers: Array { providers.forEach(b => { if (b instanceof Type) { - _normalizeProvider(provide(b, {asClass: b}), res); + _normalizeProvider(provide(b, {useClass: b}), res); } else if (b instanceof Provider) { _normalizeProvider(b, res); diff --git a/modules/angular2/src/core/facade/exception_handler.ts b/modules/angular2/src/core/facade/exception_handler.ts index 8410abb803..5ab3a2a67f 100644 --- a/modules/angular2/src/core/facade/exception_handler.ts +++ b/modules/angular2/src/core/facade/exception_handler.ts @@ -27,7 +27,7 @@ class _ArrayLogger { * } * } * - * bootstrap(MyApp, [provide(ExceptionHandler, {asClass: MyExceptionHandler})]) + * bootstrap(MyApp, [provide(ExceptionHandler, {useClass: MyExceptionHandler})]) * * ``` */ diff --git a/modules/angular2/src/core/forms/directives/checkbox_value_accessor.ts b/modules/angular2/src/core/forms/directives/checkbox_value_accessor.ts index b01c5dcecb..7a843b893c 100644 --- a/modules/angular2/src/core/forms/directives/checkbox_value_accessor.ts +++ b/modules/angular2/src/core/forms/directives/checkbox_value_accessor.ts @@ -8,7 +8,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; import {setProperty} from './shared'; const CHECKBOX_VALUE_ACCESSOR = CONST_EXPR(new Provider( - NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => CheckboxControlValueAccessor), multi: true})); + NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => CheckboxControlValueAccessor), multi: true})); /** * The accessor for writing a value and listening to changes on a checkbox input element. diff --git a/modules/angular2/src/core/forms/directives/default_value_accessor.ts b/modules/angular2/src/core/forms/directives/default_value_accessor.ts index e0c8030a44..c7b0e3e804 100644 --- a/modules/angular2/src/core/forms/directives/default_value_accessor.ts +++ b/modules/angular2/src/core/forms/directives/default_value_accessor.ts @@ -7,7 +7,7 @@ import {isBlank, CONST_EXPR} from 'angular2/src/core/facade/lang'; import {setProperty} from './shared'; const DEFAULT_VALUE_ACCESSOR = CONST_EXPR(new Provider( - NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => DefaultValueAccessor), multi: true})); + NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => DefaultValueAccessor), multi: true})); /** * The default accessor for writing a value and listening to changes that is used by the diff --git a/modules/angular2/src/core/forms/directives/ng_control_group.ts b/modules/angular2/src/core/forms/directives/ng_control_group.ts index 2186960a38..8e787bb861 100644 --- a/modules/angular2/src/core/forms/directives/ng_control_group.ts +++ b/modules/angular2/src/core/forms/directives/ng_control_group.ts @@ -10,7 +10,7 @@ import {ControlGroup} from '../model'; import {Form} from './form_interface'; const controlGroupBinding = - CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgControlGroup)})); + CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgControlGroup)})); /** * Creates and binds a control group to a DOM element. diff --git a/modules/angular2/src/core/forms/directives/ng_control_name.ts b/modules/angular2/src/core/forms/directives/ng_control_name.ts index 97b16106b8..8edd82999e 100644 --- a/modules/angular2/src/core/forms/directives/ng_control_name.ts +++ b/modules/angular2/src/core/forms/directives/ng_control_name.ts @@ -14,7 +14,7 @@ import {Validators, NG_VALIDATORS} from '../validators'; const controlNameBinding = - CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgControlName)})); + CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgControlName)})); /** * Creates and binds a control with a specified name to a DOM element. diff --git a/modules/angular2/src/core/forms/directives/ng_form.ts b/modules/angular2/src/core/forms/directives/ng_form.ts index dac6298d5f..4d52d14621 100644 --- a/modules/angular2/src/core/forms/directives/ng_form.ts +++ b/modules/angular2/src/core/forms/directives/ng_form.ts @@ -16,7 +16,7 @@ import {AbstractControl, ControlGroup, Control} from '../model'; import {setUpControl} from './shared'; const formDirectiveProvider = - CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgForm)})); + CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgForm)})); /** * If `NgForm` is bound in a component, `
` elements in that component will be diff --git a/modules/angular2/src/core/forms/directives/ng_form_control.ts b/modules/angular2/src/core/forms/directives/ng_form_control.ts index ce4cf3153f..156829e0f1 100644 --- a/modules/angular2/src/core/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/core/forms/directives/ng_form_control.ts @@ -11,7 +11,7 @@ import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor' import {setUpControl, isPropertyUpdated, selectValueAccessor} from './shared'; const formControlBinding = - CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgFormControl)})); + CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgFormControl)})); /** * Binds an existing {@link Control} to a DOM element. diff --git a/modules/angular2/src/core/forms/directives/ng_form_model.ts b/modules/angular2/src/core/forms/directives/ng_form_model.ts index b411979366..879f8bfdd7 100644 --- a/modules/angular2/src/core/forms/directives/ng_form_model.ts +++ b/modules/angular2/src/core/forms/directives/ng_form_model.ts @@ -13,7 +13,7 @@ import {Control, ControlGroup} from '../model'; import {setUpControl} from './shared'; const formDirectiveProvider = - CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgFormModel)})); + CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgFormModel)})); /** * Binds an existing control group to a DOM element. diff --git a/modules/angular2/src/core/forms/directives/ng_model.ts b/modules/angular2/src/core/forms/directives/ng_model.ts index 6d95e9c6bb..937f62161e 100644 --- a/modules/angular2/src/core/forms/directives/ng_model.ts +++ b/modules/angular2/src/core/forms/directives/ng_model.ts @@ -11,7 +11,7 @@ import {Validators, NG_VALIDATORS} from '../validators'; import {setUpControl, isPropertyUpdated, selectValueAccessor} from './shared'; const formControlBinding = - CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgModel)})); + CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgModel)})); /** * Binds a domain model to a form control. diff --git a/modules/angular2/src/core/forms/directives/select_control_value_accessor.ts b/modules/angular2/src/core/forms/directives/select_control_value_accessor.ts index 489ad8efa4..fb4cee131a 100644 --- a/modules/angular2/src/core/forms/directives/select_control_value_accessor.ts +++ b/modules/angular2/src/core/forms/directives/select_control_value_accessor.ts @@ -9,7 +9,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; import {setProperty} from './shared'; const SELECT_VALUE_ACCESSOR = CONST_EXPR(new Provider( - NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => SelectControlValueAccessor), multi: true})); + NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => SelectControlValueAccessor), multi: true})); /** * Marks `