Fork me on GitHub
#re-frame
<
2022-03-22
>
Dustin Paluch03:03:24

Can I just return nil from a reg-event-fx if nothing needs to happen?

Dustin Paluch03:03:10

> When an event handler is registered via reg-event-fx, it must return effects. maybe not?

Dustin Paluch03:03:29

> In fact, it is perfectly valid for an event handler to return an effects map of {}. Slightly puzzling, but not a problem. gottem

p-himik07:03:31

nil should also be fine.

Franklin08:03:15

how do I ensure unhandled errors in subs and events don't cause my application to crash?

p-himik08:03:14

Exceptions in events should not make your app crash. Exceptions in subscriptions are exceptions in views - there are React error boundaries for that, and they will also catch errors within view functions as well. Alternatively, you can write wrappers for reg-event-* and reg-sub that wrap the handling code in try-catch.

Franklin08:03:28

thanks, yeah makes sense... I just realized the component causing the crash is outside my error boundary

πŸ‘ 1
Dustin Paluch14:03:50

I’m wrapping my head around event handlers (`reg-event-*` ) vs effect handlers (`reg-fx`). The latter should be β€œas simple as possible, and then simplify them further. You don’t want them containing any fancy logic.” But the former should contain as much logic as needed to determine what effects need to happen, right?

p-himik14:03:18

> the former should contain as much logic as needed In aggregate, yes - because there's no other place where such logic could be put. But you can still split it into multiple functions and keep on reusing different parts of it. The reason for that statement about reg-fx is because effects are meant to be as reusable as possible. The more logic you put into them (assuming that logic is highly specific and is not applicable to all effects of that kind), the less you can reuse it.

Dustin Paluch14:03:07

Got it. Thank you!

πŸ‘ 1
Dustin Paluch15:03:36

Are these both valid and equivalent effect maps? {:fx [[:dispatch [:do-something-else 3]]]} {:dispatch [:do-something-else 3]}

Dustin Paluch15:03:45

So you would use :fx in order to do more than one :dispatch since you can’t have duplicate map keys. And that also lets you define an order which they will occur in, whether that matters or not.

p-himik15:03:25

Right. But there's also :dispatch-n.

πŸ‘ 1
genRaiy15:03:44

is there anyway to limit the visibility of a component by time eg can I reveal a secret in a pop-up for at most 10 seconds?

genRaiy15:03:49

I'm building a re-com app and cannot find anything directly

p-himik15:03:21

You can use the :dispatch-later effect.

1
genRaiy15:03:16

ah, ok so reset a boolean after n seconds and that will dispose of the modal

πŸ‘ 1
genRaiy15:03:05

this effect was added after I first learned re-frame so it's good to get a chance to use it ::))

E. Kevin Hall M.D.16:03:10

Hi Folks. I've been struggling getting my head around re-frame and haven't found too many online resources giving nice overviews of it. I purchased Jack Schae's great course but the architecture and concepts aren't really explained in my opinion (a lot of "put this here, this goes here".) Anyone have experience with Eric Normand's course? Does he do explain some of the broader concepts behind it within the course? (There's no where to preview any parts of it it seems.) Or perhaps any other good walkthrough resources out there?

p-himik16:03:09

Just to exclude the obvious - have you read the official documentation on re-frame's website?

Daniel Craig16:03:44

I read through this tutorial (same as @U2FRKM4TW is referring to) and really liked it, the concepts are featured prominently

E. Kevin Hall M.D.16:03:53

Ok - thanks guys. I started there but I was turned off by the geophysical weather diagrams. πŸ™‚ I'll re-appraoch. Very kind thanks.

πŸ‘ 2
E. Kevin Hall M.D.00:03:26

Thanks @U2FRKM4TW and @USDPTD3FY for pointing me back there. The docs are indeed very well written. I must just not have been ready in the past.

πŸŽ‰ 2
hairfire18:03:47

I'm using re-pressed to capture a keyup on Enter. Everything works great in Windows 10 for Chrome, Brave and Firefox, but Microsoft Edge does not work. Any thoughts?

p-himik18:03:12

I would try create an MRE with as little higher abstractions as possible. In the process of coming up with such an MRE, it should become clear where the bug is exactly. Given what you describe, chances are it's a bug in Edge, and it might've even been reported already. Or you might have some Edge extension that likes to rob pages of events.

πŸ‘ 1
gadfly36118:03:58

@U44P1CP5K I agree with what @U2FRKM4TW is saying. Under the hood, re-pressed is a very thin wrapper for goog.events.listen and any issues with keypresses not being listened to are probably upstream of re-pressed.

hairfire19:03:07

Got it. Thanks!