party_bus 1.0.0
party_bus: ^1.0.0 copied to clipboard
Party Bus is a simple, naive event bus library oriented for DDD and CQRS.
example/party_bus_example.dart
import 'package:party_bus/party_bus.dart';
/// Any dart [Object] can be an `event`
final class const ExampleEvent() {
int get propertyA => 1;
}
Future<void> main() async {
/// Using the default event bus
final PartyBus partyBus = PartyBus();
/// Create a listener for a given <T> event
/// Multiples listeners can be created
partyBus.on<ExampleEvent>().listen(
(ExampleEvent ee) => print('on<ExampleEvent> listener : ${ee.propertyA}'),
);
/// You can also listen to ALL event on the bus
partyBus.any.listen(
((Object? event) => print('any listener : ${event.runtimeType}')),
);
/// We send an event on the bus
partyBus.add(const ExampleEvent());
/// We can use any object even the bus itself
/// the event will be broadcasted onto the any stream only
partyBus.add(partyBus);
await partyBus.dispose();
}