问题标签 [reactive-extensions-js]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1353 浏览

rxjs - RxJS - toBlocking 操作符

在 RxJava 中有 Observable.toBlocking() 操作符来同步检索 observable 的数据。我找不到 RxJS 的类似运算符。我想使用这个操作符来改进我的 Rx 代码,而不是使用另一个函数式编程库......

0 投票
2 回答
44574 浏览

javascript - Angular2 RxJS 得到“Observable_1.Observable.fromEvent 不是函数”错误

我正在使用 AngularJS 2 Beta 0,我正在尝试从窗口对象上的事件创建一个 RxJS Observable。我相信我知道在我的服务中将事件捕获为 Observable 的公式:

问题是每次我尝试运行此代码时,都会收到一条错误消息,指出“fromEvent”不是函数。

在我看来,这似乎意味着我没有import正确处理我的问题,因为 RxJS 不包含在 Angular 2 的构建中,尽管我的应用程序的其余部分功能正常,这对我来说意味着 RxJS 是它应该在的地方。

我在服务中的导入如下所示:

虽然我也尝试过使用它(对代码进行适当的更改),但结果相同:

我的 Index.html 中有以下配置:

有人可以告诉我我做错了什么吗?

0 投票
2 回答
1164 浏览

javascript - 等待 Observable 的 RxJS Observable

所以我有一个可观察的,它发出一个 HTTP 帖子以从服务器获取访问令牌。我有另一个执行对同一服务器的获取,但需要从第一个存在的访问令牌。所以我希望能够在两个不同的地方同时订阅两个 observable,但是 GET observable 当然必须等待 POST observable。如何在另一个 Observables 订阅完成时进行 observable 等待?

0 投票
1 回答
197 浏览

angular - RxJS:使用 Angular 2 的 JavaScript 响应式扩展

有人可以向我解释为什么 Angular 2 需要 RxJS 库以及它与 Observables 和 Angular 2 的确切关系吗

0 投票
2 回答
1352 浏览

javascript - Rx.Observable.interval,每个事件都有不同的间隔

我有一堆事件,每个事件都必须在前一个事件之后触发,并具有特定于该事件的延迟。

Rx.Observable.interval提供了只提供一个区间的可能性。

有没有办法提供不同的间隔?

0 投票
1 回答
898 浏览

javascript - Proper way to deal with errors thrown in "onNext" for hot, shared, observables

In RxJS version 5, the following code results in the process being terminated after three iterations of both subscriptions:

However, my understanding was that an error thrown in the next handler would simply unsubscribe that particular subscription, and not cause the underlying observable to terminate. My expected output would be that the "One" subscription would unsubscribe, but the interval would continue to produce results to the "Two" subscription.

This behavior is causing me issues, where I may have multiple subscriptions to an underlying hot observable - yet a single exception thrown on any of those subscriptions causes the underlying observable to completely terminate.

It's especially annoying when I'm in development using hot module reloading, since any programming error in any subscription causes me to have to refresh the entire page to re-start the observable sequences.

Is there a way, without wrapping each of my subscriptions in a try/catch, to have an exception thrown in my next handler to simply unsubscribe that ONE subscription, and not terminate the underlying observable?

------------ EDIT ------------

I've found the behavior that I'm looking for, by setting syncErrorThrowable to true on the subscription object returned by "subscribe". It seems that the only time this is ever set to true in the codebase is via the "do" operator.

Should I take advantage of this field? I feel pretty dirty using it, but on the other hand I find it strange that the "do" operator has different error handling semantics than the "next" subscription handler.

Here's the primary block of code affected by this flag: https://github.com/ReactiveX/RxJS/blob/master/src%2FSubscriber.ts#L132

If it's set to false, this method gets invoked: https://github.com/ReactiveX/RxJS/blob/master/src%2FSubscriber.ts#L179

Whereas if it's set to true, this method is used instead: https://github.com/ReactiveX/RxJS/blob/master/src%2FSubscriber.ts#L188

The difference is that the first method will re-throw the exception back up the callstack, whereas the second one instead propagates the error forward to subsequent subscriptions.

Why does the do operator propagate the error forward, whereas the "next" handler bubbles the error back up? This seems odd to me.

0 投票
2 回答
45 浏览

javascript - 在链中稍后访问变量

在下面的示例中,我将获取一个用户并为该用户创建一个目录。我想简单地记录用户已创建。user在链中稍后访问变量的最佳方法是什么?

我想做类似的事情:

0 投票
5 回答
16034 浏览

javascript - RxJs:轮询直到间隔完成或收到正确的数据

如何使用 RxJs 在浏览器中执行以下场景:

  • 提交数据到队列进行处理
  • 取回工作 ID
  • 每 1 秒轮询另一个端点,直到结果可用或 60 秒过去(然后失败)

我提出的中间解决方案:

  1. 一旦数据到达或发生错误,是否有没有中间变量的方法来停止计时器?我现在可以引入新的 observable 然后使用takeUntil
  2. flatMap这里的用法在语义上正确吗?也许这整个事情应该被重写而不是与flatMap?
0 投票
3 回答
236 浏览

javascript - RxJs:在 flatMapLatest 完成后在 flatMapLatest 之前访问数据

设想:

  1. 用户使用组合成单个流的过滤器
  2. 当过滤器更改时,会触发后端事件以获取“便宜”数据
  3. 当“廉价”数据到达时,另一个具有相同参数的请求被触发到不同的端点,返回“昂贵”数据,这些数据将用于丰富廉价数据。请求应延迟 1 秒,并且仅在用户未更改任何过滤器时触发(否则应等待 1 秒)

我正在为没有中间变量的 3) 选项而苦苦挣扎。

0 投票
1 回答
6348 浏览

typescript - 将 Array 转换为 Observable,执行转换并再次返回为 Array?

ngOnInit()我有我想放入的“返回 x” Observable,然后执行转换并以相同的格式再次返回。

这是工作的 plunker:http ://plnkr.co/edit/z26799bSy17mAL4P5MiD?p=preview