1.1.3 • Published 5 years ago

redux-aggregate-immer v1.1.3

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

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
})
1.1.3

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

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