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
35
votes
5 answers

Can't find `combineLatest` in RxJS 5.0

The following code it's causing me a Observable.combineLatest is not a function using RxJS 5.0: let Observable = require('rxjs/Observable.js').Observable; import 'rxjs/add/operator/combineLatest'; Observable .combineLatest([player, spaceShip],…
Claudiordgz
  • 3,023
  • 1
  • 21
  • 48
34
votes
5 answers

How to Stop observable.timer in Angular2

I am implementing the following functions in Angular2's Component: export class MypageEditComponent { ngOnInit() { this.timer = Observable.timer(100, 100); this.timer.subscribe(t => { this.setFormData(); } private…
xKxAxKx
  • 1,044
  • 5
  • 16
  • 31
33
votes
2 answers

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This…
msamprz
  • 573
  • 2
  • 7
  • 15
33
votes
5 answers

Observable.forkJoin() doesn't execute

I have the following code: //Loop: For each user ID/Role ID, get the data userMeta.forEach((businessRole) => { Observable.forkJoin( af.database.object('/roles/'+businessRole.$value), af.database.object('/users/'+businessRole.$key) …
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
32
votes
8 answers

How to dispatch an empty action?

I am using ngrx/effects. How can I dispatch an empty action? This is how I am doing now: @Effect() foo$ = this.actions$ .ofType(Actions.FOO) .withLatestFrom(this.store, (action, state) => ({ action, state })) .map(({ action, state }) =>…
Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
32
votes
1 answer

Angular 2 router resolve with Observable

After the release of Angular 2 RC.5 there was introduced router resolve. Here demonstrated example with Promise, how to do the same if I make a request to the server with Observable? search.service.ts searchFields(id: number) { return…
Rakhat
  • 4,783
  • 4
  • 40
  • 50
32
votes
1 answer

Cannot find module 'rxjs/subject/BehaviorSubject'

I am using Angular 2. When I use either of these two, my program runs well: import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject } from 'rxjs'; However, I try to use the following way: import { BehaviorSubject } from…
Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
31
votes
3 answers

Any need to call unsubscribe for RxJS first()

In the following code:- RxJS.Observable.of(1,2).first().subscribe((x) => console.log(x);); is it necessary to unsubscribe given the operator first()?
bhantol
  • 9,368
  • 7
  • 44
  • 81
31
votes
3 answers

How to convert an Observable to a ReplaySubject?

Here is what I'm doing now to convert an Observable to a ReplaySubject: const subject = new Rx.ReplaySubject(1); observable.subscribe(e => subject.next(e)); Is this the best way to make the conversion, or is there a more idiomatic way?
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
31
votes
2 answers

How to subscribe to event emitter once?

// Part of service public someEvent: EventEmitter = new EventEmitter(); .... // Component @Component({ selector: 'some-component', template: `...` }) export class SomeComponent { constructor(public service: Service) { …
Eggy
  • 4,052
  • 7
  • 23
  • 39
30
votes
2 answers

RxJs: Incrementally push stream of data to BehaviorSubject<[]>

Basically I'm trying to inflate BehaviorSubject<[]> with array of data which will be loaded in chunks. BehaviorSubject<[]> will be added with new chunk of data (like Array.push) but I don't want to use another array to store and add to…
Reddy
  • 1,403
  • 3
  • 14
  • 27
26
votes
4 answers

What is observable, observer and subscribe in angular?

I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain.
Amit Sharma
  • 668
  • 1
  • 6
  • 14
25
votes
3 answers

RxJS5 finalize operator not called

I'm trying to trigger a callback when all my observables are executed. In my other, older project i used finally like so and that worked like a charm: this.myService.callDummy() .finally(() => console.log('Works!')) .subscribe(result =>…
Nico Van Belle
  • 4,911
  • 4
  • 32
  • 49
25
votes
4 answers

How to create Observable from function?

I want to call a function (synchronously) and then use its return value as an initial emission (subsequently chaining some other operators on the resulting observable). I want to invoke this function during subscription, so I can't just use…
Titan
  • 2,875
  • 5
  • 23
  • 34
25
votes
1 answer

Angular 2 - Sort list from Observable

What is the best way to sort a list of items coming from an Observable and still be able to use the async pipe? (I read that making a custom sort pipe is not really efficient.) I want to avoid subscribing and keeping a local copy of data and thus…
Thibs
  • 8,058
  • 13
  • 54
  • 85