15

Click here to load reader

FRP with Ractive and RxJS

Embed Size (px)

DESCRIPTION

Intro to Functional Reactive Programming for web apps with Ractive.js and Reactive Extensions (RxJS).

Citation preview

Page 1: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

Page 2: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

Why Ractive?o Created at theguardian.como Mustache templateso POJO data binding, event proxieso Animations, transitions, SVG, Promise/A+o Partials, components, pluginso Interactive tutorials

Architectureagnostic

Page 3: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

What is Functional Reactive Programming?

1. FRP is programming with async data streams

2. Everything is a stream

Page 4: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

Two kinds of asynchronism? o Defective async: I/O

o Natural async: Events

Network lags, etc...

Users are free to choos

e

when to click a button

Page 5: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

When we embrace async programming, events are the same as other async

streams.

We can merge async streams from different sources: events, promises...

Reactive Extensions:

Observable interface

Page 6: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

Page 7: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

Example Implement a Twitter-like “Who to follow”

suggestion box for GitHub usersAdapted from André Staltzintroduction to FRP

Page 8: FRP with Ractive and RxJS

Template

Pass index to event handlers

Declare event proxy sources

in HTML code

Page 9: FRP with Ractive and RxJS

Ractive-RxJS bridge & utility

There are also Ractive adaptorsfor RxJS and Bacon.js

Page 10: FRP with Ractive and RxJS

Initialize RactiveElement container

Template

Data

Page 11: FRP with Ractive and RxJS

Refresh event streamEs6 arrow functionsfor simplicity

flatMap === map to another

stream/Observable

Think sequantially!

Page 12: FRP with Ractive and RxJS

Close event streamWe don’t carewhere this is coming from

(declared in HTML)

The Ractive event

contains the index

value

Page 13: FRP with Ractive and RxJS

And that’s all!

Thanks for your attention!I hope this gives you some inspiration

Page 14: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

References Source codeVideo of talk (Spanish)Original example sourceAndré Staltz intro to RsJXRactive.js homepageReactive Extensions: RxJS

Page 15: FRP with Ractive and RxJS

Functional Reactive Programmingwith Ractive.js

I’m a collaborator of the FunScript project(F# to JS compiler), if you’re interested in

functional programming you may want to check it funscript.info/github.com/alfonsogarciacaromeetup.com/madrid-fsharp/

@alfonsogcnunez

tiny