all files / src/structure/plain/ getIn.js

100% Statements 21/21
100% Branches 10/10
100% Functions 4/4
100% Lines 7/7
1 statement, 2 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14    185×   180× 180×          
import toPath from 'lodash.topath'
 
const getInWithPath = (state, first, ...rest) => {
  if(!state) {
    return state
  }
  const next = state[first]
  return rest.length ? getInWithPath(next, ...rest) : next
}
 
const getIn = (state, field) => getInWithPath(state, ...toPath(field))
 
export default getIn