redux-regeneration
v1.0.4
Published
regeneration of non-changed redux state values
Downloads
10
Maintainers
Readme
Redux-regeneration
Regenerates unchanged state
values instead of your reducers.
Usage regenerationMap Regenerative reducers Regeneration preventing
Installation
For install: npm i -S redux-regeneration
Usage
// reducer.js
import { applyRegeneration } from 'redux-regeneration'
const initialState = {
deep: {
value: 0,
another: 'bla'
},
shallowValue: [],
another: 'bla'
}
// since we construct the state by plain objects and use regeneration
// regenerativeReducer can return only clean state changes (also called as regenerationMap)
const regenerativeReducer = (state=initialState, action) => {
switch(action.type) {
case 'CHANGE_SHALLOW_VALUE':
return {
shallowValue: action.value
}
// same in vanilla reducer:
// return {
// ...state,
// shallowValue: action.value
// }
case 'CHANGE_DEEP_VALUE':
return {
deep: {
value: action.value
}
}
// same in vanilla reducer:
// return {
// ...state,
// deep: {
// ...state.deep,
// value: action.value
// }
// }
default: return state
}
}
export default applyRegeneration(regenerativeReducer)