2016-04-12 15:10:07 +02:00
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
import items from './items';
|
2016-04-16 18:06:27 +02:00
|
|
|
import groups from './groups';
|
2016-06-27 15:46:12 +02:00
|
|
|
import choices from './choices';
|
2019-01-26 13:36:47 +01:00
|
|
|
import general from './general';
|
2018-05-28 17:22:22 +02:00
|
|
|
import { cloneObject } from '../lib/utils';
|
2016-03-31 15:51:41 +02:00
|
|
|
|
2016-06-08 15:45:29 +02:00
|
|
|
const appReducer = combineReducers({
|
2016-09-05 23:04:15 +02:00
|
|
|
items,
|
|
|
|
groups,
|
|
|
|
choices,
|
2019-01-26 13:36:47 +01:00
|
|
|
general,
|
2016-06-08 15:45:29 +02:00
|
|
|
});
|
|
|
|
|
2016-08-14 23:14:37 +02:00
|
|
|
const rootReducer = (passedState, action) => {
|
2016-09-05 23:04:15 +02:00
|
|
|
let state = passedState;
|
|
|
|
// If we are clearing all items, groups and options we reassign
|
|
|
|
// state and then pass that state to our proper reducer. This isn't
|
|
|
|
// mutating our actual state
|
|
|
|
// See: http://stackoverflow.com/a/35641992
|
|
|
|
if (action.type === 'CLEAR_ALL') {
|
|
|
|
state = undefined;
|
2018-05-28 17:22:22 +02:00
|
|
|
} else if (action.type === 'RESET_TO') {
|
|
|
|
return cloneObject(action.state);
|
2016-09-05 23:04:15 +02:00
|
|
|
}
|
2016-06-08 15:45:29 +02:00
|
|
|
|
2016-09-05 23:04:15 +02:00
|
|
|
return appReducer(state, action);
|
2016-06-08 15:45:29 +02:00
|
|
|
};
|
2016-04-04 15:43:22 +02:00
|
|
|
|
2016-09-24 12:07:48 +02:00
|
|
|
export default rootReducer;
|