This commit is contained in:
Nicholas Kariniemi 2015-08-10 06:45:09 +03:00
parent d71f9260e8
commit cec0060984

View file

@ -74,24 +74,26 @@
(defn remap-keys [key-maps coll] (defn remap-keys [key-maps coll]
(reduce (fn [new-coll [key new-key]] (assoc new-coll new-key (get coll key))) {} key-maps)) (reduce (fn [new-coll [key new-key]] (assoc new-coll new-key (get coll key))) {} key-maps))
(defn get-current-state [conn] (defn query-entities [db entity-key]
(let [db (d/db conn) (->> db
get-entity (fn [[id]] (d/touch (d/entity db id))) (d/q [:find '?e :where ['?e entity-key]])
grub-ids (d/q '[:find ?g :where [?g :grub/id]] (d/db conn)) ((fn [[id]] (d/entity db id)))))
map-grub-keys #(remap-keys {:grub/id :id :grub/text :text :grub/completed :completed} %)
grubs (->> grub-ids (defn get-current-db-state [db]
(map (comp map-grub-keys get-entity)) (let [grubs (->> (query-entities db :grub/id)
(map #(remap-keys {:grub/id :id :grub/text :text :grub/completed :completed} %))
vec vec
(util/map-by-key :id)) (util/map-by-key :id))
recipe-ids (d/q '[:find ?r :where [?r :recipe/id]] (d/db conn)) recipes (->> (query-entities db :recipe/id)
map-recipe-keys #(remap-keys {:recipe/id :id :recipe/name :name :recipe/grubs :grubs :recipe/directions :directions} %) (map #(remap-keys {:recipe/id :id :recipe/name :name :recipe/grubs :grubs :recipe/directions :directions} %))
recipes (->> recipe-ids
(map (comp map-recipe-keys get-entity))
vec vec
(util/map-by-key :id))] (util/map-by-key :id))]
{:grubs grubs {:grubs grubs
:recipes recipes})) :recipes recipes}))
(defn get-current-state [conn]
(get-current-db-state (d/db conn)))
(defn remove-keys-with-nil-vals [mapcoll] (defn remove-keys-with-nil-vals [mapcoll]
(->> mapcoll (->> mapcoll
(remove (fn [[k v]] (nil? v))) (remove (fn [[k v]] (nil? v)))