{"name":"@eggjs/eventbus-decorator","version":"0.1.0","keywords":["egg","typescript","eventbus","eventemitter","tegg"],"author":{"name":"killagu","email":"killa123@126.com"},"license":"MIT","_id":"@eggjs/eventbus-decorator@0.1.0","homepage":"https://github.com/eggjs/tegg","bugs":{"url":"https://github.com/eggjs/tegg/issues"},"dist":{"shasum":"22949bcaeec2b9072171aa0d78eadc8a9e7a803c","tarball":"http://registry-npm.ywwl.com/@eggjs/eventbus-decorator/download/@eggjs/eventbus-decorator-0.1.0.tgz","fileCount":12,"integrity":"sha512-mSNcCLtOm6hliAKHEyS5tM2U0cNjoGzAV/IWFLq4UZe82ZiGptu9thKmGkVxcgBcX10ucniQdSj2I6YwTd82kw==","signatures":[{"sig":"MEYCIQDxgm8apLFvaFoTyYdbZkXodS6JU4ylyqLu3DqiXUbLzAIhAJAiebpapnEfnKk/VVaMsg2geVjZ8FtKW6ZmYo1P2JEb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8833,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg+TH/CRA9TVsSAnZWagAAF1sP+wXgYQg8X4ZZWS/OxcMQ\n4iV3PTA9G+HGL26Sz6OzHPYH1xCpZ1Xz1xmlVpHF7Zy9qJHuiNRj/GLe3wjb\nvpE9thMv290ncNRxXbERQVXM76St879ePjfmbgZ0qw9opeubw5cT2Ybrp1zt\nTdsI2Bi+nLEFPGFkTeVvjcQjXSO84LWVB/Zy4WFbJCSvBUkFhbNJgorQ7zhI\n7x4ExeaSl05Jx6o43vEG9okFLT9qUTMybcb4SYCdDh7mzhlRsCtnm+yarZL9\n86StnX+Fnqwcpz5abEqfgpnsOgfA5/eVIw8HKaDYuC0Or7Ao3DGw2S77qpFS\nwCTFgleZF0xEosHPo3A/v8xMuiujQRklPinrS/gvn0AqYZWB5AX+WXXNULY0\nivLuy+RUscX8i0KpLXqPU40uJAXBYlcYrQudDkWvm/iQ8yXaM7uKrk55s8Nj\ntIo7U7RjK9rdcWPxmwh6fIEsTkyv7yCjK3K6ROknn8iVAablgi3cp/sPhPi8\nrXO7LM7Np71TLAa8hgl9Z+hVOVBqRxJBNIcPfa7CnFa8C6G5iN6j7nia35zn\ntPYd4d/u0UYEdR0+guhkdAZp4g+EwdA1Gg98mSfVKXOkkm30upVPvFwUWOhS\nnBmNx5s2CxyMJBX8C0m8e/IA/VetXVm+uU5pHJSTim+rcxYGH/WsjqQHe7Ne\nOsc9\r\n=ZY1l\r\n-----END PGP SIGNATURE-----\r\n","size":3918,"noattachment":false,"key":"/@eggjs/eventbus-decorator/-/@eggjs/eventbus-decorator-0.1.0.tgz"},"main":"dist/index.js","engines":{"node":">=14.0.0"},"gitHead":"ba2e9ba8be6ed7d4e8e56b1bb77950588243179c","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":"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@v14.16.0+x64 (darwin)","description":"tegg eventbus decorator","directories":{},"_nodeVersion":"14.16.0","dependencies":{"typed-emitter":"^1.3.1","@eggjs/core-decorator":"^0.1.0","@eggjs/tegg-common-util":"^0.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"coffee":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/eventbus-decorator_0.1.0_1626943998985_0.10994903828126379","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":1626943999128,"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":1626943999128,"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"}}