reactive-extensions-js

How to structure rxjs code

匆匆过客 提交于 2019-12-02 20:40:05
How does one structure an rxjs app? There are about a hundred toy intro examples, but not a single example of a full app, with widgets, subwidgets, etc., showing data flow through the whole application. E.g. suppose you have an observable with some state. You need to pass it to a widget. That widget has subwidgets that need portions of that state. Do you do a subscribe? sub = state.subscribe(widget) Now 'widget' is outside the monad. The subwidgets can't use observable methods on state. You have the same problem if you run the widget as a side effect. state.doAction(widget) So do you pass the

Requesting a clear, picturesque explanation of Reactive Extensions (RX)?

爱⌒轻易说出口 提交于 2019-12-02 17:33:28
For a long time now I am trying to wrap my head around RX. And, to be true, I am never sure if I got it - or not. Today, I found an explanation on http://reactive-extensions.github.com/RxJS/ which - in my opinion - is horrible. It says: RxJS is to events as promises are to async. Great. This is a sentence so full of complexity that if you do not have the slightest idea of what RX is about, after that sentence you are quite as dumb as before. And this is basically my problem: All the explanations in the usual places you find about RX make (at least me) feel dumb. They explain RX as a highly

trigger event after several ajax calls succeeded

╄→尐↘猪︶ㄣ 提交于 2019-12-02 04:12:19
问题 I wonder which is the best approach to trigger an event after several (unordered) ajax calls finished. To make it a bit clearer, I would like to call a Method doSomethingGreat() which triggers several ajax calls, the order in which those succeed ins unnecessary. I just want to trigger an event 'SomethingGreatFinished' when all of those calls succeeded. I also don't want to chain these calls, because that would be lacking performance and would be totally against the idea of asynchronous

trigger event after several ajax calls succeeded

为君一笑 提交于 2019-12-02 01:14:10
I wonder which is the best approach to trigger an event after several (unordered) ajax calls finished. To make it a bit clearer, I would like to call a Method doSomethingGreat() which triggers several ajax calls, the order in which those succeed ins unnecessary. I just want to trigger an event 'SomethingGreatFinished' when all of those calls succeeded. I also don't want to chain these calls, because that would be lacking performance and would be totally against the idea of asynchronous programming. I wonder if a.) there is a common pattern for that, b.) this can be done with the Reactive

Collect RxJS Observable to Array

雨燕双飞 提交于 2019-12-01 17:57:49
I'd like to use RxJS to "bridge" async world of events with sync world. Specifically I want to create an function which returns an array of events collected during some time interval. I can create Observable which does what I want var source = Rx.Observable .interval(100 /* ms */) .bufferWithTime(1000).take(1) I can print correct values just fine var subscription = source.subscribe( function (x) { console.log('Next: ' + JSON.stringify(x)); }, function () { console.log('Completed'); }); This prints [0,1,2,3,4,5,6,7,8] Completed But want I want is to assign this array to variable. Conceptually I

ForkJoin 2 BehaviorSubjects

假如想象 提交于 2019-12-01 16:53:28
I have two behaviour subject streams what I'm trying to forkJoin with no luck. As I imagined it gives back the two last values of it. Is this possible to implement it somehow? It is not called after the subject. let stream1 = new BehaviorSubject(2); let stream2 = new BehaviorSubject('two'); Observable.forkJoin(stream1, stream2) .subscribe(r => { console.log(r); }); Note what forkJoin() actually does from its documentation: Wait for Observables to complete and then combine last values they emitted. This means that forkJoin() emits a value when all input Observable are complete. When using

ForkJoin 2 BehaviorSubjects

六眼飞鱼酱① 提交于 2019-12-01 15:26:43
问题 I have two behaviour subject streams what I'm trying to forkJoin with no luck. As I imagined it gives back the two last values of it. Is this possible to implement it somehow? It is not called after the subject. let stream1 = new BehaviorSubject(2); let stream2 = new BehaviorSubject('two'); Observable.forkJoin(stream1, stream2) .subscribe(r => { console.log(r); }); 回答1: Note what forkJoin() actually does from its documentation: Wait for Observables to complete and then combine last values

Turning paginated requests into an Observable stream with RxJs

我只是一个虾纸丫 提交于 2019-11-30 13:27:50
问题 I have a service which returns data in pages. The response to one page contains details on how to query for the next page. My approach is to return the response data and then immediately concat a deferred call to the same observable sequence if there are more pages available. function getPageFromServer(index) { // return dummy data for testcase return {nextpage:index+1, data:[1,2,3]}; } function getPagedItems(index) { return Observable.return(getPageFromServer(index)) .flatMap(function

Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error

﹥>﹥吖頭↗ 提交于 2019-11-29 23:11:31
I'm using AngularJS 2 Beta 0 and I'm trying to create an RxJS Observable from an event on a window object. I believe I know the formula for capturing the event as an Observable in my service: var observ = Observable.fromEvent(this.windowHandle, 'hashchange'); The problem is that every time I try run this code, I get an error stating that 'fromEvent' is not a function. Uncaught EXCEPTION: Error during evaluation of "click" ORIGINAL EXCEPTION: TypeError: Observable_1.Observable.fromEvent is not a function This seems to imply to me that I'm not handling my import correctly now that RxJS is not

Idiomatic way to recover from stream onError

被刻印的时光 ゝ 提交于 2019-11-29 13:18:52
问题 Disclaimer: it is the continuation for the previous Safe update for 2 dependent streams question What is the idiomatic way to handle errors in RxJS (or any other RX implementation) that allows the stream to not terminate? Relevant code is function convert(unit, value) { var request = {}; request[unit] = value; var conversion = $.ajax({ method: 'POST', url: './convert.php', data: request, dataType: 'json' }).promise(); return Rx.Observable.fromPromise(conversion).takeUntil(inInput.merge