JSFiddle - React, Tailwind, and code Playground

by vikikamath

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.35/Bacon.min.js"></script>
<a href="#1">A</a>
<a href="#2">B</a>
<a href="#3">C</a>

JavaScript

var eChannel = new Bacon.Bus(),
    s,
    hChannel = new Bacon.Bus();


eChannel.plug(Bacon.interval(1000, "a"));

hEventStream = Bacon.repeatedly(5000, ["A", "A", "B"]).map(function(v){
    if (!s) {
        s = v;
        return false; // will enable events flow
    } else {
        // s === v then screenId did not change
        // s !== v then screenId changed
        return s === v;
    }
})

hChannel.plug(hEventStream);

eChannel.holdWhen(hChannel).log()

hChannel.log()
//eChannel.log()


//Bacon.interval(2000, "a").holdWhen(Bacon.repeatedly(5000, [true, false])).log()



/*var scoreMultiplier = Bacon.constant(1),
    hitUfo = new Bacon.Bus(),
    hitMotherShip = new Bacon.Bus(), 
    score = Bacon.update(
     0,
  [hitUfo, scoreMultiplier], function(score, _, multiplier) { return score + 100 * multiplier },
  [hitMotherShip], function(score, _) { return score + 2000 }
);

hitUfo.plug(Bacon.interval(1000, Bacon.sequentially(1, [1,2,3])))

score.onValue(function(x){
    console.log(x);
});*/

/*var hitUfo = new Bacon.Bus(),
    hitMotherShip = new Bacon.Bus(), 
    score = Bacon.when(
      [hitUfo], function(score, _) { return score + 33 },
      [hitMotherShip], function(score, _) { return score + 2000 }
    );

hitUfo.plug(Bacon.interval(1000, 1))
hitMotherShip.plug(Bacon.interval(2000, 3))

score.onValue(function(x){
    console.log(x);
});
*/

/*var analyticsChannel = new Bacon.Bus(),
    hashChangeChannel = new Bacon.Bus(),
    s = screen();
    pattern = Bacon.when(
        [hashChangeChannel], function(h){
            screen().set(h);
            return screen().get();
        },
        [analyticsChannel], function(a){
            return a + "-" + screen().get();
        }
      );

function screen (){
        var scr = "";
           
        return {
            "get": function(){
               return this.scr;   
            }.bind(this),
            "set": function(_sc){
                this.scr = _sc;
            }.bind(this)
        }
   ...