This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-29
Channels
- # adventofcode (1)
- # announcements (2)
- # beginners (163)
- # biff (3)
- # calva (19)
- # cider (56)
- # cljs-dev (5)
- # clojure (43)
- # clojure-belgium (2)
- # clojure-europe (47)
- # clojure-norway (32)
- # clojure-uk (2)
- # clojurescript (24)
- # datomic (5)
- # events (1)
- # fulcro (2)
- # hoplon (11)
- # hyperfiddle (12)
- # jobs (1)
- # lsp (15)
- # malli (7)
- # music (1)
- # polylith (2)
- # re-frame (7)
- # reagent (7)
- # shadow-cljs (25)
- # specter (9)
- # squint (16)
- # xtdb (5)
Hello, I'm trying to keep track of which re-frame event was the original call of a chain of events, so I tried with an interceptor
{:id "test"
:before (fn [context] context)
:after (fn [context]
(let [orig-event (get-in context [:coeffects :original-event 0])]
(println "BEFORE" orig-event) ;; prints the correct value
(assoc-in
context
[:effects some path in the subsequent event]
orig-event)))}
but when I look at the effect the data is never addedand if I do
(let [orig-event (get-in context [:coeffects :original-event 0])
new-context
(assoc-in
context
[:effects some-path]
orig-event)]
(println "BEFORE" (:effects new-context))
new-context)
the :effects
of the new context are what I am expectingTo add clarity to my intent: I have event-a
that dispatches event-b
, the interceptor should add to the arguments of event-b
(a hashmap) the orig-event
value, it's correctly done, but event-b doesn't see the orig-event value
To make sure it's not an XY problem - what exactly are you trying to achieve? And why are you doing it this way and not the more direct way where you put that info there explicitly?
It's currently done explicitely, but there are many possible event-a_1
, event-a_2
, that all dispatch event-b
(this one is unique), and in some cases, event-b
needs to dispatch again the correct event-a_...
So right now, when dispatching event-b
I have a key :orig-event event-a_1
as part of the argument map of the dispatch, but I'm trying to create an interceptor that does that itself, to avoid having to type :orig-event every time and risking typos and such
I see. I would still pass that data by hand, I think. Even if it's 10 events doing that - :orig-event
is just a keyword and you can't safeguard every keyword, and the event ID is already there as a value.
And in the case of an interceptor you're exchanging correctly typing :orig-event
for remembering to having to provide the right interceptor. :)
Ah, I'm wrong, sorry. So yeah, you'll have to provide that interceptor to all the events.
it's a graphql request, so essentially we have
event-a_1 -> graphql-request-event (with :http-xhrio) -> graphql-on-success-event
and depending on the return value of graphql (e.g. pagination), we want to trigger event-a_1
again
the way our a* events dispatch it is just with returning
{:graphql-request-event request-args}
instead of a {:dispatch [...]}
and I just realised this seems to prevent the interceptors from triggering
And there are many ways to have a built-in effect dispatch an event: :dispatch
, :dispatch-n
, :dispatch-later
, and their 3 combinations with :fx
. And some libraries or your own code can add more - just like with that GraphQL key.
Not sure what you mean by "run" here. If it's building that you're talking about, I would recommend shadow-cljs.
My preferred way is with shadow-cljs. It has very good https://shadow-cljs.github.io/docs/UsersGuide.html: basically define your target depending on what you are looking to do, it supports multiple REPL options (nREPL, socket, others). Let us know what you are after!