jozz_events 1.0.1 copy "jozz_events: ^1.0.1" to clipboard
jozz_events: ^1.0.1 copied to clipboard

Domain-first, framework-agnostic event system built for Clean Architecture

๐Ÿ“ฆ jozz_events #

Domain-first, framework-agnostic event system built for Clean Architecture

jozz_events is a lightweight, strongly-typed event management system designed to enable clean, decoupled communication between features in large-scale applications.

Inspired by domain-driven design and separation of concerns, it enables features to react to domain events without knowing about each other, making it a perfect fit for Clean Architecture, modular design, and scalable systems.


๐Ÿš€ Why jozz_events? #

โœ… Clean Architecture Friendly #

  • Events are fully decoupled from emitters and listeners.
  • Works across layers: UI, Application, Domain, Infrastructure.
  • Perfect for feature-based modular projects.

โœ… Typed, Predictable, and Testable #

  • No string-based events or untyped channels.
  • Built with Dart's type system using generics and sealed base classes.

โœ… Framework-Agnostic #

  • No dependency on Flutter or any UI toolkit.
  • Can be used in Dart CLIs, server apps, or Flutter mobile/web/desktop.

โœ… Lifecycle Aware #

  • Optional lifecycle management for Bloc, Cubit, State, or any component.
  • Auto-dispose subscriptions on destruction.

โœ… Simpler and Safer Than Alternatives #

Package Clean Arch Friendly Strongly Typed Lifecycle Support Global Singleton DI-Friendly
jozz_events โœ… Yes โœ… Yes โœ… Yes โŒ Opt-in only โœ… Yes
event_bus โŒ No โŒ No โŒ No โœ… Always โŒ No
Bloc-to-Bloc Comm. โŒ Tight Coupling โœ… Yes โœ… Yes โŒ โœ… Yes
Signals โŒ UI-focused โœ… Yes โœ… (via hooks) โŒ โš ๏ธ UI-tied

๐Ÿงฑ Use Case Example #

You have two features:

  • A TodoService that emits TodoCreatedEvent
  • A NotificationModule that listens for this event and displays a notification

๐Ÿง  These two features must be completely unaware of each other โ€” and jozz_events makes that easy.


๐Ÿ“ฆ Installation #

dependencies:
  jozz_events: ^latest

Then import it:

import 'package:jozz_events/jozz_events.dart';

๐Ÿ› ๏ธ Getting Started #

1. Define a Domain Event #

class TodoCreatedEvent extends JozzEvent {
  final String todoId;
  final String title;

  const TodoCreatedEvent({required this.todoId, required this.title});
}

2. Create a Shared Event Bus (or inject it) #

final JozzBus eventBus = JozzBusService();

3. Emit the Event (e.g., inside a service) #

eventBus.emit(TodoCreatedEvent(todoId: '1', title: 'Buy milk'));

Or using fluent API:

eventBus
  .emitEvent(TodoCreatedEvent(todoId: '1', title: 'Buy milk'))
  .emitEvent(TodoCreatedEvent(todoId: '2', title: 'Call mom'));

4. Listen for the Event (e.g., in a notification module) #

eventBus.on<TodoCreatedEvent>().listen((event) {
  print('NOTIFICATION: New todo created: ${event.title}');
});

5. Manage Subscriptions #

final sub = eventBus.listen<TodoCreatedEvent>((event) {
  print('Handling todo: ${event.todoId}');
});

// later
sub.cancel();

class MyBloc with JozzLifecycleMixin {
  final JozzBus _eventBus;

  MyBloc(this._eventBus) {
    _eventBus.autoListen<TodoCreatedEvent>(this, _onTodoCreated);
  }

  void _onTodoCreated(TodoCreatedEvent event) {
    // handle logic
  }

  @override
  Future<void> close() {
    disposeJozzSubscriptions();
    return super.close();
  }
}

๐Ÿงช Testing #

Mock JozzBus and verify behavior easily:

final mockBus = MockJozzBus();
when(() => mockBus.on<TodoCreatedEvent>()).thenAnswer((_) => Stream.value(TodoCreatedEvent(...)));

โœ… Features #

  • โœ… Strongly typed events
  • โœ… No tight coupling between features
  • โœ… Clean architecture ready
  • โœ… Pure Dart โ€” no Flutter dependency
  • โœ… Lifecycle support for widgets, blocs, cubits, etc.
  • โœ… Fluent event emission
  • โœ… Easy testing & mocking

๐Ÿ“ Clean Architecture Example Structure #

features/
โ”œโ”€โ”€ todo/
โ”‚   โ”œโ”€โ”€ domain/events/todo_created_event.dart
โ”‚   โ””โ”€โ”€ application/todo_service.dart
โ””โ”€โ”€ notifications/
    โ””โ”€โ”€ presentation/notification_listener.dart

Both features are fully decoupled. Communication happens through JozzBus. Created by developers who love Clean Architecture and hate spaghetti.


๐Ÿ“ข Coming Soon #

  • โœ… Singleton opt-in with JozzBus.instance
  • โœ… Flutter integration subpackage
  • ๐Ÿงช Built-in testing utilities
  • ๐Ÿงฉ Middleware or interceptors (event logging)
  • ๐Ÿ“ก Namespaced topics or channels

๐Ÿ”— License #

MIT ยฉ Jozz


2
likes
0
points
211
downloads

Publisher

verified publisherjozz.biz

Weekly Downloads

Domain-first, framework-agnostic event system built for Clean Architecture

Repository (GitHub)
View/report issues

Topics

#events #clean-architecture #domain-driven-design #separation-of-concerns #bloc

License

unknown (license)

More

Packages that depend on jozz_events