X Tutup
Skip to content

Commit 1aeafd3

Browse files
committed
feat(di): change the params of Provider and provide to start with "use"
Closes #4684
1 parent f443ecb commit 1aeafd3

File tree

110 files changed

+466
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+466
-434
lines changed

modules/angular2/http.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export {URLSearchParams} from './src/http/url_search_params';
107107
* search: string = 'coreTeam=true';
108108
* }
109109
*
110-
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
110+
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
111111
* .catch(err => console.error(err));
112112
* ```
113113
*
@@ -125,7 +125,7 @@ export {URLSearchParams} from './src/http/url_search_params';
125125
* var injector = Injector.resolveAndCreate([
126126
* HTTP_PROVIDERS,
127127
* MockBackend,
128-
* provide(XHRBackend, {asAlias: MockBackend})
128+
* provide(XHRBackend, {useExisting: MockBackend})
129129
* ]);
130130
* var http = injector.get(Http);
131131
* var backend = injector.get(MockBackend);
@@ -153,12 +153,12 @@ export const HTTP_PROVIDERS: any[] = [
153153
// issue: https://github.com/angular/angular/issues/3183
154154
provide(Http,
155155
{
156-
asFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions),
156+
useFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions),
157157
deps: [XHRBackend, RequestOptions]
158158
}),
159159
BrowserXhr,
160-
provide(RequestOptions, {asClass: BaseRequestOptions}),
161-
provide(ResponseOptions, {asClass: BaseResponseOptions}),
160+
provide(RequestOptions, {useClass: BaseRequestOptions}),
161+
provide(ResponseOptions, {useClass: BaseResponseOptions}),
162162
XHRBackend
163163
];
164164

@@ -230,7 +230,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
230230
* search: string = 'coreTeam=true';
231231
* }
232232
*
233-
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
233+
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
234234
* .catch(err => console.error(err));
235235
* ```
236236
*
@@ -247,7 +247,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
247247
* var injector = Injector.resolveAndCreate([
248248
* JSONP_PROVIDERS,
249249
* MockBackend,
250-
* provide(JSONPBackend, {asAlias: MockBackend})
250+
* provide(JSONPBackend, {useExisting: MockBackend})
251251
* ]);
252252
* var jsonp = injector.get(Jsonp);
253253
* var backend = injector.get(MockBackend);
@@ -275,13 +275,13 @@ export const JSONP_PROVIDERS: any[] = [
275275
// issue: https://github.com/angular/angular/issues/3183
276276
provide(Jsonp,
277277
{
278-
asFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions),
278+
useFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions),
279279
deps: [JSONPBackend, RequestOptions]
280280
}),
281281
BrowserJsonp,
282-
provide(RequestOptions, {asClass: BaseRequestOptions}),
283-
provide(ResponseOptions, {asClass: BaseResponseOptions}),
284-
provide(JSONPBackend, {asClass: JSONPBackend_})
282+
provide(RequestOptions, {useClass: BaseRequestOptions}),
283+
provide(ResponseOptions, {useClass: BaseResponseOptions}),
284+
provide(JSONPBackend, {useClass: JSONPBackend_})
285285
];
286286

287287
/**

modules/angular2/router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]);
111111
*/
112112
export const ROUTER_PROVIDERS: any[] = CONST_EXPR([
113113
RouteRegistry,
114-
CONST_EXPR(new Provider(LocationStrategy, {toClass: PathLocationStrategy})),
114+
CONST_EXPR(new Provider(LocationStrategy, {useClass: PathLocationStrategy})),
115115
Location,
116116
CONST_EXPR(
117117
new Provider(Router,
118118
{
119-
toFactory: routerFactory,
119+
useFactory: routerFactory,
120120
deps: CONST_EXPR([RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT])
121121
})),
122122
CONST_EXPR(new Provider(
123123
ROUTER_PRIMARY_COMPONENT,
124-
{toFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])}))
124+
{useFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])}))
125125
]);
126126

127127
/**

modules/angular2/src/core/application_common.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ export function applicationDomBindings(): Array<Type | Provider | any[]> {
4949
throw "Must set a root DOM adapter first.";
5050
}
5151
return [
52-
provide(DOCUMENT, {asValue: DOM.defaultDoc()}),
52+
provide(DOCUMENT, {useValue: DOM.defaultDoc()}),
5353
EventManager,
54-
new Provider(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
55-
new Provider(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
56-
new Provider(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
57-
provide(DomRenderer, {asClass: DomRenderer_}),
58-
provide(Renderer, {asAlias: DomRenderer}),
54+
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}),
55+
new Provider(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}),
56+
new Provider(EVENT_MANAGER_PLUGINS, {useClass: HammerGesturesPlugin, multi: true}),
57+
provide(DomRenderer, {useClass: DomRenderer_}),
58+
provide(Renderer, {useExisting: DomRenderer}),
5959
DomSharedStylesHost,
60-
provide(SharedStylesHost, {asAlias: DomSharedStylesHost}),
60+
provide(SharedStylesHost, {useExisting: DomSharedStylesHost}),
6161
EXCEPTION_PROVIDER,
62-
provide(XHR, {asValue: new XHRImpl()}),
62+
provide(XHR, {useValue: new XHRImpl()}),
6363
Testability,
6464
BrowserDetails,
6565
AnimationBuilder,

modules/angular2/src/core/application_ref.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ import {Compiler_} from "./linker/compiler";
5050
* running on the page.
5151
*/
5252
export function platformBindings(): Array<Type | Provider | any[]> {
53-
return [provide(Reflector, {asValue: reflector}), TestabilityRegistry];
53+
return [provide(Reflector, {useValue: reflector}), TestabilityRegistry];
5454
}
5555

5656
/**
5757
* Construct providers specific to an individual root component.
5858
*/
5959
function _componentProviders(appComponentType: Type): Array<Type | Provider | any[]> {
6060
return [
61-
provide(APP_COMPONENT, {asValue: appComponentType}),
61+
provide(APP_COMPONENT, {useValue: appComponentType}),
6262
provide(APP_COMPONENT_REF_PROMISE,
6363
{
64-
asFactory: (dynamicComponentLoader, injector: Injector) => {
64+
useFactory: (dynamicComponentLoader, injector: Injector) => {
6565
// TODO(rado): investigate whether to support bindings on root component.
6666
return dynamicComponentLoader.loadAsRoot(appComponentType, null, injector)
6767
.then((componentRef) => {
@@ -77,7 +77,7 @@ function _componentProviders(appComponentType: Type): Array<Type | Provider | an
7777
}),
7878
provide(appComponentType,
7979
{
80-
asFactory: (p: Promise<any>) => p.then(ref => ref.instance),
80+
useFactory: (p: Promise<any>) => p.then(ref => ref.instance),
8181
deps: [APP_COMPONENT_REF_PROMISE]
8282
}),
8383
];
@@ -89,24 +89,24 @@ function _componentProviders(appComponentType: Type): Array<Type | Provider | an
8989
*/
9090
export function applicationCommonBindings(): Array<Type | Provider | any[]> {
9191
return [
92-
provide(Compiler, {asClass: Compiler_}),
92+
provide(Compiler, {useClass: Compiler_}),
9393
APP_ID_RANDOM_PROVIDER,
9494
AppViewPool,
95-
provide(APP_VIEW_POOL_CAPACITY, {asValue: 10000}),
96-
provide(AppViewManager, {asClass: AppViewManager_}),
95+
provide(APP_VIEW_POOL_CAPACITY, {useValue: 10000}),
96+
provide(AppViewManager, {useClass: AppViewManager_}),
9797
AppViewManagerUtils,
9898
AppViewListener,
9999
ProtoViewFactory,
100100
ViewResolver,
101101
DEFAULT_PIPES,
102-
provide(IterableDiffers, {asValue: defaultIterableDiffers}),
103-
provide(KeyValueDiffers, {asValue: defaultKeyValueDiffers}),
102+
provide(IterableDiffers, {useValue: defaultIterableDiffers}),
103+
provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
104104
DirectiveResolver,
105105
PipeResolver,
106-
provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}),
106+
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
107107
provide(LifeCycle,
108108
{
109-
asFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()),
109+
useFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()),
110110
deps: [ExceptionHandler]
111111
})
112112
];
@@ -236,8 +236,8 @@ export class PlatformRef_ extends PlatformRef {
236236
var injector: Injector;
237237
var app: ApplicationRef;
238238
zone.run(() => {
239-
providers.push(provide(NgZone, {asValue: zone}));
240-
providers.push(provide(ApplicationRef, {asFactory: (): ApplicationRef => app, deps: []}));
239+
providers.push(provide(NgZone, {useValue: zone}));
240+
providers.push(provide(ApplicationRef, {useFactory: (): ApplicationRef => app, deps: []}));
241241

242242
var exceptionHandler;
243243
try {
@@ -297,7 +297,7 @@ export abstract class ApplicationRef {
297297
* ```
298298
* var app = platform.application([applicationCommonBindings(), applicationDomBindings()];
299299
* app.bootstrap(FirstRootComponent);
300-
* app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {asClass: OverriddenBinding})]);
300+
* app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {useClass: OverriddenBinding})]);
301301
* ```
302302
*/
303303
abstract bootstrap(componentType: Type, bindings?: Array<Type | Provider | any[]>):

modules/angular2/src/core/application_tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function _appIdRandomProviderFactory() {
4343
* Bindings that will generate a random APP_ID_TOKEN.
4444
*/
4545
export const APP_ID_RANDOM_PROVIDER: Provider =
46-
CONST_EXPR(new Provider(APP_ID, {toFactory: _appIdRandomProviderFactory, deps: []}));
46+
CONST_EXPR(new Provider(APP_ID, {useFactory: _appIdRandomProviderFactory, deps: []}));
4747

4848
function _randomChar(): string {
4949
return StringWrapper.fromCharCode(97 + Math.floor(Math.random() * 25));

modules/angular2/src/core/change_detection/differs/iterable_differs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class IterableDiffers {
5656
*/
5757
static extend(factories: IterableDifferFactory[]): Provider {
5858
return new Provider(IterableDiffers, {
59-
toFactory: (parent: IterableDiffers) => {
59+
useFactory: (parent: IterableDiffers) => {
6060
if (isBlank(parent)) {
6161
// Typically would occur when calling IterableDiffers.extend inside of dependencies passed
6262
// to

modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class KeyValueDiffers {
5656
*/
5757
static extend(factories: KeyValueDifferFactory[]): Provider {
5858
return new Provider(KeyValueDiffers, {
59-
toFactory: (parent: KeyValueDiffers) => {
59+
useFactory: (parent: KeyValueDiffers) => {
6060
if (isBlank(parent)) {
6161
// Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed
6262
// to

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ export function compilerProviders(): Array<Type | Provider | any[]> {
4242
ChangeDetectionCompiler,
4343
provide(ChangeDetectorGenConfig,
4444
{
45-
asValue:
45+
useValue:
4646
new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), false, true)
4747
}),
4848
TemplateCompiler,
49-
provide(RuntimeCompiler, {asClass: RuntimeCompiler_}),
50-
provide(Compiler, {asAlias: RuntimeCompiler}),
49+
provide(RuntimeCompiler, {useClass: RuntimeCompiler_}),
50+
provide(Compiler, {useExisting: RuntimeCompiler}),
5151
DomElementSchemaRegistry,
52-
provide(ElementSchemaRegistry, {asAlias: DomElementSchemaRegistry}),
52+
provide(ElementSchemaRegistry, {useExisting: DomElementSchemaRegistry}),
5353
AnchorBasedAppRootUrl,
54-
provide(AppRootUrl, {asAlias: AnchorBasedAppRootUrl}),
54+
provide(AppRootUrl, {useExisting: AnchorBasedAppRootUrl}),
5555
UrlResolver
5656
];
5757
}

modules/angular2/src/core/debug/debug_element_view_listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class DebugElementViewListener implements AppViewListener {
6969

7070
export const ELEMENT_PROBE_PROVIDERS: any[] = CONST_EXPR([
7171
DebugElementViewListener,
72-
CONST_EXPR(new Provider(AppViewListener, {toAlias: DebugElementViewListener})),
72+
CONST_EXPR(new Provider(AppViewListener, {useExisting: DebugElementViewListener})),
7373
]);
7474

7575
export const ELEMENT_PROBE_BINDINGS = ELEMENT_PROBE_PROVIDERS;

modules/angular2/src/core/di/exceptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export class NoProviderError extends AbstractProviderError {
9191
*
9292
* ```typescript
9393
* var injector = Injector.resolveAndCreate([
94-
* provide("one", {asFactory: (two) => "two", deps: [[new Inject("two")]]}),
95-
* provide("two", {asFactory: (one) => "one", deps: [[new Inject("one")]]})
94+
* provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}),
95+
* provide("two", {useFactory: (one) => "one", deps: [[new Inject("one")]]})
9696
* ]);
9797
*
9898
* expect(() => injector.get("one")).toThrowError();
@@ -252,8 +252,8 @@ export class OutOfBoundsError extends BaseException {
252252
*
253253
* ```typescript
254254
* expect(() => Injector.resolveAndCreate([
255-
* new Provider("Strings", {toValue: "string1", multi: true}),
256-
* new Provider("Strings", {toValue: "string2", multi: false})
255+
* new Provider("Strings", {useValue: "string1", multi: true}),
256+
* new Provider("Strings", {useValue: "string2", multi: false})
257257
* ])).toThrowError();
258258
* ```
259259
*/

0 commit comments

Comments
 (0)
X Tutup