I’m trying to register for a CustomEvent (https://developer.mozilla.org/en-US/docs/DOM/Event/CustomEvent) in Dart. The old code for this was:
window.on['foo'].add((e) => print(e.detail));
The new streams API has changed the way you register for events. How do you register for CustomEvents using the new API?
The idea is that custom events are declared and used the same way as built-in events.
So for a custom event, you’d do something along the lines of:
Then for listening to it on elements:
This will get cleaner once element subclassing is supported and events are normally fired directly on their element, and when event subclassing allows more useful event types for custom events.
We discussed keeping a
window.on['foo'].listen(...)API, but are trying to discourage the string accessors as for some events we polyfill them to different event names.Here’s a more complete example: