Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/y-monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,27 @@ export class MonacoBinding {
this.awareness = awareness
}
}
/**
* Destroy the MonacoBinding and clean up all listeners.
*
* @param {boolean} [skipYjsUnobserve=false] - When true, skips calling `ytext.unobserve`
* to avoid harmless Yjs warnings like:
* `[yjs] Tried to remove event handler that doesn't exist.`
*/
destroy ( skipYjsUnobserve = false) {
// skipYjsUnobserve will skip Yjs unobserve cause it can through error if y-text is already unobserved
this._monacoChangeHandler.dispose()
this._monacoDisposeHandler.dispose()

destroy () {
this._monacoChangeHandler.dispose()
this._monacoDisposeHandler.dispose()
this.ytext.unobserve(this._ytextObserver)
this.doc.off('beforeAllTransactions', this._beforeTransaction)
if (this.awareness) {
this.awareness.off('change', this._rerenderDecorations)
}
// optionally skip this part to avoid Yjs warning
if (!skipYjsUnobserve) {
try { this.ytext.unobserve(this._ytextObserver) } catch {}
}

this.doc.off('beforeAllTransactions', this._beforeTransaction)

if (this.awareness) {
this.awareness.off('change', this._rerenderDecorations)
}
}
}