This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-11
Channels
- # aleph (3)
- # announcements (3)
- # aws (7)
- # babashka (121)
- # beginners (82)
- # calva (40)
- # chlorine-clover (37)
- # clj-kondo (68)
- # cljsrn (4)
- # clojure (43)
- # clojure-australia (1)
- # clojure-dev (6)
- # clojure-europe (15)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-provo (3)
- # clojure-spec (23)
- # clojure-taiwan (1)
- # clojure-uk (21)
- # clojurescript (214)
- # code-reviews (1)
- # conjure (4)
- # core-async (10)
- # cursive (52)
- # datahike (5)
- # datascript (5)
- # datomic (62)
- # duct (1)
- # emacs (4)
- # fulcro (8)
- # graalvm (1)
- # helix (1)
- # honeysql (5)
- # integrant (1)
- # jackdaw (32)
- # jobs (3)
- # jobs-discuss (16)
- # juxt (1)
- # kaocha (3)
- # lsp (6)
- # malli (2)
- # meander (6)
- # nrepl (1)
- # off-topic (46)
- # other-languages (4)
- # pathom (7)
- # polylith (13)
- # re-frame (3)
- # releases (2)
- # shadow-cljs (56)
- # spacemacs (15)
- # tools-deps (3)
- # unrepl (1)
- # utah-clojurians (1)
Hey.
Is there a best practice way to inject the js/document
into a reg-sub
using interceptors?
My reframe subscription calculates the position of elements in a game board div in relation to each other. Using getElementById js/document
and the .-offsetLeft
to calculate css left and top would make the sub non pure. I could also do the positional math in the component directly.
Interceptors are only for events, not subscriptions.
No need to inject js/document
anywhere because it's already a singleton. Unless you need to create mocks of documents.
Even if you use js/document
in a sub, the sub won't be recalculated because a document has nothing to do with the Reagent's reactive context.
Don't use getElementById
if you are the one controlling that component. Instead, use React refs.
There are two reasonable ways to solve that:
- Listen to some JS event that's fired when that position that you're interested in changes. If there are no such events, just do it on each requestAnimationFrame
. In the JS event listener dispatch
a re-frame event and write the position to the re-frame's app-db
. In the relevant sub, just use that position
- Don't use re-frame for that particular part of your app - just keep it confined to Reagent. But it's a trade-off