Created
December 18, 2015 20:04
-
-
Save spieden/79255a3a0f27e2c372d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cpdx.db.entity-patch | |
(:require [clojure.data :as data] | |
[slingshot.slingshot :refer [throw+]])) | |
(defn pair->assertion [verb id-ref [attr value]] | |
[verb id-ref attr value]) | |
(defn make-assertions [verb id-ref pairs] | |
(map (partial pair->assertion verb id-ref) | |
pairs)) | |
(defn resolve-patch [id-attr previous current] | |
(let [[removed added retained] (data/diff previous current) | |
id-ref [id-attr (current id-attr)]] | |
(when-not (contains? retained id-attr) | |
(throw+ :ids-disagree)) | |
(into [] | |
(comp cat (remove nil?)) | |
[(make-assertions :db/retract id-ref removed) | |
(make-assertions :db/add id-ref added)]))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment