reducer.js
42 lines
| 1 | import {initialState} from './initialState'; |
| 2 | |
| 3 | export const reducer = (state = initialState, action) => { |
| 4 | switch (action.type) { |
| 5 | case 'SET_ACTIVE_TAB': |
| 6 | return { |
| 7 | ...state, |
| 8 | activeTab: action.payload.tab, |
| 9 | }; |
| 10 | case 'ADD_TAB': |
| 11 | const registeredTabs = Object.assign({}, state.tabs); |
| 12 | registeredTabs[action.payload.tab.slug] = action.payload.tab; |
| 13 | |
| 14 | return { |
| 15 | ...state, |
| 16 | tabs: registeredTabs, |
| 17 | }; |
| 18 | case 'SET_PROFILE': |
| 19 | return { |
| 20 | ...state, |
| 21 | profile: action.payload.profile, |
| 22 | }; |
| 23 | case 'SET_APPLICATION_ERROR': |
| 24 | return { |
| 25 | ...state, |
| 26 | applicationError: action.payload.error, |
| 27 | }; |
| 28 | case 'SET_STATES': |
| 29 | return { |
| 30 | ...state, |
| 31 | states: action.payload.states, |
| 32 | }; |
| 33 | case 'SET_FETCHING_STATES': |
| 34 | return { |
| 35 | ...state, |
| 36 | fetchingStates: action.payload.fetchingStates, |
| 37 | }; |
| 38 | default: |
| 39 | return state; |
| 40 | } |
| 41 | }; |
| 42 |