Skip to content

Commit

Permalink
Fix 684: deselect row before removing it on store notify
Browse files Browse the repository at this point in the history
  • Loading branch information
edhager committed Sep 23, 2013
1 parent 2273d9e commit a8c3934
Show file tree
Hide file tree
Showing 2 changed files with 294 additions and 38 deletions.
37 changes: 27 additions & 10 deletions Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,30 +335,44 @@ return declare(null, {
// or to the list/grid's removeRow method otherwise.

var self = this,
store = this.store;

store = this.store,
beforeSignal, afterSignal;

// Remove anything previously configured
if(this._deselectionSignal){
this._deselectionSignal.remove();
if(this._removeDeselectSignals){
this._removeDeselectSignals();
}

// Is there currently an observable store?
if(store && store.notify){
this._deselectionSignal = aspect.after(store, "notify", function(object, idToUpdate){
var id = idToUpdate || (object && object[this.idProperty || "id"]);
function ifSelected(object, idToUpdate, methodName){
// Calls a method if the row corresponding to the object is selected.
var id = idToUpdate || (object && object[self.idProperty || "id"]);
if (id != null) {
var row = self.row(id),
selection = row && self.selection[row.id];
// Is the row currently in the selection list.
if(selection){
// Ensure consistency between DOM and state on add/put;
// prune from selection on remove
self[(object ? "" : "de") + "select"](row, null, selection);
self[methodName](row, null, selection);
}
}
}
beforeSignal = aspect.before(store, "notify", function(object, idToUpdate){
if (!object){
// Deselect the node if it is selected. This allows the
// deselect event to reference the row element while it still exists in the DOM.
ifSelected(object, idToUpdate, "deselect");
}
});
afterSignal = aspect.after(store, "notify", function(object, idToUpdate){
ifSelected(object, idToUpdate, "select");
}, true);
this._removeDeselectSignals = function(){
beforeSignal.remove();
afterSignal.remove();
}
}else{
this._deselectionSignal = aspect.before(this, "removeRow", function(rowElement, justCleanup){
beforeSignal = aspect.before(this, "removeRow", function(rowElement, justCleanup){
var row;
if(!justCleanup){
row = this.row(rowElement);
Expand All @@ -368,6 +382,9 @@ return declare(null, {
}
}
});
this._removeDeselectSignals = function(){
beforeSignal.remove();
}
}
},

Expand Down
Loading

0 comments on commit a8c3934

Please sign in to comment.