redux-regeneration

1.0.4 • Public • Published

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)

Package Sidebar

Install

npm i redux-regeneration

Weekly Downloads

8

Version

1.0.4

License

none

Unpacked Size

13.6 kB

Total Files

7

Last publish

Collaborators

  • phationmationion