Skip to content

Commit

Permalink
requestAnimationFrame update for clock (#151)
Browse files Browse the repository at this point in the history
Switches setInterval to requestAnimationFrame (closes #135).
  • Loading branch information
andOrlando committed Dec 16, 2020
1 parent 2a20a69 commit 81b3fed
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions public/js/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ let current_schedule = covid_schedule ? "covid" : "regular";
// current date and time.
let date_override = undefined;

let schedulesCallback = function(response) {
function schedulesCallback(response) {
schedules = response;
redraw_clock();
setInterval(function() {
redraw_clock();
}, 1000);
};

let last_interval = 0;
const redraw_clock_with_timestamp = timestamp => {
// Redraw clock 4 times per second (once every 1000/4 milliseconds)
if (timestamp > last_interval * 1000/4) {
last_interval++;
redraw_clock();
}
window.requestAnimationFrame(redraw_clock_with_timestamp);
}

redraw_clock_with_timestamp();
}

//#ifndef lite
$.ajax({
Expand Down

0 comments on commit 81b3fed

Please sign in to comment.