Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Reactive Programming in Bacon.js

Functional Reactive Programming in Bacon.js

Lightning talk on Functional Reactive Programming in Bacon.js: a short overview of some FRP concepts with some bacon.js code samples.

Tom Kruijsen

January 14, 2016
Tweet

More Decks by Tom Kruijsen

Other Decks in Programming

Transcript

  1. var up = $('#up').asEventStream('click'); var down = $('#down').asEventStream('click'); var counter

    = // map up to 1, down to -1 up.map(1).merge(down.map(-1)) // accumulate sum .scan(0, function(x,y) { return x + y });
  2. var firstname = $("#firstname").asEventStream("keyup") .map(function(event) { return $(event.target).val(); }).toProperty(""); var

    lastname = $("#lastname").asEventStream("keyup") .map(function(event) { return $(event.target).val(); }).toProperty(""); function nonEmpty(x) { return x.length > 0 }; var valid = firstname.map(nonEmpty).and(lastname.map(nonEmpty)); valid.onValue(function(enabled) { $("#submit").attr("disabled", !enabled); });