Skip to content

Commit

Permalink
Merge pull request #112 from KentoMoriwaki/timeout
Browse files Browse the repository at this point in the history
Fix wrong timeout object
  • Loading branch information
dmonad authored May 17, 2022
2 parents be34a36 + 746caa0 commit 0a522ff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const ySyncPlugin = (yXmlFragment, {
onFirstRender = () => {}
} = {}) => {
let changedInitialContent = false
let rerenderTimeoutId
let rerenderTimeout
const plugin = new Plugin({
props: {
editable: (state) => {
Expand Down Expand Up @@ -140,11 +140,11 @@ export const ySyncPlugin = (yXmlFragment, {
},
view: view => {
const binding = new ProsemirrorBinding(yXmlFragment, view)
if (rerenderTimeoutId != null) {
clearTimeout(rerenderTimeoutId)
if (rerenderTimeout != null) {
rerenderTimeout.destroy()
}
// Make sure this is called in a separate context
rerenderTimeoutId = eventloop.timeout(0, () => {
rerenderTimeout = eventloop.timeout(0, () => {
binding._forceRerender()
view.dispatch(view.state.tr.setMeta(ySyncPluginKey, { binding }))
onFirstRender()
Expand All @@ -160,7 +160,7 @@ export const ySyncPlugin = (yXmlFragment, {
}
},
destroy: () => {
clearTimeout(rerenderTimeoutId)
rerenderTimeout.destroy()
binding.destroy()
}
}
Expand Down

0 comments on commit 0a522ff

Please sign in to comment.