Update codemirror example

This commit is contained in:
Michiel Borkent 2022-11-23 13:40:09 +01:00
parent c18ba8ebd8
commit 3fcc3978e5

View file

@ -16,15 +16,18 @@
(def cm
(let [doc (str/trim "
(require '[reagent.core :as r]
'[reagent.dom :as rdom])
'[reagent.dom :as rdom]
'[re-frame.core :as rf])
(defonce state (r/atom {:clicks 0}))
(rf/reg-event-fx ::click (fn [{:keys [db]} _] {:db (update db :clicks (fnil inc 0))}))
(rf/reg-sub ::clicks (fn [db] (:clicks db)))
(defn my-component []
(let [clicks (rf/subscribe [::clicks])]
[:div
[:p \"Clicks: \" (:clicks @state)]
[:p [:button {:on-click #(swap! state update :clicks inc)}
\"Click me!\"]]])
[:p \"Clicks: \" @clicks]
[:p [:button {:on-click #(rf/dispatch [::click])}
\"Click me!\"]]]))
(rdom/render [my-component] (.getElementById js/document \"reagent\"))
")]