Skip to content

Conversation

xmo-odoo
Copy link
Contributor

Currently the event bus allows sending and listening to arbitrary events, I got got by that when I pushed a fix using addEventListener on a bus across an events renaming, and on the other side the fix did nothing anymore. Entirely my fault, but if the list of events sent on a bus is known and documented (e.g. a jsdoc has @emits tags) it would make sense for both the listening and the dispatching to also be validated.

This proposal performs validation only when the eventbus is created:

  • in dev mode (which also requires being in a component context)
  • if an iterable of events is passed to the ctor

The dev-mode check might be overkill but it seems like a good idea at least for an initial version, as the validation does have a cost however low, and validation errors can occur essentially anywhere.

Currently the event bus allows sending and listening to arbitrary
events, I got got by that when I pushed a fix using `addEventListener`
on a bus across an events renaming, and on the other side the fix did
nothing anymore. Entirely my fault, but if the list of events sent on
a bus is known and documented (e.g. a jsdoc has `@emits` tags) it
would make sense for both the listening and the dispatching to also be
validated.

This proposal performs validation only when the eventbus is created:

- in dev mode (which also requires being in a component context)
- if an iterable of events is passed to the ctor

The dev-mode check might be overkill but it seems like a good idea at
least for an initial version, as the validation does have a cost
however low, and validation errors can occur essentially anywhere.
@xmo-odoo xmo-odoo force-pushed the eventbus-events-validation branch from 76792d4 to 9edd31f Compare September 12, 2025 12:09
@xmo-odoo
Copy link
Contributor Author

Erf there's a circular dependency between utils and component_node, not sure what the best way to handle it would be:

  • forget about the dev stuff, the opt in is probably sufficient to make this safe, and users of EventBus can always check the dev mode on their side and only pass in the events list if it's true (getCurrent and ComponentNode are the cause of needing component_node)
  • move EventBus outside of utils (not very onerous since it's used nowhere inside owl itself)
  • ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant