1.0.4 • Published 6 years ago

redux-regeneration v1.0.4

Weekly downloads
36
License
-
Repository
github
Last release
6 years ago

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)
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.0.9

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago