Skip to content

Instantly share code, notes, and snippets.

@tomconnors
Created November 27, 2013 00:05
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 tomconnors/7668570 to your computer and use it in GitHub Desktop.
Save tomconnors/7668570 to your computer and use it in GitHub Desktop.
Init of main component of cljs + react
;;; 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