export type Unsub = (() => void) | Unsubs; export class Unsubs { private fns: Unsub[] = []; public add(fn: Unsub): this { this.fns.push(fn); return this; } public unsub(): this { this.fns.forEach((unsub) => { if (typeof unsub === "function") { unsub(); } else { unsub.unsub(); } }); return this; } public clear(): this { this.fns = []; return this; } }