Skip to content

Commit

Permalink
Add early invariants for bad method results
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 1, 2015
1 parent fdad029 commit 18a2cad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/ComponentDragSource.js
Expand Up @@ -93,7 +93,16 @@ export default class ComponentDragSource extends DragSource {

beginDrag(monitor, id) {
const component = this.getComponentRef();
return this.spec.beginDrag.call(null, this.props, monitor, component, id);
const item = this.spec.beginDrag.call(null, this.props, monitor, component, id);
if (process.env.NODE_ENV !== 'production') {
invariant(
isObject(item) && typeof item !== 'function',
'beginDrag() must return an object that represents the dragged item. ' +
'Instead received %s.',
item
);
}
return item;
}

endDrag(monitor, id) {
Expand Down
12 changes: 11 additions & 1 deletion src/ComponentDropTarget.js
Expand Up @@ -83,7 +83,17 @@ export default class ComponentDropTarget extends DropTarget {
drop(monitor, id) {
if (this.spec.drop) {
const component = this.getComponentRef();
return this.spec.drop.call(null, this.props, monitor, component, id);
const dropResult = this.spec.drop.call(null, this.props, monitor, component, id);
if (process.env.NODE_ENV !== 'production') {
invariant(
typeof dropResult === 'undefined' ||
isObject(dropResult) && typeof dropResult !== 'function',
'drop() must either return undefined, or an object that represents the drop result. ' +
'Instead received %s.',
dropResult
);
}
return dropResult;
} else {
return super.drop(monitor, id);
}
Expand Down

0 comments on commit 18a2cad

Please sign in to comment.