0

If you try the demo4 of my svg.rx.js project, with a multi-touch device (such as Nexus 7), you'll notice that the SVG circles are falling behind the fingers.

I'd like to skip coordinates if there are later ones, but it does not seem to be that simple. As far as I can tell, RxJS does not really buffer the values. It probably spins off my application's subscribe calls and once that happens, there's no way to cancel those - just let them run.

There's a very similar SO issue 11010602 but I would like to keep the code to the minimum, of course.

Can some more experienced RxJS fellow advice me on this? I'm currently using RxJS 4.0.7 and the relevant code is here. Thanks.

I've read about Backpressure with RxJS but none of the approaches worked. Using .sample at the application side seems like the best bet (trying to get it working).

Edit:

Here's the way I'm trying to deal with it, using .sample and a Subject that would be triggered every time a coordinate has been processed - thus kind of synchronizing the stream to the drawing capabilities of the device (hopefully). Something with the types I get wrong, since it ends up not having .onNext.

https://github.com/akauppi/svg.rx.js/blob/backpressure/demo/demo4.js

Community
  • 1
  • 1
akauppi
  • 17,018
  • 15
  • 95
  • 120

1 Answers1

1

Something with the types I get wrong, since it ends up not having .onNext.

You need to call onNext directly on the subject, so to simplify:

var subject = new Rx.Subject();
var triggerObs = subject.startWith(true);
// ... 
subject.onNext() // rather than triggerObs.onNext();

Regarding performance & leaving out values: Rx has a requestAnimationFrame scheduler, maybe that could help you out. You could just supply it to dragObs I guess. merge takes a scheduler argument.

Other than that, RxJS5 is supposed to be a lot faster

Niklas Fasching
  • 1,326
  • 11
  • 15
  • Thanks, @Nupf. I changed the code accordingly, but it still doesn't work. The triggering of the subject does not seem to let further events through the .sample. My take is that the trigger happens too early and is not remembered by "sample". Well, this is not crucial for me and RxJS 5.0 people mention that actual back pressure could be in the plans, some day. So maybe I'll do without. Thanks! – akauppi Jan 14 '16 at 20:49
  • Yep, would be my take as well. triggerObs seems to be making sample execute before dragObs has emitted a new value. If you look at the [definition](http://reactivex.io/documentation/operators/sample.html) of sample, you can see its meant to only emits each source (dragObs) value once, even if multiple sample (triggerObs) events were fired (playing around with the marbles on that page illustrates that better). – Niklas Fasching Jan 14 '16 at 21:00
  • The interactive marbe diagram is awesome! I've seen them but use too little - maybe because they are not in the RxJS side of docs. Anyways, throttleFirst is what I should be using but it seems simply to lack from RxJS 4.0.7 implementation (it's meant to be in). Will raise an issue. Thanks! – akauppi Jan 15 '16 at 07:41
  • Awesome :). I'll have to check out throttlefirst – Niklas Fasching Jan 15 '16 at 08:33
  • It does not exist, though it should, in RxJS 4.x. See the RxJS issue above. It is shown in the http://reactivex.io/documentation/operators/sample.html page on a static diagram (under RxJS). – akauppi Jan 16 '16 at 10:50