Skip to content

Simple typed actions

Latest
Compare
Choose a tag to compare
@Reaverart Reaverart released this 06 Jun 13:51
· 6 commits to master since this release

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
      }
   ...
}