Fork me on GitHub
#re-frame
<
2023-01-30
>
Ziad Salah18:01:50

Hi all, I have an event naming question please. Let's say that one of the routes in my app shows the user a list of products /products. I want to dispatch an event, X, in which the event handler describes the API call that will be made to retrieve the list of products. It feels wrong to call the event products-requested, because that to me implies that an API request to get the products has been made, when in reality that request is only about to be made. An alternative I have considered is to instead call the event something like products-page-requested or products-page-navigated but that feels a little bit like naming it according to technical concepts rather than domain concepts, and some might feel those event names are too coupled to the view. If I've understood https://ericnormand.me/guide/database-structure-in-re-frame#events, then something like 'request-products' may be appropriate. However, that would upset the 'past-tense for event names' crowd. Thoughts much appreciated!

p-himik18:01:24

> that would upset the 'past-tense for event names' crowd They aren't police, they won't arrest you. :) I usually name my events in the imperative way, :do-stuff.

😂 2
Ziad Salah18:01:42

I'm secretly the 'past-tense for event names' crowd. I take it I should stop self-policing 😄 Thanks for your input!

p-himik18:01:20

IIRC re-frame documentation also suggest naming events in the past tense, so that event IDs describe a thing that happened and not something that should happen. So e.g. :login-form-submit-button-clicked instead of :submit-login-form. But I'm a huge nonfan of that approach.

👍 2
scarytom13:01:43

Naming is hard, but with a little thought we ought to be able to come up with past-tense event names that also avoid using the language of UI interactions or the language of API calls, as @U050P0ACR recommends. In your example Ziad, how about product-data-desired

Ziad Salah14:01:15

I think that can work, yeah. Thanks for the idea :)

valtteri19:01:12

re-frame docs also recommend naming events so that they capture the user intention. In your example the users intent could be to navigate to product page. So in that sense products-page-navigated would make sense. That event could have a (side) effect to get the products from a server.

👍 2