From f4e9827013ab84e1ca88109889a1a08a9c37ecec Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 17 Nov 2023 03:27:51 -0800 Subject: [PATCH] delete ComponentDescriptor::createEventEmitter (#41514) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41514 changelog: [internal] `ComponentDescriptor::createEventEmitter` can be deleted. Reviewed By: christophpurrer Differential Revision: D51394153 fbshipit-source-id: 7541c3cb018a009e8c9555f9a9b0d41215dca1bc --- .../react/renderer/core/ComponentDescriptor.h | 7 -- .../core/ConcreteComponentDescriptor.h | 11 +- .../react/renderer/core/ShadowNodeFamily.cpp | 4 +- .../react/renderer/core/ShadowNodeFamily.h | 1 + .../renderer/core/tests/ShadowNodeTest.cpp | 104 +++++++----------- 5 files changed, 47 insertions(+), 80 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h index aa9c40fc8dd..7839906e5fc 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -130,12 +129,6 @@ class ComponentDescriptor { virtual ShadowNodeFamily::Shared createFamily( const ShadowNodeFamilyFragment& fragment) const = 0; - /* - * Creates an event emitter for particular node. - */ - virtual SharedEventEmitter createEventEmitter( - const InstanceHandle::Shared& instanceHandle) const = 0; - protected: friend ShadowNode; diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 4fc25fe73c7..f161e9b12c1 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -155,14 +155,11 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { ShadowNodeFamily::Shared createFamily( const ShadowNodeFamilyFragment& fragment) const override { + auto eventEmitter = std::make_shared( + std::make_shared(fragment.instanceHandle), + eventDispatcher_); return std::make_shared( - fragment, eventDispatcher_, *this); - } - - SharedEventEmitter createEventEmitter( - const InstanceHandle::Shared& instanceHandle) const override { - return std::make_shared( - std::make_shared(instanceHandle), eventDispatcher_); + fragment, std::move(eventEmitter), eventDispatcher_, *this); } protected: diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp index cf2bd385b95..0e73b0a5cf3 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.cpp @@ -20,14 +20,14 @@ using AncestorList = ShadowNode::AncestorList; ShadowNodeFamily::ShadowNodeFamily( const ShadowNodeFamilyFragment& fragment, + SharedEventEmitter eventEmitter, EventDispatcher::Weak eventDispatcher, const ComponentDescriptor& componentDescriptor) : eventDispatcher_(std::move(eventDispatcher)), tag_(fragment.tag), surfaceId_(fragment.surfaceId), instanceHandle_(fragment.instanceHandle), - eventEmitter_( - componentDescriptor.createEventEmitter(fragment.instanceHandle)), + eventEmitter_(std::move(eventEmitter)), componentDescriptor_(componentDescriptor), componentHandle_(componentDescriptor.getComponentHandle()), componentName_(componentDescriptor.getComponentName()) {} diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h index 1fefb9532ea..dc5dbc81531 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h @@ -50,6 +50,7 @@ class ShadowNodeFamily final { ShadowNodeFamily( const ShadowNodeFamilyFragment& fragment, + SharedEventEmitter eventEmitter, EventDispatcher::Weak eventDispatcher, const ComponentDescriptor& componentDescriptor); diff --git a/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp b/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp index 8a1f19bdd8a..ac00541f103 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp @@ -37,14 +37,11 @@ class ShadowNodeTest : public ::testing::Test { auto traits = TestShadowNode::BaseTraits(); - auto familyAA = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 11, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyAA = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 11, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeAA_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -53,14 +50,11 @@ class ShadowNodeTest : public ::testing::Test { familyAA, traits); - auto familyABA = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 12, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyABA = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 12, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeABA_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -69,14 +63,11 @@ class ShadowNodeTest : public ::testing::Test { familyABA, traits); - auto familyABB = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 13, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyABB = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 13, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeABB_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -88,14 +79,11 @@ class ShadowNodeTest : public ::testing::Test { auto nodeABChildren = std::make_shared( ShadowNode::ListOfShared{nodeABA_, nodeABB_}); - auto familyAB = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 15, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyAB = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 15, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeAB_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -104,14 +92,11 @@ class ShadowNodeTest : public ::testing::Test { familyAB, traits); - auto familyAC = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 16, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyAC = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 16, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeAC_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -123,14 +108,11 @@ class ShadowNodeTest : public ::testing::Test { auto nodeAChildren = std::make_shared( ShadowNode::ListOfShared{nodeAA_, nodeAB_, nodeAC_}); - auto familyA = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 17, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyA = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 17, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeA_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -139,14 +121,11 @@ class ShadowNodeTest : public ::testing::Test { familyA, traits); - auto familyZ = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 18, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto familyZ = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 18, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); nodeZ_ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, @@ -234,14 +213,11 @@ TEST_F(ShadowNodeTest, handleCloneFunction) { } TEST_F(ShadowNodeTest, handleState) { - auto family = std::make_shared( - ShadowNodeFamilyFragment{ - /* .tag = */ 9, - /* .surfaceId = */ surfaceId_, - /* .instanceHandle = */ nullptr, - }, - eventDispatcher_, - componentDescriptor_); + auto family = componentDescriptor_.createFamily(ShadowNodeFamilyFragment{ + /* .tag = */ 9, + /* .surfaceId = */ surfaceId_, + /* .instanceHandle = */ nullptr, + }); auto traits = TestShadowNode::BaseTraits();