Last active
August 31, 2018 15:54
-
-
Save mweststrate/8602ab306eefb00b22bf7e3c2fde3e94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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