feat(di): rename Binding into Provider

Closes #4416

Closes #4654
This commit is contained in:
vsavkin
2015-10-10 22:11:13 -07:00
committed by Victor Savkin
parent 7c6130c2c5
commit 1eb0162cde
190 changed files with 2071 additions and 1816 deletions

View File

@ -12,7 +12,8 @@ import {
View,
ViewContainerRef,
bind,
Binding,
provide,
Provider,
NgIf,
ViewMetadata
} from 'angular2/core';
@ -22,17 +23,20 @@ import {ViewResolver} from 'angular2/src/core/linker/view_resolver';
import {getIntParameter, bindAction} from 'angular2/src/test_lib/benchmark_util';
function _createBindings(): Binding[] {
function _createBindings(): Provider[] {
var multiplyTemplatesBy = getIntParameter('elements');
return [
bind(ViewResolver)
.toFactory(() => new MultiplyViewResolver(
multiplyTemplatesBy,
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
[]),
provide(ViewResolver,
{
asFactory: () => new MultiplyViewResolver(
multiplyTemplatesBy,
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
deps: []
}),
// Use DynamicChangeDetector as that is the only one that Dart supports as well
// so that we can compare the numbers between JS and Dart
bind(ChangeDetectorGenConfig).toValue(new ChangeDetectorGenConfig(false, false, false, false))
provide(ChangeDetectorGenConfig,
{asValue: new ChangeDetectorGenConfig(false, false, false, false)})
];
}

View File

@ -1,4 +1,4 @@
import {Injectable, Injector, Key, bind} from "angular2/core";
import {Injectable, Injector, Key, bind, provide} from "angular2/core";
import {reflector} from 'angular2/src/core/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
import {getIntParameter, bindAction, microBenchmark} from 'angular2/src/test_lib/benchmark_util';
@ -27,9 +27,9 @@ export function main() {
.resolveAndCreateChild([])
.resolveAndCreateChild([]);
var variousBindings = [A, bind(B).toClass(C), [D, [E]], bind(F).toValue(6)];
var variousProviders = [A, provide(B, {asClass: C}), [D, [E]], provide(F, {asValue: 6})];
var variousBindingsResolved = Injector.resolve(variousBindings);
var variousProvidersResolved = Injector.resolve(variousProviders);
function getByToken() {
for (var i = 0; i < iterations; ++i) {
@ -59,20 +59,20 @@ export function main() {
}
/**
* Creates an injector with a variety of binding types.
* Creates an injector with a variety of provider types.
*/
function createVariety() {
for (var i = 0; i < iterations; ++i) {
Injector.resolveAndCreate(variousBindings);
Injector.resolveAndCreate(variousProviders);
}
}
/**
* Same as [createVariety] but resolves bindings ahead of time.
* Same as [createVariety] but resolves providers ahead of time.
*/
function createVarietyResolved() {
for (var i = 0; i < iterations; ++i) {
Injector.fromResolvedBindings(variousBindingsResolved);
Injector.fromResolvedProviders(variousProvidersResolved);
}
}

View File

@ -1,7 +1,7 @@
import {reflector} from 'angular2/src/core/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
import {Injectable, Injector} from 'angular2/core';
import {ProtoElementInjector, DirectiveBinding} from 'angular2/src/core/linker/element_injector';
import {ProtoElementInjector, DirectiveProvider} from 'angular2/src/core/linker/element_injector';
import {getIntParameter, bindAction, microBenchmark} from 'angular2/src/test_lib/benchmark_util';
import {BrowserDomAdapter} from 'angular2/src/core/dom/browser_adapter';
@ -12,12 +12,12 @@ export function main() {
var iterations = getIntParameter('iterations');
reflector.reflectionCapabilities = new ReflectionCapabilities();
var bindings = [
DirectiveBinding.createFromType(A, null),
DirectiveBinding.createFromType(B, null),
DirectiveBinding.createFromType(C, null)
var providers = [
DirectiveProvider.createFromType(A, null),
DirectiveProvider.createFromType(B, null),
DirectiveProvider.createFromType(C, null)
];
var proto = ProtoElementInjector.create(null, 0, bindings, false, 0, null);
var proto = ProtoElementInjector.create(null, 0, providers, false, 0, null);
var elementInjector = proto.instantiate(null);
function instantiate() {

View File

@ -13,6 +13,7 @@ import {
Directive,
View,
bind,
provide,
NgFor,
NgSwitch,
NgSwitchWhen,
@ -36,9 +37,9 @@ function _createBindings() {
return [
bind(BENCHMARK_TYPE)
.toValue(getStringParameter('benchmarkType')),
bind(LARGETABLE_ROWS).toValue(getIntParameter('rows')),
bind(LARGETABLE_COLS).toValue(getIntParameter('columns')),
bind(APP_VIEW_POOL_CAPACITY).toValue(viewCacheCapacity)
provide(LARGETABLE_ROWS, {asValue: getIntParameter('rows')}),
provide(LARGETABLE_COLS, {asValue: getIntParameter('columns')}),
provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})
];
}

View File

@ -3,12 +3,12 @@ import {bootstrap} from 'angular2/bootstrap';
import {App} from './app';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
import {bind} from 'angular2/core';
import {bind, provide} from 'angular2/core';
export function main() {
bootstrap(App, createBindings());
}
function createBindings(): any[] {
return [bind(APP_VIEW_POOL_CAPACITY).toValue(100000)];
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: 100000})];
}

View File

@ -6,7 +6,8 @@ import {
View,
ViewContainerRef,
bind,
Binding,
provide,
Provider,
NgIf
} from 'angular2/core';
import {ComponentRef_} from 'angular2/src/core/linker/dynamic_component_loader';
@ -25,9 +26,9 @@ import {
import {BrowserDomAdapter} from 'angular2/src/core/dom/browser_adapter';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
function createBindings(): Binding[] {
function createBindings(): Provider[] {
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 0;
return [bind(APP_VIEW_POOL_CAPACITY).toValue(viewCacheCapacity)];
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})];
}
function setupReflector() {

View File

@ -6,7 +6,8 @@ import {
View,
ViewContainerRef,
bind,
Binding,
provide,
Provider,
NgIf
} from 'angular2/core';
@ -24,9 +25,9 @@ import {
import {BrowserDomAdapter} from 'angular2/src/core/dom/browser_adapter';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
function createBindings(): Binding[] {
function createProviders(): Provider[] {
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 1;
return [bind(APP_VIEW_POOL_CAPACITY).toValue(viewCacheCapacity)];
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})];
}
var BASELINE_TREE_TEMPLATE;
@ -37,7 +38,7 @@ export function main() {
var maxDepth = getIntParameter('depth');
BASELINE_TREE_TEMPLATE = DOM.createTemplate(
'<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>');
'<span>_<template class="ng-provider"></template><template class="ng-provider"></template></span>');
BASELINE_IF_TEMPLATE = DOM.createTemplate('<span template="if"><tree></tree></span>');
var app;
@ -91,7 +92,7 @@ export function main() {
function noop() {}
function initNg2() {
bootstrap(AppComponent, createBindings())
bootstrap(AppComponent, createProviders())
.then((ref) => {
var injector = ref.injector;
lifeCycle = injector.get(LifeCycle);