bus 0.0.9 copy "bus: ^0.0.9" to clipboard
bus: ^0.0.9 copied to clipboard

outdatedDart 1 only

A light-weight event bus implementing the pub-sub pattern.

Event Bus on Dart #

A light-weight event bus library for Dart implementing the pub-sub pattern.

diagram

Send a message to the bus and let the bus distribute the message to various handlers which are subscribed to that type of event. This library utilizes the Stream async library in Dart to handle subscriptions and publishing messages.

Install #

See pub.dartlang.org for instructions on how to use bus in your project.

Usage #

A simple usage example:

import 'package:bus/bus.dart';

main() async {
  var bus = new Bus<String>();

  bus.subscribe((String message) {
    print('Received a string: "$message"');
  });

  await bus.post('Hey there!');
}

Also supported is subscribing an object full of handlers:

class GameListener implements Listener {
  @handler
  _onGame(GameEvent event) {
    print('[An event occurred at ${event.timestamp}]');
  }

  @handler
  _onChat(ChatEvent event) {
    print('${event.username} says "${event.message}"');
  }
}

...

var bus = new Bus<GameEvent>();
bus.subscribeAll(new GameListener());

See the game example for explicit details.

For your synchronous needs, you can use SyncBus to publish and handle messages synchronously.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A light-weight event bus implementing the pub-sub pattern.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on bus