Simple eventbus realization based on internal Svelte's tools only
The svelte-eventbus is a simple eventbus realization that is based on internal Svelte tools only. This eventbus allows developers to handle events from deeply-nested child components without the need for events forwarding.
To install the svelte-eventbus theme, you can follow these steps:
npm install svelte-eventbus
or
yarn add svelte-eventbus
import { Eventbus, createEventbusDispatcher } from 'svelte-eventbus';
// Parent component - App.svelte
<script>
import { Eventbus } from 'svelte-eventbus';
</script>
<div>
<!-- Eventbus component -->
<Eventbus />
<!-- Child component -->
<Child />
</div>
// Child component - Child.svelte
<script>
import { createEventbusDispatcher } from 'svelte-eventbus';
const dispatch = createEventbusDispatcher();
</script>
<div>
<button on:click={() => dispatch('event:example')}>
Click me
</button>
</div>
The svelte-eventbus is a simple and efficient eventbus tool for Svelte developers. It allows for easy event handling from deeply-nested child components without the need for events forwarding. With its ability to isolate events within specific Eventbus instances, developers have flexibility in managing events within their app. The eventbus also supports event bubbling, ensuring that events reach the appropriate event listeners.