Created
November 27, 2013 00:05
-
-
Save tomconnors/7668570 to your computer and use it in GitHub Desktop.
Init of main component of cljs + react
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
;;; definition of Layout component - the root component for the application | |
(defr Layout | |
[component prop _] | |
[:div.nav-slide-wrap {:on-click handle-body-clicks} | |
;; a sub component - it's passed the entire `prop` even though it | |
;; doesn't need all of it. Eventually it'll be smart for me to only pass the necessary data to components. | |
[Nav prop] | |
[:div {:class-name (str "main-body " (if (:user prop) "signedIn" "notSignedIn"))} | |
[Header prop] | |
[Content prop] | |
[Footer]]]) | |
;; create an endless loop that reads from the app-state atom whenever there's new state, and sets | |
;; the `props` of the layout to the new state. | |
(go (let [ch (chan) | |
[_ _ _ _ new-state] (<! (state/sub ch)) | |
layout (react/render-component (Layout new-state) content-el)] | |
(loop [] | |
(let [[_ _ _ _ new] (<! ch)] | |
(.replaceProps layout new) | |
(recur))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment