Skip to content

Observable Collection Ideas

aaronc edited this page Nov 8, 2014 · 5 revisions

Change notifications

Every change notification is a vector consisting of vectors representing the individual changes.

Insertion/updates

[unique-key map-of-key-value-pairs]

Deletions/retractions

[unique-key nil]
[unique-key {:key-to-retract nil}]
[unique-key :key-to-retract]
[unique-key [& keys-to-retract]]

Transactions

Try modeling after something similar to Datomic.

Example:

(transact! coll [unique-key map-of-key-value-pairs]) 

(transact! coll map-of-key-value-pairs)

;; Retractions
(transact! coll [:unique-key nil])
(transact! coll :unique-key)

Transaction data:

(defalias UpdateOrInsert (U (HMap) (HVec [Keyword (HMap)]))
(defalias Retraction (U Keyword (HVec [Keyword]))
(defalias PropertyRetraction (HVec [Keyword (U Keyword (HVec [Keyword]))]))
(defalias TxAtom (U Retraction UpdateOrInsert))
(defalias TxData (U TxAtom (Vec TxAtom)))

Or maybe something simpler:

(defalias UpdateOrInsert (HVec [Keyword (HMap)]))
;; or
(defalias UpdateOrInsert (HMap))

(defalias Retraction (HVec [Keyword nil])
(defalias PropertyRetraction (HVec [Keyword (Vec Keyword)])) ;; can also be done by setting null values in UpdateOrInsert
(defalias TxData (U UpdateOrInsert Retraction PropertyRetraction))

(defn transact! [coll & tx-data])

Or maybe something like this:

;; Insert data
(transact! {:a 0 :b 1}) ;; auto-generated key
(transact! {:a 0 :b 1 :id 0}) ;; user-specified key
(transact! [0 {:a 0 :b 1}]) ;; user-specified key in tuple
(transact! [[0 {:a 0 :b 1}] [1 {:a 2 :b 3}]]) ;; multiple insert/update with user-specified keys
(transact! [{:a 0 :b 1} {:a 2 :b 3}]) ;; multiple insert/update with auto-generated keys
(transact! [0 nil]) ;;retract entity
(transact! [[0 nil] [1 nil])) ;;retract entities
Clone this wiki locally