1.0.4 • Published 6 years ago

set-state-redux v1.0.4

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

set-state-redux

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

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago