Skip to content

Instantly share code, notes, and snippets.

@pleasetrythisathome
Last active August 29, 2015 13:58
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 pleasetrythisathome/10420721 to your computer and use it in GitHub Desktop.
Save pleasetrythisathome/10420721 to your computer and use it in GitHub Desktop.
stab at multimethods for app view
(def app-state (atom {:section :main
:sections {:admin {:id :admin
:title "Admin"}
:main {:id :main
:title "Main"}
:other {:id :other
:title "Other"}}}))
(defn button
[{:keys [id title] :as section} owner]
(reify
om/IRender
(render [_]
(html
[:div {:class "button"
:on-click #(put! (om/get-shared owner :transact) [[:section] id])}
title]))))
(defmulti section-view :section)
(defmethod section-view :main
[app owner]
(reify
om/IRender
(render [_]
(html
[:div {:class "main"}
"This is the main section!"]))))
(defmethod section-view :admin
[app owner]
(reify
om/IRender
(render [_]
(html
[:div {:class "admin"}
"This is where you make shit up for your users!"]))))
(defmethod section-view :other
[app owner]
(reify
om/IRender
(render [_]
(html
[:div {:class "other"}
"the big mystery of life"]))))
(defn app-view
[{:keys [section sections] :as app} owner]
(reify
om/IWillMount
(will-mount [_]
(go
(while true
(let [[path val] (<! (om/get-shared owner :transact))]
(om/update! app path val)))))
om/IRender
(render [_]
(html
[:div {:class "app"}
[:div
(om/build-all button (vals sections) {:key :id})]
[:div
(om/build #(section-view %) app)]]))))
(om/root app-view app-state {:target (.getElementById js/document "ccs")
:shared {:transact (chan)}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment