reducer.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import uniq from 'lodash/uniq';
  2. export const initialState = {
  3. appQuit: false,
  4. genericWindowActingType: '',
  5. windowsInit: false,
  6. windowsOpen: []
  7. };
  8. const ui = (state = initialState, action) => {
  9. switch (action.type) {
  10. case '[MAIN]:APP_QUIT:SUCCESS':
  11. return Object.assign({}, state, { appQuit: true });
  12. case '[MAIN]:WINDOW:OPEN':
  13. return Object.assign({}, state, {
  14. windowsOpen: uniq(state.windowsOpen.concat(action.payload.windowType))
  15. });
  16. case '[MAIN]:WINDOW:CLOSE':
  17. return Object.assign({}, state, {
  18. windowsOpen: state.windowsOpen.filter(w => {
  19. return w !== action.payload.windowType;
  20. })
  21. });
  22. case '[MAIN]:WINDOWS:INIT_FINISH':
  23. return Object.assign({}, state, { windowsInit: true });
  24. case '[MAIN]:GENERIC_WINDOW:REUSE':
  25. return Object.assign({}, state, {
  26. genericWindowActingType: action.payload.actingType,
  27. windowsOpen: state.windowsOpen.concat('generic')
  28. });
  29. case '[MAIN]:GENERIC_WINDOW:RESET':
  30. return Object.assign({}, state, {
  31. genericWindowActingType: '',
  32. windowsOpen: state.windowsOpen.filter(i => i !== 'generic')
  33. });
  34. default:
  35. return state;
  36. }
  37. };
  38. export default ui;