Skip to content

Instantly share code, notes, and snippets.

@jmlsf
jmlsf / f3-example.md
Last active July 20, 2018 19:55
Reagent Form-3 component-did-update
(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]
@jmlsf
jmlsf / reagent-input.md
Last active March 16, 2018 17:59
Input elements in reagent (and react)
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).

@jmlsf
jmlsf / reagent-render-remount.md
Last active February 27, 2018 03:06
reagent/render forces a remount
(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]
@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. 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.

Packaging and Delivering Code

@jmlsf
jmlsf / gist:d691e53e1fea4019a393412f781e2561
Last active September 13, 2021 12:58
(Rough Notes) Importing a javascript module into ClojureScript

Importing a JavaScript Module into ClojureScript

Clojurescript.org Documentation

Documentation for interop is spread all over the place. Under the "Reference" section:

  1. "Dependencies": mostly about how to consume javascript libraries
  2. clojurescript.org: "Packaging Foreign Dependenciees": mostly about how to provide javascript libraries for others to consume
  3. "Advanced Compilation": mostly duplicative, but also describes how to access cljs vars from javascript
  4. "JS Module Support": describes an alpha-quality feature from GCC to allow optimized imports of GCC compatible libraries without using goog.provide