All files / lib network.js

0% Statements 0/12
100% Branches 0/0
0% Functions 0/4
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18                                   
import { dispatch } from "../store/Store";
import { networkChanged } from "../store/actions/network";
 
const ONLINE_EVENT = 'online';
const OFFLINE_EVENT = 'offline';
 
const handleOnline = () => dispatch(networkChanged(true));
const handleOffline = () => dispatch(networkChanged(false));
 
export const listenToNetworkChanges = () => {
    window.addEventListener(ONLINE_EVENT, handleOnline);
    window.addEventListener(OFFLINE_EVENT, handleOffline);
};
 
export const stopListeningToNetworkChanges = () => {
    window.removeEventListener(ONLINE_EVENT, handleOnline);
    window.removeEventListener(OFFLINE_EVENT, handleOffline);
};