Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Always return 'this' from Thorax.View.render(). #312

Merged
merged 2 commits into from
Feb 5, 2014
Merged
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
4 changes: 2 additions & 2 deletions src/thorax.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Thorax.View = Backbone.View.extend({
var self = this;
// NOP for destroyed views
if (!self.el) {
return;
return self;
}

Thorax.runSection('thorax-render', {name: self.name}, function() {
Expand Down Expand Up @@ -199,7 +199,7 @@ Thorax.View = Backbone.View.extend({
self._rendering = false;
}
});
return output;
return self;
},

context: function() {
Expand Down
39 changes: 30 additions & 9 deletions test/src/thorax.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,63 @@ describe('core', function() {
}).to['throw']();
});

it("returns context on render()", function () {
$('body').append('<div id="test-target-container"><div id="test-target"></div></div>');

view = new Thorax.View({
template: function() { return 'testing123'; },
el: $('#test-target')[0]
});
expect(view.render()).to.equal(view);

// Nuke the view and test again.
view.release();
expect(view.render()).to.equal(view);

$('#test-target-container').remove();
});

it("render() subclassing", function() {
var result;
var a = new Thorax.View({
render: function() {
Thorax.View.prototype.render.call(this, '<p>a</p>');
return Thorax.View.prototype.render.call(this, '<p>a</p>');
}
});
a.render();
result = a.render();
expect(result).to.equal(a);

var b = new Thorax.View({
render: function() {
Thorax.View.prototype.render.call(this, $('<p>b</p>'));
return Thorax.View.prototype.render.call(this, $('<p>b</p>'));
}
});
b.render();
result = b.render();
expect(result).to.equal(b);

var c = new Thorax.View({
render: function() {
var el = document.createElement('p');
el.innerHTML = 'c';
Thorax.View.prototype.render.call(this, el);
return Thorax.View.prototype.render.call(this, el);
}
});
c.render();
result = c.render();
expect(result).to.equal(c);

var d = new Thorax.View({
render: function() {
var view = new Thorax.View({
render: function() {
Thorax.View.prototype.render.call(this, '<p>d</p>');
return Thorax.View.prototype.render.call(this, '<p>d</p>');
}
});
view.render();
Thorax.View.prototype.render.call(this, view);
return Thorax.View.prototype.render.call(this, view);
}
});
d.render();
result = d.render();
expect(result).to.equal(d);

expect(a._renderCount).to.equal(1, '_renderCount incrimented');
expect(b._renderCount).to.equal(1, '_renderCount incrimented');
Expand Down