RxJS forkjoin 未运行



我正在尝试通过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))

内部控制台.log触发,但外部订阅不会触发。为什么会发生这种行为?我怎样才能实际将值发送到外部订阅?

如果要像这样导入rx-http-request

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

您可能像这样安装它:

npm install --save rx-http-request

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

npm WARN 已弃用的 rx-http-request@1.2.0:此包不再维护,并已移至 @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';

导出似乎已更改,因此您应该查阅文档。

另外,你应该小心rx-http-request,因为它包括rxjs作为依赖项,而不是对等依赖项。这打开了安装多个rxjs包的可能性(取决于版本和安装顺序(。我鼓励您提出一个问题,将其更改为对等依赖关系。

最新更新