From 78ae6cd774ee4037dab5650ec3c4e6a4f009cfe9 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 27 Dec 2014 23:49:31 -0500 Subject: [PATCH] add extra "on init finished" callback to client-side init! function --- .../clj_browserchannel_messaging/client.cljs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cljs/clj_browserchannel_messaging/client.cljs b/src/cljs/clj_browserchannel_messaging/client.cljs index dffabe5..b837545 100644 --- a/src/cljs/clj_browserchannel_messaging/client.cljs +++ b/src/cljs/clj_browserchannel_messaging/client.cljs @@ -118,6 +118,11 @@ :base - the base URL on which the server's browserchannel routes are located at. default if not specified is '/browserchannel' + :callback - optional function that receives no arguments which will + get called once the browserchannel session is established + (useful if your cljs app init should not be run until an + active browserchannel session is available) + :middleware - a vector of middleware maps. Middleware is optional. If specificed, each middleware is provided as a @@ -175,9 +180,16 @@ X-CSRF-Token HTTP header on all BrowserChannel POST requests to work with any CSRF protection your web app uses (e.g. Ring's wrap-anti-forgery middleware)." - [& {:keys [base middleware]}] + [& {:keys [base middleware callback]}] (let [base (or base "/browserchannel") - anti-forgery-token (get-anti-forgery-token)] + anti-forgery-token (get-anti-forgery-token) + middleware (if callback + (cons + {:on-open (fn [handler] + (fn [] + (callback) + (handler)))} + middleware))] (register-middleware! middleware) (events/listen js/window "unload"