mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: As we did in the previous diff, here we implemented `EventEmitter`'s ownership model as a `shared_ptr`. This change fixes problem with leaking `WeakObject`s which happens on hot-reload. So, in short: * `EventTargetWrapper` object owns `jsi::WeakObject` that can be converted to actual `jsi::Object` that represent event target in JavaScript realm; * `EventTargetWrapper` and `jsi::WeakObject` objects must be deallocated as soon as native part does not need them anymore; * `EventEmitter` objects retain `EventTarget` objects; * `EventEmitter` can loose event target object in case if assosiated `ShadowNode` got unmounted (not deallocated); in this case `EventEmitter` is loosing possibility to dispatch event even if some mounting-layer code is still retaining it. Reviewed By: mdvacca Differential Revision: D9762755 fbshipit-source-id: 96e989767a32914db9f4627fce51b044c71f257a
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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 <folly/dynamic.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
enum class EventPriority: int {
|
|
SynchronousUnbatched,
|
|
SynchronousBatched,
|
|
AsynchronousUnbatched,
|
|
AsynchronousBatched,
|
|
|
|
Sync = SynchronousUnbatched,
|
|
Work = SynchronousBatched,
|
|
Interactive = AsynchronousUnbatched,
|
|
Deferred = AsynchronousBatched
|
|
};
|
|
|
|
/*
|
|
* We need this types only to ensure type-safety when we deal with them. Conceptually,
|
|
* they are opaque pointers to some types that derived from those classes.
|
|
*/
|
|
class EventHandler {};
|
|
class EventTarget {};
|
|
using SharedEventHandler = std::shared_ptr<const EventHandler>;
|
|
using SharedEventTarget = std::shared_ptr<const EventTarget>;
|
|
using WeakEventTarget = std::weak_ptr<const EventTarget>;
|
|
|
|
using EventPipe = std::function<void(const EventTarget *eventTarget, const std::string &type, const folly::dynamic &payload)>;
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|