Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

loadingMiddleware.js 795B

123456789101112131415161718192021222324252627282930
  1. import {
  2. DELETE,
  3. ERROR,
  4. FETCH,
  5. SUCCESS,
  6. UPDATE,
  7. SUBMIT,
  8. } from '../actions/actionHelpers';
  9. import { addLoader, removeLoader } from '../actions/app/appActions';
  10. const promiseTypes = [FETCH, UPDATE, DELETE, SUBMIT];
  11. export default ({ dispatch }) => (next) => (action) => {
  12. const promiseType = promiseTypes.find((promiseType) =>
  13. action.type.includes(promiseType),
  14. );
  15. if (promiseType) {
  16. dispatch(addLoader(action.type));
  17. return next(action);
  18. }
  19. if (action.type.includes(SUCCESS) || action.type.includes(ERROR)) {
  20. // const actionType = action.type.includes(SUCCESS)
  21. // ? action.type.replace(SUCCESS, '[LOADING]')
  22. // : action.type.replace(ERROR, '[LOADING]');
  23. dispatch(removeLoader(action.type));
  24. return next(action);
  25. }
  26. next(action);
  27. };