reactive-extensions-js

Catch circular dependency between observables

拈花ヽ惹草 提交于 2020-01-06 04:12:07
问题 I have a user-programming scenario where user can end up creating two observables that depend on each other. RxJS does not allow circular dependencies, as far as I can see, the memory or stack reaches its limits and the onError callback is triggered with the value true . How to detect the circular dependency explicitly and throw a more descriptive error message? This codes illustrates how to create a circular dependency in RxJS: var obsA, obsB; obsA = Rx.Observable .returnValue(42)

Synchronicity in RxJS

六月ゝ 毕业季﹏ 提交于 2020-01-01 10:14:44
问题 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

RxJs: poll until interval done or correct data received

无人久伴 提交于 2019-12-31 12:18:44
问题 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)))

How to load images async with RxJs and perform a method when all loaded

亡梦爱人 提交于 2019-12-30 03:14:28
问题 I am trying to convert my promise based code to RxJs but have a hard time to get my head around Rx especially RxJs. I have a an array with paths. var paths = ["imagePath1","imagePath2"]; And I like to load images in Javascript var img = new Image(); img.src = imagePath; image.onload // <- when this callback fires I'll add them to the images array and when all Images are loaded I like to execute a method on. I know there is Rx.Observable.fromArray(imagepathes) there is also something like Rx

RxJS Continue Listening After Ajax Error

南楼画角 提交于 2019-12-29 03:37:49
问题 RxJs stops listening to click events when an inner observable errors (Ajax request). I'm trying to figure out how to keep the event listener hooked to the button click event and gracefully handle the inner ajax error. Here is my example code and a link to plunkr var input = $("#testBtn"); var test = Rx.Observable.fromEvent(input,'click'); var testAjax = function() { return Rx.Observable.range(0,3).then(function(x){ if(x==2)throw "RAWR"; //Simulating a promise error. return x; }); } test.map

How to cancel a composed RxJS observable

浪子不回头ぞ 提交于 2019-12-23 05:45:35
问题 Folks, I have an app using RxJS to handle mouse events. I am composing these events into more complex observable 'gestures'. One such gesture is "shake". The series of events I am trying to compose are: mousedown mousemove left mousemove right mousemove left mousemove right mouseup What I am finding is that mousedown mouseup mousemove left mousemove right mousemove left mousemove right is also triggering the same result. I have made a fiddle demonstrating the issue on codepen. My question in

Collect RxJS Observable to Array

守給你的承諾、 提交于 2019-12-19 19:47:40
问题 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

rxjs flatmap missing

风格不统一 提交于 2019-12-18 01:18:51
问题 I try to chain multiple rx.js observables and pass the data. Flatmap should be the fitting operator but with an import of import { Observable } from 'rxjs/Observable'; it is not found: Error TS2339: Property 'flatmap' does not exist on type 'Observable<Coordinates>' Version 5.0.0-beta.6 of rx.js is used. public getCurrentLocationAddress():Observable<String> { return Observable.fromPromise(Geolocation.getCurrentPosition()) .map(location => location.coords) .flatmap(coordinates => { console.log

rx data driven subwidgets

一曲冷凌霜 提交于 2019-12-12 18:28:01
问题 Following up on How to structure rxjs code, concerning how to structure a widget with subwidget when using rx, how would you structure rx code where the subwidgets are data-driven? As a toy problem, suppose you have an external source (e.g. web service) streaming a list of stocks to watch, with value, high, low, etc. So you have an Observable stream like (time goes down): [{id: 'csco', value: 12, high: 20, low: 10}] [{id: 'csco', value: 12, high: 20, low: 8}, {id: 'aapl', value: 29, high: 30,

Safe update for 2 dependent streams

与世无争的帅哥 提交于 2019-12-11 10:16:55
问题 As an exercise I'm trying to build 2 dependent streams which update one another. The test application is simply an "Inches <-> Centimeters" converter, with both inputs editable. The issue I am experiencing is that I cannot get how can I stop recursion that causes one field change. To better explain the issue let's have a look at the relevant part of code: var cmValue = new Rx.BehaviorSubject(0), inValue = new Rx.BehaviorSubject(0); # handler #1 cmValue.distinctUntilChanged().subscribe