New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request - Controller registration (load) callback #574
Comments
Updated with another example encountered today for a dark mode button. We need to ensure some code runs as soon as possible (before DOM ready) once we know the identifier used. Also added some 'alternative' work around or approaches. |
Thank you for opening this feature request! I kinda like the idea of having a static |
Maybe Kind of aligns with the existing name |
Yeah, I was also thinking about that. The function which adds a controller to the application is called application.register("hello", HelloController) And this is the function we want the |
Please let me know if this is something you would like to see a PR for. Happy to get one together. |
Please do, I'm happy to get this moving! Thank you! 🙏🏼 |
- when a controller is registered, the `afterLoad` static method, if present, will be called - it gets passed the application instance and the identifier that was used to register it - resolves hotwired#574
- when a controller is registered, the `afterLoad` static method, if present, will be called - it gets passed the application instance and the identifier that was used to register it - resolves hotwired#574
Summary
When a controller is registered (aka loaded), it would be helpful to provide the ability for the controller (class) to be able to provide a callback to know it has been registered and with what identifier.
Details
shoudLoad
static get method can kind of serve this purpose but this has no access to the application instance, nor the identifier string that the controller has been registered with.Example usage - adding support for the controller to bootstrap its own usage for classes triggering
Example usage - side effects before DOM is ready
Alternative approaches
shouldLoad
for side effects - it's good enough for this and works today - except you won't have access to identifier or application.The text was updated successfully, but these errors were encountered: