2015-04-26 11:35:25 -07:00
|
|
|
import {
|
|
|
|
bootstrap,
|
|
|
|
Component,
|
|
|
|
Decorator,
|
2015-04-26 12:15:42 -07:00
|
|
|
View,
|
|
|
|
DynamicComponentLoader,
|
|
|
|
ElementRef,
|
|
|
|
DynamicComponent
|
2015-04-26 11:35:25 -07:00
|
|
|
} from 'angular2/angular2';
|
|
|
|
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';
|
|
|
|
import {If, For} from 'angular2/directives';
|
|
|
|
|
|
|
|
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
|
|
|
|
bindAction('#createComponentsWithDecorators', function() {
|
|
|
|
app.createComponentsWithDecorators();
|
|
|
|
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-04-26 12:15:42 -07:00
|
|
|
directives: [If, For, DummyComponent, DummyDecorator, DynamicDummy],
|
2015-04-26 11:35:25 -07:00
|
|
|
template: `
|
|
|
|
<div *if="testingPlainComponents">
|
|
|
|
<dummy *for="#i of list"></dummy>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div *if="testingWithDecorators">
|
|
|
|
<dummy dummy-decorator *for="#i of list"></dummy>
|
|
|
|
</div>
|
2015-04-26 12:15:42 -07:00
|
|
|
|
|
|
|
<div *if="testingDynamicComponents">
|
|
|
|
<dynamic-dummy *for="#i of list"></dynamic-dummy>
|
|
|
|
</div>
|
2015-04-26 11:35:25 -07:00
|
|
|
`
|
|
|
|
})
|
|
|
|
class AppComponent {
|
|
|
|
list:List;
|
|
|
|
testingPlainComponents:boolean;
|
|
|
|
testingWithDecorators: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;
|
|
|
|
this.testingWithDecorators = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
createComponentsWithDecorators():void {
|
|
|
|
this.list = testList;
|
|
|
|
this.testingWithDecorators = true;
|
|
|
|
}
|
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 {}
|
|
|
|
|
|
|
|
@Decorator({selector: '[dummy-decorator]'})
|
|
|
|
class DummyDecorator {}
|
2015-04-26 12:15:42 -07:00
|
|
|
|
|
|
|
@DynamicComponent({selector: 'dynamic-dummy'})
|
|
|
|
class DynamicDummy {
|
|
|
|
constructor(loader:DynamicComponentLoader, location:ElementRef) {
|
|
|
|
loader.loadIntoExistingLocation(DummyComponent, location);
|
|
|
|
}
|
|
|
|
}
|