Skip to content

Commit 0685b28

Browse files
authored
Merge pull request #195 from ruiramos/master
Clear _subviews array on _downsertBindings
2 parents beb1bdf + 518afe1 commit 0685b28

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ampersand-view.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ assign(View.prototype, {
416416
_downsertBindings: function() {
417417
var parsedBindings = this._parsedBindings;
418418
if (!this.bindingsSet) return;
419-
if (this._subviews) invokeMap(flatten(this._subviews), 'remove');
419+
if (this._subviews){
420+
invokeMap(flatten(this._subviews), 'remove');
421+
this._subviews = [];
422+
}
420423
this.stopListening();
421424
this.bindingsSet = false;
422425
},

test/main.js

+19
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,22 @@ test('render, remove, render yields consistent subview behavior', function (t) {
977977
event.initMouseEvent('click');
978978
parent.childv.el.dispatchEvent(event);
979979
});
980+
981+
test('the subviews array is empty after the parent view is removed', function(t){
982+
t.plan(2);
983+
var Child = AmpersandView.extend({
984+
template: function() { return document.createElement('div'); }
985+
});
986+
var Parent = AmpersandView.extend({
987+
template: function() { return document.createElement('div'); },
988+
render: function(){
989+
this.renderWithTemplate();
990+
this.renderSubview(new Child(), this.el);
991+
}
992+
});
993+
var parent = new Parent({ el: document.createElement('div') });
994+
parent.render();
995+
t.equal(parent._subviews.length, 1, 'adds child view to subviews array');
996+
parent.remove();
997+
t.equal(parent._subviews.length, 0, 'removes child view from subviews array');
998+
});

0 commit comments

Comments
 (0)