redux-aggregate-immer
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

redux-aggregate-immer

Latest Version CircleCI

The helper module for redux-aggregate. Below code be able to write more comfortable, with wrapImmer.

 
const initialState = {
  count: 0,
  nested: { some: { value: 'string' } }
}
//
// @ Mutations
 
function increment(s) {
  return { ...s, count: s.count + 1 }
}
function decrement(s) {
  return { ...s, count: s.count - 1 }
}
function setNestedValue (s, value) {
  return {
    ...s,
    nested: {
      ...s.nested,
      some: {
        ...s.nested.some,
        value
      }
    }
  }
}
export const Mutations = {
  increment,
  decrement,
  setNestedValue
}

Mutable mutations will be convert to immutable mutations. To be careful not to return state at those mutation.

//
// @ with wrapImmer
 
import { wrapImmer } from 'redux-aggregate-immer'
 
const initialState = {
  count: 0,
  nested: { some: { value: 'string' } }
}
//
// @ Mutations for wrapImmer
 
function increment(s) {
  s.count++
}
function decrement(s) {
  s.count--
}
function setNestedValue (s, value) {
  s.nested.some.value = value
}
export const Mutations = wrapImmer({
  increment,
  decrement,
  setNestedValue
})

/redux-aggregate-immer/

    Package Sidebar

    Install

    npm i redux-aggregate-immer

    Weekly Downloads

    1

    Version

    1.1.3

    License

    MIT

    Unpacked Size

    250 kB

    Total Files

    22

    Last publish

    Collaborators

    • takepepe