Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Dart Event Bus | 635 | 127 | 32 | a year ago | 22 | March 04, 2021 | 1 | mit | Dart | |
An Event Bus using Dart Streams for decoupling applications | ||||||||||
Channelx | 48 | 2 years ago | 4 | November 20, 2021 | mit | Go | ||||
Some useful tools implemented by channel to increase development efficiency, e.g. event bus, promise, actor, stream, aggregator, goroutine pool, etc.. | ||||||||||
Kiqr | 25 | 1 | 6 years ago | 1 | November 08, 2017 | apache-2.0 | Java | |||
A distributed generic query layer for Apache Kafka Interactive Queries | ||||||||||
Vxrifa | 15 | 5 days ago | 7 | August 04, 2020 | 1 | lgpl-2.1 | Java | |||
Utility library for Vert.X that allows using strong-typed interfaces in communication through EventBus | ||||||||||
Websockets Vertx Flink Kafka | 13 | 2 years ago | Java | |||||||
A simple request response cycle using Websockets, Eclipse Vert-x server, Apache Kafka, Apache Flink. | ||||||||||
Event_taxi | 12 | 3 | 2 years ago | 8 | March 15, 2021 | apache-2.0 | Dart | |||
An Event Bus using Dart Stream API | ||||||||||
Rxjs Reactive Patterns | 8 | 2 years ago | 3 | TypeScript | ||||||
Course Notes, Implementation for RxJs & Reactive Patterns Angular Architecture (Observer, Observable, Store ... ), Clean Code, StoryBook | ||||||||||
Busfactor | 6 | 7 months ago | 14 | June 29, 2022 | mit | PHP | ||||
CQRS and Event Sourcing infrastructure for modern PHP | ||||||||||
Telstar | 5 | 3 years ago | 38 | mit | Python | |||||
Telstar makes it easy to write consumer groups and producers against redis streams | ||||||||||
Vertx Streams | 4 | 6 years ago | other | Scala | ||||||
A simple Event Bus using Dart Streams for decoupling applications.
GitHub | Pub | Demos and Examples
An Event Bus follows the publish/subscribe pattern. It allows listeners to subscribe for events and publishers to fire events. This enables objects to interact without requiring to explicitly define listeners and keeping track of them.
The Event Bus pattern is especially helpful for decoupling MVC (or MVP) applications.
One group of MVC is not a problem.
But as soon as there are multiple groups of MVCs, those groups will have to talk to each other. This creates a tight coupling between the controllers.
By communication through an Event Bus, the coupling is reduced.
Create an instance of EventBus
and make it available to other classes.
Usually there is just one Event Bus per application, but more than one may be set up to group a specific set of events.
import 'package:event_bus/event_bus.dart';
EventBus eventBus = EventBus();
Note: The default constructor will create an asynchronous event bus. To
create a synchronous bus you must provide the optional sync: true
attribute.
Any Dart class can be used as an event.
class UserLoggedInEvent {
User user;
UserLoggedInEvent(this.user);
}
class NewOrderEvent {
Order order;
NewOrderEvent(this.order);
}
Register listeners for specific events:
eventBus.on<UserLoggedInEvent>().listen((event) {
// All events are of type UserLoggedInEvent (or subtypes of it).
print(event.user);
});
Register listeners for all events:
eventBus.on().listen((event) {
// Print the runtime type. Such a set up could be used for logging.
print(event.runtimeType);
});
EventBus
uses Dart Streams
as its underlying mechanism to keep track of listeners. You may use all
functionality available by the Stream
API. One example is the use of StreamSubscriptions
to later unsubscribe from the events.
StreamSubscription loginSubscription = eventBus.on<UserLoggedInEvent>().listen((event) {
print(event.user);
});
loginSubscription.cancel();
Finally, we need to fire an event.
User myUser = User('Mickey');
eventBus.fire(UserLoggedInEvent(myUser));
Instead of using the default StreamController
you can use the following constructor
to provide your own.
An example would be to use an RxDart Subject as the controller.
import 'package:rxdart/rxdart.dart';
EventBus behaviorBus = EventBus.customController(BehaviorSubject());
webdev serve
webdev build
pub run build_runner test -- -p chrome
The MIT License (MIT)