15 #include <lager/store.hpp>
16 #include <lager/reader.hpp>
17 #include <lager/event_loop/manual.hpp>
30 struct ListenerHolder;
32 using Result = std::pair<Model,
33 lager::effect<Action, lager::deps<ListenerHolder &>>>;
35 using SlotT = std::function<void(
KazvEvent)>;
40 for (
const auto &slot: m_slots) {
45 void connect(SlotT slot) {
46 m_slots.push_back(std::move(slot));
49 std::vector<SlotT> m_slots;
52 using ListenerSP = std::shared_ptr<Listener>;
53 using ListenerWSP = std::weak_ptr<Listener>;
58 bool needsCleanup =
false;
59 for (
auto listener : m_listeners) {
60 auto strongListener = listener.lock();
62 strongListener->emit(e);
69 std::remove_if(m_listeners.begin(),
78 std::vector<ListenerWSP> m_listeners;
81 inline static Result update(Model, Action a) {
85 auto &holder = lager::get<ListenerHolder &>(ctx);
86 holder.sendToListeners(a.nextEvent);
92 template<
class EventLoop>
96 lager::make_store<Action>(
99 lager::with_reducer(&update),
100 lager::with_deps(
std::ref(m_holder))))
102 [loop=loop](auto &&func) mutable {
103 loop.post(
std::forward<decltype(func)>(func));
108 m_store.dispatch(Action{e});
115 : m_listener(
std::make_shared<Listener>()) {
116 ee.addListener(m_listener);
118 template<
class EventType,
class Func>
121 [f=std::forward<Func>(func)](
KazvEvent e) {
122 if (std::holds_alternative<EventType>(e)) {
123 f(std::get<EventType>(e));
131 [f=std::forward<Func>(func)](
KazvEvent e) {
137 ListenerSP m_listener;
154 void addListener(ListenerSP listener) {
155 m_postingFunc([=]() {
156 m_holder.m_listeners.push_back(listener);
161 decltype(lager::make_store<Action>(
163 lager::with_manual_event_loop{},
164 lager::with_reducer(&update),
165 lager::with_deps(std::ref(detail::declref<ListenerHolder>()))));
167 using PostingFunc = std::function<void(std::function<
void()>)>;
169 ListenerHolder m_holder;
171 PostingFunc m_postingFunc;
Definition: eventinterface.hpp:15
Definition: lagerstoreeventemitter.hpp:112
void afterAll(Func &&func)
Definition: lagerstoreeventemitter.hpp:129
Watchable(LagerStoreEventEmitter &ee)
Definition: lagerstoreeventemitter.hpp:114
void after(Func &&func)
Definition: lagerstoreeventemitter.hpp:119
Definition: lagerstoreeventemitter.hpp:26
Watchable watchable()
An object you can watch for events.
Definition: lagerstoreeventemitter.hpp:148
void emit(KazvEvent e) override
Definition: lagerstoreeventemitter.hpp:107
~LagerStoreEventEmitter() override=default
LagerStoreEventEmitter(EventLoop loop)
Definition: lagerstoreeventemitter.hpp:93
Definition: location.hpp:10
std::variant< std::monostate, ReceivingPresenceEvent, ReceivingAccountDataEvent, ReceivingRoomTimelineEvent, ReceivingRoomStateEvent, RoomMembershipChanged, ReceivingRoomAccountDataEvent, ReceivingToDeviceMessage, LoginSuccessful, LoginFailed, SyncSuccessful, SyncFailed, PostInitialFiltersSuccessful, PostInitialFiltersFailed, PaginateSuccessful, PaginateFailed, CreateRoomSuccessful, CreateRoomFailed, InviteUserSuccessful, InviteUserFailed, JoinRoomSuccessful, JoinRoomFailed, LeaveRoomSuccessful, LeaveRoomFailed, ForgetRoomSuccessful, ForgetRoomFailed, SendMessageSuccessful, SendMessageFailed, SendToDeviceMessageSuccessful, SendToDeviceMessageFailed, InvalidMessageFormat, GetRoomStatesSuccessful, GetRoomStatesFailed, GetStateEventSuccessful, GetStateEventFailed, SendStateEventSuccessful, SendStateEventFailed, SetTypingSuccessful, SetTypingFailed, PostReceiptSuccessful, PostReceiptFailed, SetReadMarkerSuccessful, SetReadMarkerFailed, UploadContentSuccessful, UploadContentFailed, DownloadContentSuccessful, DownloadContentFailed, DownloadThumbnailSuccessful, DownloadThumbnailFailed, UploadIdentityKeysSuccessful, UploadIdentityKeysFailed, UploadOneTimeKeysSuccessful, UploadOneTimeKeysFailed, ClaimKeysSuccessful, ClaimKeysFailed, UnrecognizedResponse, ShouldQueryKeys > KazvEvent
Definition: kazvevents.hpp:390
Definition: clientutil.hpp:217