Skip to content

Instantly share code, notes, and snippets.

@hkjels
Last active May 27, 2016 08:52
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 hkjels/ec2bfa514e9c17291d9b11ef3cf76785 to your computer and use it in GitHub Desktop.
Save hkjels/ec2bfa514e9c17291d9b11ef3cf76785 to your computer and use it in GitHub Desktop.
There are no remote calls being made
(defmethod read :lifelines/title
[{:keys [state]} k _]
{:value "Boooom!"})
(defmethod read :lifelines/items
[{:keys [state ast] :as env} k _]
(let [st @state]
(if (contains? st k)
{:value (get st k)}
{:remote true})))
(defmethod read :route/handler
[{:keys [state query]} k _]
(let [st @state]
{:value (get st k)}))
(defmethod read :route/data
[{:keys [parser query ast target] :as env} k params]
{:value (parser env query target)})
(defmethod write 'change/route!
[{:keys [state component]} _ {:keys [handler]}]
"Swaps the route-handler and injects it's query into the root-component"
{:value {:keys [:route/handler :route/data]}
:action #(let [query (om/get-query (route->view (first handler)))]
(swap! state assoc :route/handler handler)
(om/set-query! component {:params {:route/data query}}))})
(def route->view
"Maps a route-keyword to the corresponding view"
{:app/home Home
:app/lifelines Lifelines})
(def route->factory
"Maps a route-keyword to the corresponding view-factory"
{:app/home home
:app/lifelines lifelines})
(defui App
static om/IQueryParams
(params [this] {:route/data []})
static om/IQuery
(query [this] '[:route/handler {:route/data ?route/data}])
Object
(componentWillMount [this]
(let [{:keys [route/handler]} (om/props this)
initial-query (om/get-query (route->view (first handler)))]
(om/set-query! this {:params {:route/data initial-query}})))
(render [this]
(let [{:keys [route/handler route/data]} (om/props this)
current-view (get route->factory (first handler))]
(html [:div.container
(header data)
[:main (current-view data)]]))))
@hkjels
Copy link
Author

hkjels commented May 27, 2016

So, if I mount the Lifeline-component directly as root, the remote calls are made. But I'm trying to achieve some routing and thought I could just manually run my parser, but then send is never invoked.

@hkjels
Copy link
Author

hkjels commented May 27, 2016

In short. Boooom! is outputted, but not my :lifeline/items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment