Home Reference Source

application/redux/reducers/application-reducers.js

  1. import Immutable from 'immutable';
  2. import {
  3. APPLICATION_NOTIFY_UPDATES,
  4. APPLICATION_DID_NOTIFY_UPDATES,
  5. APPLICATION_SET_VERSION,
  6. APPLICATION_IS_CONNECTED,
  7. APPLICATION_IS_DIRTY,
  8. APPLICATION_SET_SETTINGS,
  9. APPLICATION_SET_SETPLUGINS
  10. } from '../actions/application-actions';
  11.  
  12. export function application(state = null, action) {
  13. if (state == null) {
  14. state = {
  15. version: '0.0.0',
  16. doNotifyChanges: false,
  17. connectedState: false,
  18. isDirty: false,
  19. settings: Immutable.fromJS({}),
  20. plugins: Immutable.fromJS([])
  21. }
  22. }
  23.  
  24. switch(action.type) {
  25. case APPLICATION_IS_DIRTY:
  26. // GIMME MY MONEY!
  27. return Object.assign({}, state, {
  28. isDirty: action.payload.isDirty
  29. });
  30. case APPLICATION_SET_VERSION:
  31. return Object.assign({}, state, {
  32. version: action.payload.version
  33. });
  34. case APPLICATION_NOTIFY_UPDATES:
  35. return Object.assign({}, state, {
  36. doNotifyChanges: true
  37. });
  38. case APPLICATION_DID_NOTIFY_UPDATES:
  39. return Object.assign({}, state, {
  40. doNotifyChanges: false
  41. });
  42. case APPLICATION_IS_CONNECTED:
  43. return Object.assign({}, state, {
  44. connectedState: action.payload.connectedState
  45. });
  46. case APPLICATION_SET_SETTINGS:
  47. return Object.assign({}, state, {
  48. settings: action.payload.settings
  49. });
  50. case APPLICATION_SET_SETPLUGINS:
  51. return Object.assign({}, state, {
  52. plugins: action.payload.plugins
  53. });
  54. }
  55.  
  56. return state;
  57. }