@stacksjs/events
Version:
Functional event emitting.
77 lines (46 loc) โข 1.74 kB
Markdown
Functional event emitting.
- Functional event emitting
```bash
bun install -d @stacksjs/events
```
Now, you can use it in your project:
```js
import { all, dispatch, listen, off } from '@stacksjs/events'
// listen to an event
listen('foo', e => console.log('foo', e))
// listen to all events
listen('*', (type, e) => console.log(type, e))
// fire an event
dispatch('foo', { a: 'b' })
// clearing all events
all.clear()
// working with handler references:
function onFoo() {}
listen('foo', onFoo) // listen
off('foo', onFoo) // unlisten
```
To view the full documentation, please visit [<https://stacksjs.com/event>s](https://stacksjs.com/events).
```bash
bun test
```
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
[](https://github.com/stacksjs/stacks/discussions)
For casual chit-chat with others using this package:
[](https://discord.gg/stacksjs)
Many thanks to the following core technologies & people who have contributed to this package:
- [mitt](https://github.com/developit/mitt)
- [Chris Breuer](https://github.com/chrisbbreuer)
- [All Contributors](../../contributors)
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
Made with ๐