{"name":"@eggjs/eventbus-decorator","version":"0.1.7","keywords":["egg","typescript","eventbus","eventemitter","tegg"],"author":{"name":"killagu","email":"killa123@126.com"},"license":"MIT","_id":"@eggjs/eventbus-decorator@0.1.7","homepage":"https://github.com/eggjs/tegg","bugs":{"url":"https://github.com/eggjs/tegg/issues"},"dist":{"shasum":"689bee271291a923ffd941de9fc638398b9863d2","tarball":"http://registry-npm.ywwl.com/@eggjs/eventbus-decorator/download/@eggjs/eventbus-decorator-0.1.7.tgz","fileCount":12,"integrity":"sha512-X5z04vDV4NLCeiIaUkv6VsCptrf5UzAiNzNABA/WKONvUMLgKinaZ3TsYnXnqnnf9AICqxOt9/nx+SfCYmeSvw==","signatures":[{"sig":"MEUCIQDKF5FXv41eVJOsCurPD5Hb3kHNm47AvR1pvYk0KhuMhwIga4177TAtbICTxnJIjlw7I8kkQhJ7i3LMbrhCuiT8iDs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8869,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhPrjfCRA9TVsSAnZWagAAoaMP/39PEyKJFPu8SusX3NYQ\nJRQsqHrNFQOkFLWX89GiXQgXnxGYtKyS9GICYYQksVuBwNcflBHfsrKlI1E4\n45rb6lNZw/UGTH9IjZXjHgDx4l1F+DSIRRqW4UOkk0VEkfD0WKsoSw37Tmvd\nN9P4bX13J7PLoEqAWoN4IZ8IcJfxYoNrXr0+Mz30Ajc29K48xGyK2QsD2ZdS\nRyBaTyRg/3I3StJ2UbXF1PCUn/5VK2Oijn5+xfqCn4Gc+MA/Hnd3hDCqVUKp\n2LW66IMPzeha1xFES/ivVIy+41Ui1SVCY5RioWuqobSgRmli2SX0bpX9REpZ\nOoNliFSgHGGbtfv1VwYjAS+QsN+XcO36ha6uLdmGOn0l83ZFLzYpwC7q4YQA\nn9wttASvCGO+r3KKMkEMVxKUr7xI0l90gG0jDbj6Z3vmwdAl0ZGbSQ1/OkbO\nhyKD1lSJ0kxcE3bAku0Dc+NgJJaTZXV6+zrs3qnPw+CsuDco7GT34aa6Bnh0\nWjPLlX29MRycYhZpxqUrKCSFA/IR5z/TEjedY4/0FKnr97Y2M8Skga8SVz7m\nO7ffgn4FbvQ/xbq5tOJdalV/mf7DSxg3YjqiDuD5Jfj0arDjqo7DnljyGo9G\nQ+LkQ+o46L9yu7Y1H72fIG6Ea5e9vl36lrtlVDLsf7BYkbL4f5+m+S85M2kd\nptjG\r\n=5Rqw\r\n-----END PGP SIGNATURE-----\r\n","size":3941,"noattachment":false,"key":"/@eggjs/eventbus-decorator/-/@eggjs/eventbus-decorator-0.1.7.tgz"},"main":"dist/index.js","engines":{"node":">=14.0.0"},"gitHead":"e005a240b5021f8d7b0e7a3de5076cc2acfc5d44","scripts":{"ci":"npm run lint && npm run cov","tsc":"npm run clean && tsc -p ./tsconfig.json","autod":"autod","clean":"tsc -b --clean","tsc:pub":"npm run clean && tsc -p ./tsconfig.pub.json","prepublish":"npm run tsc:pub"},"typings":"dist/index.d.ts","_npmUser":{"name":"wanghx","email":"whxaxes@gmail.com"},"repository":{"url":"git+ssh://git@github.com/eggjs/tegg.git","type":"git","directory":"core/eventbus-decorator"},"_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (darwin)","description":"tegg eventbus decorator","directories":{},"_nodeVersion":"12.18.3","dependencies":{"typed-emitter":"^1.3.1","@eggjs/core-decorator":"^0.1.5","@eggjs/tegg-common-util":"^0.1.5"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"coffee":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/eventbus-decorator_0.1.7_1631500511367_0.8621260472389625","host":"s3://npm-registry-packages"},"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":1631500511507,"maintainers":[{"name":"akitasummer","email":"644171127@qq.com"},{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"gemwuu","email":"gemwuu@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"}],"_cnpm_publish_time":1631500511507,"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"}}