What is Bacon.js?

A small functional reactive programming lib for JavaScript. Turns your event spaghetti into clean and declarative feng shui bacon, by switching from imperative to functional. It's like replacing nested for-loops with functional programming concepts like map and filter . Stop working on individual events and work with event-streams instead. Transform your data with map and filter . Combine your data with merge and combine . Then switch to the heavier weapons and wield flatMap and combineTemplate like a boss. It's the _ of Events. Too bad the symbol ~ is not allowed in Javascript.

Getting started

Check out the introduction (slideshow), the API reference and the GitHub page. Or take a look at one of the tutorials to learn how to use Bacon.js on the client, server or in game programming.

Examples

Simple counter

Behold! It counts up and down as you click the buttons Up Down 0 var up = Bacon.fromEvent($('#up'), 'click'); var down = Bacon.fromEvent($('#down'), 'click'); var counter = // map up to 1, down to -1 up.map(1).merge(down.map(-1)) // accumulate sum .scan(0, (x,y) => x + y); // assign observable value to jQuery property text counter.onValue(text => $('#counter').text(text)); Reload

Movie Search