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
|
#pragma once
|
||||||
|
|
||||||
|
#include <folly/dynamic.h>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
enum class EventPriority {
|
enum class EventPriority: int {
|
||||||
SynchronousUnbatched,
|
SynchronousUnbatched,
|
||||||
SynchronousBatched,
|
SynchronousBatched,
|
||||||
AsynchronousUnbatched,
|
AsynchronousUnbatched,
|
||||||
|
@ -19,7 +21,7 @@ enum class EventPriority {
|
||||||
Sync = SynchronousUnbatched,
|
Sync = SynchronousUnbatched,
|
||||||
Work = SynchronousBatched,
|
Work = SynchronousBatched,
|
||||||
Interactive = AsynchronousUnbatched,
|
Interactive = AsynchronousUnbatched,
|
||||||
Deferred = AsynchronousBatched,
|
Deferred = AsynchronousBatched
|
||||||
};
|
};
|
||||||
|
|
||||||
/* `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque
|
/* `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque
|
||||||
|
@ -32,5 +34,13 @@ enum class EventPriority {
|
||||||
using EventTarget = struct EventTargetDummyStruct {} *;
|
using EventTarget = struct EventTargetDummyStruct {} *;
|
||||||
using EventHandler = struct EventHandlerDummyStruct {} *;
|
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 react
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
|
|
@ -114,21 +114,22 @@ void FabricUIManager::setReleaseEventTargetFunction(std::function<ReleaseEventTa
|
||||||
releaseEventTargetFunction_ = releaseEventTargetFunction;
|
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 {
|
void FabricUIManager::dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const {
|
||||||
dispatchEventToTargetFunction_(
|
if (eventTarget != EmptyEventTarget) {
|
||||||
eventHandler_,
|
dispatchEventToTargetFunction_(
|
||||||
eventTarget,
|
eventHandler_,
|
||||||
const_cast<std::string &>(type),
|
eventTarget,
|
||||||
const_cast<folly::dynamic &>(payload)
|
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 {
|
void FabricUIManager::releaseEventTarget(const EventTarget &eventTarget) const {
|
||||||
|
|
|
@ -51,7 +51,6 @@ public:
|
||||||
|
|
||||||
#pragma mark - Native-facing Interface
|
#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 dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const;
|
||||||
void releaseEventTarget(const EventTarget &eventTarget) const;
|
void releaseEventTarget(const EventTarget &eventTarget) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue