refactor (angular2/test_lib): ts'ifying last of test_lib
Translates last .es6 files in angular2/src/test_lib to TypeScript.
This commit is contained in:
@@ -11,6 +11,7 @@ import {Parser, Lexer, DynamicChangeDetection} from 'angular2/change_detection';
|
||||
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
|
||||
import * as viewModule from 'angular2/src/core/annotations_impl/view';
|
||||
import {Component, Directive, View} from 'angular2/angular2';
|
||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
||||
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
||||
@@ -113,10 +114,10 @@ class MultipleTemplateResolver extends TemplateResolver {
|
||||
MapWrapper.set(this._cache, component, ListWrapper.join(multiplier, ''));
|
||||
}
|
||||
|
||||
resolve(component: Type): View {
|
||||
resolve(component: Type): viewModule.View {
|
||||
var view = super.resolve(component);
|
||||
var myView =
|
||||
new View({template: MapWrapper.get(this._cache, component), directives: view.directives});
|
||||
var myView = new viewModule.View(
|
||||
{template:<string>MapWrapper.get(this._cache, component), directives: view.directives});
|
||||
return myView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,23 @@ export function main() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: `<div></div>`})
|
||||
class DummyComponent {
|
||||
}
|
||||
|
||||
@Directive({selector: '[dummy-decorator]'})
|
||||
class DummyDirective {
|
||||
}
|
||||
|
||||
@Component({selector: 'dynamic-dummy'})
|
||||
class DynamicDummy {
|
||||
constructor(loader: DynamicComponentLoader, location: ElementRef) {
|
||||
loader.loadIntoExistingLocation(DummyComponent, location);
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'app'})
|
||||
@View({
|
||||
directives: [NgIf, NgFor, DummyComponent, DummyDirective, DynamicDummy],
|
||||
@@ -60,7 +77,7 @@ export function main() {
|
||||
</div>
|
||||
|
||||
<div *ng-if="testingWithDirectives">
|
||||
<dummy dummy-decorator *ng-for="#i of list"></dummy>
|
||||
<dummy [dummy-decorator] *ng-for="#i of list"></dummy>
|
||||
</div>
|
||||
|
||||
<div *ng-if="testingDynamicComponents">
|
||||
@@ -69,7 +86,7 @@ export function main() {
|
||||
`
|
||||
})
|
||||
class AppComponent {
|
||||
list: List;
|
||||
list: List<any>;
|
||||
testingPlainComponents: boolean;
|
||||
testingWithDirectives: boolean;
|
||||
testingDynamicComponents: boolean;
|
||||
@@ -98,19 +115,3 @@ class AppComponent {
|
||||
this.testingDynamicComponents = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: `<div></div>`})
|
||||
class DummyComponent {
|
||||
}
|
||||
|
||||
@Directive({selector: '[dummy-decorator]'})
|
||||
class DummyDirective {
|
||||
}
|
||||
|
||||
@Component({selector: 'dynamic-dummy'})
|
||||
class DynamicDummy {
|
||||
constructor(loader: DynamicComponentLoader, location: ElementRef) {
|
||||
loader.loadIntoExistingLocation(DummyComponent, location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import {window, document, gc} from 'angular2/src/facade/browser';
|
||||
import {
|
||||
getIntParameter,
|
||||
getStringParameter,
|
||||
bindAction
|
||||
bindAction,
|
||||
windowProfile,
|
||||
windowProfileEnd
|
||||
} from 'angular2/src/test_lib/benchmark_util';
|
||||
|
||||
import {NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from 'angular2/directives';
|
||||
@@ -18,7 +20,7 @@ import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {bind} from 'angular2/di';
|
||||
import {Inject} from 'angular2/src/di/annotations_impl';
|
||||
import {Inject} from 'angular2/src/di/decorators';
|
||||
|
||||
export const BENCHMARK_TYPE = 'LargetableComponent.benchmarkType';
|
||||
export const LARGETABLE_ROWS = 'LargetableComponent.rows';
|
||||
@@ -73,7 +75,7 @@ export function main() {
|
||||
|
||||
function profile(create, destroy, name) {
|
||||
return function() {
|
||||
window.console.profile(name + ' w GC');
|
||||
windowProfile(name + ' w GC');
|
||||
var duration = 0;
|
||||
var count = 0;
|
||||
while (count++ < 150) {
|
||||
@@ -83,10 +85,10 @@ export function main() {
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
window.console.profileEnd(name + ' w GC');
|
||||
windowProfileEnd(name + ' w GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
|
||||
window.console.profile(name + ' w/o GC');
|
||||
windowProfile(name + ' w/o GC');
|
||||
duration = 0;
|
||||
count = 0;
|
||||
while (count++ < 150) {
|
||||
@@ -95,7 +97,7 @@ export function main() {
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
window.console.profileEnd(name + ' w/o GC');
|
||||
windowProfileEnd(name + ' w/o GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
};
|
||||
}
|
||||
@@ -187,7 +189,8 @@ class BaseLineLargetableComponent {
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.table = DOM.clone(BASELINE_LARGETABLE_TEMPLATE.content.firstChild);
|
||||
var shadowRoot = DOM.createShadowRoot(this.element) DOM.appendChild(shadowRoot, this.table);
|
||||
var shadowRoot = DOM.createShadowRoot(this.element);
|
||||
DOM.appendChild(shadowRoot, this.table);
|
||||
}
|
||||
update(tbody) {
|
||||
var oldBody = DOM.querySelector(this.table, 'tbody');
|
||||
@@ -212,43 +215,33 @@ class CellData {
|
||||
iFn() { return this.i; }
|
||||
}
|
||||
|
||||
@Component({selector: 'app'})
|
||||
@View({
|
||||
directives: [LargetableComponent],
|
||||
template: `<largetable [data]='data' [benchmarkType]='benchmarkType'></largetable>`
|
||||
})
|
||||
class AppComponent {
|
||||
data;
|
||||
benchmarkType: string;
|
||||
}
|
||||
|
||||
@Component({selector: 'largetable', properties: ['data', 'benchmarkType']})
|
||||
@View({
|
||||
directives: [NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault],
|
||||
template: `
|
||||
<table [ng-switch]="benchmarkType">
|
||||
<tbody template="switch-when 'interpolation'">
|
||||
<tr template="for #row of data">
|
||||
<td template="for #column of row">
|
||||
<tbody template="ng-switch-when 'interpolation'">
|
||||
<tr template="ng-for #row of data">
|
||||
<td template="ng-for #column of row">
|
||||
{{column.i}}:{{column.j}}|
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody template="switch-when 'interpolationAttr'">
|
||||
<tr template="for #row of data">
|
||||
<td template="for #column of row" i="{{column.i}}" j="{{column.j}}">
|
||||
<tbody template="ng-switch-when 'interpolationAttr'">
|
||||
<tr template="ng-for #row of data">
|
||||
<td template="ng-for #column of row" i="{{column.i}}" j="{{column.j}}">
|
||||
i,j attrs
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody template="switch-when 'interpolationFn'">
|
||||
<tr template="for #row of data">
|
||||
<td template="for #column of row">
|
||||
<tbody template="ng-switch-when 'interpolationFn'">
|
||||
<tr template="ng-for #row of data">
|
||||
<td template="ng-for #column of row">
|
||||
{{column.iFn()}}:{{column.jFn()}}|
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody template="switch-default">
|
||||
<tbody template="ng-switch-default">
|
||||
<tr>
|
||||
<td>
|
||||
<em>{{benchmarkType}} not yet implemented</em>
|
||||
@@ -262,10 +255,20 @@ class LargetableComponent {
|
||||
benchmarkType: string;
|
||||
rows: number;
|
||||
columns: number;
|
||||
constructor(@Inject(BENCHMARK_TYPE) benchmarkType: BENCHMARK_TYPE,
|
||||
@Inject(LARGETABLE_ROWS) rows: LARGETABLE_ROWS, @Inject(LARGETABLE_COLS) columns) {
|
||||
constructor(@Inject(BENCHMARK_TYPE) benchmarkType, @Inject(LARGETABLE_ROWS) rows,
|
||||
@Inject(LARGETABLE_COLS) columns) {
|
||||
this.benchmarkType = benchmarkType;
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'app'})
|
||||
@View({
|
||||
directives: [LargetableComponent],
|
||||
template: `<largetable [data]='data' [benchmarkType]='benchmarkType'></largetable>`
|
||||
})
|
||||
class AppComponent {
|
||||
data;
|
||||
benchmarkType: string;
|
||||
}
|
||||
|
||||
@@ -10,14 +10,16 @@ import {window, document, gc} from 'angular2/src/facade/browser';
|
||||
import {
|
||||
getIntParameter,
|
||||
getStringParameter,
|
||||
bindAction
|
||||
bindAction,
|
||||
windowProfile,
|
||||
windowProfileEnd
|
||||
} from 'angular2/src/test_lib/benchmark_util';
|
||||
import {NgIf} from 'angular2/directives';
|
||||
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
||||
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
|
||||
import {bind} from 'angular2/di';
|
||||
import {bind, Binding} from 'angular2/di';
|
||||
|
||||
function createBindings(): List {
|
||||
function createBindings(): List<Binding> {
|
||||
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 1;
|
||||
return [bind(APP_VIEW_POOL_CAPACITY).toValue(viewCacheCapacity)];
|
||||
}
|
||||
@@ -53,7 +55,7 @@ export function main() {
|
||||
|
||||
function profile(create, destroy, name) {
|
||||
return function() {
|
||||
window.console.profile(name + ' w GC');
|
||||
windowProfile(name + ' w GC');
|
||||
var duration = 0;
|
||||
var count = 0;
|
||||
while (count++ < 150) {
|
||||
@@ -63,10 +65,10 @@ export function main() {
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
window.console.profileEnd(name + ' w GC');
|
||||
windowProfileEnd(name + ' w GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
|
||||
window.console.profile(name + ' w/o GC');
|
||||
windowProfile(name + ' w/o GC');
|
||||
duration = 0;
|
||||
count = 0;
|
||||
while (count++ < 150) {
|
||||
@@ -75,7 +77,7 @@ export function main() {
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
window.console.profileEnd(name + ' w/o GC');
|
||||
windowProfileEnd(name + ' w/o GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
};
|
||||
}
|
||||
@@ -218,6 +220,16 @@ class BaseLineIf {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'tree', properties: ['data']})
|
||||
@View({
|
||||
directives: [TreeComponent, NgIf],
|
||||
template:
|
||||
`<span> {{data.value}} <span template='ng-if data.right != null'><tree [data]='data.right'></tree></span><span template='ng-if data.left != null'><tree [data]='data.left'></tree></span></span>`
|
||||
})
|
||||
class TreeComponent {
|
||||
data: TreeNode;
|
||||
}
|
||||
|
||||
@Component({selector: 'app'})
|
||||
@View({directives: [TreeComponent], template: `<tree [data]='initData'></tree>`})
|
||||
class AppComponent {
|
||||
@@ -228,13 +240,3 @@ class AppComponent {
|
||||
this.initData = new TreeNode('', null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'tree', properties: ['data']})
|
||||
@View({
|
||||
directives: [TreeComponent, NgIf],
|
||||
template:
|
||||
`<span> {{data.value}} <span template='ng-if data.right != null'><tree [data]='data.right'></tree></span><span template='ng-if data.left != null'><tree [data]='data.left'></tree></span></span>`
|
||||
})
|
||||
class TreeComponent {
|
||||
data: TreeNode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user