You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { NetInfoCellularGeneration, NetInfoStateType } from '@react-native-community/netinfo';
  2. import ReducerRegistry from '../redux/ReducerRegistry';
  3. import { assign } from '../redux/functions';
  4. import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes';
  5. import { STORE_NAME } from './constants';
  6. const DEFAULT_STATE = {
  7. isOnline: true
  8. };
  9. export interface INetInfoState {
  10. _cleanup?: Function;
  11. cellularGeneration?: NetInfoCellularGeneration;
  12. details?: Object;
  13. isOnline?: boolean;
  14. networkType?: NetInfoStateType;
  15. }
  16. /**
  17. * The base/net-info feature's reducer.
  18. */
  19. ReducerRegistry.register<INetInfoState>(STORE_NAME, (state = DEFAULT_STATE, action): INetInfoState => {
  20. switch (action.type) {
  21. case SET_NETWORK_INFO:
  22. return assign(state, {
  23. isOnline: action.isOnline,
  24. networkType: action.networkType,
  25. cellularGeneration: action.cellularGeneration,
  26. details: action.details
  27. });
  28. case _STORE_NETWORK_INFO_CLEANUP:
  29. return assign(state, {
  30. _cleanup: action.cleanup
  31. });
  32. default:
  33. return state;
  34. }
  35. });