Replies: 2 comments 2 replies
-
Hey @ulisesmac thanks for opening the discussion and sharing your thoughts So why this macros exist: function so lots of events and even events which dispatch lots of events itself as you might know there is a state machine in re-frame, so these events will be dispatched in next js task, one by one, and its not so effective, also one event could rewrite results from previous events, but each event will trigger reagent render , yes there is optimizations but it works differently in RN, (reagent doesn't consider that it will be used in other env different from web browser), we had cases there js thread was busy and UI was slow yes in IDEA it highlights macro with a warning, but at some point, I gave up and ignore these warnings
i would remove this sugar from re-frame, it adds only confusion, reg-event-fx should be used only, because there are tons of mistakes when you expect db but its cofx and vise versa
yes thats a PITA, i've been living with this long time :( also Cursive doesn't work well with js interop :(
it's not a macros it's just a regular function btw we also have a rule that we shouldn't use hope this shed some light |
Beta Was this translation helpful? Give feedback.
-
just to summarize we have lots of small events, we want to combine them in one handler, order matters, re-frame doesn't guarantee it, so the example above might be executed like -event2 so as you can see its completely unpredictable but developer might expect that event2 will be handled on top of the result of event1 in app-db with fx/merge it will be -event1 |
Beta Was this translation helpful? Give feedback.
-
Hi all!
I've seen the code is using a
defn
macro inutils.re-frame
to register re-frame event handlers.I'd say it's a bit confusing to understand what it does and why it's necessary, also my IDE is showing me code errors since I tried to resolve it as
clojure.core/defn
and the macro generates a function taking the number of delcared args - 1.I oppened this discussion to:
Here's my list:
re-frame.core/reg-event-db
, it always creates them usingre-frame.core/reg-event-fx
, so we're always receivingcofx
, which is not required by all events. When possible, generating events receiving onlydb
is more simple and we're losing this abstraction.defn
macro not asclojure.core/defn
butclj-kondo.lint-as/def-catch-all
which is adef
ignoring its body and being lenient with linting.clojure.core/defn
but the function generated takes less arguments than the args declared, e.g.I must say I'm a big fan of using/writing custom macros, but I try to be very careful when making the decision of where and when to use/create them, also I try not to get too inventive with the API as I use the my IDE's symbol resolution very often.
Thanks for reading,
What do you guys think about it?
Beta Was this translation helpful? Give feedback.
All reactions