UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

39 lines (37 loc) 1.04 kB
export class TimeoutManager { timeoutIds = (() => new Map())(); intervalIds = (() => new Map())(); startTimeout = (key, delay, fn) => { this.clearTimeout(key); const id = setTimeout(() => { this.timeoutIds.delete(key); fn(); }, delay); /* Node.js types are enabled in development */ this.timeoutIds.set(key, id); }; startInterval = (key, delay, fn) => { this.clearTimeout(key); const id = setInterval(fn, delay); /* Node.js types are enabled in development */ this.intervalIds.set(key, id); }; clearTimeout = key => { const id = this.timeoutIds.get(key); if (id != null) { clearTimeout(id); this.timeoutIds.delete(key); } }; clearInterval = key => { const id = this.intervalIds.get(key); if (id != null) { clearInterval(id); this.intervalIds.delete(key); } }; clearAll = () => { this.timeoutIds.forEach(clearTimeout); this.timeoutIds.clear(); this.intervalIds.forEach(clearInterval); this.intervalIds.clear(); }; }