{"name":"@eggjs/eventbus-decorator","version":"1.1.1","keywords":["egg","typescript","eventbus","eventemitter","tegg"],"author":{"name":"killagu","email":"killa123@126.com"},"license":"MIT","_id":"@eggjs/eventbus-decorator@1.1.1","homepage":"https://github.com/eggjs/tegg","bugs":{"url":"https://github.com/eggjs/tegg/issues"},"dist":{"shasum":"18b3d85ef4a876c677f6ad6edfc19b4d3c61f58f","tarball":"http://registry-npm.ywwl.com/@eggjs/eventbus-decorator/download/@eggjs/eventbus-decorator-1.1.1.tgz","fileCount":12,"integrity":"sha512-tj3dW2s3nVOxkkeUYPkIDUk2nwoDAy7Ukt+uqTzj9kWDqnXdDkO5y0o8WrufL0NN5j/7AtnWZmX1e9xCALdrkg==","signatures":[{"sig":"MEUCIQD8OpJcRF2ou/YMPEbW4zkqIa0HmXfXb5eX/yh4umU5zAIgbCW8iilTbvULIMy8c1drt3+3ww2EUVL8OtTRfM3X6a8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJisZadACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp+kxAAlxzQbITfmLTWuDlDtTpyE0lXYCmz6DoCV4eakVVDbwNWOx7n\r\nYjf1I3xlC/20s7i09RyYqmorU7TpwB7BwSaMMc6Q7hADJBdgLl9Y1JvFzptH\r\nANMLyb9ztRYPVw65OLsscyTAVx+s5d2MBkDVHuM39F0U/gypibqmrDicNWz2\r\na3W5GviwgFWuMHF/1Ns5YocYd1lyui04Od4ZWlUNv+hbPT+8fX8Bhuh9HOLB\r\nLfwRdftMJeL1BwHHHeabao3K47752Rw5BUZMGcYLT/i2dFqkgGg6qjjz2ujD\r\nact4sqFK87bKPuHeQIAzcf61Up3mEGqzgvaEfC97/JnwITGTglIlWDUoV/Xo\r\nsj4TCYlOF8eLVBtJ9jtRA8XQXIwKi4at8//yK3HCxYuXlX5su43QAHifJaia\r\nXSjEHUReizPAhtFI0VY7CxKCZ2p6AQn75n8v2IfCpJnIYDFtCb1j5Nez/jPA\r\n9r2cGQUbqDwoeZ2kjG6Db0JO4cWncw5xj6nUwTqEiYzIX+Q/6G547+HZSs4l\r\n9tZCFyJzwH0hppGGKAGPZIt5SBYpWWy+H+uhq6/8CLgQjyCOrQJx6qo+HvQ7\r\nMnUKihQpmA2wbEI5WokHVqVdU1hJki2vnus4s6asjlpUInKoxReVHxkSMbbb\r\n7jIRpx+VwzPwdvW1CBh3/eHBT57KQF/JST4=\r\n=kV3B\r\n-----END PGP SIGNATURE-----\r\n","size":4008,"noattachment":false,"key":"/@eggjs/eventbus-decorator/-/@eggjs/eventbus-decorator-1.1.1.tgz"},"main":"dist/index.js","engines":{"node":">=14.0.0"},"gitHead":"9d4984de5de24ac446d70fe8f5f0108afc160521","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","prepublishOnly":"npm run tsc:pub"},"typings":"dist/index.d.ts","_npmUser":{"name":"killagu","email":"killa07071201@gmail.com"},"repository":{"url":"git+ssh://git@github.com/eggjs/tegg.git","type":"git","directory":"core/eventbus-decorator"},"_npmVersion":"lerna/3.22.1/node@v16.14.2+x64 (darwin)","description":"tegg eventbus decorator","directories":{},"_nodeVersion":"16.14.2","dependencies":{"typed-emitter":"^1.3.1","@eggjs/core-decorator":"^1.1.1","@eggjs/tegg-common-util":"^1.1.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"coffee":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/eventbus-decorator_1.1.1_1655805597599_0.5049667617095908","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":1655805597750,"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":1655805597750,"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"}}