forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
107 lines (88 loc) · 2.78 KB
/
index.ts
File metadata and controls
107 lines (88 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {bootstrap} from 'angular2/platform/browser';
import {Component, Directive, DynamicComponentLoader, ViewContainerRef} from 'angular2/core';
import {NgIf, NgFor} from 'angular2/common';
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {ListWrapper} from 'angular2/src/facade/collection';
import {getIntParameter, bindAction} from 'angular2/src/testing/benchmark_util';
var testList = null;
export function main() {
var size = getIntParameter('size');
testList = ListWrapper.createFixedSize(size);
bootstrap(AppComponent)
.then((ref) => {
var injector = ref.injector;
var app: AppComponent = ref.instance;
var appRef = injector.get(ApplicationRef);
bindAction('#reset', function() {
app.reset();
appRef.tick();
});
// Baseline (plain components)
bindAction('#createPlainComponents', function() {
app.createPlainComponents();
appRef.tick();
});
// Components with decorators
bindAction('#createComponentsWithDirectives', function() {
app.createComponentsWithDirectives();
appRef.tick();
});
// Components with decorators
bindAction('#createDynamicComponents', function() {
app.createDynamicComponents();
appRef.tick();
});
});
}
@Component({selector: 'dummy', template: `<div></div>`})
class DummyComponent {
}
@Directive({selector: '[dummy-decorator]'})
class DummyDirective {
}
@Directive({selector: 'dynamic-dummy'})
class DynamicDummy {
constructor(loader: DynamicComponentLoader, location: ViewContainerRef) {
loader.loadNextToLocation(DummyComponent, location);
}
}
@Component({
selector: 'app',
directives: [NgIf, NgFor, DummyComponent, DummyDirective, DynamicDummy],
template: `
<div *ngIf="testingPlainComponents">
<dummy *ngFor="#i of list"></dummy>
</div>
<div *ngIf="testingWithDirectives">
<dummy dummy-decorator *ngFor="#i of list"></dummy>
</div>
<div *ngIf="testingDynamicComponents">
<dynamic-dummy *ngFor="#i of list"></dynamic-dummy>
</div>
`
})
class AppComponent {
list: any[];
testingPlainComponents: boolean;
testingWithDirectives: boolean;
testingDynamicComponents: boolean;
constructor() { this.reset(); }
reset(): void {
this.list = [];
this.testingPlainComponents = false;
this.testingWithDirectives = false;
this.testingDynamicComponents = false;
}
createPlainComponents(): void {
this.list = testList;
this.testingPlainComponents = true;
}
createComponentsWithDirectives(): void {
this.list = testList;
this.testingWithDirectives = true;
}
createDynamicComponents(): void {
this.list = testList;
this.testingDynamicComponents = true;
}
}