Push vs pull in reactive-banana
Asked Answered
P

1

7

I am building a mediaplayer-like application using reactive-banana.

Let's say I want a Behavior that represents the currently selected track in the track list.

I have two options: use fromPoll to get the current selection when it's needed; or use fromChanges and subscribe to the selection change event.

I use the selected track Behavior only when the user presses the "Play" button. This event is much more rare than a selection change.

Given that, I'd assume that fromPoll would be better/more efficient than fromChanges in this situation. But the docs say that "the recommended way to obtain Behaviors is by using fromChanges".

Does it still apply here? I.e. will the polling action be executed more often than it is actually used (sampled) by the network?

Pentahedron answered 11/6, 2013 at 19:25 Comment(0)
C
5

In the current version (0.7) of reactive-banana, the fromPoll function actually creates a behavior whose value is determined by executing the polling action whenever any event happens at all.

In contrast, fromChanges will only update the behavior when the particular event given as argument has an occurrence.

In other words, in the current implementation, fromPoll is always less efficient than fromChanges.

Then again, I wouldn't worry too much about efficiency right now, because I haven't spent much time implementing suitable optimizations yet. Just use whatever is simplest now and save any efficiency issues for future versions of reactive-banana.

Cachet answered 12/6, 2013 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.