We've just run into a situation where a component can not use global state management efficiently, because the list we're using in our component can grow super large. Furthermore, the list doesn't change interactively a lot. So for this special case we decided to use Event Listeners.
The component is not in hierarchy with other components that may lead to a required update of the component, so we can't use $emit
. Looking at https://vuejs.org/guide/components/events#emitting-and-listening-to-events the docs say:
If there is a need to communicate between sibling or deeply nested components, use an external event bus or a global state management solution.
First look went on useEventBus()
from VueUse, but it simply doesn't look like what we need. We don't need any data to provide, instead just a dedicated event to listen for. And we didn't like the DX of the implementation.
Looking for alternatives, we found Mitt: https://github.com/developit/mitt
Which just looks great and is exactly what we expected (and even more with the *
selector - if it should ever be needed ...). So for the future this will be our very simple and smart Event Bus, where State is not the right choice.