refactor: change provide(...) for {provide: ...}
- provide() is deprecated, - {} syntax is required by the offline compiler
This commit is contained in:
parent
27a47e7841
commit
a6ad61d83e
|
@ -49,7 +49,7 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s
|
||||||
*
|
*
|
||||||
* @Component({
|
* @Component({
|
||||||
* selector: 'app',
|
* selector: 'app',
|
||||||
* providers: [provide(NgLocalization, {useClass: MyLocalization})]
|
* providers: [{provide: NgLocalization, useClass: MyLocalization}]
|
||||||
* })
|
* })
|
||||||
* @View({
|
* @View({
|
||||||
* template: `
|
* template: `
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
Host,
|
Host,
|
||||||
SkipSelf,
|
SkipSelf,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
Provider,
|
|
||||||
Self
|
Self
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {ControlContainer} from './control_container';
|
import {ControlContainer} from './control_container';
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Optional,
|
Optional,
|
||||||
Host,
|
Host,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
Provider,
|
|
||||||
forwardRef
|
forwardRef
|
||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {AbstractControl} from '../model';
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* @Directive({
|
* @Directive({
|
||||||
* selector: '[custom-validator]',
|
* selector: '[custom-validator]',
|
||||||
* providers: [provide(NG_VALIDATORS, {useExisting: CustomValidatorDirective, multi: true})]
|
* providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
|
||||||
* })
|
* })
|
||||||
* class CustomValidatorDirective implements Validator {
|
* class CustomValidatorDirective implements Validator {
|
||||||
* validate(c: Control): {[key: string]: any} {
|
* validate(c: Control): {[key: string]: any} {
|
||||||
|
|
|
@ -42,7 +42,7 @@ import {UrlChangeListener, PlatformLocation} from './platform_location';
|
||||||
*
|
*
|
||||||
* bootstrap(AppCmp, [
|
* bootstrap(AppCmp, [
|
||||||
* ROUTER_PROVIDERS,
|
* ROUTER_PROVIDERS,
|
||||||
* provide(LocationStrategy, {useClass: HashLocationStrategy})
|
* {provide: LocationStrategy, useClass: HashLocationStrategy}
|
||||||
* ]);
|
* ]);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,7 +56,7 @@ export abstract class LocationStrategy {
|
||||||
*
|
*
|
||||||
* bootstrap(AppCmp, [
|
* bootstrap(AppCmp, [
|
||||||
* ROUTER_PROVIDERS,
|
* ROUTER_PROVIDERS,
|
||||||
* provide(APP_BASE_HREF, {useValue: '/my/app'})
|
* {provide: APP_BASE_HREF, useValue: '/my/app'}
|
||||||
* ]);
|
* ]);
|
||||||
* ```
|
* ```
|
||||||
* @stable
|
* @stable
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {Location} from './location';
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* import {Component, provide} from '@angular/core';
|
* import {Component} from '@angular/core';
|
||||||
* import {bootstrap} from '@angular/platform-browser/browser';
|
* import {bootstrap} from '@angular/platform-browser/browser';
|
||||||
* import {
|
* import {
|
||||||
* Location,
|
* Location,
|
||||||
|
@ -50,7 +50,7 @@ import {Location} from './location';
|
||||||
*
|
*
|
||||||
* bootstrap(AppCmp, [
|
* bootstrap(AppCmp, [
|
||||||
* ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
|
* ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
|
||||||
* provide(APP_BASE_HREF, {useValue: '/my/app'})
|
* {provide: APP_BASE_HREF, useValue: '/my/app'}
|
||||||
* ]);
|
* ]);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
|
|
@ -10,14 +10,14 @@ import {
|
||||||
xit,
|
xit,
|
||||||
} from '@angular/core/testing/testing_internal';
|
} from '@angular/core/testing/testing_internal';
|
||||||
import {AsyncTestCompleter} 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';
|
import {NgPlural, NgPluralCase, NgLocalization} from '@angular/common';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('switch', () => {
|
describe('switch', () => {
|
||||||
beforeEachProviders(() => [provide(NgLocalization, {useClass: TestLocalizationMap})]);
|
beforeEachProviders(() => [{provide: NgLocalization, useClass: TestLocalizationMap}]);
|
||||||
|
|
||||||
it('should display the template according to the exact value',
|
it('should display the template according to the exact value',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
|
|
@ -35,7 +35,6 @@ import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||||
import {ListWrapper} from '../../src/facade/collection';
|
import {ListWrapper} from '../../src/facade/collection';
|
||||||
import {ObservableWrapper, TimerWrapper} from '../../src/facade/async';
|
import {ObservableWrapper, TimerWrapper} from '../../src/facade/async';
|
||||||
import {PromiseWrapper} from '../../src/facade/promise';
|
import {PromiseWrapper} from '../../src/facade/promise';
|
||||||
import {browserDetection} from '@angular/platform-browser/testing';
|
|
||||||
import {dispatchEvent} from '@angular/platform-browser/testing';
|
import {dispatchEvent} from '@angular/platform-browser/testing';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
|
@ -1547,8 +1546,7 @@ class LoginIsEmptyValidator {
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[uniq-login-validator]',
|
selector: '[uniq-login-validator]',
|
||||||
providers: [
|
providers: [
|
||||||
new Provider(NG_ASYNC_VALIDATORS,
|
{provide: NG_ASYNC_VALIDATORS, useExisting: forwardRef(() => UniqLoginValidator), multi: true}
|
||||||
{useExisting: forwardRef(() => UniqLoginValidator), multi: true})
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
class UniqLoginValidator implements Validator {
|
class UniqLoginValidator implements Validator {
|
||||||
|
|
|
@ -29,11 +29,9 @@ import {
|
||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
AfterViewChecked,
|
AfterViewChecked,
|
||||||
SimpleChanges,
|
SimpleChanges,
|
||||||
provide
|
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import {TEST_PROVIDERS} from './test_bindings';
|
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 {PLATFORM_DIRECTIVES} from '@angular/core/src/platform_directives_and_pipes';
|
||||||
import {MalformedStylesComponent} from './metadata_resolver_fixture';
|
import {MalformedStylesComponent} from './metadata_resolver_fixture';
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ export function main() {
|
||||||
|
|
||||||
describe("platform directives", () => {
|
describe("platform directives", () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective], multi: true})]);
|
() => [{provide: PLATFORM_DIRECTIVES, useValue: [ADirective], multi: true}]);
|
||||||
|
|
||||||
it('should include platform directives when available',
|
it('should include platform directives when available',
|
||||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
inject,
|
inject,
|
||||||
beforeEachProviders
|
beforeEachProviders
|
||||||
} from '@angular/core/testing/testing_internal';
|
} from '@angular/core/testing/testing_internal';
|
||||||
import {provide} from '@angular/core';
|
|
||||||
import {SecurityContext} from '../core_private';
|
import {SecurityContext} from '../core_private';
|
||||||
|
|
||||||
import {Console} from '@angular/core/src/console';
|
import {Console} from '@angular/core/src/console';
|
||||||
|
@ -63,9 +62,10 @@ var expressionUnparser = new Unparser();
|
||||||
var someModuleUrl = 'package:someModule';
|
var someModuleUrl = 'package:someModule';
|
||||||
|
|
||||||
var MOCK_SCHEMA_REGISTRY = [
|
var MOCK_SCHEMA_REGISTRY = [
|
||||||
provide(
|
{
|
||||||
ElementSchemaRegistry,
|
provide: ElementSchemaRegistry,
|
||||||
{useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})})
|
useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let zeConsole = console;
|
let zeConsole = console;
|
||||||
|
@ -80,7 +80,7 @@ export function main() {
|
||||||
function commonBeforeEach() {
|
function commonBeforeEach() {
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
console = new ArrayConsole();
|
console = new ArrayConsole();
|
||||||
return [provide(Console, {useValue: console})];
|
return [{provide: Console, useValue: console}];
|
||||||
});
|
});
|
||||||
beforeEach(inject([TemplateParser], (parser) => {
|
beforeEach(inject([TemplateParser], (parser) => {
|
||||||
var component = CompileDirectiveMetadata.create({
|
var component = CompileDirectiveMetadata.create({
|
||||||
|
@ -108,7 +108,7 @@ export function main() {
|
||||||
beforeEachProviders(() => [TEST_PROVIDERS, MOCK_SCHEMA_REGISTRY]);
|
beforeEachProviders(() => [TEST_PROVIDERS, MOCK_SCHEMA_REGISTRY]);
|
||||||
|
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(TEMPLATE_TRANSFORMS, {useValue: new FooAstTransformer(), multi: true})]);
|
() => [{provide: TEMPLATE_TRANSFORMS, useValue: new FooAstTransformer(), multi: true}]);
|
||||||
|
|
||||||
describe('single', () => {
|
describe('single', () => {
|
||||||
commonBeforeEach();
|
commonBeforeEach();
|
||||||
|
@ -118,7 +118,7 @@ export function main() {
|
||||||
|
|
||||||
describe('multiple', () => {
|
describe('multiple', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(TEMPLATE_TRANSFORMS, {useValue: new BarAstTransformer(), multi: true})]);
|
() => [{provide: TEMPLATE_TRANSFORMS, useValue: new BarAstTransformer(), multi: true}]);
|
||||||
|
|
||||||
commonBeforeEach();
|
commonBeforeEach();
|
||||||
it('should compose transformers',
|
it('should compose transformers',
|
||||||
|
@ -131,7 +131,7 @@ export function main() {
|
||||||
// Uses the actual DomElementSchemaRegistry.
|
// Uses the actual DomElementSchemaRegistry.
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() =>
|
() =>
|
||||||
[TEST_PROVIDERS, provide(ElementSchemaRegistry, {useClass: DomElementSchemaRegistry})]);
|
[TEST_PROVIDERS, {provide: ElementSchemaRegistry, useClass: DomElementSchemaRegistry}]);
|
||||||
|
|
||||||
commonBeforeEach();
|
commonBeforeEach();
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {ElementSchemaRegistry, XHR, UrlResolver} from '@angular/compiler';
|
||||||
import {createUrlResolverWithoutPackagePrefix} from '@angular/compiler/src/url_resolver';
|
import {createUrlResolverWithoutPackagePrefix} from '@angular/compiler/src/url_resolver';
|
||||||
|
|
||||||
export var TEST_PROVIDERS: any[] = [
|
export var TEST_PROVIDERS: any[] = [
|
||||||
provide(ElementSchemaRegistry, {useValue: new MockSchemaRegistry({}, {})}),
|
{provide: ElementSchemaRegistry, useValue: new MockSchemaRegistry({}, {})},
|
||||||
provide(XHR, {useClass: MockXHR}),
|
{provide: XHR, useClass: MockXHR},
|
||||||
provide(UrlResolver, {useFactory: createUrlResolverWithoutPackagePrefix})
|
{provide: UrlResolver, useFactory: createUrlResolverWithoutPackagePrefix}
|
||||||
];
|
];
|
||||||
|
|
|
@ -18,7 +18,6 @@ import {
|
||||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||||
import {
|
import {
|
||||||
Injectable,
|
Injectable,
|
||||||
provide,
|
|
||||||
Component,
|
Component,
|
||||||
Input,
|
Input,
|
||||||
ViewMetadata,
|
ViewMetadata,
|
||||||
|
@ -290,7 +289,7 @@ export function main() {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
|
||||||
tcb.overrideProviders(TestBindingsComp,
|
tcb.overrideProviders(TestBindingsComp,
|
||||||
[provide(FancyService, {useClass: MockFancyService})])
|
[{provide: FancyService, useClass: MockFancyService}])
|
||||||
.createAsync(TestBindingsComp)
|
.createAsync(TestBindingsComp)
|
||||||
.then((componentFixture) => {
|
.then((componentFixture) => {
|
||||||
componentFixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
@ -305,7 +304,7 @@ export function main() {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
|
||||||
tcb.overrideViewProviders(TestViewBindingsComp,
|
tcb.overrideViewProviders(TestViewBindingsComp,
|
||||||
[provide(FancyService, {useClass: MockFancyService})])
|
[{provide: FancyService, useClass: MockFancyService}])
|
||||||
.createAsync(TestViewBindingsComp)
|
.createAsync(TestViewBindingsComp)
|
||||||
.then((componentFixture) => {
|
.then((componentFixture) => {
|
||||||
componentFixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
@ -337,7 +336,7 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
|
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
|
||||||
withProviders(() => [provide(ComponentFixtureAutoDetect, {useValue: true})])
|
withProviders(() => [{provide: ComponentFixtureAutoDetect, useValue: true}])
|
||||||
.inject([TestComponentBuilder, AsyncTestCompleter],
|
.inject([TestComponentBuilder, AsyncTestCompleter],
|
||||||
(tcb: TestComponentBuilder, async) => {
|
(tcb: TestComponentBuilder, async) => {
|
||||||
|
|
||||||
|
@ -551,7 +550,7 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('No NgZone', () => {
|
describe('No NgZone', () => {
|
||||||
beforeEachProviders(() => [provide(ComponentFixtureNoNgZone, {useValue: true})]);
|
beforeEachProviders(() => [{provide: ComponentFixtureNoNgZone, useValue: true}]);
|
||||||
|
|
||||||
it('calling autoDetectChanges raises an error', () => {
|
it('calling autoDetectChanges raises an error', () => {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
|
||||||
|
|
|
@ -20,7 +20,7 @@ export abstract class Injector {
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* var injector = ReflectiveInjector.resolveAndCreate([
|
* var injector = ReflectiveInjector.resolveAndCreate([
|
||||||
* provide("validToken", {useValue: "Value"})
|
* {provide: "validToken", useValue: "Value"}
|
||||||
* ]);
|
* ]);
|
||||||
* expect(injector.get("validToken")).toEqual("Value");
|
* expect(injector.get("validToken")).toEqual("Value");
|
||||||
* expect(() => injector.get("invalidToken")).toThrowError();
|
* expect(() => injector.get("invalidToken")).toThrowError();
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {stringify} from '../facade/lang';
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* provide("MyEngine", {useClass: Engine}),
|
* {provide: "MyEngine", useClass: Engine},
|
||||||
* Car
|
* Car
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* var t = new OpaqueToken("value");
|
* var t = new OpaqueToken("value");
|
||||||
*
|
*
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* provide(t, {useValue: "bindingValue"})
|
* {provide: t, useValue: "bindingValue"}
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get(t)).toEqual("bindingValue");
|
* expect(injector.get(t)).toEqual("bindingValue");
|
||||||
|
|
|
@ -280,11 +280,11 @@ export class ProviderBuilder {
|
||||||
*
|
*
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
* var injectorClass = Injector.resolveAndCreate([
|
||||||
* Car,
|
* Car,
|
||||||
* provide(Vehicle, {useClass: Car})
|
* {provide: Vehicle, useClass: Car}
|
||||||
* ]);
|
* ]);
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
* var injectorAlias = Injector.resolveAndCreate([
|
||||||
* Car,
|
* Car,
|
||||||
* provide(Vehicle, {useExisting: Car})
|
* {provide: Vehicle, useExisting: Car}
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
||||||
|
@ -309,7 +309,7 @@ export class ProviderBuilder {
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* provide('message', {useValue: 'Hello'})
|
* {provide: 'message', useValue: 'Hello'}
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get('message')).toEqual('Hello');
|
* expect(injector.get('message')).toEqual('Hello');
|
||||||
|
@ -335,11 +335,11 @@ export class ProviderBuilder {
|
||||||
*
|
*
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
* var injectorAlias = Injector.resolveAndCreate([
|
||||||
* Car,
|
* Car,
|
||||||
* provide(Vehicle, {useExisting: Car})
|
* {provide: Vehicle, useExisting: Car}
|
||||||
* ]);
|
* ]);
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
* var injectorClass = Injector.resolveAndCreate([
|
||||||
* Car,
|
* Car,
|
||||||
* provide(Vehicle, {useClass: Car})
|
* {provide: Vehicle, useClass: Car})
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
||||||
|
@ -363,8 +363,8 @@ export class ProviderBuilder {
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* provide(Number, {useFactory: () => { return 1+2; }}),
|
* {provide: Number, useFactory: () => { return 1+2; }},
|
||||||
* provide(String, {useFactory: (v) => { return "Value: " + v; }, deps: [Number]})
|
* {provide: String, useFactory: (v) => { return "Value: " + v; }, deps: [Number]}
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get(Number)).toEqual(3);
|
* expect(injector.get(Number)).toEqual(3);
|
||||||
|
|
|
@ -94,8 +94,8 @@ export class NoProviderError extends AbstractProviderError {
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}),
|
* {provide: "one", useFactory: (two) => "two", deps: [[new Inject("two")]]},
|
||||||
* provide("two", {useFactory: (one) => "one", deps: [[new Inject("one")]]})
|
* {provide: "two", useFactory: (one) => "one", deps: [[new Inject("one")]]}
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(() => injector.get("one")).toThrowError();
|
* expect(() => injector.get("one")).toThrowError();
|
||||||
|
|
|
@ -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
|
* @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
|
* @stable
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,9 +24,9 @@ import {
|
||||||
|
|
||||||
import {isPresent, isArray, IS_DART} from '../../src/facade/lang';
|
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 {CompilerConfig} from '@angular/compiler';
|
||||||
import {AnimationDriver} from '../../src/animation/animation_driver';
|
import {AnimationDriver} from '../../src/animation/animation_driver';
|
||||||
|
@ -41,13 +41,13 @@ export function main() {
|
||||||
} else {
|
} else {
|
||||||
describe('jit', () => {
|
describe('jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||||
declareTests();
|
declareTests();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('no jit', () => {
|
describe('no jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||||
declareTests();
|
declareTests();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ export function main() {
|
||||||
|
|
||||||
function declareTests() {
|
function declareTests() {
|
||||||
describe('animation tests', function() {
|
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 makeAnimationCmp = (tcb: TestComponentBuilder, tpl: string, animationEntry: AnimationEntryMetadata|AnimationEntryMetadata[], callback = null) => {
|
||||||
var entries = isArray(animationEntry)
|
var entries = isArray(animationEntry)
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
} from '@angular/core/src/application_ref';
|
} from '@angular/core/src/application_ref';
|
||||||
import {
|
import {
|
||||||
Injector,
|
Injector,
|
||||||
Provider,
|
|
||||||
APP_INITIALIZER,
|
APP_INITIALIZER,
|
||||||
Component,
|
Component,
|
||||||
ReflectiveInjector,
|
ReflectiveInjector,
|
||||||
|
@ -63,8 +62,7 @@ export function main() {
|
||||||
APPLICATION_CORE_PROVIDERS,
|
APPLICATION_CORE_PROVIDERS,
|
||||||
{provide: Console, useValue: new _MockConsole()},
|
{provide: Console, useValue: new _MockConsole()},
|
||||||
{provide: ExceptionHandler, useValue: new ExceptionHandler(errorLogger, false)},
|
{provide: ExceptionHandler, useValue: new ExceptionHandler(errorLogger, false)},
|
||||||
new Provider(ComponentResolver,
|
{provide: ComponentResolver, useValue: new _MockComponentResolver(someCompFactory)},
|
||||||
{useValue: new _MockComponentResolver(someCompFactory)}),
|
|
||||||
providers
|
providers
|
||||||
],
|
],
|
||||||
platform.injector);
|
platform.injector);
|
||||||
|
@ -125,8 +123,7 @@ export function main() {
|
||||||
it("should throw if an APP_INITIIALIZER is not yet resolved",
|
it("should throw if an APP_INITIIALIZER is not yet resolved",
|
||||||
inject([Injector], (injector) => {
|
inject([Injector], (injector) => {
|
||||||
var app = createApplication([
|
var app = createApplication([
|
||||||
new Provider(APP_INITIALIZER,
|
{provide: APP_INITIALIZER, useValue: () => PromiseWrapper.completer().promise, multi: true}
|
||||||
{useValue: () => PromiseWrapper.completer().promise, multi: true})
|
|
||||||
]);
|
]);
|
||||||
expect(() => app.bootstrap(someCompFactory))
|
expect(() => app.bootstrap(someCompFactory))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
|
|
|
@ -60,7 +60,7 @@ export function main() {
|
||||||
it('should extend di-inherited diffesr', () => {
|
it('should extend di-inherited diffesr', () => {
|
||||||
var parent = new IterableDiffers([factory1]);
|
var parent = new IterableDiffers([factory1]);
|
||||||
var injector =
|
var injector =
|
||||||
ReflectiveInjector.resolveAndCreate([provide(IterableDiffers, {useValue: parent})]);
|
ReflectiveInjector.resolveAndCreate([{provide: IterableDiffers, useValue: parent}]);
|
||||||
var childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
|
var childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
|
||||||
|
|
||||||
expect(injector.get(IterableDiffers).factories).toEqual([factory1]);
|
expect(injector.get(IterableDiffers).factories).toEqual([factory1]);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import {isBlank, stringify, isPresent} from '../../src/facade/lang';
|
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 {describe, ddescribe, it, iit, expect, beforeEach} from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
provide,
|
|
||||||
ReflectiveKey,
|
ReflectiveKey,
|
||||||
ReflectiveInjector,
|
ReflectiveInjector,
|
||||||
Injector,
|
Injector,
|
||||||
|
@ -10,10 +9,8 @@ import {
|
||||||
Injectable,
|
Injectable,
|
||||||
InjectMetadata,
|
InjectMetadata,
|
||||||
SelfMetadata,
|
SelfMetadata,
|
||||||
SkipSelfMetadata,
|
|
||||||
Optional,
|
Optional,
|
||||||
Inject,
|
Inject,
|
||||||
Provider
|
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ReflectiveInjector_,
|
ReflectiveInjector_,
|
||||||
|
@ -88,17 +85,17 @@ function factoryFn(a) {}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
var dynamicProviders = [
|
var dynamicProviders = [
|
||||||
provide('provider0', {useValue: 1}),
|
{provide: 'provider0', useValue: 1},
|
||||||
provide('provider1', {useValue: 1}),
|
{provide: 'provider1', useValue: 1},
|
||||||
provide('provider2', {useValue: 1}),
|
{provide: 'provider2', useValue: 1},
|
||||||
provide('provider3', {useValue: 1}),
|
{provide: 'provider3', useValue: 1},
|
||||||
provide('provider4', {useValue: 1}),
|
{provide: 'provider4', useValue: 1},
|
||||||
provide('provider5', {useValue: 1}),
|
{provide: 'provider5', useValue: 1},
|
||||||
provide('provider6', {useValue: 1}),
|
{provide: 'provider6', useValue: 1},
|
||||||
provide('provider7', {useValue: 1}),
|
{provide: 'provider7', useValue: 1},
|
||||||
provide('provider8', {useValue: 1}),
|
{provide: 'provider8', useValue: 1},
|
||||||
provide('provider9', {useValue: 1}),
|
{provide: 'provider9', useValue: 1},
|
||||||
provide('provider10', {useValue: 1})
|
{provide: 'provider10', useValue: 1}
|
||||||
];
|
];
|
||||||
|
|
||||||
[{strategy: 'inline', providers: [], strategyClass: ReflectiveInjectorInlineStrategy},
|
[{strategy: 'inline', providers: [], strategyClass: ReflectiveInjectorInlineStrategy},
|
||||||
|
@ -155,7 +152,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when no type and not @Inject (factory case)', () => {
|
it('should throw when no type and not @Inject (factory case)', () => {
|
||||||
expect(() => createInjector([provide("someToken", {useFactory: factoryFn})]))
|
expect(() => createInjector([{provide: "someToken", useFactory: factoryFn}]))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
"Cannot resolve all parameters for 'factoryFn'(?). " +
|
"Cannot resolve all parameters for 'factoryFn'(?). " +
|
||||||
'Make sure that all the parameters are decorated with Inject or have valid type annotations ' +
|
'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', () => {
|
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);
|
var engine = injector.get(Engine);
|
||||||
expect(engine).toEqual("fake engine");
|
expect(engine).toEqual("fake engine");
|
||||||
|
@ -182,7 +179,7 @@ export function main() {
|
||||||
function sportsCarFactory(e) { return new SportsCar(e); }
|
function sportsCarFactory(e) { return new SportsCar(e); }
|
||||||
|
|
||||||
var injector =
|
var injector =
|
||||||
createInjector([Engine, provide(Car, {useFactory: sportsCarFactory, deps: [Engine]})]);
|
createInjector([Engine, {provide: Car, useFactory: sportsCarFactory, deps: [Engine]}]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
expect(car).toBeAnInstanceOf(SportsCar);
|
expect(car).toBeAnInstanceOf(SportsCar);
|
||||||
|
@ -194,33 +191,33 @@ export function main() {
|
||||||
|
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
Engine,
|
Engine,
|
||||||
provide(Car,
|
{
|
||||||
{
|
provide: Car,
|
||||||
useFactory: factoryWithTooManyArgs,
|
useFactory: factoryWithTooManyArgs,
|
||||||
deps: [
|
deps: [
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine,
|
Engine,
|
||||||
Engine
|
Engine
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -233,7 +230,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should supporting provider to null', () => {
|
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);
|
var engine = injector.get(Engine);
|
||||||
expect(engine).toBeNull();
|
expect(engine).toBeNull();
|
||||||
});
|
});
|
||||||
|
@ -241,8 +238,8 @@ export function main() {
|
||||||
it('should provide to an alias', () => {
|
it('should provide to an alias', () => {
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
Engine,
|
Engine,
|
||||||
provide(SportsCar, {useClass: SportsCar}),
|
{provide: SportsCar, useClass: SportsCar},
|
||||||
provide(Car, {useExisting: SportsCar})
|
{provide: Car, useExisting: SportsCar}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
|
@ -278,22 +275,22 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when the aliased provider does not exist', () => {
|
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)})`;
|
var e = `No provider for ${stringify(SportsCar)}! (car -> ${stringify(SportsCar)})`;
|
||||||
expect(() => injector.get('car')).toThrowError(e);
|
expect(() => injector.get('car')).toThrowError(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle forwardRef in useExisting', () => {
|
it('should handle forwardRef in useExisting', () => {
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
provide('originalEngine', {useClass: forwardRef(() => Engine)}),
|
{provide: 'originalEngine', useClass: forwardRef(() => Engine)},
|
||||||
provide('aliasedEngine', {useExisting:<any>forwardRef(() => 'originalEngine')})
|
{provide: 'aliasedEngine', useExisting:<any>forwardRef(() => 'originalEngine')}
|
||||||
]);
|
]);
|
||||||
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
|
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support overriding factory dependencies', () => {
|
it('should support overriding factory dependencies', () => {
|
||||||
var injector = createInjector(
|
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);
|
var car = injector.get(Car);
|
||||||
expect(car).toBeAnInstanceOf(SportsCar);
|
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", () => {
|
it("should use the last provider when there are multiple providers for same token", () => {
|
||||||
var injector = createInjector(
|
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);
|
expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use non-type tokens', () => {
|
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');
|
expect(injector.get('token')).toEqual('value');
|
||||||
});
|
});
|
||||||
|
@ -353,7 +350,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to instantiate a cyclic dependency', () => {
|
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))
|
expect(() => injector.get(Car))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
|
@ -362,7 +359,7 @@ export function main() {
|
||||||
|
|
||||||
it('should show the full path when error happens in a constructor', () => {
|
it('should show the full path when error happens in a constructor', () => {
|
||||||
var providers =
|
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 proto = new ReflectiveProtoInjector([providers[0], providers[1]]);
|
||||||
var injector = new ReflectiveInjector_(proto);
|
var injector = new ReflectiveInjector_(proto);
|
||||||
|
|
||||||
|
@ -379,7 +376,7 @@ export function main() {
|
||||||
|
|
||||||
it('should provide context when throwing an exception ', () => {
|
it('should provide context when throwing an exception ', () => {
|
||||||
var engineProvider =
|
var engineProvider =
|
||||||
ReflectiveInjector.resolve([provide(Engine, {useClass: BrokenEngine})])[0];
|
ReflectiveInjector.resolve([{provide: Engine, useClass: BrokenEngine}])[0];
|
||||||
var protoParent = new ReflectiveProtoInjector([engineProvider]);
|
var protoParent = new ReflectiveProtoInjector([engineProvider]);
|
||||||
|
|
||||||
var carProvider = ReflectiveInjector.resolve([Car])[0];
|
var carProvider = ReflectiveInjector.resolve([Car])[0];
|
||||||
|
@ -401,7 +398,7 @@ export function main() {
|
||||||
|
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
Car,
|
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"));
|
expect(() => injector.get(Car)).toThrowError(new RegExp("Error"));
|
||||||
|
@ -412,7 +409,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support null values', () => {
|
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);
|
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",
|
it("should not use the child providers when resolving the dependencies of a parent provider",
|
||||||
() => {
|
() => {
|
||||||
var parent = ReflectiveInjector.resolveAndCreate([Car, Engine]);
|
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);
|
var carFromChild = child.get(Car);
|
||||||
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
|
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
|
||||||
|
@ -441,7 +438,7 @@ export function main() {
|
||||||
|
|
||||||
it('should create new instance in a child injector', () => {
|
it('should create new instance in a child injector', () => {
|
||||||
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
|
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 engineFromParent = parent.get(Engine);
|
||||||
var engineFromChild = child.get(Engine);
|
var engineFromChild = child.get(Engine);
|
||||||
|
@ -486,7 +483,7 @@ export function main() {
|
||||||
it("should return a dependency from self", () => {
|
it("should return a dependency from self", () => {
|
||||||
var inj = ReflectiveInjector.resolveAndCreate([
|
var inj = ReflectiveInjector.resolveAndCreate([
|
||||||
Engine,
|
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);
|
expect(inj.get(Car)).toBeAnInstanceOf(Car);
|
||||||
|
@ -495,7 +492,7 @@ export function main() {
|
||||||
it("should throw when not requested provider on self", () => {
|
it("should throw when not requested provider on self", () => {
|
||||||
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
|
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
|
||||||
var child = parent.resolveAndCreateChild([
|
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))
|
expect(() => child.get(Car))
|
||||||
|
@ -507,8 +504,8 @@ export function main() {
|
||||||
it("should not skip self", () => {
|
it("should not skip self", () => {
|
||||||
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
|
var parent = ReflectiveInjector.resolveAndCreate([Engine]);
|
||||||
var child = parent.resolveAndCreateChild([
|
var child = parent.resolveAndCreateChild([
|
||||||
provide(Engine, {useClass: TurboEngine}),
|
{provide: Engine, useClass: TurboEngine},
|
||||||
provide(Car, {useFactory: (e) => new Car(e), deps: [Engine]})
|
{provide: Car, useFactory: (e) => new Car(e), deps: [Engine]}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(child.get(Car).engine).toBeAnInstanceOf(TurboEngine);
|
expect(child.get(Car).engine).toBeAnInstanceOf(TurboEngine);
|
||||||
|
@ -578,9 +575,9 @@ export function main() {
|
||||||
it('should resolve forward references', () => {
|
it('should resolve forward references', () => {
|
||||||
var providers = ReflectiveInjector.resolve([
|
var providers = ReflectiveInjector.resolve([
|
||||||
forwardRef(() => Engine),
|
forwardRef(() => Engine),
|
||||||
[provide(forwardRef(() => BrokenEngine), {useClass: forwardRef(() => Engine)})],
|
[{provide: forwardRef(() => BrokenEngine), useClass: forwardRef(() => Engine)}],
|
||||||
provide(forwardRef(() => String),
|
{provide: forwardRef(() => String),
|
||||||
{useFactory: () => 'OK', deps: [forwardRef(() => Engine)]})
|
useFactory: () => 'OK', deps: [forwardRef(() => Engine)]}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var engineProvider = providers[0];
|
var engineProvider = providers[0];
|
||||||
|
@ -597,12 +594,11 @@ export function main() {
|
||||||
it('should support overriding factory dependencies with dependency annotations',
|
it('should support overriding factory dependencies with dependency annotations',
|
||||||
() => {
|
() => {
|
||||||
var providers = ReflectiveInjector.resolve([
|
var providers = ReflectiveInjector.resolve([
|
||||||
provide(
|
{
|
||||||
"token",
|
provide: "token",
|
||||||
{
|
useFactory: (e) => "result",
|
||||||
useFactory: (e) => "result",
|
deps: [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]
|
||||||
deps: [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]
|
}
|
||||||
})
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var provider = providers[0];
|
var provider = providers[0];
|
||||||
|
@ -614,9 +610,9 @@ export function main() {
|
||||||
|
|
||||||
it('should allow declaring dependencies with flat arrays', () => {
|
it('should allow declaring dependencies with flat arrays', () => {
|
||||||
var resolved = ReflectiveInjector.resolve(
|
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(
|
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)
|
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
|
||||||
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
|
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
|
||||||
});
|
});
|
||||||
|
|
|
@ -125,7 +125,7 @@ export function main() {
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
RenderLog,
|
RenderLog,
|
||||||
DirectiveLog,
|
DirectiveLog,
|
||||||
provide(RootRenderer, {useClass: LoggingRootRenderer}),
|
{provide: RootRenderer, useClass: LoggingRootRenderer},
|
||||||
TEST_PROVIDERS,
|
TEST_PROVIDERS,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,11 @@ import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'
|
||||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
import {
|
import {
|
||||||
Type,
|
|
||||||
isPresent,
|
isPresent,
|
||||||
assertionsEnabled,
|
|
||||||
isJsObject,
|
|
||||||
global,
|
|
||||||
stringify,
|
stringify,
|
||||||
isBlank,
|
isBlank,
|
||||||
} from '../../src/facade/lang';
|
} from '../../src/facade/lang';
|
||||||
import {BaseException, WrappedException} from '../../src/facade/exceptions';
|
import {BaseException} from '../../src/facade/exceptions';
|
||||||
import {
|
import {
|
||||||
PromiseWrapper,
|
PromiseWrapper,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
|
@ -33,10 +29,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Injector,
|
Injector,
|
||||||
bind,
|
|
||||||
provide,
|
|
||||||
Injectable,
|
Injectable,
|
||||||
Provider,
|
|
||||||
forwardRef,
|
forwardRef,
|
||||||
OpaqueToken,
|
OpaqueToken,
|
||||||
Inject,
|
Inject,
|
||||||
|
@ -91,13 +84,13 @@ export function main() {
|
||||||
} else {
|
} else {
|
||||||
describe('jit', () => {
|
describe('jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||||
declareTests(true);
|
declareTests(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('no jit', () => {
|
describe('no jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||||
declareTests(false);
|
declareTests(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -106,7 +99,7 @@ export function main() {
|
||||||
function declareTests(isJit: boolean) {
|
function declareTests(isJit: boolean) {
|
||||||
describe('integration tests', function() {
|
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() {
|
describe('react to record changes', function() {
|
||||||
it('should consume text node changes',
|
it('should consume text node changes',
|
||||||
|
@ -1714,7 +1707,7 @@ function declareTests(isJit: boolean) {
|
||||||
|
|
||||||
describe('logging property updates', () => {
|
describe('logging property updates', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, true, isJit)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, true, isJit)}]);
|
||||||
|
|
||||||
it('should reflect property values as attributes',
|
it('should reflect property values as attributes',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
@ -1947,7 +1940,7 @@ class DynamicViewport {
|
||||||
var myService = new MyService();
|
var myService = new MyService();
|
||||||
myService.greeting = 'dynamic greet';
|
myService.greeting = 'dynamic greet';
|
||||||
|
|
||||||
var injector = ReflectiveInjector.resolveAndCreate([provide(MyService, {useValue: myService})],
|
var injector = ReflectiveInjector.resolveAndCreate([{ provide: MyService, useValue: myService}],
|
||||||
vc.injector);
|
vc.injector);
|
||||||
this.done = compiler.resolveComponent(ChildCompUsingService)
|
this.done = compiler.resolveComponent(ChildCompUsingService)
|
||||||
.then((componentFactory) => vc.createComponent(componentFactory, 0, injector));
|
.then((componentFactory) => vc.createComponent(componentFactory, 0, injector));
|
||||||
|
@ -2436,13 +2429,10 @@ function createParentBus(peb) {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'parent-providing-event-bus',
|
selector: 'parent-providing-event-bus',
|
||||||
providers: [
|
providers: [
|
||||||
new Provider(EventBus,
|
{provide: EventBus, useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]}
|
||||||
{useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]})
|
|
||||||
],
|
],
|
||||||
directives: [forwardRef(() => ChildConsumingEventBus)],
|
directives: [forwardRef(() => ChildConsumingEventBus)],
|
||||||
template: `
|
template: `<child-consuming-event-bus></child-consuming-event-bus>`
|
||||||
<child-consuming-event-bus></child-consuming-event-bus>
|
|
||||||
`
|
|
||||||
})
|
})
|
||||||
class ParentProvidingEventBus {
|
class ParentProvidingEventBus {
|
||||||
bus: EventBus;
|
bus: EventBus;
|
||||||
|
|
|
@ -25,7 +25,7 @@ export function main() {
|
||||||
describe('Compiler', () => {
|
describe('Compiler', () => {
|
||||||
var someCompFactory;
|
var someCompFactory;
|
||||||
|
|
||||||
beforeEachProviders(() => [provide(ComponentResolver, {useClass: ReflectorComponentResolver})]);
|
beforeEachProviders(() => [{provide: ComponentResolver, useClass: ReflectorComponentResolver}]);
|
||||||
|
|
||||||
beforeEach(inject([ComponentResolver], (_compiler) => {
|
beforeEach(inject([ComponentResolver], (_compiler) => {
|
||||||
someCompFactory = new ComponentFactory(null, null, null);
|
someCompFactory = new ComponentFactory(null, null, null);
|
||||||
|
|
|
@ -34,13 +34,13 @@ export function main() {
|
||||||
} else {
|
} else {
|
||||||
describe('jit', () => {
|
describe('jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||||
declareTests(true);
|
declareTests(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('no jit', () => {
|
describe('no jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||||
declareTests(false);
|
declareTests(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ function declareTests(isJit: boolean) {
|
||||||
describe('regressions', () => {
|
describe('regressions', () => {
|
||||||
|
|
||||||
describe('platform pipes', () => {
|
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',
|
it('should overwrite them by custom pipes',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
@ -106,7 +106,7 @@ function declareTests(isJit: boolean) {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
var token = new OpaqueToken('a.b');
|
var token = new OpaqueToken('a.b');
|
||||||
var tokenValue = 1;
|
var tokenValue = 1;
|
||||||
createInjector(tcb, [provide(token, {useValue: tokenValue})])
|
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||||
.then((injector: Injector) => {
|
.then((injector: Injector) => {
|
||||||
expect(injector.get(token)).toEqual(tokenValue);
|
expect(injector.get(token)).toEqual(tokenValue);
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -117,7 +117,7 @@ function declareTests(isJit: boolean) {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
var token = 'a.b';
|
var token = 'a.b';
|
||||||
var tokenValue = 1;
|
var tokenValue = 1;
|
||||||
createInjector(tcb, [provide(token, {useValue: tokenValue})])
|
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||||
.then((injector: Injector) => {
|
.then((injector: Injector) => {
|
||||||
expect(injector.get(token)).toEqual(tokenValue);
|
expect(injector.get(token)).toEqual(tokenValue);
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -128,7 +128,7 @@ function declareTests(isJit: boolean) {
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
var token = () => true;
|
var token = () => true;
|
||||||
var tokenValue = 1;
|
var tokenValue = 1;
|
||||||
createInjector(tcb, [provide(token, {useValue: tokenValue})])
|
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||||
.then((injector: Injector) => {
|
.then((injector: Injector) => {
|
||||||
expect(injector.get(token)).toEqual(tokenValue);
|
expect(injector.get(token)).toEqual(tokenValue);
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -143,7 +143,7 @@ function declareTests(isJit: boolean) {
|
||||||
var tokenValue2 = {'a': 1};
|
var tokenValue2 = {'a': 1};
|
||||||
createInjector(
|
createInjector(
|
||||||
tcb,
|
tcb,
|
||||||
[provide(token1, {useValue: tokenValue1}), provide(token2, {useValue: tokenValue2})])
|
[{provide: token1, useValue: tokenValue1}, {provide: token2, useValue: tokenValue2}])
|
||||||
.then((injector: Injector) => {
|
.then((injector: Injector) => {
|
||||||
expect(injector.get(token1)).toEqual(tokenValue1);
|
expect(injector.get(token1)).toEqual(tokenValue1);
|
||||||
expect(injector.get(token2)).toEqual(tokenValue2);
|
expect(injector.get(token2)).toEqual(tokenValue2);
|
||||||
|
|
|
@ -28,13 +28,13 @@ export function main() {
|
||||||
} else {
|
} else {
|
||||||
describe('jit', () => {
|
describe('jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||||
declareTests(true);
|
declareTests(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('no jit', () => {
|
describe('no jit', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
|
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||||
declareTests(false);
|
declareTests(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ function itAsync(msg: string,
|
||||||
function declareTests(isJit: boolean) {
|
function declareTests(isJit: boolean) {
|
||||||
describe('security integration tests', function() {
|
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;
|
let originalLog: (msg: any) => any;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
|
@ -287,7 +287,7 @@ export function main() {
|
||||||
// On CJS fakeAsync is not supported...
|
// On CJS fakeAsync is not supported...
|
||||||
if (!getDOM().supportsDOMEvents()) return;
|
if (!getDOM().supportsDOMEvents()) return;
|
||||||
|
|
||||||
beforeEachProviders(() => [provide("appService", {useValue: 'appService'})]);
|
beforeEachProviders(() => [{provide: "appService", useValue: 'appService'}]);
|
||||||
|
|
||||||
beforeEach(inject([TestComponentBuilder], (_tcb) => { tcb = _tcb; }));
|
beforeEach(inject([TestComponentBuilder], (_tcb) => { tcb = _tcb; }));
|
||||||
|
|
||||||
|
@ -308,14 +308,14 @@ export function main() {
|
||||||
|
|
||||||
it('should support useValue with different values', fakeAsync(() => {
|
it('should support useValue with different values', fakeAsync(() => {
|
||||||
var el = createComp('', tcb.overrideProviders(TestComp, [
|
var el = createComp('', tcb.overrideProviders(TestComp, [
|
||||||
provide('numLiteral', {useValue: 0}),
|
{provide:'numLiteral', useValue: 0},
|
||||||
provide('boolLiteral', {useValue: true}),
|
{provide: 'boolLiteral', useValue: true},
|
||||||
provide('strLiteral', {useValue: 'a'}),
|
{provide: 'strLiteral', useValue: 'a'},
|
||||||
provide('null', {useValue: null}),
|
{provide: 'null', useValue: null},
|
||||||
provide('array', {useValue: [1]}),
|
{provide: 'array', useValue: [1]},
|
||||||
provide('map', {useValue: {'a': 1}}),
|
{provide: 'map', useValue: {'a': 1}},
|
||||||
provide('instance', {useValue: new TestValue('a')}),
|
{provide: 'instance', useValue: new TestValue('a')},
|
||||||
provide('nested', {useValue: [{'a': [1]}, new TestValue('b')]}),
|
{provide: 'nested', useValue: [{'a': [1]}, new TestValue('b')]},
|
||||||
]));
|
]));
|
||||||
expect(el.inject('numLiteral')).toBe(0);
|
expect(el.inject('numLiteral')).toBe(0);
|
||||||
expect(el.inject('boolLiteral')).toBe(true);
|
expect(el.inject('boolLiteral')).toBe(true);
|
||||||
|
@ -331,19 +331,19 @@ export function main() {
|
||||||
var el = createComp('<div simpleDirective><span someOtherDirective></span></div>',
|
var el = createComp('<div simpleDirective><span someOtherDirective></span></div>',
|
||||||
tcb.overrideProviders(
|
tcb.overrideProviders(
|
||||||
SimpleDirective,
|
SimpleDirective,
|
||||||
[provide('injectable1', {useValue: 'injectable1'})])
|
[{provide: 'injectable1', useValue: 'injectable1'}])
|
||||||
.overrideProviders(SomeOtherDirective, [
|
.overrideProviders(SomeOtherDirective, [
|
||||||
provide('injectable1', {useValue: 'new-injectable1'}),
|
{provide: 'injectable1', useValue: 'new-injectable1'},
|
||||||
provide('injectable2',
|
{
|
||||||
{
|
provide: 'injectable2',
|
||||||
useFactory: (val) => `${val}-injectable2`,
|
useFactory: (val) => `${val}-injectable2`,
|
||||||
deps: [
|
deps: [
|
||||||
[
|
[
|
||||||
new InjectMetadata('injectable1'),
|
new InjectMetadata('injectable1'),
|
||||||
new SkipSelfMetadata()
|
new SkipSelfMetadata()
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
]));
|
]));
|
||||||
expect(el.children[0].children[0].inject('injectable2'))
|
expect(el.children[0].children[0].inject('injectable2'))
|
||||||
.toEqual('injectable1-injectable2');
|
.toEqual('injectable1-injectable2');
|
||||||
|
@ -351,9 +351,8 @@ export function main() {
|
||||||
|
|
||||||
it("should instantiate providers that have dependencies", fakeAsync(() => {
|
it("should instantiate providers that have dependencies", fakeAsync(() => {
|
||||||
var providers = [
|
var providers = [
|
||||||
provide('injectable1', {useValue: 'injectable1'}),
|
{provide: 'injectable1', useValue: 'injectable1'},
|
||||||
provide('injectable2',
|
{provide: 'injectable2', useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']}
|
||||||
{useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']})
|
|
||||||
];
|
];
|
||||||
var el = createComp('<div simpleDirective></div>',
|
var el = createComp('<div simpleDirective></div>',
|
||||||
tcb.overrideProviders(SimpleDirective, providers));
|
tcb.overrideProviders(SimpleDirective, providers));
|
||||||
|
@ -362,9 +361,8 @@ export function main() {
|
||||||
|
|
||||||
it("should instantiate viewProviders that have dependencies", fakeAsync(() => {
|
it("should instantiate viewProviders that have dependencies", fakeAsync(() => {
|
||||||
var viewProviders = [
|
var viewProviders = [
|
||||||
provide('injectable1', {useValue: 'injectable1'}),
|
{provide: 'injectable1', useValue: 'injectable1'},
|
||||||
provide('injectable2',
|
{provide: 'injectable2', useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']}
|
||||||
{useFactory: (val) => `${val}-injectable2`, deps: ['injectable1']})
|
|
||||||
];
|
];
|
||||||
|
|
||||||
var el = createComp('<div simpleComponent></div>',
|
var el = createComp('<div simpleComponent></div>',
|
||||||
|
@ -376,14 +374,14 @@ export function main() {
|
||||||
var el =
|
var el =
|
||||||
createComp('<div needsServiceComponent></div>',
|
createComp('<div needsServiceComponent></div>',
|
||||||
tcb.overrideViewProviders(NeedsServiceComponent,
|
tcb.overrideViewProviders(NeedsServiceComponent,
|
||||||
[provide('service', {useValue: 'service'})]));
|
[{provide: 'service', useValue: 'service'}]));
|
||||||
expect(el.children[0].inject(NeedsServiceComponent).service).toEqual('service');
|
expect(el.children[0].inject(NeedsServiceComponent).service).toEqual('service');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should instantiate multi providers", fakeAsync(() => {
|
it("should instantiate multi providers", fakeAsync(() => {
|
||||||
var providers = [
|
var providers = [
|
||||||
provide('injectable1', {useValue: 'injectable11', multi: true}),
|
{provide: 'injectable1', useValue: 'injectable11', multi: true},
|
||||||
provide('injectable1', {useValue: 'injectable12', multi: true})
|
{provide: 'injectable1', useValue: 'injectable12', multi: true}
|
||||||
];
|
];
|
||||||
var el = createComp('<div simpleDirective></div>',
|
var el = createComp('<div simpleDirective></div>',
|
||||||
tcb.overrideProviders(SimpleDirective, providers));
|
tcb.overrideProviders(SimpleDirective, providers));
|
||||||
|
@ -395,7 +393,7 @@ export function main() {
|
||||||
var el = createComp(
|
var el = createComp(
|
||||||
'<div simpleDirective></div>',
|
'<div simpleDirective></div>',
|
||||||
tcb.overrideProviders(SimpleDirective,
|
tcb.overrideProviders(SimpleDirective,
|
||||||
[provide('service', {useFactory: () => created = true})]));
|
[{provide: 'service', useFactory: () => created = true}]));
|
||||||
|
|
||||||
expect(created).toBe(false);
|
expect(created).toBe(false);
|
||||||
|
|
||||||
|
@ -409,7 +407,7 @@ export function main() {
|
||||||
var el = createComp(
|
var el = createComp(
|
||||||
'<div simpleComponent></div>',
|
'<div simpleComponent></div>',
|
||||||
tcb.overrideViewProviders(SimpleComponent,
|
tcb.overrideViewProviders(SimpleComponent,
|
||||||
[provide('service', {useFactory: () => created = true})]));
|
[{provide: 'service', useFactory: () => created = true}]));
|
||||||
|
|
||||||
expect(created).toBe(false);
|
expect(created).toBe(false);
|
||||||
|
|
||||||
|
@ -423,7 +421,7 @@ export function main() {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
createComp('<div simpleComponent needsService></div>',
|
createComp('<div simpleComponent needsService></div>',
|
||||||
tcb.overrideViewProviders(
|
tcb.overrideViewProviders(
|
||||||
SimpleComponent, [provide("service", {useValue: "service"})])))
|
SimpleComponent, [{provide: "service", useValue: "service"}])))
|
||||||
.toThrowError(containsRegexp(`No provider for service!`));
|
.toThrowError(containsRegexp(`No provider for service!`));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -432,7 +430,7 @@ export function main() {
|
||||||
var el =
|
var el =
|
||||||
createComp('<div simpleDirective><div needsService></div></div>',
|
createComp('<div simpleDirective><div needsService></div></div>',
|
||||||
tcb.overrideProviders(SimpleDirective,
|
tcb.overrideProviders(SimpleDirective,
|
||||||
[provide('service', {useValue: 'parentService'})]));
|
[{provide: 'service', useValue: 'parentService'}]));
|
||||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -441,7 +439,7 @@ export function main() {
|
||||||
var el = createComp(
|
var el = createComp(
|
||||||
'<div simpleDirective><template [ngIf]="true"><div *ngIf="true" needsService></div></template></div>',
|
'<div simpleDirective><template [ngIf]="true"><div *ngIf="true" needsService></div></template></div>',
|
||||||
tcb.overrideProviders(SimpleDirective,
|
tcb.overrideProviders(SimpleDirective,
|
||||||
[provide('service', {useValue: 'parentService'})]));
|
[{provide: 'service', useValue: 'parentService'}]));
|
||||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -450,7 +448,7 @@ export function main() {
|
||||||
createComp('<div simpleComponent></div>',
|
createComp('<div simpleComponent></div>',
|
||||||
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
||||||
.overrideProviders(SimpleComponent,
|
.overrideProviders(SimpleComponent,
|
||||||
[provide('service', {useValue: 'hostService'})]));
|
[{provide: 'service', useValue: 'hostService'}]));
|
||||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -460,7 +458,7 @@ export function main() {
|
||||||
'<div simpleComponent></div>',
|
'<div simpleComponent></div>',
|
||||||
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
||||||
.overrideViewProviders(SimpleComponent,
|
.overrideViewProviders(SimpleComponent,
|
||||||
[provide('service', {useValue: 'hostService'})]));
|
[{provide: 'service', useValue: 'hostService'}]));
|
||||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -470,7 +468,7 @@ export function main() {
|
||||||
'<div simpleComponent></div>',
|
'<div simpleComponent></div>',
|
||||||
tcb.overrideTemplate(SimpleComponent, '<div *ngIf="true" needsService></div>')
|
tcb.overrideTemplate(SimpleComponent, '<div *ngIf="true" needsService></div>')
|
||||||
.overrideViewProviders(SimpleComponent,
|
.overrideViewProviders(SimpleComponent,
|
||||||
[provide('service', {useValue: 'hostService'})]));
|
[{provide: 'service', useValue: 'hostService'}]));
|
||||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -492,7 +490,7 @@ export function main() {
|
||||||
expect(() => createComp(
|
expect(() => createComp(
|
||||||
'<div simpleComponent></div>',
|
'<div simpleComponent></div>',
|
||||||
tcb.overrideProviders(SimpleComponent,
|
tcb.overrideProviders(SimpleComponent,
|
||||||
[provide('service', {useValue: 'hostService'})])
|
[{provide: 'service', useValue: 'hostService'}])
|
||||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
|
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
|
||||||
|
@ -504,7 +502,7 @@ export function main() {
|
||||||
expect(() => createComp(
|
expect(() => createComp(
|
||||||
'<div simpleComponent someOtherDirective></div>',
|
'<div simpleComponent someOtherDirective></div>',
|
||||||
tcb.overrideProviders(SomeOtherDirective,
|
tcb.overrideProviders(SomeOtherDirective,
|
||||||
[provide('service', {useValue: 'hostService'})])
|
[{provide: 'service', useValue: 'hostService'}])
|
||||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
|
`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(() => {
|
it('should instantiate pipes that have dependencies', fakeAsync(() => {
|
||||||
var el = createComp(
|
var el = createComp(
|
||||||
'<div [simpleDirective]="true | pipeNeedsService"></div>',
|
'<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');
|
expect(el.children[0].inject(SimpleDirective).value.service).toEqual('pipeService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class TestInjector {
|
||||||
|
|
||||||
private _injector: ReflectiveInjector = null;
|
private _injector: ReflectiveInjector = null;
|
||||||
|
|
||||||
private _providers: Array<Type | Provider | any[]> = [];
|
private _providers: Array<Type | Provider | any[] | any> = [];
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this._injector = null;
|
this._injector = null;
|
||||||
|
@ -21,11 +21,11 @@ export class TestInjector {
|
||||||
this._instantiated = false;
|
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) {
|
if (this._instantiated) {
|
||||||
throw new BaseException('Cannot add providers after test injector is instantiated');
|
throw new BaseException('Cannot add providers after test injector is instantiated');
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,8 +92,8 @@ export function beforeEach(fn: Function): void {
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* beforeEachProviders(() => [
|
* beforeEachProviders(() => [
|
||||||
* provide(Compiler, {useClass: MockCompiler}),
|
* {provide: Compiler, useClass: MockCompiler},
|
||||||
* provide(SomeToken, {useValue: myValue}),
|
* {provide: SomeToken, useValue: myValue},
|
||||||
* ]);
|
* ]);
|
||||||
*/
|
*/
|
||||||
export function beforeEachProviders(fn): void {
|
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);
|
var timeOut = Math.max(globalTimeOut, testTimeOut);
|
||||||
|
|
||||||
jsmFn(name, (done) => {
|
jsmFn(name, (done) => {
|
||||||
var completerProvider = provide(AsyncTestCompleter, {
|
var completerProvider = {
|
||||||
|
provide: AsyncTestCompleter,
|
||||||
useFactory: () => {
|
useFactory: () => {
|
||||||
// Mark the test as async when an AsyncTestCompleter is injected in an it()
|
// 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()"');
|
if (!inIt) throw new Error('AsyncTestCompleter can only be injected in an "it()"');
|
||||||
return new AsyncTestCompleter();
|
return new AsyncTestCompleter();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
testInjector.addProviders([completerProvider]);
|
testInjector.addProviders([completerProvider]);
|
||||||
runner.run();
|
runner.run();
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,5 @@ class MyUrlResolver extends UrlResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(MyApp, [provide(UrlResolver, {useClass: MyUrlResolver})]);
|
bootstrap(MyApp, [{provide: UrlResolver, useClass: MyUrlResolver}]);
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {NG_VALIDATORS} from '@angular/common';
|
import {NG_VALIDATORS} from '@angular/common';
|
||||||
import {Provider} from '@angular/core';
|
|
||||||
|
|
||||||
let MyApp: Function = null;
|
let MyApp: Function = null;
|
||||||
let myValidator: any = null;
|
let myValidator: any = null;
|
||||||
|
|
||||||
// #docregion ng_validators
|
// #docregion ng_validators
|
||||||
bootstrap(MyApp, [new Provider(NG_VALIDATORS, {useValue: myValidator, multi: true})]);
|
bootstrap(MyApp, [{provide: NG_VALIDATORS, useValue: myValidator, multi: true}]);
|
||||||
// #enddocregion
|
// #enddocregion
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {provide, Component, ComponentRef} from '@angular/core';
|
import {Component, ComponentRef} from '@angular/core';
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {
|
import {
|
||||||
CanActivate,
|
CanActivate,
|
||||||
|
@ -53,5 +53,5 @@ export class AppCmp {
|
||||||
|
|
||||||
export function main(): Promise<ComponentRef<AppCmp>> {
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
||||||
return bootstrap(
|
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'}]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,5 +63,5 @@ export class AppCmp {
|
||||||
|
|
||||||
export function main(): Promise<ComponentRef<AppCmp>> {
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
||||||
return bootstrap(
|
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'}]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,5 @@ export class AppCmp {
|
||||||
|
|
||||||
export function main(): Promise<ComponentRef<AppCmp>> {
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
||||||
return bootstrap(
|
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'}]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {bootstrap} from '@angular/platform-browser';
|
||||||
import {
|
import {
|
||||||
OnDeactivate,
|
OnDeactivate,
|
||||||
|
@ -57,7 +57,7 @@ export class AppCmp {
|
||||||
|
|
||||||
export function main(): Promise<ComponentRef<AppCmp>> {
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
||||||
return bootstrap(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
|
LogService
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component, provide, ComponentRef} from '@angular/core';
|
import {Component, ComponentRef} from '@angular/core';
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {
|
import {
|
||||||
RouteConfig,
|
RouteConfig,
|
||||||
|
@ -53,5 +53,5 @@ export class AppCmp {
|
||||||
|
|
||||||
export function main(): Promise<ComponentRef<AppCmp>> {
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
||||||
return bootstrap(AppCmp,
|
return bootstrap(AppCmp,
|
||||||
[provide(APP_BASE_HREF, {useValue: '/@angular/examples/router/ts/reuse'})]);
|
[{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/reuse'}]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
beforeEachProviders,
|
beforeEachProviders,
|
||||||
inject
|
inject
|
||||||
} from '@angular/core/testing/testing_internal';
|
} from '@angular/core/testing/testing_internal';
|
||||||
import {provide} from '@angular/core';
|
|
||||||
|
|
||||||
var db: any;
|
var db: any;
|
||||||
class MyService {}
|
class MyService {}
|
||||||
|
@ -70,7 +69,7 @@ describe('some component', () => {
|
||||||
|
|
||||||
// #docregion beforeEachProviders
|
// #docregion beforeEachProviders
|
||||||
describe('some component', () => {
|
describe('some component', () => {
|
||||||
beforeEachProviders(() => [provide(MyService, {useClass: MyMockService})]);
|
beforeEachProviders(() => [{provide: MyService, useClass: MyMockService}]);
|
||||||
it('uses MyService', inject([MyService], (service: MyMockService) => {
|
it('uses MyService', inject([MyService], (service: MyMockService) => {
|
||||||
// service is an instance of MyMockService.
|
// service is an instance of MyMockService.
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -27,7 +27,7 @@ class _ArrayLogger {
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(MyApp, [provide(ExceptionHandler, {useClass: MyExceptionHandler})])
|
* bootstrap(MyApp, {provide: ExceptionHandler, useClass: MyExceptionHandler}])
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* @stable
|
* @stable
|
||||||
|
|
|
@ -110,7 +110,7 @@ export {URLSearchParams} from './src/url_search_params';
|
||||||
* search: string = 'coreTeam=true';
|
* 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));
|
* .catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
@ -130,7 +130,7 @@ export {URLSearchParams} from './src/url_search_params';
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* HTTP_PROVIDERS,
|
* HTTP_PROVIDERS,
|
||||||
* MockBackend,
|
* MockBackend,
|
||||||
* provide(XHRBackend, {useExisting: MockBackend})
|
* {provide: XHRBackend, useExisting: MockBackend}
|
||||||
* ]);
|
* ]);
|
||||||
* var http = injector.get(Http);
|
* var http = injector.get(Http);
|
||||||
* var backend = injector.get(MockBackend);
|
* var backend = injector.get(MockBackend);
|
||||||
|
@ -174,27 +174,26 @@ export {URLSearchParams} from './src/url_search_params';
|
||||||
*
|
*
|
||||||
* bootstrap(
|
* bootstrap(
|
||||||
* App,
|
* App,
|
||||||
* [HTTP_PROVIDERS, provide(XSRFStrategy,
|
* [HTTP_PROVIDERS, {provide: XSRFStrategy,
|
||||||
* {useValue: new CookieXSRFStrategy('MY-XSRF-COOKIE-NAME', 'X-MY-XSRF-HEADER-NAME')})])
|
* useValue: new CookieXSRFStrategy('MY-XSRF-COOKIE-NAME', 'X-MY-XSRF-HEADER-NAME')}])
|
||||||
* .catch(err => console.error(err));
|
* .catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const HTTP_PROVIDERS: any[] = [
|
export const HTTP_PROVIDERS: any[] = [
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
// TODO(pascal): use factory type annotations once supported in DI
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
// issue: https://github.com/angular/angular/issues/3183
|
||||||
provide(Http,
|
{ provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
||||||
{
|
|
||||||
useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) =>
|
|
||||||
new Http(xhrBackend, requestOptions),
|
|
||||||
deps: [XHRBackend, RequestOptions]
|
|
||||||
}),
|
|
||||||
BrowserXhr,
|
BrowserXhr,
|
||||||
provide(RequestOptions, {useClass: BaseRequestOptions}),
|
{provide: RequestOptions, useClass: BaseRequestOptions},
|
||||||
provide(ResponseOptions, {useClass: BaseResponseOptions}),
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||||
XHRBackend,
|
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.
|
* See {@link HTTP_PROVIDERS} instead.
|
||||||
*
|
*
|
||||||
|
@ -267,7 +266,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
|
||||||
* search: string = 'coreTeam=true';
|
* 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));
|
* .catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
@ -285,7 +284,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* JSONP_PROVIDERS,
|
* JSONP_PROVIDERS,
|
||||||
* MockBackend,
|
* MockBackend,
|
||||||
* provide(JSONPBackend, {useExisting: MockBackend})
|
* {provide: JSONPBackend, useExisting: MockBackend}
|
||||||
* ]);
|
* ]);
|
||||||
* var jsonp = injector.get(Jsonp);
|
* var jsonp = injector.get(Jsonp);
|
||||||
* var backend = injector.get(MockBackend);
|
* var backend = injector.get(MockBackend);
|
||||||
|
@ -312,18 +311,18 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
|
||||||
export const JSONP_PROVIDERS: any[] = [
|
export const JSONP_PROVIDERS: any[] = [
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
// TODO(pascal): use factory type annotations once supported in DI
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
// issue: https://github.com/angular/angular/issues/3183
|
||||||
provide(Jsonp,
|
{provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions]},
|
||||||
{
|
|
||||||
useFactory: (jsonpBackend: JSONPBackend, requestOptions: RequestOptions) =>
|
|
||||||
new Jsonp(jsonpBackend, requestOptions),
|
|
||||||
deps: [JSONPBackend, RequestOptions]
|
|
||||||
}),
|
|
||||||
BrowserJsonp,
|
BrowserJsonp,
|
||||||
provide(RequestOptions, {useClass: BaseRequestOptions}),
|
{provide: RequestOptions, useClass: BaseRequestOptions},
|
||||||
provide(ResponseOptions, {useClass: BaseResponseOptions}),
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||||
provide(JSONPBackend, {useClass: JSONPBackend_})
|
{provide: JSONPBackend, useClass: JSONPBackend_},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions) {
|
||||||
|
return new Jsonp(jsonpBackend, requestOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link JSONP_PROVIDERS} instead.
|
* See {@link JSONP_PROVIDERS} instead.
|
||||||
*
|
*
|
||||||
|
|
|
@ -171,9 +171,9 @@ export class CookieXSRFStrategy implements XSRFStrategy {
|
||||||
* @Component({
|
* @Component({
|
||||||
* viewProviders: [
|
* viewProviders: [
|
||||||
* HTTP_PROVIDERS,
|
* HTTP_PROVIDERS,
|
||||||
* provide(Http, {useFactory: (backend, options) => {
|
* {provide: Http, useFactory: (backend, options) => {
|
||||||
* return new Http(backend, options);
|
* return new Http(backend, options);
|
||||||
* }, deps: [MyNodeBackend, BaseRequestOptions]})]
|
* }, deps: [MyNodeBackend, BaseRequestOptions]}]
|
||||||
* })
|
* })
|
||||||
* class MyComponent {
|
* class MyComponent {
|
||||||
* constructor(http:Http) {
|
* constructor(http:Http) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ export class RequestOptions {
|
||||||
* search: string = 'coreTeam=true';
|
* 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}
|
* The options could also be extended when manually creating a {@link Request}
|
||||||
|
|
|
@ -125,7 +125,7 @@ export class ResponseOptions {
|
||||||
* headers:Headers = new Headers({network: 'github'});
|
* 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}
|
* The options could also be extended when manually creating a {@link Response}
|
||||||
|
|
|
@ -82,11 +82,11 @@ function mergeOptions(defaultOpts: BaseRequestOptions, providedOpts: RequestOpti
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* BaseRequestOptions,
|
* BaseRequestOptions,
|
||||||
* MockBackend,
|
* MockBackend,
|
||||||
* provide(Http, {useFactory:
|
* {provide: Http, useFactory:
|
||||||
* function(backend, defaultOptions) {
|
* function(backend, defaultOptions) {
|
||||||
* return new Http(backend, defaultOptions);
|
* return new Http(backend, defaultOptions);
|
||||||
* },
|
* },
|
||||||
* deps: [MockBackend, BaseRequestOptions]})
|
* deps: [MockBackend, BaseRequestOptions]}
|
||||||
* ]);
|
* ]);
|
||||||
* var http = injector.get(Http);
|
* var http = injector.get(Http);
|
||||||
* http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));
|
* http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));
|
||||||
|
|
|
@ -71,9 +71,9 @@ export function main() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
let injector = ReflectiveInjector.resolveAndCreate([
|
let injector = ReflectiveInjector.resolveAndCreate([
|
||||||
provide(ResponseOptions, {useClass: BaseResponseOptions}),
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||||
provide(BrowserJsonp, {useClass: MockBrowserJsonp}),
|
{provide: BrowserJsonp, useClass: MockBrowserJsonp},
|
||||||
provide(JSONPBackend, {useClass: JSONPBackend_})
|
{provide: JSONPBackend, useClass: JSONPBackend_}
|
||||||
]);
|
]);
|
||||||
backend = injector.get(JSONPBackend);
|
backend = injector.get(JSONPBackend);
|
||||||
let base = new BaseRequestOptions();
|
let base = new BaseRequestOptions();
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function main() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
var injector = ReflectiveInjector.resolveAndCreate(
|
var injector = ReflectiveInjector.resolveAndCreate(
|
||||||
[provide(ResponseOptions, {useClass: BaseResponseOptions}), MockBackend]);
|
[{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
|
||||||
backend = injector.get(MockBackend);
|
backend = injector.get(MockBackend);
|
||||||
var base = new BaseRequestOptions();
|
var base = new BaseRequestOptions();
|
||||||
sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
||||||
|
|
|
@ -94,9 +94,11 @@ export function main() {
|
||||||
|
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() =>
|
() =>
|
||||||
[provide(ResponseOptions, {useClass: BaseResponseOptions}),
|
[
|
||||||
provide(BrowserXhr, {useClass: MockBrowserXHR}), XHRBackend,
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||||
provide(XSRFStrategy, {useValue: new CookieXSRFStrategy()}),
|
{provide: BrowserXhr, useClass: MockBrowserXHR},
|
||||||
|
XHRBackend,
|
||||||
|
{provide: XSRFStrategy, useValue: new CookieXSRFStrategy()},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
|
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
|
||||||
|
@ -112,7 +114,7 @@ export function main() {
|
||||||
class NoopXsrfStrategy implements XSRFStrategy {
|
class NoopXsrfStrategy implements XSRFStrategy {
|
||||||
configureRequest(req: Request) {}
|
configureRequest(req: Request) {}
|
||||||
}
|
}
|
||||||
beforeEachProviders(() => [provide(XSRFStrategy, {useClass: NoopXsrfStrategy})]);
|
beforeEachProviders(() => [{provide: XSRFStrategy, useClass: NoopXsrfStrategy}]);
|
||||||
|
|
||||||
it('succeeds',
|
it('succeeds',
|
||||||
() => { expect(() => backend.createConnection(sampleRequest)).not.toThrow(); });
|
() => { expect(() => backend.createConnection(sampleRequest)).not.toThrow(); });
|
||||||
|
@ -135,8 +137,7 @@ export function main() {
|
||||||
|
|
||||||
describe('configuration', () => {
|
describe('configuration', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [provide(
|
() => [{provide: XSRFStrategy, useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')}]);
|
||||||
XSRFStrategy, {useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')})]);
|
|
||||||
|
|
||||||
it('uses the configured names', () => {
|
it('uses the configured names', () => {
|
||||||
getDOM().setCookie('my cookie', 'XSRF value');
|
getDOM().setCookie('my cookie', 'XSRF value');
|
||||||
|
|
|
@ -44,15 +44,15 @@ export function main() {
|
||||||
it('should allow using jsonpInjectables and httpInjectables in same injector',
|
it('should allow using jsonpInjectables and httpInjectables in same injector',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
parentInjector = ReflectiveInjector.resolveAndCreate([
|
parentInjector = ReflectiveInjector.resolveAndCreate([
|
||||||
provide(XHRBackend, {useClass: MockBackend}),
|
{provide: XHRBackend, useClass: MockBackend},
|
||||||
provide(JSONPBackend, {useClass: MockBackend})
|
{provide: JSONPBackend, useClass: MockBackend}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
childInjector = parentInjector.resolveAndCreateChild([
|
childInjector = parentInjector.resolveAndCreateChild([
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
JSONP_PROVIDERS,
|
JSONP_PROVIDERS,
|
||||||
provide(XHRBackend, {useClass: MockBackend}),
|
{provide: XHRBackend, useClass: MockBackend},
|
||||||
provide(JSONPBackend, {useClass: MockBackend})
|
{provide: JSONPBackend, useClass: MockBackend}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
http = childInjector.get(Http);
|
http = childInjector.get(Http);
|
||||||
|
@ -97,22 +97,20 @@ export function main() {
|
||||||
injector = ReflectiveInjector.resolveAndCreate([
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
BaseRequestOptions,
|
BaseRequestOptions,
|
||||||
MockBackend,
|
MockBackend,
|
||||||
provide(
|
{
|
||||||
Http,
|
provide: Http,
|
||||||
{
|
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
return new Http(backend, defaultOptions);
|
||||||
return new Http(backend, defaultOptions);
|
},
|
||||||
},
|
deps: [MockBackend, BaseRequestOptions]
|
||||||
deps: [MockBackend, BaseRequestOptions]
|
},
|
||||||
}),
|
{
|
||||||
provide(
|
provide: Jsonp,
|
||||||
Jsonp,
|
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||||
{
|
return new Jsonp(backend, defaultOptions);
|
||||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
},
|
||||||
return new Jsonp(backend, defaultOptions);
|
deps: [MockBackend, BaseRequestOptions]
|
||||||
},
|
}
|
||||||
deps: [MockBackend, BaseRequestOptions]
|
|
||||||
})
|
|
||||||
]);
|
]);
|
||||||
http = injector.get(Http);
|
http = injector.get(Http);
|
||||||
jsonp = injector.get(Jsonp);
|
jsonp = injector.get(Jsonp);
|
||||||
|
|
|
@ -81,7 +81,7 @@ export class MockConnection implements Connection {
|
||||||
* Emits the provided error object as an error to the {@link Response} {@link EventEmitter}
|
* Emits the provided error object as an error to the {@link Response} {@link EventEmitter}
|
||||||
* returned
|
* returned
|
||||||
* from {@link Http}.
|
* from {@link Http}.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
|
@ -90,7 +90,7 @@ export class MockConnection implements Connection {
|
||||||
* http.request('data.json').subscribe(res => res, err => console.log(err)));
|
* http.request('data.json').subscribe(res => res, err => console.log(err)));
|
||||||
* connection.mockError(new Error('error'));
|
* connection.mockError(new Error('error'));
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
mockError(err?: Error) {
|
mockError(err?: Error) {
|
||||||
// Matches XHR semantics
|
// Matches XHR semantics
|
||||||
|
@ -114,9 +114,9 @@ export class MockConnection implements Connection {
|
||||||
* var connection;
|
* var connection;
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* MockBackend,
|
* MockBackend,
|
||||||
* provide(Http, {useFactory: (backend, options) => {
|
* {provide: Http, useFactory: (backend, options) => {
|
||||||
* return new Http(backend, options);
|
* return new Http(backend, options);
|
||||||
* }, deps: [MockBackend, BaseRequestOptions]})]);
|
* }, deps: [MockBackend, BaseRequestOptions]}]);
|
||||||
* var http = injector.get(Http);
|
* var http = injector.get(Http);
|
||||||
* var backend = injector.get(MockBackend);
|
* var backend = injector.get(MockBackend);
|
||||||
* //Assign any newly-created connection to local variable
|
* //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 text; //this will be set from mock response
|
||||||
* var injector = Injector.resolveAndCreate([
|
* var injector = Injector.resolveAndCreate([
|
||||||
* MockBackend,
|
* MockBackend,
|
||||||
* provide(Http, {useFactory: (backend, options) => {
|
* {provide: Http, useFactory: (backend, options) => {
|
||||||
* return new Http(backend, options);
|
* return new Http(backend, options);
|
||||||
* }, deps: [MockBackend, BaseRequestOptions]})]);
|
* }, deps: [MockBackend, BaseRequestOptions]}]);
|
||||||
* var backend = injector.get(MockBackend);
|
* var backend = injector.get(MockBackend);
|
||||||
* var http = injector.get(Http);
|
* var http = injector.get(Http);
|
||||||
* backend.connections.subscribe(c => connection = c);
|
* backend.connections.subscribe(c => connection = c);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
DebugNode,
|
DebugNode,
|
||||||
getDebugNode,
|
getDebugNode,
|
||||||
Provider,
|
|
||||||
RootRenderer,
|
RootRenderer,
|
||||||
NgZone,
|
NgZone,
|
||||||
ApplicationRef
|
ApplicationRef
|
||||||
|
|
|
@ -8,15 +8,11 @@ import {WebWorkerPlatformLocation} from './platform_location';
|
||||||
*/
|
*/
|
||||||
export const WORKER_APP_LOCATION_PROVIDERS = [
|
export const WORKER_APP_LOCATION_PROVIDERS = [
|
||||||
{provide: PlatformLocation, useClass: WebWorkerPlatformLocation},
|
{provide: PlatformLocation, useClass: WebWorkerPlatformLocation},
|
||||||
{
|
{provide: APP_INITIALIZER, useFactory: appInitFnFactory, multi: true, deps: [PlatformLocation, NgZone]}
|
||||||
provide: APP_INITIALIZER,
|
|
||||||
useFactory: (platformLocation: WebWorkerPlatformLocation, zone: NgZone) => () =>
|
|
||||||
initWorkerLocation(platformLocation, zone),
|
|
||||||
multi: true,
|
|
||||||
deps: [PlatformLocation, NgZone]
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function initWorkerLocation(platformLocation: WebWorkerPlatformLocation, zone: NgZone): Promise<boolean> {
|
function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () => Promise<boolean> {
|
||||||
return zone.runGuarded(() => platformLocation.init());
|
return () => {
|
||||||
|
return zone.runGuarded(() => platformLocation.init());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,17 +102,8 @@ export const WORKER_RENDER_APPLICATION_PROVIDERS: Array<any /*Type | Provider |
|
||||||
Testability,
|
Testability,
|
||||||
EventManager,
|
EventManager,
|
||||||
WebWorkerInstance,
|
WebWorkerInstance,
|
||||||
{
|
{ provide: APP_INITIALIZER, useFactory: initWebWorkerAppFn, multi: true, deps: [Injector] },
|
||||||
provide: APP_INITIALIZER,
|
{ provide: MessageBus, useFactory: messageBusFactory, deps: [WebWorkerInstance] }
|
||||||
useFactory: (injector => () => initWebWorkerApplication(injector)),
|
|
||||||
multi: true,
|
|
||||||
deps: [Injector]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: MessageBus,
|
|
||||||
useFactory: (instance) => instance.bus,
|
|
||||||
deps: [WebWorkerInstance]
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export function initializeGenericWorkerRenderer(injector: Injector) {
|
export function initializeGenericWorkerRenderer(injector: Injector) {
|
||||||
|
@ -142,6 +133,10 @@ export function bootstrapRender(
|
||||||
return PromiseWrapper.resolve(app.get(ApplicationRef));
|
return PromiseWrapper.resolve(app.get(ApplicationRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function messageBusFactory(instance: WebWorkerInstance): MessageBus {
|
||||||
|
return instance.bus;
|
||||||
|
}
|
||||||
|
|
||||||
function initWebWorkerRenderPlatform(): void {
|
function initWebWorkerRenderPlatform(): void {
|
||||||
BrowserDomAdapter.makeCurrent();
|
BrowserDomAdapter.makeCurrent();
|
||||||
wtfInit();
|
wtfInit();
|
||||||
|
@ -163,19 +158,21 @@ function _document(): any {
|
||||||
return getDOM().defaultDoc();
|
return getDOM().defaultDoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initWebWorkerApplication(injector: Injector): void {
|
function initWebWorkerAppFn(injector: Injector): () => void {
|
||||||
var scriptUri: string;
|
return () => {
|
||||||
try {
|
var scriptUri: string;
|
||||||
scriptUri = injector.get(WORKER_SCRIPT);
|
try {
|
||||||
} catch (e) {
|
scriptUri = injector.get(WORKER_SCRIPT);
|
||||||
throw new BaseException(
|
} catch (e) {
|
||||||
"You must provide your WebWorker's initialization script with the WORKER_SCRIPT token");
|
throw new BaseException(
|
||||||
}
|
"You must provide your WebWorker's initialization script with the WORKER_SCRIPT token");
|
||||||
|
}
|
||||||
|
|
||||||
let instance = injector.get(WebWorkerInstance);
|
let instance = injector.get(WebWorkerInstance);
|
||||||
spawnWebWorker(scriptUri, instance);
|
spawnWebWorker(scriptUri, instance);
|
||||||
|
|
||||||
initializeGenericWorkerRenderer(injector);
|
initializeGenericWorkerRenderer(injector);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -113,7 +113,7 @@ export function main() {
|
||||||
getDOM().appendChild(el, lightDom);
|
getDOM().appendChild(el, lightDom);
|
||||||
getDOM().setText(lightDom, 'loading');
|
getDOM().setText(lightDom, 'loading');
|
||||||
testProviders =
|
testProviders =
|
||||||
[provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})];
|
[{provide: DOCUMENT, useValue: fakeDoc}, {provide: Console, useClass: DummyConsole}];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(disposePlatform);
|
afterEach(disposePlatform);
|
||||||
|
@ -123,7 +123,7 @@ export function main() {
|
||||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||||
expect(
|
expect(
|
||||||
() => bootstrap(HelloRootDirectiveIsNotCmp,
|
() => bootstrap(HelloRootDirectiveIsNotCmp,
|
||||||
[testProviders, provide(ExceptionHandler, {useValue: exceptionHandler})]))
|
[testProviders, {provide: ExceptionHandler, useValue: exceptionHandler}]))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
|
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
|
||||||
expect(logger.res.join("")).toContain("Could not compile");
|
expect(logger.res.join("")).toContain("Could not compile");
|
||||||
|
@ -134,7 +134,7 @@ export function main() {
|
||||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||||
|
|
||||||
var refPromise =
|
var refPromise =
|
||||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
|
||||||
PromiseWrapper.then(refPromise, null, (reason) => {
|
PromiseWrapper.then(refPromise, null, (reason) => {
|
||||||
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
|
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -150,7 +150,7 @@ export function main() {
|
||||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||||
|
|
||||||
var refPromise =
|
var refPromise =
|
||||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
|
||||||
PromiseWrapper.then(refPromise, null, (reason: any) => {
|
PromiseWrapper.then(refPromise, null, (reason: any) => {
|
||||||
expect(reason.message)
|
expect(reason.message)
|
||||||
.toContain('The selector "hello-app" did not match any elements');
|
.toContain('The selector "hello-app" did not match any elements');
|
||||||
|
@ -164,7 +164,7 @@ export function main() {
|
||||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||||
|
|
||||||
var refPromise =
|
var refPromise =
|
||||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
|
||||||
PromiseWrapper.then(refPromise, null, (reason) => {
|
PromiseWrapper.then(refPromise, null, (reason) => {
|
||||||
expect(logger.res.join(""))
|
expect(logger.res.join(""))
|
||||||
.toContain('The selector "hello-app" did not match any elements');
|
.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",
|
it("should make the provided bindings available to the application component",
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
var refPromise = bootstrap(
|
var refPromise = bootstrap(
|
||||||
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
|
HelloRootCmp3, [testProviders, {provide: "appBinding", useValue: "BoundValue"}]);
|
||||||
|
|
||||||
refPromise.then((ref) => {
|
refPromise.then((ref) => {
|
||||||
expect(ref.instance.appBinding).toEqual("BoundValue");
|
expect(ref.instance.appBinding).toEqual("BoundValue");
|
||||||
|
@ -246,16 +246,16 @@ export function main() {
|
||||||
it("should run platform initializers", inject([Log], (log: Log) => {
|
it("should run platform initializers", inject([Log], (log: Log) => {
|
||||||
let p = createPlatform(ReflectiveInjector.resolveAndCreate([
|
let p = createPlatform(ReflectiveInjector.resolveAndCreate([
|
||||||
BROWSER_PLATFORM_PROVIDERS,
|
BROWSER_PLATFORM_PROVIDERS,
|
||||||
provide(PLATFORM_INITIALIZER, {useValue: log.fn("platform_init1"), multi: true}),
|
{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_init2"), multi: true}
|
||||||
]));
|
]));
|
||||||
expect(log.result()).toEqual("platform_init1; platform_init2");
|
expect(log.result()).toEqual("platform_init1; platform_init2");
|
||||||
log.clear();
|
log.clear();
|
||||||
var a = ReflectiveInjector.resolveAndCreate(
|
var a = ReflectiveInjector.resolveAndCreate(
|
||||||
[
|
[
|
||||||
BROWSER_APP_PROVIDERS,
|
BROWSER_APP_PROVIDERS,
|
||||||
provide(APP_INITIALIZER, {useValue: log.fn("app_init1"), multi: true}),
|
{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_init2"), multi: true}
|
||||||
],
|
],
|
||||||
p.injector);
|
p.injector);
|
||||||
a.get(ApplicationRef);
|
a.get(ApplicationRef);
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SpyComponentRef extends SpyObject implements ComponentRef<dynamic> {
|
||||||
|
|
||||||
SpyComponentRef() {
|
SpyComponentRef() {
|
||||||
this.injector = ReflectiveInjector
|
this.injector = ReflectiveInjector
|
||||||
.resolveAndCreate([bind(ApplicationRef).toClass(SpyApplicationRef)]);
|
.resolveAndCreate([{provide: ApplicationRef, useClass: SpyApplicationRef}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class SpyComponentRef extends SpyObject {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.injector = ReflectiveInjector.resolveAndCreate(
|
this.injector = ReflectiveInjector.resolveAndCreate(
|
||||||
[provide(ApplicationRef, {useClass: SpyApplicationRef})]);
|
[{provide: ApplicationRef, useClass: SpyApplicationRef}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ export function main() {
|
||||||
|
|
||||||
describe('using the test injector with the inject helper', () => {
|
describe('using the test injector with the inject helper', () => {
|
||||||
describe('setting up Providers', () => {
|
describe('setting up Providers', () => {
|
||||||
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
|
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
|
||||||
|
|
||||||
it('provides a real XHR instance',
|
it('provides a real XHR instance',
|
||||||
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
|
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
|
||||||
|
|
|
@ -134,7 +134,7 @@ export function main() {
|
||||||
|
|
||||||
describe('using the test injector with the inject helper', () => {
|
describe('using the test injector with the inject helper', () => {
|
||||||
describe('setting up Providers', () => {
|
describe('setting up Providers', () => {
|
||||||
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
|
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
|
||||||
|
|
||||||
it('should use set up providers',
|
it('should use set up providers',
|
||||||
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
|
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
|
||||||
|
@ -185,12 +185,12 @@ export function main() {
|
||||||
|
|
||||||
describe('per test providers', () => {
|
describe('per test providers', () => {
|
||||||
it('should allow per test providers',
|
it('should allow per test providers',
|
||||||
withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
|
withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
|
||||||
.inject([FancyService],
|
.inject([FancyService],
|
||||||
(service) => { expect(service.value).toEqual('real value'); }));
|
(service) => { expect(service.value).toEqual('real value'); }));
|
||||||
|
|
||||||
it('should return value from inject', () => {
|
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) => {
|
.inject([FancyService], (service) => {
|
||||||
expect(service.value).toEqual('real value');
|
expect(service.value).toEqual('real value');
|
||||||
return 10;
|
return 10;
|
||||||
|
@ -265,7 +265,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('using beforeEachProviders', () => {
|
describe('using beforeEachProviders', () => {
|
||||||
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
|
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(
|
||||||
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
|
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', () => {
|
it('should fail when the injector has already been used', () => {
|
||||||
patchJasmineBeforeEach();
|
patchJasmineBeforeEach();
|
||||||
expect(() => {
|
expect(() => {
|
||||||
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
|
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
|
||||||
})
|
})
|
||||||
.toThrowError('beforeEachProviders was called after the injector had been used ' +
|
.toThrowError('beforeEachProviders was called after the injector had been used ' +
|
||||||
'in a beforeEach or it block. This invalidates the test injector');
|
'in a beforeEach or it block. This invalidates the test injector');
|
||||||
|
@ -364,7 +364,7 @@ export function main() {
|
||||||
it('should override a provider',
|
it('should override a provider',
|
||||||
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
|
|
||||||
tcb.overrideProviders(TestProvidersComp, [provide(FancyService, {useClass: MockFancyService})])
|
tcb.overrideProviders(TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
|
||||||
.createAsync(TestProvidersComp)
|
.createAsync(TestProvidersComp)
|
||||||
.then((componentFixture) => {
|
.then((componentFixture) => {
|
||||||
componentFixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
@ -378,7 +378,7 @@ export function main() {
|
||||||
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
|
|
||||||
tcb.overrideViewProviders(TestViewProvidersComp,
|
tcb.overrideViewProviders(TestViewProvidersComp,
|
||||||
[provide(FancyService, {useClass: MockFancyService})])
|
[{provide: FancyService, useClass: MockFancyService}])
|
||||||
.createAsync(TestViewProvidersComp)
|
.createAsync(TestViewProvidersComp)
|
||||||
.then((componentFixture) => {
|
.then((componentFixture) => {
|
||||||
componentFixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
|
|
@ -112,7 +112,7 @@ export function main() {
|
||||||
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
|
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
|
||||||
|
|
||||||
it("should buffer messages and wait for the zone to exit before sending",
|
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],
|
.inject([AsyncTestCompleter, NgZone],
|
||||||
(async, zone: MockNgZone) => {
|
(async, zone: MockNgZone) => {
|
||||||
bus = createConnectedMessageBus();
|
bus = createConnectedMessageBus();
|
||||||
|
|
|
@ -27,7 +27,7 @@ export function main() {
|
||||||
const RESULT = 20;
|
const RESULT = 20;
|
||||||
const ID = "methodId";
|
const ID = "methodId";
|
||||||
|
|
||||||
beforeEachProviders(() => [Serializer, provide(ON_WEB_WORKER, {useValue: true}), RenderStore]);
|
beforeEachProviders(() => [Serializer, {provide: ON_WEB_WORKER, useValue: true}, RenderStore]);
|
||||||
|
|
||||||
describe("UIMessageBroker", () => {
|
describe("UIMessageBroker", () => {
|
||||||
var messageBuses;
|
var messageBuses;
|
||||||
|
|
|
@ -86,9 +86,9 @@ export function main() {
|
||||||
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
|
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
|
||||||
testUiInjector.addProviders([
|
testUiInjector.addProviders([
|
||||||
Serializer,
|
Serializer,
|
||||||
provide(RenderStore, {useValue: uiRenderStore}),
|
{provide: RenderStore, useValue: uiRenderStore},
|
||||||
provide(DomRootRenderer, {useClass: DomRootRenderer_}),
|
{provide: DomRootRenderer, useClass: DomRootRenderer_},
|
||||||
provide(RootRenderer, {useExisting: DomRootRenderer})
|
{provide: RootRenderer, useExisting: DomRootRenderer}
|
||||||
]);
|
]);
|
||||||
uiInjector = testUiInjector.createInjector();
|
uiInjector = testUiInjector.createInjector();
|
||||||
var uiSerializer = uiInjector.get(Serializer);
|
var uiSerializer = uiInjector.get(Serializer);
|
||||||
|
@ -96,16 +96,16 @@ export function main() {
|
||||||
workerRenderStore = new RenderStore();
|
workerRenderStore = new RenderStore();
|
||||||
return [
|
return [
|
||||||
Serializer,
|
Serializer,
|
||||||
provide(CompilerConfig, {useValue: new CompilerConfig(true, true, false)}),
|
{provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
|
||||||
provide(RenderStore, {useValue: workerRenderStore}),
|
{provide: RenderStore, useValue: workerRenderStore},
|
||||||
provide(RootRenderer,
|
{
|
||||||
{
|
provide: RootRenderer,
|
||||||
useFactory: (workerSerializer) => {
|
useFactory: (workerSerializer) => {
|
||||||
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
|
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
|
||||||
uiRenderStore, workerRenderStore);
|
uiRenderStore, workerRenderStore);
|
||||||
},
|
},
|
||||||
deps: [Serializer]
|
deps: [Serializer]
|
||||||
})
|
}
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ export function main() {
|
||||||
return new CachedXHR();
|
return new CachedXHR();
|
||||||
}
|
}
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(UrlResolver, {useClass: TestUrlResolver}),
|
{provide: UrlResolver, useClass: TestUrlResolver},
|
||||||
provide(XHR, {useFactory: createCachedXHR})
|
{provide: XHR, useFactory: createCachedXHR}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
it('should throw exception if $templateCache is not found', () => {
|
it('should throw exception if $templateCache is not found', () => {
|
||||||
|
|
|
@ -31,7 +31,7 @@ export function runBenchmark(config) {
|
||||||
execute: config.work,
|
execute: config.work,
|
||||||
prepare: config.prepare,
|
prepare: config.prepare,
|
||||||
microMetrics: config.microMetrics,
|
microMetrics: config.microMetrics,
|
||||||
providers: [bind(Options.SAMPLE_DESCRIPTION).toValue(description)]
|
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: description }]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,9 +58,9 @@ export class RouterOutlet implements OnDestroy {
|
||||||
var childRouter = this._parentRouter.childRouter(componentType);
|
var childRouter = this._parentRouter.childRouter(componentType);
|
||||||
|
|
||||||
var providers = ReflectiveInjector.resolve([
|
var providers = ReflectiveInjector.resolve([
|
||||||
provide(RouteData, {useValue: nextInstruction.routeData}),
|
{provide: RouteData, useValue: nextInstruction.routeData},
|
||||||
provide(RouteParams, {useValue: new RouteParams(nextInstruction.params)}),
|
{provide: RouteParams, useValue: new RouteParams(nextInstruction.params)},
|
||||||
provide(routerMod.Router, {useValue: childRouter})
|
{provide: routerMod.Router, useValue: childRouter}
|
||||||
]);
|
]);
|
||||||
this._componentRef =
|
this._componentRef =
|
||||||
this._loader.loadNextToLocation(componentType, this._viewContainerRef, providers);
|
this._loader.loadNextToLocation(componentType, this._viewContainerRef, providers);
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
|
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
|
||||||
import {Provider} from '@angular/core';
|
|
||||||
import {BrowserPlatformLocation} from '@angular/platform-browser';
|
import {BrowserPlatformLocation} from '@angular/platform-browser';
|
||||||
import {PlatformLocation} from '@angular/common';
|
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))
|
* ### Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {ApplicationRef, Provider} from '@angular/core';
|
import {ApplicationRef} from '@angular/core';
|
||||||
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
|
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
|
||||||
import {Router, RootRouter} from './router';
|
import {Router, RootRouter} from './router';
|
||||||
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './route_registry';
|
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './route_registry';
|
||||||
|
|
|
@ -37,8 +37,8 @@ export function main() {
|
||||||
var tcb: TestComponentBuilder;
|
var tcb: TestComponentBuilder;
|
||||||
|
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(Location, {useValue: makeDummyLocation()}),
|
{provide: Location, useValue: makeDummyLocation()},
|
||||||
provide(Router, {useValue: makeDummyRouter()})
|
{provide: Router, useValue: makeDummyRouter()}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));
|
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));
|
||||||
|
|
|
@ -50,8 +50,8 @@ export function main() {
|
||||||
describe('router bootstrap', () => {
|
describe('router bootstrap', () => {
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
ROUTER_PROVIDERS,
|
ROUTER_PROVIDERS,
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
{provide: LocationStrategy, useClass: MockLocationStrategy},
|
||||||
provide(ApplicationRef, {useClass: MockApplicationRef})
|
{provide: ApplicationRef, useClass: MockApplicationRef}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// do not refactor out the `bootstrap` functionality. We still want to
|
// do not refactor out the `bootstrap` functionality. We still want to
|
||||||
|
@ -64,10 +64,10 @@ export function main() {
|
||||||
bootstrap(AppCmp,
|
bootstrap(AppCmp,
|
||||||
[
|
[
|
||||||
ROUTER_PROVIDERS,
|
ROUTER_PROVIDERS,
|
||||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp},
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
{provide: LocationStrategy, useClass: MockLocationStrategy},
|
||||||
provide(DOCUMENT, {useValue: fakeDoc}),
|
{provide: DOCUMENT, useValue: fakeDoc},
|
||||||
provide(Console, {useClass: DummyConsole})
|
{provide: Console, useClass: DummyConsole}
|
||||||
])
|
])
|
||||||
.then((applicationRef) => {
|
.then((applicationRef) => {
|
||||||
var router = applicationRef.instance.router;
|
var router = applicationRef.instance.router;
|
||||||
|
@ -80,7 +80,7 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('broken app', () => {
|
describe('broken app', () => {
|
||||||
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: BrokenAppCmp})]);
|
beforeEachProviders(() => [{provide: ROUTER_PRIMARY_COMPONENT, useValue: BrokenAppCmp}]);
|
||||||
|
|
||||||
it('should rethrow exceptions from component constructors',
|
it('should rethrow exceptions from component constructors',
|
||||||
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
||||||
|
@ -95,7 +95,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('back button app', () => {
|
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',
|
it('should change the url without pushing a new history state for back navigations',
|
||||||
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
||||||
|
@ -146,7 +146,7 @@ export function main() {
|
||||||
|
|
||||||
describe('hierarchical app', () => {
|
describe('hierarchical app', () => {
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
|
() => { return [{provide: ROUTER_PRIMARY_COMPONENT, useValue: HierarchyAppCmp}]; });
|
||||||
|
|
||||||
it('should bootstrap an app with a hierarchy',
|
it('should bootstrap an app with a hierarchy',
|
||||||
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
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
|
// TODO(btford): mock out level lower than LocationStrategy once that level exists
|
||||||
xdescribe('custom app base ref', () => {
|
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',
|
it('should bootstrap',
|
||||||
inject([AsyncTestCompleter, TestComponentBuilder],
|
inject([AsyncTestCompleter, TestComponentBuilder],
|
||||||
(async, tcb: TestComponentBuilder) => {
|
(async, tcb: TestComponentBuilder) => {
|
||||||
|
@ -191,7 +191,7 @@ export function main() {
|
||||||
|
|
||||||
describe('querystring params app', () => {
|
describe('querystring params app', () => {
|
||||||
beforeEachProviders(
|
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',
|
it('should recognize and return querystring params with the injected RouteParams',
|
||||||
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
||||||
|
@ -217,7 +217,7 @@ export function main() {
|
||||||
describe('activate event on outlet', () => {
|
describe('activate event on outlet', () => {
|
||||||
let tcb: TestComponentBuilder = null;
|
let tcb: TestComponentBuilder = null;
|
||||||
|
|
||||||
beforeEachProviders(() => [provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp})]);
|
beforeEachProviders(() => [{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp}]);
|
||||||
|
|
||||||
beforeEach(inject([TestComponentBuilder],
|
beforeEach(inject([TestComponentBuilder],
|
||||||
(testComponentBuilder) => { tcb = testComponentBuilder; }));
|
(testComponentBuilder) => { tcb = testComponentBuilder; }));
|
||||||
|
|
|
@ -48,9 +48,9 @@ export function main() {
|
||||||
|
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
RouteRegistry,
|
RouteRegistry,
|
||||||
provide(Location, {useClass: SpyLocation}),
|
{provide: Location, useClass: SpyLocation},
|
||||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: MyComp7}),
|
{provide: ROUTER_PRIMARY_COMPONENT, useValue: MyComp7},
|
||||||
provide(Router, {useClass: RootRouter}),
|
{provide: Router, useClass: RootRouter},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(inject([TestComponentBuilder, Router, Location],
|
beforeEach(inject([TestComponentBuilder, Router, Location],
|
||||||
|
|
|
@ -42,9 +42,9 @@ export function compile(
|
||||||
|
|
||||||
export var TEST_ROUTER_PROVIDERS: any[] = [
|
export var TEST_ROUTER_PROVIDERS: any[] = [
|
||||||
RouteRegistry,
|
RouteRegistry,
|
||||||
provide(Location, {useClass: SpyLocation}),
|
{provide: Location, useClass: SpyLocation},
|
||||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: RootCmp}),
|
{provide: ROUTER_PRIMARY_COMPONENT, useValue: RootCmp},
|
||||||
provide(Router, {useClass: RootRouter})
|
{provide: Router, useClass: RootRouter}
|
||||||
];
|
];
|
||||||
|
|
||||||
export function clickOnElement(anchorEl) {
|
export function clickOnElement(anchorEl) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ export function main() {
|
||||||
var locationStrategy: HashLocationStrategy;
|
var locationStrategy: HashLocationStrategy;
|
||||||
|
|
||||||
beforeEachProviders(
|
beforeEachProviders(
|
||||||
() => [HashLocationStrategy, provide(PlatformLocation, {useClass: SpyPlatformLocation})]);
|
() => [HashLocationStrategy, {provide: PlatformLocation, useClass: SpyPlatformLocation}]);
|
||||||
|
|
||||||
describe('without APP_BASE_HREF', () => {
|
describe('without APP_BASE_HREF', () => {
|
||||||
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
|
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
|
||||||
|
@ -61,7 +61,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with APP_BASE_HREF with neither leading nor trailing slash', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
@ -94,7 +94,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with APP_BASE_HREF with leading slash', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
@ -127,7 +127,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with APP_BASE_HREF with both leading and trailing slash', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function main() {
|
||||||
locationStrategy = new MockLocationStrategy();
|
locationStrategy = new MockLocationStrategy();
|
||||||
locationStrategy.internalBaseHref = baseHref;
|
locationStrategy.internalBaseHref = baseHref;
|
||||||
let injector = ReflectiveInjector.resolveAndCreate(
|
let injector = ReflectiveInjector.resolveAndCreate(
|
||||||
[Location, provide(LocationStrategy, {useValue: locationStrategy}), provider]);
|
[Location, {provide: LocationStrategy, useValue: locationStrategy}, provider]);
|
||||||
return location = injector.get(Location);
|
return location = injector.get(Location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function main() {
|
||||||
|
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
PathLocationStrategy,
|
PathLocationStrategy,
|
||||||
provide(PlatformLocation, {useFactory: makeSpyPlatformLocation})
|
{provide: PlatformLocation, useFactory: makeSpyPlatformLocation}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
it('should throw without a base element or APP_BASE_HREF', () => {
|
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', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
@ -100,7 +100,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with APP_BASE_HREF with leading slash', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
@ -133,7 +133,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with APP_BASE_HREF with both leading and trailing slash', () => {
|
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) => {
|
beforeEach(inject([PlatformLocation, PathLocationStrategy], (pl, ls) => {
|
||||||
platformLocation = pl;
|
platformLocation = pl;
|
||||||
|
|
|
@ -46,10 +46,10 @@ export function main() {
|
||||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||||
testBindings = [
|
testBindings = [
|
||||||
ROUTER_PROVIDERS,
|
ROUTER_PROVIDERS,
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
{provide: LocationStrategy, useClass: MockLocationStrategy},
|
||||||
provide(DOCUMENT, {useValue: fakeDoc}),
|
{provide: DOCUMENT, useValue: fakeDoc},
|
||||||
provide(ExceptionHandler, {useValue: exceptionHandler}),
|
{provide: ExceptionHandler, useValue: exceptionHandler},
|
||||||
provide(Console, {useClass: DummyConsole})
|
{provide: Console, useClass: DummyConsole}
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ export function main() {
|
||||||
|
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
RouteRegistry,
|
RouteRegistry,
|
||||||
provide(Location, {useClass: SpyLocation}),
|
{provide: Location, useClass: SpyLocation},
|
||||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
{provide: ROUTER_PRIMARY_COMPONENT, useValue: AppCmp},
|
||||||
provide(Router, {useClass: RootRouter})
|
{provide: Router, useClass: RootRouter}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@ class _ActivateSegments {
|
||||||
private activateNewSegments(outletMap: RouterOutletMap, curr: RouteSegment, prev: RouteSegment,
|
private activateNewSegments(outletMap: RouterOutletMap, curr: RouteSegment, prev: RouteSegment,
|
||||||
outlet: RouterOutlet): Object {
|
outlet: RouterOutlet): Object {
|
||||||
let resolved = ReflectiveInjector.resolve(
|
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);
|
let ref = outlet.activate(routeSegmentComponentFactory(curr), resolved, outletMap);
|
||||||
if (hasLifecycleHook("routerOnActivate", ref.instance)) {
|
if (hasLifecycleHook("routerOnActivate", ref.instance)) {
|
||||||
ref.instance.routerOnActivate(curr, prev, this.currTree, this.prevTree);
|
ref.instance.routerOnActivate(curr, prev, this.currTree, this.prevTree);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
|
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';
|
* import {Component} from '@angular/core';
|
||||||
|
|
|
@ -17,7 +17,7 @@ export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
|
||||||
deps: /*@ts2dart_const*/
|
deps: /*@ts2dart_const*/
|
||||||
[ApplicationRef, ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location],
|
[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,
|
function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver,
|
||||||
|
@ -32,3 +32,7 @@ function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver
|
||||||
app.registerDisposeListener(() => router.dispose());
|
app.registerDisposeListener(() => router.dispose());
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function routeSegmentFactory(router: Router): RouteSegment {
|
||||||
|
return router.routeTree.root;
|
||||||
|
}
|
||||||
|
|
|
@ -36,16 +36,16 @@ import {getDOM} from '../platform_browser_private';
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('navigation', () => {
|
describe('navigation', () => {
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(RouterUrlSerializer, {useClass: DefaultRouterUrlSerializer}),
|
{provide: RouterUrlSerializer, useClass: DefaultRouterUrlSerializer},
|
||||||
RouterOutletMap,
|
RouterOutletMap,
|
||||||
provide(Location, {useClass: SpyLocation}),
|
{provide: Location, useClass: SpyLocation},
|
||||||
provide(RouteSegment, {useFactory: (r) => r.routeTree.root, deps: [Router]}),
|
{provide: RouteSegment, useFactory: (r) => r.routeTree.root, deps: [Router]},
|
||||||
provide(Router,
|
{
|
||||||
{
|
provide: Router,
|
||||||
useFactory: (resolver, urlParser, outletMap, location) => new Router(
|
useFactory: (resolver, urlParser, outletMap, location) => new Router(
|
||||||
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
|
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
|
||||||
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
|
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
|
||||||
})
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
it('should update location when navigating',
|
it('should update location when navigating',
|
||||||
|
|
|
@ -32,16 +32,16 @@ import {SpyLocation, MockLocationStrategy} from '@angular/common/testing';
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('RouterLink', () => {
|
describe('RouterLink', () => {
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(RouterUrlSerializer, {useClass: DefaultRouterUrlSerializer}),
|
{provide: RouterUrlSerializer, useClass: DefaultRouterUrlSerializer},
|
||||||
RouterOutletMap,
|
RouterOutletMap,
|
||||||
provide(Location, {useClass: SpyLocation}),
|
{provide: Location, useClass: SpyLocation},
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
{provide: LocationStrategy, useClass: MockLocationStrategy},
|
||||||
provide(Router,
|
{
|
||||||
{
|
provide: Router,
|
||||||
useFactory: (resolver, urlParser, outletMap, location) => new Router(
|
useFactory: (resolver, urlParser, outletMap, location) => new Router(
|
||||||
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
|
"RootComponent", RootCmp, resolver, urlParser, outletMap, location),
|
||||||
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
|
deps: [ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location]
|
||||||
})
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
describe("routerLink=", () => {
|
describe("routerLink=", () => {
|
||||||
|
|
|
@ -39,7 +39,7 @@ export class DowngradeNg2ComponentAdapter {
|
||||||
|
|
||||||
bootstrapNg2() {
|
bootstrapNg2() {
|
||||||
var childInjector = ReflectiveInjector.resolveAndCreate(
|
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.contentInsertionPoint = document.createComment('ng1 insertion point');
|
||||||
|
|
||||||
this.componentRef =
|
this.componentRef =
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class UpgradeAdapter {
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private downgradedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
|
private downgradedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private providers: Array<Type | Provider | any[]> = [];
|
private providers: Array<Type | Provider | any[] | any> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows Angular v2 Component to be used from AngularJS v1.
|
* Allows Angular v2 Component to be used from AngularJS v1.
|
||||||
|
@ -295,9 +295,8 @@ export class UpgradeAdapter {
|
||||||
[
|
[
|
||||||
BROWSER_APP_PROVIDERS,
|
BROWSER_APP_PROVIDERS,
|
||||||
BROWSER_APP_COMPILER_PROVIDERS,
|
BROWSER_APP_COMPILER_PROVIDERS,
|
||||||
provide(NG1_INJECTOR, {useFactory: () => ng1Injector}),
|
{provide: NG1_INJECTOR, useFactory: () => ng1Injector},
|
||||||
provide(NG1_COMPILE,
|
{provide: NG1_COMPILE, useFactory: () => ng1Injector.get(NG1_COMPILE)},
|
||||||
{useFactory: () => ng1Injector.get(NG1_COMPILE)}),
|
|
||||||
this.providers
|
this.providers
|
||||||
],
|
],
|
||||||
platformRef.injector)
|
platformRef.injector)
|
||||||
|
@ -449,7 +448,7 @@ export class UpgradeAdapter {
|
||||||
* adapter.bootstrap(document.body, ['myExample']);
|
* 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.
|
* Allows AngularJS v1 service to be accessible from Angular v2.
|
||||||
|
@ -485,10 +484,11 @@ export class UpgradeAdapter {
|
||||||
*/
|
*/
|
||||||
public upgradeNg1Provider(name: string, options?: {asToken: any}) {
|
public upgradeNg1Provider(name: string, options?: {asToken: any}) {
|
||||||
var token = options && options.asToken || name;
|
var token = options && options.asToken || name;
|
||||||
this.providers.push(provide(token, {
|
this.providers.push({
|
||||||
|
provide: token,
|
||||||
useFactory: (ng1Injector: angular.IInjectorService) => ng1Injector.get(name),
|
useFactory: (ng1Injector: angular.IInjectorService) => ng1Injector.get(name),
|
||||||
deps: [NG1_INJECTOR]
|
deps: [NG1_INJECTOR]
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -756,7 +756,7 @@ export function main() {
|
||||||
it('should export ng2 instance to ng1', inject([AsyncTestCompleter], (async) => {
|
it('should export ng2 instance to ng1', inject([AsyncTestCompleter], (async) => {
|
||||||
var adapter = new UpgradeAdapter();
|
var adapter = new UpgradeAdapter();
|
||||||
var module = angular.module('myExample', []);
|
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));
|
module.factory('someToken', adapter.downgradeNg2Provider(SomeToken));
|
||||||
adapter.bootstrap(html('<div>'), ['myExample'])
|
adapter.bootstrap(html('<div>'), ['myExample'])
|
||||||
.ready((ref) => {
|
.ready((ref) => {
|
||||||
|
|
|
@ -10,9 +10,6 @@ import {
|
||||||
Component,
|
Component,
|
||||||
Directive,
|
Directive,
|
||||||
ViewContainerRef,
|
ViewContainerRef,
|
||||||
bind,
|
|
||||||
provide,
|
|
||||||
Provider,
|
|
||||||
ViewMetadata
|
ViewMetadata
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
@ -20,19 +17,19 @@ import {CompilerConfig, ViewResolver} from '@angular/compiler';
|
||||||
|
|
||||||
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util';
|
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util';
|
||||||
|
|
||||||
function _createBindings(): Provider[] {
|
function _createBindings(): any[] {
|
||||||
var multiplyTemplatesBy = getIntParameter('elements');
|
var multiplyTemplatesBy = getIntParameter('elements');
|
||||||
return [
|
return [
|
||||||
provide(ViewResolver,
|
{
|
||||||
{
|
provide: ViewResolver,
|
||||||
useFactory: () => new MultiplyViewResolver(
|
useFactory: () => new MultiplyViewResolver(
|
||||||
multiplyTemplatesBy,
|
multiplyTemplatesBy,
|
||||||
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
|
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
|
||||||
deps: []
|
deps: []
|
||||||
}),
|
},
|
||||||
// Use interpretative mode as Dart does not support JIT and
|
// Use interpretative mode as Dart does not support JIT and
|
||||||
// we want to be able to compare the numbers between JS and Dart
|
// 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)}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {reflector} from '@angular/core/src/reflection/reflection';
|
||||||
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
|
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
|
||||||
import {getIntParameter, bindAction, microBenchmark} from '@angular/testing/src/benchmark_util';
|
import {getIntParameter, bindAction, microBenchmark} from '@angular/testing/src/benchmark_util';
|
||||||
|
@ -27,7 +27,7 @@ export function main() {
|
||||||
.resolveAndCreateChild([])
|
.resolveAndCreateChild([])
|
||||||
.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);
|
var variousProvidersResolved = ReflectiveInjector.resolve(variousProviders);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
windowProfileEnd
|
windowProfileEnd
|
||||||
} from '@angular/testing/src/benchmark_util';
|
} from '@angular/testing/src/benchmark_util';
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
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 {NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from '@angular/common';
|
||||||
import {ApplicationRef} from '@angular/core/src/application_ref';
|
import {ApplicationRef} from '@angular/core/src/application_ref';
|
||||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||||
|
@ -24,9 +24,9 @@ export const LARGETABLE_COLS = 'LargetableComponent.cols';
|
||||||
|
|
||||||
function _createBindings() {
|
function _createBindings() {
|
||||||
return [
|
return [
|
||||||
provide(BENCHMARK_TYPE, {useValue: getStringParameter('benchmarkType')}),
|
{provide: BENCHMARK_TYPE, useValue: getStringParameter('benchmarkType')},
|
||||||
provide(LARGETABLE_ROWS, {useValue: getIntParameter('rows')}),
|
{provide: LARGETABLE_ROWS, useValue: getIntParameter('rows')},
|
||||||
provide(LARGETABLE_COLS, {useValue: getIntParameter('columns')})
|
{provide: LARGETABLE_COLS, {useValue: getIntParameter('columns')},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {NgIf} from '@angular/common';
|
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 {ApplicationRef} from '@angular/core/src/application_ref';
|
||||||
import {reflector} from '@angular/core/src/reflection/reflection';
|
import {reflector} from '@angular/core/src/reflection/reflection';
|
||||||
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
|
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
|
||||||
|
@ -15,7 +15,7 @@ import {
|
||||||
} from '@angular/testing/src/benchmark_util';
|
} from '@angular/testing/src/benchmark_util';
|
||||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||||
|
|
||||||
function createBindings(): Provider[] {
|
function createBindings(): any[] {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
Directive,
|
|
||||||
ViewContainerRef,
|
|
||||||
bind,
|
|
||||||
provide,
|
|
||||||
Provider,
|
|
||||||
enableProdMode
|
enableProdMode
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
|
@ -23,7 +18,7 @@ import {
|
||||||
} from '@angular/testing/src/benchmark_util';
|
} from '@angular/testing/src/benchmark_util';
|
||||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||||
|
|
||||||
function createProviders(): Provider[] {
|
function createProviders(): any[] {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {bind, provide} from '@angular/core/src/di';
|
import {bind} from '@angular/core/src/di';
|
||||||
import {Options} from './common';
|
import {Options} from './common';
|
||||||
|
|
||||||
export * from './common';
|
export * from './common';
|
||||||
|
@ -11,7 +11,7 @@ var fs = require('fs');
|
||||||
// find another way...
|
// find another way...
|
||||||
// Note: Can't do the `require` call in a facade as it can't be loaded into the browser
|
// 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.
|
// 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> {
|
function writeFile(filename, content): Promise<any> {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
|
@ -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';
|
import {DateWrapper} from '@angular/facade';
|
||||||
|
|
||||||
export class Options {
|
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
|
// TODO(tbosch): use static initializer when our transpiler supports it
|
||||||
static get SAMPLE_ID() { return _SAMPLE_ID; }
|
static get SAMPLE_ID() { return _SAMPLE_ID; }
|
||||||
// TODO(tbosch): use static initializer when our transpiler supports it
|
// 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 _CAPTURE_FRAMES = new OpaqueToken('Options.frameCapture');
|
||||||
|
|
||||||
var _DEFAULT_PROVIDERS = [
|
var _DEFAULT_PROVIDERS = [
|
||||||
bind(_DEFAULT_DESCRIPTION)
|
{provide: _DEFAULT_DESCRIPTION, useValue: {}},
|
||||||
.toValue({}),
|
{provide: _SAMPLE_DESCRIPTION, useValue: {}},
|
||||||
provide(_SAMPLE_DESCRIPTION, {useValue: {}}),
|
{provide: _FORCE_GC, useValue: false},
|
||||||
provide(_FORCE_GC, {useValue: false}),
|
{provide: _PREPARE, useValue: false},
|
||||||
provide(_PREPARE, {useValue: false}),
|
{provide: _MICRO_METRICS, useValue: {}},
|
||||||
provide(_MICRO_METRICS, {useValue: {}}),
|
{provide: _NOW, useValue: () => DateWrapper.now()},
|
||||||
provide(_NOW, {useValue: () => DateWrapper.now()}),
|
{provide: _RECEIVED_DATA, useValue: false},
|
||||||
provide(_RECEIVED_DATA, {useValue: false}),
|
{provide: _REQUEST_COUNT, useValue: false},
|
||||||
provide(_REQUEST_COUNT, {useValue: false}),
|
{provide: _CAPTURE_FRAMES, useValue: false}
|
||||||
provide(_CAPTURE_FRAMES, {useValue: false})
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import {bind, provide, Provider} from '@angular/core/src/di';
|
|
||||||
import {BaseException, WrappedException} from '@angular/facade';
|
import {BaseException, WrappedException} from '@angular/facade';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A metric is measures values
|
* A metric is measures values
|
||||||
*/
|
*/
|
||||||
export abstract class Metric {
|
export abstract class Metric {
|
||||||
static bindTo(delegateToken): Provider[] {
|
static bindTo(delegateToken): any[] {
|
||||||
return [bind(Metric).toFactory((delegate) => delegate, [delegateToken])];
|
return [{provide: Metric, useFactory: (delegate) => delegate, deps: [delegateToken]}];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 {StringMapWrapper} from '@angular/facade';
|
||||||
import {PromiseWrapper} from '@angular/facade';
|
import {PromiseWrapper} from '@angular/facade';
|
||||||
|
|
||||||
import {Metric} from '../metric';
|
import {Metric} from '../metric';
|
||||||
|
|
||||||
export class MultiMetric extends Metric {
|
export class MultiMetric extends Metric {
|
||||||
static createBindings(childTokens: any[]): Provider[] {
|
static createBindings(childTokens: any[]): any[] {
|
||||||
return [
|
return [
|
||||||
bind(_CHILDREN)
|
{
|
||||||
.toFactory((injector: Injector) => childTokens.map(token => injector.get(token)),
|
provide: _CHILDREN,
|
||||||
[Injector]),
|
useFactory:(injector: Injector) => childTokens.map(token => injector.get(token)),
|
||||||
bind(MultiMetric).toFactory(children => new MultiMetric(children), [_CHILDREN])
|
deps: [Injector]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: MultiMetric,
|
||||||
|
useFactory: children => new MultiMetric(children),
|
||||||
|
deps: [_CHILDREN]
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
} from '@angular/facade';
|
} from '@angular/facade';
|
||||||
import {BaseException, WrappedException} from '@angular/facade';
|
import {BaseException, WrappedException} from '@angular/facade';
|
||||||
import {ListWrapper, StringMapWrapper} 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 {WebDriverExtension, PerfLogFeatures} from '../web_driver_extension';
|
||||||
import {Metric} from '../metric';
|
import {Metric} from '../metric';
|
||||||
|
@ -20,7 +20,7 @@ import {Options} from '../common_options';
|
||||||
*/
|
*/
|
||||||
export class PerflogMetric extends Metric {
|
export class PerflogMetric extends Metric {
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// 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
|
// TODO(tbosch): use static values when our transpiler supports them
|
||||||
static get SET_TIMEOUT(): OpaqueToken { return _SET_TIMEOUT; }
|
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 _FRAME_TIME_SMOOTH_THRESHOLD = 17;
|
||||||
|
|
||||||
var _PROVIDERS = [
|
var _PROVIDERS = [
|
||||||
bind(PerflogMetric)
|
{
|
||||||
.toFactory(
|
provide: PerflogMetric,
|
||||||
(driverExtension, setTimeout, microMetrics, forceGc, captureFrames, receivedData,
|
useFactory:
|
||||||
requestCount) => new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc,
|
(driverExtension, setTimeout, microMetrics, forceGc, captureFrames, receivedData,
|
||||||
captureFrames, receivedData, requestCount),
|
requestCount) => new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc,
|
||||||
[
|
captureFrames, receivedData, requestCount),
|
||||||
WebDriverExtension,
|
deps: [
|
||||||
_SET_TIMEOUT,
|
WebDriverExtension,
|
||||||
Options.MICRO_METRICS,
|
_SET_TIMEOUT,
|
||||||
Options.FORCE_GC,
|
Options.MICRO_METRICS,
|
||||||
Options.CAPTURE_FRAMES,
|
Options.FORCE_GC,
|
||||||
Options.RECEIVED_DATA,
|
Options.CAPTURE_FRAMES,
|
||||||
Options.REQUEST_COUNT
|
Options.RECEIVED_DATA,
|
||||||
]),
|
Options.REQUEST_COUNT
|
||||||
provide(_SET_TIMEOUT, {useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)})
|
]
|
||||||
|
},
|
||||||
|
{provide: _SET_TIMEOUT, useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import {bind, provide, Provider} from '@angular/core/src/di';
|
|
||||||
import {BaseException, WrappedException} from '@angular/facade';
|
import {BaseException, WrappedException} from '@angular/facade';
|
||||||
import {MeasureValues} from './measure_values';
|
import {MeasureValues} from './measure_values';
|
||||||
|
|
||||||
|
@ -6,8 +5,8 @@ import {MeasureValues} from './measure_values';
|
||||||
* A reporter reports measure values and the valid sample.
|
* A reporter reports measure values and the valid sample.
|
||||||
*/
|
*/
|
||||||
export abstract class Reporter {
|
export abstract class Reporter {
|
||||||
static bindTo(delegateToken): Provider[] {
|
static bindTo(delegateToken): any[] {
|
||||||
return [bind(Reporter).toFactory((delegate) => delegate, [delegateToken])];
|
return [{provide: Reporter, useFactory: (delegate) => delegate, deps: [delegateToken]}];
|
||||||
}
|
}
|
||||||
|
|
||||||
reportMeasureValues(values: MeasureValues): Promise<any> { throw new BaseException('NYI'); }
|
reportMeasureValues(values: MeasureValues): Promise<any> { throw new BaseException('NYI'); }
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {print, isPresent, isBlank, NumberWrapper} from '@angular/facade';
|
||||||
import {StringMapWrapper, ListWrapper} from '@angular/facade';
|
import {StringMapWrapper, ListWrapper} from '@angular/facade';
|
||||||
import {PromiseWrapper} from '@angular/facade';
|
import {PromiseWrapper} from '@angular/facade';
|
||||||
import {Math} 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 {Statistic} from '../statistic';
|
||||||
import {Reporter} from '../reporter';
|
import {Reporter} from '../reporter';
|
||||||
|
@ -18,7 +18,7 @@ export class ConsoleReporter extends Reporter {
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// TODO(tbosch): use static values when our transpiler supports them
|
||||||
static get COLUMN_WIDTH(): OpaqueToken { return _COLUMN_WIDTH; }
|
static get COLUMN_WIDTH(): OpaqueToken { return _COLUMN_WIDTH; }
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// 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 = ' ') {
|
static _lpad(value, columnWidth, fill = ' ') {
|
||||||
|
@ -94,10 +94,12 @@ export class ConsoleReporter extends Reporter {
|
||||||
var _PRINT = new OpaqueToken('ConsoleReporter.print');
|
var _PRINT = new OpaqueToken('ConsoleReporter.print');
|
||||||
var _COLUMN_WIDTH = new OpaqueToken('ConsoleReporter.columnWidth');
|
var _COLUMN_WIDTH = new OpaqueToken('ConsoleReporter.columnWidth');
|
||||||
var _PROVIDERS = [
|
var _PROVIDERS = [
|
||||||
bind(ConsoleReporter)
|
{
|
||||||
.toFactory((columnWidth, sampleDescription, print) =>
|
provide: ConsoleReporter,
|
||||||
|
useFactory: (columnWidth, sampleDescription, print) =>
|
||||||
new ConsoleReporter(columnWidth, sampleDescription, print),
|
new ConsoleReporter(columnWidth, sampleDescription, print),
|
||||||
[_COLUMN_WIDTH, SampleDescription, _PRINT]),
|
deps: [_COLUMN_WIDTH, SampleDescription, _PRINT]
|
||||||
provide(_COLUMN_WIDTH, {useValue: 18}),
|
},
|
||||||
provide(_PRINT, {useValue: print})
|
{provide: _COLUMN_WIDTH, useValue: 18},
|
||||||
|
{provide: _PRINT, useValue: print}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {DateWrapper, isPresent, isBlank, Json} from '@angular/facade';
|
import {DateWrapper, isPresent, isBlank, Json} from '@angular/facade';
|
||||||
import {PromiseWrapper} 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 {Reporter} from '../reporter';
|
||||||
import {SampleDescription} from '../sample_description';
|
import {SampleDescription} from '../sample_description';
|
||||||
|
@ -15,7 +15,7 @@ export class JsonFileReporter extends Reporter {
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// TODO(tbosch): use static values when our transpiler supports them
|
||||||
static get PATH(): OpaqueToken { return _PATH; }
|
static get PATH(): OpaqueToken { return _PATH; }
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// TODO(tbosch): use static values when our transpiler supports them
|
||||||
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
|
static get PROVIDERS(): any[] { return _PROVIDERS; }
|
||||||
|
|
||||||
_writeFile: Function;
|
_writeFile: Function;
|
||||||
_path: string;
|
_path: string;
|
||||||
|
@ -48,9 +48,11 @@ export class JsonFileReporter extends Reporter {
|
||||||
|
|
||||||
var _PATH = new OpaqueToken('JsonFileReporter.path');
|
var _PATH = new OpaqueToken('JsonFileReporter.path');
|
||||||
var _PROVIDERS = [
|
var _PROVIDERS = [
|
||||||
bind(JsonFileReporter)
|
{
|
||||||
.toFactory((sampleDescription, path, writeFile, now) =>
|
provide: JsonFileReporter,
|
||||||
|
useFactory: (sampleDescription, path, writeFile, now) =>
|
||||||
new JsonFileReporter(sampleDescription, path, writeFile, now),
|
new JsonFileReporter(sampleDescription, path, writeFile, now),
|
||||||
[SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
|
deps: [SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]
|
||||||
provide(_PATH, {useValue: '.'})
|
},
|
||||||
|
{provide: _PATH, useValue: '.'}
|
||||||
];
|
];
|
||||||
|
|
|
@ -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 {PromiseWrapper} from '@angular/facade';
|
||||||
|
|
||||||
import {MeasureValues} from '../measure_values';
|
import {MeasureValues} from '../measure_values';
|
||||||
import {Reporter} from '../reporter';
|
import {Reporter} from '../reporter';
|
||||||
|
|
||||||
export class MultiReporter extends Reporter {
|
export class MultiReporter extends Reporter {
|
||||||
static createBindings(childTokens: any[]): Provider[] {
|
static createBindings(childTokens: any[]): any[] {
|
||||||
return [
|
return [
|
||||||
bind(_CHILDREN)
|
{
|
||||||
.toFactory((injector: Injector) => childTokens.map(token => injector.get(token)),
|
provide: _CHILDREN,
|
||||||
[Injector]),
|
useFactory: (injector: Injector) => childTokens.map(token => injector.get(token)),
|
||||||
bind(MultiReporter).toFactory(children => new MultiReporter(children), [_CHILDREN])
|
deps: [Injector],
|
||||||
|
},
|
||||||
|
{provide: MultiReporter, useFactory: children => new MultiReporter(children), deps: [_CHILDREN]}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {isPresent, isBlank} from '@angular/facade';
|
||||||
import {PromiseWrapper} 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.
|
* It provides defaults, creates the injector and calls the sampler.
|
||||||
*/
|
*/
|
||||||
export class Runner {
|
export class Runner {
|
||||||
private _defaultProviders: Provider[];
|
private _defaultProviders: any[];
|
||||||
constructor(defaultProviders: Provider[] = null) {
|
constructor(defaultProviders: any[] = null) {
|
||||||
if (isBlank(defaultProviders)) {
|
if (isBlank(defaultProviders)) {
|
||||||
defaultProviders = [];
|
defaultProviders = [];
|
||||||
}
|
}
|
||||||
|
@ -39,14 +39,14 @@ export class Runner {
|
||||||
var sampleProviders = [
|
var sampleProviders = [
|
||||||
_DEFAULT_PROVIDERS,
|
_DEFAULT_PROVIDERS,
|
||||||
this._defaultProviders,
|
this._defaultProviders,
|
||||||
bind(Options.SAMPLE_ID).toValue(id),
|
{provide: Options.SAMPLE_ID, useValue: id},
|
||||||
bind(Options.EXECUTE).toValue(execute)
|
{provide: Options.EXECUTE, useValue: execute}
|
||||||
];
|
];
|
||||||
if (isPresent(prepare)) {
|
if (isPresent(prepare)) {
|
||||||
sampleProviders.push(bind(Options.PREPARE).toValue(prepare));
|
sampleProviders.push({provide: Options.PREPARE, useValue: prepare});
|
||||||
}
|
}
|
||||||
if (isPresent(microMetrics)) {
|
if (isPresent(microMetrics)) {
|
||||||
sampleProviders.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
|
sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics});
|
||||||
}
|
}
|
||||||
if (isPresent(providers)) {
|
if (isPresent(providers)) {
|
||||||
sampleProviders.push(providers);
|
sampleProviders.push(providers);
|
||||||
|
@ -68,9 +68,9 @@ export class Runner {
|
||||||
// injectors are handled better.
|
// injectors are handled better.
|
||||||
var injector = ReflectiveInjector.resolveAndCreate([
|
var injector = ReflectiveInjector.resolveAndCreate([
|
||||||
sampleProviders,
|
sampleProviders,
|
||||||
bind(Options.CAPABILITIES).toValue(capabilities),
|
{provide: Options.CAPABILITIES, useValue: capabilities},
|
||||||
bind(Options.USER_AGENT).toValue(userAgent),
|
{provide: Options.USER_AGENT, useValue: userAgent},
|
||||||
provide(WebDriverAdapter, {useValue: adapter})
|
{provide: WebDriverAdapter, useValue: adapter}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var sampler = injector.get(Sampler);
|
var sampler = injector.get(Sampler);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {StringMapWrapper} from '@angular/facade';
|
import {StringMapWrapper} from '@angular/facade';
|
||||||
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
|
|
||||||
import {Validator} from './validator';
|
import {Validator} from './validator';
|
||||||
import {Metric} from './metric';
|
import {Metric} from './metric';
|
||||||
import {Options} from './common_options';
|
import {Options} from './common_options';
|
||||||
|
@ -9,7 +8,7 @@ import {Options} from './common_options';
|
||||||
*/
|
*/
|
||||||
export class SampleDescription {
|
export class SampleDescription {
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// 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};
|
description: {[key: string]: any};
|
||||||
|
|
||||||
constructor(public id: string, descriptions: Array<{[key: string]: any}>,
|
constructor(public id: string, descriptions: Array<{[key: string]: any}>,
|
||||||
|
@ -24,8 +23,9 @@ export class SampleDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
var _PROVIDERS = [
|
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,
|
new SampleDescription(id,
|
||||||
[
|
[
|
||||||
{'forceGc': forceGc, 'userAgent': userAgent},
|
{'forceGc': forceGc, 'userAgent': userAgent},
|
||||||
|
@ -34,13 +34,14 @@ var _PROVIDERS = [
|
||||||
userDesc
|
userDesc
|
||||||
],
|
],
|
||||||
metric.describe()),
|
metric.describe()),
|
||||||
[
|
deps: [
|
||||||
Metric,
|
Metric,
|
||||||
Options.SAMPLE_ID,
|
Options.SAMPLE_ID,
|
||||||
Options.FORCE_GC,
|
Options.FORCE_GC,
|
||||||
Options.USER_AGENT,
|
Options.USER_AGENT,
|
||||||
Validator,
|
Validator,
|
||||||
Options.DEFAULT_DESCRIPTION,
|
Options.DEFAULT_DESCRIPTION,
|
||||||
Options.SAMPLE_DESCRIPTION
|
Options.SAMPLE_DESCRIPTION
|
||||||
])
|
]
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {isPresent, isBlank, Date, DateWrapper} from '@angular/facade';
|
import {isPresent, isBlank, Date, DateWrapper} from '@angular/facade';
|
||||||
import {PromiseWrapper} from '@angular/facade';
|
import {PromiseWrapper} from '@angular/facade';
|
||||||
import {bind, provide, Provider, OpaqueToken} from '@angular/core/src/di';
|
|
||||||
|
|
||||||
import {Metric} from './metric';
|
import {Metric} from './metric';
|
||||||
import {Validator} from './validator';
|
import {Validator} from './validator';
|
||||||
|
@ -20,7 +19,7 @@ import {MeasureValues} from './measure_values';
|
||||||
*/
|
*/
|
||||||
export class Sampler {
|
export class Sampler {
|
||||||
// TODO(tbosch): use static values when our transpiler supports them
|
// TODO(tbosch): use static values when our transpiler supports them
|
||||||
static get PROVIDERS(): Provider[] { return _PROVIDERS; }
|
static get PROVIDERS(): any[] { return _PROVIDERS; }
|
||||||
|
|
||||||
_driver: WebDriverAdapter;
|
_driver: WebDriverAdapter;
|
||||||
_metric: Metric;
|
_metric: Metric;
|
||||||
|
@ -95,26 +94,28 @@ export class SampleState {
|
||||||
}
|
}
|
||||||
|
|
||||||
var _PROVIDERS = [
|
var _PROVIDERS = [
|
||||||
bind(Sampler)
|
{
|
||||||
.toFactory((driver, metric, reporter, validator, prepare, execute, now) => new Sampler({
|
provide: Sampler,
|
||||||
driver: driver,
|
useFactory: (driver, metric, reporter, validator, prepare, execute, now) => new Sampler({
|
||||||
reporter: reporter,
|
driver: driver,
|
||||||
validator: validator,
|
reporter: reporter,
|
||||||
metric: metric,
|
validator: validator,
|
||||||
// TODO(tbosch): DI right now does not support null/undefined objects
|
metric: metric,
|
||||||
// Mostly because the cache would have to be initialized with a
|
// TODO(tbosch): DI right now does not support null/undefined objects
|
||||||
// special null object, which is expensive.
|
// Mostly because the cache would have to be initialized with a
|
||||||
prepare: prepare !== false ? prepare : null,
|
// special null object, which is expensive.
|
||||||
execute: execute,
|
prepare: prepare !== false ? prepare : null,
|
||||||
now: now
|
execute: execute,
|
||||||
}),
|
now: now
|
||||||
[
|
}),
|
||||||
WebDriverAdapter,
|
deps: [
|
||||||
Metric,
|
WebDriverAdapter,
|
||||||
Reporter,
|
Metric,
|
||||||
Validator,
|
Reporter,
|
||||||
Options.PREPARE,
|
Validator,
|
||||||
Options.EXECUTE,
|
Options.PREPARE,
|
||||||
Options.NOW
|
Options.EXECUTE,
|
||||||
])
|
Options.NOW
|
||||||
|
]
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue