| 
									
										
										
										
											2015-01-21 12:05:52 -08:00
										 |  |  | import {Parser, Lexer, ChangeDetector, ChangeDetection, jitChangeDetection} | 
					
						
							| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  |   from 'angular2/change_detection'; | 
					
						
							| 
									
										
										
										
											2015-02-16 14:55:00 +01:00
										 |  |  | import {ExceptionHandler} from 'angular2/src/core/exception_handler'; | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 21:20:11 +02:00
										 |  |  | import {bootstrap, Component, Viewport, View, ViewContainer, Compiler, NgElement, Decorator} from 'angular2/angular2'; | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  | import {CompilerCache} from 'angular2/src/core/compiler/compiler'; | 
					
						
							|  |  |  | import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader'; | 
					
						
							| 
									
										
										
										
											2015-04-02 14:40:49 -07:00
										 |  |  | import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; | 
					
						
							| 
									
										
										
										
											2015-02-12 14:44:59 +01:00
										 |  |  | import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; | 
					
						
							| 
									
										
										
										
											2015-04-07 20:54:20 -07:00
										 |  |  | import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy'; | 
					
						
							|  |  |  | import {NativeShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy'; | 
					
						
							|  |  |  | import {EmulatedUnscopedShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy'; | 
					
						
							| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  | import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle'; | 
					
						
							| 
									
										
										
										
											2015-04-02 09:52:00 -07:00
										 |  |  | import {UrlResolver} from 'angular2/src/services/url_resolver'; | 
					
						
							| 
									
										
										
										
											2015-04-02 14:40:49 -07:00
										 |  |  | import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver'; | 
					
						
							| 
									
										
										
										
											2015-02-24 16:05:45 +01:00
										 |  |  | import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; | 
					
						
							| 
									
										
										
										
											2015-04-02 14:40:49 -07:00
										 |  |  | import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner'; | 
					
						
							| 
									
										
										
										
											2015-04-06 13:19:30 -07:00
										 |  |  | import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability'; | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-11 19:57:21 +01:00
										 |  |  | import {reflector} from 'angular2/src/reflection/reflection'; | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  | import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  | import {DOM} from 'angular2/src/dom/dom_adapter'; | 
					
						
							| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  | import {isPresent} from 'angular2/src/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  | import {window, document, gc} from 'angular2/src/facade/browser'; | 
					
						
							| 
									
										
										
										
											2015-02-05 13:08:05 -08:00
										 |  |  | import {getIntParameter, bindAction} from 'angular2/src/test_lib/benchmark_util'; | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 09:52:00 -07:00
										 |  |  | import {XHR} from 'angular2/src/services/xhr'; | 
					
						
							|  |  |  | import {XHRImpl} from 'angular2/src/services/xhr_impl'; | 
					
						
							| 
									
										
										
										
											2015-01-30 09:43:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-20 09:48:16 +01:00
										 |  |  | import {If} from 'angular2/directives'; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  | import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter'; | 
					
						
							| 
									
										
										
										
											2015-02-20 09:48:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 09:52:00 -07:00
										 |  |  | import {EventManager} from 'angular2/src/render/dom/events/event_manager'; | 
					
						
							| 
									
										
										
										
											2015-04-07 20:54:20 -07:00
										 |  |  | import {ViewFactory, VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_factory'; | 
					
						
							|  |  |  | import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory'; | 
					
						
							|  |  |  | import {Renderer} from 'angular2/src/render/api'; | 
					
						
							|  |  |  | import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer'; | 
					
						
							|  |  |  | import * as rc from 'angular2/src/render/dom/compiler/compiler'; | 
					
						
							|  |  |  | import * as rvf from 'angular2/src/render/dom/view/view_factory'; | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  | import {Inject, bind} from 'angular2/di'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createBindings():List { | 
					
						
							|  |  |  |   return [bind(VIEW_POOL_CAPACITY).toValue(100000)]; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-24 10:19:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  | function setupReflector() { | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  |   reflector.reflectionCapabilities = new ReflectionCapabilities(); | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 15:48:18 -08:00
										 |  |  | var BASELINE_TREE_TEMPLATE; | 
					
						
							|  |  |  | var BASELINE_IF_TEMPLATE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  |   BrowserDomAdapter.makeCurrent(); | 
					
						
							|  |  |  |   var maxDepth = getIntParameter('depth'); | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  |   setupReflector(); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 15:48:18 -08:00
										 |  |  |   BASELINE_TREE_TEMPLATE = DOM.createTemplate( | 
					
						
							|  |  |  |     '<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>'); | 
					
						
							|  |  |  |   BASELINE_IF_TEMPLATE = DOM.createTemplate( | 
					
						
							|  |  |  |     '<span template="if"><tree></tree></span>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  |   var app; | 
					
						
							| 
									
										
										
										
											2015-01-14 13:51:16 -08:00
										 |  |  |   var lifeCycle; | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   var baselineRootTreeComponent; | 
					
						
							|  |  |  |   var count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |   function ng2DestroyDom() { | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |     // TODO: We need an initial value as otherwise the getter for data.value will fail
 | 
					
						
							|  |  |  |     // --> this should be already caught in change detection!
 | 
					
						
							|  |  |  |     app.initData = new TreeNode('', null, null); | 
					
						
							| 
									
										
										
										
											2015-01-14 13:51:16 -08:00
										 |  |  |     lifeCycle.tick(); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |   function profile(create, destroy, name) { | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |     return function() { | 
					
						
							| 
									
										
										
										
											2015-01-13 13:06:09 -08:00
										 |  |  |       window.console.profile(name + ' w GC'); | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |       var duration = 0; | 
					
						
							|  |  |  |       var count = 0; | 
					
						
							| 
									
										
										
										
											2015-01-13 13:06:09 -08:00
										 |  |  |       while(count++ < 150) { | 
					
						
							|  |  |  |         gc(); | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |         var start = window.performance.now(); | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |         create(); | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |         duration += window.performance.now() - start; | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |         destroy(); | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-01-13 13:06:09 -08:00
										 |  |  |       window.console.profileEnd(name + ' w GC'); | 
					
						
							|  |  |  |       window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       window.console.profile(name + ' w/o GC'); | 
					
						
							|  |  |  |       duration = 0; | 
					
						
							|  |  |  |       count = 0; | 
					
						
							|  |  |  |       while(count++ < 150) { | 
					
						
							|  |  |  |         var start = window.performance.now(); | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |         create(); | 
					
						
							| 
									
										
										
										
											2015-01-13 13:06:09 -08:00
										 |  |  |         duration += window.performance.now() - start; | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |         destroy(); | 
					
						
							| 
									
										
										
										
											2015-01-13 13:06:09 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |       window.console.profileEnd(name + ' w/o GC'); | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |       window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |   function ng2CreateDom() { | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |     var values = count++ % 2 == 0 ? | 
					
						
							|  |  |  |       ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'] : | 
					
						
							|  |  |  |       ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '-']; | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |     app.initData = buildTree(maxDepth, values, 0); | 
					
						
							| 
									
										
										
										
											2015-01-14 13:51:16 -08:00
										 |  |  |     lifeCycle.tick(); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-07 21:58:40 -08:00
										 |  |  |   function noop() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   function initNg2() { | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  |     bootstrap(AppComponent, createBindings()).then((injector) => { | 
					
						
							| 
									
										
										
										
											2015-01-14 13:51:16 -08:00
										 |  |  |       lifeCycle = injector.get(LifeCycle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |       app = injector.get(AppComponent); | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |       bindAction('#ng2DestroyDom', ng2DestroyDom); | 
					
						
							|  |  |  |       bindAction('#ng2CreateDom', ng2CreateDom); | 
					
						
							|  |  |  |       bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update')); | 
					
						
							|  |  |  |       bindAction('#ng2CreateDomProfile', profile(ng2CreateDom, ng2DestroyDom, 'ng2-create')); | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |   function baselineDestroyDom() { | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |     baselineRootTreeComponent.update(new TreeNode('', null, null)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |   function baselineCreateDom() { | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |     var values = count++ % 2 == 0 ? | 
					
						
							|  |  |  |       ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'] : | 
					
						
							|  |  |  |       ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '-']; | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  |     baselineRootTreeComponent.update(buildTree(maxDepth, values, 0)); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   function initBaseline() { | 
					
						
							| 
									
										
										
										
											2015-01-12 21:56:11 -08:00
										 |  |  |     var tree = DOM.createElement('tree'); | 
					
						
							|  |  |  |     DOM.appendChild(DOM.querySelector(document, 'baseline'), tree); | 
					
						
							|  |  |  |     baselineRootTreeComponent = new BaseLineTreeComponent(tree); | 
					
						
							| 
									
										
										
										
											2015-01-09 18:00:04 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bindAction('#baselineDestroyDom', baselineDestroyDom); | 
					
						
							|  |  |  |     bindAction('#baselineCreateDom', baselineCreateDom); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update')); | 
					
						
							|  |  |  |     bindAction('#baselineCreateDomProfile', profile(baselineCreateDom, baselineDestroyDom, 'baseline-create')); | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 17:50:10 -08:00
										 |  |  |   initNg2(); | 
					
						
							|  |  |  |   initBaseline(); | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TreeNode { | 
					
						
							|  |  |  |   value:string; | 
					
						
							|  |  |  |   left:TreeNode; | 
					
						
							|  |  |  |   right:TreeNode; | 
					
						
							|  |  |  |   constructor(value, left, right) { | 
					
						
							|  |  |  |     this.value = value; | 
					
						
							|  |  |  |     this.left = left; | 
					
						
							|  |  |  |     this.right = right; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function buildTree(maxDepth, values, curDepth) { | 
					
						
							|  |  |  |   if (maxDepth === curDepth) return new TreeNode('', null, null); | 
					
						
							|  |  |  |   return new TreeNode( | 
					
						
							|  |  |  |       values[curDepth], | 
					
						
							|  |  |  |       buildTree(maxDepth, values, curDepth+1), | 
					
						
							|  |  |  |       buildTree(maxDepth, values, curDepth+1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 13:58:26 -08:00
										 |  |  | // http://jsperf.com/nextsibling-vs-childnodes
 | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class BaseLineTreeComponent { | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  |   element; | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |   value:BaseLineInterpolation; | 
					
						
							|  |  |  |   left:BaseLineIf; | 
					
						
							|  |  |  |   right:BaseLineIf; | 
					
						
							| 
									
										
										
										
											2015-01-12 21:56:11 -08:00
										 |  |  |   constructor(element) { | 
					
						
							|  |  |  |     this.element = element; | 
					
						
							|  |  |  |     var clone = DOM.clone(BASELINE_TREE_TEMPLATE.content.firstChild); | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |     var shadowRoot = this.element.createShadowRoot(); | 
					
						
							|  |  |  |     DOM.appendChild(shadowRoot, clone); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 13:58:26 -08:00
										 |  |  |     var child = clone.firstChild; | 
					
						
							|  |  |  |     this.value = new BaseLineInterpolation(child); | 
					
						
							|  |  |  |     child = DOM.nextSibling(child); | 
					
						
							|  |  |  |     this.left = new BaseLineIf(child); | 
					
						
							|  |  |  |     child = DOM.nextSibling(child); | 
					
						
							|  |  |  |     this.right = new BaseLineIf(child); | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   update(value:TreeNode) { | 
					
						
							|  |  |  |     this.value.update(value.value); | 
					
						
							|  |  |  |     this.left.update(value.left); | 
					
						
							|  |  |  |     this.right.update(value.right); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BaseLineInterpolation { | 
					
						
							|  |  |  |   value:string; | 
					
						
							|  |  |  |   textNode; | 
					
						
							|  |  |  |   constructor(textNode) { | 
					
						
							|  |  |  |     this.value = null; | 
					
						
							|  |  |  |     this.textNode = textNode; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   update(value:string) { | 
					
						
							|  |  |  |     if (this.value !== value) { | 
					
						
							|  |  |  |       this.value = value; | 
					
						
							|  |  |  |       DOM.setText(this.textNode, value + ' '); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BaseLineIf { | 
					
						
							|  |  |  |   condition:boolean; | 
					
						
							|  |  |  |   component:BaseLineTreeComponent; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:50:06 -08:00
										 |  |  |   anchor; | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |   constructor(anchor) { | 
					
						
							|  |  |  |     this.anchor = anchor; | 
					
						
							|  |  |  |     this.condition = false; | 
					
						
							|  |  |  |     this.component = null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   update(value:TreeNode) { | 
					
						
							|  |  |  |     var newCondition = isPresent(value); | 
					
						
							|  |  |  |     if (this.condition !== newCondition) { | 
					
						
							|  |  |  |       this.condition = newCondition; | 
					
						
							|  |  |  |       if (isPresent(this.component)) { | 
					
						
							| 
									
										
										
										
											2015-02-25 15:56:08 -08:00
										 |  |  |         DOM.remove(this.component.element); | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |         this.component = null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (this.condition) { | 
					
						
							| 
									
										
										
										
											2015-01-13 11:14:05 -08:00
										 |  |  |         var element = DOM.firstChild(DOM.clone(BASELINE_IF_TEMPLATE).content); | 
					
						
							|  |  |  |         this.anchor.parentNode.insertBefore(element, DOM.nextSibling(this.anchor)); | 
					
						
							|  |  |  |         this.component = new BaseLineTreeComponent(DOM.firstChild(element)); | 
					
						
							| 
									
										
										
										
											2014-12-08 14:17:44 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (isPresent(this.component)) { | 
					
						
							|  |  |  |       this.component.update(value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  | @Component({selector: 'app'}) | 
					
						
							|  |  |  | @View({ | 
					
						
							|  |  |  |   directives: [TreeComponent], | 
					
						
							|  |  |  |   template: `<tree [data]='initData'></tree>` | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | class AppComponent { | 
					
						
							|  |  |  |   initData:TreeNode; | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     // TODO: We need an initial value as otherwise the getter for data.value will fail
 | 
					
						
							|  |  |  |     // --> this should be already caught in change detection!
 | 
					
						
							|  |  |  |     this.initData = new TreeNode('', null, null); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 17:53:36 -07:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'tree', | 
					
						
							|  |  |  |   properties: {'data': 'data'} | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | @View({ | 
					
						
							|  |  |  |   directives: [TreeComponent, If], | 
					
						
							|  |  |  |   template: `<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>` | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2014-12-08 10:57:09 -08:00
										 |  |  | class TreeComponent { | 
					
						
							|  |  |  |   data:TreeNode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |