Fork me on GitHub
#re-frame
<
2020-06-20
>
borkdude10:06:51

Something I'm working on for clj-kondo: user-level hooks for calls. E.g. for re-frame:

kitallis14:06:14

This seems super useful, I’m using a 100% namespaced kws and I often run into situations where my qualification errors aren’t correctly caught during build-time.

p-himik11:06:07

Nice! Although, IIRC re-frame itself doesn't restrict the event IDs in any way - it can be a keyword without namespace, a symbol, a vector, whatever.

p-himik11:06:54

Ah, but given that it's user-level code, then it doesn't matter that much. Whatever a particular user decided to do.

borkdude11:06:45

yeah, it gives the user choices about their own code style

borkdude11:06:09

^ there the code is in its own file

David Pham11:06:19

Would it possible to make clj kondo be aware of all events?

David Pham11:06:57

Like using the event registry and check if the dispatch always sends a valid event?

David Pham11:06:09

Idem for subscriptions? (I am just asking)

borkdude11:06:32

@neo2551 Theoretically one could write a hook for reg-event-fx and register all the keys into some state. And a hook for dispatch will then check the state. But this depends on the order of how the code is linted

borkdude11:06:13

clj-kondo currently does not care about order of how files gets linted, it doesn't sort them in terms of namespace dependencies

borkdude11:06:08

and I guess re-frame already emits warnings for this at runtime right?

borkdude11:06:42

I guess if there is a hook at the end, then you can compare all registered events and all dispatched events and discover discrepancies

borkdude11:06:47

but this only works when you lint all relevant files at the same time

borkdude11:06:07

as of now, some hacky solution would be to use println or prn in the hooks for both dispatch and reg-event-fx and then write a little script to compare the outputs

kitallis14:06:23

Pretty new to re-frame, I’m trying to do something like https://github.com/nilenso/pencil.space/blob/lobby/client/cljs/src/game/events.cljs#L30. I’m trying to fire a series of side-effects when this event is dispatched. Two questions: 1. I assume I can’t assume any particular order for their firing? 2. How do I handle dispatching multiple fx like this which share the same key? Is this even a good idea?

p-himik14:06:00

1. If you mean the effects in ::create-or-join, then yes, the order is not defined. If you really need some ordering, just chain events, i.e. use the :dispatch effect and in that event use the next effect. 2. You can either employ the event chaining described above or make the effect handler accept multiple sets of arguments.

kitallis14:06:29

Hrm, I considered doing 1., but that was making my chained dispatches coupled with the next effect

p-himik14:06:30

Not sure I follow. You should end up with "private" events - you will not call dispatch on them from anywhere.

benny21:06:11

using the renatal lein template (react native), i switched a few things around and my events aren’t firing when i dispatch from my repl. are there common pitfalls for this or is it a known issue by chance?