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; 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 { export {
atomWithDebounce, atomWithDebounce,
atomWithThrottle, atomWithThrottle,
@ -295,6 +313,7 @@ export {
boundNumber, boundNumber,
countGraphemes, countGraphemes,
fireAndForget, fireAndForget,
getNextActionId,
getPrefixedSettings, getPrefixedSettings,
getPromiseState, getPromiseState,
getPromiseValue, getPromiseValue,