{"_id":"@adrawash1999/event-bus-lib","_rev":"2-6dcf647a88ea161edaf4e8ee0f95d26e","name":"@adrawash1999/event-bus-lib","dist-tags":{"latest":"2.1.0"},"versions":{"1.0.0":{"name":"@adrawash1999/event-bus-lib","version":"1.0.0","keywords":["angular","event-bus","pubsub","postmessage","custom-events"],"author":{"name":"Ahmed Abdeltawab"},"license":"MIT","_id":"@adrawash1999/event-bus-lib@1.0.0","maintainers":[{"name":"adrawash1999","email":"mideomideo779@gmail.com"}],"homepage":"https://github.com/AhmedAbdultawab1999/event-bus-lib","bugs":{"url":"https://github.com/AhmedAbdultawab1999/event-bus-lib/issues"},"dist":{"shasum":"0887a6564ed603800cc44bd4a425bee1c373da5b","tarball":"https://registry.npmjs.org/@adrawash1999/event-bus-lib/-/event-bus-lib-1.0.0.tgz","fileCount":16,"integrity":"sha512-a9ac5izW/Eis4Ft4teqZ7PLGxzqdz1yAx+S9rNkYQje25rr7pNDf98XpSt4ca5+9xf3Vuzsosvx5W+wHUU1M2g==","signatures":[{"sig":"MEUCIFHVqiEczLAGuPan51mNTfjK3wId5OOqVT7goFaWT7m4AiEAnZCnQGfruxtRHqG1A2kihNJRw9hcACSs3cmy1f7nEXc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13123},"main":"bundles/event-bus-lib.umd.js","gitHead":"ade3da92839cfcd65573138243982e4a5c494d1e","scripts":{"lint":"ng lint","test":"ng test","build":"ng-packagr -p ng-package.json","prepublishOnly":"npm run build"},"typings":"event-bus-lib.d.ts","_npmUser":{"name":"adrawash1999","email":"mideomideo779@gmail.com"},"repository":{"url":"git+https://github.com/AhmedAbdultawab1999/event-bus-lib.git","type":"git"},"_npmVersion":"10.8.3","description":"An event bus library for Angular that enables you to choose between pubsub-js, postMessage, and custom events.","directories":{},"sideEffects":false,"_nodeVersion":"22.9.0","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"devDependencies":{"ng-packagr":"^18.2.1","typescript":"~5.4.2","@types/node":"^18.0.0","@types/jasmine":"~5.1.0"},"peerDependencies":{"pubsub-js":"^1.9.4","@angular/core":"^17.3.0","@angular/common":"^17.3.0"},"_npmOperationalInternal":{"tmp":"tmp/event-bus-lib_1.0.0_1730215663963_0.8044446485317809","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@adrawash1999/event-bus-lib","version":"2.0.0","keywords":["angular","event-bus","pubsub","postmessage","custom-events"],"author":{"name":"Ahmed Abdeltawab"},"license":"MIT","_id":"@adrawash1999/event-bus-lib@2.0.0","maintainers":[{"name":"adrawash1999","email":"mideomideo779@gmail.com"}],"homepage":"https://github.com/AhmedAbdultawab1999/event-bus-lib","bugs":{"url":"https://github.com/AhmedAbdultawab1999/event-bus-lib/issues"},"dist":{"shasum":"c25afaebe6ad492e0d0c164fbde29eda04a6751d","tarball":"https://registry.npmjs.org/@adrawash1999/event-bus-lib/-/event-bus-lib-2.0.0.tgz","fileCount":22,"integrity":"sha512-S1N1nGc+qWOfj2YvgodLnzWytUMCdY6FwIrjDvZUFNwaO3D/iez5C2/7YKr99qTGSSnpcxSNLQOr88FJmtcLKg==","signatures":[{"sig":"MEQCIHb+QRLWns/8ogItRYCISdiqKqg6r/589lHA20NsQlj8AiA7v9CtO0peXqaRAzwv5uNRy2ykOAYDStPuON6bJXMMpQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":48455},"main":"bundles/event-bus-lib.umd.js","module":"fesm2022/adrawash1999-event-bus-lib.mjs","exports":{".":{"esm":"./esm2022/adrawash1999-event-bus-lib.mjs","types":"./index.d.ts","default":"./fesm2022/adrawash1999-event-bus-lib.mjs","esm2022":"./esm2022/adrawash1999-event-bus-lib.mjs"},"./package.json":{"default":"./package.json"}},"gitHead":"ade3da92839cfcd65573138243982e4a5c494d1e","typings":"index.d.ts","_npmUser":{"name":"adrawash1999","email":"mideomideo779@gmail.com"},"repository":{"url":"git+https://github.com/AhmedAbdultawab1999/event-bus-lib.git","type":"git"},"_npmVersion":"10.8.3","description":"An event bus library for Angular that enables you to choose between pubsub-js, postMessage, and custom events.","directories":{},"sideEffects":false,"_nodeVersion":"22.9.0","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"peerDependencies":{"pubsub-js":"^1.9.4","@angular/core":"^17.3.0","@angular/common":"^17.3.0"},"_npmOperationalInternal":{"tmp":"tmp/event-bus-lib_2.0.0_1730220838540_0.5027029515086376","host":"s3://npm-registry-packages"}},"2.1.0":{"name":"@adrawash1999/event-bus-lib","version":"2.1.0","description":"An event bus library for Angular that enables you to choose between pubsub-js, postMessage, and custom events.","main":"bundles/event-bus-lib.umd.js","typings":"index.d.ts","peerDependencies":{"@angular/common":"^17.3.0","@angular/core":"^17.3.0","pubsub-js":"^1.9.4"},"dependencies":{"tslib":"^2.3.0"},"homepage":"https://github.com/AhmedAbdultawab1999/event-bus-lib","repository":{"type":"git","url":"git+https://github.com/AhmedAbdultawab1999/event-bus-lib.git"},"keywords":["angular","event-bus","pubsub","postmessage","custom-events"],"author":{"name":"Ahmed Abdeltawab"},"license":"MIT","bugs":{"url":"https://github.com/AhmedAbdultawab1999/event-bus-lib/issues"},"sideEffects":false,"module":"fesm2022/adrawash1999-event-bus-lib.mjs","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/adrawash1999-event-bus-lib.mjs","esm":"./esm2022/adrawash1999-event-bus-lib.mjs","default":"./fesm2022/adrawash1999-event-bus-lib.mjs"}},"_id":"@adrawash1999/event-bus-lib@2.1.0","gitHead":"ade3da92839cfcd65573138243982e4a5c494d1e","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-+RwXggMLu3nFJKHjhxqayFgpqwxYbWcmwwnUx4QrPLusyyhv/DkOv81iD1XeFSAvTjqL8XThTujlP9E6orqVXQ==","shasum":"e4d8ad6f796b6263835ca0293f29dae6891a9a62","tarball":"https://registry.npmjs.org/@adrawash1999/event-bus-lib/-/event-bus-lib-2.1.0.tgz","fileCount":22,"unpackedSize":53195,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHd6p4ugQgYq2fy+FtNmKJX1Iab7rlFWDQKBhWvOLWftAiEAptpYY0owL/g1i+BQ8+gnvgsYOGmnGslr/v4CtZpa/B4="}]},"_npmUser":{"name":"adrawash1999","email":"mideomideo779@gmail.com"},"directories":{},"maintainers":[{"name":"adrawash1999","email":"mideomideo779@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/event-bus-lib_2.1.0_1730231943999_0.611264263699822"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-29T15:27:43.843Z","modified":"2024-10-29T19:59:04.470Z","1.0.0":"2024-10-29T15:27:44.150Z","2.0.0":"2024-10-29T16:53:58.728Z","2.1.0":"2024-10-29T19:59:04.256Z"},"bugs":{"url":"https://github.com/AhmedAbdultawab1999/event-bus-lib/issues"},"author":{"name":"Ahmed Abdeltawab"},"license":"MIT","homepage":"https://github.com/AhmedAbdultawab1999/event-bus-lib","keywords":["angular","event-bus","pubsub","postmessage","custom-events"],"repository":{"type":"git","url":"git+https://github.com/AhmedAbdultawab1999/event-bus-lib.git"},"description":"An event bus library for Angular that enables you to choose between pubsub-js, postMessage, and custom events.","maintainers":[{"name":"adrawash1999","email":"mideomideo779@gmail.com"}],"readme":"# EventBusLib\r\n\r\n**EventBusLib** is an event bus library for Angular designed to facilitate communication between components in multirepo micro frontend architectures. It allows you to choose between different event handling strategies: `pubsub-js`, `postMessage`, and `custom events`. This flexibility makes it ideal for applications composed of multiple micro frontends that need to communicate with each other seamlessly.\r\n\r\n## Table of Contents\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n  - [Getting Started](#getting-started)\r\n  - [Using Different EventBus Types](#using-different-eventbus-types)\r\n  - [Example: Communication Between Micro Frontends](#example-communication-between-micro-frontends)\r\n- [API Documentation](#api-documentation)\r\n- [Build](#build)\r\n- [Publishing](#publishing)\r\n- [Running Unit Tests](#running-unit-tests)\r\n- [Contributing](#contributing)\r\n\r\n## Installation\r\n\r\nTo install the library, you can use npm:\r\n\r\n```bash\r\nnpm install @adrawash1999/event-bus-lib\r\n```\r\n\r\n## Usage\r\n\r\n### Getting Started\r\n\r\n1. **Import the EventBus and EventBusFactory:**\r\n   Start by importing `EventBus` and `EventBusFactory` in your Angular component or service.\r\n\r\n   ```typescript\r\n   import { EventBus, EventBusFactory } from '@adrawash1999/event-bus-lib';\r\n   ```\r\n\r\n2. **Inject EventBusFactory:**\r\n   In your constructor, inject the `EventBusFactory` to retrieve the desired event bus implementation.\r\n\r\n   ```typescript\r\n   export class YourComponent {\r\n     private eventBus: EventBus;\r\n\r\n     constructor(private eventBusFactory: EventBusFactory) {\r\n       // Here you can choose the type of event bus you want to use\r\n       this.eventBus = this.eventBusFactory.getEventBus('postmessage');\r\n     }\r\n   }\r\n   ```\r\n\r\n### Using Different EventBus Types\r\n\r\nThe library supports the following event bus implementations:\r\n\r\n- **pubsub**: Utilizes the `pubsub-js` library for event handling.\r\n- **custom-event**: Uses the built-in CustomEvent API for custom event dispatching.\r\n- **postmessage**: Leverages the `postMessage` API for inter-window communication, making it suitable for micro frontends on different domains.\r\n\r\nTo use a specific type, call `getEventBus(type)` and pass the desired type:\r\n\r\n```typescript\r\nthis.eventBus = this.eventBusFactory.getEventBus('pubsub'); // or 'custom-event' or 'postmessage'\r\n```\r\n\r\n### Example: Communication Between Micro Frontends\r\n\r\nHere’s a simple example showcasing how to use the `EventBusLib` to establish communication between micro frontends:\r\n\r\n**Micro Frontend 1:**\r\n\r\n```typescript\r\n// In Micro Frontend 1 Component\r\nimport { Component } from '@angular/core';\r\nimport { EventBus, EventBusFactory } from '@adrawash1999/event-bus-lib';\r\n\r\n@Component({\r\n  selector: 'app-micro-frontend1',\r\n  templateUrl: './micro-frontend1.component.html',\r\n})\r\nexport class MicroFrontend1Component {\r\n  private eventBus: EventBus;\r\n\r\n  constructor(private eventBusFactory: EventBusFactory) {\r\n    this.eventBus = this.eventBusFactory.getEventBus('postmessage');\r\n    this.subscribeToEvents();\r\n  }\r\n\r\n  private subscribeToEvents(): void {\r\n    this.eventBus.subscribe('shared_event', (msg, data) => {\r\n      console.log(`Received in MF1: ${msg}`, data);\r\n    });\r\n  }\r\n\r\n  public triggerEvent(): void {\r\n    this.eventBus.publish('shared_event', { info: 'Hello from Micro Frontend 1!' });\r\n  }\r\n}\r\n```\r\n\r\n**Micro Frontend 2:**\r\n\r\n```typescript\r\n// In Micro Frontend 2 Component\r\nimport { Component } from '@angular/core';\r\nimport { EventBus, EventBusFactory } from '@adrawash1999/event-bus-lib';\r\n\r\n@Component({\r\n  selector: 'app-micro-frontend2',\r\n  templateUrl: './micro-frontend2.component.html',\r\n})\r\nexport class MicroFrontend2Component {\r\n  private eventBus: EventBus;\r\n\r\n  constructor(private eventBusFactory: EventBusFactory) {\r\n    this.eventBus = this.eventBusFactory.getEventBus('postmessage');\r\n    this.subscribeToEvents();\r\n  }\r\n\r\n  private subscribeToEvents(): void {\r\n    this.eventBus.subscribe('shared_event', (msg, data) => {\r\n      console.log(`Received in MF2: ${msg}`, data);\r\n    });\r\n  }\r\n}\r\n```\r\n\r\n### API Documentation\r\n\r\n#### EventBus Interface\r\n\r\n**Methods**\r\n- **publish(eventName: string, data: any): void**\r\n  - Publishes an event with the specified name and associated data.\r\n  \r\n- **subscribe(eventName: string, callback: (msg: string, data: any) => void): void**\r\n  - Subscribes to an event and executes the callback when the event is published.\r\n\r\n- **unsubscribe(eventName: string): void**\r\n  - Unsubscribes from the specified event.\r\n\r\n## Build\r\n\r\nRun the following command to build the library:\r\n\r\n```bash\r\nng build event-bus-lib\r\n```\r\n\r\nThe build artifacts will be stored in the `dist/` directory.\r\n\r\n## Publishing\r\n\r\nAfter building your library with `ng build`, navigate to the dist folder and run:\r\n\r\n```bash\r\ncd dist/event-bus-lib\r\nnpm publish --access public\r\n```\r\n\r\n## Running Unit Tests\r\n\r\nTo execute the unit tests via Karma, run:\r\n\r\n```bash\r\nng test event-bus-lib\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please fork the repository and submit a pull request with your changes. \r\n\r\nFor any issues or feature requests, please use the [issue tracker](https://github.com/AhmedAbdultawab1999/event-bus-lib/issues).\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\r\n```\r\n\r\n","readmeFilename":"README.md"}