Skip to content

Instantly share code, notes, and snippets.

@shierro
Created October 27, 2018 03:46
Show Gist options
  • Save shierro/88e15fe622e3f8abee2f5bbf5c94fc29 to your computer and use it in GitHub Desktop.
Save shierro/88e15fe622e3f8abee2f5bbf5c94fc29 to your computer and use it in GitHub Desktop.
combined reducers
/**
* Combine all reducers in this file and export the combined reducers.
*/
import { combineReducers } from 'redux-immutable';
import { fromJS } from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';
import languageProviderReducer from 'containers/LanguageProvider/reducer';
import mapPageReducer from 'containers/MapPage/reducer';
import loginPageReducer from 'containers/LoginPage/reducer';
import householderListReducer from 'containers/HouseholderListPage/reducer';
import servicePageReducer from 'containers/ServicePage/reducer';
// import { reducer as offlineQueue } from 'redux-offline-queue';
/*
* routeReducer
*
* The reducer merges route location changes into our immutable state.
* The change is necessitated by moving to react-router-redux@4
*
*/
// Initial routing state
const routeInitialState = fromJS({ location: null });
/**
* Merge route into the global application state
*/
export function routeReducer(state = routeInitialState, action) {
switch (action.type) {
/* istanbul ignore next */
case LOCATION_CHANGE:
return state.merge({
location: action.payload,
});
default:
return state;
}
}
export function rehydrateReducer(state = false, action) {
switch (action.type) {
/* istanbul ignore next */
case 'REHYDRATE_STORE':
return true;
default:
return state;
}
}
/**
* Creates the main reducer with the dynamically injected ones
*/
export default function createReducer(injectedReducers) {
return combineReducers({
offline: require('redux-offline-queue').reducer,
mapPage: mapPageReducer,
householderListPage: householderListReducer,
loginPage: loginPageReducer,
servicePage: servicePageReducer,
rehydrate: rehydrateReducer,
route: routeReducer,
language: languageProviderReducer,
...injectedReducers,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment