【问题标题】:RXJS + Redux Observable - how to merge a new stream?RXJS + Redux Observable - 如何合并一个新的流?
【发布时间】:2017-05-01 14:32:58
【问题描述】:

我们最近选择了 Redux Observable,它是管理高级操作编排的好方法。

我最近遇到的一个问题是响应数据获取的结果。我们有一个通用的服务函数,它返回一个 RXJS observable。通常我们会选择我们需要的任何数据并订阅。

我认为这对于 redux-observable 来说是相当自然的。在 Epic 上使用 MapTo,并在随后的选择中返回 RXJS 观察者。

据我所知,Redux-observable 没有订阅,所以什么也没有发生。

有没有人举例说明它应该如何工作?

export function redirectUserToEndpointEpic(action$) { return action$.ofType(LOCATION_CHANGE) .filter(action=>action.payload.pathname !== '/')) .mapTo(action=>authService.getObserver() // returns a stream which has not been subscribed to .select(userData=>userData.defaultPath) .map(push); }

【问题讨论】:

  • 您能否提供一些示例代码,即使没有功能,以更好地说明问题?
  • 当然。我会伪代码是export function redirectUserToEndpointEpic(action$) { return action$.ofType(LOCATION_CHANGE) .filter(action=>action.payload.pathname !== '/')) .mapTo(action=>authService.getObserver() // returns a stream which has not been subscribed to .select(userData=>userData.defaultPath) .map(push); }

标签: rxjs redux-observable


【解决方案1】:

这段代码实际上是正确的。依赖项使用的是“rx”库而不是“rxjs”,这会导致冲突。

谢谢大家

【讨论】:

    猜你喜欢
    • 2020-09-01
    • 2021-02-02
    • 2021-09-26
    • 2019-01-04
    • 1970-01-01
    • 2019-10-05
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多