reactive-extensions-js

Create infinite repeatable Observable from array

一曲冷凌霜 提交于 2019-12-11 03:44:47
问题 Let's say I have an array items I know I can create an observable from this array using Rx.Observable.fromArray(items) How do I create a lazily infinitely repeating observable from this (i.e.: repeating the items as long as they are being requested)? Tried Rx.Observable.fromArray(items).repeat() But this doesn't execute lazily and therefor locks up the browser. 回答1: You cannot do this with an Observable. You way want to look at using an Enumerable. The Enumerable flavor of Reactive Extensions

Reactive Extensions for Javascript code examples

走远了吗. 提交于 2019-12-09 10:49:56
问题 Microsoft have published Reactive Extensions for Javascript. It should make asynchronous (and event based) web-ui programming easy. There are currently a video and some tutorials. But how cool UI could I really make? Do you know any good demos or code examples using rx.js? 回答1: I think this game demo is pretty cool http://juhajasatu.com/worzone/. The source is available on GitHub and the author has a few posts on JavaScript RX on his blog . 来源: https://stackoverflow.com/questions/2501013

RxJS reduce doesn't continue

三世轮回 提交于 2019-12-08 20:23:14
问题 Why doesn't the flatMap cause downstream reductions to fire? I got code like: handleFiles.flatMap(files => Rx.Observable.from(files). flatMap((file, i) => fileReader(file, i)). reduce((form, file, i) => { form.append('file[' + i + ']', result); console.log('reduce step', file); return form; }, new FormData()). tap(console.log.bind(console, 'after reduce')) ). subscribe(console.log.bind(console, 'response')); And the problem is that the 'after reduce' tap is never hit. Why? The log is like:

SignalR and Reactive combo

萝らか妹 提交于 2019-12-08 05:42:05
问题 I found this little gem about how to get SignalR and Rx to play nicely: Rx and Reactive Tutorial However as you might have noticed this only works when going from server -> client. Does anyone know how to go the other way around? I want my framework to be a bit more "message" based like NServiceBus and less RPC (which signalr standard examples tend to be). The reason for this is the weakly typed world doesn't lend itself very well to RPC. On the server side I'd love to be able to put

How to structure rxjs code

笑着哭i 提交于 2019-12-04 08:05:32
问题 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

Synchronicity in RxJS

允我心安 提交于 2019-12-04 07:17:15
I would expect that the following code would run asynchronously: var range = Rx.Observable.range(0, 3000000); range.subscribe( function(x) {}, function(err) {}, function() { console.log('Completed'); }); console.log('Hello World'); But that's not the case. It takes a while to go through the big range of numbers and only when it is completed the execution is resumed, you can try the code here . I am confused as to when to expect RxJS to behave synchronously or asynchronously. Does it depend on the method used? My previous idea was that once we are in Observables/Observer land, everything in it

rxjs with multiple forkjoin when doing http requests

依然范特西╮ 提交于 2019-12-04 02:16:01
问题 I am doing some http requests and use rxjs for successfull notification of the result: getReportings(departmentId: number): Observable<any> { return Observable.forkJoin( this.http.get('/api/members/' + departmentId).map(res => res.json()), this.http.get('/api/reports/' + departmentId).map(res => res.json()) ); } When both http requests are done I want inside the getReportings method to iterate the reports array , read some values and for each report make again a new http request with those

how to avoid glitches in Rx

二次信任 提交于 2019-12-03 13:12:05
问题 Unlike other "FRP" libraries, Rx doesn't prevent glitches: callbacks invoked with time-mismatched data. Is there a good way to work around this? As an example, imagine that we have a series of expensive computations derived from a single stream (e.g. instead of _.identity, below, we do a sort, or an ajax fetch). We do distinctUntilChanged to avoid recomputing the expensive things. sub = new Rx.Subject(); a = sub.distinctUntilChanged().share(); b = a.select(_.identity).distinctUntilChanged()

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

空扰寡人 提交于 2019-12-03 02:49:58
问题 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

RxJs: poll until interval done or correct data received

元气小坏坏 提交于 2019-12-02 22:38:30
How do i execute the following scenario in the browser with RxJs: submit data to queue for processing get back the job id poll another endpoint every 1s until result is available or 60seconds have passed(then fail) Intermediate solution that i've come up with: Rx.Observable .fromPromise(submitJobToQueue(jobData)) .flatMap(jobQueueData => Rx.Observable .interval(1000) .delay(5000) .map(_ => jobQueueData.jobId) .take(55) ) .flatMap(jobId => Rx.Observable.fromPromise(pollQueueForResult(jobId))) .filter(result => result.completed) .subscribe( result => console.log('Result', result), error =>