Skip to content

Instantly share code, notes, and snippets.

@rgkirch
Created June 20, 2022 11:34
Show Gist options
  • Save rgkirch/4f538dc1f240e37eecbf9ab899bc2af6 to your computer and use it in GitHub Desktop.
Save rgkirch/4f538dc1f240e37eecbf9ab899bc2af6 to your computer and use it in GitHub Desktop.
(require '[missionary.core :as mi])
(require '[goog.dom :as gdom])
(defn Text
[{:keys [text] :as props}]
(let [text-node (gdom/createTextNode)
parent-div (gdom/createDom "span" nil text-node)]
(mi/stream! (mi/ap (gdom/setTextContent text-node (clj->js (mi/?< text)))))
(doseq [entry (dissoc props :text)]
(mi/stream! (mi/ap (gdom/setProperties parent-div
(clj->js {(key entry) (mi/?< (val entry))})))))
parent-div))
(let [text (atom "")
root-node (gdom/getElement "app-container")
app (mi/reactor
(gdom/replaceNode
(gdom/createDom "div" (clj->js {:id "app-container"})
(Text {:text (mi/watch text)
:style (mi/ap (if (even? (count (mi/?< (mi/watch text))))
"color:blue"
"color:red"))})
(gdom/createDom "input"
(clj->js
{:type "text"
:oninput #(reset! text (.. % -target -value))})))
root-node))]
(app #(prn :success %)
#(prn :crash %)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment