2018-05-22 22:48:19 +00:00
|
|
|
/**
|
|
|
|
* 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 <memory>
|
2018-06-01 16:36:25 +00:00
|
|
|
#include <mutex>
|
2018-05-22 22:48:19 +00:00
|
|
|
|
|
|
|
#include <folly/dynamic.h>
|
|
|
|
#include <fabric/core/EventDispatcher.h>
|
|
|
|
#include <fabric/core/EventPrimitives.h>
|
|
|
|
#include <fabric/core/ReactPrimitives.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class EventHandlers;
|
|
|
|
|
|
|
|
using SharedEventHandlers = std::shared_ptr<const EventHandlers>;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base class for all particular typed event handlers.
|
|
|
|
* Stores `InstanceHandle` identifying a particular component and the pointer
|
|
|
|
* to `EventDispatcher` which is responsible for delivering the event.
|
|
|
|
*
|
|
|
|
* TODO: Reconsider naming of all event-related things.
|
|
|
|
*/
|
|
|
|
class EventHandlers {
|
|
|
|
|
|
|
|
public:
|
2018-06-01 16:36:19 +00:00
|
|
|
EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher);
|
2018-06-01 16:36:25 +00:00
|
|
|
virtual ~EventHandlers();
|
2018-05-22 22:48:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initates an event delivery process.
|
|
|
|
* Is used by particular subclasses only.
|
|
|
|
*/
|
|
|
|
void dispatchEvent(
|
2018-06-01 16:36:19 +00:00
|
|
|
const std::string &type,
|
|
|
|
const folly::dynamic &payload = folly::dynamic::object(),
|
2018-05-22 22:48:19 +00:00
|
|
|
const EventPriority &priority = EventPriority::AsynchronousBatched
|
|
|
|
) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-06-01 16:36:25 +00:00
|
|
|
void createEventTargetIfNeeded() const;
|
|
|
|
void releaseEventTargetIfNeeded() const;
|
|
|
|
|
2018-05-22 22:48:19 +00:00
|
|
|
InstanceHandle instanceHandle_;
|
2018-06-01 16:36:19 +00:00
|
|
|
Tag tag_;
|
2018-05-22 22:48:19 +00:00
|
|
|
std::weak_ptr<const EventDispatcher> eventDispatcher_;
|
2018-06-01 16:36:25 +00:00
|
|
|
mutable EventTarget eventTarget_ {nullptr};
|
|
|
|
mutable std::mutex mutex_;
|
2018-05-22 22:48:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|