All files / src/model modelSelectors.js

100% Statements 14/14
100% Branches 0/0
100% Functions 7/7
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17      17x 8x 8x 8x 8x 1x 1x 3x     8x      
import _ from 'lodash'
 
export default (model, routeParams, rootSelector) => {
  const getModelObj = state => rootSelector(state)[model.modelName]
  const getInstances = state => _.values(rootSelector(state)[model.modelName].instances)
  const isLoading = state => rootSelector(state)[model.modelName].request.loading
  const getCount = state => rootSelector(state)[model.modelName].last.count
  const getFound = state => {
    const found = rootSelector(state)[model.modelName].last.find
    const instances = rootSelector(state)[model.modelName].instances
    return _.map(found, id => instances[id])
  }
 
  return {
    getModelObj, getInstances, isLoading, getCount, getFound
  }
}