1.2.1 • Published 6 years ago
normalize-list v1.2.1
Normalize-List
Allows you convert array to normalized object with keys of specified field and back to array About normalized state : http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html
Normalize
const {normalize}=require("normalize-list")
...
// array = [ { id : 1 , value : 1 }, { id : 2 , value : 2 } ]
const object=normalize(array,"id")// object = { '1' : { id : 1 , value : 1 } , '2' : { id : 2 , value : 2 } }
// -> use in state
Denormalize
const {denormalize}=require("normalize-list")
...
// normalizedObject = { '1' : { id : 1 , value : 1 } , '2' : { id : 2 , value : 2 } }
const array=denormalize(normalizedObject)// array = [ { id : 1 , value : 1 }, { id : 2 , value : 2 } ]
// -> list items / make a request