reactjsclojurescriptcodemirrorreagent

ClojureScript: how to change CodeMirror reactively with Reagent


I'm trying to embed a CodeMirror in my webpage to edit several code snippets, one at a time.

To do this I:

Here's what doesn't work:

(defn editor [node-defs-atom node-history-atom]
  (reagent/create-class
    {:reagent-render (fn [] (do [:textarea
                     { :value (@node-defs-atom (last @node-history-atom))
                       :auto-complete "off"}]))
     :component-did-mount (editor-did-mount  node-defs-atom node-history-atom)
     }))

(defn editor-did-mount [node-defs-atom node-history-atom]
  (fn [this]
    (let [codemirror (.fromTextArea  js/CodeMirror
                                     (reagent/dom-node this)
                                     #js {:mode "clojure"
                                          :lineNumbers true})]

                            ...... )))

Changing node-history-atom with reset! doesn't do anything to the text in the CodeMirror. I'm really not sure what is going wrong.

If anyone could tell me where I should put the reference to (@node-defs-atom (last @node-history-atom)) I'd be very grateful.

Thanks in advance!


Solution

  • You can try another way to deal with the CodeMirror editor