gpt4 book ai didi

javascript - RxJS forkjoin 未运行

转载 作者:行者123 更新时间:2023-12-03 04:13:42 26 4
gpt4 key购买 nike

我尝试通过 rx-http-request 使用 RxJS 从 NodeJS 服务器查询第三方 API。从长远来看,我想使用 RxJS 来处理一些更有趣的错误情况。但目前我在运行一个相当微不足道的案例时遇到了问题。

案例 1(可行):

third_party.js
import {RxHttpRequest} from 'rx-http-request'
export default ((name) => RxHttpRequest.get(`www.third.party.com/${name}`)

然后,

   import third from './third_party'
third('bob').subscribe(console.log)

情况2(这不是)

   import third from './third_party'
import Rx from 'rx'
Rx.Observable.forkJoin(third('bob')).subscribe(console.log)

情况 1 打印(正确的)第三方响应。案例 2 似乎根本没有运行过。当我打印出 console.log(Rx.Observable.forkJoin) 时,它会打印 Function,例如事实上我已经包含了 Rx 的正确部分。

案例3:在第三方:

export default ((name) => RxHttpRequest.get(`www.third.party.com/${name}`).map((res)=>console.log(res))

内部 console.log 触发,但外部订阅不触发。为什么会发生这种行为?我怎样才能真正将值发送到外部订阅?

最佳答案

如果您像这样导入rx-http-request:

import { RxHttpRequest } from 'rx-http-request';

您可能是这样安装的:

npm install --save rx-http-request

您可能没有注意到此警告消息:

npm WARN deprecated rx-http-request@1.2.0: This package is no longer maintained and was moved to @akanass/rx-http-request.

该版本 (1.2.0) 远远落后于 GitHub 存储库中的版本 (2.3.0)。

尝试使用@akanass/rx-http-request,而不是:

npm install --save @akanass/rx-http-request

import { RxHR } from '@akanass/rx-http-request';

导出似乎已更改,因此您应该查阅 docs .

此外,您应该小心使用 rx-http-request,因为它包含 rxjs 作为 dependency ,而不是对等依赖。这开启了安装多个 rxjs 包的可能性(取决于版本和安装顺序)。我鼓励您raise an issue将其更改为对等依赖。

关于javascript - RxJS forkjoin 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44231528/

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