refactor: change provide(...) for {provide: ...}

- provide() is deprecated,
- {} syntax is required by the offline compiler
This commit is contained in:
Victor Berchet 2016-06-02 17:30:40 -07:00
parent 27a47e7841
commit a6ad61d83e
128 changed files with 676 additions and 728 deletions

View File

@ -49,7 +49,7 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s
*
* @Component({
* selector: 'app',
* providers: [provide(NgLocalization, {useClass: MyLocalization})]
* providers: [{provide: NgLocalization, useClass: MyLocalization}]
* })
* @View({
* template: `

View File

@ -7,7 +7,6 @@ import {
Host,
SkipSelf,
forwardRef,
Provider,
Self
} from '@angular/core';
import {ControlContainer} from './control_container';

View File

@ -6,7 +6,6 @@ import {
Optional,
Host,
OnDestroy,
Provider,
forwardRef
} from "@angular/core";
import {

View File

@ -13,7 +13,7 @@ import {AbstractControl} from '../model';
* ```typescript
* @Directive({
* selector: '[custom-validator]',
* providers: [provide(NG_VALIDATORS, {useExisting: CustomValidatorDirective, multi: true})]
* providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
* })
* class CustomValidatorDirective implements Validator {
* validate(c: Control): {[key: string]: any} {

View File

@ -42,7 +42,7 @@ import {UrlChangeListener, PlatformLocation} from './platform_location';
*
* bootstrap(AppCmp, [
* ROUTER_PROVIDERS,
* provide(LocationStrategy, {useClass: HashLocationStrategy})
* {provide: LocationStrategy, useClass: HashLocationStrategy}
* ]);
* ```
*

View File

@ -56,7 +56,7 @@ export abstract class LocationStrategy {
*
* bootstrap(AppCmp, [
* ROUTER_PROVIDERS,
* provide(APP_BASE_HREF, {useValue: '/my/app'})
* {provide: APP_BASE_HREF, useValue: '/my/app'}
* ]);
* ```
* @stable

View File

@ -26,7 +26,7 @@ import {Location} from './location';
* ### Example
*
* ```
* import {Component, provide} from '@angular/core';
* import {Component} from '@angular/core';
* import {bootstrap} from '@angular/platform-browser/browser';
* import {
* Location,
@ -50,7 +50,7 @@ import {Location} from './location';
*
* bootstrap(AppCmp, [
* ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
* provide(APP_BASE_HREF, {useValue: '/my/app'})
* {provide: APP_BASE_HREF, useValue: '/my/app'}
* ]);
* ```
*

View File

@ -10,14 +10,14 @@ import {
xit,
} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {Component, Injectable, provide} from '@angular/core';
import {Component, Injectable} from '@angular/core';
import {NgPlural, NgPluralCase, NgLocalization} from '@angular/common';
export function main() {
describe('switch', () => {
beforeEachProviders(() => [provide(NgLocalization, {useClass: TestLocalizationMap})]);
beforeEachProviders(() => [{provide: NgLocalization, useClass: TestLocalizationMap}]);
it('should display the template according to the exact value',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {

View File

@ -35,7 +35,6 @@ import {By} from '@angular/platform-browser/src/dom/debug/by';
import {ListWrapper} from '../../src/facade/collection';
import {ObservableWrapper, TimerWrapper} from '../../src/facade/async';
import {PromiseWrapper} from '../../src/facade/promise';
import {browserDetection} from '@angular/platform-browser/testing';
import {dispatchEvent} from '@angular/platform-browser/testing';
export function main() {
@ -1547,8 +1546,7 @@ class LoginIsEmptyValidator {
@Directive({
selector: '[uniq-login-validator]',
providers: [
new Provider(NG_ASYNC_VALIDATORS,
{useExisting: forwardRef(() => UniqLoginValidator), multi: true})
{provide: NG_ASYNC_VALIDATORS, useExisting: forwardRef(() => UniqLoginValidator), multi: true}
]
})
class UniqLoginValidator implements Validator {

View File

@ -29,11 +29,9 @@ import {
AfterViewInit,
AfterViewChecked,
SimpleChanges,
provide
} from '@angular/core';
import {TEST_PROVIDERS} from './test_bindings';
import {MODULE_SUFFIX} from '@angular/compiler/src/util';
import {PLATFORM_DIRECTIVES} from '@angular/core/src/platform_directives_and_pipes';
import {MalformedStylesComponent} from './metadata_resolver_fixture';
@ -92,7 +90,7 @@ export function main() {
describe("platform directives", () => {
beforeEachProviders(
() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective], multi: true})]);
() => [{provide: PLATFORM_DIRECTIVES, useValue: [ADirective], multi: true}]);
it('should include platform directives when available',
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {

View File

@ -10,7 +10,6 @@ import {
inject,
beforeEachProviders
} from '@angular/core/testing/testing_internal';
import {provide} from '@angular/core';
import {SecurityContext} from '../core_private';
import {Console} from '@angular/core/src/console';
@ -63,9 +62,10 @@ var expressionUnparser = new Unparser();
var someModuleUrl = 'package:someModule';
var MOCK_SCHEMA_REGISTRY = [
provide(
ElementSchemaRegistry,
{useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})})
{
provide: ElementSchemaRegistry,
useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})
}
];
let zeConsole = console;
@ -80,7 +80,7 @@ export function main() {
function commonBeforeEach() {
beforeEachProviders(() => {
console = new ArrayConsole();
return [provide(Console, {useValue: console})];
return [{provide: Console, useValue: console}];
});
beforeEach(inject([TemplateParser], (parser) => {
var component = CompileDirectiveMetadata.create({
@ -108,7 +108,7 @@ export function main() {
beforeEachProviders(() => [TEST_PROVIDERS, MOCK_SCHEMA_REGISTRY]);
beforeEachProviders(
() => [provide(TEMPLATE_TRANSFORMS, {useValue: new FooAstTransformer(), multi: true})]);
() => [{provide: TEMPLATE_TRANSFORMS, useValue: new FooAstTransformer(), multi: true}]);
describe('single', () => {
commonBeforeEach();
@ -118,7 +118,7 @@ export function main() {
describe('multiple', () => {
beforeEachProviders(
() => [provide(TEMPLATE_TRANSFORMS, {useValue: new BarAstTransformer(), multi: true})]);
() => [{provide: TEMPLATE_TRANSFORMS, useValue: new BarAstTransformer(), multi: true}]);
commonBeforeEach();
it('should compose transformers',
@ -131,7 +131,7 @@ export function main() {
// Uses the actual DomElementSchemaRegistry.
beforeEachProviders(
() =>
[TEST_PROVIDERS, provide(ElementSchemaRegistry, {useClass: DomElementSchemaRegistry})]);
[TEST_PROVIDERS, {provide: ElementSchemaRegistry, useClass: DomElementSchemaRegistry}]);
commonBeforeEach();

View File

@ -4,7 +4,7 @@ import {ElementSchemaRegistry, XHR, UrlResolver} from '@angular/compiler';
import {createUrlResolverWithoutPackagePrefix} from '@angular/compiler/src/url_resolver';
export var TEST_PROVIDERS: any[] = [
provide(ElementSchemaRegistry, {useValue: new MockSchemaRegistry({}, {})}),
provide(XHR, {useClass: MockXHR}),
provide(UrlResolver, {useFactory: createUrlResolverWithoutPackagePrefix})
{provide: ElementSchemaRegistry, useValue: new MockSchemaRegistry({}, {})},
{provide: XHR, useClass: MockXHR},
{provide: UrlResolver, useFactory: createUrlResolverWithoutPackagePrefix}
];

View File

@ -18,7 +18,6 @@ import {
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {
Injectable,
provide,
Component,
Input,
ViewMetadata,
@ -290,7 +289,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideProviders(TestBindingsComp,
[provide(FancyService, {useClass: MockFancyService})])
[{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestBindingsComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -305,7 +304,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideViewProviders(TestViewBindingsComp,
[provide(FancyService, {useClass: MockFancyService})])
[{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestViewBindingsComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -337,7 +336,7 @@ export function main() {
}));
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
withProviders(() => [provide(ComponentFixtureAutoDetect, {useValue: true})])
withProviders(() => [{provide: ComponentFixtureAutoDetect, useValue: true}])
.inject([TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async) => {
@ -551,7 +550,7 @@ export function main() {
}));
describe('No NgZone', () => {
beforeEachProviders(() => [provide(ComponentFixtureNoNgZone, {useValue: true})]);
beforeEachProviders(() => [{provide: ComponentFixtureNoNgZone, useValue: true}]);
it('calling autoDetectChanges raises an error', () => {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,

View File

@ -20,7 +20,7 @@ export abstract class Injector {
*
* ```typescript
* var injector = ReflectiveInjector.resolveAndCreate([
* provide("validToken", {useValue: "Value"})
* {provide: "validToken", useValue: "Value"}
* ]);
* expect(injector.get("validToken")).toEqual("Value");
* expect(() => injector.get("invalidToken")).toThrowError();

View File

@ -17,7 +17,7 @@ import {stringify} from '../facade/lang';
* }
*
* var injector = Injector.resolveAndCreate([
* provide("MyEngine", {useClass: Engine}),
* {provide: "MyEngine", useClass: Engine},
* Car
* ]);
*

View File

@ -7,7 +7,7 @@
* var t = new OpaqueToken("value");
*
* var injector = Injector.resolveAndCreate([
* provide(t, {useValue: "bindingValue"})
* {provide: t, useValue: "bindingValue"}
* ]);
*
* expect(injector.get(t)).toEqual("bindingValue");

View File

@ -280,11 +280,11 @@ export class ProviderBuilder {
*
* var injectorClass = Injector.resolveAndCreate([
* Car,
* provide(Vehicle, {useClass: Car})
* {provide: Vehicle, useClass: Car}
* ]);
* var injectorAlias = Injector.resolveAndCreate([
* Car,
* provide(Vehicle, {useExisting: Car})
* {provide: Vehicle, useExisting: Car}
* ]);
*
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
@ -309,7 +309,7 @@ export class ProviderBuilder {
*
* ```typescript
* var injector = Injector.resolveAndCreate([
* provide('message', {useValue: 'Hello'})
* {provide: 'message', useValue: 'Hello'}
* ]);
*
* expect(injector.get('message')).toEqual('Hello');
@ -335,11 +335,11 @@ export class ProviderBuilder {
*
* var injectorAlias = Injector.resolveAndCreate([
* Car,
* provide(Vehicle, {useExisting: Car})
* {provide: Vehicle, useExisting: Car}
* ]);
* var injectorClass = Injector.resolveAndCreate([
* Car,
* provide(Vehicle, {useClass: Car})
* {provide: Vehicle, useClass: Car})
* ]);
*
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
@ -363,8 +363,8 @@ export class ProviderBuilder {
*
* ```typescript
* var injector = Injector.resolveAndCreate([
* provide(Number, {useFactory: () => { return 1+2; }}),
* provide(String, {useFactory: (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);

View File

@ -94,8 +94,8 @@ export class NoProviderError extends AbstractProviderError {
*
* ```typescript
* var injector = Injector.resolveAndCreate([
* provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}),
* provide("two", {useFactory: (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();

View File

@ -21,7 +21,7 @@ import {OpaqueToken} from './di';
* ...
* }
*
* bootstrap(MyComponent, [provide(PLATFORM_DIRECTIVES, {useValue: [OtherDirective], multi:true})]);
* bootstrap(MyComponent, [{provide: PLATFORM_DIRECTIVES, useValue: [OtherDirective], multi:true}]);
* ```
* @stable
*/
@ -48,7 +48,7 @@ export const PLATFORM_DIRECTIVES: OpaqueToken =
* ...
* }
*
* bootstrap(MyComponent, [provide(PLATFORM_PIPES, {useValue: [OtherPipe], multi:true})]);
* bootstrap(MyComponent, [{provide: PLATFORM_PIPES, useValue: [OtherPipe], multi:true}]);
* ```
* @stable
*/

View File

@ -24,9 +24,9 @@ import {
import {isPresent, isArray, IS_DART} from '../../src/facade/lang';
import {provide, Component} from '../../index';
import {Component} from '../../index';
import {NgIf, NgFor, AsyncPipe} from '@angular/common';
import {NgIf} from '@angular/common';
import {CompilerConfig} from '@angular/compiler';
import {AnimationDriver} from '../../src/animation/animation_driver';
@ -41,13 +41,13 @@ export function main() {
} else {
describe('jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests();
});
describe('no jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests();
});
}
@ -55,7 +55,7 @@ export function main() {
function declareTests() {
describe('animation tests', function() {
beforeEachProviders(() => [provide(AnimationDriver, {useClass: MockAnimationDriver})]);
beforeEachProviders(() => [{provide: AnimationDriver, useClass: MockAnimationDriver}]);
var makeAnimationCmp = (tcb: TestComponentBuilder, tpl: string, animationEntry: AnimationEntryMetadata|AnimationEntryMetadata[], callback = null) => {
var entries = isArray(animationEntry)

View File

@ -20,7 +20,6 @@ import {
} from '@angular/core/src/application_ref';
import {
Injector,
Provider,
APP_INITIALIZER,
Component,
ReflectiveInjector,
@ -63,8 +62,7 @@ export function main() {
APPLICATION_CORE_PROVIDERS,
{provide: Console, useValue: new _MockConsole()},
{provide: ExceptionHandler, useValue: new ExceptionHandler(errorLogger, false)},
new Provider(ComponentResolver,
{useValue: new _MockComponentResolver(someCompFactory)}),
{provide: ComponentResolver, useValue: new _MockComponentResolver(someCompFactory)},
providers
],
platform.injector);
@ -125,8 +123,7 @@ export function main() {
it("should throw if an APP_INITIIALIZER is not yet resolved",
inject([Injector], (injector) => {
var app = createApplication([
new Provider(APP_INITIALIZER,
{useValue: () => PromiseWrapper.completer().promise, multi: true})
{provide: APP_INITIALIZER, useValue: () => PromiseWrapper.completer().promise, multi: true}
]);
expect(() => app.bootstrap(someCompFactory))
.toThrowError(

View File

@ -60,7 +60,7 @@ export function main() {
it('should extend di-inherited diffesr', () => {
var parent = new IterableDiffers([factory1]);
var injector =
ReflectiveInjector.resolveAndCreate([provide(IterableDiffers, {useValue: parent})]);
ReflectiveInjector.resolveAndCreate([{provide: IterableDiffers, useValue: parent}]);
var childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
expect(injector.get(IterableDiffers).factories).toEqual([factory1]);

View File

@ -1,8 +1,7 @@
import {isBlank, stringify, isPresent} from '../../src/facade/lang';
import {BaseException, WrappedException} from '../../src/facade/exceptions';
import {BaseException} from '../../src/facade/exceptions';
import {describe, ddescribe, it, iit, expect, beforeEach} from '@angular/core/testing';
import {
provide,
ReflectiveKey,
ReflectiveInjector,
Injector,
@ -10,10 +9,8 @@ import {
Injectable,
InjectMetadata,
SelfMetadata,
SkipSelfMetadata,
Optional,
Inject,
Provider
} from '@angular/core';
import {
ReflectiveInjector_,
@ -88,17 +85,17 @@ function factoryFn(a) {}
export function main() {
var dynamicProviders = [
provide('provider0', {useValue: 1}),
provide('provider1', {useValue: 1}),
provide('provider2', {useValue: 1}),
provide('provider3', {useValue: 1}),
provide('provider4', {useValue: 1}),
provide('provider5', {useValue: 1}),
provide('provider6', {useValue: 1}),
provide('provider7', {useValue: 1}),
provide('provider8', {useValue: 1}),
provide('provider9', {useValue: 1}),
provide('provider10', {useValue: 1})
{provide: 'provider0', useValue: 1},
{provide: 'provider1', useValue: 1},
{provide: 'provider2', useValue: 1},
{provide: 'provider3', useValue: 1},
{provide: 'provider4', useValue: 1},
{provide: 'provider5', useValue: 1},
{provide: 'provider6', useValue: 1},
{provide: 'provider7', useValue: 1},
{provide: 'provider8', useValue: 1},
{provide: 'provider9', useValue: 1},
{provide: 'provider10', useValue: 1}
];
[{strategy: 'inline', providers: [], strategyClass: ReflectiveInjectorInlineStrategy},
@ -155,7 +152,7 @@ export function main() {
});
it('should throw when no type and not @Inject (factory case)', () => {
expect(() => createInjector([provide("someToken", {useFactory: factoryFn})]))
expect(() => createInjector([{provide: "someToken", useFactory: factoryFn}]))
.toThrowError(
"Cannot resolve all parameters for 'factoryFn'(?). " +
'Make sure that all the parameters are decorated with Inject or have valid type annotations ' +
@ -172,7 +169,7 @@ export function main() {
});
it('should provide to a value', () => {
var injector = createInjector([provide(Engine, {useValue: "fake engine"})]);
var injector = createInjector([{provide: Engine, useValue: "fake engine"}]);
var engine = injector.get(Engine);
expect(engine).toEqual("fake engine");
@ -182,7 +179,7 @@ export function main() {
function sportsCarFactory(e) { return new SportsCar(e); }
var injector =
createInjector([Engine, provide(Car, {useFactory: sportsCarFactory, deps: [Engine]})]);
createInjector([Engine, {provide: Car, useFactory: sportsCarFactory, deps: [Engine]}]);
var car = injector.get(Car);
expect(car).toBeAnInstanceOf(SportsCar);
@ -194,33 +191,33 @@ export function main() {
var injector = createInjector([
Engine,
provide(Car,
{
useFactory: factoryWithTooManyArgs,
deps: [
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine
]
})
{
provide: Car,
useFactory: factoryWithTooManyArgs,
deps: [
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine
]
}
]);
try {
@ -233,7 +230,7 @@ export function main() {
});
it('should supporting provider to null', () => {
var injector = createInjector([provide(Engine, {useValue: null})]);
var injector = createInjector([{provide: Engine, useValue: null}]);
var engine = injector.get(Engine);
expect(engine).toBeNull();
});
@ -241,8 +238,8 @@ export function main() {
it('should provide to an alias', () => {
var injector = createInjector([
Engine,
provide(SportsCar, {useClass: SportsCar}),
provide(Car, {useExisting: SportsCar})
{provide: SportsCar, useClass: SportsCar},
{provide: Car, useExisting: SportsCar}
]);
var car = injector.get(Car);
@ -278,22 +275,22 @@ export function main() {
});
it('should throw when the aliased provider does not exist', () => {
var injector = createInjector([provide('car', {useExisting: SportsCar})]);
var injector = createInjector([{provide: 'car', useExisting: SportsCar}]);
var e = `No provider for ${stringify(SportsCar)}! (car -> ${stringify(SportsCar)})`;
expect(() => injector.get('car')).toThrowError(e);
});
it('should handle forwardRef in useExisting', () => {
var injector = createInjector([
provide('originalEngine', {useClass: forwardRef(() => Engine)}),
provide('aliasedEngine', {useExisting:<any>forwardRef(() => 'originalEngine')})
{provide: 'originalEngine', useClass: forwardRef(() => Engine)},
{provide: 'aliasedEngine', useExisting:<any>forwardRef(() => 'originalEngine')}
]);
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
});
it('should support overriding factory dependencies', () => {
var injector = createInjector(
[Engine, provide(Car, {useFactory: (e) => new SportsCar(e), deps: [Engine]})]);
[Engine, {provide: Car, useFactory: (e) => new SportsCar(e), deps: [Engine]}]);
var car = injector.get(Car);
expect(car).toBeAnInstanceOf(SportsCar);
@ -316,13 +313,13 @@ export function main() {
it("should use the last provider when there are multiple providers for same token", () => {
var injector = createInjector(
[provide(Engine, {useClass: Engine}), provide(Engine, {useClass: TurboEngine})]);
[{provide: Engine, useClass: Engine}, {provide: Engine, useClass: TurboEngine}]);
expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
});
it('should use non-type tokens', () => {
var injector = createInjector([provide('token', {useValue: 'value'})]);
var injector = createInjector([{provide: 'token', useValue: 'value'}]);
expect(injector.get('token')).toEqual('value');
});
@ -353,7 +350,7 @@ export function main() {
});
it('should throw when trying to instantiate a cyclic dependency', () => {
var injector = createInjector([Car, provide(Engine, {useClass: CyclicEngine})]);
var injector = createInjector([Car, {provide: Engine, useClass: CyclicEngine}]);
expect(() => injector.get(Car))
.toThrowError(
@ -362,7 +359,7 @@ export function main() {
it('should show the full path when error happens in a constructor', () => {
var providers =
ReflectiveInjector.resolve([Car, provide(Engine, {useClass: BrokenEngine})]);
ReflectiveInjector.resolve([Car, {provide: Engine, useClass: BrokenEngine}]);
var proto = new ReflectiveProtoInjector([providers[0], providers[1]]);
var injector = new ReflectiveInjector_(proto);
@ -379,7 +376,7 @@ export function main() {
it('should provide context when throwing an exception ', () => {
var engineProvider =
ReflectiveInjector.resolve([provide(Engine, {useClass: BrokenEngine})])[0];
ReflectiveInjector.resolve([{provide: Engine, useClass: BrokenEngine}])[0];
var protoParent = new ReflectiveProtoInjector([engineProvider]);
var carProvider = ReflectiveInjector.resolve([Car])[0];
@ -401,7 +398,7 @@ export function main() {
var injector = createInjector([
Car,
provide(Engine, {useFactory: (() => isBroken ? new BrokenEngine() : new Engine())})
{provide: Engine, useFactory: (() => isBroken ? new BrokenEngine() : new Engine())}
]);
expect(() => injector.get(Car)).toThrowError(new RegExp("Error"));
@ -412,7 +409,7 @@ export function main() {
});
it('should support null values', () => {
var injector = createInjector([provide('null', {useValue: null})]);
var injector = createInjector([{provide: 'null', useValue: null}]);
expect(injector.get('null')).toBe(null);
});
@ -433,7 +430,7 @@ export function main() {
it("should not use the child providers when resolving the dependencies of a parent provider",
() => {
var parent = ReflectiveInjector.resolveAndCreate([Car, Engine]);
var child = parent.resolveAndCreateChild([provide(Engine, {useClass: TurboEngine})]);
var child = parent.resolveAndCreateChild([{provide: Engine, useClass: TurboEngine}]);
var carFromChild = child.get(Car);
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
@ -441,7 +438,7 @@ export function main() {
it('should create new instance in a child injector', () => {
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([provide(Engine, {useClass: TurboEngine})]);
var child = parent.resolveAndCreateChild([{provide: Engine, useClass: TurboEngine}]);
var engineFromParent = parent.get(Engine);
var engineFromChild = child.get(Engine);
@ -486,7 +483,7 @@ export function main() {
it("should return a dependency from self", () => {
var inj = ReflectiveInjector.resolveAndCreate([
Engine,
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
{provide: Car, useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]}
]);
expect(inj.get(Car)).toBeAnInstanceOf(Car);
@ -495,7 +492,7 @@ export function main() {
it("should throw when not requested provider on self", () => {
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
{provide: Car, useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]}
]);
expect(() => child.get(Car))
@ -507,8 +504,8 @@ export function main() {
it("should not skip self", () => {
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([
provide(Engine, {useClass: TurboEngine}),
provide(Car, {useFactory: (e) => new Car(e), deps: [Engine]})
{provide: Engine, useClass: TurboEngine},
{provide: Car, useFactory: (e) => new Car(e), deps: [Engine]}
]);
expect(child.get(Car).engine).toBeAnInstanceOf(TurboEngine);
@ -578,9 +575,9 @@ export function main() {
it('should resolve forward references', () => {
var providers = ReflectiveInjector.resolve([
forwardRef(() => Engine),
[provide(forwardRef(() => BrokenEngine), {useClass: forwardRef(() => Engine)})],
provide(forwardRef(() => String),
{useFactory: () => 'OK', deps: [forwardRef(() => Engine)]})
[{provide: forwardRef(() => BrokenEngine), useClass: forwardRef(() => Engine)}],
{provide: forwardRef(() => String),
useFactory: () => 'OK', deps: [forwardRef(() => Engine)]}
]);
var engineProvider = providers[0];
@ -597,12 +594,11 @@ export function main() {
it('should support overriding factory dependencies with dependency annotations',
() => {
var providers = ReflectiveInjector.resolve([
provide(
"token",
{
useFactory: (e) => "result",
deps: [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]
})
{
provide: "token",
useFactory: (e) => "result",
deps: [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]
}
]);
var provider = providers[0];
@ -614,9 +610,9 @@ export function main() {
it('should allow declaring dependencies with flat arrays', () => {
var resolved = ReflectiveInjector.resolve(
[provide('token', {useFactory: e => e, deps: [new InjectMetadata("dep")]})]);
[{provide: 'token', useFactory: e => e, deps: [new InjectMetadata("dep")]}]);
var nestedResolved = ReflectiveInjector.resolve(
[provide('token', {useFactory: e => e, deps: [[new InjectMetadata("dep")]]})]);
[{provide: 'token', useFactory: e => e, deps: [[new InjectMetadata("dep")]]}]);
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
});

View File

@ -125,7 +125,7 @@ export function main() {
beforeEachProviders(() => [
RenderLog,
DirectiveLog,
provide(RootRenderer, {useClass: LoggingRootRenderer}),
{provide: RootRenderer, useClass: LoggingRootRenderer},
TEST_PROVIDERS,
]);

View File

@ -15,15 +15,11 @@ import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {
Type,
isPresent,
assertionsEnabled,
isJsObject,
global,
stringify,
isBlank,
} from '../../src/facade/lang';
import {BaseException, WrappedException} from '../../src/facade/exceptions';
import {BaseException} from '../../src/facade/exceptions';
import {
PromiseWrapper,
EventEmitter,
@ -33,10 +29,7 @@ import {
import {
Injector,
bind,
provide,
Injectable,
Provider,
forwardRef,
OpaqueToken,
Inject,
@ -91,13 +84,13 @@ export function main() {
} else {
describe('jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
}
@ -106,7 +99,7 @@ export function main() {
function declareTests(isJit: boolean) {
describe('integration tests', function() {
beforeEachProviders(() => [provide(ANCHOR_ELEMENT, {useValue: el('<div></div>')})]);
beforeEachProviders(() => [{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
describe('react to record changes', function() {
it('should consume text node changes',
@ -1714,7 +1707,7 @@ function declareTests(isJit: boolean) {
describe('logging property updates', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, true, isJit)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, true, isJit)}]);
it('should reflect property values as attributes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
@ -1947,7 +1940,7 @@ class DynamicViewport {
var myService = new MyService();
myService.greeting = 'dynamic greet';
var injector = ReflectiveInjector.resolveAndCreate([provide(MyService, {useValue: myService})],
var injector = ReflectiveInjector.resolveAndCreate([{ provide: MyService, useValue: myService}],
vc.injector);
this.done = compiler.resolveComponent(ChildCompUsingService)
.then((componentFactory) => vc.createComponent(componentFactory, 0, injector));
@ -2436,13 +2429,10 @@ function createParentBus(peb) {
@Component({
selector: 'parent-providing-event-bus',
providers: [
new Provider(EventBus,
{useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]})
{provide: EventBus, useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]}
],
directives: [forwardRef(() => ChildConsumingEventBus)],
template: `
<child-consuming-event-bus></child-consuming-event-bus>
`
template: `<child-consuming-event-bus></child-consuming-event-bus>`
})
class ParentProvidingEventBus {
bus: EventBus;

View File

@ -25,7 +25,7 @@ export function main() {
describe('Compiler', () => {
var someCompFactory;
beforeEachProviders(() => [provide(ComponentResolver, {useClass: ReflectorComponentResolver})]);
beforeEachProviders(() => [{provide: ComponentResolver, useClass: ReflectorComponentResolver}]);
beforeEach(inject([ComponentResolver], (_compiler) => {
someCompFactory = new ComponentFactory(null, null, null);

View File

@ -34,13 +34,13 @@ export function main() {
} else {
describe('jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
}
@ -51,7 +51,7 @@ function declareTests(isJit: boolean) {
describe('regressions', () => {
describe('platform pipes', () => {
beforeEachProviders(() => [provide(PLATFORM_PIPES, {useValue: [PlatformPipe], multi: true})]);
beforeEachProviders(() => [{provide: PLATFORM_PIPES, useValue: [PlatformPipe], multi: true}]);
it('should overwrite them by custom pipes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
@ -106,7 +106,7 @@ function declareTests(isJit: boolean) {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var token = new OpaqueToken('a.b');
var tokenValue = 1;
createInjector(tcb, [provide(token, {useValue: tokenValue})])
createInjector(tcb, [{provide: token, useValue: tokenValue}])
.then((injector: Injector) => {
expect(injector.get(token)).toEqual(tokenValue);
async.done();
@ -117,7 +117,7 @@ function declareTests(isJit: boolean) {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var token = 'a.b';
var tokenValue = 1;
createInjector(tcb, [provide(token, {useValue: tokenValue})])
createInjector(tcb, [{provide: token, useValue: tokenValue}])
.then((injector: Injector) => {
expect(injector.get(token)).toEqual(tokenValue);
async.done();
@ -128,7 +128,7 @@ function declareTests(isJit: boolean) {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var token = () => true;
var tokenValue = 1;
createInjector(tcb, [provide(token, {useValue: tokenValue})])
createInjector(tcb, [{provide: token, useValue: tokenValue}])
.then((injector: Injector) => {
expect(injector.get(token)).toEqual(tokenValue);
async.done();
@ -143,7 +143,7 @@ function declareTests(isJit: boolean) {
var tokenValue2 = {'a': 1};
createInjector(
tcb,
[provide(token1, {useValue: tokenValue1}), provide(token2, {useValue: tokenValue2})])
[{provide: token1, useValue: tokenValue1}, {provide: token2, useValue: tokenValue2}])
.then((injector: Injector) => {
expect(injector.get(token1)).toEqual(tokenValue1);
expect(injector.get(token2)).toEqual(tokenValue2);

View File

@ -28,13 +28,13 @@ export function main() {
} else {
describe('jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => {
beforeEachProviders(
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
}
@ -63,7 +63,7 @@ function itAsync(msg: string,
function declareTests(isJit: boolean) {
describe('security integration tests', function() {
beforeEachProviders(() => [provide(ANCHOR_ELEMENT, {useValue: el('<div></div>')})]);
beforeEachProviders(() => [{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
let originalLog: (msg: any) => any;
beforeEach(() => {

View File

@ -287,7 +287,7 @@ export function main() {
// On CJS fakeAsync is not supported...
if (!getDOM().supportsDOMEvents()) return;
beforeEachProviders(() => [provide("appService", {useValue: 'appService'})]);
beforeEachProviders(() => [{provide: "appService", useValue: 'appService'}]);
beforeEach(inject([TestComponentBuilder], (_tcb) => { tcb = _tcb; }));
@ -308,14 +308,14 @@ export function main() {
it('should support useValue with different values', fakeAsync(() => {
var el = createComp('', tcb.overrideProviders(TestComp, [
provide('numLiteral', {useValue: 0}),
provide('boolLiteral', {useValue: true}),
provide('strLiteral', {useValue: 'a'}),
provide('null', {useValue: null}),
provide('array', {useValue: [1]}),
provide('map', {useValue: {'a': 1}}),
provide('instance', {useValue: new TestValue('a')}),
provide('nested', {useValue: [{'a': [1]}, new TestValue('b')]}),
{provide:'numLiteral', useValue: 0},
{provide: 'boolLiteral', useValue: true},
{provide: 'strLiteral', useValue: 'a'},
{provide: 'null', useValue: null},
{provide: 'array', useValue: [1]},
{provide: 'map', useValue: {'a': 1}},
{provide: 'instance', useValue: new TestValue('a')},
{provide: 'nested', useValue: [{'a': [1]}, new TestValue('b')]},
]));
expect(el.inject('numLiteral')).toBe(0);
expect(el.inject('boolLiteral')).toBe(true);
@ -331,19 +331,19 @@ export function main() {
var el = createComp('<div simpleDirective><span someOtherDirective></span></div>',
tcb.overrideProviders(
SimpleDirective,
[provide('injectable1', {useValue: 'injectable1'})])
[{provide: 'injectable1', useValue: 'injectable1'}])
.overrideProviders(SomeOtherDirective, [
provide('injectable1', {useValue: 'new-injectable1'}),
provide('injectable2',
{
useFactory: (val) => `${val}-injectable2`,
deps: [
[
new InjectMetadata('injectable1'),
new SkipSelfMetadata()
]
]
})
{provide: 'injectable1', useValue: 'new-injectable1'},
{
provide: 'injectable2',
useFactory: (val) => `${val}-injectable2`,
deps: [
[
new InjectMetadata('injectable1'),
new SkipSelfMetadata()
]
]
}
]));
expect(el.children[0].children[0].inject('injectable2'))
.toEqual('injectable1-injectable2');
@ -351,9 +351,8 @@ export function main() {
it("should instantiate providers that have dependencies", fakeAsync(() => {
var providers = [
provide('injectable1', {useValue: 'injectable1'}),
provide('injectable2',
{useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']})
{provide: 'injectable1', useValue: 'injectable1'},
{provide: 'injectable2', useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']}
];
var el = createComp('<div simpleDirective></div>',
tcb.overrideProviders(SimpleDirective, providers));
@ -362,9 +361,8 @@ export function main() {
it("should instantiate viewProviders that have dependencies", fakeAsync(() => {
var viewProviders = [
provide('injectable1', {useValue: 'injectable1'}),
provide('injectable2',
{useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']})
{provide: 'injectable1', useValue: 'injectable1'},
{provide: 'injectable2', useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']}
];
var el = createComp('<div simpleComponent></div>',
@ -376,14 +374,14 @@ export function main() {
var el =
createComp('<div needsServiceComponent></div>',
tcb.overrideViewProviders(NeedsServiceComponent,
[provide('service', {useValue: 'service'})]));
[{provide: 'service', useValue: 'service'}]));
expect(el.children[0].inject(NeedsServiceComponent).service).toEqual('service');
}));
it("should instantiate multi providers", fakeAsync(() => {
var providers = [
provide('injectable1', {useValue: 'injectable11', multi: true}),
provide('injectable1', {useValue: 'injectable12', multi: true})
{provide: 'injectable1', useValue: 'injectable11', multi: true},
{provide: 'injectable1', useValue: 'injectable12', multi: true}
];
var el = createComp('<div simpleDirective></div>',
tcb.overrideProviders(SimpleDirective, providers));
@ -395,7 +393,7 @@ export function main() {
var el = createComp(
'<div simpleDirective></div>',
tcb.overrideProviders(SimpleDirective,
[provide('service', {useFactory: () => created = true})]));
[{provide: 'service', useFactory: () => created = true}]));
expect(created).toBe(false);
@ -409,7 +407,7 @@ export function main() {
var el = createComp(
'<div simpleComponent></div>',
tcb.overrideViewProviders(SimpleComponent,
[provide('service', {useFactory: () => created = true})]));
[{provide: 'service', useFactory: () => created = true}]));
expect(created).toBe(false);
@ -423,7 +421,7 @@ export function main() {
expect(() =>
createComp('<div simpleComponent needsService></div>',
tcb.overrideViewProviders(
SimpleComponent, [provide("service", {useValue: "service"})])))
SimpleComponent, [{provide: "service", useValue: "service"}])))
.toThrowError(containsRegexp(`No provider for service!`));
}));
@ -432,7 +430,7 @@ export function main() {
var el =
createComp('<div simpleDirective><div needsService></div></div>',
tcb.overrideProviders(SimpleDirective,
[provide('service', {useValue: 'parentService'})]));
[{provide: 'service', useValue: 'parentService'}]));
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
}));
@ -441,7 +439,7 @@ export function main() {
var el = createComp(
'<div simpleDirective><template [ngIf]="true"><div *ngIf="true" needsService></div></template></div>',
tcb.overrideProviders(SimpleDirective,
[provide('service', {useValue: 'parentService'})]));
[{provide: 'service', useValue: 'parentService'}]));
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
}));
@ -450,7 +448,7 @@ export function main() {
createComp('<div simpleComponent></div>',
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
.overrideProviders(SimpleComponent,
[provide('service', {useValue: 'hostService'})]));
[{provide: 'service', useValue: 'hostService'}]));
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
}));
@ -460,7 +458,7 @@ export function main() {
'<div simpleComponent></div>',
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
.overrideViewProviders(SimpleComponent,
[provide('service', {useValue: 'hostService'})]));
[{provide: 'service', useValue: 'hostService'}]));
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
}));
@ -470,7 +468,7 @@ export function main() {
'<div simpleComponent></div>',
tcb.overrideTemplate(SimpleComponent, '<div *ngIf="true" needsService></div>')
.overrideViewProviders(SimpleComponent,
[provide('service', {useValue: 'hostService'})]));
[{provide: 'service', useValue: 'hostService'}]));
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
}));
@ -492,7 +490,7 @@ export function main() {
expect(() => createComp(
'<div simpleComponent></div>',
tcb.overrideProviders(SimpleComponent,
[provide('service', {useValue: 'hostService'})])
[{provide: 'service', useValue: 'hostService'}])
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
.toThrowError(
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
@ -504,7 +502,7 @@ export function main() {
expect(() => createComp(
'<div simpleComponent someOtherDirective></div>',
tcb.overrideProviders(SomeOtherDirective,
[provide('service', {useValue: 'hostService'})])
[{provide: 'service', useValue: 'hostService'}])
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
.toThrowError(
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
@ -652,7 +650,7 @@ export function main() {
it('should instantiate pipes that have dependencies', fakeAsync(() => {
var el = createComp(
'<div [simpleDirective]="true | pipeNeedsService"></div>',
tcb.overrideProviders(TestComp, [provide('service', {useValue: 'pipeService'})]));
tcb.overrideProviders(TestComp, [{provide: 'service', useValue: 'pipeService'}]));
expect(el.children[0].inject(SimpleDirective).value.service).toEqual('pipeService');
}));

View File

@ -13,7 +13,7 @@ export class TestInjector {
private _injector: ReflectiveInjector = null;
private _providers: Array<Type | Provider | any[]> = [];
private _providers: Array<Type | Provider | any[] | any> = [];
reset() {
this._injector = null;
@ -21,11 +21,11 @@ export class TestInjector {
this._instantiated = false;
}
platformProviders: Array<Type | Provider | any[]> = [];
platformProviders: Array<Type | Provider | any[] | any> = [];
applicationProviders: Array<Type | Provider | any[]> = [];
applicationProviders: Array<Type | Provider | any[] | any> = [];
addProviders(providers: Array<Type | Provider | any[]>) {
addProviders(providers: Array<Type | Provider | any[] | any>) {
if (this._instantiated) {
throw new BaseException('Cannot add providers after test injector is instantiated');
}

View File

@ -92,8 +92,8 @@ export function beforeEach(fn: Function): void {
* Example:
*
* beforeEachProviders(() => [
* provide(Compiler, {useClass: MockCompiler}),
* provide(SomeToken, {useValue: myValue}),
* {provide: Compiler, useClass: MockCompiler},
* {provide: SomeToken, useValue: myValue},
* ]);
*/
export function beforeEachProviders(fn): void {
@ -121,13 +121,14 @@ function _it(jsmFn: Function, name: string, testFn: Function, testTimeOut: numbe
var timeOut = Math.max(globalTimeOut, testTimeOut);
jsmFn(name, (done) => {
var completerProvider = provide(AsyncTestCompleter, {
var completerProvider = {
provide: AsyncTestCompleter,
useFactory: () => {
// Mark the test as async when an AsyncTestCompleter is injected in an it()
if (!inIt) throw new Error('AsyncTestCompleter can only be injected in an "it()"');
return new AsyncTestCompleter();
}
});
};
testInjector.addProviders([completerProvider]);
runner.run();

View File

@ -15,5 +15,5 @@ class MyUrlResolver extends UrlResolver {
}
}
bootstrap(MyApp, [provide(UrlResolver, {useClass: MyUrlResolver})]);
bootstrap(MyApp, [{provide: UrlResolver, useClass: MyUrlResolver}]);
// #enddocregion

View File

@ -1,10 +1,9 @@
import {bootstrap} from '@angular/platform-browser';
import {NG_VALIDATORS} from '@angular/common';
import {Provider} from '@angular/core';
let MyApp: Function = null;
let myValidator: any = null;
// #docregion ng_validators
bootstrap(MyApp, [new Provider(NG_VALIDATORS, {useValue: myValidator, multi: true})]);
bootstrap(MyApp, [{provide: NG_VALIDATORS, useValue: myValidator, multi: true}]);
// #enddocregion

View File

@ -1,4 +1,4 @@
import {provide, Component, ComponentRef} from '@angular/core';
import {Component, ComponentRef} from '@angular/core';
import {bootstrap} from '@angular/platform-browser';
import {
CanActivate,
@ -53,5 +53,5 @@ export class AppCmp {
export function main(): Promise<ComponentRef<AppCmp>> {
return bootstrap(
AppCmp, [provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/can_activate'})]);
AppCmp, [{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/can_activate'}]);
}

View File

@ -63,5 +63,5 @@ export class AppCmp {
export function main(): Promise<ComponentRef<AppCmp>> {
return bootstrap(
AppCmp, [provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/can_deactivate'})]);
AppCmp, [{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/can_deactivate'}]);
}

View File

@ -53,5 +53,5 @@ export class AppCmp {
export function main(): Promise<ComponentRef<AppCmp>> {
return bootstrap(
AppCmp, [provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/on_activate'})]);
AppCmp, [{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/on_activate'}]);
}

View File

@ -1,4 +1,4 @@
import {Component, Injectable, provide, ComponentRef} from '@angular/core';
import {Component, Injectable, ComponentRef} from '@angular/core';
import {bootstrap} from '@angular/platform-browser';
import {
OnDeactivate,
@ -57,7 +57,7 @@ export class AppCmp {
export function main(): Promise<ComponentRef<AppCmp>> {
return bootstrap(AppCmp, [
provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/on_deactivate'}),
{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/on_deactivate'},
LogService
]);
}

View File

@ -1,4 +1,4 @@
import {Component, provide, ComponentRef} from '@angular/core';
import {Component, ComponentRef} from '@angular/core';
import {bootstrap} from '@angular/platform-browser';
import {
RouteConfig,
@ -53,5 +53,5 @@ export class AppCmp {
export function main(): Promise<ComponentRef<AppCmp>> {
return bootstrap(AppCmp,
[provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/reuse'})]);
[{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/reuse'}]);
}

View File

@ -8,7 +8,6 @@ import {
beforeEachProviders,
inject
} from '@angular/core/testing/testing_internal';
import {provide} from '@angular/core';
var db: any;
class MyService {}
@ -70,7 +69,7 @@ describe('some component', () => {
// #docregion beforeEachProviders
describe('some component', () => {
beforeEachProviders(() => [provide(MyService, {useClass: MyMockService})]);
beforeEachProviders(() => [{provide: MyService, useClass: MyMockService}]);
it('uses MyService', inject([MyService], (service: MyMockService) => {
// service is an instance of MyMockService.
}));

View File

@ -27,7 +27,7 @@ class _ArrayLogger {
* }
* }
*
* bootstrap(MyApp, [provide(ExceptionHandler, {useClass: MyExceptionHandler})])
* bootstrap(MyApp, {provide: ExceptionHandler, useClass: MyExceptionHandler}])
*
* ```
* @stable

View File

@ -110,7 +110,7 @@ export {URLSearchParams} from './src/url_search_params';
* search: string = 'coreTeam=true';
* }
*
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
* bootstrap(App, [HTTP_PROVIDERS, {provide: RequestOptions, useClass: MyOptions}])
* .catch(err => console.error(err));
* ```
*
@ -130,7 +130,7 @@ export {URLSearchParams} from './src/url_search_params';
* var injector = Injector.resolveAndCreate([
* HTTP_PROVIDERS,
* MockBackend,
* provide(XHRBackend, {useExisting: MockBackend})
* {provide: XHRBackend, useExisting: MockBackend}
* ]);
* var http = injector.get(Http);
* var backend = injector.get(MockBackend);
@ -174,27 +174,26 @@ export {URLSearchParams} from './src/url_search_params';
*
* bootstrap(
* App,
* [HTTP_PROVIDERS, provide(XSRFStrategy,
* {useValue: new CookieXSRFStrategy('MY-XSRF-COOKIE-NAME', 'X-MY-XSRF-HEADER-NAME')})])
* [HTTP_PROVIDERS, {provide: XSRFStrategy,
* useValue: new CookieXSRFStrategy('MY-XSRF-COOKIE-NAME', 'X-MY-XSRF-HEADER-NAME')}])
* .catch(err => console.error(err));
* ```
*/
export const HTTP_PROVIDERS: any[] = [
// TODO(pascal): use factory type annotations once supported in DI
// issue: https://github.com/angular/angular/issues/3183
provide(Http,
{
useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) =>
new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]
}),
{ provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
BrowserXhr,
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
{provide: RequestOptions, useClass: BaseRequestOptions},
{provide: ResponseOptions, useClass: BaseResponseOptions},
XHRBackend,
provide(XSRFStrategy, {useValue: new CookieXSRFStrategy()}),
{provide: XSRFStrategy, useValue: new CookieXSRFStrategy()},
];
function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
return new Http(xhrBackend, requestOptions);
}
/**
* See {@link HTTP_PROVIDERS} instead.
*
@ -267,7 +266,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
* search: string = 'coreTeam=true';
* }
*
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
* bootstrap(App, [JSONP_PROVIDERS, {provide: RequestOptions, useClass: MyOptions}])
* .catch(err => console.error(err));
* ```
*
@ -285,7 +284,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
* var injector = Injector.resolveAndCreate([
* JSONP_PROVIDERS,
* MockBackend,
* provide(JSONPBackend, {useExisting: MockBackend})
* {provide: JSONPBackend, useExisting: MockBackend}
* ]);
* var jsonp = injector.get(Jsonp);
* var backend = injector.get(MockBackend);
@ -312,18 +311,18 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
export const JSONP_PROVIDERS: any[] = [
// TODO(pascal): use factory type annotations once supported in DI
// issue: https://github.com/angular/angular/issues/3183
provide(Jsonp,
{
useFactory: (jsonpBackend: JSONPBackend, requestOptions: RequestOptions) =>
new Jsonp(jsonpBackend, requestOptions),
deps: [JSONPBackend, RequestOptions]
}),
{provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions]},
BrowserJsonp,
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(JSONPBackend, {useClass: JSONPBackend_})
{provide: RequestOptions, useClass: BaseRequestOptions},
{provide: ResponseOptions, useClass: BaseResponseOptions},
{provide: JSONPBackend, useClass: JSONPBackend_},
];
function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions) {
return new Jsonp(jsonpBackend, requestOptions);
}
/**
* See {@link JSONP_PROVIDERS} instead.
*

View File

@ -171,9 +171,9 @@ export class CookieXSRFStrategy implements XSRFStrategy {
* @Component({
* viewProviders: [
* HTTP_PROVIDERS,
* provide(Http, {useFactory: (backend, options) => {
* {provide: Http, useFactory: (backend, options) => {
* return new Http(backend, options);
* }, deps: [MyNodeBackend, BaseRequestOptions]})]
* }, deps: [MyNodeBackend, BaseRequestOptions]}]
* })
* class MyComponent {
* constructor(http:Http) {

View File

@ -133,7 +133,7 @@ export class RequestOptions {
* search: string = 'coreTeam=true';
* }
*
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})]);
* bootstrap(App, [HTTP_PROVIDERS, {provide: RequestOptions, useClass: MyOptions}]);
* ```
*
* The options could also be extended when manually creating a {@link Request}

View File

@ -125,7 +125,7 @@ export class ResponseOptions {
* headers:Headers = new Headers({network: 'github'});
* }
*
* bootstrap(App, [HTTP_PROVIDERS, provide(ResponseOptions, {useClass: MyOptions})]);
* bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
* ```
*
* The options could also be extended when manually creating a {@link Response}

View File

@ -82,11 +82,11 @@ function mergeOptions(defaultOpts: BaseRequestOptions, providedOpts: RequestOpti
* var injector = Injector.resolveAndCreate([
* BaseRequestOptions,
* MockBackend,
* provide(Http, {useFactory:
* {provide: Http, useFactory:
* function(backend, defaultOptions) {
* return new Http(backend, defaultOptions);
* },
* deps: [MockBackend, BaseRequestOptions]})
* deps: [MockBackend, BaseRequestOptions]}
* ]);
* var http = injector.get(Http);
* http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));

View File

@ -71,9 +71,9 @@ export function main() {
beforeEach(() => {
let injector = ReflectiveInjector.resolveAndCreate([
provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(BrowserJsonp, {useClass: MockBrowserJsonp}),
provide(JSONPBackend, {useClass: JSONPBackend_})
{provide: ResponseOptions, useClass: BaseResponseOptions},
{provide: BrowserJsonp, useClass: MockBrowserJsonp},
{provide: JSONPBackend, useClass: JSONPBackend_}
]);
backend = injector.get(JSONPBackend);
let base = new BaseRequestOptions();

View File

@ -34,7 +34,7 @@ export function main() {
beforeEach(() => {
var injector = ReflectiveInjector.resolveAndCreate(
[provide(ResponseOptions, {useClass: BaseResponseOptions}), MockBackend]);
[{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
backend = injector.get(MockBackend);
var base = new BaseRequestOptions();
sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));

View File

@ -94,9 +94,11 @@ export function main() {
beforeEachProviders(
() =>
[provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(BrowserXhr, {useClass: MockBrowserXHR}), XHRBackend,
provide(XSRFStrategy, {useValue: new CookieXSRFStrategy()}),
[
{provide: ResponseOptions, useClass: BaseResponseOptions},
{provide: BrowserXhr, useClass: MockBrowserXHR},
XHRBackend,
{provide: XSRFStrategy, useValue: new CookieXSRFStrategy()},
]);
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
@ -112,7 +114,7 @@ export function main() {
class NoopXsrfStrategy implements XSRFStrategy {
configureRequest(req: Request) {}
}
beforeEachProviders(() => [provide(XSRFStrategy, {useClass: NoopXsrfStrategy})]);
beforeEachProviders(() => [{provide: XSRFStrategy, useClass: NoopXsrfStrategy}]);
it('succeeds',
() => { expect(() => backend.createConnection(sampleRequest)).not.toThrow(); });
@ -135,8 +137,7 @@ export function main() {
describe('configuration', () => {
beforeEachProviders(
() => [provide(
XSRFStrategy, {useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')})]);
() => [{provide: XSRFStrategy, useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')}]);
it('uses the configured names', () => {
getDOM().setCookie('my cookie', 'XSRF value');

View File

@ -44,15 +44,15 @@ export function main() {
it('should allow using jsonpInjectables and httpInjectables in same injector',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
parentInjector = ReflectiveInjector.resolveAndCreate([
provide(XHRBackend, {useClass: MockBackend}),
provide(JSONPBackend, {useClass: MockBackend})
{provide: XHRBackend, useClass: MockBackend},
{provide: JSONPBackend, useClass: MockBackend}
]);
childInjector = parentInjector.resolveAndCreateChild([
HTTP_PROVIDERS,
JSONP_PROVIDERS,
provide(XHRBackend, {useClass: MockBackend}),
provide(JSONPBackend, {useClass: MockBackend})
{provide: XHRBackend, useClass: MockBackend},
{provide: JSONPBackend, useClass: MockBackend}
]);
http = childInjector.get(Http);
@ -97,22 +97,20 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
BaseRequestOptions,
MockBackend,
provide(
Http,
{
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
}),
provide(
Jsonp,
{
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Jsonp(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
})
{
provide: Http,
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
{
provide: Jsonp,
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Jsonp(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
}
]);
http = injector.get(Http);
jsonp = injector.get(Jsonp);

View File

@ -114,9 +114,9 @@ export class MockConnection implements Connection {
* var connection;
* var injector = Injector.resolveAndCreate([
* MockBackend,
* provide(Http, {useFactory: (backend, options) => {
* {provide: Http, useFactory: (backend, options) => {
* return new Http(backend, options);
* }, deps: [MockBackend, BaseRequestOptions]})]);
* }, deps: [MockBackend, BaseRequestOptions]}]);
* var http = injector.get(Http);
* var backend = injector.get(MockBackend);
* //Assign any newly-created connection to local variable
@ -150,9 +150,9 @@ export class MockBackend implements ConnectionBackend {
* var text; //this will be set from mock response
* var injector = Injector.resolveAndCreate([
* MockBackend,
* provide(Http, {useFactory: (backend, options) => {
* {provide: Http, useFactory: (backend, options) => {
* return new Http(backend, options);
* }, deps: [MockBackend, BaseRequestOptions]})]);
* }, deps: [MockBackend, BaseRequestOptions]}]);
* var backend = injector.get(MockBackend);
* var http = injector.get(Http);
* backend.connections.subscribe(c => connection = c);

View File

@ -1,7 +1,6 @@
import {
DebugNode,
getDebugNode,
Provider,
RootRenderer,
NgZone,
ApplicationRef

View File

@ -8,15 +8,11 @@ import {WebWorkerPlatformLocation} from './platform_location';
*/
export const WORKER_APP_LOCATION_PROVIDERS = [
{provide: PlatformLocation, useClass: WebWorkerPlatformLocation},
{
provide: APP_INITIALIZER,
useFactory: (platformLocation: WebWorkerPlatformLocation, zone: NgZone) => () =>
initWorkerLocation(platformLocation, zone),
multi: true,
deps: [PlatformLocation, NgZone]
}
{provide: APP_INITIALIZER, useFactory: appInitFnFactory, multi: true, deps: [PlatformLocation, NgZone]}
];
function initWorkerLocation(platformLocation: WebWorkerPlatformLocation, zone: NgZone): Promise<boolean> {
return zone.runGuarded(() => platformLocation.init());
function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () => Promise<boolean> {
return () => {
return zone.runGuarded(() => platformLocation.init());
};
}

View File

@ -102,17 +102,8 @@ export const WORKER_RENDER_APPLICATION_PROVIDERS: Array<any /*Type | Provider |
Testability,
EventManager,
WebWorkerInstance,
{
provide: APP_INITIALIZER,
useFactory: (injector => () => initWebWorkerApplication(injector)),
multi: true,
deps: [Injector]
},
{
provide: MessageBus,
useFactory: (instance) => instance.bus,
deps: [WebWorkerInstance]
}
{ provide: APP_INITIALIZER, useFactory: initWebWorkerAppFn, multi: true, deps: [Injector] },
{ provide: MessageBus, useFactory: messageBusFactory, deps: [WebWorkerInstance] }
];
export function initializeGenericWorkerRenderer(injector: Injector) {
@ -142,6 +133,10 @@ export function bootstrapRender(
return PromiseWrapper.resolve(app.get(ApplicationRef));
}
function messageBusFactory(instance: WebWorkerInstance): MessageBus {
return instance.bus;
}
function initWebWorkerRenderPlatform(): void {
BrowserDomAdapter.makeCurrent();
wtfInit();
@ -163,19 +158,21 @@ function _document(): any {
return getDOM().defaultDoc();
}
function initWebWorkerApplication(injector: Injector): void {
var scriptUri: string;
try {
scriptUri = injector.get(WORKER_SCRIPT);
} catch (e) {
throw new BaseException(
"You must provide your WebWorker's initialization script with the WORKER_SCRIPT token");
}
function initWebWorkerAppFn(injector: Injector): () => void {
return () => {
var scriptUri: string;
try {
scriptUri = injector.get(WORKER_SCRIPT);
} catch (e) {
throw new BaseException(
"You must provide your WebWorker's initialization script with the WORKER_SCRIPT token");
}
let instance = injector.get(WebWorkerInstance);
spawnWebWorker(scriptUri, instance);
let instance = injector.get(WebWorkerInstance);
spawnWebWorker(scriptUri, instance);
initializeGenericWorkerRenderer(injector);
initializeGenericWorkerRenderer(injector);
};
}
/**

View File

@ -113,7 +113,7 @@ export function main() {
getDOM().appendChild(el, lightDom);
getDOM().setText(lightDom, 'loading');
testProviders =
[provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})];
[{provide: DOCUMENT, useValue: fakeDoc}, {provide: Console, useClass: DummyConsole}];
});
afterEach(disposePlatform);
@ -123,7 +123,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
expect(
() => bootstrap(HelloRootDirectiveIsNotCmp,
[testProviders, provide(ExceptionHandler, {useValue: exceptionHandler})]))
[testProviders, {provide: ExceptionHandler, useValue: exceptionHandler}]))
.toThrowError(
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
expect(logger.res.join("")).toContain("Could not compile");
@ -134,7 +134,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
async.done();
@ -150,7 +150,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason: any) => {
expect(reason.message)
.toContain('The selector "hello-app" did not match any elements');
@ -164,7 +164,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(logger.res.join(""))
.toContain('The selector "hello-app" did not match any elements');
@ -225,7 +225,7 @@ export function main() {
it("should make the provided bindings available to the application component",
inject([AsyncTestCompleter], (async) => {
var refPromise = bootstrap(
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
HelloRootCmp3, [testProviders, {provide: "appBinding", useValue: "BoundValue"}]);
refPromise.then((ref) => {
expect(ref.instance.appBinding).toEqual("BoundValue");
@ -246,16 +246,16 @@ export function main() {
it("should run platform initializers", inject([Log], (log: Log) => {
let p = createPlatform(ReflectiveInjector.resolveAndCreate([
BROWSER_PLATFORM_PROVIDERS,
provide(PLATFORM_INITIALIZER, {useValue: log.fn("platform_init1"), multi: true}),
provide(PLATFORM_INITIALIZER, {useValue: log.fn("platform_init2"), multi: true})
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init1"), multi: true},
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init2"), multi: true}
]));
expect(log.result()).toEqual("platform_init1; platform_init2");
log.clear();
var a = ReflectiveInjector.resolveAndCreate(
[
BROWSER_APP_PROVIDERS,
provide(APP_INITIALIZER, {useValue: log.fn("app_init1"), multi: true}),
provide(APP_INITIALIZER, {useValue: log.fn("app_init2"), multi: true})
{provide: APP_INITIALIZER, useValue: log.fn("app_init1"), multi: true},
{provide: APP_INITIALIZER, useValue: log.fn("app_init2"), multi: true}
],
p.injector);
a.get(ApplicationRef);

View File

@ -16,7 +16,7 @@ class SpyComponentRef extends SpyObject implements ComponentRef<dynamic> {
SpyComponentRef() {
this.injector = ReflectiveInjector
.resolveAndCreate([bind(ApplicationRef).toClass(SpyApplicationRef)]);
.resolveAndCreate([{provide: ApplicationRef, useClass: SpyApplicationRef}]);
}
}

View File

@ -12,7 +12,7 @@ export class SpyComponentRef extends SpyObject {
constructor() {
super();
this.injector = ReflectiveInjector.resolveAndCreate(
[provide(ApplicationRef, {useClass: SpyApplicationRef})]);
[{provide: ApplicationRef, useClass: SpyApplicationRef}]);
}
}

View File

@ -120,7 +120,7 @@ export function main() {
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
it('provides a real XHR instance',
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));

View File

@ -134,7 +134,7 @@ export function main() {
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
it('should use set up providers',
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -185,12 +185,12 @@ export function main() {
describe('per test providers', () => {
it('should allow per test providers',
withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
.inject([FancyService],
(service) => { expect(service.value).toEqual('real value'); }));
it('should return value from inject', () => {
let retval = withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
let retval = withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
.inject([FancyService], (service) => {
expect(service.value).toEqual('real value');
return 10;
@ -265,7 +265,7 @@ export function main() {
});
describe('using beforeEachProviders', () => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
beforeEach(
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -275,7 +275,7 @@ export function main() {
it('should fail when the injector has already been used', () => {
patchJasmineBeforeEach();
expect(() => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
})
.toThrowError('beforeEachProviders was called after the injector had been used ' +
'in a beforeEach or it block. This invalidates the test injector');
@ -364,7 +364,7 @@ export function main() {
it('should override a provider',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideProviders(TestProvidersComp, [provide(FancyService, {useClass: MockFancyService})])
tcb.overrideProviders(TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -378,7 +378,7 @@ export function main() {
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideViewProviders(TestViewProvidersComp,
[provide(FancyService, {useClass: MockFancyService})])
[{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestViewProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();

View File

@ -112,7 +112,7 @@ export function main() {
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
it("should buffer messages and wait for the zone to exit before sending",
withProviders(() => [provide(NgZone, {useClass: MockNgZone})])
withProviders(() => [{provide: NgZone, useClass: MockNgZone}])
.inject([AsyncTestCompleter, NgZone],
(async, zone: MockNgZone) => {
bus = createConnectedMessageBus();

View File

@ -27,7 +27,7 @@ export function main() {
const RESULT = 20;
const ID = "methodId";
beforeEachProviders(() => [Serializer, provide(ON_WEB_WORKER, {useValue: true}), RenderStore]);
beforeEachProviders(() => [Serializer, {provide: ON_WEB_WORKER, useValue: true}, RenderStore]);
describe("UIMessageBroker", () => {
var messageBuses;

View File

@ -86,9 +86,9 @@ export function main() {
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
testUiInjector.addProviders([
Serializer,
provide(RenderStore, {useValue: uiRenderStore}),
provide(DomRootRenderer, {useClass: DomRootRenderer_}),
provide(RootRenderer, {useExisting: DomRootRenderer})
{provide: RenderStore, useValue: uiRenderStore},
{provide: DomRootRenderer, useClass: DomRootRenderer_},
{provide: RootRenderer, useExisting: DomRootRenderer}
]);
uiInjector = testUiInjector.createInjector();
var uiSerializer = uiInjector.get(Serializer);
@ -96,16 +96,16 @@ export function main() {
workerRenderStore = new RenderStore();
return [
Serializer,
provide(CompilerConfig, {useValue: new CompilerConfig(true, true, false)}),
provide(RenderStore, {useValue: workerRenderStore}),
provide(RootRenderer,
{
useFactory: (workerSerializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
uiRenderStore, workerRenderStore);
},
deps: [Serializer]
})
{provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
{provide: RenderStore, useValue: workerRenderStore},
{
provide: RootRenderer,
useFactory: (workerSerializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
uiRenderStore, workerRenderStore);
},
deps: [Serializer]
}
];
});

View File

@ -32,8 +32,8 @@ export function main() {
return new CachedXHR();
}
beforeEachProviders(() => [
provide(UrlResolver, {useClass: TestUrlResolver}),
provide(XHR, {useFactory: createCachedXHR})
{provide: UrlResolver, useClass: TestUrlResolver},
{provide: XHR, useFactory: createCachedXHR}
]);
it('should throw exception if $templateCache is not found', () => {

View File

@ -31,7 +31,7 @@ export function runBenchmark(config) {
execute: config.work,
prepare: config.prepare,
microMetrics: config.microMetrics,
providers: [bind(Options.SAMPLE_DESCRIPTION).toValue(description)]
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: description }]
});
});
});

View File

@ -58,9 +58,9 @@ export class RouterOutlet implements OnDestroy {
var childRouter = this._parentRouter.childRouter(componentType);
var providers = ReflectiveInjector.resolve([
provide(RouteData, {useValue: nextInstruction.routeData}),
provide(RouteParams, {useValue: new RouteParams(nextInstruction.params)}),
provide(routerMod.Router, {useValue: childRouter})
{provide: RouteData, useValue: nextInstruction.routeData},
{provide: RouteParams, useValue: new RouteParams(nextInstruction.params)},
{provide: routerMod.Router, useValue: childRouter}
]);
this._componentRef =
this._loader.loadNextToLocation(componentType, this._viewContainerRef, providers);

View File

@ -1,10 +1,9 @@
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
import {Provider} from '@angular/core';
import {BrowserPlatformLocation} from '@angular/platform-browser';
import {PlatformLocation} from '@angular/common';
/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
* A list of providers. To use the router, you must add this to your application.
*
* ### Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
*

View File

@ -1,4 +1,4 @@
import {ApplicationRef, Provider} from '@angular/core';
import {ApplicationRef} from '@angular/core';
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
import {Router, RootRouter} from './router';
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './route_registry';

View File

@ -37,8 +37,8 @@ export function main() {
var tcb: TestComponentBuilder;
beforeEachProviders(() => [
provide(Location, {useValue: makeDummyLocation()}),
provide(Router, {useValue: makeDummyRouter()})
{provide: Location, useValue: makeDummyLocation()},
{provide: Router, useValue: makeDummyRouter()}
]);
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));

View File

@ -50,8 +50,8 @@ export function main() {
describe('router bootstrap', () => {
beforeEachProviders(() => [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(ApplicationRef, {useClass: MockApplicationRef})
{provide: LocationStrategy, useClass: MockLocationStrategy},
{provide: ApplicationRef, useClass: MockApplicationRef}
]);
// do not refactor out the `bootstrap` functionality. We still want to
@ -64,10 +64,10 @@ export function main() {
bootstrap(AppCmp,
[
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}),
provide(Console, {useClass: DummyConsole})
{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp},
{provide: LocationStrategy, useClass: MockLocationStrategy},
{provide: DOCUMENT, useValue: fakeDoc},
{provide: Console, useClass: DummyConsole}
])
.then((applicationRef) => {
var router = applicationRef.instance.router;
@ -80,7 +80,7 @@ export function main() {
}));
describe('broken app', () => {
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: BrokenAppCmp})]);
beforeEachProviders(() => [{provide: ROUTER_PRIMARY_COMPONENT, useValue: BrokenAppCmp}]);
it('should rethrow exceptions from component constructors',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -95,7 +95,7 @@ export function main() {
});
describe('back button app', () => {
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]);
beforeEachProviders(() => [{provide: ROUTER_PRIMARY_COMPONENT, useValue: HierarchyAppCmp}]);
it('should change the url without pushing a new history state for back navigations',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -146,7 +146,7 @@ export function main() {
describe('hierarchical app', () => {
beforeEachProviders(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
() => { return [{provide: ROUTER_PRIMARY_COMPONENT, useValue: HierarchyAppCmp}]; });
it('should bootstrap an app with a hierarchy',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -167,7 +167,7 @@ export function main() {
// TODO(btford): mock out level lower than LocationStrategy once that level exists
xdescribe('custom app base ref', () => {
beforeEachProviders(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
beforeEachProviders(() => { return [{provide: APP_BASE_HREF, useValue: '/my/app'}]; });
it('should bootstrap',
inject([AsyncTestCompleter, TestComponentBuilder],
(async, tcb: TestComponentBuilder) => {
@ -191,7 +191,7 @@ export function main() {
describe('querystring params app', () => {
beforeEachProviders(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: QueryStringAppCmp})]; });
() => { return [{provide: ROUTER_PRIMARY_COMPONENT, useValue: QueryStringAppCmp}]; });
it('should recognize and return querystring params with the injected RouteParams',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -217,7 +217,7 @@ export function main() {
describe('activate event on outlet', () => {
let tcb: TestComponentBuilder = null;
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp})]);
beforeEachProviders(() => [{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp}]);
beforeEach(inject([TestComponentBuilder],
(testComponentBuilder) => { tcb = testComponentBuilder; }));

View File

@ -48,9 +48,9 @@ export function main() {
beforeEachProviders(() => [
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: MyComp7}),
provide(Router, {useClass: RootRouter}),
{provide: Location, useClass: SpyLocation},
{provide: ROUTER_PRIMARY_COMPONENT, useValue: MyComp7},
{provide: Router, useClass: RootRouter},
]);
beforeEach(inject([TestComponentBuilder, Router, Location],

View File

@ -42,9 +42,9 @@ export function compile(
export var TEST_ROUTER_PROVIDERS: any[] = [
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: RootCmp}),
provide(Router, {useClass: RootRouter})
{provide: Location, useClass: SpyLocation},
{provide: ROUTER_PRIMARY_COMPONENT, useValue: RootCmp},
{provide: Router, useClass: RootRouter}
];
export function clickOnElement(anchorEl) {

View File

@ -20,7 +20,7 @@ export function main() {
var locationStrategy: HashLocationStrategy;
beforeEachProviders(
() => [HashLocationStrategy, provide(PlatformLocation, {useClass: SpyPlatformLocation})]);
() => [HashLocationStrategy, {provide: PlatformLocation, useClass: SpyPlatformLocation}]);
describe('without APP_BASE_HREF', () => {
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
@ -61,7 +61,7 @@ export function main() {
});
describe('with APP_BASE_HREF with neither leading nor trailing slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: 'app'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: 'app'}]);
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
platformLocation = pl;
@ -94,7 +94,7 @@ export function main() {
});
describe('with APP_BASE_HREF with leading slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: '/app'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: '/app'}]);
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
platformLocation = pl;
@ -127,7 +127,7 @@ export function main() {
});
describe('with APP_BASE_HREF with both leading and trailing slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: '/app/'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: '/app/'}]);
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
platformLocation = pl;

View File

@ -24,7 +24,7 @@ export function main() {
locationStrategy = new MockLocationStrategy();
locationStrategy.internalBaseHref = baseHref;
let injector = ReflectiveInjector.resolveAndCreate(
[Location, provide(LocationStrategy, {useValue: locationStrategy}), provider]);
[Location, {provide: LocationStrategy, useValue: locationStrategy}, provider]);
return location = injector.get(Location);
}

View File

@ -24,7 +24,7 @@ export function main() {
beforeEachProviders(() => [
PathLocationStrategy,
provide(PlatformLocation, {useFactory: makeSpyPlatformLocation})
{provide: PlatformLocation, useFactory: makeSpyPlatformLocation}
]);
it('should throw without a base element or APP_BASE_HREF', () => {
@ -67,7 +67,7 @@ export function main() {
});
describe('with APP_BASE_HREF with neither leading nor trailing slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: 'app'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: 'app'}]);
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
platformLocation = pl;
@ -100,7 +100,7 @@ export function main() {
});
describe('with APP_BASE_HREF with leading slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: '/app'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: '/app'}]);
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
platformLocation = pl;
@ -133,7 +133,7 @@ export function main() {
});
describe('with APP_BASE_HREF with both leading and trailing slash', () => {
beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: '/app/'})]);
beforeEachProviders(() => [{provide: APP_BASE_HREF, useValue: '/app/'}]);
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
platformLocation = pl;

View File

@ -46,10 +46,10 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
testBindings = [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}),
provide(ExceptionHandler, {useValue: exceptionHandler}),
provide(Console, {useClass: DummyConsole})
{provide: LocationStrategy, useClass: MockLocationStrategy},
{provide: DOCUMENT, useValue: fakeDoc},
{provide: ExceptionHandler, useValue: exceptionHandler},
{provide: Console, useClass: DummyConsole}
];
});

View File

@ -29,9 +29,9 @@ export function main() {
beforeEachProviders(() => [
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(Router, {useClass: RootRouter})
{provide: Location, useClass: SpyLocation},
{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp},
{provide: Router, useClass: RootRouter}
]);

View File

@ -259,7 +259,7 @@ class _ActivateSegments {
private activateNewSegments(outletMap: RouterOutletMap, curr: RouteSegment, prev: RouteSegment,
outlet: RouterOutlet): Object {
let resolved = ReflectiveInjector.resolve(
[provide(RouterOutletMap, {useValue: outletMap}), provide(RouteSegment, {useValue: curr})]);
[{provide: RouterOutletMap, useValue: outletMap}, {provide: RouteSegment, useValue: curr}]);
let ref = outlet.activate(routeSegmentComponentFactory(curr), resolved, outletMap);
if (hasLifecycleHook("routerOnActivate", ref.instance)) {
ref.instance.routerOnActivate(curr, prev, this.currTree, this.prevTree);

View File

@ -1,7 +1,7 @@
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
* A list of providers. To use the router, you must add this to your application.
*
* ```
* import {Component} from '@angular/core';

View File

@ -17,7 +17,7 @@ export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
deps: /*@ts2dart_const*/
[ApplicationRef, ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location],
},
/*@ts2dart_Provider*/ {provide: RouteSegment, useFactory: (r) => r.routeTree.root, deps: [Router]}
/*@ts2dart_Provider*/ {provide: RouteSegment, useFactory: routeSegmentFactory, deps: [Router]}
];
function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver,
@ -32,3 +32,7 @@ function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver
app.registerDisposeListener(() => router.dispose());
return router;
}
function routeSegmentFactory(router: Router): RouteSegment {
return router.routeTree.root;
}

View File

@ -36,16 +36,16 @@ import {getDOM} from '../platform_browser_private';
export function main() {
describe('navigation', () => {
beforeEachProviders(() => [
provide(RouterUrlSerializer, {useClass: DefaultRouterUrlSerializer}),
{provide: RouterUrlSerializer, useClass: DefaultRouterUrlSerializer},
RouterOutletMap,
provide(Location, {useClass: SpyLocation}),
provide(RouteSegment, {useFactory: (r) => r.routeTree.root, deps: [Router]}),
provide(Router,
{
useFactory: (resolver, urlParser, outletMap, location) => new Router(
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
})
{provide: Location, useClass: SpyLocation},
{provide: RouteSegment, useFactory: (r) => r.routeTree.root, deps: [Router]},
{
provide: Router,
useFactory: (resolver, urlParser, outletMap, location) => new Router(
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
}
]);
it('should update location when navigating',

View File

@ -32,16 +32,16 @@ import {SpyLocation, MockLocationStrategy} from '@angular/common/testing';
export function main() {
describe('RouterLink', () => {
beforeEachProviders(() => [
provide(RouterUrlSerializer, {useClass: DefaultRouterUrlSerializer}),
{provide: RouterUrlSerializer, useClass: DefaultRouterUrlSerializer},
RouterOutletMap,
provide(Location, {useClass: SpyLocation}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(Router,
{
useFactory: (resolver, urlParser, outletMap, location) => new Router(
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
})
{provide: Location, useClass: SpyLocation},
{provide: LocationStrategy, useClass: MockLocationStrategy},
{
provide: Router,
useFactory: (resolver, urlParser, outletMap, location) => new Router(
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
}
]);
describe("routerLink=", () => {

View File

@ -39,7 +39,7 @@ export class DowngradeNg2ComponentAdapter {
bootstrapNg2() {
var childInjector = ReflectiveInjector.resolveAndCreate(
[provide(NG1_SCOPE, {useValue: this.componentScope})], this.parentInjector);
[{provide: NG1_SCOPE, useValue: this.componentScope}], this.parentInjector);
this.contentInsertionPoint = document.createComment('ng1 insertion point');
this.componentRef =

View File

@ -109,7 +109,7 @@ export class UpgradeAdapter {
/* @internal */
private downgradedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
/* @internal */
private providers: Array<Type | Provider | any[]> = [];
private providers: Array<Type | Provider | any[] | any> = [];
/**
* Allows Angular v2 Component to be used from AngularJS v1.
@ -295,9 +295,8 @@ export class UpgradeAdapter {
[
BROWSER_APP_PROVIDERS,
BROWSER_APP_COMPILER_PROVIDERS,
provide(NG1_INJECTOR, {useFactory: () => ng1Injector}),
provide(NG1_COMPILE,
{useFactory: () => ng1Injector.get(NG1_COMPILE)}),
{provide: NG1_INJECTOR, useFactory: () => ng1Injector},
{provide: NG1_COMPILE, useFactory: () => ng1Injector.get(NG1_COMPILE)},
this.providers
],
platformRef.injector)
@ -449,7 +448,7 @@ export class UpgradeAdapter {
* adapter.bootstrap(document.body, ['myExample']);
*```
*/
public addProvider(provider: Type | Provider | any[]): void { this.providers.push(provider); }
public addProvider(provider: Type | Provider | any[] | any): void { this.providers.push(provider); }
/**
* Allows AngularJS v1 service to be accessible from Angular v2.
@ -485,10 +484,11 @@ export class UpgradeAdapter {
*/
public upgradeNg1Provider(name: string, options?: {asToken: any}) {
var token = options && options.asToken || name;
this.providers.push(provide(token, {
this.providers.push({
provide: token,
useFactory: (ng1Injector: angular.IInjectorService) => ng1Injector.get(name),
deps: [NG1_INJECTOR]
}));
});
}
/**

View File

@ -756,7 +756,7 @@ export function main() {
it('should export ng2 instance to ng1', inject([AsyncTestCompleter], (async) => {
var adapter = new UpgradeAdapter();
var module = angular.module('myExample', []);
adapter.addProvider(provide(SomeToken, {useValue: 'correct_value'}));
adapter.addProvider({provide: SomeToken, useValue: 'correct_value'});
module.factory('someToken', adapter.downgradeNg2Provider(SomeToken));
adapter.bootstrap(html('<div>'), ['myExample'])
.ready((ref) => {

View File

@ -10,9 +10,6 @@ import {
Component,
Directive,
ViewContainerRef,
bind,
provide,
Provider,
ViewMetadata
} from '@angular/core';
@ -20,19 +17,19 @@ import {CompilerConfig, ViewResolver} from '@angular/compiler';
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util';
function _createBindings(): Provider[] {
function _createBindings(): any[] {
var multiplyTemplatesBy = getIntParameter('elements');
return [
provide(ViewResolver,
{
useFactory: () => new MultiplyViewResolver(
{
provide: ViewResolver,
useFactory: () => new MultiplyViewResolver(
multiplyTemplatesBy,
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
deps: []
}),
deps: []
},
// Use interpretative mode as Dart does not support JIT and
// we want to be able to compare the numbers between JS and Dart
provide(CompilerConfig, {useValue: new CompilerConfig(false, false, false)})
{provide: CompilerConfig, useValue: new CompilerConfig(false, false, false)}
];
}

View File

@ -1,4 +1,4 @@
import {Injectable, ReflectiveInjector, ReflectiveKey, bind, provide} from '@angular/core';
import {Injectable, ReflectiveInjector, ReflectiveKey} from '@angular/core';
import {reflector} from '@angular/core/src/reflection/reflection';
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
import {getIntParameter, bindAction, microBenchmark} from '@angular/testing/src/benchmark_util';
@ -27,7 +27,7 @@ export function main() {
.resolveAndCreateChild([])
.resolveAndCreateChild([]);
var variousProviders = [A, provide(B, {useClass: C}), [D, [E]], provide(F, {useValue: 6})];
var variousProviders = [A, {provide: B, useClass: C}, [D, [E]], {provide: F, useValue: 6}];
var variousProvidersResolved = ReflectiveInjector.resolve(variousProviders);

View File

@ -8,7 +8,7 @@ import {
windowProfileEnd
} from '@angular/testing/src/benchmark_util';
import {bootstrap} from '@angular/platform-browser';
import {Component, Directive, bind, provide} from '@angular/core';
import {Component} from '@angular/core';
import {NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from '@angular/common';
import {ApplicationRef} from '@angular/core/src/application_ref';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
@ -24,9 +24,9 @@ export const LARGETABLE_COLS = 'LargetableComponent.cols';
function _createBindings() {
return [
provide(BENCHMARK_TYPE, {useValue: getStringParameter('benchmarkType')}),
provide(LARGETABLE_ROWS, {useValue: getIntParameter('rows')}),
provide(LARGETABLE_COLS, {useValue: getIntParameter('columns')})
{provide: BENCHMARK_TYPE, useValue: getStringParameter('benchmarkType')},
{provide: LARGETABLE_ROWS, useValue: getIntParameter('rows')},
{provide: LARGETABLE_COLS, {useValue: getIntParameter('columns')},
];
}

View File

@ -1,6 +1,6 @@
import {bootstrap} from '@angular/platform-browser';
import {NgIf} from '@angular/common';
import {Component, Directive, ViewContainerRef, bind, provide, Provider} from '@angular/core';
import {Component} from '@angular/core';
import {ApplicationRef} from '@angular/core/src/application_ref';
import {reflector} from '@angular/core/src/reflection/reflection';
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
@ -15,7 +15,7 @@ import {
} from '@angular/testing/src/benchmark_util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
function createBindings(): Provider[] {
function createBindings(): any[] {
return [];
}

View File

@ -1,11 +1,6 @@
import {bootstrap} from '@angular/platform-browser';
import {
Component,
Directive,
ViewContainerRef,
bind,
provide,
Provider,
enableProdMode
} from '@angular/core';
import {NgIf} from '@angular/common';
@ -23,7 +18,7 @@ import {
} from '@angular/testing/src/benchmark_util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
function createProviders(): Provider[] {
function createProviders(): any[] {
return [];
}

View File

@ -1,4 +1,4 @@
import {bind, provide} from '@angular/core/src/di';
import {bind} from '@angular/core/src/di';
import {Options} from './common';
export * from './common';
@ -11,7 +11,7 @@ var fs = require('fs');
// find another way...
// Note: Can't do the `require` call in a facade as it can't be loaded into the browser
// for our unit tests via karma.
Options.DEFAULT_PROVIDERS.push(bind(Options.WRITE_FILE).toValue(writeFile));
Options.DEFAULT_PROVIDERS.push({provide: Options.WRITE_FILE, useValue: writeFile});
function writeFile(filename, content): Promise<any> {
return new Promise(function(resolve, reject) {

View File

@ -1,8 +1,8 @@
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {OpaqueToken} from '@angular/core/src/di';
import {DateWrapper} from '@angular/facade';
export class Options {
static get DEFAULT_PROVIDERS(): Provider[] { return _DEFAULT_PROVIDERS; }
static get DEFAULT_PROVIDERS(): any[] { return _DEFAULT_PROVIDERS; }
// TODO(tbosch): use static initializer when our transpiler supports it
static get SAMPLE_ID() { return _SAMPLE_ID; }
// TODO(tbosch): use static initializer when our transpiler supports it
@ -49,14 +49,13 @@ var _REQUEST_COUNT = new OpaqueToken('Options.requestCount');
var _CAPTURE_FRAMES = new OpaqueToken('Options.frameCapture');
var _DEFAULT_PROVIDERS = [
bind(_DEFAULT_DESCRIPTION)
.toValue({}),
provide(_SAMPLE_DESCRIPTION, {useValue: {}}),
provide(_FORCE_GC, {useValue: false}),
provide(_PREPARE, {useValue: false}),
provide(_MICRO_METRICS, {useValue: {}}),
provide(_NOW, {useValue: () => DateWrapper.now()}),
provide(_RECEIVED_DATA, {useValue: false}),
provide(_REQUEST_COUNT, {useValue: false}),
provide(_CAPTURE_FRAMES, {useValue: false})
{provide: _DEFAULT_DESCRIPTION, useValue: {}},
{provide: _SAMPLE_DESCRIPTION, useValue: {}},
{provide: _FORCE_GC, useValue: false},
{provide: _PREPARE, useValue: false},
{provide: _MICRO_METRICS, useValue: {}},
{provide: _NOW, useValue: () => DateWrapper.now()},
{provide: _RECEIVED_DATA, useValue: false},
{provide: _REQUEST_COUNT, useValue: false},
{provide: _CAPTURE_FRAMES, useValue: false}
];

View File

@ -1,12 +1,11 @@
import {bind, provide, Provider} from '@angular/core/src/di';
import {BaseException, WrappedException} from '@angular/facade';
/**
* A metric is measures values
*/
export abstract class Metric {
static bindTo(delegateToken): Provider[] {
return [bind(Metric).toFactory((delegate) => delegate, [delegateToken])];
static bindTo(delegateToken): any[] {
return [{provide: Metric, useFactory: (delegate) => delegate, deps: [delegateToken]}];
}
/**

View File

@ -1,16 +1,22 @@
import {bind, provide, Binding, Provider, Injector, OpaqueToken} from '@angular/core/src/di';
import {Injector, OpaqueToken} from '@angular/core/src/di';
import {StringMapWrapper} from '@angular/facade';
import {PromiseWrapper} from '@angular/facade';
import {Metric} from '../metric';
export class MultiMetric extends Metric {
static createBindings(childTokens: any[]): Provider[] {
static createBindings(childTokens: any[]): any[] {
return [
bind(_CHILDREN)
.toFactory((injector: Injector) => childTokens.map(token => injector.get(token)),
[Injector]),
bind(MultiMetric).toFactory(children => new MultiMetric(children), [_CHILDREN])
{
provide: _CHILDREN,
useFactory:(injector: Injector) => childTokens.map(token => injector.get(token)),
deps: [Injector]
},
{
provide: MultiMetric,
useFactory: children => new MultiMetric(children),
deps: [_CHILDREN]
}
];
}

View File

@ -9,7 +9,7 @@ import {
} from '@angular/facade';
import {BaseException, WrappedException} from '@angular/facade';
import {ListWrapper, StringMapWrapper} from '@angular/facade';
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {OpaqueToken} from '@angular/core/src/di';
import {WebDriverExtension, PerfLogFeatures} from '../web_driver_extension';
import {Metric} from '../metric';
@ -20,7 +20,7 @@ import {Options} from '../common_options';
*/
export class PerflogMetric extends Metric {
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static get PROVIDERS(): any[] { return _PROVIDERS; }
// TODO(tbosch): use static values when our transpiler supports them
static get SET_TIMEOUT(): OpaqueToken { return _SET_TIMEOUT; }
@ -364,19 +364,21 @@ var _MARK_NAME_FRAME_CAPUTRE = 'frameCapture';
var _FRAME_TIME_SMOOTH_THRESHOLD = 17;
var _PROVIDERS = [
bind(PerflogMetric)
.toFactory(
(driverExtension, setTimeout, microMetrics, forceGc, captureFrames, receivedData,
requestCount) => new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc,
captureFrames, receivedData, requestCount),
[
WebDriverExtension,
_SET_TIMEOUT,
Options.MICRO_METRICS,
Options.FORCE_GC,
Options.CAPTURE_FRAMES,
Options.RECEIVED_DATA,
Options.REQUEST_COUNT
]),
provide(_SET_TIMEOUT, {useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)})
{
provide: PerflogMetric,
useFactory:
(driverExtension, setTimeout, microMetrics, forceGc, captureFrames, receivedData,
requestCount) => new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc,
captureFrames, receivedData, requestCount),
deps: [
WebDriverExtension,
_SET_TIMEOUT,
Options.MICRO_METRICS,
Options.FORCE_GC,
Options.CAPTURE_FRAMES,
Options.RECEIVED_DATA,
Options.REQUEST_COUNT
]
},
{provide: _SET_TIMEOUT, useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)}
];

View File

@ -1,4 +1,3 @@
import {bind, provide, Provider} from '@angular/core/src/di';
import {BaseException, WrappedException} from '@angular/facade';
import {MeasureValues} from './measure_values';
@ -6,8 +5,8 @@ import {MeasureValues} from './measure_values';
* A reporter reports measure values and the valid sample.
*/
export abstract class Reporter {
static bindTo(delegateToken): Provider[] {
return [bind(Reporter).toFactory((delegate) => delegate, [delegateToken])];
static bindTo(delegateToken): any[] {
return [{provide: Reporter, useFactory: (delegate) => delegate, deps: [delegateToken]}];
}
reportMeasureValues(values: MeasureValues): Promise<any> { throw new BaseException('NYI'); }

View File

@ -2,7 +2,7 @@ import {print, isPresent, isBlank, NumberWrapper} from '@angular/facade';
import {StringMapWrapper, ListWrapper} from '@angular/facade';
import {PromiseWrapper} from '@angular/facade';
import {Math} from '@angular/facade';
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {OpaqueToken} from '@angular/core/src/di';
import {Statistic} from '../statistic';
import {Reporter} from '../reporter';
@ -18,7 +18,7 @@ export class ConsoleReporter extends Reporter {
// TODO(tbosch): use static values when our transpiler supports them
static get COLUMN_WIDTH(): OpaqueToken { return _COLUMN_WIDTH; }
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static get PROVIDERS(): any[] { return _PROVIDERS; }
static _lpad(value, columnWidth, fill = ' ') {
@ -94,10 +94,12 @@ export class ConsoleReporter extends Reporter {
var _PRINT = new OpaqueToken('ConsoleReporter.print');
var _COLUMN_WIDTH = new OpaqueToken('ConsoleReporter.columnWidth');
var _PROVIDERS = [
bind(ConsoleReporter)
.toFactory((columnWidth, sampleDescription, print) =>
{
provide: ConsoleReporter,
useFactory: (columnWidth, sampleDescription, print) =>
new ConsoleReporter(columnWidth, sampleDescription, print),
[_COLUMN_WIDTH, SampleDescription, _PRINT]),
provide(_COLUMN_WIDTH, {useValue: 18}),
provide(_PRINT, {useValue: print})
deps: [_COLUMN_WIDTH, SampleDescription, _PRINT]
},
{provide: _COLUMN_WIDTH, useValue: 18},
{provide: _PRINT, useValue: print}
];

View File

@ -1,7 +1,7 @@
import {DateWrapper, isPresent, isBlank, Json} from '@angular/facade';
import {PromiseWrapper} from '@angular/facade';
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {OpaqueToken} from '@angular/core/src/di';
import {Reporter} from '../reporter';
import {SampleDescription} from '../sample_description';
@ -15,7 +15,7 @@ export class JsonFileReporter extends Reporter {
// TODO(tbosch): use static values when our transpiler supports them
static get PATH(): OpaqueToken { return _PATH; }
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static get PROVIDERS(): any[] { return _PROVIDERS; }
_writeFile: Function;
_path: string;
@ -48,9 +48,11 @@ export class JsonFileReporter extends Reporter {
var _PATH = new OpaqueToken('JsonFileReporter.path');
var _PROVIDERS = [
bind(JsonFileReporter)
.toFactory((sampleDescription, path, writeFile, now) =>
{
provide: JsonFileReporter,
useFactory: (sampleDescription, path, writeFile, now) =>
new JsonFileReporter(sampleDescription, path, writeFile, now),
[SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
provide(_PATH, {useValue: '.'})
deps: [SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]
},
{provide: _PATH, useValue: '.'}
];

View File

@ -1,16 +1,18 @@
import {bind, provide, Provider, Injector, OpaqueToken} from '@angular/core/src/di';
import {Injector, OpaqueToken} from '@angular/core/src/di';
import {PromiseWrapper} from '@angular/facade';
import {MeasureValues} from '../measure_values';
import {Reporter} from '../reporter';
export class MultiReporter extends Reporter {
static createBindings(childTokens: any[]): Provider[] {
static createBindings(childTokens: any[]): any[] {
return [
bind(_CHILDREN)
.toFactory((injector: Injector) => childTokens.map(token => injector.get(token)),
[Injector]),
bind(MultiReporter).toFactory(children => new MultiReporter(children), [_CHILDREN])
{
provide: _CHILDREN,
useFactory: (injector: Injector) => childTokens.map(token => injector.get(token)),
deps: [Injector],
},
{provide: MultiReporter, useFactory: children => new MultiReporter(children), deps: [_CHILDREN]}
];
}

View File

@ -1,4 +1,4 @@
import {Injector, bind, provide, Provider, ReflectiveInjector} from '@angular/core';
import {ReflectiveInjector} from '@angular/core';
import {isPresent, isBlank} from '@angular/facade';
import {PromiseWrapper} from '@angular/facade';
@ -25,8 +25,8 @@ import {Options} from './common_options';
* It provides defaults, creates the injector and calls the sampler.
*/
export class Runner {
private _defaultProviders: Provider[];
constructor(defaultProviders: Provider[] = null) {
private _defaultProviders: any[];
constructor(defaultProviders: any[] = null) {
if (isBlank(defaultProviders)) {
defaultProviders = [];
}
@ -39,14 +39,14 @@ export class Runner {
var sampleProviders = [
_DEFAULT_PROVIDERS,
this._defaultProviders,
bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute)
{provide: Options.SAMPLE_ID, useValue: id},
{provide: Options.EXECUTE, useValue: execute}
];
if (isPresent(prepare)) {
sampleProviders.push(bind(Options.PREPARE).toValue(prepare));
sampleProviders.push({provide: Options.PREPARE, useValue: prepare});
}
if (isPresent(microMetrics)) {
sampleProviders.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics});
}
if (isPresent(providers)) {
sampleProviders.push(providers);
@ -68,9 +68,9 @@ export class Runner {
// injectors are handled better.
var injector = ReflectiveInjector.resolveAndCreate([
sampleProviders,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
{provide: Options.CAPABILITIES, useValue: capabilities},
{provide: Options.USER_AGENT, useValue: userAgent},
{provide: WebDriverAdapter, useValue: adapter}
]);
var sampler = injector.get(Sampler);

View File

@ -1,5 +1,4 @@
import {StringMapWrapper} from '@angular/facade';
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {Validator} from './validator';
import {Metric} from './metric';
import {Options} from './common_options';
@ -9,7 +8,7 @@ import {Options} from './common_options';
*/
export class SampleDescription {
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static get PROVIDERS(): any[] { return _PROVIDERS; }
description: {[key: string]: any};
constructor(public id: string, descriptions: Array<{[key: string]: any}>,
@ -24,8 +23,9 @@ export class SampleDescription {
}
var _PROVIDERS = [
bind(SampleDescription)
.toFactory((metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) =>
{
provide: SampleDescription,
useFactory: (metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) =>
new SampleDescription(id,
[
{'forceGc': forceGc, 'userAgent': userAgent},
@ -34,13 +34,14 @@ var _PROVIDERS = [
userDesc
],
metric.describe()),
[
Metric,
Options.SAMPLE_ID,
Options.FORCE_GC,
Options.USER_AGENT,
Validator,
Options.DEFAULT_DESCRIPTION,
Options.SAMPLE_DESCRIPTION
])
deps: [
Metric,
Options.SAMPLE_ID,
Options.FORCE_GC,
Options.USER_AGENT,
Validator,
Options.DEFAULT_DESCRIPTION,
Options.SAMPLE_DESCRIPTION
]
}
];

View File

@ -1,6 +1,5 @@
import {isPresent, isBlank, Date, DateWrapper} from '@angular/facade';
import {PromiseWrapper} from '@angular/facade';
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
import {Metric} from './metric';
import {Validator} from './validator';
@ -20,7 +19,7 @@ import {MeasureValues} from './measure_values';
*/
export class Sampler {
// TODO(tbosch): use static values when our transpiler supports them
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static get PROVIDERS(): any[] { return _PROVIDERS; }
_driver: WebDriverAdapter;
_metric: Metric;
@ -95,26 +94,28 @@ export class SampleState {
}
var _PROVIDERS = [
bind(Sampler)
.toFactory((driver, metric, reporter, validator, prepare, execute, now) => new Sampler({
driver: driver,
reporter: reporter,
validator: validator,
metric: metric,
// TODO(tbosch): DI right now does not support null/undefined objects
// Mostly because the cache would have to be initialized with a
// special null object, which is expensive.
prepare: prepare !== false ? prepare : null,
execute: execute,
now: now
}),
[
WebDriverAdapter,
Metric,
Reporter,
Validator,
Options.PREPARE,
Options.EXECUTE,
Options.NOW
])
{
provide: Sampler,
useFactory: (driver, metric, reporter, validator, prepare, execute, now) => new Sampler({
driver: driver,
reporter: reporter,
validator: validator,
metric: metric,
// TODO(tbosch): DI right now does not support null/undefined objects
// Mostly because the cache would have to be initialized with a
// special null object, which is expensive.
prepare: prepare !== false ? prepare : null,
execute: execute,
now: now
}),
deps: [
WebDriverAdapter,
Metric,
Reporter,
Validator,
Options.PREPARE,
Options.EXECUTE,
Options.NOW
]
}
];

Some files were not shown because too many files have changed in this diff Show More