【发布时间】:2020-04-20 19:08:25
【问题描述】:
我有以下代码,它正在工作,但我读过链接订阅是一种反模式。在调用需要用户 authtoken 的 API 之前,我需要确保用户的登录状态为 true。
在 RXJS 中处理这个问题的正确方法是什么?
const subscrAuth = this.store
.pipe(select(isLoggedIn))
.subscribe(isLoggedIn => {
console.log(isLoggedIn);
if (isLoggedIn) {
const subscrLoaded = this.store
.pipe(select(hasCarriersLoaded))
.subscribe(hasCarrierLoaded => {
if (!hasCarrierLoaded) {
this.store.dispatch(new CarriersPageRequested());
}
});
}
});
this.unsubscribe.push(subscrAuth);
【问题讨论】: