From 6e224d785306c818143c6aab4589717862c154f8 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 9 Jun 2015 11:43:44 -0400 Subject: [PATCH] fix(html-behavior): add htmlName to element with behavior instance reference --- src/html-behavior.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/html-behavior.js b/src/html-behavior.js index 819ffc82..7ab47f37 100644 --- a/src/html-behavior.js +++ b/src/html-behavior.js @@ -61,7 +61,8 @@ export class HtmlBehaviorResource { this.handlesUnbind = ('unbind' in proto); this.handlesAttached = ('attached' in proto); this.handlesDetached = ('detached' in proto); - this.apiName = (this.elementName || this.attributeName).replace(/-([a-z])/g, (m, w) => w.toUpperCase()); + this.htmlName = this.elementName || this.attributeName; + this.apiName = this.htmlName.replace(/-([a-z])/g, (m, w) => w.toUpperCase()); if(attributeName !== null){ if(properties.length === 0){ //default for custom attributes @@ -223,8 +224,8 @@ export class HtmlBehaviorResource { viewFactory = instruction.viewFactory || this.viewFactory; if(viewFactory){ - //TODO: apply element instructions? var results = viewFactory.applyElementInstructions(container, behaviorInstance.executionContext, element); - behaviorInstance.view = viewFactory.create(container, behaviorInstance.executionContext, instruction); + //TODO: apply element instructions? var results = viewFactory.applyElementInstructions(container, executionContext, element); + behaviorInstance.view = viewFactory.create(container, executionContext, instruction); //TODO: register results with view } @@ -254,7 +255,7 @@ export class HtmlBehaviorResource { if(instruction.anchorIsContainer){ if(this.childExpression){ - behaviorInstance.view.addBinding(this.childExpression.createBinding(host, behaviorInstance.executionContext)); + behaviorInstance.view.addBinding(this.childExpression.createBinding(host, executionContext)); } behaviorInstance.view.appendNodesTo(host); @@ -262,26 +263,32 @@ export class HtmlBehaviorResource { behaviorInstance.view.insertNodesBefore(host); } }else if(this.childExpression){ - bindings.push(this.childExpression.createBinding(element, behaviorInstance.executionContext)); + bindings.push(this.childExpression.createBinding(element, executionContext)); } }else if(behaviorInstance.view){ //dynamic element with view behaviorInstance.view.owner = behaviorInstance; if(this.childExpression){ - behaviorInstance.view.addBinding(this.childExpression.createBinding(instruction.host, behaviorInstance.executionContext)); + behaviorInstance.view.addBinding(this.childExpression.createBinding(instruction.host, executionContext)); } }else if(this.childExpression){ //dynamic element without view - bindings.push(this.childExpression.createBinding(instruction.host, behaviorInstance.executionContext)); + bindings.push(this.childExpression.createBinding(instruction.host, executionContext)); } } else if(this.childExpression){ //custom attribute - bindings.push(this.childExpression.createBinding(element, behaviorInstance.executionContext)); + bindings.push(this.childExpression.createBinding(element, executionContext)); } - if(element && !(this.apiName in element)){ - element[this.apiName] = behaviorInstance.executionContext; + if(element){ + if(!(this.apiName in element){ + element[this.apiName] = executionContext; + } + + if(!(this.htmlName in element){ + element[this.htmlName] = behaviorInstance; + } } return behaviorInstance;