2015-04-26 11:35:25 -07:00
|
|
|
import {
|
|
|
|
bootstrap,
|
2015-04-26 12:15:42 -07:00
|
|
|
DynamicComponentLoader,
|
2015-04-28 18:17:00 -07:00
|
|
|
ElementRef
|
|
|
|
} from 'angular2/angular2';
|
2015-04-26 11:35:25 -07:00
|
|
|
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
|
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
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';
|
2015-05-11 17:04:55 -07:00
|
|
|
import {If, NgFor} from 'angular2/directives';
|
2015-04-26 11:35:25 -07:00
|
|
|
|
2015-04-28 18:17:00 -07:00
|
|
|
// TODO(radokirov): Once the application is transpiled by TS instead of Traceur,
|
|
|
|
// add those imports back into 'angular2/angular2';
|
2015-04-30 13:38:40 -07:00
|
|
|
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
2015-04-28 18:17:00 -07:00
|
|
|
import {View} from 'angular2/src/core/annotations_impl/view';
|
|
|
|
|
2015-04-26 11:35:25 -07:00
|
|
|
var testList = null;
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
|
|
|
var size = getIntParameter('size');
|
|
|
|
testList = ListWrapper.createFixedSize(size);
|
|
|
|
|
|
|
|
bootstrap(AppComponent).then((ref) => {
|
|
|
|
var injector = ref.injector;
|
|
|
|
var app:AppComponent = injector.get(AppComponent);
|
|
|
|
var lifeCycle = injector.get(LifeCycle);
|
|
|
|
|
|
|
|
bindAction('#reset', function() {
|
|
|
|
app.reset();
|
|
|
|
lifeCycle.tick();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Baseline (plain components)
|
|
|
|
bindAction('#createPlainComponents', function() {
|
|
|
|
app.createPlainComponents();
|
|
|
|
lifeCycle.tick();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Components with decorators
|
2015-04-30 13:38:40 -07:00
|
|
|
bindAction('#createComponentsWithDirectives', function() {
|
|
|
|
app.createComponentsWithDirectives();
|
2015-04-26 11:35:25 -07:00
|
|
|
lifeCycle.tick();
|
|
|
|
});
|
2015-04-26 12:15:42 -07:00
|
|
|
|
|
|
|
// Components with decorators
|
|
|
|
bindAction('#createDynamicComponents', function() {
|
|
|
|
app.createDynamicComponents();
|
|
|
|
lifeCycle.tick();
|
|
|
|
});
|
2015-04-26 11:35:25 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'app'})
|
|
|
|
@View({
|
2015-05-11 17:04:55 -07:00
|
|
|
directives: [If, NgFor, DummyComponent, DummyDirective, DynamicDummy],
|
2015-04-26 11:35:25 -07:00
|
|
|
template: `
|
2015-05-11 15:58:59 -07:00
|
|
|
<div *ng-if="testingPlainComponents">
|
2015-05-11 17:04:55 -07:00
|
|
|
<dummy *ng-for="#i of list"></dummy>
|
2015-04-26 11:35:25 -07:00
|
|
|
</div>
|
|
|
|
|
2015-05-11 15:58:59 -07:00
|
|
|
<div *ng-if="testingWithDirectives">
|
2015-05-11 17:04:55 -07:00
|
|
|
<dummy dummy-decorator *ng-for="#i of list"></dummy>
|
2015-04-26 11:35:25 -07:00
|
|
|
</div>
|
2015-04-26 12:15:42 -07:00
|
|
|
|
2015-05-11 15:58:59 -07:00
|
|
|
<div *ng-if="testingDynamicComponents">
|
2015-05-11 17:04:55 -07:00
|
|
|
<dynamic-dummy *ng-for="#i of list"></dynamic-dummy>
|
2015-04-26 12:15:42 -07:00
|
|
|
</div>
|
2015-04-26 11:35:25 -07:00
|
|
|
`
|
|
|
|
})
|
|
|
|
class AppComponent {
|
|
|
|
list:List;
|
|
|
|
testingPlainComponents:boolean;
|
2015-04-30 13:38:40 -07:00
|
|
|
testingWithDirectives:boolean;
|
2015-04-26 12:15:42 -07:00
|
|
|
testingDynamicComponents:boolean;
|
2015-04-26 11:35:25 -07:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset():void {
|
|
|
|
this.list = [];
|
|
|
|
this.testingPlainComponents = false;
|
2015-04-30 13:38:40 -07:00
|
|
|
this.testingWithDirectives = false;
|
2015-04-26 12:15:42 -07:00
|
|
|
this.testingDynamicComponents = false;
|
2015-04-26 11:35:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
createPlainComponents():void {
|
|
|
|
this.list = testList;
|
|
|
|
this.testingPlainComponents = true;
|
|
|
|
}
|
|
|
|
|
2015-04-30 13:38:40 -07:00
|
|
|
createComponentsWithDirectives():void {
|
2015-04-26 11:35:25 -07:00
|
|
|
this.list = testList;
|
2015-04-30 13:38:40 -07:00
|
|
|
this.testingWithDirectives = true;
|
2015-04-26 11:35:25 -07:00
|
|
|
}
|
2015-04-26 12:15:42 -07:00
|
|
|
|
|
|
|
createDynamicComponents():void {
|
|
|
|
this.list = testList;
|
|
|
|
this.testingDynamicComponents = true;
|
|
|
|
}
|
2015-04-26 11:35:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'dummy'})
|
|
|
|
@View({template: `<div></div>`})
|
|
|
|
class DummyComponent {}
|
|
|
|
|
2015-04-30 13:38:40 -07:00
|
|
|
@Directive({selector: '[dummy-decorator]'})
|
|
|
|
class DummyDirective {}
|
2015-04-26 12:15:42 -07:00
|
|
|
|
2015-04-29 16:52:34 -07:00
|
|
|
@Component({selector: 'dynamic-dummy'})
|
2015-04-26 12:15:42 -07:00
|
|
|
class DynamicDummy {
|
|
|
|
constructor(loader:DynamicComponentLoader, location:ElementRef) {
|
|
|
|
loader.loadIntoExistingLocation(DummyComponent, location);
|
|
|
|
}
|
|
|
|
}
|