Svelte: check if parent is listening a custom event

41 Views Asked by At

I have a child component and want to check if any parent is listening to a custom event, so I can do something (e.g. creating a blocking mask for click), is that a way to do it?

Child.svelte:

...
const dispatchEvent = createEventDispatcher<{ click: void }>();
...
{#if $listeners && $listeners.click} <!-- syntax to check if any parent is listening to click event? -->
  <span>Listening to click</span>
{/if}

Parent.svelte:

<Child on:click={...} /> <!-- print "Listening to click" -->
<Child /> <!-- print nothing -->

P.S. I know $$props and $$restProps but they seem not apply to events.

0

There are 0 best solutions below