Stimulus Discourse

How to add Even Load Listener to stimulus

Hey guys says i have code snippet like this :slight_smile:
div data-controller=“parent”>
div data-action=“load@document->MY_ACTION”>children /div
div data-action=“load@document->MY_ACTION”>children /div
div

how can i add event load listener to trigger individual action when its children are both loaded given that i dont want to use connect to trigger them all at once, but just want them to be individually instead.
Is that possible/or way of doing it?

Not sure I 100% understand this question… if the children exist when the controller is connected, why wouldn’t you just make the children targets and loop through them on connect()? E.g.

<div data-controller="parent">
  <div data-target="parent.child">...</div>
  <div data-target="parent.child">...</div>
</div>

static targets = ["child"];
connect() { this.childTargets.forEach((target) => { ... }); }