Questions tagged [rxjs5]

The 5th version of the reactive extensions for javascript.

This tag is for questions regarding the 5th version of the ReactiveX framework for the JavaScript language.

Basics

RxJS is a framework for Observables. Observables are similar to Promises, in that they represent data, that may not jet be available. The difference is, that Observables can get multiple results (they are said to observe multiple events). These events could be anything, like clicks on a button, or network requests.

RxJS

rxjs provides an API for working with Observables in JavaScript. It has many methods, that allow modifying Observables, similar to how map(), filter() and reduce() work on ES6 Arrays.

Links

Before asking an rxjs5 question here on StackOverflow, please make sure to read the official documentation.

1510 questions
9
votes
1 answer

Trying to understand RxJS imports

I'm having a hard time figuring out how exactly this import statement works (in an Angular application written in Typescript): import 'rxjs/add/operator/toPromise'; I get that rxjs is mapped to the respective node_modules subfolder in the SystemJS…
lex82
  • 11,173
  • 2
  • 44
  • 69
9
votes
3 answers

How do I repeat an ajax request until a condition is met with RxJS Observable?

I'm attempting to repeat a request until the response has data using RxJS, at which point I'd like to call a success (or failure) handler, but I'm having trouble w/RxJS. Here's my current approach: // ... redux-observable action…
seitzej
  • 131
  • 1
  • 7
9
votes
4 answers

How do I test a function that returns an observable using timed intervals in rxjs 5?

For example, I have a function like this: export function timeRange(start: number, end: number): Rx.Observable { return Rx.Observable.interval(1000) .map(n => n + start) .take(end - start + 1) } And I had a unit test that ran…
Chris
  • 4,594
  • 4
  • 29
  • 39
9
votes
3 answers

Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

I have created a Rx.Observable from a stream of events: Rx.Observable.fromEvent(recognizeStream, 'data') In which every data event looks like this: { error: null, alternatives: [result1, result2, result3] } I want to pluck every value inside the…
lngs
  • 690
  • 1
  • 8
  • 17
9
votes
2 answers

Rx distinctUntilChanged allow repetition after configurable time between events

Let's consider for a moment the following code Rx.Observable.merge( Rx.Observable.just(1), Rx.Observable.just(1).delay(1000) ).distinctUntilChanged() .subscribe(x => console.log(x)) We expect that 1 is logged just once. However what if we…
franDayz
  • 883
  • 10
  • 22
9
votes
3 answers

Angular2 observable share is not working

Angular2 Observable share is not working and duplicate http calls going BuildingService.ts @Injectable() export class BuildingService { constructor(private http: Http){ } buildings$: Observable; this.buildings:…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
9
votes
2 answers

Subscribe to multiple Observables (like chaining then() in Promises)

My Angular 2 application has 2 methods (GetCategories() and GetCartItems()) in a service , and both of these methods return Observables. In order to invoke these two methods one after another from my component, I have written below code: ngOnInit()…
refactor
  • 13,954
  • 24
  • 68
  • 103
9
votes
1 answer

RxJS 5 and alternatives to the cache operator

Before upgrading RxJS to 5.0.0-rc.0 I was using .cache() a lot to share a subscription in my Angular application. The great advantage in using this was that any new subscription would get the last published value. The RxJS team decided to remove it,…
Martín Coll
  • 3,368
  • 3
  • 37
  • 52
9
votes
2 answers

Pause, upon resume give last paused value

I have a hot Observable fed by a socket. I can use the pausable to pause the socket feed. But once I 'unpause' the observable, I need to display the last values that the socket could have sent while the subscription was paused. I don't want to keep…
Thibs
  • 8,058
  • 13
  • 54
  • 85
9
votes
2 answers

RxJS (5.0rc4): Pause and resume an interval timer

I am using Rx to keep an animation clock. Every animation frame, it maps an interval tick to the new values for that tick. Suppose I want to pause the animation. The most natural way would be to somehow suspend the clock rx and then resume it at a…
masonk
  • 9,176
  • 2
  • 47
  • 58
9
votes
2 answers

How to subscribe exactly once to an element from AsyncSubject (consumer pattern)

In rxjs5, I have an AsyncSubject and want to subscribe to it multiple times, but only ONE subscriber should ever receive the next() event. All others (if they are not yet unsubscribed) should immediately get the complete() event without…
Dynalon
  • 6,577
  • 10
  • 54
  • 84
9
votes
1 answer

switchMapTo creates observable before subscription

I'm writing a timer stream using Date.now() and I'm having a problem understanding a detail. When I write the stream using a switchMap, it works fine, and the getTestStartTime$() is called after the start$ starts emitting events. let start$ =…
skovmand
  • 4,372
  • 5
  • 25
  • 30
9
votes
2 answers

Creating an RxJS Observable from a (server sent) EventSource

I would like to create a RxJs Observable from an EventSource (server sent events). I tried the following: import {Component, OnInit} from 'angular2/core'; import {Subject, Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', …
balteo
  • 23,602
  • 63
  • 219
  • 412
9
votes
1 answer

ReactiveX/RxJS 5 in the browser without any loaders?

How do you load RxJS in an old javascript application which does not use any loaders? For RxJS 4.x I could simply do it like this: What about RxJS 5? Their…
gerasalus
  • 7,538
  • 6
  • 44
  • 66
9
votes
2 answers

shareReplay in RxJS 5

According to the RxJS 5 MIGRATION.md it looks like shareReplay() been removed. Why? Does .publishReplay(1).refCount() faithfully replicate the behaviour? Basically I need to replay the single most recent data set to any new subscribers.
Philip Bulley
  • 9,014
  • 3
  • 33
  • 46