BigW Consortium Gitlab

Commit 49aecb60 by Regis

properly remove events and get rid of lingering interval loops

parent 30e7952a
...@@ -49,28 +49,20 @@ ...@@ -49,28 +49,20 @@
startTimeLoops(); startTimeLoops();
const removeTimeIntervals = () => { const removeTimeIntervals = () => clearInterval(this.timeLoopInterval);
clearInterval(this.timeLoopInterval); const startIntervalLoops = () => startTimeLoops();
};
const startIntervalLoops = () => {
startTimeLoops();
};
const removeAll = () => { const removeAll = () => {
removeTimeIntervals();
window.removeEventListener('beforeunload', removeTimeIntervals); window.removeEventListener('beforeunload', removeTimeIntervals);
window.removeEventListener('focus', startIntervalLoops); window.removeEventListener('focus', startIntervalLoops);
window.removeEventListener('blur', removeTimeIntervals); window.removeEventListener('blur', removeTimeIntervals);
document.removeEventListener('page:fetch', removeAll);
// turbolinks event handler
document.removeEventListener('page:fetch', () => {});
}; };
window.addEventListener('beforeunload', removeTimeIntervals); window.addEventListener('beforeunload', removeTimeIntervals);
window.addEventListener('focus', startIntervalLoops); window.addEventListener('focus', startIntervalLoops);
window.addEventListener('blur', removeTimeIntervals); window.addEventListener('blur', removeTimeIntervals);
// turbolinks event handler
document.addEventListener('page:fetch', removeAll); document.addEventListener('page:fetch', removeAll);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment