This is a note of the Learn ClojureScript.
ClojureScript and Tools
The immutable data structure and FP optimize UI. ClojureScript uses CSP (Communicating Sequential Processes) for async tasks.
Figwheel compiles and load changes into the browser instantly. There are three pillars of reloadable code
- idempotent functions
defonce: it binds the var once, as well as evaluation of its expression once.
- separate UI and business logic.
js->clj for converting from JS data and
clj->js for converting to JS. ClojureScript creates a namespace
js that contains all of the global JS variables. Use
set! to update a js variable.
#js to create object literal. Use
aset to get and set properties. Properties can be accessed with
.-propertyName obj and seet with
set! (.-propertyName obj) value.
(.methodName obj args) to call a JS object method.
We use Google Closure’s DOM lib
goog.dom to manipulate DOM. The root is
js/document. Google dom lib has functions such as
getElement, etc. Use
aget to get an element’s value.
listen to bind event handler.