Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created August 31, 2018 17:56
Show Gist options
  • Save mweststrate/83cfbfd88ee271b3603d88649ce50598 to your computer and use it in GitHub Desktop.
Save mweststrate/83cfbfd88ee271b3603d88649ce50598 to your computer and use it in GitHub Desktop.
No concurrency
onStopDrag = (id, { dx, dy }) => {
// we capture this outside the propose closure!
const baseBox = this.client.currentState.boxes.find(b => b.id === id);
this.client.propose(draft => {
const box = draft.boxes.find(b => b.id === id);
if (box.x !== baseBox.x || box.y !== baseBox.y)
throw "Somebody else already dragged this box!";
box.x += dx;
box.y += dy;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment