redux-heat 🔥
Redux side-effects as a function of state.
- Reducers and action creators as pure functions;
- It is not a middleware, so setup and testing are super easy;
- Follows the same pattern as React (decide what to do based on the state and not the actions);
- Effects are pure functions.
Install
Add it as a dependency in your project:
npm install --save redux-heat
Usage
Here is a simple example to fetch user details once the id of the user changes is the Redux store:
// Define a selector to define what data to check for changesconst getUserId = stateuserId // Action creatorsconst setUserDetails = type: 'SET_USER_DETAILS' payload: user const notifyUserFetchFailed = type: 'FETCH_USER_FAILED' payload: e const fetchUser = // Describe the effect based on state changesconst fetchUserHeat = fn: fetchUser args: onValue: setUserDetails onError: notifyUserFetchFailed // Then subscribe the effect to the Redux store