Skip to content

Instantly share code, notes, and snippets.

@s-mage

s-mage/core.cljs Secret

Created December 22, 2015 16:32
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 s-mage/de762339fc1909a271a1 to your computer and use it in GitHub Desktop.
Save s-mage/de762339fc1909a271a1 to your computer and use it in GitHub Desktop.
reagent example for clojurians
(def routes
{:. home/view
"sign_in" sign-in/view
"sign_up" sign-up/view
"videos" {
:. #(videos/index-view nil)
[:id] {:. #(videos/index-view %)
"status" {[:status] #(videos/index-view %)}}}
"cases" { [:id] cases/view }
})
(defn current-page []
(session/get :current-page))
(defn dispatch! [path]
(session/put! :current-page
(let [path (if (helpers/need-login? path) "/sign_in" path)]
(if-let [r (rm/match path routes)]
(if-let [p (:params r)]
#((:match r) p)
(:match r))
not-found/view)))
(render-component ((current-page)) (sel1 "#app")))
(defn index-view [{:keys [id status]}]
[:div
[:main
(header/view)
[:div.row.videos-list>div.large-12.columns (search-form search-video!)]
[:div.row.videos-list>div.large-12.columns (pages-stats-handler (:pages-statistics @state))]
[:div.row.videos-list>div.large-12.columns
(main (videos/videos-to-show status) @links (if (nil? id) id (int id)))]
[:br]
[:div.row.videos-list>div.large-6.columns
(apply pagination
(conj (into [] ((juxt :page-number :page-size) @state))
(videos/video-ids @links)
change-page!
#(videos/request-videos links state)))]]
(footer/view)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment