53 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-08-18 11:41:13 +02:00
/**
* Combine all reducers in this file and export the combined reducers.
* If we were to do this in store.js, reducers wouldn't be hot reloadable.
*/
import { combineReducers } from 'redux-immutable';
2016-08-18 11:47:26 +02:00
import { fromJS } from 'immutable';
2016-08-18 11:41:13 +02:00
import { LOCATION_CHANGE } from 'react-router-redux';
import appReducer from 'containers/App/reducer';
2016-08-18 11:41:13 +02:00
import languageProviderReducer from 'containers/LanguageProvider/reducer';
2016-09-30 18:25:04 +02:00
import notificationProviderReducer from 'containers/NotificationProvider/reducer';
2016-08-18 11:41:13 +02:00
/*
* 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({
locationBeforeTransitions: null,
});
/**
* Merge route into the global application state
*/
function routeReducer(state = routeInitialState, action) {
switch (action.type) {
/* istanbul ignore next */
case LOCATION_CHANGE:
return state.merge({
locationBeforeTransitions: action.payload,
});
default:
2016-10-05 11:32:31 +02:00
return state;
}
2016-08-18 11:41:13 +02:00
}
/**
* Creates the main reducer with the asynchronously loaded ones
*/
export default function createReducer(asyncReducers) {
return combineReducers({
route: routeReducer,
language: languageProviderReducer,
2016-09-30 18:25:04 +02:00
notification: notificationProviderReducer,
app: appReducer,
2016-08-18 11:41:13 +02:00
...asyncReducers,
});
}