{"name":"@eggjs/eventbus-decorator","version":"4.0.0-beta.2","keywords":["egg","typescript","eventbus","eventemitter","tegg"],"author":{"name":"killagu","email":"killa123@126.com"},"license":"MIT","_id":"@eggjs/eventbus-decorator@4.0.0-beta.2","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"akitasummer","email":"644171127@qq.com"}],"homepage":"https://github.com/eggjs/tegg","bugs":{"url":"https://github.com/eggjs/tegg/issues"},"dist":{"shasum":"bd52c7a16194ee87652159098243469d64b1ece9","tarball":"http://registry-npm.ywwl.com/@eggjs/eventbus-decorator/download/@eggjs/eventbus-decorator-4.0.0-beta.2.tgz","fileCount":16,"integrity":"sha512-DIhcVvoAe6rdlGbaij18RbOANRpw9EdD2A/Z9UKZnLaLSO20XtmTRRKMQ014FpZRb4Fz34lHmx0EfFSSkfAOEw==","signatures":[{"sig":"MEUCIQC1ml++6UBN+vYG+jhekn80Y0Uf/DiKAZXRwtACmSQzmQIgcvxTcNRqGbCQe6THFt4PBTTHT4RubTX7pHUhGQWoiqM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15502,"size":5525,"noattachment":false,"key":"/@eggjs/eventbus-decorator/-/@eggjs/eventbus-decorator-4.0.0-beta.2.tgz"},"type":"module","engines":{"node":">=20.0.0"},"exports":{".":{"types":"./src/index.d.ts","default":"./src/index.js"}},"gitHead":"7e29d49dcc2eb26909697d5543b3c4f596c9e927","scripts":{"tsc":"npm run clean && tsc -p ./tsconfig.json","clean":"tsc -b --clean","tsc:pub":"npm run tsc","prepublishOnly":"npm run tsc"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git+ssh://git@github.com/eggjs/tegg.git","type":"git","directory":"core/eventbus-decorator"},"_npmVersion":"lerna/6.6.2/node@v22.14.0+arm64 (darwin)","description":"tegg eventbus decorator","directories":{},"_nodeVersion":"22.14.0","dependencies":{"@eggjs/tegg-types":"^4.0.0-beta.2","@eggjs/core-decorator":"^4.0.0-beta.2","@eggjs/tegg-common-util":"^4.0.0-beta.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"coffee":"5","ts-node":"10","typescript":"5","@types/node":"22"},"_npmOperationalInternal":{"tmp":"tmp/eventbus-decorator_4.0.0-beta.2_1741012746336_0.8413277872464333","host":"s3://npm-registry-packages-npm-production"},"readme":"# `@eggjs/eventbus-decorator`\n\n## Usage\n\n### emit event\n\n```ts\nimport { EventBus } from '@eggjs/eventbus-decorator'\n\n// Define event first.\n// Ts can check event and args type for you.\ndeclare module '@eggjs/eventbus-decorator' {\n  interface Events {\n    hello: (msg: string) => Promise<void>;\n  }\n}\n\nclass Foo {\n  @Inject()\n  private readonly eventBus: EventBus;\n\n  bar() {\n    this.eventBus.emit('hello', '01');\n  }\n}\n```\n\n### cork events\n\nCache events in memory until uncork.\n\n```ts\nclass Foo {\n  @Inject()\n  private readonly eventBus: ContextEventBus;\n\n  bar() {\n    this.eventBus.cork();\n    // ...do something\n    this.eventBus.emit('hello', '01');\n    // ...do other things\n    \n    // emit all cached events\n    this.eventBus.uncork();\n  }\n}\n```\n\n### handle event\n\n```ts\n@Event('hello')\nexport class Foo {\n  async handle(msg: string): Promise<void> {\n    console.log('msg: ', msg);\n  }\n}\n```\n\n### handle multiple event\n```ts\n@Event('hello')\n@Event('hi')\nexport class Foo {\n  async handle(msg: string): Promise<void> {\n    console.log('msg: ', msg);\n  }\n}\n```\n\n### inject event context \ninject event context  if you want to know which event is being handled.\nThe context param must be the first param\n\n```ts\n@Event('hello')\n@Event('hi')\nexport class Foo {\n  async handle(@EventContext() ctx: IEventContext, msg: string):Promise<void> {\n    console.log('eventName: ', ctx.eventName);\n    console.log('msg: ', msg);\n  }\n}\n```\n","publish_time":1741012746526,"_cnpm_publish_time":1741012746526,"dist-tags":{"alpha":"3.57.15-alpha.0","beta":"4.0.2-beta.27","beta-v3":"3.74.0-beta.3","latest":"4.1.0","rc":"4.0.2-rc.1"}}