From 79399e1c511fb9bf3f26259af43d6ad51e3fdef7 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Thu, 19 Nov 2015 11:14:44 -0800 Subject: [PATCH] feat(dom_renderer): add setBindingDebugInfo method This is used for setting property binding values as attributes on elements when running in dev mode. This implementation will also serialize binding information to template placeholder comment nodes. Closes #5227 --- modules/angular2/src/core/linker/view.ts | 2 +- modules/angular2/src/core/render/api.ts | 3 ++ .../angular2/src/platform/dom/dom_renderer.ts | 33 +++++++++++++++++-- .../angular2/src/web_workers/ui/renderer.ts | 2 ++ .../src/web_workers/worker/renderer.ts | 11 +++++++ .../test/core/linker/integration_spec.ts | 23 +++++++++++-- .../worker/renderer_integration_spec.ts | 21 +++++++++++- 7 files changed, 88 insertions(+), 7 deletions(-) diff --git a/modules/angular2/src/core/linker/view.ts b/modules/angular2/src/core/linker/view.ts index f87e4960ef..5eec1fcbe5 100644 --- a/modules/angular2/src/core/linker/view.ts +++ b/modules/angular2/src/core/linker/view.ts @@ -173,7 +173,7 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher { logBindingUpdate(b: BindingTarget, value: any): void { if (b.isDirective() || b.isElementProperty()) { var elementRef = this.elementRefs[this.elementOffset + b.elementIndex]; - this.renderer.setElementAttribute( + this.renderer.setBindingDebugInfo( elementRef, `${REFLECT_PREFIX}${camelCaseToDashCase(b.name)}`, `${value}`); } } diff --git a/modules/angular2/src/core/render/api.ts b/modules/angular2/src/core/render/api.ts index 8791d22161..fc2461659b 100644 --- a/modules/angular2/src/core/render/api.ts +++ b/modules/angular2/src/core/render/api.ts @@ -300,6 +300,9 @@ export abstract class Renderer { abstract setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string); + abstract setBindingDebugInfo(location: RenderElementRef, propertyName: string, + propertyValue: string); + /** * Sets a (CSS) class on the Element specified via `location`. * diff --git a/modules/angular2/src/platform/dom/dom_renderer.ts b/modules/angular2/src/platform/dom/dom_renderer.ts index 8d5e699eef..e44fef1833 100644 --- a/modules/angular2/src/platform/dom/dom_renderer.ts +++ b/modules/angular2/src/platform/dom/dom_renderer.ts @@ -1,9 +1,11 @@ import {Inject, Injectable, OpaqueToken} from 'angular2/src/core/di'; import {AnimationBuilder} from 'angular2/src/animate/animation_builder'; +import {StringMapWrapper} from 'angular2/src/facade/collection'; import { isPresent, isBlank, + Json, RegExpWrapper, CONST_EXPR, stringify, @@ -41,11 +43,13 @@ import { } from 'angular2/src/core/render/view'; import {ViewEncapsulation} from 'angular2/src/core/metadata'; -// TODO move it once DomAdapter is moved +// TODO move it once DdomAdapter is moved import {DOM} from 'angular2/src/platform/dom/dom_adapter'; const NAMESPACE_URIS = CONST_EXPR({'xlink': 'http://www.w3.org/1999/xlink', 'svg': 'http://www.w3.org/2000/svg'}); +const TEMPLATE_COMMENT_TEXT = 'template bindings={}'; +var TEMPLATE_BINDINGS_EXP = /^template bindings=(.*)$/g; export abstract class DomRenderer extends Renderer implements NodeFactory { abstract registerComponentTemplate(template: RenderComponentTemplate); @@ -118,7 +122,7 @@ export abstract class DomRenderer extends Renderer implements NodeFactory dehydrateView(viewRef: RenderViewRef) { resolveInternalDomView(viewRef).dehydrate(); } createTemplateAnchor(attrNameAndValues: string[]): Node { - return this.createElement('script', attrNameAndValues); + return DOM.createComment(TEMPLATE_COMMENT_TEXT); } abstract createElement(name: string, attrNameAndValues: string[]): Node; abstract mergeElement(existing: Node, attrNameAndValues: string[]); @@ -145,6 +149,31 @@ export abstract class DomRenderer extends Renderer implements NodeFactory } } + /** + * Used only in debug mode to serialize property changes to comment nodes, + * such as