summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_realtime_listener/index.js.es6
blob: 23cac1466d22242c8e0097ed0ab79b63a6cb610f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* eslint-disable no-param-reassign */

((gl) => {
  gl.VueRealtimeListener = (removeIntervals, startIntervals) => {
    const removeAll = () => {
      removeIntervals();
      window.removeEventListener('beforeunload', removeIntervals);
      window.removeEventListener('focus', startIntervals);
      window.removeEventListener('blur', removeIntervals);
      document.removeEventListener('page:fetch', removeAll);
    };

    window.addEventListener('beforeunload', removeIntervals);
    window.addEventListener('focus', startIntervals);
    window.addEventListener('blur', removeIntervals);
    document.addEventListener('page:fetch', removeAll);
  };
})(window.gl || (window.gl = {}));