Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. let RetryStrategy = attempts => attempts
  2. .zip(Observable.range(1, 4))
  3. .flatMap(([error, i]) => {
  4. if (i > 3) {
  5. return Observable.throw('Network error occured')
  6. }
  7. return Observable.timer(i * 1000)
  8. })
  9.  
  10. export const deleteSurveyQuestionEpic = (action$, {getState, dispatch}) =>
  11. action$.ofType('MY_ACTION')
  12. .switchMap(
  13. action => ajax.delete(`myURL`)
  14. .map(res => res.response)
  15. .flatMap(response => {
  16. console.log(response) // <-- returns null
  17. return arrayRemove('formName', 'questions', 1) // <-- redux-form action-creator
  18. })
  19. .retryWhen(RetryStrategy)
  20. .takeUntil(action$.ofType('MY_CANCEL_ACTION'))
  21. .catch((e) => {
  22. return Observable.of(
  23. errorSurvey((e.xhr && `Error ${e.xhr.statusText}: ${e.xhr.statusText}`) || 'Network error occured')
  24. )
  25. })
  26. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement