summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/is_navigating_away.js
blob: 7df00b4537994007a76f00e62f750dca303d1de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let navigating = false;

window.addEventListener('beforeunload', () => {
  navigating = true;
});

/**
 * To only be used for testing purposes. Allows the navigating state to be set
 * to a given value.
 *
 * @param {boolean} value The value to set the navigating flag to.
 */
export const setNavigatingForTestsOnly = (value) => {
  navigating = value;
};

/**
 * Returns a boolean indicating whether the browser is in the process of
 * navigating away from the current page.
 *
 * @returns {boolean}
 */
export const isNavigatingAway = () => navigating;