Component Nesting
(defcomp comp-child [prop-b]
(div {} (<> (str prop-b))))
(defcomp comp-demo [prop-a prop-b]
(div {:class-name "demo" :style {} :on {}}
(<> (str prop-a))
(comp-child prop-b)))
Inline Styles
(def style-page
{:background-color (hsl 240 80 80)
:font-size "14px"})
(div {:style (merge ui/fullscreen ui/column style-page)})
Event Handling
(defn on-click [e dispatch! mutate!]
(dispatch! :confirm "from button")
(println "clicked"))
(div {:style ui/button
:on-click on-click}})
Hot Swapping
(defn reload! []
(clear-cache!)
(render-app!)
(println "Code update."))
Store
(defonce *store
(atom
{:tasks []
:states {}}))
(defn updater [store op op-data]
(case op
:states (update store :states (mutate op-data))
:add-task (add-task store op-data)
store))
(defn dispatch! [op op-data]
(reset! *store (updater @*store op op-data)))
(add-watch *store
(fn [] (println "store is changed!")))
State Management
(defn on-input [e dispatch! mutate!]
(mutate! (:value e)))
(defcomp comp-field [states]
(let
[state (or (:data states) "")]
(div {}
(div {}
(<> span "name" nil))
(input {:placeholder "name"
:value state
:on-input on-input}))))
(defcomp comp-parent [states]
(div {}
(cursor-> :field comp-field states)))