event_truck 1.0.0 copy "event_truck: ^1.0.0" to clipboard
event_truck: ^1.0.0 copied to clipboard

EventTruck is a lightweight, extensible, and type-safe event bus for managing event-driven architecture

example/event_truck_example.dart

import 'package:event_truck/event_truck.dart';

class MyObserver implements EventTrackObserver {
  @override
  void onEvent<E, T>(EventTruck<E> truck, T event) {
    /// print(event);
  }

}

void main() {
  EventTruck.observer = MyObserver();
  EventTruck<Event>()..on(_callbackA)
  ..on(_callback)
  ..on(_callbackB)..add(EventA())..add(EventB())..dispose();
}

void _callback(Event event) => switch(event) {
    EventA() => _callbackA(event),
    EventB() => _callbackB(event),
    EventC() => throw Exception(),
  };

void _callbackB(EventB event) {
  /// print('$event');
}

void _callbackA(EventA event) {
  /// print('$event');
}

sealed class Event {}

class EventA extends Event {}

class EventB extends Event {}

class EventC extends Event {}
1
likes
160
points
108
downloads

Publisher

verified publishercontributors.info

Weekly Downloads

EventTruck is a lightweight, extensible, and type-safe event bus for managing event-driven architecture

Homepage
Repository (GitHub)
View/report issues

Topics

#event-bus #events #stream #event-handling #event-listeners

Documentation

API reference

License

MIT (license)

More

Packages that depend on event_truck