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
14
votes
3 answers

Return Observable from service method after two subscriptions resolve

I'm trying to setup a simple way to compare the current username with a profile's username within an Angular service. Obviously the profile username and the user's username must resolve before I can compare them so how do I return a boolean…
Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
14
votes
1 answer

pass array of observables to zip

I have an array of observables and want to pass to Rx.Observable.zip. I tried and it does not get subscribed at all. Code snippet(just am example): const sourceOne = Rx.Observable.of('Hello'); const sourceTwo = Rx.Observable.of('World!'); const…
softshipper
  • 32,463
  • 51
  • 192
  • 400
14
votes
4 answers

RxJS: Observable.create() vs. Observable.from()

What's the difference between these two? return Observable.create(function(observer) { if (array) observer.next([]); else observer.next(null); observer.complete(); }); and return Observable.from( array ? [] : null ); I…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
14
votes
3 answers

Flattening nested Observables

I'm a stuck in nested observable hell and could do with a hand. I have the following block of code return this.findUser(term).map( users => { return users.map( user => this.getLastLogin(user.user_id).map( last_login => { user.last_login =…
user3750194
  • 387
  • 2
  • 11
14
votes
2 answers

What's the difference between publish and multicast operator in rxjs 5?

I'm reading the rxjs manual, I'm a little confused about what's the difference between multicast and publish operators. They seem very similar.
Aaron Shen
  • 8,124
  • 10
  • 44
  • 86
14
votes
1 answer

Why can I no longer call next() after calling complete() on an RxJs Subject?

I have service which connects with Subject() to do paging. I'm using next(newData) to pass to subject, which keeps things alive, now I need to use complete() on each ajax call and pass it to subject. but after doing one complete() I'm started get…
Basit
  • 16,316
  • 31
  • 93
  • 154
14
votes
2 answers

RXJS control observable invocation

I use RxJs version 5 within my Angular 2 project. I want to create some observables but I don't want the observables being invoked immediately. In version 4 you could control the invocation with (for example) the Controlled command or Pausable…
Justin
  • 2,960
  • 2
  • 34
  • 48
13
votes
4 answers

How can I mock fromEvent function from RXJS 5.5.6?

I have to test a function that uses the fromEvent observable function. Before the upgrade to 'lettable' operators, I was just doing this: spyOn(Observable, 'fromEvent').and.callFake(mockFromEventFunction) But now, Rxjs have changed, and…
13
votes
1 answer

this keyword for function parameter

Recently when I use Rxjs 5, I downloaded Rxjs by using npm install Rxjs@5.0.1, from downloaded code under node_modules, I found Observable.d.ts in Rxjs folder, I saw it declare its constructor like below: * * @constructor * @param {Function}…
IcyBrk
  • 1,090
  • 12
  • 21
13
votes
2 answers

rxjs5 toPromise not working

In the following example toPromise does not work: https://jsfiddle.net/tossp/nmf9jg32/ My code: function getPostData() { return fetch('https://jsonplaceholder.typicode.com/posts/1') .then(res => res.json()) } var source =…
TossPig
  • 511
  • 5
  • 9
13
votes
8 answers

RxJs and Typescript. TS2307: Cannot find module '@reactivex/rxjs'

I got a problem with typescript and RxJs v5. Please Look the UPDATE sections. I did yarn add @reactivex/rxjs (also yarn add rxjs) and on my index.ts did import Rx from '@reactivex/rxjs'; and got this error: Also, if I run node…
Alejandro Nanez
  • 335
  • 2
  • 6
  • 16
13
votes
2 answers

Is Rx.Subject a hot observable?

The code const a = new Rx.Subject().do(x => console.log('a')) const b = a.mapTo(0) const c = a.mapTo(1) const d = Rx.Observable.merge(b, c) d.subscribe(x => console.log('d')) a.next(3) And the output a d a d Why does a got printed twice? Isn't…
c c
  • 241
  • 2
  • 6
13
votes
1 answer

Conditional Observable.forkJoin() building

Based on the parameters of the function I want to build the forkJoin() method. For example: if parameter1 is empty => don't put a http request for it inside the forkJoin() if parameter2 is empty => don't put a http request for it inside the…
Korki Korkig
  • 2,736
  • 9
  • 34
  • 51
12
votes
2 answers

How to delay next(value) on subject?

My AlertService has private subject = new Subject();. I want to autocratically clear alert after 5 seconds. I can do it with using setTimeout() like this: autoClear(alertId?: string) { setTimeout( () => this.subject.next(new…
Xalion
  • 623
  • 9
  • 27
12
votes
3 answers

Rxjs conditional delay

I want an observable to be delayed depending on its value. For example: of(someBool).pipe(delay(1000)) skip delay when someBool is false, but wait a sec when it's true.
Hikmat G.
  • 2,591
  • 1
  • 20
  • 40