Elm (plus Angular2/RxJs)
Jon Kelly
Twitter @jsnightowl
Email [email protected]
Github jkbits1
Slide 2
Slide 2 text
Why Elm?
In how many ways can JavaScript crash?
(and I’m a fan!)
Slide 3
Slide 3 text
What’s different with Elm
All the jargon you may have heard (and more)
Immutability
Pure functions
Compiled code
Uni-directional data flow
(any redux fans here?)
btw, it runs pretty fast
Slide 4
Slide 4 text
FP background
Immutability - not always so fixed
Compiled code - not all languages, e.g. Lisp
Slide 5
Slide 5 text
Elm has real benefits
This UI is straightforward
to code and reason about
Basic framework – 20 lines of code
Slide 6
Slide 6 text
Overview
Elm code basics
Elm front-end
DEMO! Time travel debugging
Elm - uni-directional design
Bonus - solutions in Angular2/RxJs app
(if we get the time)
Slide 7
Slide 7 text
Elm code
Let’s start small and work forwards
Slide 8
Slide 8 text
Elm code
two = 2
Slide 9
Slide 9 text
Elm code
timesTwo x = x * two
Slide 10
Slide 10 text
Elm code
timesTwo x = x * two
timesTwo 2
= 4
Slide 11
Slide 11 text
Elm code
timesTwo2 = (*) two
Slide 12
Slide 12 text
Elm code
timesTwo2 = (*) two
timesTwo2 2
= 4
Slide 13
Slide 13 text
Elm code - currying
timesTwice x y = two * x * y
timesTwice 3 4 = 24
x = timesTwice 3 = ??
x 4 = 24
Slide 14
Slide 14 text
Types
The usual num/int, float, string, bool
Suspects
Lists like arrays
Any length – can only store a single type
Tuples like, er, multiples ?
Fixed length – may store multiple types
Records a bit object-y and a bit duck type-y
Slide 15
Slide 15 text
Lists - real quick
Build [1,2,3] like this 1:: 2 :: 3 :: []
Pass as params :
xs – entire list
x:xs (destructuring like ES6) x is “head”, xs is “tail”
NOTE - access anything after head – takes longer
TL;DR – Elm functions designed to work with
head of list as much as possible