12345678910111213141516171819202122232425262728293031323334353637 |
- import { createReducer } from '../utils/reducer'
- import { has, map, isEqual } from 'lodash'
- /**
- *
- * @param {*} containers
- * @param {*} action
- */
- const setContainers = (containers, action) => {
- // single instance
- if (has(action.payload, 'container')) {
- containers = map(containers, c => {
- return isEqual(c.id, action.payload.container.id) ? action.payload.container : c
- })
- }
- // multiple instances
- if (has(action.payload, 'containers')) {
- containers = action.payload.containers
- }
- return containers
- }
- /**
- *
- */
- const containersReducer = createReducer([], {
- 'REQUEST_OK': setContainers
- })
- /**
- *
- */
- export const containers = (state = [], action) => {
- return containersReducer(state, action)
- }
|