Skip to content

Commit 8a3d905

Browse files
committed
feat(TreeBenchmark): use angular2 If directive
1 parent 58ba700 commit 8a3d905

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

modules/benchmarks/src/tree/tree_benchmark.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {getIntParameter, bindAction} from 'angular2/src/test_lib/benchmark_util'
1919
import {XHR} from 'angular2/src/core/compiler/xhr/xhr';
2020
import {XHRImpl} from 'angular2/src/core/compiler/xhr/xhr_impl';
2121

22+
import {If} from 'angular2/directives';
23+
2224
function setupReflector() {
2325
// TODO: Put the general calls to reflector.register... in a shared file
2426
// as they are needed in all benchmarks...
@@ -43,18 +45,18 @@ function setupReflector() {
4345
bind: {'data': 'data'}
4446
}),
4547
new Template({
46-
directives: [TreeComponent, NgIf],
47-
inline: `<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>`
48+
directives: [TreeComponent, If],
49+
inline: `<span> {{data.value}} <span template='if data.right != null'><tree [data]='data.right'></tree></span><span template='if data.left != null'><tree [data]='data.left'></tree></span></span>`
4850
})]
4951
});
5052

51-
reflector.registerType(NgIf, {
52-
'factory': (vp) => new NgIf(vp),
53+
reflector.registerType(If, {
54+
'factory': (vp) => new If(vp),
5355
'parameters': [[ViewContainer]],
5456
'annotations' : [new Viewport({
55-
selector: '[ng-if]',
57+
selector: '[if]',
5658
bind: {
57-
'ngIf': 'ng-if'
59+
'condition': 'if'
5860
}
5961
})]
6062
});
@@ -133,7 +135,8 @@ function setupReflector() {
133135
'left': (a) => a.left,
134136
'right': (a) => a.right,
135137
'initData': (a) => a.initData,
136-
'data': (a) => a.data
138+
'data': (a) => a.data,
139+
'condition': (a) => a.condition,
137140
});
138141

139142
reflector.registerSetters({
@@ -142,7 +145,7 @@ function setupReflector() {
142145
'right': (a,v) => a.right = v,
143146
'initData': (a,v) => a.initData = v,
144147
'data': (a,v) => a.data = v,
145-
'ngIf': (a,v) => a.ngIf = v
148+
'condition': (a,v) => a.condition = v,
146149
});
147150
}
148151

@@ -265,7 +268,7 @@ function buildTree(maxDepth, values, curDepth) {
265268
var BASELINE_TREE_TEMPLATE = DOM.createTemplate(
266269
'<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>');
267270
var BASELINE_IF_TEMPLATE = DOM.createTemplate(
268-
'<span template="ng-if"><tree></tree></span>');
271+
'<span template="if"><tree></tree></span>');
269272
// http://jsperf.com/nextsibling-vs-childnodes
270273

271274
class BaseLineTreeComponent {
@@ -346,22 +349,6 @@ class AppComponent {
346349
}
347350
}
348351

349-
// TODO: Move this into a reusable directive in the 'core' module!
350-
class NgIf {
351-
_viewContainer:ViewContainer;
352-
constructor(viewContainer:ViewContainer) {
353-
this._viewContainer = viewContainer;
354-
}
355-
set ngIf(value:boolean) {
356-
if (this._viewContainer.length > 0) {
357-
this._viewContainer.remove(0);
358-
}
359-
if (value) {
360-
this._viewContainer.create();
361-
}
362-
}
363-
}
364-
365352
class TreeComponent {
366353
data:TreeNode;
367354
}

0 commit comments

Comments
 (0)