Clojurescript re-mount module, that handles browser window/tab focus.
Add [district0x/district-ui-window-focus "1.0.0"] into your project.clj
Include [district.ui.window-focus] in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
- district.ui.window-focus
- district.ui.window-focus.subs
- district.ui.window-focus.events
- district.ui.window-focus.queries
This namespace contains window-focus mount module.
This module has no configuration params.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.window-focus]))
(-> (mount/with-args
{})
(mount/start))re-frame subscriptions provided by this module:
Returns browser window/tab is currently focused.
(ns my-district.home-page
(:require [district.ui.window-focus.subs :as window-focus-subs]
[re-frame.core :refer [subscribe]]))
(defn home-page []
(let [focused? (subscribe [::window-focus-subs/focused?])]
(fn []
(if @focused?
[:div "Browser tab is focused"]
[:div "Browser tab is not focused"]))))re-frame events provided by this module:
Event fired when window/tab is focused or blurred. You may want to use re-frame-forward-events-fx to hook into this event.
DB queries provided by this module:
You should use them in your events, instead of trying to get this module's
data directly with get-in into re-frame db.
Returns window-focus instance.
Associates focused state and returns new re-frame db.
lein deps
# To run tests and rerun on changes
lein doo chrome tests