Build your next single
page app in ClojureScript
and re-frame
Paul Bostrom

@pbostrom
The speaker
• Generalist - mostly backend and devops; some frontend
experience

• Prefer Clojure/ClojureScript

- 7 years experience (hobby/work)

- Don’t consider myself an expert

- I can go fast and get things mostly right

• Current project is first production ClojureScript
The audience
• Clojure developers who want to try frontend

• Tech leads who need to choose a frontend tech

• JavaScript developers who want to try something new

• ClojureScript skeptics
ClojureScript for Skeptics
https://www.youtube.com/watch?v=gsffg5xxFQI
ClojureScript for Skeptics
• JavaScript interop and npm ecosystem is available

• Tooling

grunt, gulp, webpack, babel, browserify, yeoman, brunch

vs.

ClojureScript compiler, figwheel, lein (or boot, tools.deps)

• Performance is equivalent (or better: immutability + React)

• clojure.spec in lieu of types

• Editor support: emacs, vim, Atom, VS Code

• core.async (compare with async/await)

• Code size: advanced compilation, code-splitting/output modules
JavaScript vs ClojureScript
Some high-level characteristics
• Permissiveness

• Expressiveness

• Top-down vs bottom-up design
JavaScript permissiveness
• Mutability

• Classes, prototypes, inheritance

• Accidental global variables

• hoisting

• callback hell, promises, async/await

• this
• funky truthiness
Languages ranked by
expressiveness
https://redmonk.com/dberkholz/2013/03/25/programming-languages-ranked-by-expressiveness/
Top-down vs bottom-up
design
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design
A top-down approach is essentially the breaking down of a system to gain insight into
its compositional sub-systems. Top down approach starts with the big picture. It breaks
down from there into smaller segments.
A bottom-up approach is the piecing together of systems to give rise to more complex
systems, thus making the original systems sub-systems of the emergent system.
Bottom-up processing is a type of information processing based on incoming data from
the environment to form a perception.
Top-down vs bottom-up
design
• Web design: visual, wire-frames, big picture

• Clojure design: data, data, data
Bottom Up vs Top Down Design in Clojure - Mark Bastian
https://www.youtube.com/watch?v=Tb823aqgX_0
JavaScript vs ClojureScript
An observation
High-level language characteristics (permissiveness, expressiveness, design approach)
permeate the development ecosystem
The project
• Browser-based single page web app

• Not necessarily optimized for mobile, but should still be
usable

• Multiple data sources: HTTP APIs, WebSockets
Demo
https://docs.metismachine.io/docs/predict-the-price-of-cryptocurrency-in-10-minutes
Why do we need a framework?
https://medium.com/dailyjs/the-deepest-reason-why-
modern-javascript-frameworks-exist-933b86ebc445
re-frame
• Data oriented design. Events are data. Effects are data.
DOM is data. The functions which transform data are
registered and looked up via data.

• Uses reagent: “minimalistic interface between
ClojureScript and React”

• Hiccup-like syntax for describing UI
re-frame
https://github.com/Day8/re-frame
re-frame
app state
view
event/effects
handlers
subscriptions
events
events/effects
update
state
re-frame
app state
view
event/effects
handlers
subscriptions
events
events/effects
update
state
Async HTTP
fetch logs scroll
HTTP API
fetching
fetching
re-frame
app state
view
event/effects
handlers
subscriptions
events
events/effects
update
state
render spinner
Async HTTP
re-frame
app state
view
event/effects
handlers
subscriptions
events
events/effects
update
state
HTTP Response
new
logs
new
logs
render new logs
Async HTTP
re-frame
app state
view
event/effects
handlers
subscriptions
events
events/effects
update
state
validate with clojure.spec
re-frame
• Around since 2015

• Stable

• Rich ecosystem: 

https://github.com/Day8/re-frame/blob/master/docs/
External-Resources.md

• re-frame-10x: http://localhost:3000
Code size
Advanced compilation, gzipped
Not bad, even for mobile
Avg case: < 1s
Worst case: slow 3G connection ~ 5-10s
re-frame
Misc.
• What about Vue.js or AngularJS?

• Onboarding new developers

• 3rd party libraries: npm deps, CLJSJS

• Advanced compilation

• Testing: doo, chrome-headless, re-frame.test
The end.

Build your next single page app in ClojureScript and re-frame