From 90ddee1716d07f49db7d7ebaa810c9c2703a8549 Mon Sep 17 00:00:00 2001 From: Braden Herndon Date: Wed, 14 Apr 2021 13:52:55 -0500 Subject: [PATCH] Clean up yDoc observers on PM plugin destroy --- src/plugins/sync-plugin.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugins/sync-plugin.js b/src/plugins/sync-plugin.js index 557fed01..84e59f8b 100644 --- a/src/plugins/sync-plugin.js +++ b/src/plugins/sync-plugin.js @@ -202,14 +202,17 @@ export class ProsemirrorBinding { * current selection as relative positions in the Yjs model */ this.beforeTransactionSelection = null - this.doc.on('beforeAllTransactions', () => { + this.beforeAllTransactions = () => { if (this.beforeTransactionSelection === null) { this.beforeTransactionSelection = getRelativeSelection(this, prosemirrorView.state) } - }) - this.doc.on('afterAllTransactions', e => { + } + this.afterAllTransactions = () => { this.beforeTransactionSelection = null - }) + } + + this.doc.on('beforeAllTransactions', this.beforeAllTransactions) + this.doc.on('afterAllTransactions', this.afterAllTransactions) yXmlFragment.observeDeep(this._observeFunction) this._domSelectionInView = null @@ -370,6 +373,8 @@ export class ProsemirrorBinding { destroy () { this.type.unobserveDeep(this._observeFunction) + this.doc.off('beforeAllTransactions', this.beforeAllTransactions) + this.doc.off('afterAllTransactions', this.afterAllTransactions) } }