Raw DOM manipulation and events handling
Thanks to the interoperability with JavaScript, we can translate, mostly word by word, the same very mutable JavaScript logic into ClojureScript programs. You'll find yourself select DOM nodes using their IDs or mutating their properties to change their appearance on the browser for instance. In JavaScript, handling events corresponds to setting callbacks, that is, assigning functions - called callbacks - to special properties corresponding to those events (like onmousemove
, and so on). You can follow the same logic in ClojureScript, setting event handlers by mutating those same DOM nodes event descriptor properties.
You only have to remember that if you want to access a DOM's element property, you would write:
(-.property a-js-object)
And to mutate these properties properties, you would have to make use of the set!
function:
(set! (-.a-property a-js-object)
Although this approach means somehow falling back to raw JavaScript, all of the...