Created
April 15, 2017 12:59
-
-
Save Otann/92ce5f5e1c0911e3c480f68f7ba37ab3 to your computer and use it in GitHub Desktop.
Scum example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns probe.core | |
(:require-macros [cljs.core.async.macros :refer [go go-loop]]) | |
(:require [rum.core :as r] | |
[scrum.core :as scrum] | |
[probe.scrum.counter :as counter])) | |
(defonce reconciler | |
(scrum/reconciler {:state (atom {}) | |
:controllers {:counter/state counter/counter-controller}})) | |
(defonce init-ctrl | |
(scrum/broadcast-sync! reconciler :init)) | |
(r/mount (counter/counter-ui reconciler) | |
(js/document.getElementById "app")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns probe.scrum.counter | |
(:require [rum.core :as rum] | |
[scrum.core :as scrum])) | |
(rum/defc counter-ui < rum/reactive [r] | |
[:div | |
; :counter here should be in sync with keyword in | |
; reconciler declaration -> =( | |
[:button {:on-click #(scrum/dispatch! r ::state :dec)} "-"] | |
[:span (rum/react (scrum/subscription r [::state]))] | |
[:button {:on-click #(scrum/dispatch! r ::state :inc)} "+"]]) | |
(def initial-state 0) | |
(defmulti counter-controller (fn [action] action)) | |
(defmethod counter-controller :init [] initial-state) | |
(defmethod counter-controller :inc [_ _ counter] (inc counter)) | |
(defmethod counter-controller :dec [_ _ counter] (dec counter)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment