Fabric: `FabricUIManager::dispatchEventToEmptyTarget` got coupled with `dispatchEventToTarget`
Summary: @public Instead of having two methods it's easier to have just one which can be abstracted as `EventPipe`. Reviewed By: mdvacca Differential Revision: D8886231 fbshipit-source-id: af9fd92dc4afa1219a11acce0aa021a85c94d232
This commit is contained in:
parent
5965ba283f
commit
b784adc7ae
|
@ -7,10 +7,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
enum class EventPriority {
|
||||
enum class EventPriority: int {
|
||||
SynchronousUnbatched,
|
||||
SynchronousBatched,
|
||||
AsynchronousUnbatched,
|
||||
|
@ -19,7 +21,7 @@ enum class EventPriority {
|
|||
Sync = SynchronousUnbatched,
|
||||
Work = SynchronousBatched,
|
||||
Interactive = AsynchronousUnbatched,
|
||||
Deferred = AsynchronousBatched,
|
||||
Deferred = AsynchronousBatched
|
||||
};
|
||||
|
||||
/* `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque
|
||||
|
@ -32,5 +34,13 @@ enum class EventPriority {
|
|||
using EventTarget = struct EventTargetDummyStruct {} *;
|
||||
using EventHandler = struct EventHandlerDummyStruct {} *;
|
||||
|
||||
/*
|
||||
* EmptyEventTarget is used when some event cannot be dispatched to an original
|
||||
* event target but still has to be dispatched to preserve consistency of event flow.
|
||||
*/
|
||||
static const EventTarget EmptyEventTarget = nullptr;
|
||||
|
||||
using EventPipe = std::function<void(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload)>;
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
|
|
@ -114,21 +114,22 @@ void FabricUIManager::setReleaseEventTargetFunction(std::function<ReleaseEventTa
|
|||
releaseEventTargetFunction_ = releaseEventTargetFunction;
|
||||
}
|
||||
|
||||
void FabricUIManager::dispatchEventToEmptyTarget(const std::string &type, const folly::dynamic &payload) const {
|
||||
dispatchEventToEmptyTargetFunction_(
|
||||
eventHandler_,
|
||||
const_cast<std::string &>(type),
|
||||
const_cast<folly::dynamic &>(payload)
|
||||
);
|
||||
}
|
||||
|
||||
void FabricUIManager::dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const {
|
||||
dispatchEventToTargetFunction_(
|
||||
eventHandler_,
|
||||
eventTarget,
|
||||
const_cast<std::string &>(type),
|
||||
const_cast<folly::dynamic &>(payload)
|
||||
);
|
||||
if (eventTarget != EmptyEventTarget) {
|
||||
dispatchEventToTargetFunction_(
|
||||
eventHandler_,
|
||||
eventTarget,
|
||||
const_cast<std::string &>(type),
|
||||
const_cast<folly::dynamic &>(payload)
|
||||
);
|
||||
}
|
||||
else {
|
||||
dispatchEventToEmptyTargetFunction_(
|
||||
eventHandler_,
|
||||
const_cast<std::string &>(type),
|
||||
const_cast<folly::dynamic &>(payload)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void FabricUIManager::releaseEventTarget(const EventTarget &eventTarget) const {
|
||||
|
|
|
@ -51,7 +51,6 @@ public:
|
|||
|
||||
#pragma mark - Native-facing Interface
|
||||
|
||||
void dispatchEventToEmptyTarget(const std::string &type, const folly::dynamic &payload) const;
|
||||
void dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const;
|
||||
void releaseEventTarget(const EventTarget &eventTarget) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue