bacon.js

Wait for latest values from dependent streams in BaconJS?

帅比萌擦擦* 提交于 2020-01-07 02:49:04
问题 I have 3 streams. gradingResult and contextId depend on studentResponse . I need to fire an event and only one event (otherwise, this is trivial) when all 3 have the latest values. I've tried #combineTemplate and #sampledBy studentResponse . Unfortunately, I always see the wrong data--- gradingResult and contextId have the old values in the combined template. How can I wait for all streams to have the latest values? Code is shown below: var studentResponse = new Bacon.Bus(); var gradingResult

bacon.js Bus.plug: Uncaught Error: not an Observable : [object Object]

这一生的挚爱 提交于 2020-01-06 14:08:11
问题 I was trying baconjs's tutorial. https://baconjs.github.io/tutorials.html#content/tutorials/2_Ajax But, I got the error at "Bus.plug" var cart = ShoppingCarEt([]) var cartView = ShoppingCartView(cart.contentsProperty) var newItemView = NewItemView() cart.addBus.plug(newItemView.newItemStream) Error: Uncaught Error: not an Observable : [object Object] shopBundle.js:145 assertObservable shopBundle.js:2650 Bus.plug I use follows baconjs@0.7.53 jquery@2.1.3 bacon-jquery-bindings@0.2.8 webpack 1.7

How to handle mouse and touch events simultaneously with reactive event streams

孤人 提交于 2020-01-03 09:49:59
问题 I'm building an audio playback control that lets users scrub back and forth through an audio file. It needs to work with touch and mouse events. How should I go about managing the events for this with reactive event streams? Here's a rough idea of how I would expect to build it. <div id="timeline"> <span id="scrubber"></span> </div> then, using Bacon.js to create event streams var mousedowns = $('#timeline').asEventStream('mousedown'); var touchstarts = $('#timeline').asEventStream(

How to handle mouse and touch events simultaneously with reactive event streams

前提是你 提交于 2020-01-03 09:49:09
问题 I'm building an audio playback control that lets users scrub back and forth through an audio file. It needs to work with touch and mouse events. How should I go about managing the events for this with reactive event streams? Here's a rough idea of how I would expect to build it. <div id="timeline"> <span id="scrubber"></span> </div> then, using Bacon.js to create event streams var mousedowns = $('#timeline').asEventStream('mousedown'); var touchstarts = $('#timeline').asEventStream(

Functional reactive operator for custom filter based on another Observable

北慕城南 提交于 2019-12-22 10:28:58
问题 For fun and to learn I'm trying to implement an undo system in my app using functional reactive programming. I have a stream of state changes, which need to be saved onto the undo stack. When the user clicks undo, I take a value from the stack and update application state accordingly. The problem is that this update itself also generates an event in the state change stream. So what I would like is to derive another stream from state changes, which ommits state change right after undo. A

Bacon.js Maximum Call Stack Exceeded

穿精又带淫゛_ 提交于 2019-12-22 08:59:42
问题 I'm trying to produce a stream similar to Bacon.fromPoll for requestAnimationFrame Why does the following code produce a " Maximum call stack exceeded " error? function rafSequence() { var raf = Bacon.fromCallback(function(callback) { requestAnimationFrame(function() { callback(Date.now()); }); }); return raf.merge(raf.flatMap(rafSequence)); } rafSequence().log(); I thought merge() would garbage collect when one of the 2 streams threw a Bacon.End (the raf in raf.merge(...) . So why does it

How to interleave streams (with backpressure)

百般思念 提交于 2019-12-18 15:18:27
问题 Suppose I have two possibly infinite streams: s1 = a..b..c..d..e... s2 = 1.2.3.4.5.6.7... I want to merge the streams and then map merged stream with slowish asynchronous operation (e.g. in Bacon with fromPromise and flatMapConcat ). I can combine them with merge : me = a12b3.c45d6.7e... And then map s1 = a..b..c..d..e... s2 = 1.2.3.4.5.6.7... me = a12b3.c45d6.7e... mm = a..1..2..b..3..c..4..5.. As you see greedier s2 streams gets advantage in the long run. This is undesired behaviour . The

how should I keep a running total of several values with bacon.js?

偶尔善良 提交于 2019-12-12 20:39:04
问题 Messing around with a bacon.js. I'd like to keep a running total of values in a group of text inputs. The example on the github site uses .scan and an adder function, which works fine for the example because it's using -1 and +1 in the stream. But I'd like values to be removed from the stream if they are edited, so the .scan solution won't really work for me or I'm not doing it right. Markup: <ul style="repeat-direction: vertical; list-style-type: none;"> <li><input data-group="0"></li> <li>

bacon.js - Ignoring certain values in a stream

谁都会走 提交于 2019-12-11 18:42:40
问题 Assuming the following code (current state can be viewed here ): function scrollTopFromEvent(evt) { return $(evt.target).scrollTop(); } function scrollDirection(evt) { return -evt.originalEvent.wheelDelta / 120 || evt.originalEvent.detail / 3; } function pageNumber(previous, next) { return previous + next; } function scrollToPage(pageNumber) { var container = $('.parallax'); TweenLite.to(container, 1, { scrollTop: container.height() * (pageNumber) }); } function inRange(pageNumber) { var

map a stream to lazy promise stream

笑着哭i 提交于 2019-12-10 10:35:29
问题 I have a I have a stream of numbers, I have to turn them into a stream of posts using a promise. And I want to do this lazily. So if I do .take(1) from the post stream, it will turn only one number to a post. This is the promise that gets a post from a number: var getPost = function(author) { console.log('get post' + author); return new RSVP.Promise(function(resolve, reject) { setTimeout(function() { var result = "Post by " + author; resolve(result); }, 1000); }); }; I am only interested in