无法获取 takeUntil 取消请求

Can't get takeUntil to cancel the request

发送 SEARCH 后,我正在尝试取消 AJAX 请求,同时保持 observable 监听。我正在使用 takeUntil 并等待 CLEAR_SEARCH_RESULTS 类型的操作来取消请求。

这是我的史诗:

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)
                )
            )
        )
    )

编辑: 我有一个 Redux 记录器,它按以下顺序输出调度的操作:

  1. SEARCH
  2. SEARCH
  3. SEARCH
  4. SEARCH
  5. CLEAR_SEARCH_RESULTS
  6. SEARCH_SUCCESS

(每个SEARCH是一个击键)

我通过将 takeUntil 移到 switchMap 之外并在其后放置 repeat() 来解决它,如下所示:

const searchEpic = action$ =>
    action$.ofType(SEARCH).pipe(
        debounceTime(500),
        switchMap(({ payload }) =>
            search(query).pipe(
                map(({ response }) => SearchActions.searchSuccess(response))
            )
        ),
        takeUntil(action$.ofType(CLEAR_SEARCH_RESULTS)),
        repeat()
    )

问题是史诗仅在 debounceTime 的 500 毫秒后才开始侦听 CLEAR_SEARCH_RESULTS,这不是我想要的。

所有功劳归于 by Jay Phelps and to Evert Bouw for finding and pointing it out to me on Gitter