rxjs5

Waiting for an observable to finish

一笑奈何 提交于 2019-12-05 05:52:56
I have a method that needs to wait for an observable to finish. I know observable are great for returning single pieces of data over time but I need to know when this observable has completely finished returning all of its data so I can run validation code on the object it has returned. The method getCustom subscribes to an observable run on the supplied url which then returns the observable. I am not too sure if this is the best way to approach this situation so I would appreciate if anyone could give me any advice or a direction to handle this. private validateQuoteRetrievalAnswers(reference

Should rxjs subjects be public in the class?

不羁的心 提交于 2019-12-05 04:22:46
Let's say I have two classes, where you can observe over some observables. First example, with public subject: class EventsPub { public readonly onEnd = new Subject<void>(); } Second example, with private subject and registering method: class EventsPriv { private readonly endEvent = new Subject<void>(); public onEnd(cb: () => void): Subscription { return this.endEvent.subscribe(cb); } } The first example is somehow unsafe because anyone can call eventsPub.endEvent.next() from outside the class and introduce side effects, however, comparing to example 2 It allows for pipes, which is a big plus

RXJS 5 .subscribe() without arguments

99封情书 提交于 2019-12-05 02:42:37
So a quick question. I've been using RxJS 5 for a few months now, and I've run into a bit of behavior that I don't really understand, as I haven't been able to look it up anywhere. I'm in a situation where subscribing to an observable chain with simply .subscribe(); doesn't trigger the observable. However, if I add an onNext callback (empty or not), the observable triggers, and the chain processes: .subscribe(() => {}); Can anyone explain why this behavior happens? EDIT2 - Removed irrelevant example .subscribe() actually doesn't require any parameters, it will just create an emptyObserver if

What's the difference between publish and multicast operator in rxjs 5?

…衆ロ難τιáo~ 提交于 2019-12-05 01:26:55
I'm reading the rxjs manual, I'm a little confused about what's the difference between multicast and publish operators. They seem very similar. I had the same question when reading http://reactivex.io/rxjs/manual/overview.html . So to make it clear, .publish() is just shorthand for .multicast(new Rx.Subject()) (and publishBehavior , publishLast , and publishReplay are similar but instantiate BehaviorSubject , AsyncSubject and ReplaySubject respectively). They are indeed very similar, and they have a history that makes it even more confusing. In simple terms, publish is a special case of

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

*爱你&永不变心* 提交于 2019-12-05 00:21:36
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 BehaviorSubject.next because this will cause rendering to take too long as the data grow over time. Any suggestion? You can use getValue() method to achieve what you want to do. Example: data = new BehaviorSubject<any[]>([]); addData(foo:any):void{ // I'm using concat here to avoid using an intermediate array (push doesn't return the result array, concat does).

How to use RxJs distinctUntilChanged?

懵懂的女人 提交于 2019-12-04 22:36:55
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 } Completed That is not what I would expect. Why is only one entry passing distinctUntilChanged ? I would expect the output to be [ 'a', 1 ] [ 'a', 0 ] [ 'a', 1 ] { key: 'a', state: 1 } { key: 'a', state: 2 } { key: 'a', state: 0 } { key: 'a', state: 1 } Next: { value: 42 } Next: { value: 24 } Completed Here's the code import {Observable} from 'rxjs' Observable.of

Example RxJS Observable when mouse or click activity Re-starts

夙愿已清 提交于 2019-12-04 21:32:12
I'm able to create 2 observables to watch mouse move and click events as such: var mousemove$ = Rx.Observable.fromEvent(document, 'mousemove'); var click$ = Rx.Observable.fromEvent(document, 'click'); I'm also able to use merge() and debounceTime() to wait for either mousemove or click to not happen for 10 seconds like this: var allactivity$ = Rx.Observable.merge( mousemove$.mapTo('Mouse!'), click$.mapTo('Click!') ); var lastact$ = allactivity$.debounceTime(10000); However, I would like to somehow construct an observable for when a user Re-starts either moving the mouse or clicking after this

How to watch object changes with rxjs 5

只谈情不闲聊 提交于 2019-12-04 19:50:56
问题 I would like to watch over an object, so all the subscribers will be informed for any changes of it. I saw it already been asked before, yet the answer is irrelevant since RXjs verion 5 do not include the ofObjectChanges in it's API anymore. I've looked at some "hacks" like creating an observer which return a function: let myObservable = new Observable((observer) => { return (data) => { observer.next(data) } }) //... myObservable.subscribe()('someData') However, I'm sure there is more elegant

Error rxjs_Observable__.Observable.forkJoin is not a function?

无人久伴 提交于 2019-12-04 18:07:50
问题 I am using Rxjs in an angualr-cli application. in viewer.component.ts //Other Imports import { Observable } from 'rxjs/Observable'; //omitting for brevity export class ViewerComponent implements OnInit, AfterViewInit, OnDestroy { someFunction(someArg){ //omitting for brevity let someArray: any = []; //Add some info Observable.forkJoin(someArray).subscribe(data => { //Do something with data }); } //omitting for brevity } I get and error as ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_rxjs

Rxjs, fromEvent to handle multiple events

南笙酒味 提交于 2019-12-04 17:42:05
问题 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. 回答1: Note: This is for RxJS v5. See bottom of this answer for the v6 equivalent. You can use the Rx.Observable.merge function to merge multiple observable streams into a single stream: // First, create a separate observable for each event: const scrollEvents$ = Observable.fromEvent(