Skip to content

Commit

Permalink
fix(html-behavior): add htmlName to element with behavior instance re…
Browse files Browse the repository at this point in the history
…ference
  • Loading branch information
EisenbergEffect committed Jun 9, 2015
1 parent 74cc2be commit 6e224d7
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/html-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -254,34 +255,40 @@ 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);
}else{
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;
Expand Down

0 comments on commit 6e224d7

Please sign in to comment.