我正在学习CycleJS,我发现在使用Cycle的HTTP驱动程序时,我必须使用RxJS switch/mergeAll合并response stream stream才能达到流级别。但是当我尝试应用这些函数时,我得到了一个类型错误:switch is not a function (on response stream)。
const response$$ = sources.HTTP
.filter(response$ => response$.request.url === 'http://jsonplaceholder.typicode.com/users/1')
const response$ = response$$.switch()如果我遗漏了什么,请告诉我好吗?
发布于 2016-07-03 21:01:25
filter返回一个传输流,因此它不具有流的功能。
要获取流,在filter之后,使用response$$从生成的传输流中拉出response$$流,然后对其执行flatten:
const response$$ = sources.HTTP
.filter(response$ => response$.request.url === 'http://jsonplaceholder.typicode.com/users/1')
.response$$
const response$ = response$$.flatten()现在您可以继续使用map等(可用的运算符取决于您正在使用的版本。最新的使用作为它的流引擎。)
@cycle/http response$$
使用HTTP源的
,您也可以使用
httpSource.response$$来获取传输流。您应该在使用传输流之前将其展平,然后生成的响应流将发出通过superagent接收的响应对象。
或者,您可以简单地:
const response$ = sources.HTTP
.filter(response$ => response$.request.url === 'http://jsonplaceholder.typicode.com/users/1')
.response$$.flatten()现在,您已经拥有了要使用的response$。
发布于 2016-07-18 21:42:16
switch是一种RxJS运算符,它在xstream中的类似物是flatten。流引擎取决于您从哪个*-run包导入run函数。例如,如果您使用import {run} from 'rx-run',则来自驱动程序的所有源码流都将带有稳定的RxJS 4接口。
所有这些多数据流引擎的东西都是非常新的,在最新版本中引入。您可以考虑阅读migration guide
https://stackoverflow.com/questions/38166395
复制相似问题