@knicola/minibus
v0.1.1
Published
A minibus for a node package
Downloads
5
Maintainers
Readme
@knicola/minibus
A strongly typed event emitter.
Install
Using npm:
$ npm install @knicola/minibus
Using yarn:
$ yarn add @knicola/minibus
Usage
import { minibus, event } from '@knicola/minibus'
// define event schema
interface IUserCreated {
name: string
email: string
}
// register events
const Events = {
UserCreated: event<IUserCreated>('user:created'),
} as const
// create event bus
const bus = minibus()
// subscribe an event handler
bus.subscribe(Events.UserCreated, (data) => {
console.log(data)
})
// dispatch a new event
bus.dispatch(Events.UserCreated, {
name: 'Peter Pan',
email: '[email protected]',
})
License
This project is open-sourced software licensed under the MIT license.