After dispatching SEARCH
, I'm trying to cancel an AJAX request but also to keep the observable listening. I'm using takeUntil
and waiting for an action of type CLEAR_SEARCH_RESULTS
to cancel the request.
Here's my epic:
const searchEpic = action$ =>
action$.ofType(SEARCH).pipe(
debounceTime(500),
switchMap(({ payload }) =>
search(query).pipe(
map(({ response }) => SearchActions.searchSuccess(response)), // dispatches SEARCH_SUCCESS
takeUntil(
action$.ofType(CLEAR_SEARCH_RESULTS)
)
)
)
)
Edit: I have a Redux logger which outputs dispatched actions in the following order:
SEARCH
SEARCH
SEARCH
SEARCH
CLEAR_SEARCH_RESULTS
SEARCH_SUCCESS
(each SEARCH
is a keystroke)