3.39.3 • Published 5 days ago

@eggjs/eventbus-decorator v3.39.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@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');
  }
}

cork events

Cache events in memory until uncork.

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

  bar() {
    this.eventBus.cork();
    // ...do something
    this.eventBus.emit('hello', '01');
    // ...do other things
    
    // emit all cached events
    this.eventBus.uncork();
  }
}

handle event

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

handle multiple event

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

inject event context

inject event context if you want to know which event is being handled. The context param must be the first param

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

6 days ago

3.39.2

5 days ago

3.39.3

5 days ago

3.38.0

15 days ago

3.39.0

15 days ago

3.37.3

17 days ago

3.37.0

17 days ago

3.37.1

17 days ago

3.36.3

24 days ago

3.36.2

25 days ago

3.36.1

27 days ago

3.36.0

1 month ago

3.35.0

1 month ago

3.35.1

1 month ago

3.33.0

1 month ago

3.33.1

1 month ago

3.34.0

1 month ago

3.32.0

2 months ago

3.31.0

3 months ago

3.30.1

3 months ago

3.30.0

4 months ago

3.29.0

4 months ago

3.28.2

5 months ago

3.28.1

5 months ago

3.28.0

5 months ago

3.20.0

8 months ago

3.22.0

8 months ago

3.15.0

9 months ago

3.17.0

8 months ago

3.19.0

8 months ago

3.12.0

10 months ago

3.21.0

8 months ago

3.23.0

8 months ago

3.14.1

9 months ago

3.14.0

9 months ago

3.14.3

9 months ago

3.16.0

8 months ago

3.14.2

9 months ago

3.18.1

8 months ago

3.18.0

8 months ago

3.14.4

9 months ago

3.13.0

9 months ago

3.25.1

6 months ago

3.27.0

5 months ago

3.25.2

6 months ago

3.11.0

10 months ago

3.10.0

10 months ago

3.11.1

10 months ago

3.8.0

11 months ago

3.7.0

1 year ago

3.5.2

1 year ago

3.5.0

1 year ago

3.2.2

1 year ago

3.1.0

1 year ago

3.2.3

1 year ago

1.5.2

1 year ago

3.0.0

1 year ago

3.0.0-alpha.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.0

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.13

2 years ago

0.1.7

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago