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:

(def coll (observable-coll :key :id :auto-inc true))

;; Inserting updating data
(transact! coll {:a 0 :b 1}) ;; auto-generated key
(transact! coll {:a 0 :b 1 :id 0}) ;; user-specified key
(transact! coll [0 {:a 0 :b 1}]) ;; user-specified key in tuple
(transact! coll [[0 {:a 0 :b 1}] [1 {:a 2 :b 3}]]) ;; multiple insert/update with user-specified keys
(transact! coll [{:a 0 :b 1} {:a 2 :b 3}]) ;; multiple insert/update with auto-generated keys

;; Removing data
(transact! coll [0 nil]) ;;retract entity
(transact! coll [[0 nil] [1 nil])) ;;retract entities

;; Getting data
(get coll 0)
(count coll)
;; maybe something like this too??
(query coll transducer) ;; -> observable collection (w/o tx support)

;; Observing
(observe coll key f)
Clone this wiki locally