All files / hash index.js

100% Statements 15/15
100% Branches 4/4
100% Functions 6/6
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41            2x       2x 2x     1x 1x     1x 1x     5x 5x 4x 4x     1x       2x 2x 2x            
import dotProp from 'dot-prop-immutable'
import { buildReducer } from '../lib/buildReducer'
import * as ActionTypes from './actionTypes'
export * from './actions'
export * from './selectors'
 
const reducer = buildReducer(
  {},
  {
    [ActionTypes.HSET]: (state, action) => {
      const { value, path } = action.payload
      return dotProp.set(state, path, value)
    },
    [ActionTypes.HDEL]: (state, action) => {
      const { path } = action.payload
      return dotProp.delete(state, path)
    },
    [ActionTypes.HMSET]: (state, action) => {
      const { value, path } = action.payload
      return dotProp.merge(state, path, value)
    },
    [ActionTypes.HINCRBY]: (state, action) => {
      const { value, path } = action.payload
      if (dotProp.get(state, path)) {
        return dotProp.set(state, path, v => {
          return (Number(v) || 0) + value
        })
      } else {
        return dotProp.set(state, path, value)
      }
    },
    [ActionTypes.HTOGGLE]: (state, action) => {
      const { path } = action.payload
      const currentValue = Boolean(dotProp.get(state, path))
      return dotProp.set(state, path, !currentValue)
    }
  }
)
 
export default reducer