containers.js 777 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { createReducer } from '../utils/reducer'
  2. import { has, map, isEqual } from 'lodash'
  3. /**
  4. *
  5. * @param {*} containers
  6. * @param {*} action
  7. */
  8. const setContainers = (containers, action) => {
  9. // single instance
  10. if (has(action.payload, 'container')) {
  11. containers = map(containers, c => {
  12. return isEqual(c.id, action.payload.container.id) ? action.payload.container : c
  13. })
  14. }
  15. // multiple instances
  16. if (has(action.payload, 'containers')) {
  17. containers = action.payload.containers
  18. }
  19. return containers
  20. }
  21. /**
  22. *
  23. */
  24. const containersReducer = createReducer([], {
  25. 'REQUEST_OK': setContainers
  26. })
  27. /**
  28. *
  29. */
  30. export const containers = (state = [], action) => {
  31. return containersReducer(state, action)
  32. }