Shower Presentation Engine

Dabbling with Reflex FRP

(and ghcjs)

@emmanueltouzery

Reflex basics

  1. Based on FRP concepts

The alternatives

The app I've built (port from fay/knockout)

GHCJS

FRP

Nice DSLs 1/2

using clay!

Nice DSLs 2/2

Events!

source

Constructs

Event 1 2 3
Behavior 1 2 3
Dynamic 1 2 3

thanks to rxmarbles.com!

Event operations

Event is a Functor -> fmap (const 5) clickEvt

leftmost :: … ⇒ [Event t a] → Event t a
mergeWith :: … ⇒ (a → a → a) → [Event t a] → Event t a

ffilter :: FunctorMaybe f => (a → Bool) → f a → f a

Dynamic operations


foldDyn … ⇒ (a → b → b) → b → Event t a → m (Dynamic t b)
Compare to: foldr :: (a → b → b) → b → [a] → b
foldr (+) 5 [1,2,3,4] -> 15

nubDyn :: … ⇒ Dynamic t a → Dynamic t a

Events -- again

source

The ELM basic pattern

Code walkthrough: the date picker

EventsView.hs Prerequisites:
RecursiveDo
const :: a -> b -> a
const x _ = x
fmap (const 6) [1,2,3,4] -> [6,6,6,6]
fmap (\_ -> 6) [1,2,3,4] -> [6,6,6,6]

Some more APIs

Code walkthrough: password field

Config.hs

Note we bypassed the input API, and it's self-contained.

Some more APIs

combineDyn :: … ⇒ (a → b → c) → Dynamic t a → Dynamic t b → m (Dynamic t c)

Code walkthrough: the settings model/XHR

Config.hs

Some more APIs

Some difficulties... (1/2)

Some difficulties... (2/2)

What worked for me

The ugly

My SPA GHCJS/Reflex app is 18MB (all in). That's a pretty hefty page load. (I wasn't successful with first run of closure-compiler either)

— Tim Dysinger (@dysinger) February 27, 2016

... and inline CSS...

Getting started