{"id":41879138,"url":"https://github.com/orelnatan/ngx-event-bus-lib","last_synced_at":"2026-01-26T18:01:14.987Z","repository":{"id":333153716,"uuid":"1120051192","full_name":"orelnatan/ngx-event-bus-lib","owner":"orelnatan","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-17T18:06:36.000Z","size":1524,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-18T02:42:36.021Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orelnatan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-20T11:39:14.000Z","updated_at":"2026-01-17T18:45:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/orelnatan/ngx-event-bus-lib","commit_stats":null,"previous_names":["orelnatan/ngx-event-bus-lib"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/orelnatan/ngx-event-bus-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orelnatan%2Fngx-event-bus-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orelnatan%2Fngx-event-bus-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orelnatan%2Fngx-event-bus-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orelnatan%2Fngx-event-bus-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orelnatan","download_url":"https://codeload.github.com/orelnatan/ngx-event-bus-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orelnatan%2Fngx-event-bus-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28784093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-25T13:00:20.521Z","updated_at":"2026-01-26T18:01:14.980Z","avatar_url":"https://github.com/orelnatan.png","language":"TypeScript","funding_links":[],"categories":["State Management"],"sub_categories":["Other State Libraries"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003cimg\n      alt=\"Ngx Event Bus\"\n      src=\"https://github.com/orelnatan/ngx-event-bus-lib/blob/master/projects/ngx-event-bus-lib/ngx-event-bus-lib-cover.jpg\"\n      width=\"100%\"\n    /\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n# ngx-event-bus\n\n[![CircleCI](https://circleci.com/gh/orelnatan/ngx-event-bus-lib/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/orelnatan/ngx-event-bus-lib)\n[![codecov](https://codecov.io/gh/orelnatan/ngx-event-bus-lib/graph/badge.svg?token=4GAKYYNREF)](https://codecov.io/gh/orelnatan/ngx-event-bus-lib)\n[![SSR](https://img.shields.io/badge/SSR-support-brightgreen)](https://www.npmjs.com/package/on-ngx-event-bus)\n[![NPM Version](https://img.shields.io/npm/v/on-ngx-event-bus?color=blue)](https://www.npmjs.com/package/on-ngx-event-bus)\n[![npm package size](https://img.shields.io/npm/unpacked-size/on-ngx-event-bus?color=orange)](https://www.npmjs.com/package/on-ngx-event-bus)\n[![License](https://img.shields.io/npm/l/on-ngx-event-bus?color=blue)](https://github.com/orelnatan/ngx-event-bus-lib/blob/master/LICENSE)\n[![Angular](https://img.shields.io/badge/Angular-21+-dd0031)](https://angular.dev)\n[![Downloads](https://img.shields.io/npm/dm/on-ngx-event-bus?color=blue)](https://www.npmjs.com/package/on-ngx-event-bus)\n\n**A lightweight, fully-tested, type-safe global event bus for Angular — powered by decorators, pure functions, and zero shared state.**\n\nBroadcast strongly-typed events anywhere in your app and react to them declaratively —\nwithout services, DI, providers, RxJS, Signals, or tight coupling.\n\n\u003csmall\u003e\u003ci\u003e\n ⚠️\u0026ensp;The \u003ccode\u003eon-\u003c/code\u003e prefix is used solely to avoid a naming conflict on npm and has no functional meaning.\n\u003c/i\u003e\u003c/small\u003e\n\n## Motivation\n\nIn many Angular applications, **components that are completely unrelated still need to communicate**.\n\nWhen the app is not built around a state-management solution, a common approach is to introduce a shared service —\nusually based on RxJS `Subject`'s or Signals — and use it as a communication bridge.\n\nThis typically requires:\n- Services, providers, and dependency injections\n- RxJS tools or Signals\n- Manual lifecycle handling to avoid memory leaks (in the case of RxJS)\n\n`ngx-event-bus` takes a different approach.\n\nIt is built on **native JavaScript events**, automatically adds and removes event listeners to prevent **memory leaks**, and requires **no services, no DI, and no module setup or imports**. Event handling is simple, declarative, and free from shared state.\n\n## Compatibility \n\n✅\u0026ensp;**Angular support:** Angular **v9 and above**\n\nSupports **all Angular entities**:\n\n- Components\n- Directives\n- Services\n- Pipes\n\n## Quick Start\u0026ensp;🚀\n\n## Install\n```bash\n# npm\nnpm install on-ngx-event-bus\n\n# yarn\nyarn add on-ngx-event-bus\n\n# pnpm\npnpm add on-ngx-event-bus\n```\n\n## Usage\n\n### Broadcasting an event\u0026ensp;🛜​\n```ts\nimport { broadcast, GEvent } from \"on-ngx-event-bus\";\n\npublish(): void {\n  broadcast(\n    new GEvent(\"MY_EVENT\", {\n      metadata: \"My event data...\"\n    })\n  );\n}\n```\n\n- The event's payload can be **any type of data** — primitives, objects, functions, and more. (If no payload is provided, the default is null)\n\n---\n\n### Intercepting an event\u0026ensp;📡\n```ts\nimport { Component } from \"@angular/core\";\nimport { Interceptor, intercept } from \"on-ngx-event-bus\";\n\n@Interceptor([\n  { type: \"MY_EVENT\", action: \"handleEvent\" }\n])\n@Component({\n  selector: \"app-home\",\n  template: `Home`\n})\nexport class HomeComponent {\n  constructor() {\n    intercept(this);\n  }\n\n  handleEvent(payload: { metadata: string }): void {\n    console.log(\"Event intercepted: \", payload);\n  }\n}\n```\n- ⚠️\u0026ensp;Mandatory: Always call `intercept(this)` in the constructor to activate the `@Interceptor`.\n\n- The `@Interceptor` decorator can intercept and handle **any number of events**, without limits.\n\n## 🎯\u0026ensp;Targeted Events\n\nBy default, events are **broadcast globally** — each interceptor listening to the same event type will receive them.\n\nHowever, in some scenarios you may want **only specific listeners** to react to an event, even if multiple interceptors are registered for the same type. To support this, events can be optionally sent with a **`key`** (`string`).\n\n### Broadcasting a targeted event\u0026ensp;🛜​\n\n```ts\npublish(): void {\n  broadcast(\n    new GEvent(\"MY_EVENT\", {\n      metadata: \"My event data...\"\n    }, \"BUS::MY_EVENT::A9F3-77XQ\") // 🔑​\n  );\n}\n```\n\n### Intercepting a targeted event\u0026ensp;📡\n\n```ts\n@Interceptor([\n  { type: \"MY_EVENT\", action: \"handleTargetedEvent\", key: \"BUS::MY_EVENT::A9F3-77XQ\" }\n])\n@Component({\n  selector: \"app-home\",\n  template: `Home`\n})\nexport class HomeComponent {\n  constructor() {\n    intercept(this);\n  }\n\n  handleTargetedEvent(): void {\n    console.log(\"Will be triggered only if the key matches...\");\n  }\n}\n```\n- Events broadcast with a mismatched key will be **rejected** by the `@Interceptor`\u0026ensp;❌\n\n\n## Advanced Usage\u0026ensp;⚡\n\n`ngx-event-bus` supports **fully-typed events** in 3 different levels, from quick-and-loose to fully enforced best practices.  \n\n---\n\n### 1️⃣\u0026ensp;Loose / Quick Usage\n```ts\nbroadcast(new GEvent(\"MY_EVENT\", {\n  metadata: \"Quick, untyped payload\"\n}));\n```\n- ✅\u0026ensp;Fast — minimal setup, just fire-and-forget.  \n- ✅\u0026ensp;Flexible — any shape of payload is allowed.  \n- ❌\u0026ensp;No type safety (developer choice)\n\n### 2️⃣\u0026ensp;Generic enforce - Strongly Typed \n```ts\nbroadcast(\n  new GEvent\u003c\"MY_EVENT\", { metadata: string }\u003e(\"MY_EVENT\", {\n    metadata: \"Payload and event name are generic enforced.\"\n  })\n);\n```\nOr even smarter, with Enums/types and interfaces\n\n```ts\nenum MyEventTypes {\n  MyEvent = \"MY_EVENT\"\n}\n\ninterface MyEventPayload {\n  metadata: string;\n}\n\nbroadcast(\n new GEvent\u003cMyEventTypes.MyEvent, MyEventPayload\u003e(\n   MyEventTypes.MyEvent, {\n     metadata: \"Payload and event name are generic enforced.\"\n   })\n);\n```\n- ✅\u0026ensp;Payload enforced — TypeScript ensures payload shape is correct.\n- ✅\u0026ensp;Event names centralized — reduces typos and keeps event names consistent.\n- ✅\u0026ensp;Better developer experience — IDE autocompletion works.\n- ❌\u0026ensp;Event–payload relationship not fully enforced — nothing prevents using the wrong payload with a given event type.\n\n### 3️⃣\u0026ensp;Fully Enforced, Best Practice\u0026ensp;🥇\nBy extending the `GEvent` class, you can create your own fully enforced events. This ensures **both the event type and its payload are strictly typed**, making your code refactor-safe and perfect for large apps.\n\n```ts\nimport { GEvent, broadcast } from 'on-ngx-event-bus';\n\nexport class MyEvent extends GEvent\u003cMyEventTypes.MyEvent, MyEventPayload\u003e {\n  static readonly TYPE = MyEventTypes.MyEvent;\n\n  constructor(payload: MyEventPayload) {\n    super(MyEvent.TYPE, payload);\n  }\n}\n\nbroadcast(\n  new MyEvent({\n    metadata: \"Fully typed and refactor-safe!\"\n  })\n);\n```\n- ✅\u0026ensp;Fully typed — TypeScript strictly enforces both event type and payload, guaranteeing their correct relationship.\n- ✅\u0026ensp;Refactor-safe — renaming the event or payload interface will automatically propagate errors if used incorrectly.\n- ✅\u0026ensp;Best developer experience — IDE autocompletion, type-checking, and maintainability are maximized.\n- ✅\u0026ensp;Large-app ready — ideal for apps with many events and complex interactions.\n\n## Final Thoughts\u0026ensp;✨\n\n`ngx-event-bus` is designed to scale with your application — from small components to large, event-rich Angular systems.\n\nIt removes boilerplate, enforces correctness at compile time, and lets you focus on **intent**, not wiring.\nIf your app relies on clean, decoupled communication, this library is built for you.\n\n## Help / Support\u0026ensp;💬\n\nIf you run into any issues or have questions about using **ngx-event-bus**, feel free to reach out.\n\n📧 Email: [natenorel@gmail.com](mailto:natenorel@gmail.com)\n\n🐞 **Bug reports \u0026 feature requests:**  \nPlease [open an issue on GitHub](https://github.com/orelnatan/ngx-event-bus-lib/issues)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forelnatan%2Fngx-event-bus-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forelnatan%2Fngx-event-bus-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forelnatan%2Fngx-event-bus-lib/lists"}