reactivex

ReactiveX: Group and Buffer only last item in each group

梦想的初衷 提交于 2019-12-22 05:38:10
问题 How to group an Observable, and from each GroupedObservable keep in memory only the last emitted item? So that each group would behave just like BehaviorSubject. Something like this: {user: 1, msg: "Anyone here?"} {user: 2, msg: "Hi"} {user: 2, msg: "How are you?"} {user: 1, msg: "Hello"} {user: 1, msg: "Good"} So in memory we'd have only have the last item for each user : {user: 2, msg: "How are you?"} {user: 1, msg: "Good"} And when a subscriber subscribes, these two items were issued right

Stream JSON with RxJS Observable

不羁岁月 提交于 2019-12-22 01:17:01
问题 I'm trying to understand a few things about RxJs. What I would like to do is consume some JSON data and immediately begin to render that data on the DOM as it's coming in. I've setup the stream request, response, and display. It's outputting every just fine but it's doing it all at once and not over time. I want to start showing the data on the page as its coming in, instead of waiting for the whole file to complete then show at once which would create a long wait time. //Cache the selector

mergeMap does not exist on type observable

若如初见. 提交于 2019-12-21 05:05:03
问题 I am trying to use mergeMap in rxjs6 and i am getting this error: Property 'mergeMap' does not exist on type 'Observable<{}>' I have tried import 'rxjs/add/operator/mergeMap'; and it is not working. What am i doing wrong? import {from, Observable} from 'rxjs'; export class Test { public doSomething(): Observable<any> { return from(...).mergeMap(); } } 回答1: That's correct, the "patch" style of operators has been removed since RxJS 6. You should better update your code to use only "pipeable"

How to trap errors from chained rxjs observables when using combineLatest?

最后都变了- 提交于 2019-12-20 03:40:08
问题 Following on from this post, I have the following Observable.combineLatest( this.translate.get("key1"), this.translate.get(""), this.translate.get("key3"), this.translate.get("key4") ) .subscribe(([result1, result2, result3, result4]) => { console.log(result1); console.log(result2); console.log(result3); console.log(result4); }, error => { console.log(`${error}`); }); At line 2 I get an error, but this does not seem to go into the error handler above. Unfortunately the examples and doco I

RXJS: Aggregated debounce

只谈情不闲聊 提交于 2019-12-13 11:33:14
问题 My use case is as following: I get events, which sometimes happen in bursts. If a burst occurs, I only need to handle it once though. Debounce does this. However, debounce only gives me the last element of a burst, but I need to know about all elements in a burst to aggregate on them (using flatmap). This could be done by a timed window or buffer, however, these are fixed intervals, so a buffer/window timeout could occur in the middle of a burst, therefore splitting the burst in 2 parts to

RxJS - Create Observable from an EventEmitter's multiple events

余生颓废 提交于 2019-12-13 03:35:46
问题 I have a node.js EventEmitter which raises the following events: error , message . Is there a straight forward way I can create an RxJS Observable from it? i.e next() called on message and error() called on error . 回答1: You can create it like this: const obs$ = Observable.create(observer => { emitter.on('message', val => observer.next(val)); emitter.on('error', err => observer.error(err)); }); As an alternative, you can do this by constructinng and chaining observables like this, but it's

Best way to query all documents from a mongodb collection in a reactive way w/out flooding RAM

◇◆丶佛笑我妖孽 提交于 2019-12-12 20:29:00
问题 I want to query all the documents in a collection in a reactive way. The collection.find() method of the mongodb nodejs driver returns a cursor that fires events for each document found in the collection. So I made this: function giant_query = (db) => { var req = db.collection('mycollection').find({}); return Rx.Observable.merge(Rx.Observable.fromEvent(req, 'data'), Rx.Observable.fromEvent(req, 'end'), Rx.Observable.fromEvent(req, 'close'), Rx.Observable.fromEvent(req, 'readable')); } It will

RxJava flatMap and backpressure strange behavior

耗尽温柔 提交于 2019-12-12 13:29:24
问题 While writing a data synchronization job with RxJava I discovered a strange behavior that I cannot explain. I'm quite novice with RxJava and would appreciate help. Briefely my job is quite simple I have a list of element IDs, I call a webservice to get each element by ID, do some processing and do multiple call to push data to DB. Data loading is faster than data storing so I encounted OutOfMemory errors. My code pretty much look like "failing" test but then doning some test I realized that

Why I am getting NoClassDefFoundError: org/reactivestreams/Publisher

一笑奈何 提交于 2019-12-12 11:23:48
问题 Stream.java import io.reactivex.*; public class Stream { public static void main(String args[]) { Observable.just("Howdy!").subscribe(System.out::println); } } build.gradle: group 'com.sakhunzai' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = JavaVersion.VERSION_1_8 repositories { mavenCentral() } dependencies { compile 'io.reactivex.rxjava2:rxjava:2.0.5' testCompile group: 'junit', name: 'junit', version: '4.11' } Exception: Exception in thread "main" java.lang

Postpone observable when other one fired in RxJs

梦想的初衷 提交于 2019-12-12 00:42:00
问题 I have a table on a page and two subscriptions: First one reloads table data. It has a delay because it calls an api. Second highlights data. Does not affect table data. When subscriptions fire one by one everything is OK, but when they fire at the same time data is highlighted and soon after is reloaded so highlighting is gone. You can see it here. Is there are way to postpone highlighting if reloading is in action? Probably I can accomplish this by introducing loading variable but I am