【发布时间】:2021-02-06 13:09:18
【问题描述】:
我有两个stores 需要准备合并数据
- 获取所有部门(前 50 个部门)
- 获取所有用户(例如:
1000用户)
我想合并数据并准备最终数据。 注意:部门会要求加载所有用户(这可能需要一些时间),并且不知不觉地,users 不能自己做任何事情,因为他们需要 department 数据来准备最终结果。
这里是department:
this.store.select(getUserInfo).subscribe((info) => {
this.store.select(getAllDepts).subscribe((depts) => {
if (depts.length < 1) {
this.store.dispatch(loadDeptStore({ accountId: info.acntId}));
} else {
console.log(depts); // get Dept data
}
});
})
对于Users 我拥有的数据:
this.store
.select(getUserInfo)
.pipe(
flatMap((info) => {
this.acntName = info.acntId;
return this.store.select(getAllUsers, { accountId: info.acntId });
})
)
.subscribe((res) => {
if (res.length < 1 ) {
this.store.dispatch(loadUsersInAccountStore({ billingCrmAccountId: this.acntName }));
} else {
console.log(res); // get users data
}
})
我应该使用combineLates 或其他东西吗,如果是,我应该如何使用 RxJS 功能以反应的方式做到这一点。
【问题讨论】:
标签: angular redux rxjs observable ngrx