add extra "on init finished" callback to client-side init! function

This commit is contained in:
Gered 2014-12-27 23:49:31 -05:00
parent 30535a8c60
commit 78ae6cd774

View file

@ -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"