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
- Host: GitHub
- URL: https://github.com/alexxnb/svelte-eventbus
- Owner: AlexxNB
- Created: 2020-02-23T19:25:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-30T17:02:09.000Z (10 months ago)
- Last Synced: 2025-04-22T17:03:28.100Z (about 2 months ago)
- Language: JavaScript
- Size: 92.8 KB
- Stars: 38
- Watchers: 2
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
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
```