Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruanyl/reducer-tools
https://github.com/ruanyl/reducer-tools
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ruanyl/reducer-tools
- Owner: ruanyl
- License: mit
- Created: 2018-05-01T12:29:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T03:21:45.000Z (about 2 years ago)
- Last Synced: 2024-12-05T16:18:51.478Z (about 1 month ago)
- Language: TypeScript
- Size: 725 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## reducer tools ![travis](https://travis-ci.org/ruanyl/reducer-tools.svg?branch=master)
Create reducer easily
#### Usage
```typescript
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
```typescript
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)
```