如何取消订阅 redux observable 中的内部 observables?

How do I unsubscribe from inner observables in redux observable?

在接下来的史诗中,我正在收听 action$ 流,然后还收听 auth 流 authState(app.auth())

export const fetchAuthStatus = action$ =>
      action$.pipe(
        ofType(AUTH_STATUS_CHECKED),
        switchMap(() => authState(app.auth())),
        switchMap(user =>
          user
            ? of({ type: 'SIGNED_IN', payload: user })
            : signIn(googleAuthProvider)
        ),
        catchError(error => console.log('problems signing in'))
      );

它按预期工作,唯一的问题是,如果我通过注销更改身份验证状态,那么史诗会触发 signIn() 方法,因为 user 不再可用。

如何在登录后停止收听 authState(app.auth())。取消订阅逻辑在史诗中的什么位置?

Epics 应该只要您的应用程序 运行.

就可以存活

你没有完成它们,你将它们静音

要使流静音,有很多种可能性。例如,windowToggle 运算符可以让您通过其他流(例如其他事件流)使您的可观察对象静音。

例如您在 in-between SIGN_INSIGN_OUT 序列时将史诗静音。并在 SIGN_OUTSIGN_IN 期间取消静音。

这是一篇关于 different pausing strategies with rxjs 的文章。

希望对您有所帮助