Permalink
Browse files

Refactor collection:remove rendering event to use removeItem

  • Loading branch information...
1 parent c47336b commit b66a04794d040facbabfeaf9c1b1bb7b44d7ea3d Ryan Eastridge committed Dec 27, 2012
Showing with 7 additions and 12 deletions.
  1. +7 −12 src/collection.js
View
@@ -117,11 +117,13 @@ _.extend(Thorax.View.prototype, {
if (!viewEl.length) {
return false;
}
- var viewCid = viewEl.attr(viewCidAttributeName);
- if (this.children[viewCid]) {
- delete this.children[viewCid];
- }
viewEl.remove();
+ var viewCid = viewEl.attr(viewCidAttributeName),
+ child = this.children[viewCid];
+ if (child) {
+ this._removeChild(child);
+ child.destroy();
+ }
return true;
},
renderCollection: function() {
@@ -212,14 +214,7 @@ _.extend(Thorax.View.prototype, {
},
remove: function(model) {
var $el = this.getCollectionElement();
- $el.find('[' + modelCidAttributeName + '="' + model.cid + '"]').remove();
- for (var cid in this.children) {
- if (this.children[cid].model && this.children[cid].model.cid === model.cid) {
- this.children[cid].destroy();
- delete this.children[cid];
- break;
- }
- }
+ this.removeItem(model);
this.collection.length === 0 && $el.length && handleChangeFromNotEmptyToEmpty.call(this);
}
}

0 comments on commit b66a047

Please sign in to comment.