mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Ok so I wasn't as smart as I thought I was. The stimulus controller knows when its element is added/removed from the DOM (and calls connect/disconnect appropriately). But if any child elements are added, they don't automatically have my new event handlers. So I borrowed jQuery's event delegation concept, and listen for any events that 'bubble' up to the controller element, and delegate them as needed. Alternatively, maybe I could have used a Mutation Observer, but I think it's best to avoid where possible. Or of course, we could just revert my change and keep the 'data-action's in the HTML. I'm curious to hear opinions on this.."