From 61f7639d38baef71855626475bc70e9e2127dbcb Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 19 Dec 2019 13:45:35 -0800 Subject: [PATCH] Fabric: Remove eventEmitter from ShadowNodeFragment Summary: As part of the plan is splitting ShadowNodeFragment into two parts. ShadowNodeFamilyFragment is already in place. This diff removes use of `ShadowNodeFragment::eventEmitter` and goes over all call sites to change it to `ShadowNodeFamilyFragment::surfaceId`. Changelog: [Internal] Reviewed By: shergin Differential Revision: D19146697 fbshipit-source-id: 22cae5404b0f3098feb86c0437a4aa256d5b773e --- .../fabric/components/root/RootShadowNode.cpp | 1 - .../ConcreteComponentDescriptor.h | 2 +- .../fabric/core/shadownode/ShadowNode.cpp | 3 --- .../core/shadownode/ShadowNodeFragment.cpp | 9 +-------- .../fabric/core/shadownode/ShadowNodeFragment.h | 3 --- .../core/tests/ComponentDescriptorTest.cpp | 5 ----- .../fabric/core/tests/ShadowNodeTest.cpp | 17 ----------------- ReactCommon/fabric/mounting/ShadowTree.cpp | 3 --- ReactCommon/fabric/mounting/stubs/stubs.cpp | 1 - .../uimanager/ComponentDescriptorRegistry.cpp | 3 +-- ReactCommon/fabric/uimanager/Scheduler.cpp | 2 -- ReactCommon/fabric/uimanager/UIManager.cpp | 8 +------- 12 files changed, 4 insertions(+), 53 deletions(-) diff --git a/ReactCommon/fabric/components/root/RootShadowNode.cpp b/ReactCommon/fabric/components/root/RootShadowNode.cpp index 206ea508dfc..425eaeea3dd 100644 --- a/ReactCommon/fabric/components/root/RootShadowNode.cpp +++ b/ReactCommon/fabric/components/root/RootShadowNode.cpp @@ -74,7 +74,6 @@ RootShadowNode::Unshared RootShadowNode::clone( childNode = parentNode.clone({ ShadowNodeFragment::propsPlaceholder(), - ShadowNodeFragment::eventEmitterPlaceholder(), std::make_shared(children), }); } diff --git a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h index c944824dc5b..21670bb6b96 100644 --- a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h +++ b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h @@ -70,7 +70,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { ShadowNodeFamilyFragment const &familyFragment) const override { assert(std::dynamic_pointer_cast(fragment.props)); assert(std::dynamic_pointer_cast( - fragment.eventEmitter)); + familyFragment.eventEmitter)); auto family = std::make_shared(familyFragment, *this); diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 1b8f0b06c31..68dce5fc539 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -74,9 +74,6 @@ ShadowNode::ShadowNode( : sourceShadowNode.getMostRecentState()), family_(sourceShadowNode.family_), traits_(sourceShadowNode.traits_) { - // `eventEmitter` cannot be changed with cloning. - assert( - fragment.eventEmitter == ShadowNodeFragment::eventEmitterPlaceholder()); assert(props_); assert(children_); diff --git a/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.cpp b/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.cpp index 4f89d4fd2ca..64ea2bb63ac 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.cpp @@ -15,11 +15,6 @@ Props::Shared const &ShadowNodeFragment::propsPlaceholder() { return instance; } -EventEmitter::Shared const &ShadowNodeFragment::eventEmitterPlaceholder() { - static auto &instance = *new EventEmitter::Shared(); - return instance; -} - ShadowNode::SharedListOfShared const & ShadowNodeFragment::childrenPlaceholder() { static auto &instance = *new ShadowNode::SharedListOfShared(); @@ -40,14 +35,12 @@ using Value = ShadowNodeFragment::Value; Value::Value(ShadowNodeFragment const &fragment) : props_(fragment.props), - eventEmitter_(fragment.eventEmitter), children_(fragment.children), localData_(fragment.localData), state_(fragment.state) {} Value::operator ShadowNodeFragment() const { - return ShadowNodeFragment{ - props_, eventEmitter_, children_, localData_, state_}; + return ShadowNodeFragment{props_, children_, localData_, state_}; } } // namespace react diff --git a/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.h b/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.h index d25d02b5a94..208479122fb 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNodeFragment.h @@ -28,7 +28,6 @@ namespace react { */ struct ShadowNodeFragment { Props::Shared const &props = propsPlaceholder(); - EventEmitter::Shared const &eventEmitter = eventEmitterPlaceholder(); ShadowNode::SharedListOfShared const &children = childrenPlaceholder(); LocalData::Shared const &localData = localDataPlaceholder(); State::Shared const &state = statePlaceholder(); @@ -39,7 +38,6 @@ struct ShadowNodeFragment { * be changed. */ static Props::Shared const &propsPlaceholder(); - static EventEmitter::Shared const &eventEmitterPlaceholder(); static ShadowNode::SharedListOfShared const &childrenPlaceholder(); static LocalData::Shared const &localDataPlaceholder(); static State::Shared const &statePlaceholder(); @@ -63,7 +61,6 @@ struct ShadowNodeFragment { private: Props::Shared const props_; - EventEmitter::Shared const eventEmitter_; ShadowNode::SharedListOfShared const children_; LocalData::Shared const localData_; State::Shared const state_; diff --git a/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp b/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp index a14253ec464..fb11a57aa0e 100644 --- a/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp +++ b/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp @@ -26,7 +26,6 @@ TEST(ComponentDescriptorTest, createShadowNode) { SharedShadowNode node = descriptor->createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ descriptor->createEventEmitter(0, 9), }, ShadowNodeFamilyFragment{ /* .tag = */ 9, @@ -52,7 +51,6 @@ TEST(ComponentDescriptorTest, cloneShadowNode) { SharedShadowNode node = descriptor->createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ descriptor->createEventEmitter(0, 9), }, ShadowNodeFamilyFragment{ /* .tag = */ 9, @@ -78,7 +76,6 @@ TEST(ComponentDescriptorTest, appendChild) { SharedShadowNode node1 = descriptor->createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ descriptor->createEventEmitter(0, 1), }, ShadowNodeFamilyFragment{ /* .tag = */ 1, @@ -88,7 +85,6 @@ TEST(ComponentDescriptorTest, appendChild) { SharedShadowNode node2 = descriptor->createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ descriptor->createEventEmitter(0, 2), }, ShadowNodeFamilyFragment{ /* .tag = */ 2, @@ -98,7 +94,6 @@ TEST(ComponentDescriptorTest, appendChild) { SharedShadowNode node3 = descriptor->createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ descriptor->createEventEmitter(0, 3), }, ShadowNodeFamilyFragment{ /* .tag = */ 3, diff --git a/ReactCommon/fabric/core/tests/ShadowNodeTest.cpp b/ReactCommon/fabric/core/tests/ShadowNodeTest.cpp index 566a1d17e60..ffc2cf9f67b 100644 --- a/ReactCommon/fabric/core/tests/ShadowNodeTest.cpp +++ b/ReactCommon/fabric/core/tests/ShadowNodeTest.cpp @@ -28,7 +28,6 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) { auto node = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -59,7 +58,6 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) { auto node = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -86,7 +84,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) { auto node1 = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family1, @@ -101,7 +98,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) { auto node2 = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family2, @@ -116,7 +112,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) { auto node3 = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family3, @@ -164,7 +159,6 @@ TEST(ShadowNodeTest, handleCloneFunction) { auto firstNode = std::make_shared( ShadowNodeFragment{ /* .props = */ std::make_shared(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -207,7 +201,6 @@ TEST(ShadowNodeTest, handleLocalData) { auto firstNode = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -215,7 +208,6 @@ TEST(ShadowNodeTest, handleLocalData) { auto secondNode = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -223,7 +215,6 @@ TEST(ShadowNodeTest, handleLocalData) { auto thirdNode = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, family, @@ -272,7 +263,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeAA = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyAA, @@ -288,7 +278,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeABA = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyABA, @@ -304,7 +293,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeABB = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyABB, @@ -320,7 +308,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeABC = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyABC, @@ -339,7 +326,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeAB = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ nodeABChildren, }, familyAB, @@ -355,7 +341,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeAC = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyAC, @@ -374,7 +359,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeA = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ nodeAChildren, }, familyA, @@ -390,7 +374,6 @@ TEST(ShadowNodeTest, handleBacktracking) { auto nodeZ = std::make_shared( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }, familyZ, diff --git a/ReactCommon/fabric/mounting/ShadowTree.cpp b/ReactCommon/fabric/mounting/ShadowTree.cpp index de5e3d29984..dca5a27da8c 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.cpp +++ b/ReactCommon/fabric/mounting/ShadowTree.cpp @@ -106,7 +106,6 @@ ShadowTree::ShadowTree( rootComponentDescriptor.createShadowNode( ShadowNodeFragment{ /* .props = */ props, - /* .eventEmitter = */ noopEventEmitter, }, {surfaceId, surfaceId, noopEventEmitter})); @@ -211,8 +210,6 @@ void ShadowTree::commitEmptyTree() const { *oldRootShadowNode, ShadowNodeFragment{ /* .props = */ ShadowNodeFragment::propsPlaceholder(), - /* .eventEmitter = */ - ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), }); }); diff --git a/ReactCommon/fabric/mounting/stubs/stubs.cpp b/ReactCommon/fabric/mounting/stubs/stubs.cpp index 5739c921252..d6ecc11b4af 100644 --- a/ReactCommon/fabric/mounting/stubs/stubs.cpp +++ b/ReactCommon/fabric/mounting/stubs/stubs.cpp @@ -51,7 +51,6 @@ StubViewTree stubViewTreeFromShadowNode(ShadowNode const &rootShadowNode) { auto emptyRootShadowNode = rootShadowNode.clone( ShadowNodeFragment{ShadowNodeFragment::propsPlaceholder(), - ShadowNodeFragment::eventEmitterPlaceholder(), ShadowNode::emptySharedShadowNodeSharedList()}); auto stubViewTree = StubViewTree(ShadowView(*emptyRootShadowNode)); diff --git a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp index 7a84ffe4a94..0e643eba1f1 100644 --- a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp +++ b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp @@ -171,12 +171,11 @@ SharedShadowNode ComponentDescriptorRegistry::createNode( auto const props = componentDescriptor.cloneProps(nullptr, RawProps(propsDynamic)); auto const state = componentDescriptor.createInitialState( - ShadowNodeFragment{props, eventEmitter}, surfaceId); + ShadowNodeFragment{props}, surfaceId); return componentDescriptor.createShadowNode( { /* .props = */ props, - /* .eventEmitter = */ eventEmitter, /* .children = */ ShadowNodeFragment::childrenPlaceholder(), /* .localData = */ ShadowNodeFragment::localDataPlaceholder(), /* .state = */ state, diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 5753aa4d94b..602ef105001 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -180,8 +180,6 @@ void Scheduler::renderTemplateToSurface( *oldRootShadowNode, ShadowNodeFragment{ /* .props = */ ShadowNodeFragment::propsPlaceholder(), - /* .eventEmitter = */ - ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ std::make_shared( SharedShadowNodeList{tree}), diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index f61819f32cd..4fc668736fb 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -36,7 +36,7 @@ SharedShadowNode UIManager::createNode( componentDescriptor.createEventEmitter(std::move(eventTarget), tag); auto const props = componentDescriptor.cloneProps(nullptr, rawProps); auto const state = componentDescriptor.createInitialState( - ShadowNodeFragment{props, eventEmitter}, surfaceId); + ShadowNodeFragment{props}, surfaceId); auto shadowNode = componentDescriptor.createShadowNode( ShadowNodeFragment{ @@ -47,7 +47,6 @@ SharedShadowNode UIManager::createNode( ? componentDescriptor.cloneProps( props, RawProps(folly::dynamic::object("name", name))) : props, - /* .eventEmitter = */ eventEmitter, /* .children = */ ShadowNodeFragment::childrenPlaceholder(), /* .localData = */ ShadowNodeFragment::localDataPlaceholder(), /* .state = */ state, @@ -88,7 +87,6 @@ SharedShadowNode UIManager::cloneNode( rawProps ? componentDescriptor.cloneProps( shadowNode->getProps(), *rawProps) : ShadowNodeFragment::propsPlaceholder(), - /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ children, }); @@ -115,8 +113,6 @@ void UIManager::completeSurface( *oldRootShadowNode, ShadowNodeFragment{ /* .props = */ ShadowNodeFragment::propsPlaceholder(), - /* .eventEmitter = */ - ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ rootChildren, }); }); @@ -205,8 +201,6 @@ void UIManager::updateState( shadowNode, [&](ShadowNode const &oldShadowNode) { return oldShadowNode.clone({ /* .props = */ ShadowNodeFragment::propsPlaceholder(), - /* .eventEmitter = */ - ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */ ShadowNodeFragment::childrenPlaceholder(), /* .localData = */ ShadowNodeFragment::localDataPlaceholder(),