/**
 * @flow
 */

import { combineReducers } from 'redux';

type Reducer<S, A> = (state: S, action: A) => S

type PayloadAction<P> = {
  type: string,
  payload: P,
}

type ReplaceReducer<T> = Reducer<T, PayloadAction<T>>
function replaceReducer<T>(actionType: string, defaultValue: T): ReplaceReducer<T> {
  return (state = defaultValue, action) => {
    if (action.type === actionType) {
      return action.payload;
    }
    return state;
  };
}

const progress = replaceReducer('hotUpdateLoading/progress', -2)
const showDialog = replaceReducer('hotUpdateLoading/showDialog', false)
const path = replaceReducer('hotUpdateLoading/path', '')
const hash = replaceReducer('hotUpdateLoading/hash', '')

export default combineReducers({
  progress,
  showDialog,
  path,
  hash,
});
