gpt4 book ai didi

javascript - switch/mergeAll/flatten 不是函数 - 在 cyclejs 中使用 http 驱动程序时

转载 作者:行者123 更新时间:2023-11-30 15:58:15 24 4
gpt4 key购买 nike

我正在学习 CycleJS,我发现在使用 Cycle 的 HTTP 驱动程序时,我必须使用 RxJS switch/mergeAll 合并 response stream 流 以达到流级别.但是当我尝试应用这些函数时,出现类型错误:switch is not a function(在响应流流上)。

  const response$$ = sources.HTTP
.filter(response$ => response$.request.url === 'http://jsonplaceholder.typicode.com/users/1')
const response$ = response$$.switch()

如果我遗漏了什么,你能告诉我吗?

最佳答案

@cycle/http filter 返回一个 metastream,因此它没有 stream 的功能。

要获取,在您过滤之后,从生成的metastream 中提取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.js 的版本。最新的使用 xstream 作为 引擎。)

@cycle/http response$$

With an HTTP Source, you can also use httpSource.response$$ to get the metastream. You should flatten the metastream before consuming it, then the resulting response stream will emit the response object received through superagent.


或者你可以简单地:

const response$ = sources.HTTP
.filter(response$ => response$.request.url === 'http://jsonplaceholder.typicode.com/users/1')
.response$$.flatten()

现在您可以按预期使用 response$ 了。

关于javascript - switch/mergeAll/flatten 不是函数 - 在 cyclejs 中使用 http 驱动程序时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38166395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com