From 6c7a272edce0c56d5e4cf268f99da9a51b6cb1eb Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 25 Jul 2024 19:22:44 +0300 Subject: [PATCH] client-ts: Port services/app/services/spaced_update --- .../services/{spaced_update.js => spaced_update.ts} | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) rename src/public/app/services/{spaced_update.js => spaced_update.ts} (81%) diff --git a/src/public/app/services/spaced_update.js b/src/public/app/services/spaced_update.ts similarity index 81% rename from src/public/app/services/spaced_update.js rename to src/public/app/services/spaced_update.ts index bfac5f056..4ac0fdd23 100644 --- a/src/public/app/services/spaced_update.js +++ b/src/public/app/services/spaced_update.ts @@ -1,5 +1,13 @@ +type Callback = () => Promise; + export default class SpacedUpdate { - constructor(updater, updateInterval = 1000) { + private updater: Callback; + private lastUpdated: number; + private changed: boolean; + private updateInterval: number; + private changeForbidden?: boolean; + + constructor(updater: Callback, updateInterval = 1000) { this.updater = updater; this.lastUpdated = Date.now(); this.changed = false; @@ -52,7 +60,7 @@ export default class SpacedUpdate { } } - async allowUpdateWithoutChange(callback) { + async allowUpdateWithoutChange(callback: Callback) { this.changeForbidden = true; try {