This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-10
Channels
- # announcements (1)
- # babashka (178)
- # beginners (216)
- # bootstrapped-cljs (1)
- # brompton (5)
- # calva (3)
- # chlorine-clover (1)
- # clj-kondo (2)
- # cljdoc (37)
- # cljfx (4)
- # cljs-dev (2)
- # clojure (360)
- # clojure-chile (8)
- # clojure-europe (3)
- # clojure-italy (5)
- # clojure-nl (9)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (61)
- # clojuredesign-podcast (1)
- # clojurescript (83)
- # clr (2)
- # conjure (4)
- # core-async (14)
- # cursive (20)
- # data-science (2)
- # datomic (15)
- # docker (11)
- # emotion-cljs (1)
- # figwheel-main (28)
- # find-my-lib (1)
- # fulcro (46)
- # helix (16)
- # honeysql (14)
- # jobs (10)
- # jobs-discuss (17)
- # joker (1)
- # juxt (9)
- # kaocha (8)
- # leiningen (3)
- # meander (3)
- # news-and-articles (1)
- # off-topic (110)
- # pathom (7)
- # pedestal (4)
- # protojure (2)
- # re-frame (12)
- # reagent (25)
- # ring (4)
- # shadow-cljs (109)
- # spacemacs (9)
- # specter (1)
- # sql (3)
- # tools-deps (23)
Just as with any other side effect - create an effect handler that adds event listeners and its counterpart that removes them.
i'm brand new to re-frame (literally just have the lein template stuff) so could you please point me to resources on how to do that?
It's all there in the documentation: https://github.com/day8/re-frame/blob/master/docs/Effects.md
lifecycle methods are cleaner for this imo (like component did mount, and component will unmount), but re-framers don't like them
In this case, listening to an event has nothing to do with any lifecycle method because the question doesn't say anything about any component. It's perfectly fine to listen to window events even if you don't have any React component on the page.
@U08JKUHA9 @UAEH11THP You have probably seen this, but just in case: https://github.com/day8/re-frame/blob/master/docs/FAQs/LoadOnMount.md#just-dont
@UAEH11THP the idea is that the window event handlers which you install will dispatch
events which are then handled
by event handlers
There are two ways that the event handlers could be installed: 1. If they are installed and then removed, then that would happen via an effect handler 2. if they are installed once at the beginning on the program and never removed, then just mainline it
my use case is handling cross-process events in electron that are passed as window 'message' events. i can pass stuff from the renderer to main without problem, but going back i'd need window.addEventListener('message', ...)
. specifically i use this to open system-native dialogs (file picker) and i'd need to pass back the result.
i figured i'd add a window event handler that'd then dispatch re-frame events which i could then handle pretty -- but i couldn't figure out what was the right way to "add a window event handler".