11import { Inject , Injectable , OpaqueToken } from 'angular2/src/core/di' ;
22import { AnimationBuilder } from 'angular2/src/animate/animation_builder' ;
33
4+ import { StringMapWrapper } from 'angular2/src/facade/collection' ;
45import {
56 isPresent ,
67 isBlank ,
8+ Json ,
79 RegExpWrapper ,
810 CONST_EXPR ,
911 stringify ,
@@ -41,11 +43,13 @@ import {
4143} from 'angular2/src/core/render/view' ;
4244import { ViewEncapsulation } from 'angular2/src/core/metadata' ;
4345
44- // TODO move it once DomAdapter is moved
46+ // TODO move it once DdomAdapter is moved
4547import { DOM } from 'angular2/src/platform/dom/dom_adapter' ;
4648
4749const NAMESPACE_URIS =
4850 CONST_EXPR ( { 'xlink' : 'http://www.w3.org/1999/xlink' , 'svg' : 'http://www.w3.org/2000/svg' } ) ;
51+ const TEMPLATE_COMMENT_TEXT = 'template bindings={}' ;
52+ var TEMPLATE_BINDINGS_EXP = / ^ t e m p l a t e b i n d i n g s = ( .* ) $ / g;
4953
5054export abstract class DomRenderer extends Renderer implements NodeFactory < Node > {
5155 abstract registerComponentTemplate ( template : RenderComponentTemplate ) ;
@@ -118,7 +122,7 @@ export abstract class DomRenderer extends Renderer implements NodeFactory<Node>
118122 dehydrateView ( viewRef : RenderViewRef ) { resolveInternalDomView ( viewRef ) . dehydrate ( ) ; }
119123
120124 createTemplateAnchor ( attrNameAndValues : string [ ] ) : Node {
121- return this . createElement ( 'script' , attrNameAndValues ) ;
125+ return DOM . createComment ( TEMPLATE_COMMENT_TEXT ) ;
122126 }
123127 abstract createElement ( name : string , attrNameAndValues : string [ ] ) : Node ;
124128 abstract mergeElement ( existing : Node , attrNameAndValues : string [ ] ) ;
@@ -145,6 +149,31 @@ export abstract class DomRenderer extends Renderer implements NodeFactory<Node>
145149 }
146150 }
147151
152+ /**
153+ * Used only in debug mode to serialize property changes to comment nodes,
154+ * such as <template> placeholders.
155+ */
156+ setBindingDebugInfo ( location : RenderElementRef , propertyName : string ,
157+ propertyValue : string ) : void {
158+ var view : DefaultRenderView < Node > = resolveInternalDomView ( location . renderView ) ;
159+ var element = view . boundElements [ location . boundElementIndex ] ;
160+ var dashCasedPropertyName = camelCaseToDashCase ( propertyName ) ;
161+ if ( DOM . isCommentNode ( element ) ) {
162+ var existingBindings = RegExpWrapper . firstMatch (
163+ TEMPLATE_BINDINGS_EXP , StringWrapper . replaceAll ( DOM . getText ( element ) , / \n / g, '' ) ) ;
164+ var parsedBindings = Json . parse ( existingBindings [ 1 ] ) ;
165+ if ( isPresent ( propertyValue ) ) {
166+ parsedBindings [ dashCasedPropertyName ] = propertyValue ;
167+ } else {
168+ StringMapWrapper . delete ( parsedBindings , dashCasedPropertyName ) ;
169+ }
170+ DOM . setText ( element , StringWrapper . replace ( TEMPLATE_COMMENT_TEXT , '{}' ,
171+ Json . stringify ( parsedBindings ) ) ) ;
172+ } else {
173+ this . setElementAttribute ( location , propertyName , propertyValue ) ;
174+ }
175+ }
176+
148177 setElementClass ( location : RenderElementRef , className : string , isAdd : boolean ) : void {
149178 var view = resolveInternalDomView ( location . renderView ) ;
150179 var element = view . boundElements [ location . boundElementIndex ] ;
0 commit comments