Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Last active August 31, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweststrate/8602ab306eefb00b22bf7e3c2fde3e94 to your computer and use it in GitHub Desktop.
Save mweststrate/8602ab306eefb00b22bf7e3c2fde3e94 to your computer and use it in GitHub Desktop.
onStopDrag = (id, { dx, dy }) => {
// dx and dy are captured in the closure!
this.client.propose(draft => {
const box = draft.boxes.find(b => b.id === id);
box.x += dx;
box.y += dy;
if (box.x < 0 || box.x > 400 || box.y < 0 || box.y > 400)
// throwing here is safe; as original state will be untouched.
// This can happen when actions are being replayed
throw "Invalid drop coordinates: " + JSON.stringify(box);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment