-
Notifications
You must be signed in to change notification settings - Fork 825
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already include this feature request, without success.
Describe the Feature Request
Add an ability to check whether the @event decorated property has any event listeners/subscribers.
There is currently no way to check if a callback function was assigned to this event prop.
Describe the Use Case
The original idea was to create a resuable component, containing a conditionally-rendered button as part of the component template outside of <slot>. The button needs to have an onClick action, but since it's inside the template, an @event decorator will be used on <Host> and we link onClick handler with action.emit().
But the conditional rendering has to be done with @Prop() hasAction:boolean
<SomeComponent hasAction={true} onAction={handler}/>
Describe Preferred Solution
A preferred solution would be to be able to check if the action has listeners/callback subscribed and based on that, render or hide the button in the template.
Angular offers this soluton using this.click.observers.length > 0
then the result with button would look like: <SomeComponent onAction={handler}/>
without button: <SomeComponent />
Describe Alternatives
An alternative could be a custom attribute added to the <Host> after rendering, e.g. reflect-event="action", which we could access via elementRef.
On the other hand it can be also done via children inside of , but then wiring between internal logic of and will be harder
Chromium Devtools offers node.eventListeners(); and getEventListeners(node), but of course it's not part of native DOM API.
Related Code
No response
Additional Information
No response