Skip to content

Commit

Permalink
Import top-level-indexer from #16
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Sep 27, 2012
1 parent 2102d63 commit f20232b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/jiraph/layer/ruminate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ true/false."
(apply concat)
(into source-actions))))))))

(defn top-level-indexer [source index field]
(make source [[field index]]
(fn [source [index] keyseq f args]
(fn [read]
(let [source-update ((apply update-in-node source keyseq f args) read)
read' (graph/advance-reader read source-update)]
(reduce into source-update
(when-let [id (first (if (seq keyseq)
(when (or (not (next keyseq))
(= field (second keyseq)))
keyseq)
args))]
(let [[old-idx new-idx] ((juxt read read') source [id field])]
(when (not= old-idx new-idx)
[((update-in-node index [old-idx] disj id) read)
((update-in-node index [new-idx] conj id) read)])))))))))

;; - eventually, switch from deleted to exists, but not yet
;; - until then, copy all data to incoming edges, whether using adjoin or not

0 comments on commit f20232b

Please sign in to comment.