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

Typescript Select Ids from object

I am new to Typescript. I want to select ids from observable This is my observable let myObj = [{ "id": 1, "text": "Mary" }, { "id": 2, "text": "Nancy" }, { "id": 3, "text": "Paul" }, { "id": 4, "text": "Cheryl" }, { "id": 5, …
Sathya V
  • 589
  • 3
  • 7
  • 15
25
votes
2 answers

How to use RxJs distinctUntilChanged?

I'm getting started with RxJs (using the v5 beta), but somehow I can't figure out how to work with distinctUntilChanged. The output from the code below if I run it in babel-node is [ 'a', 1 ] { key: 'a', state: 1 } Next: { value: 42…
Thijs Koerselman
  • 21,680
  • 22
  • 74
  • 108
23
votes
4 answers

Rxjs, fromEvent to handle multiple events

What is the best way to handle multiple events on the same DOM node in rxjs 5.1? fromEvent($element, 'event_name') but I can specify only one event at a time. I want handle scroll wheel touchmove touchend events.
Reddy
  • 1,403
  • 3
  • 14
  • 27
23
votes
4 answers

How to only execute an Observable if term is not null/empty?

I have the following code inside my constructor: this.searchResults = this.searchTerm.valueChanges .debounceTime(500) .distinctUntilChanged() .switchMap(term => this.apiService.search({ limit: this.searchResultsLimit, …
Fizzix
  • 23,679
  • 38
  • 110
  • 176
23
votes
3 answers

rxjs 5 publishReplay refCount

I can't figure out how publishReplay().refCount() works. For example (https://jsfiddle.net/7o3a45L1/): var source = Rx.Observable.create(observer => { console.log("call"); // expensive http request …
Oleg Gello
  • 253
  • 1
  • 2
  • 4
23
votes
1 answer

What are the semantics of different RxJS subjects?

Documentation for the topic is sparse and it's hard to discover an "entry-point" there.
Ivan Kleshnin
  • 1,667
  • 2
  • 21
  • 24
22
votes
2 answers

import .of() for Observable in typescript

I'm using this great repo for my angular 2 test project (TypeScript) - https://github.com/qdouble/angular-webpack2-starter. And I need to use Observable.of(..). When I try to import it: import { Observable } from "rxjs/Observable"; import { of }…
AlexB
  • 4,167
  • 4
  • 45
  • 117
22
votes
5 answers

How to implement a draggable div in Angular 2 using Rx

I've been trying to get a draggable div working using Angular 2. I'm using this example from the angular2-examples repo as a starting point, only really adjusting the code to account for the removal of the toRx() method. The code works, but it…
Chris
  • 1,657
  • 1
  • 13
  • 20
21
votes
3 answers

RXJS - Using both take(1) and takeUntil()

After searching online, I see that people generally use one or the other and not both. Is it possible to use both? Is it good or bad practice? Edit I am not asking what take(1) or takeUntil is used for. Rather I am asking if it is possible to have…
Informat
  • 808
  • 2
  • 11
  • 25
21
votes
3 answers

RxJS 5, converting an observable to a BehaviorSubject(?)

I have a parent observable that, once it has a subscriber, will do a lookup and emit a single value, then complete. I'd like to convert that into an observable (or behavior subject or whatever works) that does the following: once it has at least one…
Karptonite
  • 1,490
  • 2
  • 14
  • 30
21
votes
2 answers

RxJS - .subscribe() vs .publish().connect()

This is mainly an RxJs best practice/approach question, since my POC code works but I'm brand new to RxJs. The question boils down to .subscribe() vs .publish().connect(), since they both appear to do the same thing. In my angular2 app, I have a…
ClaytonK
  • 417
  • 1
  • 5
  • 12
21
votes
2 answers

Rx.Observable.just is not a function in JSBIN & RxJS 5

In JsBin, I got error "Rx.Observable.just is not a function" in Firefox & Chrome. JsBin example : http://jsbin.com/vunuta/edit?html,js,console HTML : script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.7/dist/global/Rx.umd.js"> Typescript…
Philippe sillon
  • 1,572
  • 2
  • 14
  • 20
20
votes
2 answers

RxJS how to ignore an error with catch and keep going

Hi I have the following code and I would like to know how to prevent the main (upstream) Observable from getting deleted when an error is thrown. How can I change the following code so that all numbers expect '4' get displayed? I am looking for a…
devguy
  • 672
  • 3
  • 7
  • 21
20
votes
3 answers

Reactive Caching of HTTP Service

I am using RsJS 5 (5.0.1) to cache in Angular 2. It works well. The meat of the caching function is: const observable = Observable.defer( () => actualFn().do(() => this.console.log('CACHE MISS', cacheKey)) ) .publishReplay(1,…
Martin
  • 15,820
  • 4
  • 47
  • 56
20
votes
1 answer

What is the difference between Reactive-Extensions/RxJS and ReactiveX/rxjs

I am a bit confused. What is the difference between these libraries? https://github.com/ReactiveX/rxjs https://github.com/Reactive-Extensions/RxJS What is the differance between rx, @reactivex/rxjs rxjs on npm. If you search npm there are…
Arin
  • 632
  • 6
  • 16