Slide 1

Slide 1 text

Building Functional front ends with ClojureScript @silveira_bells Isa Silveira

Slide 2

Slide 2 text

Hi from Brazil

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Life as a frond-end developer since 2010 has had its ups and downs

Slide 8

Slide 8 text

The ups were amazing ✨

Slide 9

Slide 9 text

The JS community is really something else

Slide 10

Slide 10 text

Lots of different approaches and flavors to choose from

Slide 11

Slide 11 text

An infinity of boilerplates

Slide 12

Slide 12 text

But the downs were painful

Slide 13

Slide 13 text

Trying to make sense out of a messy soup of states and scopes

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

An inception of closures to desperately deal with the messy soup of states and scopes

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Async and callback hell

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Async and callback promise hell

Slide 20

Slide 20 text

Overall, JS is great, but how can I lower its cost?

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

What if our front-end didn’t have to be imperative?

Slide 23

Slide 23 text

Functional programming could help me with the downs big time

Slide 24

Slide 24 text

Pure functions and function composition could help me dealing with state and scope

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

And immutability alone could take care of 3 other huge issues

Slide 27

Slide 27 text

Immutability benefits 1.Asynchronous operations 2.Performance 3.Mutation tracking

Slide 28

Slide 28 text

1.Asynchronous operations 2.Performance 3.Mutation tracking Immutability benefits

Slide 29

Slide 29 text

1.Asynchronous operations 2.Performance 3.Mutation tracking Immutability benefits

Slide 30

Slide 30 text

Null Head Obj Obj Obj

Slide 31

Slide 31 text

Head Obj Obj Obj Null Obj

Slide 32

Slide 32 text

1.Asynchronous operations 2.Performance 3.Mutation tracking Immutability benefits

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

“Turn and face the strange”

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Enter ClojureScript

Slide 38

Slide 38 text

So what exactly is ClojureScript?

Slide 39

Slide 39 text

Clojure compiled to JS

Slide 40

Slide 40 text

(((( A simple guide to LISP syntax ))))

Slide 41

Slide 41 text

(defn add-numbers [num1 num2] (+ num1 num2))

Slide 42

Slide 42 text

(add-numbers 3 1) ;; 4

Slide 43

Slide 43 text

Tooling

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

A single tool for managing packages, project build, bootstrapping and scaffolding

Slide 46

Slide 46 text

https://leiningen.org/

Slide 47

Slide 47 text

Built-in ClojureScript REPL and live reload

Slide 48

Slide 48 text

Figwheel https://github.com/bhauman/lein-figwheel

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Native immutable data structures

Slide 51

Slide 51 text

core.async

Slide 52

Slide 52 text

(let [channel (chan)] (go (put! channel “hello AmsterdamJS!”)) (go (.log js/console (take! channel))))

Slide 53

Slide 53 text

(let [channel (chan)] (go (put! channel “hello AmsterdamJS!”)) (go (.log js/console (take! channel))))

Slide 54

Slide 54 text

(let [channel (chan)] (go (put! channel “hello AmsterdamJS!”)) (go (.log js/console (take! channel))))

Slide 55

Slide 55 text

Google Closure Compiler

Slide 56

Slide 56 text

Closure Compilers’s superpowers 1. Dead code removal 2. Cross-module code motion

Slide 57

Slide 57 text

1. Dead code removal 2. Cross-module code motion Closure Compilers’s superpowers

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

1. Dead code removal 2. Cross-module code motion Closure Compilers’s superpowers

Slide 60

Slide 60 text

utils.cljc

Slide 61

Slide 61 text

core.cljs

Slide 62

Slide 62 text

signup.cljs

Slide 63

Slide 63 text

utils.cljc core.cljs signup.cljs app-state get-logged-user app-state get-field-value

Slide 64

Slide 64 text

utils.cljc core.cljs signup.cljs app-state get-logged-user get-field-value

Slide 65

Slide 65 text

JS interop

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

vs

Slide 69

Slide 69 text

Closure Compiler compliant libs also benefit from advanced compilation optimizations

Slide 70

Slide 70 text

~16% smaller React’s bundle size is https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules

Slide 71

Slide 71 text

How does it look like in practice?

Slide 72

Slide 72 text

$ brew install lein

Slide 73

Slide 73 text

$ lein new figwheel cljs-slides

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Back-end

Slide 78

Slide 78 text

Front-end

Slide 79

Slide 79 text

Shared code

Slide 80

Slide 80 text

$ lein do clean, cljsbuild once min

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No matter what your problem is, remember to think of the non-obvious solutions

Slide 84

Slide 84 text

“If all you have is a hammer, everything looks like a nail”

Slide 85

Slide 85 text

You’re not a language, you’re not a framework, you’re not a programming paradigm

Slide 86

Slide 86 text

@silveira_bells Thanks!