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
348
votes
22 answers

What is the correct way to share the result of an Angular Http network call in RxJs 5?

By using Http, we call a method that does a network call and returns an http observable: getCustomer() { return this.http.get('/someUrl').map(res => res.json()); } If we take this observable and add multiple subscribers to it: let network$ =…
Angular University
  • 42,341
  • 15
  • 74
  • 81
180
votes
5 answers

What is pipe for in RxJS?

I think I have the base concept, but there are some obscurities So in general this is how I use an Observable: observable.subscribe(x => { }) If I want to filter data I can use this: import { first, last, map, reduce, find, skipWhile } from…
enno.void
  • 6,242
  • 4
  • 25
  • 42
177
votes
3 answers

Observable Finally on Subscribe

According to this artcle, onComplete and onError function of the subscribe are mutually exclusive. Meaning either onError or onComplete events will fire up in my subscribe. I have a logic block which needs to be executed whether I receive an…
Amir Tugi
  • 2,386
  • 3
  • 16
  • 18
152
votes
12 answers

How to return value from function which has Observable subscription inside?

I dont know how to extract value from Observable to be returned by function in which Observable is present. I need just a value from it to be returned, nothing else. Current version which works function getValueFromObservable() { …
Teddy
  • 2,277
  • 3
  • 15
  • 19
134
votes
4 answers

Rxjs: Observable.combineLatest vs Observable.forkJoin

I'm wondering what are the differences between Observable.combineLatest and Observable.forkJoin? As far as I can see, the only difference is forkJoin expects the Observables to be completed, while combineLatest returns the latest values.
Tuong Le
  • 18,533
  • 11
  • 50
  • 44
134
votes
4 answers

When to use asObservable() in rxjs?

I am wondering what is the use of asObservable: As per docs: An observable sequence that hides the identity of the source sequence. But why would you need to hide the sequence?
born2net
  • 24,129
  • 22
  • 65
  • 104
117
votes
2 answers

Difference between .unsubscribe to .take(1)

I wonder, if there is any difference in performance between using .take(1) and .unsubscribe when unsubscribe is used right after the subscription: var observable = Rx.Observable.interval(100); First: var subscription =…
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
85
votes
2 answers

Chaining Observables in RxJS

I'm learning RxJS and Angular 2. Let's say I have a promise chain with multiple async function calls which depend on the previous one's result which looks like: var promiseChain = new Promise((resolve, reject) => { setTimeout(() => { …
Harindaka
  • 4,658
  • 8
  • 43
  • 62
80
votes
9 answers

RxJS: takeUntil() Angular component's ngOnDestroy()

tl;dr: Basically I want to marry Angular's ngOnDestroy with the Rxjs takeUntil() operator. -- is that possible? I have an Angular component that opens several Rxjs subscriptions. These need to be closed when the component is destroyed. A simple…
marius
  • 1,533
  • 3
  • 16
  • 22
78
votes
11 answers

How to get current value of State object with @ngrx/store?

My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I'm doing it like this: constructor(public _store: Store < AppState > , public _APIService: APIService) { const store$ =…
Philippe sillon
  • 1,572
  • 2
  • 14
  • 20
72
votes
4 answers

Hot and Cold observables: are there 'hot' and 'cold' operators?

I reviewed the following SO question: What are the Hot and Cold observables? To summarize: a cold observable emits its values when it has an observer to consume them, i.e. the sequence of values received by observers is independent of time of…
user3743222
  • 18,345
  • 5
  • 69
  • 75
68
votes
2 answers

Simple way to get the current value of a BehaviorSubject with rxjs5

Previously in rxjs4 there was a method in the BehaviorSubject called: getValue() (doc here). This method does not exist anymore in rxjs5. So the only solution that I found to get the value of a BehaviorSubject was: let…
Clement
  • 3,860
  • 4
  • 24
  • 36
68
votes
2 answers

ObjectUnsubscribedError when trying to prevent subscribing twice

I have a Service and a component that uses it: PagesService PagesListComponent In the PagesService I have an array of Pages. I notify changes in the array via a BehaviorSubject which both of them are subscribed to. The PagesService are provided at…
AlvYuste
  • 915
  • 1
  • 6
  • 14
61
votes
6 answers

Best way to "flatten" an array inside an RxJS Observable

My backend frequently returns data as an array inside an RxJS 5 Observable (I'm using Angular 2). I often find myself wanting to process the array items individually with RxJS operators and I do so with the following code (JSBin): const…
AngularChef
  • 13,797
  • 8
  • 53
  • 69
60
votes
6 answers

How to make HTTP request at an interval?

I am quite new to angular and rxjs. I am trying to create an angular2 app that gets some data from staticly served text file(Locally on server), which I would like to retrieve and map to Datamodel using Angular2's http provider and rxjs's map at a…
Tony Krøger
  • 988
  • 1
  • 10
  • 11
1
2 3
99 100