Skip to content

Commit

Permalink
fix(behavior): not all attached/detached were cascaded
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
EisenbergEffect committed Mar 22, 2015
1 parent d260bdb commit 31702e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/behavior-instance.js
Expand Up @@ -2,6 +2,7 @@ export class BehaviorInstance {
constructor(behavior, executionContext, instruction){
this.behavior = behavior;
this.executionContext = executionContext;
this.isAttached = false;

var observerLookup = behavior.observerLocator.getObserversLookup(executionContext),
handlesBind = behavior.handlesBind,
Expand Down Expand Up @@ -70,14 +71,32 @@ export class BehaviorInstance {
}

attached(){
if(this.isAttached){
return;
}

this.isAttached = true;

if(this.behavior.handlesAttached){
this.executionContext.attached();
}

if(this.view){
this.view.attached();
}
}

detached(){
if(this.behavior.handlesDetached){
this.executionContext.detached();
if(this.isAttached){
this.isAttached = false;

if(this.view){
this.view.detached();
}

if(this.behavior.handlesDetached){
this.executionContext.detached();
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/view.js
Expand Up @@ -99,7 +99,7 @@ export class View {

insertNodesBefore(refNode){
var parent = refNode.parentNode;
parent.insertBefore(this.fragment, refNode);
parent.insertBefore(this.fragment, refNode);
}

appendNodesTo(parent){
Expand Down Expand Up @@ -169,7 +169,7 @@ export class View {
children = this.children;
for(i = 0, ii = children.length; i < ii; ++i){
children[i].detached();
}
}
}
}
}
}

0 comments on commit 31702e1

Please sign in to comment.