如何使用rxjs和redux-observable实现promise类型的场景



我有一个场景,在保存表单数据后,用户将在react组件中看到一个通知。我不想把数据保存在redux存储中。如何使用redux-observable和react来做到这一点?

如果您正在询问如何将promise转换为observable,可以使用from运算符。在您的场景中,您可以尝试下面的代码。

const saveObservable$ = from(httpSvc.save(reqBody);
saveObservable$.pipe(
switchMap(saveMessage => from(notificationService.showNotificataion(saveMessage))),
take(1) // this will only take the first stream so we don't get memory leaks after subscribing.
).subscribe();

相关内容

最新更新