Releases: Reaverart/redux-callapi-middleware
Simple typed actions
Sometimes we dont want to handle all the request
, success
, failure
action types or reducer is simple enough to handle all of them at once, so with new release you can use simple typed action:
[CALL_API]: {
type: YOUR_ACTION_TYPE,
...
}
in result it will dispatch following actions:
{
type: YOUR_ACTION_TYPE,
[CALL_API_PHASE]: REQUEST || SUCCESS || FAILURE ,
}
where CALL_API_PHASE
- is a js Symbol
you can import from library and phases are constants library also exports. I.e. if in reducer you need to check phase then:
import { CALL_API_PHASE, callApiPhases } from `redux-callapi-middleware`;
// reducer.js
(state, action) => {
...
case YOUR_ACTION_TYPE:
const phase = action[CALL_API_PHASE];
if (phase === callApiPhases.REQUEST) {
// handle request
} else if (phase === callApiPhases.SUCCESS) {
// handle success
} else if (phase === callApiPhases.FAILURE) {
// handle failure
}
...
}
Remove fetch dependency
Breaking changes
No more fetch dependency, instead of optional interceptors you need to pass your own fetch
function named callApi
that should return a Promise
. This way is more flexible in part that your project might already have own fetch implementation and it might be any lib like axios or isomorphic-fetch or anything.
0.3.0
Batch multiple requests and response interceptors!
✨ batch requests is out! Now it allows to fetch multiple requests at once!
✨ response interceptors!
Breaking changes:
- createMiddleware now receives responseSuccess and responseFailure interceptors, see create middleware in readme