https://github.com/halfzebra/algebraic-actions
🌈 Algebraic Actions in Redux
https://github.com/halfzebra/algebraic-actions
algebraic-data-types javascript redux
Last synced: 2 months ago
JSON representation
🌈 Algebraic Actions in Redux
- Host: GitHub
- URL: https://github.com/halfzebra/algebraic-actions
- Owner: halfzebra
- Created: 2018-08-27T21:30:07.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-28T14:01:40.000Z (almost 8 years ago)
- Last Synced: 2025-01-20T10:21:12.580Z (over 1 year ago)
- Topics: algebraic-data-types, javascript, redux
- Language: JavaScript
- Homepage:
- Size: 110 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# algebraic-actions
A library that helps representing Redux [Actions](https://redux.js.org/basics/actions) as an [Algebraic Union Type](https://en.wikipedia.org/wiki/Algebraic_data_type) in JavaScript.
In helps to describe state transitions in a type-safe manner with exhaustive Action coverage.
## Usage
```js
const Actions = withCase(fromObject({
Increment: PropTypes.any,
Decrement: PropTypes.any,
DecrementBy: PropTypes.number
}));
const reducer = Actions.case({
Increment: state => state + 1,
Decrement: state => state - 1,
DecrementBy: (state, number) => state - number,
_: (state = 0) => state
});
const store = createStore(reducer);
store.dispatch(Actions.Increment())
```
## Acknowledgements
- [Elm: Custom Types](https://guide.elm-lang.org/types/custom_types.html)
- [fantasyland/daggy](https://github.com/fantasyland/daggy)
- [paldepind/union-type](https://github.com/paldepind/union-type)