Simplify leaderboard rows and defer disruptive refreshes

This commit is contained in:
2026-10-06 19:12:25 -04:00
parent 01d764946c
commit 1370873cba
6 changed files with 234 additions and 70 deletions
+27
View File
@@ -0,0 +1,27 @@
import type { LeaderboardResponse } from './leaderboard.js';
export const leaderboardPageSize = 25;
/** Keep a viewed ranking stable until the reader chooses to apply new results. */
export function createLeaderboardUpdates(scope: string, current: LeaderboardResponse) {
let pending: LeaderboardResponse | null = null;
return {
reset(nextScope: string, report: LeaderboardResponse) {
scope = nextScope;
current = report;
pending = null;
},
receive(requestScope: string, report: LeaderboardResponse, inspecting: boolean) {
if (requestScope !== scope) return null;
if (JSON.stringify(current) === JSON.stringify(report)) pending = null;
else if (inspecting || pending) pending = report;
else current = report;
return { current, pending };
},
apply() {
if (pending) current = pending;
pending = null;
return current;
}
};
}