Skip to content

Commit

Permalink
Only update state if excalidraw "scene" actually changes.
Browse files Browse the repository at this point in the history
This fixes syncing bidirectionally, but there can still be timing issues that overwrite one person's changes
  • Loading branch information
tibetsprague committed Feb 23, 2024
1 parent cb3afc1 commit dd5cd67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions ui/src/GriffyPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
$: if ($state) {
if (excalidrawAPI) {
// TODO: maybe check scene version to see if its changed? getSceneVersion($state.excalidrawElements)
// XXX: Need to do a cloneDeep here too otherwise resizing elements doesn't trigger
// updateExcalidrawState because it must be editing the $state.excalidrawElements directly and so the scene # is updated internally
excalidrawAPI.updateScene({
elements: $state.excalidrawElements,
elements: cloneDeep($state.excalidrawElements),
//appState: $state.excalidrawState
})
}
}
onMount(async () => {
console.log('mounted', excalidrawAPI, $state)
});
const setExcalidrawAPI = (api) => {
Expand Down Expand Up @@ -86,8 +86,10 @@
}
const updateExcalidrawState = throttle((excalidrawElements, appState, files) => {
activeBoard.requestChanges([{type: 'set-excalidraw', excalidrawElements, excalidrawState: appState}])
}, 5000)
if (getSceneVersion($state.excalidrawElements) !== getSceneVersion(excalidrawElements)) {
activeBoard.requestChanges([{type: 'set-excalidraw', excalidrawElements, excalidrawState: appState}])
}
}, 3000)
</script>
<div class="board" >
Expand Down
4 changes: 2 additions & 2 deletions ui/src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export const boardGrammar = {
break;
case "set-excalidraw":
// For some reason customData is set to undefined which breaks in syn code getValueDescription
const excalidrawElements = delta.excalidrawElements.map(e => pickBy(e, (v, k) => typeof(v) !== "undefined"))
state.excalidrawElements = cloneDeep(excalidrawElements)
const newExcalidrawElements = cloneDeep(delta.excalidrawElements).map(e => pickBy(e, (v, k) => typeof(v) !== "undefined"))
state.excalidrawElements = newExcalidrawElements
//state.excalidrawState = delta.excalidrawState
break;
}
Expand Down

0 comments on commit dd5cd67

Please sign in to comment.