1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00
comunicmobile/lib/helpers/events_helper.dart

70 lines
1.3 KiB
Dart
Raw Normal View History

2020-04-18 11:48:21 +00:00
import 'dart:async';
2020-04-18 14:35:53 +00:00
import 'package:comunic/models/comment.dart';
2020-04-18 11:48:21 +00:00
import 'package:event_bus/event_bus.dart';
/// Events helper
///
/// @author Pierre Hubert
/// Main WebSocket closed
class WSClosedEvent {}
/// New number of notifications
class NewNumberNotifsEvent {
final int newNum;
NewNumberNotifsEvent(this.newNum);
}
/// New number of unread conversations
class NewNumberUnreadConversations {
final int newNum;
NewNumberUnreadConversations(this.newNum);
}
2020-04-18 14:35:53 +00:00
/// New comment
class NewCommentEvent {
final Comment comment;
NewCommentEvent(this.comment);
}
2020-04-18 14:46:55 +00:00
/// Updated comment
class UpdatedCommentEvent {
final Comment comment;
UpdatedCommentEvent(this.comment);
}
2020-04-18 14:57:00 +00:00
/// Deleted comment
class DeletedCommentEvent {
final int commentID;
DeletedCommentEvent(this.commentID);
}
2020-04-18 11:48:21 +00:00
class EventsHelper {
static EventBus _mgr = EventBus();
/// Listen to event
///
/// Do not use this method directly. You should instead prefer to use
/// [SafeState.listen] to handle safely widgets lifecycle...
///
/// You can not register to global events
static StreamSubscription<T> on<T>(void onData(T event)) {
if (T == dynamic) throw Exception("Do not register to all events!");
final stream = _mgr.on<T>();
return stream.listen(onData);
}
/// Propagate an event
static void emit<T>(T event) {
_mgr.fire(event);
}
}