Git Product home page Git Product logo

entities-reducer's Introduction

Entities Reducer

Build Status Code Coverage version

Watch on GitHub Star on GitHub

This package is a high-order reducer that updates state using entities from normalizr. By default, it expects the action to have a property of entities or to follow the flux-standard-action spec. However, it is possible to pass a data resolver (see Parameters) if your case doesn't match either of those.

Why

Why does this package exist?

One of the best things to store in redux is data from server requests. Additionally, working with items stored in redux is best done when the data is normalized. To simplify the storing of the data, this package will handle updating state with fresh normalized data.

Entities Reducer is a high-order reducer, which means it will accept more reducers for further customizations. The custom reducers are passed directly to combineReducers from redux and should be passed into entities-reducers with the same format.

Installation

npm install --save entities-reducer
--- or ---
yarn add entities-reducer

Then add to your root reducer:

import { combineReducers } from 'redux';
import entitiesReducer from 'entities-reducer';

const rootReducer = combineReducers({
  entities: entitiesReducer({
    /* custom reducers here */
  }),
});

export default rootReducer;

Parameters

entitiesReducer(reducers, { dataResolver })

Reducers

Reducers are passed directly into combineReducers from redux, after the entities have been updated in state. It is called with the updated state and immediately returned.

dataResolver

The data resolver is a lookup function that is passed the action and returns the entities object to use while updating. If the data resolver returns a falsy value the entities-reducer will skip process and move directly to handling the custom reducers. Below is a customer dataResolver example, or you can checkout the default resolver. Example

const customDataResolver = (action) => {
  if (action.error) {
    return false;
  }
  return action.data.extra.normalized;
}

entities-reducer's People

Contributors

kwelch avatar rbrewington avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.