(def atm (reagent/atom "foo"))
(defn f3
[a b]
(js/console.log "test-component")
(reagent/create-class
{:display-name "test"
:component-did-update
(fn [this prev-argv]
The basic "cursor jumping" issue: | facebook/react#955 |
I.E. onchange events out of order: | facebook/react#7027 |
The relevant fix in reagent: | reagent-project/reagent#253 |
One problem is that you must update the dom value synchronously.
If you fail to do that, you'll get dropped characters, because eventually you'll get two events
in a row and the second one will be based on a stale value (so the first event will get overwritten).
(defn form2-child-component [num]
(print "form2-child-component being created")
(let [pointless-atom (reagent/atom nil)]
(print "form2-child-component being rendered")
(fn [num]
[:div num])))
(defn form3-child-component [num]
[num]
Using JavaScript libraries from ClojureScript involves two distinct concerns:
- Packaging the code and delivering it to the browser
- Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization
Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs
, and so that is what I favor. In paricular, shadow-cljs
lets you install npm modules using npm
or yarn
and uses the resulting package.json
to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.
Documentation for interop is spread all over the place. Under the "Reference" section:
- "Dependencies": mostly about how to consume javascript libraries
- clojurescript.org: "Packaging Foreign Dependenciees": mostly about how to provide javascript libraries for others to consume
- "Advanced Compilation": mostly duplicative, but also describes how to access cljs vars from javascript
- "JS Module Support": describes an alpha-quality feature from GCC to allow optimized imports of GCC compatible libraries without using
goog.provide