11import 'dart:html' ;
2+ import 'dart:convert' ;
23
34import 'package:angular2/src/core/change_detection/change_detection.dart'
45 show ChangeDetectionStrategy, ChangeDetectorState;
@@ -14,7 +15,12 @@ import 'package:angular2/src/core/render/api.dart' show RenderComponentType;
1415import 'package:angular2/src/debug/debug_context.dart'
1516 show StaticNodeDebugInfo, DebugContext;
1617import 'package:angular2/src/debug/debug_node.dart'
17- show DebugElement, DebugNode, getDebugNode, indexDebugNode;
18+ show
19+ DebugElement,
20+ DebugNode,
21+ getDebugNode,
22+ indexDebugNode,
23+ DebugEventListener;
1824import 'package:angular2/src/platform/dom/dom_renderer.dart'
1925 show DomRootRenderer;
2026
@@ -24,6 +30,10 @@ export 'package:angular2/src/debug/debug_context.dart'
2430
2531WtfScopeFn _scope_check = wtfCreateScope ('AppView#check(ascii id)' );
2632
33+ // RegExp to match anchor comment when logging bindings for debugging.
34+ RegExp _TEMPLATE_BINDINGS_EXP = new RegExp (r'^template bindings=(.*)$' );
35+ const _TEMPLATE_COMMENT_TEXT = 'template bindings={}' ;
36+
2737class DebugAppView <T > extends AppView <T > {
2838 static bool profilingEnabled = false ;
2939
@@ -142,6 +152,31 @@ class DebugAppView<T> extends AppView<T> {
142152 };
143153 }
144154
155+ Function listen (dynamic renderElement, String name, Function callback) {
156+ var debugEl = getDebugNode (renderElement);
157+ if (debugEl != null ) {
158+ debugEl.listeners.add (new DebugEventListener (name, callback));
159+ }
160+ return super .listen (renderElement, name, callback);
161+ }
162+
163+ /// Used only in debug mode to serialize property changes to dom nodes as
164+ /// attributes.
165+ void setBindingDebugInfo (
166+ dynamic renderElement, String propertyName, String propertyValue) {
167+ if (renderElement is Comment ) {
168+ var existingBindings = _TEMPLATE_BINDINGS_EXP
169+ .firstMatch (renderElement.text.replaceAll (new RegExp (r'\n' ), '' ));
170+ var parsedBindings = JSON .decode (existingBindings[1 ]);
171+ parsedBindings[propertyName] = propertyValue;
172+ String debugStr =
173+ const JsonEncoder .withIndent (' ' ).convert (parsedBindings);
174+ renderElement.text = _TEMPLATE_COMMENT_TEXT .replaceFirst ('{}' , debugStr);
175+ } else {
176+ setAttr (renderElement, propertyName, propertyValue);
177+ }
178+ }
179+
145180 /// Sets up current debug context to node so that failures can be associated
146181 /// with template source location and DebugElement.
147182 DebugContext dbg (num nodeIndex, num rowNum, num colNum) =>
0 commit comments