About attach_hook/4 after callback

Curently it supports :mount, :handle_params, :handle_event , and :handle_info and they are executed before main live view callback. Its all fine for cases, when one needs to validate/authenticate and so on, but if i need to do something after every handle_params, (to calculate active menu page, or just load extra data after main base bulk is loaded) i need to call it manually from every handle_params live view callback.

It would be nice if :mount, :handle_params, :handle_event , and :handle_info would also have after counterparts, for those cases.

Are there some mayor drawbacks for such approach?
How would you do it while there isnt such after hooks?

I find the assigning of nav and page title relevant to the page and/or data, so I have those functions in each liveview. Sometimes it is simply assigning constants and others it is more context aware. There is no context switching involved which I’m a fan of.

I’m not super keen on having something defined at the top of the file that will then change the output of functions down below :person_shrugging:

1 Like

Components are always good for menu state. You can use attach_hook for handle_params to store the params or uri in state then pass that to a menu component which can do the calculation (so long as it’s a pure calculation, of course).