insomnia/app/reducers/global.js

47 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-03-20 04:00:40 +00:00
import * as types from '../constants/actionTypes';
import settingsReducer from './settings'
2016-03-24 05:26:04 +00:00
import requestsReducer from './requests'
2016-04-04 01:05:34 +00:00
import requestGroupsReducer from './requestGroups'
2016-03-20 04:00:40 +00:00
const initialState = {
initialized: false,
2016-04-08 04:05:08 +00:00
loading: false,
prompt: null,
tabs: {}
2016-03-20 04:00:40 +00:00
};
export default function (state = initialState, action) {
2016-04-08 04:05:08 +00:00
let prompt;
2016-03-20 04:00:40 +00:00
switch (action.type) {
case types.GLOBAL_STATE_SAVED:
return state;
case types.GLOBAL_STATE_RESTORED:
return Object.assign({}, state, action.state, {initialized: true});
case types.GLOBAL_LOAD_START:
return Object.assign({}, state, {loading: true});
case types.GLOBAL_LOAD_STOP:
return Object.assign({}, state, {loading: false});
2016-04-08 04:05:08 +00:00
case types.GLOBAL_SHOW_PROMPT:
prompt = {id: action.id, data: action.data};
return Object.assign({}, state, {prompt});
case types.GLOBAL_HIDE_PROMPT:
prompt = null;
return Object.assign({}, state, {prompt});
case types.GLOBAL_SELECT_TAB:
let tabs = Object.assign({}, state.tabs);
tabs[action.id] = action.selectedIndex;
return Object.assign({}, state, {tabs});
2016-03-20 04:00:40 +00:00
default:
// Send everything else to the child reducers
const settings = settingsReducer(state.settings, action);
2016-03-24 05:26:04 +00:00
const requests = requestsReducer(state.requests, action);
const requestGroups = requestGroupsReducer(state.requestGroups, action);
2016-04-03 22:54:39 +00:00
2016-03-20 04:00:40 +00:00
return Object.assign({}, state, {
settings,
2016-03-24 05:26:04 +00:00
requests,
2016-04-05 06:08:03 +00:00
requestGroups
2016-03-20 04:00:40 +00:00
});
}
};