Created
April 24, 2017 22:47
-
-
Save roman01la/4f10b860cba71362fbab5ca305a78fce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defmulti control (fn [action] action)) | |
(defmethod control :init [_ [init-state] _] | |
init-state) | |
(defonce reconciler | |
(scrum/reconciler {:state (atom {}) ;; <= client-side state | |
:controllers {:user control}})) ;; <= action handlers | |
(defn render [state] ;; <= initial state rendered into HTML on server | |
;; ... dispatch state to controllers ... | |
(rum/mount (App reconciler) | |
(. js/document (getElementById "app")))) |
This file contains hidden or 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
(defn make-resolver [db] | |
{[:user] #(find-user db)}) ;; <= data resolver for subscription [:user] | |
(def reconciler (-> db make-resolver scrum/reconciler)) | |
(def html (-> reconciler App rum/render-html)) | |
(def state @(:state reconciler)) ;; <= retrieve resolved data after rendering | |
(render-page html state) ;; <= render HTML document |
This file contains hidden or 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
;; UI component with subscription [:user] | |
(rum/defc App < rum/reactive [r] | |
(let [user (rum/react (scrum/subscription r [:user]))] | |
[:div | |
[:div (:name user)] | |
[:div (:email user)]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment