On_mount callbacks in single module?

The documentation for Phoenix.LiveView.on_mount (Phoenix.LiveView — Phoenix LiveView v0.19.3) says:

Tip: if you need to define multiple on_mount callbacks, avoid defining multiple modules. Instead, pass a tuple and use pattern matching to handle different cases

What is the reason for this recommendation?

I am using the authentication code generated by phx.gen.auth which defines a number of these callbacks in the MyAppWeb.UserAuth module. I also have a couple of other callbacks that I use for audit logging. Should I follow this recommendation and move them all to a single new module?

1 Like

(Many) separate, but small modules can increase compile times. So this is less a recommendation to keep everything in a single module, and more one against having each callback in a separate module.