簡體   English   中英

功能性Javascript BaconJS,如何將更多值推送到事件流?

[英]Functional Javascript BaconJS, how can I push more values to an event stream?

我試圖在BaconJS中創建一堆AJAX響應。 它以先進先出的方式處理它們,但每個'out'事件應該等待用戶輸入。

這就是我現在所處的位置: 直播JSBin

var pages = Bacon.fromArray([1,2,3])
var next = $("#next").asEventStream('click').map(true);

pages.flatMapConcat(asyncFunction).zip(next).log("responses")

function asyncFunction(page) {
  // Simulating something like an AJAX request
  return Bacon.later(1000 + (Math.random() * 3000), "Page "+ page)
}

目前, #next單擊EventStream時,這將同步從EventStream pages輸出一個事件,這是我想要的行為。


但是 ,我無法弄清楚如何將更多值推送到EventStream pages 我試圖用Bus替換EventStream頁面,並推送像這樣的值(這不起作用)。

var pages = new Bacon.Bus()
pages.push("value")

如何將更多值推送到EventStream

我知道這是一個老帖子,但公共汽車會工作。 只需將數字(之前有一個數組)推入其中:

var pages = new Bacon.Bus();
// Bacon.fromArray([1,2,3])
var next = $("#next").asEventStream('click').map(true);

pages.flatMapConcat(asyncFunction).zip(next).log("responses")

function asyncFunction(page) {
  // Simulating something like an AJAX request
  return Bacon.later(1000 + (Math.random() * 3000), "Page "+ page)
}


pages.push(1);
pages.push(2);
pages.push(3);

我克隆了你的jsbin並將其更改為使用總線

如前所述,您可以使用fromEventfromBinder等流式傳輸頁面值的來源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM