File size: 1,288 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// @flow
import type { WebsocketConnectionType } from 'src/reducers/connectionStatus';
type ConnectionProps = {
networkOnline: boolean,
websocketConnection: WebsocketConnectionType,
};
type Props = {
prev: ConnectionProps,
curr: ConnectionProps,
};
const validateProps = (props: Props) => {
if (!props.prev || !props.curr) return false;
if (
!props.prev.hasOwnProperty('networkOnline') ||
!props.curr.hasOwnProperty('networkOnline')
) {
return false;
}
if (
!props.prev.hasOwnProperty('websocketConnection') ||
!props.curr.hasOwnProperty('websocketConnection')
) {
return false;
}
return true;
};
const websocketDidReconnect = (props: Props) => {
const { curr, prev } = props;
if (
prev.websocketConnection === 'reconnecting' &&
curr.websocketConnection === 'reconnected'
)
return true;
return false;
};
const networkOnlineDidReconnect = (props: Props) => {
const { curr, prev } = props;
if (prev.networkOnline === false && curr.networkOnline === true) return true;
return false;
};
export const useConnectionRestored = (props: Props) => {
if (!validateProps(props)) return false;
if (websocketDidReconnect(props)) return false;
if (networkOnlineDidReconnect(props)) return false;
return false;
};
|