set-state-redux

1.0.4 • Public • Published

set-state-redux

Travis CI npm

Love and setState is all you need.

Installation

npm install --save set-state-redux

Usage

const redux = require('redux')
const setStateRedux = require('set-state-redux')
 
// Reducers are optional. You can create a store without one.
function animalsReducer(state = [], action = {}) {
  switch (action.type) {
    case 'ADD_ANIMAL':
      return [ ...state, action.payload ]
    default:
      return state
  }
}
 
// Decorate `redux.createStore`
const createStoreWithSetState = setStateRedux.decorateCreateStore(redux.createStore)
 
// Use `createStoreWithSetState` as `redux.createStore`
const store = createStoreWithSetState(animalsReducer)
 
// Choose between dispatching actions...
store.dispatch({
  type: 'ADD_ANIMAL',
  payload: 'sheep'
})
 
// Or using `setState` directly
store.setState({ animals: ['dog', 'cow'] })

Example

FAQ

Why you did this? This is not blessed by the Holy Church of React!

Redux is an awesome piece of software, but too verbose to my needs. What I just need is setState. Actually what I need is unistore, but there is already a lot of code coupled with Redux on my current project. Consider this an intermediate solution.

This is a piece of shit! I'll not use that!

Whatever floats your boat, my dude. I'll use this shit because it's simpler and because shit floats as well.

You will lose time travel and all other nice things Redux give to you if you follow the conventions!

Actually not. There is a reducer under the hood, so everything is still supported.

Related


caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

Package Sidebar

Install

npm i set-state-redux

Weekly Downloads

11

Version

1.0.4

License

MIT

Unpacked Size

55.6 kB

Total Files

8

Last publish

Collaborators

  • caiogondim