Skip to content

Commit

Permalink
fix cpt disposal
Browse files Browse the repository at this point in the history
fixes #129
closes #130
  • Loading branch information
Bertrand Laporte authored and divdavem committed Apr 15, 2014
1 parent 7bdf786 commit 0ff4d3f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hsp/rt/$root.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ var $CptNode = klass({
this.controller = null;
this.ctlAttributes = null;
this.template = null;
if (this.node1) {
this.node1=null;
this.node2=null;
}
},

/**
Expand Down Expand Up @@ -614,6 +618,9 @@ var $CptNode = klass({
// Warning: this method may be called even if the object referenced by the path didn't change
// because we observe all the properties of the object on the path - so we need to detect
// first if one of the objects on the path really changed
if (!this.parent && !this.root) {
return; // object has been disposed, but notification callback is still in the call stack
}
var pos = this.getPathObjects(), opos=this._observedPathObjects;
var sz = pos? pos.length : -1;
var osz = opos? opos.length : -1;
Expand Down
50 changes: 50 additions & 0 deletions public/test/rt/cptattelements4.spec.hsp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ var ListCtrl = klass({
</#list>
# /template

# template tabA(tab)
{tab.title}
# /template

var TabCtrl = klass({
$init: function () {
this.tabs = [{title:"Tab A", template: tabA},{title:"Tab B"}];
},
removeTab: function (event, index) {
this.tabs.splice(index, 1);
try {
event.preventDefault();
} catch (ex) {
// preventDefault is not supported on IE8!!
}
}
});

# template tabs using c:TabCtrl
<ul class="nav nav-tabs">
{foreach index,tab in c.tabs}
<li><a href="#">
{if tab.template}
<#tab.template tab="{tab}" />
{else}
{tab.title}
{/if}
&nbsp;/&nbsp;<a class="close" onclick="{c.removeTab(event, index)}">&times;</a>
</a></li>
{/foreach}
</ul>
# /template

var EMPTY_MSG=".nodata";
var OPTIONS="ul .opt";

Expand Down Expand Up @@ -183,6 +216,23 @@ describe("Component attribute elements (4)", function () {
h.$dispose();
});

it("validates that path change event are ignored when cpt object is disposed", function() {
var h=ht.newTestContext();
tabs().render(h.container);

expect(h("li .close").length).to.equal(2);

// remove first tab
h("li .close").item(0).click();
expect(h("li .close").length).to.equal(1);

// remove 2nd tab
h("li .close").item(0).click();
expect(h("li .close").length).to.equal(0);

h.$dispose();
});

// TODO validate that parent is passed to controller $init

});

0 comments on commit 0ff4d3f

Please sign in to comment.