bus 0.0.8

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 0

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';

class Event {
  final DateTime timestamp;

  Event() : this.timestamp = new DateTime.now();
}

main() async {
  // Create a new bus, which accepts messages of type Event.
  var bus = new Bus<Event>();

  // Subscribe a single handler
  bus.subscribe((Event event) {
    print('An event occurred at ${event.timestamp}.');
  });

  // Post the event and (optional) await for handlers to receive them 
  await bus.post(new Event());
}

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}"');
  }
}

...

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.

Changelog #

0.0.8 #

  • Add tests (sync, async and listeners tests).

0.0.7 #

  • Getter for message type
  • Internal changes, util file for helpers

0.0.5 #

  • Synchronous bus, via new SyncBus<T>().

0.0.2-0.0.4 #

  • Documentation, README fixes.

0.0.1 #

  • Initial beta version.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bus: ^0.0.8

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bus/bus.dart';
  
Version Uploaded Documentation Archive
0.0.11 Oct 17, 2017 Go to the documentation of bus 0.0.11 Download bus 0.0.11 archive
0.0.10 May 19, 2017 Go to the documentation of bus 0.0.10 Download bus 0.0.10 archive
0.0.9 May 19, 2017 Go to the documentation of bus 0.0.9 Download bus 0.0.9 archive
0.0.8 May 19, 2017 Go to the documentation of bus 0.0.8 Download bus 0.0.8 archive
0.0.7 May 19, 2017 Go to the documentation of bus 0.0.7 Download bus 0.0.7 archive
0.0.6 May 18, 2017 Go to the documentation of bus 0.0.6 Download bus 0.0.6 archive
0.0.5 May 18, 2017 Go to the documentation of bus 0.0.5 Download bus 0.0.5 archive
0.0.4 May 18, 2017 Go to the documentation of bus 0.0.4 Download bus 0.0.4 archive
0.0.3 May 18, 2017 Go to the documentation of bus 0.0.3 Download bus 0.0.3 archive
0.0.2 May 18, 2017 Go to the documentation of bus 0.0.2 Download bus 0.0.2 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0