@mocanvas/editor · class
declare class TimersPer-editor timers.
Every setTimeout, setInterval and requestAnimationFrame scheduled
through this manager is remembered and cancelled when the editor is disposed.
Work scheduled by a tool, a side effect or a host integration therefore
cannot outlive the editor it belongs to and fire against a torn-down store —
the usual source of "cannot read properties of undefined" after unmount.
Handles are this manager's own; they are only meaningful to its clear*
methods, never to the global ones.
Methods · 9
cancelAnimationFrame(handle: number | undefined): voidCancel a pending animation frame. Unknown handles are ignored.
clearInterval(handle: number | undefined): voidCancel a repeating interval. Unknown handles are ignored.
clearTimeout(handle: number | undefined): voidCancel a pending timeout. Unknown handles are ignored.
constructor(getWindow?: () => Window | undefined)@param getWindow - The realm to schedule in; see getOwnerWindow. When it
yields nothing (node, SSR) the globals are used, and animation frames fall
back to a ~60fps timeout.
dispose(): voidCancel everything. Further scheduling is a no-op.
getPendingCount(): numberHow much work is still scheduled. Useful in tests and leak checks.
requestAnimationFrame(fn: (time: number) => void): numberRun fn before the next paint of the editor's own window. Where there is
no requestAnimationFrame (node) a 16ms timeout stands in, so scheduling
code does not have to branch on the environment.
setInterval(fn: () => void, ms: number): numberRun fn every ms until cancelled or the editor is disposed.
setTimeout(fn: () => void, ms?: number): numberRun fn after ms. The handle is released once it fires.
mocanvas 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.