@mocanvas/editor · class
declare abstract class EditorManagerThe base class for anything that owns subscriptions on behalf of an editor.
A manager is a piece of the editor that has to *listen* — to store changes, to editor events, to the DOM — and therefore has to stop listening when the editor goes away. Getting that wrong is the usual cause of "cannot read properties of undefined" after a board is closed: a timer or a listener outlives the store it was written against.
Extending this class means the unsubscribe bookkeeping is written once.
Register anything that must be undone through register (or
addEditorEvent for the common case of an editor event), and
dispose unwinds all of it in reverse order, exactly once.
Subclasses that need to do their own teardown override dispose and
call super.dispose().
Methods · 5
addEditorEvent<K extends keyof EditorEvents>(name: K, handler: EditorEvents[K]): () => voidListen to one of the editor's own events for as long as this manager lives. The returned function removes the listener early.
constructor(editor: Editor)dispose(): voidUnwind every registered teardown, newest first. Safe to call twice.
getIsDisposed(): booleanWhether dispose has already run.
register(disposable: () => void): () => voidRemember how to undo something, and hand the undo back.
Calling the returned function early both runs the teardown and forgets it,
so a subscription that ends before the editor does is not run twice. After
dispose this runs disposable immediately — a subscription created
against a dead editor must not linger.
Properties · 2
readonly disposables: (() => void)[]The teardown functions collected so far, oldest first.
Public because a host that owns a manager's lifetime (a test, a devtools
panel) can meaningfully ask how much is still attached; nothing inside the
editor reads it except dispose.
readonly editor: Editormocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.