1.1.3 • Published 4 years ago

store-renew v1.1.3

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

store-renew

when you are coding with redux, you may need to return a new state every time you deel with a reducer, just like this.

const reducer = (state, { payload }) => {
  return {
    ...state,
    list: state.list.concat(payload)
  }
}

It's too difficult to produce a state in a new object instance, especially when you are deeling with a property in a deep object "keyPath", store-renew is just made to fix this, it allow you to return property's "keyPath" in current state and a new property diffrent from old one in an array, for example. you can use like this

import { renew } from 'store-renew'
const reducer = (state, { payload }) => renew(state, `list`, state.list.concat(payload))

or even like below, they has the same effects

import { reduce } from 'store-renew'
const reducer = reduce((state, { payload }) => [`list`, state.list.concat(payload)])

when you need to use dispatch, just as usual.

dispatch({ type: 'add', payload: { id: 1, name: 'King' } })
1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago