[英]RxJS forkjoin isn't running
I am attempting to use RxJS via rx-http-request
to query third party APIs from a NodeJS server. 我正在尝试通过
rx-http-request
使用RxJS从NodeJS服务器查询第三方API。 In the long run, I want to use RxJS to handle some of the more interesting error cases. 从长远来看,我想使用RxJS处理一些更有趣的错误情况。 But for the time being I am having issues getting a fairly trivial case to run.
但是目前我在运行一个相当琐碎的案例方面遇到问题。
Case 1 (this works): 情况1(可行):
third_party.js
import {RxHttpRequest} from 'rx-http-request'
export default ((name) => RxHttpRequest.get(`www.third.party.com/${name}`)
And then, 接着,
import third from './third_party'
third('bob').subscribe(console.log)
Case 2(this does not) 情况2(不是)
import third from './third_party'
import Rx from 'rx'
Rx.Observable.forkJoin(third('bob')).subscribe(console.log)
Case 1 prints the (correct) third party response. 情况1打印(正确)第三方响应。 Case 2 doesn't appear to ever run at all.
情况2似乎根本没有运行过。 When I print out console.log(
Rx.Observable.forkJoin
) it prints Function
, eg I have in fact included the right part of Rx. 当我打印出console.log(
Rx.Observable.forkJoin
)时,它会打印Function
,例如,实际上我已经包含了Rx的右侧部分。
Case 3: In thirdParty: 情况3:在第三方:
export default ((name) => RxHttpRequest.get(`www.third.party.com/${name}`).map((res)=>console.log(res))
The inner console.log triggers, but the outer subscribe does not. 内部console.log会触发,但外部订阅不会。 Why is this behaviour happening?
为什么会发生这种现象? And how can I actually send the values into the outer subscribe?
以及如何将这些值实际发送到外部订阅中?
If you are importing rx-http-request
like this: 如果要像这样导入
rx-http-request
:
import { RxHttpRequest } from 'rx-http-request';
You likely installed it like this: 您可能是这样安装的:
npm install --save rx-http-request
And you might not have noticed this warning message: 而且您可能没有注意到以下警告消息:
npm WARN deprecated rx-http-request@1.2.0: This package is no longer maintained and was moved to @akanass/rx-http-request.
npm WARN不推荐使用rx-http-request@1.2.0:此软件包已不再维护,已移至@ akanass / rx-http-request。
That version (1.2.0) is way behind the version that's in the GitHub repo (2.3.0). 该版本(1.2.0)远低于GitHub存储库(2.3.0)中的版本。
Try using @akanass/rx-http-request
, instead: 尝试使用
@akanass/rx-http-request
,而不是:
npm install --save @akanass/rx-http-request
import { RxHR } from '@akanass/rx-http-request';
The export appears to have changed, so you should consult the docs . 导出似乎已更改,因此您应查阅docs 。
Also, you should take some care with rx-http-request
, as it includes rxjs
as a dependency , rather than a peer dependency. 另外,您应该注意
rx-http-request
,因为它包括rxjs
作为依赖项 ,而不是对等依赖项。 This opens the possibility of multiple rxjs
packages being installed (depending upon versions and installation order). 这样就可以安装多个
rxjs
软件包(取决于版本和安装顺序)。 I would encourage you to raise an issue to have it changed to a peer dependency. 我鼓励您提出一个问题 ,将其更改为对等依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.