Skip to content

Commit

Permalink
merge BatchedEventQueue into EventQueue (facebook#43438)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#43438

changelog: [internal]

EventQueue can now be merged with BatchedEventQueue since there isn't anything else subclassing it.

Reviewed By: javache

Differential Revision: D54687859

fbshipit-source-id: f646583db0e46789b667f8d79d24d0cf9d7fc00c
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Mar 14, 2024
1 parent 7af288e commit b3a8eba
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 59 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <react/renderer/core/StateUpdate.h>
#include "EventLogger.h"

#include "BatchedEventQueue.h"
#include "EventQueue.h"
#include "RawEvent.h"

namespace facebook::react {
Expand All @@ -20,9 +20,8 @@ EventDispatcher::EventDispatcher(
const EventBeat::Factory& synchonousEventBeatFactory,
const EventBeat::Factory& asynchronousEventBeatFactory,
const EventBeat::SharedOwnerBox& ownerBox)
: asynchronousBatchedQueue_(std::make_unique<BatchedEventQueue>(
eventProcessor,
asynchronousEventBeatFactory(ownerBox))) {}
: eventQueue_(
EventQueue(eventProcessor, asynchronousEventBeatFactory(ownerBox))) {}

void EventDispatcher::dispatchEvent(RawEvent&& rawEvent) const {
// Allows the event listener to interrupt default event dispatch
Expand All @@ -34,19 +33,19 @@ void EventDispatcher::dispatchEvent(RawEvent&& rawEvent) const {
if (eventLogger != nullptr) {
rawEvent.loggingTag = eventLogger->onEventStart(rawEvent.type);
}
asynchronousBatchedQueue_->enqueueEvent(std::move(rawEvent));
eventQueue_.enqueueEvent(std::move(rawEvent));
}

void EventDispatcher::dispatchStateUpdate(StateUpdate&& stateUpdate) const {
asynchronousBatchedQueue_->enqueueStateUpdate(std::move(stateUpdate));
eventQueue_.enqueueStateUpdate(std::move(stateUpdate));
}

void EventDispatcher::dispatchUniqueEvent(RawEvent&& rawEvent) const {
// Allows the event listener to interrupt default event dispatch
if (eventListeners_.willDispatchEvent(rawEvent)) {
return;
}
asynchronousBatchedQueue_->enqueueUniqueEvent(std::move(rawEvent));
eventQueue_.enqueueUniqueEvent(std::move(rawEvent));
}

void EventDispatcher::addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include <react/renderer/core/BatchedEventQueue.h>
#include <react/renderer/core/EventBeat.h>
#include <react/renderer/core/EventListener.h>
#include <react/renderer/core/EventQueue.h>
#include <react/renderer/core/EventQueueProcessor.h>
#include <react/renderer/core/StateUpdate.h>

Expand Down Expand Up @@ -62,7 +62,7 @@ class EventDispatcher {
const std::shared_ptr<const EventListener>& listener) const;

private:
std::unique_ptr<BatchedEventQueue> asynchronousBatchedQueue_;
EventQueue eventQueue_;

mutable EventListenerContainer eventListeners_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void EventQueue::enqueueStateUpdate(StateUpdate&& stateUpdate) const {
onEnqueue();
}

void EventQueue::onEnqueue() const {
eventBeat_->request();
}

void EventQueue::onBeat(jsi::Runtime& runtime) const {
flushStateUpdates();
flushEvents(runtime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class EventQueue {
EventQueue(
EventQueueProcessor eventProcessor,
std::unique_ptr<EventBeat> eventBeat);
virtual ~EventQueue() = default;

/*
* Enqueues and (probably later) dispatch a given event.
Expand All @@ -55,7 +54,7 @@ class EventQueue {
* Override in subclasses to trigger beat `request` and/or beat `induce`.
* Default implementation does nothing.
*/
virtual void onEnqueue() const = 0;
void onEnqueue() const;
void onBeat(jsi::Runtime& runtime) const;

void flushEvents(jsi::Runtime& runtime) const;
Expand Down

0 comments on commit b3a8eba

Please sign in to comment.