From 82127571b503c44a12f211c50f312c99480bca36 Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Thu, 9 Apr 2015 17:53:36 -0700 Subject: [PATCH] feat(dart/transform): Use the Dart transformer for benchmarks Remove explicit generation of reflection information in benchmark code and generate it with the transformer. --- gulpfile.js | 18 - modules/angular2/pubspec.yaml | 2 +- modules/benchmarks/pubspec.yaml | 8 +- .../src/compiler/compiler_benchmark.js | 37 +- .../element_injector_benchmark.js | 26 +- .../src/largetable/largetable_benchmark.js | 411 ++++-------------- .../src/naive_infinite_scroll/app.js | 37 +- .../src/naive_infinite_scroll/cells.js | 202 ++++----- .../src/naive_infinite_scroll/index.js | 322 +------------- .../src/naive_infinite_scroll/scroll_area.js | 49 +-- .../src/naive_infinite_scroll/scroll_item.js | 113 +++-- modules/benchmarks/src/tree/tree_benchmark.js | 259 +---------- 12 files changed, 290 insertions(+), 1194 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 311280421e..133f457524 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -564,24 +564,6 @@ gulp.task('serve/benchmarks_external.dart', pubserve(gulp, gulpPlugins, { path: CONFIG.dest.dart + '/benchmarks_external' })); -gulp.task('serve/examples.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/examples' -})); - -gulp.task('serve/benchmarks.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/benchmarks' -})); - -gulp.task('serve/benchmarks_external.dart.static', pubserve(gulp, gulpPlugins, { - command: DART_SDK.PUB, - mode: 'ngstatic', - path: CONFIG.dest.dart + '/benchmarks_external' -})); - // -------------- // doc generation var Dgeni = require('dgeni'); diff --git a/modules/angular2/pubspec.yaml b/modules/angular2/pubspec.yaml index 53790c4e15..83ed101777 100644 --- a/modules/angular2/pubspec.yaml +++ b/modules/angular2/pubspec.yaml @@ -16,6 +16,6 @@ dependencies: html: '^0.12.0' stack_trace: '^1.1.1' transformers: - - angular2/src/transform/di_transformer + - angular2 dev_dependencies: guinness: "^0.1.17" diff --git a/modules/benchmarks/pubspec.yaml b/modules/benchmarks/pubspec.yaml index e62725198e..c7c92ea0eb 100644 --- a/modules/benchmarks/pubspec.yaml +++ b/modules/benchmarks/pubspec.yaml @@ -16,7 +16,13 @@ dependency_overrides: path: ../angular2 transformers: - angular2: - entry_point: web/src/di/di_benchmark.dart + entry_points: + - web/src/compiler/compiler_benchmark.dart + - web/src/di/di_benchmark.dart + - web/src/element_injector/element_injector_benchmark.dart + - web/src/largetable/largetable_benchmark.dart + - web/src/naive_infinite_scroll/index.dart + - web/src/tree/tree_benchmark.dart - $dart2js: minify: false commandLineOptions: ['--dump-info', '--trust-type-annotations', '--trust-primitives'] diff --git a/modules/benchmarks/src/compiler/compiler_benchmark.js b/modules/benchmarks/src/compiler/compiler_benchmark.js index 6bfb682dfb..9e0bb68837 100644 --- a/modules/benchmarks/src/compiler/compiler_benchmark.js +++ b/modules/benchmarks/src/compiler/compiler_benchmark.js @@ -21,6 +21,7 @@ import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_res import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; import {reflector} from 'angular2/src/reflection/reflection'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; import {getIntParameter, bindAction} from 'angular2/src/test_lib/benchmark_util'; import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory'; @@ -29,41 +30,7 @@ import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; import * as rc from 'angular2/src/render/dom/compiler/compiler'; function setupReflector() { - reflector.registerType(BenchmarkComponent, { - "factory": () => new BenchmarkComponent(), - "parameters": [], - "annotations" : [new Component()] - }); - - reflector.registerType(Dir0, { - "factory": () => new Dir0(), - "parameters": [], - "annotations" : [new Decorator({selector: '[dir0]', properties: {'prop': 'attr0'}})] - }); - - reflector.registerType(Dir1, { - "factory": (dir0) => new Dir1(dir0), - "parameters": [[Dir0]], - "annotations" : [new Decorator({selector: '[dir1]', properties: {'prop': 'attr1'}})] - }); - - reflector.registerType(Dir2, { - "factory": (dir1) => new Dir2(dir1), - "parameters": [[Dir1]], - "annotations" : [new Decorator({selector: '[dir2]', properties: {'prop': 'attr2'}})] - }); - - reflector.registerType(Dir3, { - "factory": (dir2) => new Dir3(dir2), - "parameters": [[Dir2]], - "annotations" : [new Decorator({selector: '[dir3]', properties: {'prop': 'attr3'}})] - }); - - reflector.registerType(Dir4, { - "factory": (dir3) => new Dir4(dir3), - "parameters": [[Dir3]], - "annotations" : [new Decorator({selector: '[dir4]', properties: {'prop': 'attr4'}})] - }); + reflector.reflectionCapabilities = new ReflectionCapabilities(); reflector.registerGetters({ "inter0": (a) => a.inter0, "inter1": (a) => a.inter1, diff --git a/modules/benchmarks/src/element_injector/element_injector_benchmark.js b/modules/benchmarks/src/element_injector/element_injector_benchmark.js index 60e2e65bde..47fc6e5a7a 100644 --- a/modules/benchmarks/src/element_injector/element_injector_benchmark.js +++ b/modules/benchmarks/src/element_injector/element_injector_benchmark.js @@ -1,34 +1,17 @@ import {reflector} from 'angular2/src/reflection/reflection'; -import {Injector} from 'angular2/di'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; +import {Injectable, Injector} from 'angular2/di'; import {ProtoElementInjector} from 'angular2/src/core/compiler/element_injector'; import {getIntParameter, bindAction, microBenchmark} from 'angular2/src/test_lib/benchmark_util'; import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter'; var count = 0; -function setupReflector() { - reflector.registerType(A, { - 'factory': () => new A(), - 'parameters': [], - 'annotations' : [] - }); - reflector.registerType(B, { - 'factory': () => new B(), - 'parameters': [], - 'annotations' : [] - }); - reflector.registerType(C, { - 'factory': (a,b) => new C(a,b), - 'parameters': [[A],[B]], - 'annotations' : [] - }); -} - export function main() { BrowserDomAdapter.makeCurrent(); var iterations = getIntParameter('iterations'); - setupReflector(); + reflector.reflectionCapabilities = new ReflectionCapabilities(); var appInjector = new Injector([]); var bindings = [A, B, C]; @@ -59,18 +42,21 @@ export function main() { ); } +@Injectable() class A { constructor() { count++; } } +@Injectable() class B { constructor() { count++; } } +@Injectable() class C { constructor(a:A, b:B) { count++; diff --git a/modules/benchmarks/src/largetable/largetable_benchmark.js b/modules/benchmarks/src/largetable/largetable_benchmark.js index 74d307e841..3c24c97385 100644 --- a/modules/benchmarks/src/largetable/largetable_benchmark.js +++ b/modules/benchmarks/src/largetable/largetable_benchmark.js @@ -20,6 +20,7 @@ import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_compone import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; import {reflector} from 'angular2/src/reflection/reflection'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {isPresent, BaseException} from 'angular2/src/facade/lang'; import {window, document, gc} from 'angular2/src/facade/browser'; @@ -42,349 +43,34 @@ import {Renderer} from 'angular2/src/render/api'; import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; import * as rc from 'angular2/src/render/dom/compiler/compiler'; import * as rvf from 'angular2/src/render/dom/view/view_factory'; -import {Inject} from 'angular2/di'; +import {Inject, bind} from 'angular2/di'; + +export const BENCHMARK_TYPE = 'LargetableComponent.benchmarkType'; +export const LARGETABLE_ROWS = 'LargetableComponent.rows'; +export const LARGETABLE_COLS = 'LargetableComponent.cols'; +function _createBindings() { + return [ + bind(BENCHMARK_TYPE).toValue(getStringParameter('benchmarkType')), + bind(LARGETABLE_ROWS).toValue(getIntParameter('rows')), + bind(LARGETABLE_COLS).toValue(getIntParameter('columns')) + ]; +} var BASELINE_LARGETABLE_TEMPLATE; function setupReflector() { - // TODO: Put the general calls to reflector.register... in a shared file - // as they are needed in all benchmarks... - - reflector.registerType(AppComponent, { - 'factory': () => new AppComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'app' - - }), - new View({ - directives: [LargetableComponent], - template: `` - })] - }); - - reflector.registerType(LargetableComponent, { - 'factory': () => new LargetableComponent(getStringParameter('benchmarkType'), - getIntParameter('rows'), getIntParameter('columns')), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'largetable', - properties: { - 'data': 'data', - 'benchmarkType': 'benchmarktype' - } - }), - new View({ - directives: [For, Switch, SwitchWhen, SwitchDefault], - template: ` - - - - - - - - - - - - - - - - - - - - - -
- {{column.i}}:{{column.j}}| -
- i,j attrs -
- {{column.iFn()}}:{{column.jFn()}}| -
- {{benchmarkType}} not yet implemented -
` - }) - ] - }); - - reflector.registerType(If, { - 'factory': (vp) => new If(vp), - 'parameters': [[ViewContainer]], - 'annotations' : [new Viewport({ - selector: '[if]', - properties: { - 'condition': 'if' - } - })] - }); - - reflector.registerType(For, { - 'factory': (vp) => new For(vp), - 'parameters': [[ViewContainer]], - 'annotations' : [new Viewport({ - selector: '[for]', - properties: { - 'iterableChanges': 'of | iterableDiff' - } - })] - }); - - reflector.registerType(Switch, { - 'factory': () => new Switch(), - 'parameters': [], - 'annotations' : [new Decorator({ - selector: '[switch]', - properties: { - 'value': 'switch' - } - })] - }); - - reflector.registerType(SwitchWhen, { - 'factory': (vc, ss) => new SwitchWhen(vc, ss), - 'parameters': [[ViewContainer],[Switch, new Parent()]], - 'annotations' : [new Viewport({ - selector: '[switch-when]', - properties: { - 'when': 'switch-when' - } - })] - }); - - reflector.registerType(SwitchDefault, { - 'factory': (vc, ss) => new SwitchDefault(vc, ss), - 'parameters': [[ViewContainer],[Switch, new Parent()]], - 'annotations' : [new Viewport({ - selector: '[switch-default]' - })] - }); - - reflector.registerType(Compiler, { - "factory": (reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory) => - new Compiler(reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory), - "parameters": [[DirectiveMetadataReader], [CompilerCache], [TemplateResolver], [ComponentUrlMapper], - [UrlResolver], [Renderer], [ProtoViewFactory]], - "annotations": [] - }); - - reflector.registerType(CompilerCache, { - 'factory': () => new CompilerCache(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(Parser, { - 'factory': (lexer) => new Parser(lexer), - 'parameters': [[Lexer]], - 'annotations': [] - }); - - reflector.registerType(TemplateLoader, { - 'factory': (xhr, urlResolver) => new TemplateLoader(xhr, urlResolver), - 'parameters': [[XHR], [UrlResolver]], - 'annotations': [] - }); - - reflector.registerType(TemplateResolver, { - 'factory': () => new TemplateResolver(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(XHR, { - 'factory': () => new XHRImpl(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(DirectiveMetadataReader, { - 'factory': () => new DirectiveMetadataReader(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(ShadowDomStrategy, { - "factory": (strategy) => strategy, - "parameters": [[NativeShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(NativeShadowDomStrategy, { - "factory": (styleUrlResolver) => new NativeShadowDomStrategy(styleUrlResolver), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(EmulatedUnscopedShadowDomStrategy, { - "factory": (styleUrlResolver) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, null), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(StyleUrlResolver, { - "factory": (urlResolver) => new StyleUrlResolver(urlResolver), - "parameters": [[UrlResolver]], - "annotations": [] - }); - - reflector.registerType(TestabilityRegistry, { - "factory": () => new TestabilityRegistry(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Testability, { - "factory": () => new Testability(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(UrlResolver, { - "factory": () => new UrlResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Lexer, { - 'factory': () => new Lexer(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(ExceptionHandler, { - "factory": () => new ExceptionHandler(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(LifeCycle, { - "factory": (exHandler, cd) => new LifeCycle(exHandler, cd), - "parameters": [[ExceptionHandler], [ChangeDetector]], - "annotations": [] - }); - - reflector.registerType(ComponentUrlMapper, { - "factory": () => new ComponentUrlMapper(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(StyleInliner, { - "factory": (xhr, styleUrlResolver, urlResolver) => - new StyleInliner(xhr, styleUrlResolver, urlResolver), - "parameters": [[XHR], [StyleUrlResolver], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(EventManager, { - "factory": () => new EventManager([], null), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DynamicComponentLoader, { - "factory": (compiler, reader, renderer, viewFactory) => - new DynamicComponentLoader(compiler, reader, renderer, viewFactory), - "parameters": [[Compiler], [DirectiveMetadataReader], [Renderer], [ViewFactory]], - "annotations": [] - }); - - reflector.registerType(DirectDomRenderer, { - "factory": (renderCompiler, renderViewFactory, shadowDomStrategy) => - new DirectDomRenderer(renderCompiler, renderViewFactory, shadowDomStrategy), - "parameters": [[rc.Compiler], [rvf.ViewFactory], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rc.DefaultCompiler, { - "factory": (parser, shadowDomStrategy, templateLoader) => - new rc.DefaultCompiler(parser, shadowDomStrategy, templateLoader), - "parameters": [[Parser], [ShadowDomStrategy], [TemplateLoader]], - "annotations": [] - }); - - reflector.registerType(rvf.ViewFactory, { - "factory": (capacity, eventManager, shadowDomStrategy) => - new rvf.ViewFactory(capacity, eventManager, shadowDomStrategy), - "parameters": [[new Inject(rvf.VIEW_POOL_CAPACITY)], [EventManager], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rvf.VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ProtoViewFactory, { - "factory": (changeDetection, renderer) => - new ProtoViewFactory(changeDetection, renderer), - "parameters": [[ChangeDetection], [Renderer]], - "annotations": [] - }); - - reflector.registerType(ViewFactory, { - "factory": (capacity) => - new ViewFactory(capacity), - "parameters": [[new Inject(VIEW_POOL_CAPACITY)]], - "annotations": [] - }); - - reflector.registerType(VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); + reflector.reflectionCapabilities = new ReflectionCapabilities(); + // TODO(kegluneq): Generate these. reflector.registerGetters({ - 'data': (a) => a.data, - 'benchmarkType': (a) => a.benchmarkType, - 'benchmarktype': (a) => a.benchmarktype, - 'when': (a) => a.when, - 'switchWhen': (a) => a.switchWhen, - 'switchwhen': (a) => a.switchwhen, - 'value': (a) => a.value, - 'iterable': (a) => a.iterable, - 'iterableChanges': (a) => a.iterableChanges, - 'row': (a) => a.row, - 'column': (a) => a.column, - 'i': (a) => a.i, - 'j': (a) => a.j, - 'switch': (a) => {throw new BaseException('not implemented, reserved word in dart')}, - 'for': (a) => {throw new BaseException('not implemented, reserved word in dart')}, - 'of': (a) => a.of + 'benchmarktype': (o) => o.benchmarktype, + 'switch': (o) => null, + 'switchWhen': (o) => o.switchWhen }); - - reflector.registerMethods({ - 'iFn': (a, args) => a.iFn(), - 'jFn': (a, args) => a.jFn(), - }) - reflector.registerSetters({ - 'data': (a,v) => a.data = v, - 'benchmarkType': (a,v) => a.benchmarkType = v, - 'benchmarktype': (a,v) => a.benchmarktype = v, - 'when': (a,v) => a.when = v, - 'switchWhen': (a,v) => a.switchWhen = v, - 'switchwhen': (a,v) => a.switchwhen = v, - 'value': (a,v) => a.value = v, - 'iterable': (a,v) => a.iterable = v, - 'iterableChanges': (a,v) => a.iterableChanges = v, - 'row': (a,v) => a.row = v, - 'column': (a,v) => a.column = v, - 'i': (a,v) => a.i = v, - 'j': (a,v) => a.j = v, - 'switch': (a,v) => {throw new BaseException('not implemented, reserved word in dart')}, - 'for': (a,v) => {throw new BaseException('not implemented, reserved word in dart')}, - 'of': (a,v) => a.j = v + 'benchmarktype': (o, v) => o.benchmarktype = v, + 'switch': (o, v) => null, + 'switchWhen': (o, v) => o.switchWhen = v }); } @@ -456,7 +142,7 @@ export function main() { function noop() {} function initNg2() { - bootstrap(AppComponent).then((injector) => { + bootstrap(AppComponent, _createBindings()).then((injector) => { app = injector.get(AppComponent); lifecycle = injector.get(LifeCycle); bindAction('#ng2DestroyDom', ng2DestroyDom); @@ -556,17 +242,68 @@ class CellData { } } +@Component({ + selector: 'app' +}) +@View({ + directives: [LargetableComponent], + template: `` +}) class AppComponent { data; benchmarkType:string; } +@Component({ + selector: 'largetable', + properties: { + 'data': 'data', + 'benchmarkType': 'benchmarktype' + } +}) +@View({ + directives: [For, Switch, SwitchWhen, SwitchDefault], + template: ` + + + + + + + + + + + + + + + + + + + + + +
+ {{column.i}}:{{column.j}}| +
+ i,j attrs +
+ {{column.iFn()}}:{{column.jFn()}}| +
+ {{benchmarkType}} not yet implemented +
` +}) class LargetableComponent { data; benchmarkType:string; rows:number; columns:number; - constructor(benchmarkType:string,rows:number,columns:number) { + constructor( + @Inject(BENCHMARK_TYPE) benchmarkType, + @Inject(LARGETABLE_ROWS) rows, + @Inject(LARGETABLE_COLS) columns) { this.benchmarkType = benchmarkType; this.rows = rows; this.columns = columns; diff --git a/modules/benchmarks/src/naive_infinite_scroll/app.js b/modules/benchmarks/src/naive_infinite_scroll/app.js index 9bc0b2fc7a..258dfbe0fe 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/app.js +++ b/modules/benchmarks/src/naive_infinite_scroll/app.js @@ -10,6 +10,21 @@ import {If, For} from 'angular2/directives'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {document} from 'angular2/src/facade/browser'; + +@Component({selector: 'scroll-app'}) +@View({ + directives: [ScrollAreaComponent, If, For], + template: ` +
+
+ +
+
+

Following tables are only here to add weight to the UI:

+ +
+
` +}) export class App { scrollAreas:List; iterationCount:int; @@ -77,25 +92,3 @@ export class App { return DOM.query('body /deep/ #testArea /deep/ #scrollDiv'); } } - -export function setupReflectorForApp() { - reflector.registerType(App, { - 'factory': () => { return new App(); }, - 'parameters': [], - 'annotations': [ - new Component({selector: 'scroll-app'}), - new View({ - directives: [ScrollAreaComponent, If, For], - template: ` -
-
- -
-
-

Following tables are only here to add weight to the UI:

- -
-
` - })] - }); -} diff --git a/modules/benchmarks/src/naive_infinite_scroll/cells.js b/modules/benchmarks/src/naive_infinite_scroll/cells.js index 714c74e720..904655d71b 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/cells.js +++ b/modules/benchmarks/src/naive_infinite_scroll/cells.js @@ -21,14 +21,47 @@ export class HasStyle { } } +@Component({ + selector: 'company-name', + properties: { + 'width': 'cell-width', + 'company': 'company' + } +}) +@View({ + directives: [], + template: `
{{company.name}}
` +}) export class CompanyNameComponent extends HasStyle { company:Company; } +@Component({ + selector: 'opportunity-name', + properties: { + 'width': 'cell-width', + 'opportunity': 'opportunity' + } +}) +@View({ + directives: [], + template: `
{{opportunity.name}}
` +}) export class OpportunityNameComponent extends HasStyle { opportunity:Opportunity; } +@Component({ + selector: 'offering-name', + properties: { + 'width': 'cell-width', + 'offering': 'offering' + } +}) +@View({ + directives: [], + template: `
{{offering.name}}
` +}) export class OfferingNameComponent extends HasStyle { offering:Offering; } @@ -40,6 +73,25 @@ export class Stage { apply:Function; } +@Component({ + selector: 'stage-buttons', + properties: { + 'width': 'cell-width', + 'offering': 'offering' + } +}) +@View({ + directives: [For], + template: ` +
+ +
` +}) export class StageButtonsComponent extends HasStyle { _offering:Offering; stages:List; @@ -80,10 +132,37 @@ export class StageButtonsComponent extends HasStyle { } } +@Component({ + selector: 'account-cell', + properties: { + 'width': 'cell-width', + 'account': 'account' + } +}) +@View({ + directives: [], + template: ` +
+ + {{account.accountId}} + +
` +}) export class AccountCellComponent extends HasStyle { account:Account; } +@Component({ + selector: 'formatted-cell', + properties: { + 'width': 'cell-width', + 'value': 'value' + } +}) +@View({ + directives: [], + template: `
{{formattedValue}}
` +}) export class FormattedCellComponent extends HasStyle { formattedValue:string; @@ -95,126 +174,3 @@ export class FormattedCellComponent extends HasStyle { } } } - -export function setupReflectorForCells() { - reflector.registerType(CompanyNameComponent, { - 'factory': () => new CompanyNameComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'company-name', - properties: { - 'width': 'cell-width', - 'company': 'company' - } - }), - new View({ - directives: [], - template: `
{{company.name}}
` - }) - ] - }); - - reflector.registerType(OpportunityNameComponent, { - 'factory': () => new OpportunityNameComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'opportunity-name', - properties: { - 'width': 'cell-width', - 'opportunity': 'opportunity' - } - }), - new View({ - directives: [], - template: `
{{opportunity.name}}
` - }) - ] - }); - - reflector.registerType(OfferingNameComponent, { - 'factory': () => new OfferingNameComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'offering-name', - properties: { - 'width': 'cell-width', - 'offering': 'offering' - } - }), - new View({ - directives: [], - template: `
{{offering.name}}
` - }) - ] - }); - - reflector.registerType(StageButtonsComponent, { - 'factory': () => new StageButtonsComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'stage-buttons', - properties: { - 'width': 'cell-width', - 'offering': 'offering' - } - }), - new View({ - directives: [For], - template: ` -
- -
` - }) - ] - }); - - reflector.registerType(AccountCellComponent, { - 'factory': () => new AccountCellComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'account-cell', - properties: { - 'width': 'cell-width', - 'account': 'account' - } - }), - new View({ - directives: [], - template: ` -
- - {{account.accountId}} - -
` - }) - ] - }); - - reflector.registerType(FormattedCellComponent, { - 'factory': () => new FormattedCellComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'formatted-cell', - properties: { - 'width': 'cell-width', - 'value': 'value' - } - }), - new View({ - directives: [], - template: `
{{formattedValue}}
` - }) - ] - }); -} diff --git a/modules/benchmarks/src/naive_infinite_scroll/index.js b/modules/benchmarks/src/naive_infinite_scroll/index.js index 8c1a8fb626..2828909995 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/index.js +++ b/modules/benchmarks/src/naive_infinite_scroll/index.js @@ -9,6 +9,7 @@ import { bootstrap, Component, Viewport, View, ViewContainer, Compiler, onChange, NgElement, Decorator } from 'angular2/angular2'; import {reflector} from 'angular2/src/reflection/reflection'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; import {CompilerCache} from 'angular2/src/core/compiler/compiler'; import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader'; import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy'; @@ -27,12 +28,11 @@ import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_compone import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; import {If, For} from 'angular2/directives'; -import {App, setupReflectorForApp} from './app'; -import {ScrollAreaComponent, setupReflectorForScrollArea} from './scroll_area'; -import {ScrollItemComponent, setupReflectorForScrollItem} from './scroll_item'; +import {App} from './app'; +import {ScrollAreaComponent} from './scroll_area'; +import {ScrollItemComponent} from './scroll_item'; import {CompanyNameComponent, OpportunityNameComponent, OfferingNameComponent, - AccountCellComponent, StageButtonsComponent, FormattedCellComponent, - setupReflectorForCells} + AccountCellComponent, StageButtonsComponent, FormattedCellComponent} from './cells'; import {EventManager} from 'angular2/src/render/dom/events/event_manager'; @@ -42,114 +42,22 @@ import {Renderer} from 'angular2/src/render/api'; import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; import * as rc from 'angular2/src/render/dom/compiler/compiler'; import * as rvf from 'angular2/src/render/dom/view/view_factory'; -import {Inject} from 'angular2/di'; +import {Inject, bind} from 'angular2/di'; export function main() { setupReflector(); - bootstrap(App); + bootstrap(App, createBindings()); +} + +function createBindings():List { + return [bind(VIEW_POOL_CAPACITY).toValue(100000)]; } export function setupReflector() { - setupReflectorForAngular(); - setupReflectorForApp(); - setupReflectorForScrollArea(); - setupReflectorForScrollItem(); - setupReflectorForCells(); - - reflector.registerGetters({ - 'scrollAreas': (o) => o.scrollAreas, - 'length': (o) => o.length, - 'iterableChanges': (o) => o.iterableChanges, - 'scrollArea': (o) => o.scrollArea, - 'item': (o) => o.item, - 'visibleItems': (o) => o.visibleItems, - 'condition': (o) => o.condition, - 'width': (o) => o.width, - 'value': (o) => o.value, - 'href': (o) => o.href, - 'company': (o) => o.company, - 'formattedValue': (o) => o.formattedValue, - 'name': (o) => o.name, - 'style': (o) => o.style, - 'offering': (o) => o.offering, - 'account': (o) => o.account, - 'accountId': (o) => o.accountId, - 'companyNameWidth': (o) => o.companyNameWidth, - 'opportunityNameWidth': (o) => o.opportunityNameWidth, - 'offeringNameWidth': (o) => o.offeringNameWidth, - 'accountCellWidth': (o) => o.accountCellWidth, - 'basePointsWidth': (o) => o.basePointsWidth, - 'scrollDivStyle': (o) => o.scrollDivStyle, - 'paddingStyle': (o) => o.paddingStyle, - 'innerStyle': (o) => o.innerStyle, - 'opportunity': (o) => o.opportunity, - 'itemStyle': (o) => o.itemStyle, - 'dueDateWidth': (o) => o.dueDateWidth, - 'basePoints': (o) => o.basePoints, - 'kickerPoints': (o) => o.kickerPoints, - 'kickerPointsWidth': (o) => o.kickerPointsWidth, - 'bundles': (o) => o.bundles, - 'stageButtonsWidth': (o) => o.stageButtonsWidth, - 'bundlesWidth': (o) => o.bundlesWidth, - 'disabled': (o) => o.disabled, - 'isDisabled': (o) => o.isDisabled, - 'dueDate': (o) => o.dueDate, - 'endDate': (o) => o.endDate, - 'aatStatus': (o) => o.aatStatus, - 'stage': (o) => o.stage, - 'stages': (o) => o.stages, - 'aatStatusWidth': (o) => o.aatStatusWidth, - 'endDateWidth': (o) => o.endDateWidth, - '$event': (o) => null - }); + reflector.reflectionCapabilities = new ReflectionCapabilities(); + // TODO(kegluneq): Generate this. reflector.registerSetters({ - 'scrollAreas': (o, v) => o.scrollAreas = v, - 'length': (o, v) => o.length = v, - 'condition': (o, v) => o.condition = v, - 'scrollArea': (o, v) => o.scrollArea = v, - 'item': (o, v) => o.item = v, - 'visibleItems': (o, v) => o.visibleItems = v, - 'iterableChanges': (o, v) => o.iterableChanges = v, - 'width': (o, v) => o.width = v, - 'value': (o, v) => o.value = v, - 'company': (o, v) => o.company = v, - 'name': (o, v) => o.name = v, - 'offering': (o, v) => o.offering = v, - 'account': (o, v) => o.account = v, - 'accountId': (o, v) => o.accountId = v, - 'formattedValue': (o, v) => o.formattedValue = v, - 'stage': (o, v) => o.stage = v, - 'stages': (o, v) => o.stages = v, - 'disabled': (o, v) => o.disabled = v, - 'isDisabled': (o, v) => o.isDisabled = v, - 'href': (o, v) => o.href = v, - 'companyNameWidth': (o, v) => o.companyNameWidth = v, - 'opportunityNameWidth': (o, v) => o.opportunityNameWidth = v, - 'offeringNameWidth': (o, v) => o.offeringNameWidth = v, - 'accountCellWidth': (o, v) => o.accountCellWidth = v, - 'basePointsWidth': (o, v) => o.basePointsWidth = v, - 'scrollDivStyle': (o, v) => o.scrollDivStyle = v, - 'paddingStyle': (o, v) => o.paddingStyle = v, - 'innerStyle': (o, v) => o.innerStyle = v, - 'opportunity': (o, v) => o.opportunity = v, - 'itemStyle': (o, v) => o.itemStyle = v, - 'basePoints': (o, v) => o.basePoints = v, - 'kickerPoints': (o, v) => o.kickerPoints = v, - 'kickerPointsWidth': (o, v) => o.kickerPointsWidth = v, - 'stageButtonsWidth': (o, v) => o.stageButtonsWidth = v, - 'dueDate': (o, v) => o.dueDate = v, - 'dueDateWidth': (o, v) => o.dueDateWidth = v, - 'endDate': (o, v) => o.endDate = v, - 'endDateWidth': (o, v) => o.endDate = v, - 'aatStatus': (o, v) => o.aatStatus = v, - 'aatStatusWidth': (o, v) => o.aatStatusWidth = v, - 'bundles': (o, v) => o.bundles = v, - 'bundlesWidth': (o, v) => o.bundlesWidth = v, - 'if': (o, v) => {}, - 'of': (o, v) => {}, - 'cellWidth': (o, v) => o.cellWidth = v, - '$event': (o, v) => null, 'style': (o, m) => { //if (isBlank(m)) return; // HACK @@ -167,207 +75,3 @@ export function setupReflector() { 'setStage': (o, args) => o.setStage(args[0]) }); } - -export function setupReflectorForAngular() { - reflector.registerType(If, { - 'factory': (vp) => new If(vp), - 'parameters': [[ViewContainer]], - 'annotations' : [new Viewport({ - selector: '[if]', - properties: { - 'condition': 'if' - } - })] - }); - - reflector.registerType(For, { - 'factory': (vp) => new For(vp), - 'parameters': [[ViewContainer]], - 'annotations' : [new Viewport({ - selector: '[for]', - properties: { - 'iterableChanges': 'of | iterableDiff' - } - })] - }); - - reflector.registerType(Compiler, { - "factory": (reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory) => - new Compiler(reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory), - "parameters": [[DirectiveMetadataReader], [CompilerCache], [TemplateResolver], [ComponentUrlMapper], - [UrlResolver], [Renderer], [ProtoViewFactory]], - "annotations": [] - }); - - reflector.registerType(CompilerCache, { - 'factory': () => new CompilerCache(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(Parser, { - 'factory': (lexer) => new Parser(lexer), - 'parameters': [[Lexer]], - 'annotations': [] - }); - - reflector.registerType(TemplateLoader, { - "factory": (xhr, urlResolver) => new TemplateLoader(xhr, urlResolver), - "parameters": [[XHR], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(TemplateResolver, { - "factory": () => new TemplateResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(XHR, { - "factory": () => new XHRImpl(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DirectiveMetadataReader, { - 'factory': () => new DirectiveMetadataReader(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(Lexer, { - 'factory': () => new Lexer(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(ExceptionHandler, { - "factory": () => new ExceptionHandler(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(LifeCycle, { - "factory": (exHandler, cd) => new LifeCycle(exHandler, cd), - "parameters": [[ExceptionHandler], [ChangeDetector]], - "annotations": [] - }); - - reflector.registerType(ShadowDomStrategy, { - "factory": (strategy) => strategy, - "parameters": [[NativeShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(NativeShadowDomStrategy, { - "factory": (styleUrlResolver) => new NativeShadowDomStrategy(styleUrlResolver), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(EmulatedUnscopedShadowDomStrategy, { - "factory": (styleUrlResolver) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, null), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(StyleUrlResolver, { - "factory": (urlResolver) => new StyleUrlResolver(urlResolver), - "parameters": [[UrlResolver]], - "annotations": [] - }); - - reflector.registerType(UrlResolver, { - "factory": () => new UrlResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ComponentUrlMapper, { - "factory": () => new ComponentUrlMapper(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(TestabilityRegistry, { - "factory": () => new TestabilityRegistry(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Testability, { - "factory": () => new Testability(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(StyleInliner, { - "factory": (xhr, styleUrlResolver, urlResolver) => - new StyleInliner(xhr, styleUrlResolver, urlResolver), - "parameters": [[XHR], [StyleUrlResolver], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(EventManager, { - "factory": () => new EventManager([], null), - "parameters": [], - "annotations": [] - }); - - - reflector.registerType(DynamicComponentLoader, { - "factory": (compiler, reader, renderer, viewFactory) => - new DynamicComponentLoader(compiler, reader, renderer, viewFactory), - "parameters": [[Compiler], [DirectiveMetadataReader], [Renderer], [ViewFactory]], - "annotations": [] - }); - - reflector.registerType(DirectDomRenderer, { - "factory": (renderCompiler, renderViewFactory, shadowDomStrategy) => - new DirectDomRenderer(renderCompiler, renderViewFactory, shadowDomStrategy), - "parameters": [[rc.Compiler], [rvf.ViewFactory], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rc.DefaultCompiler, { - "factory": (parser, shadowDomStrategy, templateLoader) => - new rc.DefaultCompiler(parser, shadowDomStrategy, templateLoader), - "parameters": [[Parser], [ShadowDomStrategy], [TemplateLoader]], - "annotations": [] - }); - - reflector.registerType(rvf.ViewFactory, { - "factory": (capacity, eventManager, shadowDomStrategy) => - new rvf.ViewFactory(capacity, eventManager, shadowDomStrategy), - "parameters": [[new Inject(rvf.VIEW_POOL_CAPACITY)], [EventManager], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rvf.VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ProtoViewFactory, { - "factory": (changeDetection, renderer) => - new ProtoViewFactory(changeDetection, renderer), - "parameters": [[ChangeDetection], [Renderer]], - "annotations": [] - }); - - reflector.registerType(ViewFactory, { - "factory": (capacity) => - new ViewFactory(capacity), - "parameters": [[new Inject(VIEW_POOL_CAPACITY)]], - "annotations": [] - }); - - reflector.registerType(VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); -} diff --git a/modules/benchmarks/src/naive_infinite_scroll/scroll_area.js b/modules/benchmarks/src/naive_infinite_scroll/scroll_area.js index 7496753045..a2d2e9fdeb 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/scroll_area.js +++ b/modules/benchmarks/src/naive_infinite_scroll/scroll_area.js @@ -14,6 +14,26 @@ import {generateOfferings} from './random_data'; import {ScrollItemComponent} from './scroll_item'; import {For} from 'angular2/directives'; +@Component({ + selector: 'scroll-area', +}) +@View({ + directives: [ScrollItemComponent, For], + template: ` +
+
+
+
+ + +
+
+
` +}) export class ScrollAreaComponent { _fullList:List; visibleItems:List; @@ -59,32 +79,3 @@ export class ScrollAreaComponent { this.visibleItems = ListWrapper.slice(this._fullList, iStart, iEnd); } } - -export function setupReflectorForScrollArea() { - reflector.registerType(ScrollAreaComponent, { - 'factory': () => new ScrollAreaComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'scroll-area', - }), - new View({ - directives: [ScrollItemComponent, For], - template: ` -
-
-
-
- - -
-
-
` - }) - ] - }); -} diff --git a/modules/benchmarks/src/naive_infinite_scroll/scroll_item.js b/modules/benchmarks/src/naive_infinite_scroll/scroll_item.js index f03baf5568..19ec32069e 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/scroll_item.js +++ b/modules/benchmarks/src/naive_infinite_scroll/scroll_item.js @@ -16,6 +16,58 @@ import {Offering, ITEM_HEIGHT, COMPANY_NAME_WIDTH, OPPORTUNITY_NAME_WIDTH, END_DATE_WIDTH, AAT_STATUS_WIDTH} from './common'; import {generateOfferings} from './random_data'; +@Component({ + selector: 'scroll-item', + properties: { + 'offering': 'offering' + } +}) +@View({ + directives: [ + CompanyNameComponent, + OpportunityNameComponent, + OfferingNameComponent, + StageButtonsComponent, + AccountCellComponent, + FormattedCellComponent + ], + template: ` +
+ + + + + + + + + + + + + + + + + + + + + + +
` +}) export class ScrollItemComponent { offering:Offering; @@ -43,64 +95,3 @@ export class ScrollItemComponent { get endDateWidth() { return `${END_DATE_WIDTH}px`; } get aatStatusWidth() { return `${AAT_STATUS_WIDTH}px`; } } - -export function setupReflectorForScrollItem() { - reflector.registerType(ScrollItemComponent, { - 'factory': () => new ScrollItemComponent(), - 'parameters': [], - 'annotations': [ - new Component({ - selector: 'scroll-item', - properties: { - 'offering': 'offering' - } - }), - new View({ - directives: [ - CompanyNameComponent, - OpportunityNameComponent, - OfferingNameComponent, - StageButtonsComponent, - AccountCellComponent, - FormattedCellComponent - ], - template: ` -
- - - - - - - - - - - - - - - - - - - - - - -
` - }) - ] - }); -} diff --git a/modules/benchmarks/src/tree/tree_benchmark.js b/modules/benchmarks/src/tree/tree_benchmark.js index 60144fecd0..efa2eaa2af 100644 --- a/modules/benchmarks/src/tree/tree_benchmark.js +++ b/modules/benchmarks/src/tree/tree_benchmark.js @@ -20,6 +20,7 @@ import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_compone import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; import {reflector} from 'angular2/src/reflection/reflection'; +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {isPresent} from 'angular2/src/facade/lang'; import {window, document, gc} from 'angular2/src/facade/browser'; @@ -38,245 +39,14 @@ import {Renderer} from 'angular2/src/render/api'; import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; import * as rc from 'angular2/src/render/dom/compiler/compiler'; import * as rvf from 'angular2/src/render/dom/view/view_factory'; -import {Inject} from 'angular2/di'; +import {Inject, bind} from 'angular2/di'; + +function createBindings():List { + return [bind(VIEW_POOL_CAPACITY).toValue(100000)]; +} function setupReflector() { - // TODO: Put the general calls to reflector.register... in a shared file - // as they are needed in all benchmarks... - - reflector.registerType(AppComponent, { - 'factory': () => new AppComponent(), - 'parameters': [], - 'annotations' : [ - new Component({selector: 'app'}), - new View({ - directives: [TreeComponent], - template: `` - })] - }); - - reflector.registerType(TreeComponent, { - 'factory': () => new TreeComponent(), - 'parameters': [], - 'annotations' : [ - new Component({ - selector: 'tree', - properties: {'data': 'data'} - }), - new View({ - directives: [TreeComponent, If], - template: ` {{data.value}} ` - })] - }); - - reflector.registerType(If, { - 'factory': (vp) => new If(vp), - 'parameters': [[ViewContainer]], - 'annotations' : [new Viewport({ - selector: '[if]', - properties: { - 'condition': 'if' - } - })] - }); - - reflector.registerType(Compiler, { - "factory": (reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory) => - new Compiler(reader, compilerCache, tplResolver, cmpUrlMapper, urlResolver, renderer, - protoViewFactory), - "parameters": [[DirectiveMetadataReader], [CompilerCache], [TemplateResolver], [ComponentUrlMapper], - [UrlResolver], [Renderer], [ProtoViewFactory]], - "annotations": [] - }); - - reflector.registerType(CompilerCache, { - 'factory': () => new CompilerCache(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(Parser, { - 'factory': (lexer) => new Parser(lexer), - 'parameters': [[Lexer]], - 'annotations': [] - }); - - reflector.registerType(TemplateLoader, { - 'factory': (xhr, urlResolver) => new TemplateLoader(xhr, urlResolver), - 'parameters': [[XHR], [UrlResolver]], - 'annotations': [] - }); - - reflector.registerType(TemplateResolver, { - 'factory': () => new TemplateResolver(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(XHR, { - 'factory': () => new XHRImpl(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(DirectiveMetadataReader, { - 'factory': () => new DirectiveMetadataReader(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(ShadowDomStrategy, { - "factory": (strategy) => strategy, - "parameters": [[NativeShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(NativeShadowDomStrategy, { - "factory": (styleUrlResolver) => new NativeShadowDomStrategy(styleUrlResolver), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(EmulatedUnscopedShadowDomStrategy, { - "factory": (styleUrlResolver) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, null), - "parameters": [[StyleUrlResolver]], - "annotations": [] - }); - - reflector.registerType(TestabilityRegistry, { - "factory": () => new TestabilityRegistry(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Testability, { - "factory": () => new Testability(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(StyleUrlResolver, { - "factory": (urlResolver) => new StyleUrlResolver(urlResolver), - "parameters": [[UrlResolver]], - "annotations": [] - }); - - reflector.registerType(UrlResolver, { - "factory": () => new UrlResolver(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(Lexer, { - 'factory': () => new Lexer(), - 'parameters': [], - 'annotations': [] - }); - - reflector.registerType(ExceptionHandler, { - "factory": () => new ExceptionHandler(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(LifeCycle, { - "factory": (exHandler, cd) => new LifeCycle(exHandler, cd), - "parameters": [[ExceptionHandler], [ChangeDetector]], - "annotations": [] - }); - - reflector.registerType(ComponentUrlMapper, { - "factory": () => new ComponentUrlMapper(), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(StyleInliner, { - "factory": (xhr, styleUrlResolver, urlResolver) => - new StyleInliner(xhr, styleUrlResolver, urlResolver), - "parameters": [[XHR], [StyleUrlResolver], [UrlResolver]], - "annotations": [] - }); - - reflector.registerType(EventManager, { - "factory": () => new EventManager([], null), - "parameters": [], - "annotations": [] - }); - - reflector.registerType(DynamicComponentLoader, { - "factory": (compiler, reader, renderer, viewFactory) => - new DynamicComponentLoader(compiler, reader, renderer, viewFactory), - "parameters": [[Compiler], [DirectiveMetadataReader], [Renderer], [ViewFactory]], - "annotations": [] - }); - - reflector.registerType(DirectDomRenderer, { - "factory": (renderCompiler, renderViewFactory, shadowDomStrategy) => - new DirectDomRenderer(renderCompiler, renderViewFactory, shadowDomStrategy), - "parameters": [[rc.Compiler], [rvf.ViewFactory], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rc.DefaultCompiler, { - "factory": (parser, shadowDomStrategy, templateLoader) => - new rc.DefaultCompiler(parser, shadowDomStrategy, templateLoader), - "parameters": [[Parser], [ShadowDomStrategy], [TemplateLoader]], - "annotations": [] - }); - - reflector.registerType(rvf.ViewFactory, { - "factory": (capacity, eventManager, shadowDomStrategy) => - new rvf.ViewFactory(capacity, eventManager, shadowDomStrategy), - "parameters": [[new Inject(rvf.VIEW_POOL_CAPACITY)], [EventManager], [ShadowDomStrategy]], - "annotations": [] - }); - - reflector.registerType(rvf.VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); - - reflector.registerType(ProtoViewFactory, { - "factory": (changeDetection, renderer) => - new ProtoViewFactory(changeDetection, renderer), - "parameters": [[ChangeDetection], [Renderer]], - "annotations": [] - }); - - reflector.registerType(ViewFactory, { - "factory": (capacity) => - new ViewFactory(capacity), - "parameters": [[new Inject(VIEW_POOL_CAPACITY)]], - "annotations": [] - }); - - reflector.registerType(VIEW_POOL_CAPACITY, { - "factory": () => 100000, - "parameters": [], - "annotations": [] - }); - - reflector.registerGetters({ - 'value': (a) => a.value, - 'left': (a) => a.left, - 'right': (a) => a.right, - 'initData': (a) => a.initData, - 'data': (a) => a.data, - 'condition': (a) => a.condition, - }); - - reflector.registerSetters({ - 'value': (a,v) => a.value = v, - 'left': (a,v) => a.left = v, - 'right': (a,v) => a.right = v, - 'initData': (a,v) => a.initData = v, - 'data': (a,v) => a.data = v, - 'condition': (a,v) => a.condition = v, - 'if': (a,v) => a['if'] = v, - }); + reflector.reflectionCapabilities = new ReflectionCapabilities(); } var BASELINE_TREE_TEMPLATE; @@ -346,7 +116,7 @@ export function main() { function noop() {} function initNg2() { - bootstrap(AppComponent).then((injector) => { + bootstrap(AppComponent, createBindings()).then((injector) => { lifeCycle = injector.get(LifeCycle); app = injector.get(AppComponent); @@ -475,6 +245,11 @@ class BaseLineIf { } } +@Component({selector: 'app'}) +@View({ + directives: [TreeComponent], + template: `` +}) class AppComponent { initData:TreeNode; constructor() { @@ -484,6 +259,14 @@ class AppComponent { } } +@Component({ + selector: 'tree', + properties: {'data': 'data'} +}) +@View({ + directives: [TreeComponent, If], + template: ` {{data.value}} ` +}) class TreeComponent { data:TreeNode; }