refactor(chore): Replace all 'bindings' with 'providers'

BREAKING CHANGE

Deprecated `bindings:` and `viewBindings:` are replaced with
`providers:` and `viewProviders:`

Closes #7687
This commit is contained in:
Vamsi Varikuti
2016-03-21 16:27:17 +05:30
committed by Misko Hevery
parent 49fb7ef421
commit 0795dd307b
36 changed files with 97 additions and 142 deletions

View File

@ -13,7 +13,7 @@ import {ValidatorFn, AsyncValidatorFn} from './directives/validators';
* ```typescript * ```typescript
* @Component({ * @Component({
* selector: 'my-app', * selector: 'my-app',
* viewBindings: [FORM_BINDINGS] * viewProviders: [FORM_BINDINGS]
* template: ` * template: `
* <form [ngFormModel]="loginForm"> * <form [ngFormModel]="loginForm">
* <p>Login <input ngControl="login"></p> * <p>Login <input ngControl="login"></p>

View File

@ -154,7 +154,7 @@ class MockFancyService extends FancyService {
@Component({ @Component({
selector: 'my-service-comp', selector: 'my-service-comp',
bindings: [FancyService], providers: [FancyService],
template: `injected value: {{fancyService.value}}` template: `injected value: {{fancyService.value}}`
}) })
class TestBindingsComp { class TestBindingsComp {

View File

@ -56,20 +56,6 @@ export class MockDirectiveResolver extends DirectiveResolver {
}); });
} }
/**
* @deprecated
*/
setBindingsOverride(type: Type, bindings: any[]): void {
this._providerOverrides.set(type, bindings);
}
/**
* @deprecated
*/
setViewBindingsOverride(type: Type, viewBindings: any[]): void {
this.viewProviderOverrides.set(type, viewBindings);
}
setProvidersOverride(type: Type, providers: any[]): void { setProvidersOverride(type: Type, providers: any[]): void {
this._providerOverrides.set(type, providers); this._providerOverrides.set(type, providers);
} }

View File

@ -344,9 +344,9 @@ export class TestComponentBuilder {
(to, from) => { mockViewResolver.overrideViewDirective(component, from, to); }); (to, from) => { mockViewResolver.overrideViewDirective(component, from, to); });
}); });
this._bindingsOverrides.forEach( this._bindingsOverrides.forEach(
(bindings, type) => mockDirectiveResolver.setBindingsOverride(type, bindings)); (bindings, type) => mockDirectiveResolver.setProvidersOverride(type, bindings));
this._viewBindingsOverrides.forEach( this._viewBindingsOverrides.forEach(
(bindings, type) => mockDirectiveResolver.setViewBindingsOverride(type, bindings)); (bindings, type) => mockDirectiveResolver.setViewProvidersOverride(type, bindings));
let promise: Promise<ComponentFactory<any>> = let promise: Promise<ComponentFactory<any>> =
this._injector.get(ComponentResolver).resolveComponent(rootComponentType); this._injector.get(ComponentResolver).resolveComponent(rootComponentType);

View File

@ -32,8 +32,6 @@ class Directive extends DirectiveMetadata {
@Deprecated('Use `outputs` or `@Output` instead') @Deprecated('Use `outputs` or `@Output` instead')
List<String> events, List<String> events,
Map<String, String> host, Map<String, String> host,
@Deprecated('Use `providers` instead')
List bindings,
List providers, List providers,
String exportAs, String exportAs,
Map<String, dynamic> queries}) Map<String, dynamic> queries})
@ -44,7 +42,6 @@ class Directive extends DirectiveMetadata {
properties: properties, properties: properties,
events: events, events: events,
host: host, host: host,
bindings: bindings,
providers: providers, providers: providers,
exportAs: exportAs, exportAs: exportAs,
queries: queries); queries: queries);
@ -63,14 +60,10 @@ class Component extends ComponentMetadata {
@Deprecated('Use `outputs` or `@Output` instead') @Deprecated('Use `outputs` or `@Output` instead')
List<String> events, List<String> events,
Map<String, String> host, Map<String, String> host,
@Deprecated('Use `providers` instead')
List bindings,
List providers, List providers,
String exportAs, String exportAs,
String moduleId, String moduleId,
Map<String, dynamic> queries, Map<String, dynamic> queries,
@Deprecated('Use `viewProviders` instead')
List viewBindings,
List viewProviders, List viewProviders,
ChangeDetectionStrategy changeDetection, ChangeDetectionStrategy changeDetection,
String templateUrl, String templateUrl,
@ -87,11 +80,9 @@ class Component extends ComponentMetadata {
properties: properties, properties: properties,
events: events, events: events,
host: host, host: host,
bindings: bindings,
providers: providers, providers: providers,
exportAs: exportAs, exportAs: exportAs,
moduleId: moduleId, moduleId: moduleId,
viewBindings: viewBindings,
viewProviders: viewProviders, viewProviders: viewProviders,
queries: queries, queries: queries,
changeDetection: changeDetection, changeDetection: changeDetection,

View File

@ -153,7 +153,6 @@ export interface DirectiveMetadataFactory {
properties?: string[], properties?: string[],
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
bindings?: any[],
providers?: any[], providers?: any[],
exportAs?: string, exportAs?: string,
queries?: {[key: string]: any} queries?: {[key: string]: any}
@ -165,7 +164,6 @@ export interface DirectiveMetadataFactory {
properties?: string[], properties?: string[],
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
bindings?: any[],
providers?: any[], providers?: any[],
exportAs?: string, exportAs?: string,
queries?: {[key: string]: any} queries?: {[key: string]: any}
@ -211,13 +209,10 @@ export interface ComponentMetadataFactory {
properties?: string[], properties?: string[],
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
/* @deprecated */
bindings?: any[],
providers?: any[], providers?: any[],
exportAs?: string, exportAs?: string,
moduleId?: string, moduleId?: string,
queries?: {[key: string]: any}, queries?: {[key: string]: any},
viewBindings?: any[],
viewProviders?: any[], viewProviders?: any[],
changeDetection?: ChangeDetectionStrategy, changeDetection?: ChangeDetectionStrategy,
templateUrl?: string, templateUrl?: string,
@ -235,14 +230,10 @@ export interface ComponentMetadataFactory {
properties?: string[], properties?: string[],
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
/* @deprecated */
bindings?: any[],
providers?: any[], providers?: any[],
exportAs?: string, exportAs?: string,
moduleId?: string, moduleId?: string,
queries?: {[key: string]: any}, queries?: {[key: string]: any},
/* @deprecated */
viewBindings?: any[],
viewProviders?: any[], viewProviders?: any[],
changeDetection?: ChangeDetectionStrategy, changeDetection?: ChangeDetectionStrategy,
templateUrl?: string, templateUrl?: string,

View File

@ -649,7 +649,7 @@ export class DirectiveMetadata extends InjectableMetadata {
* *
* @Directive({ * @Directive({
* selector: 'greet', * selector: 'greet',
* bindings: [ * providers: [
* Greeter * Greeter
* ] * ]
* }) * })
@ -663,13 +663,9 @@ export class DirectiveMetadata extends InjectableMetadata {
* ``` * ```
*/ */
get providers(): any[] { get providers(): any[] {
return isPresent(this._bindings) && this._bindings.length > 0 ? this._bindings : return this._providers;
this._providers;
} }
/** @deprecated */
get bindings(): any[] { return this.providers; }
private _providers: any[]; private _providers: any[];
private _bindings: any[];
/** /**
* Defines the name that can be used in the template to assign this directive to a variable. * Defines the name that can be used in the template to assign this directive to a variable.
@ -731,7 +727,7 @@ export class DirectiveMetadata extends InjectableMetadata {
*/ */
queries: {[key: string]: any}; queries: {[key: string]: any};
constructor({selector, inputs, outputs, properties, events, host, bindings, providers, exportAs, constructor({selector, inputs, outputs, properties, events, host, providers, exportAs,
queries}: { queries}: {
selector?: string, selector?: string,
inputs?: string[], inputs?: string[],
@ -740,7 +736,6 @@ export class DirectiveMetadata extends InjectableMetadata {
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
providers?: any[], providers?: any[],
/** @deprecated */ bindings?: any[],
exportAs?: string, exportAs?: string,
queries?: {[key: string]: any} queries?: {[key: string]: any}
} = {}) { } = {}) {
@ -754,7 +749,6 @@ export class DirectiveMetadata extends InjectableMetadata {
this.exportAs = exportAs; this.exportAs = exportAs;
this.queries = queries; this.queries = queries;
this._providers = providers; this._providers = providers;
this._bindings = bindings;
} }
} }
@ -836,12 +830,9 @@ export class ComponentMetadata extends DirectiveMetadata {
* ``` * ```
*/ */
get viewProviders(): any[] { get viewProviders(): any[] {
return isPresent(this._viewBindings) && this._viewBindings.length > 0 ? this._viewBindings : return this._viewProviders;
this._viewProviders;
} }
get viewBindings(): any[] { return this.viewProviders; }
private _viewProviders: any[]; private _viewProviders: any[];
private _viewBindings: any[];
/** /**
* The module id of the module that contains the component. * The module id of the module that contains the component.
@ -877,8 +868,8 @@ export class ComponentMetadata extends DirectiveMetadata {
encapsulation: ViewEncapsulation; encapsulation: ViewEncapsulation;
constructor({selector, inputs, outputs, properties, events, host, exportAs, moduleId, bindings, constructor({selector, inputs, outputs, properties, events, host, exportAs, moduleId,
providers, viewBindings, viewProviders, providers, viewProviders,
changeDetection = ChangeDetectionStrategy.Default, queries, templateUrl, template, changeDetection = ChangeDetectionStrategy.Default, queries, templateUrl, template,
styleUrls, styles, directives, pipes, encapsulation}: { styleUrls, styles, directives, pipes, encapsulation}: {
selector?: string, selector?: string,
@ -887,11 +878,9 @@ export class ComponentMetadata extends DirectiveMetadata {
properties?: string[], properties?: string[],
events?: string[], events?: string[],
host?: {[key: string]: string}, host?: {[key: string]: string},
/** @deprecated */ bindings?: any[],
providers?: any[], providers?: any[],
exportAs?: string, exportAs?: string,
moduleId?: string, moduleId?: string,
/** @deprecated */ viewBindings?: any[],
viewProviders?: any[], viewProviders?: any[],
queries?: {[key: string]: any}, queries?: {[key: string]: any},
changeDetection?: ChangeDetectionStrategy, changeDetection?: ChangeDetectionStrategy,
@ -911,14 +900,12 @@ export class ComponentMetadata extends DirectiveMetadata {
events: events, events: events,
host: host, host: host,
exportAs: exportAs, exportAs: exportAs,
bindings: bindings,
providers: providers, providers: providers,
queries: queries queries: queries
}); });
this.changeDetection = changeDetection; this.changeDetection = changeDetection;
this._viewProviders = viewProviders; this._viewProviders = viewProviders;
this._viewBindings = viewBindings;
this.templateUrl = templateUrl; this.templateUrl = templateUrl;
this.template = template; this.template = template;
this.styleUrls = styleUrls; this.styleUrls = styleUrls;

View File

@ -250,7 +250,7 @@ class OnChangeComponent implements OnChanges {
selector: 'component-with-observable-list', selector: 'component-with-observable-list',
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
inputs: const ['list'], inputs: const ['list'],
bindings: const [ providers: const [
const Binding(IterableDiffers, const Binding(IterableDiffers,
toValue: const IterableDiffers(const [ toValue: const IterableDiffers(const [
const ObservableListDiffFactory(), const ObservableListDiffFactory(),

View File

@ -214,7 +214,7 @@ To better understand the kinds of injections which are supported in Angular we h
### Injecting Services ### Injecting Services
Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `bindings` or `viewBindings` and then letting the directive ask for the configured service. Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `providers` or `viewProviders` and then letting the directive ask for the configured service.
This example illustrates how to inject `MyService` into `House` directive. This example illustrates how to inject `MyService` into `House` directive.
@ -225,7 +225,7 @@ class MyService {} | Assume a service which needs to be inject
| |
@Component({ | Assume a top level application component which @Component({ | Assume a top level application component which
selector: 'my-app', | configures the services to be injected. selector: 'my-app', | configures the services to be injected.
viewBindings: [MyService], | viewProviders: [MyService], |
templateUrl: 'my_app.html', | Assume we have a template that needs to be templateUrl: 'my_app.html', | Assume we have a template that needs to be
directives: [House] | configured with directives to be injected. directives: [House] | configured with directives to be injected.
}) | }) |
@ -351,7 +351,7 @@ class Dad {
@Component({ @Component({
selector: '[grandpa]', selector: '[grandpa]',
viewBindings: [], viewProviders: [],
templateUrl: 'grandpa.html', templateUrl: 'grandpa.html',
directives: [Dad] directives: [Dad]
}) })

View File

@ -24,7 +24,7 @@ var inj = Injector.resolveAndCreate([
var engine = inj.get(ENGINE_KEY); // no mapping var engine = inj.get(ENGINE_KEY); // no mapping
``` ```
Every key has an id, which we utilize to store bindings and instances. So Injector uses keys internally for performance reasons. Every key has an id, which we utilize to store providers and instances. So Injector uses keys internally for performance reasons.
### ProtoInjector and Injector ### ProtoInjector and Injector
@ -33,15 +33,15 @@ Often there is a need to create multiple instances of essentially the same injec
Doing the following would be very inefficient. Doing the following would be very inefficient.
``` ```
function createComponetInjector(parent, bindings: Binding[]) { function createComponetInjector(parent, providers: Binding[]) {
return parent.resolveAndCreateChild(bindings); return parent.resolveAndCreateChild(providers);
} }
``` ```
This would require us to resolve and store bindings for every single component instance. Instead, we want to resolve and store the bindings for every component type, and create a set of instances for every component. To enable that DI separates the meta information about injectables (Bindings and their dependencies), which are stored in `ProtoInjector`, and injectables themselves, which are stored in `Injector`. This would require us to resolve and store providers for every single component instance. Instead, we want to resolve and store the providers for every component type, and create a set of instances for every component. To enable that DI separates the meta information about injectables (providers and their dependencies), which are stored in `ProtoInjector`, and injectables themselves, which are stored in `Injector`.
``` ```
var proto = new ProtoInjector(bindings); // done once var proto = new ProtoInjector(providers); // done once
function createComponentInjector(parent, proto) { function createComponentInjector(parent, proto) {
return new Injector(proto, parent); return new Injector(proto, parent);
} }
@ -74,7 +74,7 @@ Imagine the following scenario:
Child1 Child2 Child1 Child2
``` ```
Here both Child1 and Child2 are children of ParentInjector. Child2 marks this relationship as host. ParentInjector might want to expose two different sets of bindings for its "regular" children and its "host" children. Bindings visible to "regular" children are called "public" and bindings visible to "host" children are called "private". This is an advanced use case used by Angular, where components can provide different sets of bindings for their children and their view. Here both Child1 and Child2 are children of ParentInjector. Child2 marks this relationship as host. ParentInjector might want to expose two different sets of providers for its "regular" children and its "host" children. providers visible to "regular" children are called "public" and providers visible to "host" children are called "private". This is an advanced use case used by Angular, where components can provide different sets of providers for their children and their view.
Let's look at this example. Let's look at this example.
@ -154,12 +154,12 @@ Now let's see how Angular 2 uses DI behind the scenes.
The right mental model is to think that every DOM element has an Injector. (In practice, only interesting elements containing directives will have an injector, but this is a performance optimization) The right mental model is to think that every DOM element has an Injector. (In practice, only interesting elements containing directives will have an injector, but this is a performance optimization)
There are two properties that can be used to configure DI: bindings and viewBindings. There are two properties that can be used to configure DI: providers and viewProviders.
- `bindings` affects the element and its children. - `providers` affects the element and its children.
- `viewBindings` affects the component's view. - `viewProviders` affects the component's view.
Every directive can declare injectables via `bindings`, but only components can declare `viewBindings`. Every directive can declare injectables via `providers`, but only components can declare `viewProviders`.
Let's look at a complex example that shows how the injector tree gets created. Let's look at a complex example that shows how the injector tree gets created.
@ -174,10 +174,10 @@ Both `MyComponent` and `MyDirective` are created on the same element.
``` ```
@Component({ @Component({
selector: 'my-component', selector: 'my-component',
bindings: [ providers: [
bind('componentService').toValue('Host_MyComponentService') bind('componentService').toValue('Host_MyComponentService')
], ],
viewBindings: [ viewProviders: [
bind('viewService').toValue('View_MyComponentService') bind('viewService').toValue('View_MyComponentService')
], ],
template: `<needs-view-service></needs-view-service>`, template: `<needs-view-service></needs-view-service>`,
@ -187,7 +187,7 @@ class MyComponent {}
@Directive({ @Directive({
selector: '[my-directive]', selector: '[my-directive]',
bindings: [ providers: [
bind('directiveService').toValue('MyDirectiveService') bind('directiveService').toValue('MyDirectiveService')
] ]
}) })
@ -231,5 +231,5 @@ Injector2 [ Injector3 [
] ] ] ]
``` ```
As you can see the component and its bindings can be seen by its children and its view. The view bindings can be seen only by the view. And the bindings of other directives can be seen only their children. As you can see the component and its providers can be seen by its children and its view. The view providers can be seen only by the view. And the providers of other directives can be seen only their children.

View File

@ -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,
bindings: [bind(Options.SAMPLE_DESCRIPTION).toValue(description)] providers: [bind(Options.SAMPLE_DESCRIPTION).toValue(description)]
}); });
}); });
}); });

View File

@ -34,7 +34,7 @@ describe('router', function () {
it('should bind the component to the current router', function() { it('should bind the component to the current router', function() {
var router; var router;
registerComponent('homeCmp', { registerComponent('homeCmp', {
bindings: { $router: '=' }, providers: { $router: '=' },
controller: function($scope, $element) { controller: function($scope, $element) {
this.$routerOnActivate = function() { this.$routerOnActivate = function() {
router = this.$router; router = this.$router;
@ -148,7 +148,7 @@ describe('router', function () {
it('should provide the root level router', function() { it('should provide the root level router', function() {
registerComponent('homeCmp', { registerComponent('homeCmp', {
template: 'Home ({{homeCmp.isAdmin}})', template: 'Home ({{homeCmp.isAdmin}})',
bindings: { providers: {
$router: '<' $router: '<'
} }
}); });
@ -175,8 +175,8 @@ describe('router', function () {
function registerComponent(name, options) { function registerComponent(name, options) {
var definition = { var definition = {
bindings: options.bindings, providers: options.providers,
controller: getController(options), controller: getController(options)
}; };
if (options.template) definition.template = options.template; if (options.template) definition.template = options.template;
if (options.templateUrl) definition.templateUrl = options.templateUrl; if (options.templateUrl) definition.templateUrl = options.templateUrl;

View File

@ -173,7 +173,7 @@ To collect these metrics, you need to execute `console.time('frameCapture')` and
In addition to that, one extra binding needs to be passed to benchpress in tests that want to collect these metrics: In addition to that, one extra binding needs to be passed to benchpress in tests that want to collect these metrics:
benchpress.sample(bindings: [bp.bind(bp.Options.CAPTURE_FRAMES).toValue(true)], ... ) benchpress.sample(providers: [bp.bind(bp.Options.CAPTURE_FRAMES).toValue(true)], ... )
# Requests Metrics # Requests Metrics
@ -182,9 +182,9 @@ Benchpress can also record the number of requests sent and count the received "e
- `receivedData`: number of bytes received since the last navigation start - `receivedData`: number of bytes received since the last navigation start
- `requestCount`: number of requests sent since the last navigation start - `requestCount`: number of requests sent since the last navigation start
To collect these metrics, you need the following corresponding extra bindings: To collect these metrics, you need the following corresponding extra providers:
benchpress.sample(bindings: [ benchpress.sample(providers: [
bp.bind(bp.Options.RECEIVED_DATA).toValue(true), bp.bind(bp.Options.RECEIVED_DATA).toValue(true),
bp.bind(bp.Options.REQUEST_COUNT).toValue(true) bp.bind(bp.Options.REQUEST_COUNT).toValue(true)
], ... ) ], ... )

View File

@ -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 BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { 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; }

View File

@ -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 BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
static _lpad(value, columnWidth, fill = ' ') { static _lpad(value, columnWidth, fill = ' ') {

View File

@ -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 BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
_writeFile: Function; _writeFile: Function;
_path: string; _path: string;

View File

@ -25,34 +25,34 @@ 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 _defaultBindings: Provider[]; private _defaultProviders: Provider[];
constructor(defaultBindings: Provider[] = null) { constructor(defaultProviders: Provider[] = null) {
if (isBlank(defaultBindings)) { if (isBlank(defaultProviders)) {
defaultBindings = []; defaultProviders = [];
} }
this._defaultBindings = defaultBindings; this._defaultProviders = defaultProviders;
} }
sample({id, execute, prepare, microMetrics, bindings}: sample({id, execute, prepare, microMetrics, providers}:
{id: string, execute?: any, prepare?: any, microMetrics?: any, bindings?: any}): {id: string, execute?: any, prepare?: any, microMetrics?: any, providers?: any}):
Promise<SampleState> { Promise<SampleState> {
var sampleBindings = [ var sampleProviders = [
_DEFAULT_PROVIDERS, _DEFAULT_PROVIDERS,
this._defaultBindings, this._defaultProviders,
bind(Options.SAMPLE_ID).toValue(id), bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute) bind(Options.EXECUTE).toValue(execute)
]; ];
if (isPresent(prepare)) { if (isPresent(prepare)) {
sampleBindings.push(bind(Options.PREPARE).toValue(prepare)); sampleProviders.push(bind(Options.PREPARE).toValue(prepare));
} }
if (isPresent(microMetrics)) { if (isPresent(microMetrics)) {
sampleBindings.push(bind(Options.MICRO_METRICS).toValue(microMetrics)); sampleProviders.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
} }
if (isPresent(bindings)) { if (isPresent(providers)) {
sampleBindings.push(bindings); sampleProviders.push(providers);
} }
var inj = ReflectiveInjector.resolveAndCreate(sampleBindings); var inj = ReflectiveInjector.resolveAndCreate(sampleProviders);
var adapter = inj.get(WebDriverAdapter); var adapter = inj.get(WebDriverAdapter);
return PromiseWrapper return PromiseWrapper
@ -67,7 +67,7 @@ export class Runner {
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child // TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better. // injectors are handled better.
var injector = ReflectiveInjector.resolveAndCreate([ var injector = ReflectiveInjector.resolveAndCreate([
sampleBindings, sampleProviders,
bind(Options.CAPABILITIES).toValue(capabilities), bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent), bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter}) provide(WebDriverAdapter, {useValue: adapter})
@ -81,15 +81,15 @@ export class Runner {
var _DEFAULT_PROVIDERS = [ var _DEFAULT_PROVIDERS = [
Options.DEFAULT_PROVIDERS, Options.DEFAULT_PROVIDERS,
Sampler.BINDINGS, Sampler.PROVIDERS,
ConsoleReporter.BINDINGS, ConsoleReporter.PROVIDERS,
RegressionSlopeValidator.BINDINGS, RegressionSlopeValidator.PROVIDERS,
SizeValidator.BINDINGS, SizeValidator.PROVIDERS,
ChromeDriverExtension.BINDINGS, ChromeDriverExtension.PROVIDERS,
FirefoxDriverExtension.BINDINGS, FirefoxDriverExtension.PROVIDERS,
IOsDriverExtension.BINDINGS, IOsDriverExtension.PROVIDERS,
PerflogMetric.BINDINGS, PerflogMetric.PROVIDERS,
SampleDescription.BINDINGS, SampleDescription.PROVIDERS,
MultiReporter.createBindings([ConsoleReporter]), MultiReporter.createBindings([ConsoleReporter]),
MultiMetric.createBindings([PerflogMetric]), MultiMetric.createBindings([PerflogMetric]),

View File

@ -9,7 +9,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 BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { 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}>,

View File

@ -20,7 +20,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 BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
_driver: WebDriverAdapter; _driver: WebDriverAdapter;
_metric: Metric; _metric: Metric;

View File

@ -15,7 +15,7 @@ export class RegressionSlopeValidator extends Validator {
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get METRIC(): OpaqueToken { return _METRIC; } static get METRIC(): OpaqueToken { return _METRIC; }
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
_sampleSize: number; _sampleSize: number;
_metric: string; _metric: string;

View File

@ -9,7 +9,7 @@ import {MeasureValues} from '../measure_values';
*/ */
export class SizeValidator extends Validator { export class SizeValidator extends Validator {
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get SAMPLE_SIZE() { return _SAMPLE_SIZE; } static get SAMPLE_SIZE() { return _SAMPLE_SIZE; }

View File

@ -23,7 +23,7 @@ import {Options} from '../common_options';
*/ */
export class ChromeDriverExtension extends WebDriverExtension { export class ChromeDriverExtension extends WebDriverExtension {
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
private _majorChromeVersion: number; private _majorChromeVersion: number;

View File

@ -4,7 +4,7 @@ import {WebDriverExtension, PerfLogFeatures} from '../web_driver_extension';
import {WebDriverAdapter} from '../web_driver_adapter'; import {WebDriverAdapter} from '../web_driver_adapter';
export class FirefoxDriverExtension extends WebDriverExtension { export class FirefoxDriverExtension extends WebDriverExtension {
static get BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
private _profilerStarted: boolean; private _profilerStarted: boolean;

View File

@ -7,7 +7,7 @@ import {WebDriverAdapter} from '../web_driver_adapter';
export class IOsDriverExtension extends WebDriverExtension { export class IOsDriverExtension extends WebDriverExtension {
// TODO(tbosch): use static values when our transpiler supports them // TODO(tbosch): use static values when our transpiler supports them
static get BINDINGS(): Provider[] { return _PROVIDERS; } static get PROVIDERS(): Provider[] { return _PROVIDERS; }
constructor(private _driver: WebDriverAdapter) { super(); } constructor(private _driver: WebDriverAdapter) { super(); }

View File

@ -25,7 +25,7 @@ describe('deep tree baseline', function() {
id: 'baseline', id: 'baseline',
execute: function() { $('button') execute: function() { $('button')
.click(); }, .click(); },
bindings: [benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue({depth: 9})] providers: [benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue({depth: 9})]
}) })
.then(done, done.fail); .then(done, done.fail);
}); });

View File

@ -48,9 +48,9 @@ export function main() {
if (isBlank(microMetrics)) { if (isBlank(microMetrics)) {
microMetrics = StringMapWrapper.create(); microMetrics = StringMapWrapper.create();
} }
var bindings = [ var providers = [
Options.DEFAULT_PROVIDERS, Options.DEFAULT_PROVIDERS,
PerflogMetric.BINDINGS, PerflogMetric.PROVIDERS,
bind(Options.MICRO_METRICS).toValue(microMetrics), bind(Options.MICRO_METRICS).toValue(microMetrics),
bind(PerflogMetric.SET_TIMEOUT) bind(PerflogMetric.SET_TIMEOUT)
.toValue((fn, millis) => { .toValue((fn, millis) => {
@ -61,18 +61,18 @@ export function main() {
.toValue(new MockDriverExtension(perfLogs, commandLog, perfLogFeatures)) .toValue(new MockDriverExtension(perfLogs, commandLog, perfLogFeatures))
]; ];
if (isPresent(forceGc)) { if (isPresent(forceGc)) {
bindings.push(bind(Options.FORCE_GC).toValue(forceGc)); providers.push(bind(Options.FORCE_GC).toValue(forceGc));
} }
if (isPresent(captureFrames)) { if (isPresent(captureFrames)) {
bindings.push(bind(Options.CAPTURE_FRAMES).toValue(captureFrames)); providers.push(bind(Options.CAPTURE_FRAMES).toValue(captureFrames));
} }
if (isPresent(receivedData)) { if (isPresent(receivedData)) {
bindings.push(bind(Options.RECEIVED_DATA).toValue(receivedData)); providers.push(bind(Options.RECEIVED_DATA).toValue(receivedData));
} }
if (isPresent(requestCount)) { if (isPresent(requestCount)) {
bindings.push(bind(Options.REQUEST_COUNT).toValue(requestCount)); providers.push(bind(Options.REQUEST_COUNT).toValue(requestCount));
} }
return ReflectiveInjector.resolveAndCreate(bindings).get(PerflogMetric); return ReflectiveInjector.resolveAndCreate(providers).get(PerflogMetric);
} }
describe('perflog metric', () => { describe('perflog metric', () => {

View File

@ -37,7 +37,7 @@ export function main() {
sampleId = 'null'; sampleId = 'null';
} }
var bindings = [ var bindings = [
ConsoleReporter.BINDINGS, ConsoleReporter.PROVIDERS,
provide(SampleDescription, provide(SampleDescription,
{useValue: new SampleDescription(sampleId, descriptions, metrics)}), {useValue: new SampleDescription(sampleId, descriptions, metrics)}),
bind(ConsoleReporter.PRINT).toValue((line) => log.push(line)) bind(ConsoleReporter.PRINT).toValue((line) => log.push(line))

View File

@ -32,7 +32,7 @@ export function main() {
function createReporter({sampleId, descriptions, metrics, path}) { function createReporter({sampleId, descriptions, metrics, path}) {
var bindings = [ var bindings = [
JsonFileReporter.BINDINGS, JsonFileReporter.PROVIDERS,
provide(SampleDescription, provide(SampleDescription,
{useValue: new SampleDescription(sampleId, descriptions, metrics)}), {useValue: new SampleDescription(sampleId, descriptions, metrics)}),
bind(JsonFileReporter.PATH).toValue(path), bind(JsonFileReporter.PATH).toValue(path),

View File

@ -63,7 +63,7 @@ export function main() {
it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => { it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => {
createRunner([bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})]) createRunner([bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})])
.sample({id: 'someId', bindings: [bind(Options.SAMPLE_DESCRIPTION).toValue({'b': 2})]}) .sample({id: 'someId', providers: [bind(Options.SAMPLE_DESCRIPTION).toValue({'b': 2})]})
.then((_) => injector.get(SampleDescription)) .then((_) => injector.get(SampleDescription))
.then((desc) => { .then((desc) => {
expect(desc.description) expect(desc.description)
@ -121,7 +121,7 @@ export function main() {
]) ])
.sample({ .sample({
id: 'someId', id: 'someId',
bindings: [ providers: [
bind(Options.DEFAULT_DESCRIPTION) bind(Options.DEFAULT_DESCRIPTION)
.toValue({'a': 2}), .toValue({'a': 2}),
] ]

View File

@ -51,9 +51,9 @@ export function main() {
if (isBlank(driver)) { if (isBlank(driver)) {
driver = new MockDriverAdapter([]); driver = new MockDriverAdapter([]);
} }
var bindings = [ var providers = [
Options.DEFAULT_PROVIDERS, Options.DEFAULT_PROVIDERS,
Sampler.BINDINGS, Sampler.PROVIDERS,
provide(Metric, {useValue: metric}), provide(Metric, {useValue: metric}),
provide(Reporter, {useValue: reporter}), provide(Reporter, {useValue: reporter}),
provide(WebDriverAdapter, {useValue: driver}), provide(WebDriverAdapter, {useValue: driver}),
@ -62,10 +62,10 @@ export function main() {
bind(Options.NOW).toValue(() => DateWrapper.fromMillis(time++)) bind(Options.NOW).toValue(() => DateWrapper.fromMillis(time++))
]; ];
if (isPresent(prepare)) { if (isPresent(prepare)) {
bindings.push(bind(Options.PREPARE).toValue(prepare)); providers.push(bind(Options.PREPARE).toValue(prepare));
} }
sampler = ReflectiveInjector.resolveAndCreate(bindings).get(Sampler); sampler = ReflectiveInjector.resolveAndCreate(providers).get(Sampler);
} }
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor',

View File

@ -26,9 +26,9 @@ export function main() {
function createValidator({size, metric}) { function createValidator({size, metric}) {
validator = ReflectiveInjector.resolveAndCreate([ validator = ReflectiveInjector.resolveAndCreate([
RegressionSlopeValidator.BINDINGS, RegressionSlopeValidator.PROVIDERS,
bind(RegressionSlopeValidator.METRIC).toValue(metric), provide(RegressionSlopeValidator.METRIC).toValue(metric),
bind(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size) provide(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size)
]) ])
.get(RegressionSlopeValidator); .get(RegressionSlopeValidator);
} }

View File

@ -26,8 +26,8 @@ export function main() {
function createValidator(size) { function createValidator(size) {
validator = ReflectiveInjector.resolveAndCreate([ validator = ReflectiveInjector.resolveAndCreate([
SizeValidator.BINDINGS, SizeValidator.PROVIDERS,
bind(SizeValidator.SAMPLE_SIZE).toValue(size) provide(SizeValidator.SAMPLE_SIZE).toValue(size)
]) ])
.get(SizeValidator); .get(SizeValidator);
} }

View File

@ -59,10 +59,10 @@ export function main() {
log = []; log = [];
extension = extension =
ReflectiveInjector.resolveAndCreate([ ReflectiveInjector.resolveAndCreate([
ChromeDriverExtension.BINDINGS, ChromeDriverExtension.PROVIDERS,
bind(WebDriverAdapter) provide(WebDriverAdapter)
.toValue(new MockDriverAdapter(log, perfRecords, messageMethod)), .toValue(new MockDriverAdapter(log, perfRecords, messageMethod)),
bind(Options.USER_AGENT).toValue(userAgent) provide(Options.USER_AGENT).toValue(userAgent)
]) ])
.get(ChromeDriverExtension); .get(ChromeDriverExtension);
return extension; return extension;

View File

@ -38,7 +38,7 @@ export function main() {
} }
log = []; log = [];
extension = ReflectiveInjector.resolveAndCreate([ extension = ReflectiveInjector.resolveAndCreate([
IOsDriverExtension.BINDINGS, IOsDriverExtension.PROVIDERS,
provide(WebDriverAdapter, provide(WebDriverAdapter,
{useValue: new MockDriverAdapter(log, perfRecords)}) {useValue: new MockDriverAdapter(log, perfRecords)})
]) ])

View File

@ -179,7 +179,7 @@ class PersonsComponent {
@Component({ @Component({
selector: 'person-management-app', selector: 'person-management-app',
viewBindings: [DataService], viewProviders: [DataService],
template: ` template: `
<button (click)="switchToEditName()">Edit Full Name</button> <button (click)="switchToEditName()">Edit Full Name</button>
<button (click)="switchToPersonList()">Person Array</button> <button (click)="switchToPersonList()">Person Array</button>

View File

@ -225,7 +225,7 @@ exports.createBenchpressRunner = function(options) {
benchpress.bind(benchpress.Options.FORCE_GC).toValue(argv['force-gc']), benchpress.bind(benchpress.Options.FORCE_GC).toValue(argv['force-gc']),
benchpress.bind(benchpress.Options.DEFAULT_DESCRIPTION) benchpress.bind(benchpress.Options.DEFAULT_DESCRIPTION)
.toValue({'lang': options.lang, 'runId': runId}), .toValue({'lang': options.lang, 'runId': runId}),
benchpress.JsonFileReporter.BINDINGS, benchpress.JsonFileReporter.PROVIDERS,
benchpress.bind(benchpress.JsonFileReporter.PATH).toValue(resultsFolder) benchpress.bind(benchpress.JsonFileReporter.PATH).toValue(resultsFolder)
]; ];
if (!argv['dryrun']) { if (!argv['dryrun']) {