Fork me on GitHub
#re-frame
<
2021-11-09
>
Wilson Velez02:11:53

If I have a long page with many forms, and each form has more than 10 fields also each form is saved in the app-db like

{:ui {:form-1 {:a "1" :b "2"….}
      :form-2 {:c "3" :d "4"...}
should I create a handler for every field? like [::handler/update-a val] ..`[..handler/update-d val]` or could I have a handler by form? like [::handler/update-form1 val field] and [::handler/update-form2 val field]

lispers-anonymous02:11:30

It's up to you really. I like to have 1 event handler correspond to one component, perhaps a field in this case. If they are handled with similar logic I extract out helper functions and reuse them across event handlers. I like to have the separate events because experience shows me that the logic of the event handlers diverge over time as business requirements change.

Audy16:11:58

I agree here, I tend to try to find handlers that do the same thing and abstract it so other components may be able to use them. But one issue I’ve encountered is that when I come back to the code and its been abstracted multiple times, it does take me longer to parse 🙂 Also if you’re working with a team, sometimes its better to be explicit in those event handlers for better readability.