Redux-dunk — A better effect middleware for redux
Effect middleware for redux, inspired by loop and thunk
Schedule async functions from reducers to run after reducers using dispatch-getstate
store api.
But why creating yet another library?
Background and motivation
Redux is an extremely popular state management library for JS applications, however, side-effect handling seems to be one side of it where the community has never really settled on a single preferred solution. There’s redux-thunk, which is famously only 14 lines long, then redux-loop, redux-saga, redux-observable, and many more.
What is redux-dunk?
Out of all of the previously mentioned side-effect libraries there is one architecture that seemed to me and many others at Prezi to be the most sensible. It’s the one that redux-loop also follows and it looks like this:
This means you can schedule async functions that run after the reducer and can trigger new state changes with dispatch
. Optionally you can get the current state in the effect, both in dunk and loop using getState
.
As said redux-dunk has similarities with redux-loop, but here are the differences:
- Dunk is a much smaller library, helpers included
- Dunk is written in TypeScript
- Simpler, more flexible Effect API (just
dispatch
andgetState
, gives you everything you need) - Easy testing with
Jest
andredux-mock-store
- Dunk is just a middleware, not an enhancer, it’s architecture is simpler too
Dunk is being used at Prezi in frontend applications such as the latest integrated version of https://prezi.com/video.
For more in-depth information visit the repo 😉: