{"_id":"@ai-zen/event-bus","_rev":"9-d94c282e4e41b5396c7fc27477b2598f","name":"@ai-zen/event-bus","description":"EventBus is a simple event management library for TypeScript.","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.1":{"name":"@ai-zen/event-bus","version":"1.0.1","keywords":["event","event-bus","event bus"],"author":{"name":"刘自强"},"license":"MIT","_id":"@ai-zen/event-bus@1.0.1","maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"dist":{"shasum":"bcff3c817a24c7b40d85d6c139a1fd9ac9cfb0e3","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.0.1.tgz","fileCount":9,"integrity":"sha512-toCOVAMFKR5e5pavc6fG/7HrBJmcSovFq+pAtzjc8gIK9/1rKRGz9sDG1CJtEWC7fLaR0AHAfBCH5zz7zQIROA==","signatures":[{"sig":"MEQCIFG0JL+Uvu35B61LwbYcdCDHUEjOgex7XVTr9dVLBR3zAiBq/8yVDZVWr2ZpVP0QQMwXgDsnLgBMZ7AteJou5JbjiA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13209,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgPSWJCRA9TVsSAnZWagAA+SgP/2J3Hz67SwNyWIlBozDl\ncIo2JHm6C73i2igFxoT8V+fl9IO2MLq1wMwz7exgs08Vgtuq4/HMwzZeruOt\nVvaOOMBUzubDCVVF7rPchmhpheiWnMG5V8FtxeSHDRAtagquADktbij9aArI\nbW8sfEGJ4I/k4CxLsyxs81K6gSCmSNJzY3xK9ycZqBv2Y+LsjD3PIEQVFqEc\n98YL9bxP1avq80SoIiiX0sg+pjh2M5ZWVmEx2nwWkgtGVWeNIFA+/JoFfOCc\nBjgK22yHcDCP6r0HrsNRjRCTZggWBM/WimgVNQV9p1qOiFrKv66FSWjA6pKn\ncXDi3cE6+2l6lpaVfMt2D3JdgCBd0JOYGXeDccBur2m4Tt5Rg7SOxCnX6cjy\n6GaUG4K0fNpyKDWZptXUggj6BtQm0b0SfjsPvIbEt86Oo6Myj4911/XAyI/S\nDzEbfD/tx6bXVTp1MdSEJ9Pn5vQzCzMGe25h8bdR+7lAqdelbK9vALKXvY+8\nVOVQxeDTb2iRVMZVeczIIEoLgvffhxYE2IkWeCkEpEzm7ulQfjskgdkL9Itu\nXPo75yHh+Reok980v6E6HfVJW2fm5xKt1NJPysAxczQ+oRKOC2D3GhiIOBTh\npSF9wQ7IJ+yfxKyQSREqGafPWqsPiRYRsPFGcV9p6yqf055bJLkiTeVFDYbX\nso4W\r\n=glEg\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/EventBus.js","type":"module","gitHead":"24cc3c5733091db3c91d67b9f33922f0358bdc59","scripts":{"test":"npm run build & node ./test/test.js","build":"tsc"},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"repository":{"url":"git+https://github.com/ai-zen/event-bus.git","type":"git"},"_npmVersion":"6.14.7","description":"A simple JavaScript library for managing events.","directories":{},"_nodeVersion":"14.7.0","eslintConfig":{"env":{"node":true},"root":true,"parser":"@typescript-eslint/parser","extends":["eslint:recommended","plugin:@typescript-eslint/recommended"],"plugins":["@typescript-eslint"]},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^7.21.0","typescript":"^4.2.2","@typescript-eslint/parser":"^4.15.2","@typescript-eslint/eslint-plugin":"^4.15.2"},"_npmOperationalInternal":{"tmp":"tmp/event-bus_1.0.1_1614620037978_0.7025820455014535","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@ai-zen/event-bus","version":"1.0.2","keywords":["event","event-bus","event bus"],"author":{"name":"LZQCN"},"license":"MIT","_id":"@ai-zen/event-bus@1.0.2","maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"dist":{"shasum":"51937924020fd96f25e28bd2f7c0f78355bcd6d8","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.0.2.tgz","fileCount":12,"integrity":"sha512-oMH2dW4uSNAVBUmSwUEg0tEv4EgnOlTRualEu7xeLP36ObZdYjQtuENr/GLnPWXrGkDM4yPQLuW/kXvavSMvtA==","signatures":[{"sig":"MEQCICIVLUsKAYBHaHbzFfp4V19FvXakGxqM0s9Y5teVIXP0AiBMqQcdGlp/eQ+dN82PYzEyI2z5NzE1Q+lS7qMzKkHzkw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17588},"main":"dist/EventBus.js","type":"module","_from":"file:ai-zen-event-bus-1.0.2.tgz","types":"dist/EventBus.d.ts","scripts":{"test":"npm run build && NODE_OPTIONS=--experimental-vm-modules jest","build":"tsc","clean":"rimraf ./dist","prebuild":"npm run clean"},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"_resolved":"/tmp/47f0b87f80e7d4ae06c0f956d075a051/ai-zen-event-bus-1.0.2.tgz","_integrity":"sha512-oMH2dW4uSNAVBUmSwUEg0tEv4EgnOlTRualEu7xeLP36ObZdYjQtuENr/GLnPWXrGkDM4yPQLuW/kXvavSMvtA==","repository":{"url":"git+https://github.com/ai-zen/event-bus.git","type":"git"},"_npmVersion":"9.6.7","description":"EventBus is a simple event management library for TypeScript.","directories":{},"_nodeVersion":"20.3.0","dependencies":{"rimraf":"^5.0.5"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29","typescript":"^5.3.3","@types/jest":"^29","@jest/globals":"^29"},"_npmOperationalInternal":{"tmp":"tmp/event-bus_1.0.2_1709622153687_0.25459629685413043","host":"s3://npm-registry-packages"}},"1.0.3":{"name":"@ai-zen/event-bus","version":"1.0.3","keywords":["event","event-bus","event bus"],"author":{"name":"LZQCN"},"license":"MIT","_id":"@ai-zen/event-bus@1.0.3","maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"dist":{"shasum":"620fb5fe727bbafef2e72e5101fa1055520a639b","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.0.3.tgz","fileCount":12,"integrity":"sha512-AclYdRhUuDZbeezFZLE6956MppSDiACXjCaIyjozDXUoJ4A/qIfSSzCRYL4qvqo25i7S2Jhv70uXnUDsKvI1RA==","signatures":[{"sig":"MEUCIBxZ0X0KpOGphQPAAN8hYPmC5ocWhxfrH13/1KiuNTKXAiEAvh2oEvmi5mfvuLpt0DFIKTH7O+GXRxmQXQGExqGUwnA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17611},"main":"dist/EventBus.js","type":"module","types":"dist/EventBus.d.ts","gitHead":"1e13ccf163277d14fbbc7cd1154af74ac4c82d32","scripts":{"test":"npm run build && NODE_OPTIONS=--experimental-vm-modules jest","build":"tsc","clean":"rimraf ./dist","prebuild":"npm run clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"repository":{"url":"git+https://github.com/ai-zen/event-bus.git","type":"git"},"_npmVersion":"9.6.7","description":"EventBus is a simple event management library for TypeScript.","directories":{},"_nodeVersion":"20.3.0","dependencies":{"rimraf":"^5.0.5"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29","typescript":"^5.3.3","@types/jest":"^29","@jest/globals":"^29"},"_npmOperationalInternal":{"tmp":"tmp/event-bus_1.0.3_1709622374214_0.6034092246381824","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"@ai-zen/event-bus","version":"1.0.4","keywords":["event","event-bus","event bus"],"author":{"name":"LZQCN"},"license":"MIT","_id":"@ai-zen/event-bus@1.0.4","maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"dist":{"shasum":"6f84b69aad771df8de84756c563ef66d77205513","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.0.4.tgz","fileCount":7,"integrity":"sha512-27mmr0mTcfEhuvFB1WxvdHHrLYlMxGXpqj2u4RyrM1yoN1HWeC1VnXAGlKBFJmyPlpXCKjCivwwSGQEioLTptA==","signatures":[{"sig":"MEYCIQC52EwxYQP1lr7X6f0gdIu2QbfujZqGwAGka/WppPy77AIhALKVu8DSQzpYgHo0eSrIpjuPf0xNnZegZFmVqMJ0Su5C","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13826},"main":"dist/EventBus.js","type":"module","types":"dist/EventBus.d.ts","gitHead":"65a4c06abd500f00eff976198aac60a88bc72f3c","scripts":{"test":"npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest","build":"tsc","clean":"rimraf ./dist","prebuild":"npm run clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"repository":{"url":"git+https://github.com/ai-zen/event-bus.git","type":"git"},"_npmVersion":"10.1.0","description":"EventBus is a simple event management library for TypeScript.","directories":{},"_nodeVersion":"20.8.0","dependencies":{"rimraf":"^5.0.5"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29","cross-env":"^7.0.3","typescript":"^5.3.3","@types/jest":"^29","@jest/globals":"^29"},"_npmOperationalInternal":{"tmp":"tmp/event-bus_1.0.4_1712236873052_0.5043606533753235","host":"s3://npm-registry-packages"}},"1.0.5":{"name":"@ai-zen/event-bus","version":"1.0.5","keywords":["event","event-bus","event bus"],"author":{"name":"LZQCN"},"license":"MIT","_id":"@ai-zen/event-bus@1.0.5","maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"dist":{"shasum":"7764379e594137131eaa8e40db346c971b7ed390","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.0.5.tgz","fileCount":7,"integrity":"sha512-KZ8e5sD2YkrDFvsJYpGbGS8Md6E41HMgnw5nzUbQixx3E7i84SjlkK31wjSv654xqhEpK9JpZVu7fRz0yB0QzQ==","signatures":[{"sig":"MEUCICp+dpIEhjPx2FSU5Q0IP0DdnLJRrWGHESVSHD4P0ZpNAiEAg5ky1frREhdKCOim5LB1U75kV7UMuC2f4IHOwySCAuM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13763},"main":"dist/EventBus.js","type":"module","_from":"file:ai-zen-event-bus-1.0.5.tgz","types":"dist/EventBus.d.ts","scripts":{"test":"npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest","build":"tsc","clean":"rimraf ./dist","prebuild":"npm run clean"},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"_resolved":"/tmp/622a9b5b62c2eaaa0b6633e0c1856c95/ai-zen-event-bus-1.0.5.tgz","_integrity":"sha512-KZ8e5sD2YkrDFvsJYpGbGS8Md6E41HMgnw5nzUbQixx3E7i84SjlkK31wjSv654xqhEpK9JpZVu7fRz0yB0QzQ==","repository":{"url":"git+https://github.com/ai-zen/event-bus.git","type":"git"},"_npmVersion":"9.6.7","description":"EventBus is a simple event management library for TypeScript.","directories":{},"_nodeVersion":"20.3.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29","rimraf":"^5.0.5","cross-env":"^7.0.3","typescript":"^5.3.3","@types/jest":"^29","@jest/globals":"^29"},"_npmOperationalInternal":{"tmp":"tmp/event-bus_1.0.5_1713754082837_0.4318398434144419","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@ai-zen/event-bus","version":"1.1.0","description":"EventBus is a simple event management library for TypeScript.","main":"dist/EventBus.js","types":"dist/EventBus.d.ts","type":"module","repository":{"type":"git","url":"git+https://github.com/ai-zen/event-bus.git"},"keywords":["event","event-bus","event bus"],"author":{"name":"LZQCN"},"license":"MIT","devDependencies":{"@jest/globals":"^29","@types/jest":"^29","cross-env":"^7.0.3","jest":"^29","typescript":"^5.3.3","rimraf":"^5.0.5"},"scripts":{"clean":"rimraf ./dist","prebuild":"npm run clean","build":"tsc","test":"npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest"},"bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"homepage":"https://github.com/ai-zen/event-bus#readme","_id":"@ai-zen/event-bus@1.1.0","_integrity":"sha512-xjfQEmUMly++dOSrQMJkwrnBVl7bQHtiw8S09AW5jPuqnFV9OwBk0PsGFc/T+4eP4yWThBJo2X3cCdE5DkAr+Q==","_resolved":"C:\\Users\\bylzq\\AppData\\Local\\Temp\\12902b3f3f6678a6f8363cb6ad67331c\\ai-zen-event-bus-1.1.0.tgz","_from":"file:ai-zen-event-bus-1.1.0.tgz","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-xjfQEmUMly++dOSrQMJkwrnBVl7bQHtiw8S09AW5jPuqnFV9OwBk0PsGFc/T+4eP4yWThBJo2X3cCdE5DkAr+Q==","shasum":"a8655bf5e3bbbdc3156d137ceafee0baea3d83cb","tarball":"https://registry.npmjs.org/@ai-zen/event-bus/-/event-bus-1.1.0.tgz","fileCount":7,"unpackedSize":21860,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCW3Ge9d70CwIzBnP3LDqjSo1yaZsVnJuslsYW0LDzj7gIgP1g2dMV1mysMCRq4GJGDuZbkqqtkfSm5UCt9+lSKHVM="}]},"_npmUser":{"name":"lzqcn","email":"by.lzq@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/event-bus_1.1.0_1719161897154_0.15844645613944275"},"_hasShrinkwrap":false}},"time":{"created":"2021-03-01T17:33:57.688Z","modified":"2024-06-23T16:58:17.514Z","1.0.0":"2021-03-01T17:23:42.834Z","1.0.1":"2021-03-01T17:33:58.128Z","1.0.2":"2024-03-05T07:02:33.827Z","1.0.3":"2024-03-05T07:06:14.355Z","1.0.4":"2024-04-04T13:21:13.218Z","1.0.5":"2024-04-22T02:48:02.998Z","1.1.0":"2024-06-23T16:58:17.301Z"},"maintainers":[{"name":"lzqcn","email":"by.lzq@qq.com"}],"author":{"name":"LZQCN"},"repository":{"type":"git","url":"git+https://github.com/ai-zen/event-bus.git"},"keywords":["event","event-bus","event bus"],"license":"MIT","homepage":"https://github.com/ai-zen/event-bus#readme","bugs":{"url":"https://github.com/ai-zen/event-bus/issues"},"readme":"# EventBus\r\n\r\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\r\n\r\nEventBus is a simple event management library for TypeScript.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @ai-zen/event-bus\r\n```\r\n\r\n## Usage\r\n\r\n```javascript\r\nimport EventBus from \"@ai-zen/event-bus\";\r\n\r\n// Create a new instance of EventBus\r\nconst eventBus = new EventBus();\r\n\r\n// Subscribe to an event\r\neventBus.on(\"eventName\", (arg1, arg2) => {\r\n  // Handle the event\r\n});\r\n\r\n// Unsubscribe from an event\r\neventBus.off(\"eventName\", handler);\r\n\r\n// Unsubscribe from all handlers of an event\r\neventBus.offAll(\"eventName\");\r\n\r\n// Destroy the event bus and remove all event subscriptions\r\neventBus.destroy();\r\n\r\n// Emit an event\r\neventBus.emit(\"eventName\", arg1, arg2);\r\n\r\n// Gather the results returned by all handlers of an event\r\nconst results = eventBus.gather < T > (\"eventName\", arg1, arg2);\r\n\r\n// Gather the results returned by all handlers of an event as a map\r\nconst resultsMap = eventBus.gatherMap < T > (\"eventName\", arg1, arg2);\r\n\r\n// Subscribe to an event and automatically unsubscribe after the first invocation\r\neventBus.once(\"eventName\", (arg1, arg2) => {\r\n  // Handle the event\r\n});\r\n\r\n// Subscribe to an event and return a promise that resolves when the event is emitted\r\nconst resultPromise = eventBus.promise(\"eventName\");\r\n```\r\n\r\n## API\r\n\r\n### `on(name: string, handler: EventHandler, error?: ErrorHandler): Disposable`\r\n\r\nSubscribes to an event.\r\n\r\n- `name` (required): The name of the event to subscribe to.\r\n- `handler` (required): The event handler function.\r\n- `error` (optional): The error handler function.\r\n- Returns: A Disposable object that can be used to unsubscribe from the event.\r\n\r\n#### Example\r\n\r\n```javascript\r\nconst disposable = eventBus.on(\"eventName\", (arg1, arg2) => {\r\n  // Handle the event\r\n});\r\n\r\n// Unsubscribe from the event\r\ndisposable.dispose();\r\n```\r\n\r\n### `off(name: string, handler: EventHandler): boolean`\r\n\r\nUnsubscribes from an event.\r\n\r\n- `name` (required): The name of the event to unsubscribe from.\r\n- `handler` (required): The event handler function.\r\n- Returns: True if the unsubscribing was successful, otherwise false.\r\n\r\n### `offAll(name: string): void`\r\n\r\nUnsubscribes all event handlers from an event.\r\n\r\n- `name` (required): The name of the event to unsubscribe all handlers from.\r\n\r\n### `destroy(): void`\r\n\r\nDestroys the event bus by clearing all event subscribers.\r\n\r\n### `emit(name: string, ...args: any[]): void`\r\n\r\nEmits an event.\r\n\r\n- `name` (required): The name of the event to emit.\r\n- `args` (optional): The arguments to pass to the event handlers.\r\n\r\n### `error(name: string, reason: any): void`\r\n\r\nThis method is used to send an error event through the event bus.\r\n\r\n- `name` (required): The name of the error event to be sent.\r\n- `reason` (required): The reason for the error.\r\n\r\n#### Example\r\n\r\n```javascript\r\ntry {\r\n  // Do something that might throw an error\r\n  const data = await getData();\r\n  eventBus.emit(\"fooEvent\", data);\r\n} catch (error) {\r\n  eventBus.error(\"fooEvent\", error); // Send an error event\r\n}\r\n```\r\n\r\n```javascript\r\n// Use the error handler function for eventBus.on\r\neventBus.on(\r\n  \"fooEvent\",\r\n  (data) => {\r\n    // Handle the data\r\n  },\r\n  (error) => {\r\n    // Handle the error\r\n  }\r\n);\r\n\r\n// You can also use a promise catch to handle the error\r\neventBus.promise(\"fooEvent\").catch((error) => {\r\n  // Handle the error\r\n});\r\n```\r\n\r\n### `gather<T>(name: string, ...args: any[]): T[]`\r\n\r\nGathers the results from all event handlers of the specified event.\r\n\r\n- `name` (required): The name of the event to gather results from.\r\n- `args` (optional): The arguments to pass to the event handlers.\r\n- Returns: An array of results from all event handlers.\r\n\r\n### `gatherMap<T>(name: string, ...args: any[]): Map<EventHandler, T>`\r\n\r\nGathers the results from all event handlers of the specified event with a map of the handlers.\r\n\r\n- `name` (required): The name of the event to gather results from.\r\n- `args` (optional): The arguments to pass to the event handlers.\r\n- Returns: A map of event handlers and their corresponding results.\r\n\r\n### `once(name: string, handler: EventHandler, error?: ErrorHandler): Disposable`\r\n\r\nSubscribes to an event and unsubscribes automatically after the event is emitted once.\r\n\r\n- `name` (required): The name of the event to subscribe to.\r\n- `handler` (required): The event handler function.\r\n- `error` (optional): The error handler function.\r\n- Returns: A Disposable object that can be used to unsubscribe from the event.\r\n\r\n#### Example\r\n\r\n```javascript\r\nconst disposable = eventBus.once(\"eventName\", (arg1, arg2) => {\r\n  // Handle the event\r\n});\r\n\r\n// The handler will be automatically unsubscribed after the first invocation\r\n```\r\n\r\n### `promise(name: string): Promise<any>`\r\n\r\nReturns a promise that resolves when the specified event is emitted.\r\n\r\n- `name` (required): The name of the event to create a promise for.\r\n- Returns: A promise that resolves when the event is emitted.\r\n\r\n#### Example\r\n\r\n```javascript\r\nconst resultPromise = eventBus.promise(\"eventName\");\r\n\r\nresultPromise.then((result) => {\r\n  // Handle the result\r\n});\r\n```\r\n\r\n### `subscribe(name: string, handler: EventHandler): void`\r\n\r\nAlias for the `on` method.\r\n\r\n### `unsubscribe(name: string, handler: EventHandler): boolean`\r\n\r\nAlias for the `off` method.\r\n\r\n### `publish(name: string, ...args: any[]): void`\r\n\r\nAlias for the `emit` method.\r\n\r\n## License\r\n\r\n[MIT](LICENSE)\r\n","readmeFilename":"README.md"}