Rework sync - also actually remove removed items

This commit is contained in:
Nicholas Kariniemi 2015-07-17 00:36:12 +03:00
parent 755d06f32b
commit d71f9260e8

View file

@ -156,21 +156,31 @@
:recipes {:- #{} :+ nil}})
(defn diff-tx [diff]
(let [grubs-tx (->> diff
:grubs
:+
(map (fn [[k v]] (assoc v :id k)))
(map upsert-grub-tx)
(flatten)
(vec))
recipes-tx (->> diff
:recipes
:+
(map (fn [[k v]] (assoc v :id k)))
(map upsert-recipe-tx)
(flatten)
(vec))]
(into grubs-tx recipes-tx)))
(let [grubs-upsert-tx (->> diff
:grubs
:+
(map (fn [[k v]] (assoc v :id k)))
(map upsert-grub-tx)
(flatten)
(vec))
grubs-retract-tx (->> diff
:grubs
:-
(map (fn [id] [:db.fn/retractEntity [:grub/id id]]))
(vec))
recipes-upsert-tx (->> diff
:recipes
:+
(map (fn [[k v]] (assoc v :id k)))
(map upsert-recipe-tx)
(flatten)
(vec))
recipes-retract-tx (->> diff
:recipes
:-
(map (fn [id] [:db.fn/retractEntity [:recipe/id id]]))
(vec))]
(vec (concat grubs-upsert-tx grubs-retract-tx recipes-upsert-tx recipes-retract-tx))))
(defn patch-state! [conn diff]
(pprint (diff-tx diff))