immer-combine-reducers
v1.0.1
Published
Immer Combine Reducers : redux combineReducers like for immer!
Downloads
96
Maintainers
Readme
immer-combine-reducers
Immer Combine Reducers : redux combineReducers like for immer!
Installation
Using npm:
$ npm install --save immer-combine-reducers
Or yarn:
$ yarn add immer-combine-reducers
Usage
store.js
import { createStore, applyMiddleware } from 'redux';
import { immerCombineReducers } from 'immer-combine-reducers';
import produce from 'immer';
// Reducers
import { user } from './user';
import { catalog } from './catalog';
export const store = createStore(
immerCombineReducers(produce, {
user,
catalog,
// ...
// [key]: reducerFunction (change reducer name)
}),
composeWithDevTools(
applyMiddleware(sagaMiddleware),
applyMiddleware(thunk),
applyMiddleware(routerMiddleware),
),
);
user.js
const initialState = {
id: null,
profile: {}
};
export const user = (draft = initialState, action) => {
switch (action.type) {
case types.LOAD_USER:
draft.id = action.id;
draft.profile = action.profile;
return draft; // or just return;
default:
return draft; //important return draft on default for initialState!!
}
};
catalog.js
const initialState = [];
export const user = (draft = initialState, action) => {
switch (action.type) {
case types.LOAD_CATALOG:
draft = action.data;
return draft; // or just return;
default:
return draft; //important return draft on default for initialState!!
}
};
Feedback
Let me know what do you think! Enjoy it? Star this project! :D
any idea? let me know and contribute!
Contributors
See Contributors.