{"id":15008661,"url":"https://github.com/thekeenant/bus","last_synced_at":"2026-01-11T04:49:39.030Z","repository":{"id":56826810,"uuid":"91740315","full_name":"thekeenant/bus","owner":"thekeenant","description":":bus: A light-weight event bus library for Dart implementing the pub-sub pattern.","archived":false,"fork":false,"pushed_at":"2017-10-17T22:28:42.000Z","size":672,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T21:08:20.882Z","etag":null,"topics":["bus","dart","dartlang","event","eventbus","library","pubsub"],"latest_commit_sha":null,"homepage":"https://thekeenant.github.io/bus/","language":"Dart","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/thekeenant.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-18T21:45:48.000Z","updated_at":"2020-02-09T02:15:16.000Z","dependencies_parsed_at":"2022-09-20T22:44:35.901Z","dependency_job_id":null,"html_url":"https://github.com/thekeenant/bus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeenant%2Fbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeenant%2Fbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeenant%2Fbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeenant%2Fbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thekeenant","download_url":"https://codeload.github.com/thekeenant/bus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225110579,"owners_count":17422411,"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":["bus","dart","dartlang","event","eventbus","library","pubsub"],"created_at":"2024-09-24T19:19:55.928Z","updated_at":"2026-01-11T04:49:38.985Z","avatar_url":"https://github.com/thekeenant.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Bus on Dart\n\nA light-weight event bus library for Dart implementing the pub-sub pattern.\n\nFunctionality for JavaScript through dart2js is thanks to [dart-patch-mirrors](https://github.com/matthewfranglen/dart-patch-mirrors)\nwhich provides some fixes for the buggy mirror functionality. All the examples provided work with dart2js.\n\n![diagram](http://i.imgur.com/gBnIdO5.png)\n\nSend a message to the bus and let the bus distribute the message to various handlers which are subscribed to that type of\nevent. This library utilizes the `Stream` async library in Dart to handle subscriptions and publishing messages.\n\n## Install\n\nSee [pub.dartlang.org][install] for instructions on how to use bus in your project.\n\n## Usage\n\nA simple usage example:\n\n```dart\nimport 'package:bus/bus.dart';\n\nmain() async {\n  var bus = new Bus\u003cString\u003e();\n\n  var sub = bus.subscribe((String message) {\n    print('Received a string: \"$message\"');\n  });\n\n  await bus.post('Hey there!');\n  \n  // cancel the subscription\n  sub.cancel();\n  \n  // the subscription was cancelled, this is pointless\n  bus.post('This message will not be heard...');\n}\n```\n\nAlso supported is subscribing an object full of handlers:\n\n```dart\nclass GameListener implements Listener {\n  @handler\n  void _onGame(GameEvent event) {\n    print('[An event occurred at ${event.timestamp}]');\n  }\n\n  @handler\n  void _onChat(ChatEvent event) {\n    print('${event.username} says \"${event.message}\"');\n  }\n}\n\n...\n\nvar bus = new Bus\u003cGameEvent\u003e();\nvar subs = bus.subscribeAll(new GameListener()); // returns a list of subscriptions\n\n// remember to cancel your event subscriptions\nsubs.forEach((s) =\u003e s.cancel());\n```\n\nSee the [game example][game] for more details.\n\nFor your synchronous needs, you can use `SyncBus` to publish and handle messages synchronously.\n\n## Web Demo\n\nVisit [https://thekeenant.github.io/bus/](https://thekeenant.github.io/bus/). Try it yourself\nby cloning this repository and running `pub serve web`. This will serve the assets in the `web` directory.\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[install]: https://pub.dartlang.org/packages/bus#-pkg-tab-installing\n[game]: https://github.com/thekeenant/dart-bus/blob/master/example/bus_game.dart\n[tracker]: https://github.com/thekeenant/dart-bus/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekeenant%2Fbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthekeenant%2Fbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekeenant%2Fbus/lists"}