normalized-data-structure
v1.1.1
Published
Utilities for working with simple "Normalized" structure with immutablity. Designed for Redux
Readme
Normalized Data Structure
A very simple library to make it easier to work with Redux Normalizing State Shape, in an immutable way.
Written in typescript.
Structure
byId: Simple "dictionary", where the object key is the items unique identifier
allIds: Array of all unique identifiers
Usage
empty<T>: create a new normalized data structure of typeT. Ex:{ byId: {}, allIds: [] }forEach: loop through each itemmap: map items returning a new Arrayfilter: filter items, returning a new Arrayset: add an item by key, over-writing any previous itemaddItems: add a array of items to the structure. Takes either akeyof Tor a selector function that returns a string to specify the structurekey.removeItem: Remove item by keyfromArray: creates a new "normalized" object from an array. Takes either akeyof Tor a selector function that returns a string to specify the structurekey.toArray: get all items as an array
