SlideShare a Scribd company logo
bacon.js
FRP (functional reactive programming) library for 
Javascript
functional reactive programming?
functional programming 
focus on functions that take immutable values as 
input and produce new values as output 
reactive programming 
based on data flows and the propagation of change
FRP allows us to combine the power from 
both the functional and the reactive 
paradigms
event streams
collection of events that happens over time 
ev ev ev ev ev 
time
events can be mouse clicks, keyboard 
events or any other input 
(ex. data from websocket)
var minusOnes = $('#minusOne').asEventStream('click') 
var allKeyDowns = $(document).asEventStream('keydown') 
var ws = new WebSocket('ws://someurl.com/'); 
var updateStream = Bacon.fromEventTarget(ws, 'message')
power of EventStreams is that 
they are composable
map
1 2 3 
time 
myStream 
3 6 9 f(x) = x * 3 
myStream.map(f)
minusOnes = $('#minusOne').asEventStream('click') 
.map(function(value) { return -1 });
merge
1 4 3 
myStream_2 5 2 
time 
myStream_1 
1 4 3 myStream_1 
.merge(myStream_2) 
5 2
var minusOnes = 
$('#minusOne').asEventStream('click').map(-1); 
var plusOnes = 
$('#plusOne').asEventStream('click').map(1); 
var scores = minusOnes.merge(plusOnes);
scan
b y e 
time 
myStream 
'' 'by' 'bye' 
f(x, y) = concat(x, y) 
myStream.scan('', f) 
'b'
var minusOnes = 
$('#minusOne').asEventStream('click').map(-1); 
var plusOnes = 
$('#plusOne').asEventStream('click').map(1); 
var merged = minusOnes.merge(plusOnes); 
var score = merged.scan(0, function(sum, value) { 
return sum + value 
});
filter
2 3 4 
time 
myStream 
f(x) = even?(x) 
myStream.filter(f) 
2 4
var minusOnes = 
$('#minusOne').asEventStream('click').map(-1); 
var plusOnes = 
$('#plusOne').asEventStream('click').map(1); 
var merged = minusOnes.merge(plusOnes); 
var score = merged.scan(0, function(sum, value) { 
return sum + value 
}); 
var scoreByTens = score.filter(function(value) { 
return value % 10 == 0 
});
property
value that changes over time 
almost like an EventStream, but has a 
current value
a property can be created from an 
EventStream with scan or toProperty
a property can be used for assigning values 
and attributes to DOM elements with 
jQuery
demo
flatMap
flatMap maps each event in the stream to a 
new stream of events
another demo
and more...
http://baconjs.github.io/api.html
interesting examples
collaborative piano 
http://frppiano.herokuapp.com/ 
snake 
http://philipnilsson.github.io/badness/ 
spreadsheet 
http://latentflip.com/bacon_js_spreadsheet/ 
wikipedia updates 
http://dangorst.github.io/frp-with-bacon/
¡gracias!
:)

More Related Content

PDF
Let it Flow - Introduction to Functional Reactive Programming
PPT
Action script 101
PDF
Listing for MyNumberFormats
KEY
Flexible Event Tracking (Paul Gebheim)
PDF
Mpesa_C# (2)
PDF
Angular Refactoring in Real World
PDF
Clojure functions 4
PDF
20180921 #24 we_are_javascripters
Let it Flow - Introduction to Functional Reactive Programming
Action script 101
Listing for MyNumberFormats
Flexible Event Tracking (Paul Gebheim)
Mpesa_C# (2)
Angular Refactoring in Real World
Clojure functions 4
20180921 #24 we_are_javascripters

Viewers also liked (20)

PDF
Prepare your metadata - intro
PPTX
PPTX
Роман Мартин: Cайт “Рада”: Парламент на долоні
ODP
Jumptools testimonials
PDF
Ie for-orgnizational-excellence -nitie
PDF
Gelugor Beamer
PDF
AFIT Beamer
PDF
Alene hjemme
PPS
Sport
PPS
Munkavegzes2
PPTX
PPS
Utcák
PPT
Monopoly1
PPS
Zidanci
PPTX
Character costume
PDF
Kohēzijas politikas ES fondu un ārvalstu finanšu palīdzības investīciju progr...
PDF
Weingarten Beamer
PDF
Adel abouhana HRMS implementation
PPS
Tuzoltok
Prepare your metadata - intro
Роман Мартин: Cайт “Рада”: Парламент на долоні
Jumptools testimonials
Ie for-orgnizational-excellence -nitie
Gelugor Beamer
AFIT Beamer
Alene hjemme
Sport
Munkavegzes2
Utcák
Monopoly1
Zidanci
Character costume
Kohēzijas politikas ES fondu un ārvalstu finanšu palīdzības investīciju progr...
Weingarten Beamer
Adel abouhana HRMS implementation
Tuzoltok
Ad

Similar to bacon.js (20)

PDF
Functional Reactive Programming / Compositional Event Systems
PDF
Functional Reactive Programming in Clojurescript
PDF
How do you do that in FRP
PDF
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
PPTX
Real world functional reactive programming
ODP
FRP and Bacon.js
PDF
FRP with Ractive and RxJS
PDF
Functional Reactive Programming in JavaScript
PDF
Functional Reactive Programming. What does it solve? Does it solve things? Le...
PDF
Reactive programming - Observable
PDF
Funtional Reactive Programming with Examples in Scala + GWT
PPTX
Functional Reactive Programming with RxJS
PDF
Functional Reactive Programming - What does it solve? Does it solve things? L...
PPTX
Reactive programming every day
PPTX
RxJS vs RxJava: Intro
PDF
(Functional) reactive programming (@pavlobaron)
PDF
Learn how to build Functional Reactive Applications with Elm, Node.js and Inf...
PDF
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming in Clojurescript
How do you do that in FRP
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
Real world functional reactive programming
FRP and Bacon.js
FRP with Ractive and RxJS
Functional Reactive Programming in JavaScript
Functional Reactive Programming. What does it solve? Does it solve things? Le...
Reactive programming - Observable
Funtional Reactive Programming with Examples in Scala + GWT
Functional Reactive Programming with RxJS
Functional Reactive Programming - What does it solve? Does it solve things? L...
Reactive programming every day
RxJS vs RxJava: Intro
(Functional) reactive programming (@pavlobaron)
Learn how to build Functional Reactive Applications with Elm, Node.js and Inf...
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd
Ad

bacon.js