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
50
votes
4 answers

Angular2: Unsubscribe from http observable in Service

What is the best practice to unsubscribe within a Angular2 service from a http subscription? Currently I do this but I'm not sure if this will be the best way. import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import…
NCC-2909-M
  • 709
  • 1
  • 7
  • 15
49
votes
11 answers

'Observable' is not a class derived from 'Observable'

When trying to extend a class from a class in a node_modules the typescript compiler throws a error saying: Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'. This only happens when the base class…
fredrik
  • 17,537
  • 9
  • 51
  • 71
48
votes
2 answers

How does the RxJs 5 share() operator work?

Its not 100% clear for me how the RxJs 5 share() operator works, see here the latest docs. Jsbin for the question here. If I create an observable with a series of 0 to 2, each value separated by one second: var source =…
Angular University
  • 42,341
  • 15
  • 74
  • 81
47
votes
4 answers

How to achieve a debounce service on input keyup event in angular2 with rxjs

I am trying to call to a service on input key-up event. The HTML Below is the onKeyUp() function onKeyUp(event) { let observable = Observable.fromEvent(event.target, 'keyup') …
user3260023
47
votes
6 answers

How to two-way bind my own RxJS Subject to an [(ngModel)]?

Is there a short and simple way to pass an RxJS Subject or BehaviorSubject to an an Angular 2 directive for two-way binding? The long way to do it would be as follows: @Component({ template: `
mhelvens
  • 4,225
  • 4
  • 31
  • 55
46
votes
9 answers

How do I get around this "Subject incorrectly extends Observable" error in TypeScript 2.4 and RxJS 5.x?

When I compile, I get the following compiler error in the RxJS declaration files: node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject' incorrectly extends base class 'Observable'. Types of property 'lift' are incompatible. …
Daniel Rosenwasser
  • 21,855
  • 13
  • 48
  • 61
46
votes
3 answers

How does Observables (Rx.js) compare to ES2015 generators?

As far as I understand, following are the techniques to solve asynchronous programming workflows: Callbacks (CSP) Promises Newer approaches: Rx.js Observables (or mostjs, bacon.js, xstream etc) ES6 generators Async/Await We are now moving away…
Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
46
votes
3 answers

Difference between audit and debounce in RxJS?

I am reading the official documentation of RxJS and then I realized they both are doing exactly the same thing. To me they both seem exactly similar. Please point out the difference between them if there is any at all.
Godfather
  • 5,711
  • 5
  • 21
  • 27
42
votes
2 answers

How to stop an interval on an Observable in RxJS

I have a specific situation where I'm using an RxJS interval, but at any given moment I may need to stop that interval. I assumed there was something easy like a cancel() or stop(). Similar to clearTimeout. This is possible to stop an interval once…
selanac82
  • 2,920
  • 4
  • 27
  • 37
42
votes
2 answers

Check if object is an Observable

I am using RxJS 5 and have this method: Queue.prototype.drain = function (obs, opts) {}; in the method, I would like to check if the user passed in an Observable for the first argument or if they omitted the Observable and just passed in an options…
user5047085
41
votes
2 answers

How to force observables to execute in sequence?

I am moving from the Promise world to the Observable world. One thing I usually do with Promise is to chain a series of tasks and make them run in sequence. For example, I have three tasks: printLog1() to print 1 to the console, printLog23() to…
Haoliang Yu
  • 2,987
  • 7
  • 22
  • 28
41
votes
7 answers

Observable forkJoin not firing

I'm trying to use forkJoin on two Observables. One of them starts as a stream... If I subscribe to them directly I get a response, forkJoin isn't firing though. Any ideas? private data$: Observable; private statuses$:…
nick
  • 3,521
  • 3
  • 22
  • 32
39
votes
6 answers

How to get an observable to return data immediately and every 5 seconds thereafter

I want to create an observable that returns data from a webapi. I'd like it to return the data immediately, and poll the API every 10 seconds. The code below shows I'm using the 'interval' method. But this delays the first set of data by 10…
FeeFiFoFum
  • 1,719
  • 1
  • 11
  • 18
38
votes
6 answers

RxJS takeWhile but include the last value

I have a RxJS5 pipeline looks like this Rx.Observable.from([2, 3, 4, 5, 6]) .takeWhile((v) => { v !== 4 }) I want to keep the subscription until I see 4, but I want to last element 4 also to be included in the result. So the example above should…
Fang-Pen Lin
  • 13,420
  • 15
  • 66
  • 96
36
votes
2 answers

Pipe RxJS observable to existing subject

There is existing subject that is in use: const fooSubject = new BehaviorSubject(null); And there is another observable (another subject in this example): const barSubject = new Subject(); barSubject.subscribe( value => fooSubject.next(), err…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565