Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Created April 7, 2016 03:55
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 adrianmcli/55caa5a6862021507406ec3ce1ec03e8 to your computer and use it in GitHub Desktop.
Save adrianmcli/55caa5a6862021507406ec3ce1ec03e8 to your computer and use it in GitHub Desktop.
const hasFocus = editorState.getSelection().getHasFocus();
if (hasFocus) {
// make an array of blocks we need to request locks for
// 1. which locks do we currently have?
const currentLocks = this.locks.map(lock => lock.blockKey);
// 2. which locks does the user want? (getSelectedBlocks)
const desiredLocks = getSelectedBlocks().map(block => block.getKey());
// 3. Make a list of all elements in the desiredLocks not contained in currentLocks
const requestLocks = R.difference(desiredLocks, currentLocks);
// 4. Make a list of all elements in currentLocks not contained in desiredLocks
const releaseLocks = R.difference(currentLocks, desiredLocks);
// 5. send the request for those
requestBlockLocks(requestLocks, user);
releaseBlockLocks(releaseLocks, user);
} else {
releaseAllBlockLocks(user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment