Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 23, 2013 19:05
Show Gist options
  • Select an option

  • Save aamedina/6322861 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6322861 to your computer and use it in GitHub Desktop.
(def ads-api "http://192.241.130.213:8080/user/15/ads-api/")
(defmodel account
{:url "accounts/:id" :api ads-api})
(defcollection accounts
{:url "accounts" :model account :api ads-api})
(defmodel campaign
{:url "accounts/:account-id/campaigns/:id" :api ads-api})
(defcollection campaigns
{:url "accounts/:id/campaigns" :model campaign :api ads-api})
(defn collection
[{:keys [url model api]}
& {:keys [for models channels] :or {models #{}}}]
(let [chans (reduce #(into %1 {%2 (broadcasting-port)}) {} [:sync :update :destroy :sort])
coll (with-meta models {:url url :api api :channels chans :type :collection :model model :for for})]
(sub! [coll :sync] (pub! coll :update coll))
coll))
(defview account-view
[account campaigns]
[:h1.page-header (:name account)]
(account-stats account)
(campaign-collection-view account campaigns))
(defn bootstrap
[& args]
(go (let [accounts (<! (accounts)) account (first accounts) campaigns (<! (campaigns :for account))]
(append! :div#content (account-view account campaigns)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment