reducer-tools
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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)

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i reducer-tools

    Weekly Downloads

    74

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    8.67 kB

    Total Files

    16

    Last publish

    Collaborators

    • ruanyu1