Skip to content

Instantly share code, notes, and snippets.

@wavejumper
Created October 3, 2020 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wavejumper/5f27a0b4a16a04a9b6f1be6d9a9267f1 to your computer and use it in GitHub Desktop.
Save wavejumper/5f27a0b4a16a04a9b6f1be6d9a9267f1 to your computer and use it in GitHub Desktop.
cljspad re-frame demo
(require '[re-frame.core :as rf]
'[sandbox.reagent :refer [render]])
(rf/reg-sub :demo/counter
(fn [db _]
(:counter db)))
(rf/reg-event-db :demo/increment-counter
(fn [db _]
(update db :counter (fnil inc 0))))
(defn ui []
(let [i @(rf/subscribe [:demo/counter])]
[:div
[:h1 "re-frame demo"]
[:button {:on-click #(rf/dispatch [:demo/increment-counter])}
"Increment"]
[:p "The current value is: " [:strong (or i 0)]]]))
(render [ui])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment