build functional reactive - developermarch.com · functional reactive programming (frp) principles....

47

Upload: hoangque

Post on 29-Jun-2018

269 views

Category:

Documents


0 download

TRANSCRIPT

Build Functional Reactive Applications with Elm, Node.js and Infinispan

Galder Zamarreño Arrizabalaga 25th April 2017

Moi

• @

• Infinispan developer & co-founder

•Polyglot programmer

•Functional programming

@galderz

#infinispan

Learn How To Build Functional Reactive Apps

Functional reactive apps

Apps constructed using

Functional Reactive Programming (FRP)

principles

Functional Reactive Programming

is

Abstract

defining FRP

•What is FRP? •Definition

•Why is FRP interesting? •Usefulness

what is FRP?

Composable, declarative way of

programming with

values changing over time

functional

input => combinators => output

Functional + Reactive

event + state → transform

→ state and/or event

Why is FRP interesting?

Composability: easier to reason Asynchronous by default

Efficiency++

how to build frp apps?

HTTP TCP/IP

Elm

HTTP

TCP/IP

statically compiled

Elm

HTTP

TCP/IP

statically compiled

building web user interfaces

Elm

HTTP

TCP/IP

statically compiled

building web user interfaces

promotes FRP

Elm

HTTP

TCP/IP

statically compiled

building web user interfaces

promotes FRP

compiles to fast

Javascript

Elm

HTTP

TCP/IP

statically compiled

building web user interfaces

promotes FRP

compiles to fast

Javascript

most helpful compiler

Elm

HTTP

TCP/IP

statically compiled

building web user interfaces

promotes FRP

compiles to fast

Javascript

most helpful compiler

no runtime

exceptions

Node.js

HTTPTCP/IP

based on express.js

Node.js

HTTPTCP/IP

based on express.js

FRP friendly (async, events)

Node.js

HTTPTCP/IP

based on express.js

FRP friendly (async, events)

stateless, listens on port 3000

Node.js

HTTPTCP/IP

based on express.js

FRP friendly (async, events)

stateless, listens on port 3000

talks binary to data grid

infinispan

HTTPTCP/IP

in-memory data grid

infinispan

HTTPTCP/IP

in-memory data grid

open source

(ASL2)

infinispan

HTTPTCP/IP

in-memory data grid

open source

(ASL2)3 server node

domain

infinispan

HTTPTCP/IP

in-memory data grid

open source

(ASL2)3 server node

domain

2 copies redundant

infinispan

HTTPTCP/IP

in-memory data grid

open source

(ASL2)3 server node

domain

2 copies redundant

Java, Node.js, C/C++... clients

infinispan

HTTPTCP/IP

in-memory data grid

open source

(ASL2)3 server node

domain

2 copies redundant

Java, Node.js, C/C++... clients

remote event

listeners

Elm ArchitectureElm Runtime

Model

Html + Msg (Click) update

Msg (Click) + Model

Cmd e.g. http call…Msg (Http Resp) + Model

Model updated

Model

view

… button click …

Demo: Fetch Talks (1)

GET /events

Demo: fetch Talks (2)

GET /events

iterate

event 1

event 2

Demo: fetch Talks (3)

GET /events

iterate

event 1

event 2

…JSON event[]

Demo: Fetch Talks

Demo: insert Talk (1)

POST /events

demo: insert Talk (2)

POST /events

putIfAbsent

demo: insert Talk (3)

POST /events

putIfAbsent

true/false

createdevent

demo: insert Talk (4)

POST /events

putIfAbsent

true/false

createdevent

JSON true/false

WS: JSON event

WS: JSON event

demo: insert Talk

Elm limitations

• typeclasses → +boiler plate code •dictionary type

•Less FRPy version 0.17+ • Interacting with complex Javascript libraries

•Alternative: Purescript (+complex)

Learn How To Build Functional Reactive Apps

what is FRP

Learn How To Build Functional Reactive Apps

what is FRP

why FRP is useful

Learn How To Build Functional Reactive Apps

what is FRP

why FRP is useful

how to build an FR app

Learn How To Build Functional Reactive Apps

what is FRP

why FRP is useful

how to build an FR app

live coding an FR app

creditsApprove by Aha-Soft from the Noun Project

Window by Oleg Frolov

from the Noun Project

Server Error by Montu Yadav

from the Noun Project

Databases by Oliviu Stoian

from the Noun Project

demo link

github.com/galderz/infinispan-events/tree/early17

Thanks

•elm-lang.org

• infinispan.org

•redhat.com/en/technologies/jboss-middleware/data-grid

www.modsummit.com

www.developersummit.com