add helper init/shutdown functions
this init function only is suitable for non-distributed configurations, but is probably still worthwhile to have something like this as it helps remove boilerplate in applications where only a simple config is needed anyway. adding shutdown is mostly useful for applications using component/mount
This commit is contained in:
parent
78feb25839
commit
defd41dd33
|
@ -289,6 +289,31 @@
|
|||
[f]
|
||||
(swap! view-system assoc :put-hints-fn f))
|
||||
|
||||
(defn init!
|
||||
"Initializes the view system for use with some basic defaults that can be
|
||||
overridden as needed. Many applications may want to ignore this function
|
||||
and instead manually initialize the view system themselves. Some of the
|
||||
defaults set by this function are only appropriate for non-distributed
|
||||
configurations."
|
||||
[& {:keys [refresh-interval worker-threads send-fn put-hints-fn views]
|
||||
:or {refresh-interval 1000
|
||||
worker-threads 4
|
||||
put-hints-fn #(refresh-views! %)}}]
|
||||
(if send-fn
|
||||
(set-send-fn! send-fn))
|
||||
(if put-hints-fn
|
||||
(set-put-hints-fn! put-hints-fn))
|
||||
(if views
|
||||
(add-views! views))
|
||||
(start-update-watcher! refresh-interval worker-threads))
|
||||
|
||||
(defn shutdown!
|
||||
"Closes the view system down, terminating all worker threads and clearing
|
||||
all view subscriptions and data."
|
||||
[]
|
||||
(stop-update-watcher!)
|
||||
(reset! view-system {}))
|
||||
|
||||
(comment
|
||||
(defrecord SQLView [id query-fn]
|
||||
IView
|
||||
|
|
Loading…
Reference in a new issue