Thinking'in'ClojureScript - - PowerPoint PPT Presentation

thinking in clojurescript
SMART_READER_LITE
LIVE PREVIEW

Thinking'in'ClojureScript - - PowerPoint PPT Presentation

Thinking'in'ClojureScript Programming)is)not)about)typing,)it's)about)thinking)4)Rich)Hickey What%is%ClojureScript? ClojureScript-is-a-compiler-for-Clojure-that-targets-JavaScript. Goals Understand*the*ClojureScript*thought*process


slide-1
SLIDE 1

Thinking'in'ClojureScript

Programming)is)not)about)typing,)it's)about)thinking)4)Rich)Hickey

slide-2
SLIDE 2

What%is%ClojureScript?

ClojureScript-is-a-compiler-for-Clojure-that-targets-JavaScript.

slide-3
SLIDE 3

Goals

  • Understand*the*ClojureScript*thought*process
  • Learn*enough*ClojureScript
  • Convince*YOU*to*take*ClojureScript*for*a*spin
  • Take*some*of*these*principles*back*to*JavaScript
slide-4
SLIDE 4

Why$ClojureScript?

  • Philosophy
  • It's-not-JavaScript
  • Data-Structures-/-Immutability
  • core.async-library
slide-5
SLIDE 5

It's%not%JavaScript

slide-6
SLIDE 6
slide-7
SLIDE 7
  • Thought(out(design((Nan == Nan ;false)
  • Ba2le(tested((i.e.(Google(Closure)
  • Browser(Repl
  • Real;me(feedback(
  • Macros,(namespaces
slide-8
SLIDE 8

Figwheel(/(Browser(Repl

slide-9
SLIDE 9

Just%enough%ClojureScript

slide-10
SLIDE 10

Hello%ClojureScript

Hello ClojureScript ;; Hello ClojureScript

slide-11
SLIDE 11

Func%on'Call

(+ 5 (* 5 2)) ;; 15 // JavaScript 5 + 5 * 2

slide-12
SLIDE 12

Defining'Func+ons

(defn multiply [x, y] (* x y)) // JavaScript function multiply(x, y) { x * y }

slide-13
SLIDE 13

Interop

(. js/document (getElementById "app") ;; method call (.-value input) ;; property

slide-14
SLIDE 14

atom

(def count (atom 0)) @count ;; 0 (swap! count 1) (reset! count 1)

slide-15
SLIDE 15

let

(let [x 1] x)

slide-16
SLIDE 16

Macros

(-> (om/get-node owner "new-contact-name") .-value)

slide-17
SLIDE 17

(defmacro unless [pred & body] `(if (not ~pred) (do ~@body) nil)) ;; Compiles to (macroexpand '(unless true (/ 1 0)) ; => (if (clojure.core/not true) (do (/ 1 0)) nil)

slide-18
SLIDE 18

core.asyc

Clojure's*implementa1on*of*Communica1ng*Sequen1al*Processes

slide-19
SLIDE 19

Communica)ng+Sequen)al+Processes

  • processes
  • channels
  • coordina.on
slide-20
SLIDE 20

Escape'callback'hell

slide-21
SLIDE 21

Write&sequen+al&logic

(println "do something") (send-to-channel) (println "continue")

slide-22
SLIDE 22

Primi%ves

slide-23
SLIDE 23

Chan%(get%be+er%defini0ons%for%these)

(chan)

slide-24
SLIDE 24

Put

(put!) (>!)

slide-25
SLIDE 25

Take

(take!) (<!)

slide-26
SLIDE 26

go

(go (println "Waiting...") (<! events) (show! "Got an event") )

slide-27
SLIDE 27

Code%example

slide-28
SLIDE 28

Immutability

(def a [1 2 3]) (println (conj a 42)) ;; [1 2 3 42] (println a) ;; [1 2 3]

slide-29
SLIDE 29

Om#+#React

slide-30
SLIDE 30

Lets%talk%about%Om

slide-31
SLIDE 31

Om

Interface)to)Facebook's)React

slide-32
SLIDE 32

React

  • V#in#MVC
  • Immediate#mode#rendering
  • Components
slide-33
SLIDE 33
slide-34
SLIDE 34

Example

h"ps:/ /github.com/iamjarvo/pplz

slide-35
SLIDE 35

Helpful'links

  • h#p:/

/funcool.github.io/clojurescript6unraveled/

  • h#ps:/

/github.com/circleci/frontend

  • h#ps:/

/www.youtube.com/user/ClojureTV

  • h#ps:/

/github.com/omcljs/om

  • h#p:/

/swannode#e.github.io/

slide-36
SLIDE 36

Me

  • Jearvon)Dharrie
  • Twi/er:)@jearvon
  • Podcast:)h/p:/

/turing.cool