Guest User

Untitled

a guest
Mar 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // api/loadingReducer.js
  2. const loadingReducer = (state = {}, action) => {
  3. const { type } = action;
  4. const matches = /(.*)_(REQUEST|SUCCESS|FAILURE)/.exec(type);
  5.  
  6. // not a *_REQUEST / *_SUCCESS / *_FAILURE actions, so we ignore them
  7. if (!matches) return state;
  8.  
  9. const [, requestName, requestState] = matches;
  10. return {
  11. ...state,
  12. // Store whether a request is happening at the moment or not
  13. // e.g. will be true when receiving GET_TODOS_REQUEST
  14. // and false when receiving GET_TODOS_SUCCESS / GET_TODOS_FAILURE
  15. [requestName]: requestState === 'REQUEST',
  16. };
  17. };
Add Comment
Please, Sign In to add comment