GithubHelp home page GithubHelp logo

redux-entities's Introduction

Redux Entities

A set of redux actions/selectors/reducers that helps you store and modify data.

Docs

Overview

Getting Started

All that is required to use this library is redux

1. Pre-requisites

Required

  • redux

Optional

  • normalizr The reducers for this library are based on the normalizr library

2. Install the library

npm install alexs-redux-entities

3. Add the reducer to your root reducer

Import createEntitiesReducer from the library and add it into your root reducer.

// your root reducer
import createEntitiesReducer from 'alexs-redux-entities';

export default combineReducers({
  ..., // your other reducers,
  entities: createEntitiesReducer()
})

4. Add some entities

The concept of entities in this library is based on the normalizr library (it is even encouraged to use it), all entities are stored by their entity type and then their their id.

Please note though, this library does not offer any way to store lists of ids as is normal for the normalized pattern, this is up to you to implement for now.

To add entities into the store, dispatch any action with the payload entities (unless configured differently), where entities is the normalized data.

// Without normalizr
dispatch({
  type: 'SOME_ACTION',
  payload: {
    entities: {
      todo: {
        1: {
          id: 1,
          title: 'Do stuff',
          completed: false
        }
      }
    }
  }
})

// With normalizr
dispatch({
  type: 'SOME_ACTION',
  payload: normalize({id: 2, title: 'Do other stuff', completed: false}, todoSchema)
})

6. Set up your selectors

To generate the selectors use createEntitySelectors, which takes the following arguments

  • entityName The name of the entity to generate the selectors for
  • getState Get the sub-state for where you place the entities store
// wherever-you-keep-selectors.js
import { createEntitySelectors } from 'alexs-redux-entities';

export const todoSelectors = createEntitySelectors('todo', state => state.entities);

redux-entities's People

Contributors

alexrobinson- avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.