Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions hsp/rt/cptwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ var CptWrapper = klass({

$dispose : function () {
// unobserve properties and events
var c=this.cpt;
if (c && c.$dispose) {
// call $dispose before removing the observer in case
// there is a last synchronization to do
c.$dispose();
}
if (this._cptChgeCb) {
json.unobserve(this.cpt, this._cptChgeCb);
this._cptChgeCb = null;
}
var c=this.cpt;
if (c) {
if (c.$dispose) {
c.$dispose();
}
c.nodeInstance = null;
this.cpt = null;
}
Expand Down Expand Up @@ -397,7 +399,7 @@ function createCptWrapper(Ctl, cptArgs) {

if (attributes) {
for (var k in attributes) {

// set the template attribute value on the component instance
if (attributes.hasOwnProperty(k)) {
att=cw.cpt.attributes[k];
Expand Down
46 changes: 46 additions & 0 deletions public/test/rt/cptintegration.spec.hsp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,58 @@ var TestCtrl1=klass({
# /template


var TextareaWithOnDisposeCtrl=klass({
attributes:{
text: {type:"string",binding:"2-way"}
},
$refresh: function() {
this.onTextChange();
},
onTextChange: function () {
var textarea = this.$getElement(0);
if (textarea) {
textarea.value = this.text;
}
},
$dispose: function() {
var textarea = this.$getElement(0);
if (textarea) {
this.text = textarea.value;
}
}
});

# template textareaWithOnDispose using c:TextareaWithOnDisposeCtrl
<textarea></textarea>
# /template

# template useTextarea(data)
{if data.visible}
<#textareaWithOnDispose text="{data.text}" />
{/if}
# /template

describe("External component integration", function () {
beforeEach(function() {
msg='';
refreshCount=0;
});

it("validates $dispose is called before bindings are removed", function () {
var firstValue = "hello";
var h=ht.newTestContext(), d={visible: true, text:firstValue};
useTextarea(d).render(h.container);
var textarea = h("textarea");
expect(textarea.value()).to.equal(firstValue);
expect(d.text).to.equal(firstValue);
var secondValue = "new value";
textarea.type(secondValue);
expect(textarea.value()).to.equal(secondValue);
expect(d.text).to.equal(firstValue); // still the first value because the update in the data model is on dispose
h.$set(d,"visible", false);
expect(d.text).to.equal(secondValue); // data model update normally happens when disposing the textarea on the previous line
});

it("validates $getElement() method through direct template call", function() {
var h=ht.newTestContext(), d={value:"hello"};

Expand Down