refactor(di): unified di injector and core injector
BREAKING CHANGES: * InjectAsync and InjectLazy have been removed * toAsyncFactory has been removed
This commit is contained in:
@ -8,10 +8,10 @@ export class MultiMetric extends Metric {
|
||||
static createBindings(childTokens): List<Binding> {
|
||||
return [
|
||||
bind(_CHILDREN)
|
||||
.toAsyncFactory((injector) => PromiseWrapper.all(
|
||||
ListWrapper.map(childTokens, (token) => injector.asyncGet(token))),
|
||||
[Injector]),
|
||||
bind(MultiMetric).toFactory((children) => new MultiMetric(children), [_CHILDREN])
|
||||
.toFactory(
|
||||
(injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)),
|
||||
[Injector]),
|
||||
bind(MultiMetric).toFactory(children => new MultiMetric(children), [_CHILDREN])
|
||||
];
|
||||
}
|
||||
|
||||
@ -52,4 +52,4 @@ function mergeStringMaps(maps): Object {
|
||||
return result;
|
||||
}
|
||||
|
||||
var _CHILDREN = new OpaqueToken('MultiMetric.children');
|
||||
var _CHILDREN = new OpaqueToken('MultiMetric.children');
|
@ -9,10 +9,10 @@ export class MultiReporter extends Reporter {
|
||||
static createBindings(childTokens: List<any>): List<Binding> {
|
||||
return [
|
||||
bind(_CHILDREN)
|
||||
.toAsyncFactory((injector) => PromiseWrapper.all(
|
||||
ListWrapper.map(childTokens, (token) => injector.asyncGet(token))),
|
||||
[Injector]),
|
||||
bind(MultiReporter).toFactory((children) => new MultiReporter(children), [_CHILDREN])
|
||||
.toFactory(
|
||||
(injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)),
|
||||
[Injector]),
|
||||
bind(MultiReporter).toFactory(children => new MultiReporter(children), [_CHILDREN])
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Injector, bind, Binding} from 'angular2/di';
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {Promise} from 'angular2/src/facade/async';
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
import {Sampler, SampleState} from './sampler';
|
||||
import {ConsoleReporter} from './reporter/console_reporter';
|
||||
@ -50,9 +50,31 @@ export class Runner {
|
||||
if (isPresent(bindings)) {
|
||||
sampleBindings.push(bindings);
|
||||
}
|
||||
return Injector.resolveAndCreate(sampleBindings)
|
||||
.asyncGet(Sampler)
|
||||
.then((sampler) => sampler.sample());
|
||||
|
||||
var inj = Injector.resolveAndCreate(sampleBindings);
|
||||
var adapter = inj.get(WebDriverAdapter);
|
||||
|
||||
return PromiseWrapper
|
||||
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
|
||||
.then((args) => {
|
||||
var capabilities = args[0];
|
||||
var userAgent = args[1];
|
||||
|
||||
// This might still create instances twice. We are creating a new injector with all the
|
||||
// bindings.
|
||||
// Only WebDriverAdapter is reused.
|
||||
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
|
||||
// injectors are handled better.
|
||||
var injector = Injector.resolveAndCreate([
|
||||
sampleBindings,
|
||||
bind(Options.CAPABILITIES).toValue(capabilities),
|
||||
bind(Options.USER_AGENT).toValue(userAgent),
|
||||
bind(WebDriverAdapter).toValue(adapter)
|
||||
]);
|
||||
|
||||
var sampler = injector.get(Sampler);
|
||||
return sampler.sample();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,10 +96,4 @@ var _DEFAULT_BINDINGS = [
|
||||
Validator.bindTo(RegressionSlopeValidator),
|
||||
WebDriverExtension.bindTo([ChromeDriverExtension, FirefoxDriverExtension, IOsDriverExtension]),
|
||||
Metric.bindTo(MultiMetric),
|
||||
|
||||
bind(Options.CAPABILITIES)
|
||||
.toAsyncFactory((adapter) => adapter.capabilities(), [WebDriverAdapter]),
|
||||
bind(Options.USER_AGENT)
|
||||
.toAsyncFactory((adapter) => adapter.executeScript('return window.navigator.userAgent;'),
|
||||
[WebDriverAdapter])
|
||||
];
|
||||
|
@ -14,11 +14,11 @@ import {Options} from './common_options';
|
||||
@ABSTRACT()
|
||||
export class WebDriverExtension {
|
||||
static bindTo(childTokens): List<Binding> {
|
||||
return [
|
||||
var res = [
|
||||
bind(_CHILDREN)
|
||||
.toAsyncFactory((injector) => PromiseWrapper.all(
|
||||
ListWrapper.map(childTokens, (token) => injector.asyncGet(token))),
|
||||
[Injector]),
|
||||
.toFactory(
|
||||
(injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)),
|
||||
[Injector]),
|
||||
bind(WebDriverExtension)
|
||||
.toFactory(
|
||||
(children, capabilities) => {
|
||||
@ -35,6 +35,7 @@ export class WebDriverExtension {
|
||||
},
|
||||
[_CHILDREN, Options.CAPABILITIES])
|
||||
];
|
||||
return res;
|
||||
}
|
||||
|
||||
gc(): Promise<any> { throw new BaseException('NYI'); }
|
||||
|
Reference in New Issue
Block a user