Utility library for the flux entity pattern

Motivation

A common pattern when working with a flux-based system such as Redux is to use a normalized registry of objects, keyed by some unique value.

Installation

With npm

npm install --save flux-entity

With yarn

yarn add flux-entity

API

createEntityFactory ( ) insertIntoArray ( array , ... values ) removeFromArray ( array , ... values ) clearEntity ( entity ) copyEntity ( entity ) insertIntoEntity ( entity , ... values ) removeFromEntity ( entity , ... values ) removeFromEntityById ( entity , ... ids )

Examples

Say we have an object type Person .

interface Person { }

Create an entity factory for type Person . By supplying Person , we can get excellent type safety with Typescript.

Create an entity, keyed by id . This will now mean that each Person is indexed with their id as the uniqueness qualifier.

We now have an empty entity.

{ key : ' id ' , ids : [ ] , all : { } , }

Insert a value into the entity.

insertIntoEntity ( entity , )

The resulting entity state now looks like this.