UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines 1.39 kB
{"version":3,"file":"pendingQueue.mjs","names":[],"sources":["../../../src/base-ui/Toast/pendingQueue.ts"],"sourcesContent":["const MAX_QUEUED_ACTIONS = 20;\nconst QUEUE_TTL_MS = 5000;\n\ninterface QueuedAction {\n queuedAt: number;\n run: () => void;\n}\n\nlet ready = false;\nlet queue: QueuedAction[] = [];\n\nexport const runWhenToastHostReady = (run: () => void): void => {\n if (ready) {\n run();\n return;\n }\n if (queue.length >= MAX_QUEUED_ACTIONS) {\n queue.shift();\n }\n queue.push({ queuedAt: Date.now(), run });\n};\n\nexport const markToastHostReady = (): void => {\n ready = true;\n const pending = queue;\n queue = [];\n const now = Date.now();\n for (const action of pending) {\n if (now - action.queuedAt <= QUEUE_TTL_MS) action.run();\n }\n};\n\nexport const markToastHostNotReady = (): void => {\n ready = false;\n};\n\nexport const __resetPendingToastQueueForTests = (): void => {\n ready = false;\n queue = [];\n};\n"],"mappings":";AAAA,MAAM,qBAAqB;AAC3B,MAAM,eAAe;AAOrB,IAAI,QAAQ;AACZ,IAAI,QAAwB,CAAC;AAE7B,MAAa,yBAAyB,QAA0B;CAC9D,IAAI,OAAO;EACT,IAAI;EACJ;CACF;CACA,IAAI,MAAM,UAAU,oBAClB,MAAM,MAAM;CAEd,MAAM,KAAK;EAAE,UAAU,KAAK,IAAI;EAAG;CAAI,CAAC;AAC1C;AAEA,MAAa,2BAAiC;CAC5C,QAAQ;CACR,MAAM,UAAU;CAChB,QAAQ,CAAC;CACT,MAAM,MAAM,KAAK,IAAI;CACrB,KAAK,MAAM,UAAU,SACnB,IAAI,MAAM,OAAO,YAAY,cAAc,OAAO,IAAI;AAE1D;AAEA,MAAa,8BAAoC;CAC/C,QAAQ;AACV"}