Skip to content

Higher-order reducer for store entities received from normalizr and makes it easy to handle them.

License

Notifications You must be signed in to change notification settings

itsmepetrov/redux-entities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redux Entities

build status npm version

Higher-order reducer for store entities received from normalizr and makes it easy to handle them.

Installation

npm install --save redux-entities

Usage

Use with entitiesReducer

import { combineReducers } from 'redux';
import { entitiesReducer } from 'redux-entities';
import { merge, omit } from 'lodash';

function contacts(state = {}, action) {
  const { type, payload } = action;

  switch (type) {

  case UPDATE_CONTACT:
  case REMOVE_CONTACT:
    return merge({}, state, { [payload.id]: {
      ...state[payload.id],
      isPending: true
    }});

  case UPDATE_CONTACT_SUCCESS:
    return merge({}, state, { [payload.id]: {
      ...state[payload.id],
      isPending: false
    }});

  case REMOVE_CONTACT_SUCCESS:
    return omit(state, meta.id);

  default:
    return state;
  }
}

export default combineReducers({
  contacts: entitiesReducer(contacts, 'contacts')
});

Use with combineEntitiesReducers

import { combineEntitiesReducers } from 'redux-entities';
import { contacts, groups, images, notes } from './entities';

export default combineEntitiesReducers({
  contacts,
  groups,
  images,
  notes
});

Immutable

If you want to use Immutable with Redux please check out this version of the library: redux-entities-immutable

About

Higher-order reducer for store entities received from normalizr and makes it easy to handle them.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published