-
Notifications
You must be signed in to change notification settings - Fork 442
Description
It can be very useful to know when a stimulus controller has connected, particularly in automated testing environments. While possible to work around this externally, Stimulus is aware of all the needed information, it's just not communicated externally at the moment.
What I would propose is:
-
For each controller element, automatically add a
connectedattribute after the completion ofconnect()for the given controller. This is analogous to how action cable indicates connection, or inversely how busy state is communicated in Hotwire. Since this won't be a custom element, some more thought is warranted here on the final name of the attribute. -
Manage a
fully-connected(name?) attribute on thehtmlelement indicating that all controller elements on the page are connected. This isn't required, but would be nice to have since Stimulus is already listening to all the events/mutations needed to handle this. It would also be very nice to have callbacks/events fired here.
Either or both of these would make is easier and faster for test suites to wait to interact with the page until controllers are connected.
If either of these ideas are acceptable, I'm happy to provide a PR.