EditorManager
Table of contents
Base class for editor-attached managers that need to clean up after themselves.
Extending EditorManager gives a manager one consistent teardown contract: register anything that needs undoing, and it runs automatically on dispose(). This keeps subscription lifecycle symmetric — whatever sets a thing up is what tears it down — so it can't be forgotten (the failure mode behind the strict-mode camera bug, #8892).
Register cleanup by what you're creating:
- Editor bus event (
tick,frame,change, …): EditorManager.addEditorEvent - Store side effect (editor.sideEffects.register…):this.register(disposer)- Reaction (react(...)from@tldraw/state):this.register(react(...))- DOM listener:this.register(() => el.removeEventListener(...))- Other resource (cache, index, child manager):this.register(() => x.dispose())- Resource held only part of the time (a listener attached while subscribers exist):this.register(...)on attach andthis.unregister(...)on detach, seePerformanceManager
For timeouts, intervals, and animation frames prefer editor.timers (context-grouped and auto-disposed) over raw setTimeout. For cleanup on the editor itself rather than a manager, use editor.disposables.
If a manager needs ordered teardown (e.g. pause a loop before cancelling it), override dispose() and call super.dispose() last — see TickManager.
abstract class EditorManager {}Constructor
Constructs a new instance of the EditorManager class
Parameters
| Name | Description |
|---|---|
|
Properties
disposables
protected readonly disposables: Set<() => void>;editor
protected readonly editor: Editor;Methods
addEditorEvent( )
Subscribe to an editor bus event and register the matching unsubscribe, so the listener is removed automatically on dispose(). Returns that unsubscribe, for passing to EditorManager.unregister to detach it before dispose().
protected addEditorEvent<E extends keyof TLEventMap>(
event: E,
fn: (...args: TLEventMap[E]) => void,
): () => void;Parameters
| Name | Description |
|---|---|
| |
| |
Returns
() => void;register( )
Register a teardown function to run on dispose(). The universal way for a manager to make a resource "see itself out". Returns the same function for convenience.
protected register(dispose: () => void): () => void;Parameters
| Name | Description |
|---|---|
| |
Returns
() => void;unregister( )
Run a registered teardown now instead of at dispose(). A teardown that is no longer registered (already run by dispose(), or never registered) is skipped, so nothing is torn down twice.
protected unregister(dispose: () => void): void;Parameters
| Name | Description |
|---|---|
| |
Returns
void;