How do I dispose a custom module? #4443
Answered
by
jankapunkt
jankapunkt
asked this question in
Q&A
-
I have a custom module that registers a global event listener on window to recompute on resize: import { debounce } from '../utils/dom/debounce.js'
import Quill from 'quill';
const Module = Quill.import('core/module');
export class LineNumber extends Module {
constructor(quill, options) {
super(quill, options);
this.quill = quill;
this.options = options;
this.container = document.querySelector(options.container);
quill.on('text-change', this.update.bind(this));
window.addEventListener('resize', debounce(this.update.bind(this), 100));
this.update(); // Account for initial contents
}
update() {
// compute line numbers
}
dispose () {
// remove event listener here
}
} I found no clue in the docs on how to cleanup when my components unmount, possibly causing a memleak when switching between pages a lot. Anyone got an idea here? |
Beta Was this translation helpful? Give feedback.
Answered by
jankapunkt
Oct 10, 2024
Replies: 1 comment
-
Okay I found the solution using const lineNumber = quillInstance.getModule('lineNumber')
lineNumber.dispose() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jankapunkt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay I found the solution using
getModule
, which I call before my components unmount: