UNPKG

@cgi-learning-hub/ui

Version:

@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features

43 lines (42 loc) 1.01 kB
var i = Object.defineProperty; var o = (t, e, r) => e in t ? i(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; var u = (t, e, r) => o(t, typeof e != "symbol" ? e + "" : e, r); import * as c from "react"; const s = {}; function a(t, e) { const r = c.useRef(s); return r.current === s && (r.current = t(e)), r; } const f = []; function l(t) { c.useEffect(t, f); } class n { constructor() { u(this, "currentId", null); u(this, "clear", () => { this.currentId !== null && (clearTimeout(this.currentId), this.currentId = null); }); u(this, "disposeEffect", () => this.clear); } static create() { return new n(); } /** * Executes `fn` after `delay`, clearing any previously scheduled call. */ start(e, r) { this.clear(), this.currentId = setTimeout(() => { this.currentId = null, r(); }, e); } } function d() { const t = a(n.create).current; return l(t.disposeEffect), t; } export { n as T, a, d as u };