[英]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())
在下面的史诗中,我正在收听动作$ stream,然后还要监听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'))
);
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. 它按预期工作,唯一的问题是,如果我通过注销更改auth状态,那么epic将触发signIn()
方法,因为user
不再可用。
How do I stop listening to authState(app.auth())
once I have signed in. Where does the unsubscribe logic go in an epic? authState(app.auth())
如何停止收听authState(app.auth())
。取消订阅逻辑在哪里出现史诗?
Epics are supposed to stay alive as long as your app is running. 只要您的应用程序正在运行,Epics就会保持活力。
You don't complete them, you mute them . 你没有完成它们,你将它们静音 。
To mute a stream there are a lot of possibilities. 要使流静音,有很多可能性。 For example, windowToggle
operator will let you mute your observable by another streams, say, by streams of other events. 例如, windowToggle
运算符将允许您通过其他流(例如,其他事件流)使您的observable静音。
Eg you mute the epic while in-between SIGN_IN
— SIGN_OUT
sequence. 例如,您在SIGN_IN
- SIGN_OUT
序列之间静音史诗。 And unmute in SIGN_OUT
— SIGN_IN
period. 并在SIGN_OUT
- SIGN_IN
期间取消静音。
Heres an article on different pausing strategies with rxjs . 下面是关于rxjs的不同暂停策略的文章。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.