{"id":19898978,"url":"https://github.com/arkency/event-bus","last_synced_at":"2025-09-05T23:33:32.488Z","repository":{"id":46261694,"uuid":"46229481","full_name":"arkency/event-bus","owner":"arkency","description":"Simple eventing bus","archived":false,"fork":false,"pushed_at":"2023-11-16T19:35:14.000Z","size":235,"stargazers_count":46,"open_issues_count":6,"forks_count":5,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-19T01:22:36.366Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/arkency.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}},"created_at":"2015-11-15T18:10:07.000Z","updated_at":"2023-09-24T00:19:09.000Z","dependencies_parsed_at":"2024-06-18T16:51:54.378Z","dependency_job_id":"da1e4287-d96a-4cc8-a133-344326c81a8e","html_url":"https://github.com/arkency/event-bus","commit_stats":{"total_commits":58,"total_committers":5,"mean_commits":11.6,"dds":"0.27586206896551724","last_synced_commit":"6ad7bf31c51a5d1c658a431c1b91d66a4aef40ad"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkency%2Fevent-bus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkency%2Fevent-bus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkency%2Fevent-bus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkency%2Fevent-bus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arkency","download_url":"https://codeload.github.com/arkency/event-bus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252116382,"owners_count":21697370,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-11-12T20:06:43.372Z","updated_at":"2025-05-02T22:31:40.406Z","avatar_url":"https://github.com/arkency.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Bus\n\n[![Build Status](https://travis-ci.org/arkency/event-bus.svg?branch=master)](https://travis-ci.org/arkency/event-bus)\n\nSimple event bus for your JavaScript application without any dependencies and with a low size footprint.\n\n## Installation:\n\n### Npm:\n\n```\nnpm install --save eventing-bus\n```\n\n### Yarn:\n\n```\nyarn add eventing-bus\n```\n\n## Global event bus\n\nBy default, exports in JavaScript are evaluated only once. This way, we are ensured to have one global event bus without doing anything on our side.\n\nThere is also a possibility to define an event stream [separately from the global bus](#more-than-one-event-bus).\n\n## Subscribing to events:\n\n````javascript\nimport EventBus from 'eventing-bus'\n\nconst callback = (name) =\u003e { console.log(`Hello, ${name}!`) };\n\nEventBus.on(\"exampleEventName\", callback);\n````\n\n## Publishing events:\n\n````javascript\nimport EventBus from 'eventing-bus';\n\nEventBus.publish(\"exampleEventName\", \"Watson\");\n/* After registering the subscription and publishing an event you should see\n   \"Hello, Watson!\" printed in your console. */\n````\n\n## More than one event bus:\n\nBy default you have only one, singleton event bus instance which holds subscriptions from all parts of your application. But nothing stands on your way to create your own, private instances (for example, for each logically distinct part of your complex app):\n\n````javascript\nimport EventStream from 'eventing-bus/lib/event_stream';\n\n/* You can use EventStream both as a constructor and as a factory function. */\nconst privateBus = EventStream();\nconst newPrivateBus = new EventStream();\n````\n\nThose _streams_ created by you won't share any subscriptions, nor events.\n\n## Unregistering event handlers:\n\nIf you need to unregister a subscription – a typical case would be when cleaning after your UI library – you can do it in two ways:\n\n#### Call value returned by `#on`\n\nAfter registering an event handler, a return calue will be a function unregistering the specific handler.\n\n````javascript\nimport EventBus from 'eventing-bus';\n\nconst subscription = EventBus.on('event', () =\u003e { console.log('test') })\n\nEventBus.publish('event') // Console: 'test'\n\n// This will unregister this (and only this) subscription.\nsubscription();\n\nEventBus.publish('event') // No output in console\n````\n\n#### Use `#unregisterCallback`\n\nIn case you have no easy access to value returned by `#on`, you can just call `#unregisterCallback`. Additional benefit is that this function does not require knowing an event name. This way you can de-register every single usage of suck callback.\n\n````javascript\nimport EventBus from 'eventing-bus';\n\nconst callback = () =\u003e { console.log('test') }\n\nEventBus.on('eventA', callback)\nEventBus.on('eventB', callback)\n\nEventBus.publish('eventA') // Console: 'test'\nEventBus.publish('eventB') // Console: 'test'\n\nEventBus.unregisterCallback(callback)\n\nEventBus.publish('eventA') // No output in console\nEventBus.publish('eventB') // No output in console\n````\n\n## Unregistering subscriptions in bulk:\n\nSince by default `EventBus` is a singleton instance of the bus, there may be occasions where you need to unregister all subscriptions (most notably - during testing). It can be done by calling following methods:\n\n\n#### `#unregisterAllCallbacks`\n\nRemoves all event handlers.\n\n````javascript\nimport EventBus from 'eventing-bus';\n\nEventBus.unregisterAllCallbacks();\n````\n\n#### `#unregisterCallbacksForEvent`\n\nRemvoes all event handlers for specific event\n\n````javascript\nimport EventBus from 'eventing-bus';\n\nEventBus.on('exampleEvent', () =\u003e { console.log(\"EXAMPLE\") });\nEventBus.publish(\"exampleEvent\"); // Logs `EXAMPLE`\n\nEventBus.unregisterCallbacksForEvent('exampleEvent');\n\nEventBus.publish(\"exampleEvent\"); // Empty output\n````\n\n## Compatibility\n\nIf you want to use this library on legacy browsers (IE \u003c= 8 etc.), you need to\nprovide polyfills for `Array.forEach` and `Array.filter` functions. Check out e.g.\n [es5-shim](https://github.com/es-shims/es5-shim) to read more.\n\n## Contributing\n\nFeel free to report any issue or idea on the GitHub page of this project. If you report an issue, please try to provide reproducing steps or any piece of code that can reproduce the issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkency%2Fevent-bus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farkency%2Fevent-bus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkency%2Fevent-bus/lists"}