【发布时间】: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