re-frame effect handlers related to browser window.
Add [district0x/re-frame-window-fx "VERSION"] into your project.clj
Include [district0x.re-frame.window-fx] in your CLJS file
:window/on-resizeFires :dispatch when browser window is resized. Can set :debounce-ms for debouncing event, to prevent too frequent firings.
Default :debounce-ms is 166ms.
Dispatched event receives [js/window.innerWidth js/window.innerHeight] as a last arg.
(reg-event-fx
::my-event
(fn []
{:window/on-resize {:dispatch [::window-resized]
:debounce-ms 200
;; :id is optional
:id ::my-listener}}))
:window/stop-on-resizeIf you passed :id into event handler above, you can stop listening by that :id
(reg-event-fx
::my-event
(fn []
{:window/stop-on-resize {:id ::my-listener}}))
:window/on-focusFires :dispatch when tab/window receives focus
(reg-event-fx
::my-event
(fn []
{:window/on-focus {:dispatch [::window-focused]
;; :id is optional
:id ::my-listener}}))
:window/stop-on-focusIf you passed :id into event handler above, you can stop listening by that :id
:window/on-blurFires :dispatch when tab/window was blurred
(reg-event-fx
::my-event
(fn []
{:window/on-blur {:dispatch [::window-blurred]
;; :id is optional
:id ::my-listener}}))
:window/stop-on-blurIf you passed :id into event handler above, you can stop listening by that :id
:window/on-hashchangeFires :dispatch when location hash was changed
(reg-event-fx
::my-event
(fn []
{:window/on-hashchange {:dispatch [[::window-hashchanged]
;; :id is optional
:id ::my-listener]}}))
:window/stop-on-hashchangeIf you passed :id into event handler above, you can stop listening by that :id
:window/scroll-toScroll window into x y coordinates
(reg-event-fx
::my-event
(fn []
{:window/scroll-to [100 200]}))
lein deps
# To run tests and rerun on changes
lein doo chrome tests
Can you improve this documentation? These fine people already did:
madvas & Benjamin ZaporzanEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |