Problem with the directive when migrating to Vue 3

Hey guys!
When migrating from Vue 2 to Vue 3, I faced the necessity to rewrite custom directives. One of them has these lines of code:

if (binding.modifiers['v-event'] && vnode.componentInstance) {
  vnode.componentInstance.$on(type, handlers[type])
} else el.addEventListener(type, handlers[type], false)

These lines are used to subscribe to custom events (“my-event”) if a directive is defined on a component and to ordinary events if a directive is defined on an html element.

In Vue 3, $on, $off and $once were removed.
Now I am confused about how I can catch a custom event when my directive is defined on a component.

Do you have any ideas about this?

Update:
I checked the sources of Vue and realized that now custom events are just a call of the handler function that is defined on the component.
Is there a way to subscribe to all generated custom events of the component in the directive? Could there be some kind of hook? Maybe it is in plans?