{"name":"@eggjs/eventbus-decorator","version":"4.0.2","keywords":["egg","eventbus","eventemitter","tegg","typescript"],"author":{"name":"killagu","email":"killa123@126.com"},"license":"MIT","_id":"@eggjs/eventbus-decorator@4.0.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":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"644171127@qq.com"},{"name":"elrrrrrrr","email":"elrrrrrrr@gmail.com"},{"name":"niania","email":"ljracm@gmail.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/tegg/core/eventbus-decorator","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"8f2b56c40dd12356306df8bb92aa4a22743298d2","tarball":"http://registry-npm.ywwl.com/@eggjs/eventbus-decorator/download/@eggjs/eventbus-decorator-4.0.2.tgz","fileCount":13,"integrity":"sha512-K+vHEuq+H1z9WgXXFyb3dx5cIiN7Fqk8nW0UuFIfCcyTtK6RL85Mp6krMHghpDfQ6eSkShAPhmcoTjvaj5FAhA==","signatures":[{"sig":"MEUCIAU610vRifT/ec9VJfnWXdpBN2JsA2UF5GSRYXTKlsczAiEArCkeZdsBAnqyk6uFhqWPZc5xHq74w35WFj9rdGrbenA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQCBpb2trf+mp3SErNUahEI52YWu3FNsb7KJhfmHRWp3RQIgGcn1EYKJKEsjMfGILwd5yW54dPzYaRjanNewPs0AvhI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2feventbus-decorator@4.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":11257,"size":3456,"noattachment":false,"key":"/@eggjs/eventbus-decorator/-/@eggjs/eventbus-decorator-4.0.2.tgz"},"type":"module","types":"./dist/index.d.ts","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"gitHead":"cd042a2c1fa06414f4f3290240a92a0e528b24c3","scripts":{"typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"15ec8e86-da37-4207-9623-88d498429224"}},"repository":{"url":"git+https://github.com/eggjs/egg.git","type":"git","directory":"tegg/core/eventbus-decorator"},"_npmVersion":"11.19.0","description":"tegg eventbus decorator","directories":{},"_nodeVersion":"24.21.0","dependencies":{"@eggjs/tegg-types":"4.0.2","@eggjs/core-decorator":"4.0.2","@eggjs/tegg-common-util":"4.0.2"},"publishConfig":{"access":"public","exports":{".":"./dist/index.js","./package.json":"./package.json"}},"_hasShrinkwrap":false,"devDependencies":{"coffee":"5","typescript":"^7.0.2","@types/node":"^24.10.2"},"_npmOperationalInternal":{"tmp":"tmp/eventbus-decorator_4.0.2_1791297260996_0.30839030740600615","host":"s3://npm-registry-packages-npm-production"},"readme":"# `@eggjs/eventbus-decorator`\n\n[![NPM version][npm-image]][npm-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/eventbus-decorator.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/eventbus-decorator.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/eventbus-decorator\n[snyk-image]: https://snyk.io/test/npm/@eggjs/eventbus-decorator/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/@eggjs/eventbus-decorator\n[download-image]: https://img.shields.io/npm/dm/@eggjs/eventbus-decorator.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@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\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\n\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":1791297261089,"_cnpm_publish_time":1791297261089,"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"}}