@eggjs/eventbus-decorator

tegg eventbus decorator

Usage no npm install needed!

<script type="module">
  import eggjsEventbusDecorator from 'https://cdn.skypack.dev/@eggjs/eventbus-decorator';
</script>

README

@eggjs/eventbus-decorator

Usage

emit event

import { EventBus } from '@eggjs/eventbus-decorator'

// Define event first.
// Ts can check event and args type for you.
declare module '@eggjs/eventbus-decorator' {
  interface Events {
    hello: (msg: string) => Promise<void>;
  }
}

class Foo {
  @Inject()
  private readonly eventBus: EventBus;

  bar() {
    this.eventBus.emit('hello', '01');
  }
}

handle event

@Event('hello')
export class Foo {
  async handle(msg: string): Promise<void> {
    console.log('msg: ', msg);
  }
}