Skip to content

Commit

Permalink
You'd expect endDrag not to be called on an unmounted component
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 25, 2014
1 parent 7059dc7 commit 884ada4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions modules/mixins/DragDropMixin.js
Expand Up @@ -160,24 +160,25 @@ var DragDropMixin = {
},

handleDragEnd(type, e) {

// Note: this method may be invoked even *after* component was unmounted
// This happens if source node was removed from DOM while dragging.
// We mustn't assume being mounted, but still need to gracefully reset state.

NativeDragDropSupport.handleDragEnd();

if (this.isMounted()) {
this.setState({
ownDraggedItemType: null
});
}

var { endDrag } = this._dragSources[type],
didDrop = DragDropStore.didDrop();

DragDropActionCreators.endDragging();

if (!this.isMounted()) {

// Note: this method may be invoked even *after* component was unmounted
// This happens if source node was removed from DOM while dragging.

return;
}

this.setState({
ownDraggedItemType: null
});

if (endDrag) {
endDrag(didDrop, e);
}
Expand Down

0 comments on commit 884ada4

Please sign in to comment.