@knicola/minibus
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@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: 'pete@neverland.com',
})

License

This project is open-sourced software licensed under the MIT license.

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i @knicola/minibus

    Weekly Downloads

    0

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    14.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • knicola