getNextActionId() util fn

This commit is contained in:
sawka 2024-12-18 15:17:03 -08:00
parent 007c2391f1
commit 5fa65107c9

View File

@ -287,6 +287,24 @@ function makeConnRoute(conn: string): string {
return "conn:" + conn;
}
let lastTimestamp = 0;
let counter = 0;
// guaranteed to be monotonically increasing for each call within the same tab
function getNextActionId(): string {
const now = Date.now();
if (now === lastTimestamp) {
counter += 1;
} else {
lastTimestamp = now;
counter = 0;
}
const paddedCounter = String(counter).padStart(5, "0");
return `${now}:${paddedCounter}`;
}
export {
atomWithDebounce,
atomWithThrottle,
@ -295,6 +313,7 @@ export {
boundNumber,
countGraphemes,
fireAndForget,
getNextActionId,
getPrefixedSettings,
getPromiseState,
getPromiseValue,