All files / entities selectors.js

100% Statements 10/10
100% Branches 2/2
100% Functions 5/5
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20      2x     5x   2x 4x     2x 1x     2x 2x    
import map from 'lodash/map'
import curry from 'lodash/curry'
 
const EMPTY_OBJECT = {}
 
// root state selector
export const getEntities = curry(state => state.entities)
// get all entities for domain as an object
export const getDomain = curry(function(domain, state) {
  return getEntities(state)[domain] || EMPTY_OBJECT
})
// get single entity from domain, by its id
export const getById = curry(function(domain, id, state) {
  return getDomain(domain, state)[id]
})
// get all entities as an array
export const getAll = curry((domain, state) =>
  map(getDomain(domain, state), value => value)
)