One approach that I am toying with is storing a "view context" in the app state:
a route might look something like this:
(defroute projects-path "/projects" []
[:redirect
{:view projects-component
:data-url "/api/projects"
:data-path :projects}])
I have a nav-ch (core.async chan) that is putted to via my a wrapper around
goog.History. which i then listen to and dispatch to secretary.
(defn init-navigation-handler [event-ch]
(go-loop []
(let [{:keys [token]} (<! nav-ch)]
(>! event-ch (secretary/dispatch! token)))
(recur)))
I have a generic event-ch/event-pub which i use for most top-level
communication which I put the result of the route dispatch to, in this case:
[:redirect
{:view projects-component
:data-url "/api/projects"
:data-path :projects}]
where the first item :redirect is the topic/action. This is listened to in the
next fn and is swapped onto my app-state :view-ctx along with new data after
doing an ajax request.
(defn redirect-handler []
(go-loop-sub event-pub :redirect [_ {:keys [data-url data-path] :as ctx}]
(go-ajax {:keys [success body] :as res} {:method :get :url data-url}
(when success
(swap! app-state conj {:view-ctx ctx data-path body})))))
and finally my root component acts on view-ctx and re-renders its children
based on the :view and :data-path
(defn app-view [data owner]
(om/component
(let [{:keys [view data-path] :as view-ctx} (:view-ctx data)]
(html
[:div
(if (or (nil? data-path) (nil? (data-path data)))
(om/build view data)
(om/build view (data-path data)))]))))
This seems to do the job for now and is quite un-obtrusive but i'm sure i will
have to tweak it as I go. Hopefully it will give you some ideas. Would love to
see other approaches too.
-- Ahmad Hammad
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.