import 'dart:async'; import 'package:comunic/models/comment.dart'; 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); } /// New comment class NewCommentEvent { final Comment comment; NewCommentEvent(this.comment); } /// Updated comment class UpdatedCommentEvent { final Comment comment; UpdatedCommentEvent(this.comment); } 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 on(void onData(T event)) { if (T == dynamic) throw Exception("Do not register to all events!"); final stream = _mgr.on(); return stream.listen(onData); } /// Propagate an event static void emit(T event) { _mgr.fire(event); } }