Stimulus Discourse

Does stimulus listen for dom changes?


#1

As stated in the title. Can I just add a dom node with a controller specified and expect it to work, or do I need to inform stimulus that the dom has changed? What if the adding of a new node happens in a controller’s action?


#2

Stimulus listens to changes in the DOM. If a sub-element within the controller’s sub-DOM gets added, and it’s described with data-action or data-target attributes that match the controller’s, those will automatically work with the controller (actions will fire the controller’s methods, the new object will be registered with the controller’s targets).

You can even add elements that are controlled by another controller, and those will be hooked up automatically too.

Your sub elements can even be have actions that are associated with two or more controllers, and be targets registered with two or more controllers.


#3

It doesn’t matter how or when your HTML arrives. Stimulus connects it.