mirror of
https://github.com/status-im/react-native.git
synced 2025-01-24 00:09:08 +00:00
5d9326be29
Summary: Removes the concept of instance handle. Instead we pass the event target to createNode and don't pass it to subsequent clones. The life time of the event target is managed by native (the event emitter). It has to be released manually. Reviewed By: shergin Differential Revision: D8688330 fbshipit-source-id: e11b61f147ea9ca4dfb453fe07063ed06f24b7ac
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
/**
|
|
* 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>
|
|
#include <mutex>
|
|
|
|
#include <folly/dynamic.h>
|
|
#include <fabric/core/EventDispatcher.h>
|
|
#include <fabric/core/EventPrimitives.h>
|
|
#include <fabric/core/ReactPrimitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class EventEmitter;
|
|
|
|
using SharedEventEmitter = std::shared_ptr<const EventEmitter>;
|
|
|
|
/*
|
|
* 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 EventEmitter {
|
|
|
|
public:
|
|
EventEmitter(const EventTarget &eventTarget, const Tag &tag, const SharedEventDispatcher &eventDispatcher);
|
|
virtual ~EventEmitter();
|
|
|
|
protected:
|
|
|
|
/*
|
|
* Initates an event delivery process.
|
|
* Is used by particular subclasses only.
|
|
*/
|
|
void dispatchEvent(
|
|
const std::string &type,
|
|
const folly::dynamic &payload = folly::dynamic::object(),
|
|
const EventPriority &priority = EventPriority::AsynchronousBatched
|
|
) const;
|
|
|
|
private:
|
|
|
|
mutable EventTarget eventTarget_ {nullptr};
|
|
Tag tag_;
|
|
std::weak_ptr<const EventDispatcher> eventDispatcher_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|