Merge pull request 'fix(web): classic timer ran at 2x (idempotent startTimer)' (#96) from fix/classic-timer-double-count into master
This commit was merged in pull request #96.
This commit is contained in:
@@ -270,6 +270,11 @@ function startGame(seed) {
|
|||||||
|
|
||||||
// ── Timer ────────────────────────────────────────────────────────────────────
|
// ── Timer ────────────────────────────────────────────────────────────────────
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
|
// Idempotent: never stack a second interval. The visibilitychange handler
|
||||||
|
// and startGame can both call this, and a stray call (e.g. a load-time
|
||||||
|
// visibilitychange while a timer is already running) would otherwise leak
|
||||||
|
// the old interval and make elapsedSecs increment twice per second.
|
||||||
|
if (timerInterval) return;
|
||||||
timerInterval = setInterval(() => {
|
timerInterval = setInterval(() => {
|
||||||
elapsedSecs++;
|
elapsedSecs++;
|
||||||
updateTimerDisplay();
|
updateTimerDisplay();
|
||||||
|
|||||||
Reference in New Issue
Block a user