javascript - How do I unsubscribe from inner observables in redux observable?
问题描述
In the following epic I am listening to an action$ stream and then also listening to an auth stream 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'))
);
It works as expected, the only problem is that if I change the auth status by logging out then the epic fires the signIn()
method since user
is no longer available.
How do I stop listening to authState(app.auth())
once I have signed in. Where does the unsubscribe logic go in an epic?
解决方案
只要您的应用程序正在运行,史诗就应该保持活力。
您没有完成它们,而是将它们静音。
要使流静音,有很多可能性。例如,windowToggle
operator 将允许您通过其他流(例如,通过其他事件的流)使您的 observable 静音。
例如,您在中间时将史诗静音SIGN_IN
-SIGN_OUT
序列。SIGN_OUT
并在-SIGN_IN
期间取消静音。
这是一篇关于rxjs 的不同暂停策略的文章。
希望这可以帮助
推荐阅读
- active-directory - Linux Samba/Winbind - 使用 SSH 时组不刷新 - Active Directory 成员资格
- python - matplotlib 绘图标签之间的相同空间
- node.js - 我在nest.js 中出现“Nest 无法解析 WorkspaceController 的依赖项...”错误
- mysql - 尝试使用每周数据创建数据转储,但大日期范围会覆盖所有数据
- java - 如何在 Java spring mvc 项目中从 FTP 服务器获取 pdf 文件作为 base64 编码格式?
- python - Python unrar 模块在读取 .rar 文件时抛出 MemoryError
- python-3.x - 在从表中抓取数据时将自定义字符串添加到字符串列表
- javascript - 如何在 React 组件的功能中使用 React 组件之外的 const 值
- c++ - CShellManager 初始化失败
- makefile - 使用 Makefile 将目标文件编译到发布和调试文件夹中