From defd41dd3354b7f3fd9f2504e2f81ff3767751d0 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 19 May 2016 17:36:21 -0400 Subject: [PATCH] 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 --- src/views/core.clj | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/views/core.clj b/src/views/core.clj index 8390b1c..4c09539 100644 --- a/src/views/core.clj +++ b/src/views/core.clj @@ -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