diff --git a/reagent-data-views-browserchannel/src/reagent_data_views/browserchannel/server.clj b/reagent-data-views-browserchannel/src/reagent_data_views/browserchannel/server.clj index fabf949..7e014d4 100644 --- a/reagent-data-views-browserchannel/src/reagent_data_views/browserchannel/server.clj +++ b/reagent-data-views-browserchannel/src/reagent_data_views/browserchannel/server.clj @@ -5,15 +5,24 @@ [views.core :as views] [reagent-data-views.server.core :as server])) -(defn configure-views! - "performs browserchannel-specific initialization on the views system that is - necessary to hook views and reagent-data-views together via browserchannel." - [& {:keys [context-fn]}] - (views/set-send-fn! - (fn [client-id [view-sig view-data]] - (log/trace client-id "refresh view" view-sig) - (browserchannel/send-data! client-id [:views/refresh view-sig view-data]))) - (server/set-context-fn! context-fn)) +(defn- views-send-fn + [client-id [view-sig view-data]] + (log/trace client-id "refresh view" view-sig) + (browserchannel/send-data! client-id [:views/refresh view-sig view-data])) + +(defn init-views! + "initializes the views system and adds browserchannel-specific configuration + to it to enable the necessary hooks into reagent-data-views. + you should call this *instead* of views.core/init!. all of the same + options can be used. see views.core/init! for more information. + + an additional option :context-fn can be specified which is a function + that accepts an initial context map created by reagent-data-views and + allows your application to add any information necessary to the context + passed to various view system functions (such as auth-fn, namespace-fn, etc)." + [views & [options]] + (views/init! views views-send-fn options) + (server/set-context-fn! (:context-fn options))) (def middleware "clj-browserchannel server-side event middleware. this should be included in the