Skip to content

Instantly share code, notes, and snippets.

Last active May 2, 2021
What would you like to do?
having an issue with bi-directional data binding
(def temps
(r/atom {:c 0 :f 32}))
(defn c-to-f
(+ (* temp 1.8) 32))
(defn f-to-c
(* (- temp 32) .555555555555))
(defn celcius-input [value]
[:input {:type "text"
:value value
:on-change #(assoc state/temps :c (-> % .-target .-value) :f (c-to-f (-> % .target .-value)))}])
(defn celcius-display []
(let [val (get @state/temps :c)]
(fn []
[:p "The Celcius Temperature is: " [celcius-input val]]])))
(defn fahrenheit-input [value]
[:input {:type "text"
:value value
:on-change #(assoc state/temps :f (-> % .-target .-value) :c (f-to-c (-> % .target .-value)))}])
(defn fahrenheit-display []
(let [val (get @state/temps :f)]
(fn []
[:p "The Celcius Temperature is: " [fahrenheit-input val]]])))
(defn gui-two []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment