Fork me on GitHub
#om
<
2017-05-04
>
petterik13:05:23

Found today that we can't close over locals in the clj version of ui.

(let [a 1]
  (ui Object (render [this] a)))
;; => CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context
Seems like it's not possible to close over locals vars with defrecord

carter.andrewj13:05:01

Could you try something like (let [foo (ui Object (render [this] (:a this)))] (assoc foo :a "bar")) ?

petterik13:05:56

ui returns a function which takes props and stuff, not an instance of the record:

(assoc (om/ui Object (render [this] (:a this))) :a 1)
ClassCastException clojure.lang.AFunction$1 cannot be cast to clojure.lang.Associative

petterik14:05:15

Created a macro om-ui which defines vars and replaces the vars for new generated symbols in the body passed to om.next/ui: https://gist.github.com/petterik/28c2fff796edbf4aa12e0e043e9342b0