Skip to content

Commit

Permalink
Merge pull request #181 from herkyl/master
Browse files Browse the repository at this point in the history
Run _upsertBindings before custom render function
  • Loading branch information
RickButler committed Jun 7, 2018
2 parents f73dd27 + bfd3593 commit 283b599
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ampersand-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ assign(View.prototype, {
},
set: function(fn) {
this._render = function() {
this._upsertBindings();
fn.apply(this, arguments);
this._rendered = true;
return this;
Expand All @@ -407,6 +408,7 @@ assign(View.prototype, {
this._remove = function() {
fn.apply(this, arguments);
this._rendered = false;
this._downsertBindings();
return this;
};
}
Expand Down
20 changes: 20 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,23 @@ test('the subviews array is empty after the parent view is removed', function(t)
parent.remove();
t.equal(parent._subviews.length, 0, 'removes child view from subviews array');
});

test('custom render and remove functions should maintain bindings behavior ', function (t) {
t.plan(3);
var View = AmpersandView.extend({
render: function () {
this.renderWithTemplate(this);
},
remove: function () {
if (this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el);
},
template: function () { return document.createElement('div'); }
});
var view = new View({ el: document.createElement('div') });
view.render();
t.equal(view.bindingsSet, true, 'verify initial state, constructor and render calls _upsertBindings, bindingsSet should be true');
view.remove();
t.equal(view.bindingsSet, false, 'custom remove calls _downsertBindings and bindingsSet is false');
view.render();
t.equal(view.bindingsSet, true, 'custom render calls _upsertBindings and bindingsSet is true');
});

0 comments on commit 283b599

Please sign in to comment.