Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive...

34
Reactive Programming Simon Van de Water [email protected]

Transcript of Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive...

Page 1: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Reactive Programming

Simon Van de Water [email protected]

Page 2: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Problem

Page 3: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Callback Hell

Page 4: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Spreadsheet Semantics

Page 5: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Functional Reactive Programming

A = B + C

Page 6: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Example

Page 7: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Easily Extended

updateGUI

wait(15)

beep Steer actuator

Page 8: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Reactive Programming For the Web

*

Page 9: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Rx.JS

a.k.a.

Curing your asynchronous blues

Page 10: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

JavaScript 6 Syntax inside!

Page 11: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Array Operations in a Nutshell

Page 12: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

forEach

Page 13: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

map

Page 14: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

filter

Page 15: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

concatAll

Page 16: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Recap

Page 17: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Streams

updateGUI

wait(15)

beep Steer actuator

Stream

Stream

Stream

Stream

Page 18: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Streams

Page 19: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Example

Page 20: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Example

Page 21: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Example

Page 22: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Auto-complete box

Page 23: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Auto-complete box

_

Page 24: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Auto-complete box.js

Page 25: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Reactive Programming in Meteor with

Tracker

Page 26: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Session Variables

Page 27: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Sessions at work!

Page 28: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Create your own dependencies

Page 29: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Need more than one Dictionary? ReactiveDict!

Page 30: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax
Page 31: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

What are we doing?

Large-scale Complex Event

Detection

Reactive Object-Oriented

Programming

Middleware for real-time web-apps

Distributed Reactive

Programming

Page 32: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Conclusion

• Get rid of callback hell

• Error handling made easy

• Different approaches to the same goal

• SOFTLab is making it even better!

Page 33: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax
Page 34: Reactive Programming - Vrije Universiteit Brusselsoft.vub.ac.be/~svdewate/IntroToRP.pdfReactive Programming For the Web * Rx.JS a.k.a. Curing your asynchronous blues JavaScript 6 Syntax

Resources• Netflix JavaScript Talks - Async JS with Rx

• Meteor Manual: http://manual.meteor.com/#deps

• Embedding dynamic dataflow in a call-by-value language

• http://channel9.msdn.com/Events/TechEd/Europe/2012/DEV413

• https://gist.github.com/staltz/868e7e9bc2a7b8c1f754