From 504c7694c4f678de6cd69e7e48dcb4cdc23d4c3d Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 27 Aug 2018 07:21:09 -0700 Subject: [PATCH] Fabric: Introducing `RawEvent` Summary: @public RawEvent represents ready-to-dispatch event data, an event that can be processed uniformly. Reviewed By: mdvacca Differential Revision: D8886235 fbshipit-source-id: 1c905517814330c5ecbf39f0ebc95ff2b576d1f2 --- ReactCommon/fabric/events/RawEvent.cpp | 29 ++++++++++++++++ ReactCommon/fabric/events/RawEvent.h | 48 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 ReactCommon/fabric/events/RawEvent.cpp create mode 100644 ReactCommon/fabric/events/RawEvent.h diff --git a/ReactCommon/fabric/events/RawEvent.cpp b/ReactCommon/fabric/events/RawEvent.cpp new file mode 100644 index 000000000..5195bcdbe --- /dev/null +++ b/ReactCommon/fabric/events/RawEvent.cpp @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "RawEvent.h" + +namespace facebook { +namespace react { + +RawEvent::RawEvent( + const std::string &type, + const folly::dynamic &payload, + const EventTarget &eventTarget, + const std::function &isDispatchable +): + type(type), + payload(payload), + eventTarget(eventTarget), + isDispachable_(isDispatchable) {} + +bool RawEvent::isDispachable() const { + return isDispachable_(); +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/events/RawEvent.h b/ReactCommon/fabric/events/RawEvent.h new file mode 100644 index 000000000..cecec268e --- /dev/null +++ b/ReactCommon/fabric/events/RawEvent.h @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once + +#include + +#include +#include + +namespace facebook { +namespace react { + +/* + * Represents ready-to-dispatch event data. + */ +class RawEvent { + +public: + using RawEventDispatchable = std::function; + + RawEvent( + const std::string &type, + const folly::dynamic &payload, + const EventTarget &eventTarget, + const RawEventDispatchable &isDispachable + ); + + const std::string type; + const folly::dynamic payload; + const EventTarget eventTarget; + + /* + * Returns `true` if event can be dispatched to `eventTarget`. + * Events that associated with unmounted or deallocated `ShadowNode`s + * must not be dispatched. + */ + bool isDispachable() const; + +private: + const RawEventDispatchable isDispachable_; +}; + +} // namespace react +} // namespace facebook