1.0.8 • Published 6 years ago

red-redux-class v1.0.8

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

red-redux-class

Project assumptions

  • Keep immutability
  • Allow deep object nesting
  • Favor composition in reducers
  • Easy apply to a single reducer or whole project

Install

npm install --save red-redux-class

Usage

Base whole project on ReduxClass

Replace redux "combineReducers" with "combineReduxClassReducers" in your reducers.js file.

import { combineReduxClassReducers } from 'red-redux-class'

import yourReducer from './yourReducer'

const rootReducer = combineReduxClassReducers({
  yourReducer: yourReducer,
})

export default rootReducer

Use for single reducer

In yourReducer.js file import only a wrapper

import { ReduxClassWrapper } from 'red-redux-class'

function yourReducer(state = {}, action) {
  ...
}

export default ReduxClassWrapper(yourReducer)

Extend your redux object

File: YourReduxClass.js

In your class file, extend the class with ReduxClass.

 import { ReduxClass } from 'red-redux-class'

 class YourReduxClass extends ReduxClass {
   constructor(initialState) {
     super(initialState)
   }

   setAppName(appName) {
     this.set('appName', appName)
   }

   getAppName() {
     return this.appName
   }
 }

 export default YourReduxClass

File: yourReducer.js

Use your YourReduxClass object as initial state for your reducer. For every change in state create new state using new().

import { ReduxClassWrapper } from 'red-redux-class'
import YourReduxClass from './YourReduxClass'

const initialState = new YourReduxClass({
  appName: 'App name',
})

function yourReducer(state = initialState, action) {
  ...
    const newState = state.new()
    newState.setAppName('My app')
    return newState
  ...
}

export default ReduxClassWrapper(yourReducer)

CHANGELOG

1.0.7

  • removed dependencies

1.0.6

  • update packages

1.0.5

  • added initHiddenProperty to easily add hidden properties
  • added toJSON method for array redux class
1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago