1.0.0 • Published 5 years ago

reducer-tools v1.0.0

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

reducer tools travis

Create reducer easily

Usage

import { createReducer } from 'reducer-tools'

const initialState = { total: 0 }
const increase = s => ({ ...s, total: s.total + 1 })
const decrease = s => ({ ...s, total: s.total - 1 })

const reducer = createReducer(initialState, {
  'increase': increase,
  'decrease': decrease,
})

const a1 = { type: 'increase' }
const s1 = reducer(initialState, a1)
expect(s1.total).toBe(1)

Use reducer helps

import { createReducer, payloadReducer } from 'reducer-tools'

const add = value => state => ({ ...state, total: state.total + value })
const subtract = value => state => ({ ...state, total: state.total - value })
const reducer = createReducer(initialState, {
  'add': payloadReducer(add),
  'subtract': payloadReducer(subtract),
})

const a1 = { type: 'add', payload: 10 }
const s1 = reducer(initialState, a1)
expect(s1.total).toBe(10)
1.0.0

5 years ago

1.0.0-beta4

5 years ago

1.0.0-beta3

5 years ago

0.2.2

5 years ago

1.0.0-beta2

5 years ago

1.0.0-beta1

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago