0
votes

I have following statement which was working well with rxjs5.5 and redux observable 0.x. Now, I'm using redux-observable v1, and rxjs v6. I coulnd't figure out how to trasform race for following code (since it's usage deprecated).

(action$, state$) =>
    action$.pipe(
      ofType(REQUEST),
      switchMap(action => {
        return race(
          action$.pipe(
            ofType(REQUEST_CANCEL),
            take(1),
            mapTo(
              observableOf(
                failure({
                  description: "Cancelled by user."
                })
              )
            ),
            ajax(`url`).pipe(
              map(response => response.response),
              map(data => success(data)),
              catchError(error =>
                handleError(FAILURE, error)
              )
            )
          )
        );
      })
    ),

There migh be some other problem, It doesn't make the request. It think race is the problem.

1

1 Answers

0
votes

I missed the updated documentation,

import { ajax } from 'rxjs/ajax';

const fetchUserEpic = action$ => action$.pipe(
  ofType(FETCH_USER),
  mergeMap(action => race(
    ajax.getJSON(`/api/users/${action.payload}`).pipe(
      map(response => fetchUserFulfilled(response))
    ),
    action$.pipe(
      ofType(FETCH_USER_CANCELLED),
      map(() => incrementCounter()),
      take(1)
    )
  ))
);