Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created February 29, 2016 01:14
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 jlongster/cd5df87a046c6505f8ed to your computer and use it in GitHub Desktop.
Save jlongster/cd5df87a046c6505f8ed to your computer and use it in GitHub Desktop.
(defn make-remote [ast]
(update-in
(merge ast {:query-root true})
[:query]
#(into [] (remove om/ident?) %)))
(defn read-remote
[{:keys [parser ast query target] :as env} key params]
(case key
:transactions {:remote (make-remote ast)}
:accounts {:remote (make-remote ast)}
(if query
{:remote (update-in ast [:query] #(parser env % target))})))
(def db->tree (memoize om/db->tree))
(defn read [{:keys [query state ast target] :as env} key params]
(if target
(read-remote env key params)
(cond
(= key :current-tab) {:value :tab/transactions}
(om/ident? (:key ast))
{:value (apply merge
(get-in @state (:key ast))
;; Need to do this to make links still work
(map
(fn [[k v]] {k (get @state k)})
(remove #(not (and (om/ident? %)
(= (second %) '_))) query)))}
:else
{:value (db->tree query (get @state key) @state)})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment