add helper for setting a put-hints-fn function for IView implementations
another potentially contentious change. the idea here is based on my inability to come up with a reason why each library providing an IView implementation (e.g. views-honeysql) would need a different function for this. in fact, i'd argue that it's probably a better idea to have all the hints going to a single "dispatch" function anyway (aka. this put-hints-fn) and have it check for any metadata on incoming hints and do any custom processing there. the IView implementation libraries have this ability already to add any kind of custom metadata to hints anyway. i don't think anything is lost by this change personally, and it removes the need to call multiple functions to set a custom put-hints-fn for each IView library that a project might need. tl;dr - i like simpler configuration. this change is the beginning of stuff that helps me do that in the future.
This commit is contained in:
parent
c2ef73e311
commit
78feb25839
|
@ -11,6 +11,7 @@
|
|||
;;
|
||||
;; {:views {:id1 view1, id2 view2, ...}
|
||||
;; :send-fn (fn [subscriber-key data] ...)
|
||||
;; :put-hints-fn (fn [hints] ... )
|
||||
;;
|
||||
;; :hashes {view-sig hash, ...}
|
||||
;; :subscribed {subscriber-key #{view-sig, ...}}
|
||||
|
@ -277,9 +278,17 @@
|
|||
(swap! view-system update-in [:views] (fnil into {}) (map vector (map id views) views)))
|
||||
|
||||
(defn set-send-fn!
|
||||
"Sets a function that sends view data to a subscriber whenever a view it
|
||||
is subscribed to has refreshed data."
|
||||
[f]
|
||||
(swap! view-system assoc :send-fn f))
|
||||
|
||||
(defn set-put-hints-fn!
|
||||
"Sets a function that adds hints to the view system. The function set is intended
|
||||
to be used by other implementations of IView."
|
||||
[f]
|
||||
(swap! view-system assoc :put-hints-fn f))
|
||||
|
||||
(comment
|
||||
(defrecord SQLView [id query-fn]
|
||||
IView
|
||||
|
|
Loading…
Reference in a new issue