Skip to content

Instantly share code, notes, and snippets.

@rafd
Last active January 11, 2016 08:27
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 rafd/c0aca82e0b1f9a32c5d9 to your computer and use it in GitHub Desktop.
Save rafd/c0aca82e0b1f9a32c5d9 to your computer and use it in GitHub Desktop.
om-next-routing-example
(defmethod read :episodes/all
[{:keys [state query]} _ _]
(let [episodes (->> (d/q '[:find (pull ?entity ?pattern)
:in $ ?pattern
:where [?entity :episode/name]]
@state
query)
(map first)
vec)]
(if (seq episodes)
{:value episodes}
{:remote true})))
; ...
(defroute variation-path "/v/:variation-id" [variation-id]
(om/set-query! state/reconciler {:params {:page :variation
:variation-id (UUID. variation-id nil)
:episode-id nil}}))
; ...
(defui ^:once AppView
static om/IQueryParams
(params [_]
{:page :index
:variation-id nil
:episode-id nil})
static om/IQuery
(query [_]
`[({:variation/current [:entity/id :variation/name]} {:variation-id ~'?variation-id})
{:variations/all ~(om/get-query LinksView)}
{:episodes/all ~(om/get-query LanguageView)}
({:episodes/progress ~(om/get-query ProgressView)} {:page ~'?page})
({:variation/translations ~(om/get-query EpisodeView)} {:variation-id ~'?variation-id :episode-id ~'?episode-id})
({:episode/current [:episode/name]} {:episode-id ~'?episode-id})])
Object
(componentDidMount [this]
(router/dispatch!))
(render [this]
(dom/div nil
(dom/div nil
(case ((om/get-params this) :page)
:index (links-view (get (om/props this) :variations/all))
:progress (progress-view (om/computed (vec (get (om/props this) :episodes/progress))
{:episodes (get (om/props this) :episodes/all)
:variations (get (om/props this) :variations/all)}))
:variation (language-view (om/computed (get (om/props this) :episodes/all)
{:variation (get (om/props this) :variation/current)}))
:episode (episode-view (om/computed (get (om/props this) :variation/translations)
{:episode (get (om/props this) :episode/current)
:variation (get (om/props this) :variation/current)})))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment