Nationwide Polamorous Matrimony

    This package has been deprecated

    Author message:

    Please use @guanghechen/event-bus instead

    @barusu/event-bus
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.1 • Public • Published

    @barusu/event-bus


    Install

    npm install --save @barusu/event-bus
    • yarn

      yarn add @barusu/event-bus

    Usage

    Examples

    • Basic

      import { SimpleEvent, SimpleEventBus, SimpleEventHandler } from '@barusu/event-bus'
      
      enum EventTypes {
        INIT = 'INIT',
        EXIT = 'EXIT',
      }
      
      const eventBus = new SimpleEventBus<EventTypes>()
      
      const handle: EventHandler<EventTypes> = (evt: SimpleEvent<EventTypes>) => {
        console.log('evt:', evt)
      }
      
      // Listen for specific event
      eventBus.on(EventTypes.INIT, handle)
      
      // Listen for specific event, and only need to be called once
      eventBus.once(EventTypes.INIT, handle)
      
      // Listen for all events
      eventBus.subscribe(handle, true)
      
      // Remove listener
      eventBus.removeEventListener(EventTypes.INIT, handle)
      
      // Remove subscriber
      eventBus.unsubscribe(handle)

    Keywords

    Install

    npm i @barusu/event-bus

    DownloadsWeekly Downloads

    38

    Version

    0.2.1

    License

    MIT

    Unpacked Size

    13.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • lemonclown