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
8
votes
2 answers

In RxJS what's the difference between error callback vs .catch()?

If I have code like the below: const d: any = {}; return this.http.post(url, body, httpOptions).map(data => { return d; }, error => { console.error('error'); }) .catch((err, d$) => { return Observable.of(d); }); and if there is any kind of…
Shikasta_Kashti
  • 701
  • 2
  • 13
  • 28
8
votes
2 answers

RXJS Continue with concat subscribe after error

I have an array of observables that need to fire off sequentially. Once an error happens, I need the to catch the error, log it, and continue observing. At the moment, once an error occurs, the observer stops. It's essential that the observer…
Zander Rootman
  • 2,178
  • 2
  • 17
  • 29
8
votes
3 answers

RxJS Detect When Subscription has Closed

Is there a way to detect when a Subscription has closed? I have a loading component that displays a loading message when a Subscription exists && is not closed, and otherwise displays the content, but once closed I wanted to reset the variable that…
mtpultz
  • 17,267
  • 22
  • 122
  • 201
8
votes
2 answers

How to get "Observable.of([]);" to work?

What is the correct expression and import for Observable.of([]);. import { of } from 'rxjs'; does not work for me.
Rose Nettoyeur
  • 885
  • 1
  • 16
  • 29
8
votes
3 answers

forkJoin doesn't work with AngularFire2 valueChanges

Please help me to fix an issue I'm struggling. I have an array of Firebase object keys const keys = ['-Kx9pqoMWlJLbKLQcAkP', '-Kx9pqoOYlDHTJ64Was5'] What I'm trying to do is to get all those Firebase objects in one stream using forkJoin. Here's…
Ivan
  • 852
  • 1
  • 12
  • 29
8
votes
2 answers

In redux-observable - How can I dispatch an action "mid-stream" without returning the value of that action?

I have searched everywhere and cannot find an answer to the following... In my addItemEpic I would like to dispatch a "loading" action before sending the ajax request - I DO NOT want the value of the action to be returned - I just want to DO the…
Rody Kirwan
  • 143
  • 1
  • 8
8
votes
3 answers

Repeat request until condition is met and return intermediate values

I am trying to write a (generic) function run(…): Observable which takes the following arguments: A function init: () => Observable which is an initializing request to start a backend process. A function status: (id: ID) =>…
Ingo Bürk
  • 19,263
  • 6
  • 66
  • 100
8
votes
5 answers

RxJs: lossy form of zip operator

Consider using the zip operator to zip together two infinite Observables, one of which emits items twice as frequently as the other. The current implementation is loss-less, i.e. if I keep these Observables emitting for an hour and then I switch…
JeB
  • 11,653
  • 10
  • 58
  • 87
8
votes
2 answers

Why does Rxjs unsubscribe on error?

In short: How to proceed listening after an error in stream without putting a .catch before every .subscribe? If you need more details they are here: Lets assume I have a Subject of current user or null. I get the data from API sometimes and send to…
mgrinko
  • 515
  • 1
  • 4
  • 13
8
votes
2 answers

Angular - what is the preferred way to terminate Observables?

From my understanding of Angular and RxJs there are two ways to terminate Observables. You can unsubscribe() from them or use takeUntil() and complete(). Below are examples of each approach (in pseudocode). The unsubscribe() approach private _id:…
ebakunin
  • 3,621
  • 7
  • 30
  • 49
8
votes
2 answers

RXJS - start a timer only when idle?

I'm using a stream which is throttled when I scroll the window. While throttling (as long as scrolling), it emits values to the console. However , when stream is idle (user is not scrolling the window) - I want a timer to kick in. However - if the…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
8
votes
2 answers

Cannot create observable from Observable.bindNodeCallback(fs.readFile) in TypeScript

I am trying to use rxjs 5 to write a Node.js server in TypeScript, but I hit an error when converting fs.readFile to its rxjs form. I expect the following code would work in TypeScript // This is a JavaScript example from the official documentation.…
Haoliang Yu
  • 2,987
  • 7
  • 22
  • 28
8
votes
1 answer

Waiting for an observable to finish

I have a method that needs to wait for an observable to finish. I know observable are great for returning single pieces of data over time but I need to know when this observable has completely finished returning all of its data so I can run…
user4129529
8
votes
1 answer

Shared observable and startWith operator

I have a question regarding multicasted observables and an unexpected (for me) behaviour I noticed. const a = Observable.fromEvent(someDom, 'click') .map(e => 1) .startWith(-1) .share(); const b = a.pairwise(); a.subscribe(a => { …
dinony
  • 614
  • 3
  • 13
8
votes
1 answer

RxJS5 - Operator to convert object map to array

I have a service that returns an object map which is then used in Angular's ngFor which only takes arrays. So, I am using the map operator with lodash's _toArray to convert the data to an array. Although this works, I then have to import lodash…
Thibs
  • 8,058
  • 13
  • 54
  • 85