An open API service indexing awesome lists of open source software.

https://github.com/alexxnb/svelte-eventbus

Simple eventbus realization based on internal Svelte's tools only
https://github.com/alexxnb/svelte-eventbus

Last synced: about 1 month ago
JSON representation

Simple eventbus realization based on internal Svelte's tools only

Awesome Lists containing this project

README

        

# svelte-eventbus

Simple eventbus realization based on internal Svelte's tools only.

Use when you need handle events from deeply-nested child components without events forwarding.

### Features

* You can set event listeners on `Eventbus` component and catch any event created with `createEventbusDispatcher` in any child component.

* Events are isolated inside of `Eventbus` component instance. You can have more than one `Eventbus` in the parent component. Each will listen events from it's child components only.

* If you have several nested `Eventbus` components, events will bubble through them while needed event listener will be occurred.

### Usage example:

*Parent - App.svelte*

```html

import {Eventbus} from 'svelte-eventbus';
import Child from './Child.svelte';

let totalclicks = 0;

Total clicks: {totalclicks}

totalclicks++}>

```

*Nested - Child.svelte*

```html

import {createEventbusDispatcher} from 'svelte-eventbus';
const dispatch = createEventbusDispatcher();

dispatch('button_click')}>Click
```