A strongly typed event emitter.
Using npm:
$ npm install @knicola/minibus
Using yarn:
$ yarn add @knicola/minibus
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: 'pete@neverland.com',
})
This project is open-sourced software licensed under the MIT license.
Generated using TypeDoc