Parent controllers is listening to actions within child controllers
See original GitHub issueI have asked in https://discourse.stimulusjs.org/t/is-it-intentional-that-parent-controllers-also-listens-to-actions-within-child-controller/1127 and told to file a bug report here.
Hi 👋,
Using example from https://stimulusjs.org/reference/actions#global-events, let say I have the following controllers nested like below:
<div data-controller="gallery">
<div data-controller="gallery"
data-action="resize@window->gallery#layout">
…
</div>
</div>
I found out that the parent gallery
controller is also listening to the child action. The example above will fires gallery#layout
twice when the window is resized.
Here is another example in https://codepen.io/javan/pen/JjYMYKO?editors=1010, thanks to @javan 👍 .
FYI, I’m using Stimulus 1.1.1.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
How to bind an action to a parent event? - Hotwire Discussion
In your parent controller, when you dispatch the event, you can specify the child element via the associated target, and the child element ......
Read more >How to properly destroy a child UIViewController?
I have my mainController (parent) and my menuController (child). I call the menuController with addChild(child) view.addSubview(child.view) child.
Read more >angularjs - Parent Controller listen to event from child controller
I have a parent shell html file that has an icon to update the number of products in the cart. The number is...
Read more >Rob Zolkos on Twitter: "For bubbling up custom events in ...
For bubbling up custom events in Stimulus controllers, emit a new event. Then in a parent controller listen for it eg data-action='user-added->user#save' ...
Read more >Child View Controllers in Swift 5 (Xcode 11, 2020) - iOS
In this video we will learn about child view controllers in swift 5 and xcode 11. We will look at combining them to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@javan I think this issue is partially corrected and should be reopened. I have been using custom events to communicate between controllers and I think I encountered another version of this issue
Here is a codepen to demonstrate https://codepen.io/adrienpoly/pen/gOwGpvL?editors=1011
clicking on
level 1
is expected to only triggers theanimate#fadeIn
function in the inner controller but it does also triggers the outer controller 😢.HTML
JS
I think this is a failing test