From 7a7f9601bcb680f1f4f7e2d25a38726ed81cd66b Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 15 Jul 2018 16:46:19 -0700 Subject: [PATCH] Fabric: ShadowNode::getSourceNode() was finally removed Summary: @public Trivial. Reviewed By: mdvacca Differential Revision: D8753905 fbshipit-source-id: 0a0e351dc0f8ff52e685c7d7dc79d0185cfac711 --- .../fabric/core/shadownode/ShadowNode.cpp | 40 +++---------------- .../fabric/core/shadownode/ShadowNode.h | 19 --------- .../fabric/core/tests/ShadowNodeTest.cpp | 32 ++------------- 3 files changed, 9 insertions(+), 82 deletions(-) diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index b2182bcd57..a9dc88ff61 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include namespace facebook { namespace react { @@ -49,7 +49,6 @@ ShadowNode::ShadowNode( props_(props ? props : shadowNode->props_), eventEmitter_(eventEmitter ? eventEmitter : shadowNode->eventEmitter_), children_(std::make_shared(*(children ? children : shadowNode->children_))), - sourceNode_(shadowNode), localData_(shadowNode->localData_), cloneFunction_(shadowNode->cloneFunction_), revision_(shadowNode->revision_ + 1) {} @@ -84,10 +83,6 @@ Tag ShadowNode::getRootTag() const { return rootTag_; } -SharedShadowNode ShadowNode::getSourceNode() const { - return sourceNode_.lock(); -} - SharedLocalData ShadowNode::getLocalData() const { return localData_; } @@ -122,24 +117,11 @@ void ShadowNode::replaceChild(const SharedShadowNode &oldChild, const SharedShad std::replace(nonConstChildren->begin(), nonConstChildren->end(), oldChild, newChild); } -void ShadowNode::clearSourceNode() { - ensureUnsealed(); - sourceNode_.reset(); -} - void ShadowNode::setLocalData(const SharedLocalData &localData) { ensureUnsealed(); localData_ = localData; } -void ShadowNode::shallowSourceNode() { - ensureUnsealed(); - - auto sourceNode = sourceNode_.lock(); - assert(sourceNode); - sourceNode_ = sourceNode->getSourceNode(); -} - #pragma mark - Equality bool ShadowNode::operator==(const ShadowNode& rhs) const { @@ -181,21 +163,11 @@ SharedDebugStringConvertibleList ShadowNode::getDebugChildren() const { } SharedDebugStringConvertibleList ShadowNode::getDebugProps() const { - SharedDebugStringConvertibleList list = {}; - - list.push_back(std::make_shared("tag", folly::to(tag_))); - - SharedShadowNode sourceNode = getSourceNode(); - if (sourceNode) { - list.push_back(std::make_shared( - "source", - sourceNode->getDebugDescription({.maximumDepth = 1, .format = false}) - )); - } - - SharedDebugStringConvertibleList propsList = props_->getDebugProps(); - std::move(propsList.begin(), propsList.end(), std::back_inserter(list)); - return list; + return + props_->getDebugProps() + + SharedDebugStringConvertibleList { + debugStringConvertibleItem("tag", folly::to(tag_)) + }; } } // namespace react diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index a526fd6986..65f0596937 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -28,7 +28,6 @@ using UnsharedShadowNode = std::shared_ptr; using SharedShadowNodeList = std::vector>; using SharedShadowNodeSharedList = std::shared_ptr; using SharedShadowNodeUnsharedList = std::shared_ptr; -using WeakShadowNode = std::weak_ptr; using ShadowNodeCloneFunction = std::functiongetEventEmitter(), nullptr); TestShadowNode *nodePtr = node.get(); ASSERT_EQ(node->getComponentHandle(), typeid(*nodePtr).hash_code()); - ASSERT_EQ(node->getSourceNode(), nullptr); ASSERT_EQ(node->getChildren()->size(), 0); ASSERT_STREQ(node->getProps()->nativeId.c_str(), "testNativeID"); @@ -55,7 +54,6 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) { ASSERT_EQ(node->getTag(), 9); ASSERT_EQ(node->getRootTag(), 1); ASSERT_EQ(node->getEventEmitter(), nullptr); - ASSERT_EQ(node2->getSourceNode(), node); } TEST(ShadowNodeTest, handleShadowNodeMutation) { @@ -85,35 +83,11 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) { ASSERT_TRUE(node4->getSealed()); // No more mutation after sealing. - EXPECT_THROW(node4->clearSourceNode(), std::runtime_error); + EXPECT_THROW(node4->setLocalData(nullptr), std::runtime_error); auto node5 = std::make_shared(node4, nullptr, nullptr, nullptr); - node5->clearSourceNode(); - ASSERT_EQ(node5->getSourceNode(), nullptr); -} - -TEST(ShadowNodeTest, handleSourceNode) { - auto nodeFirstGeneration = std::make_shared(9, 1, std::make_shared(), nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); - auto nodeSecondGeneration = std::make_shared(nodeFirstGeneration, nullptr, nullptr, nullptr); - auto nodeThirdGeneration = std::make_shared(nodeSecondGeneration, nullptr, nullptr, nullptr); - auto nodeForthGeneration = std::make_shared(nodeThirdGeneration, nullptr, nullptr, nullptr); - - // Ensure established shource nodes structure. - ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeThirdGeneration); - ASSERT_EQ(nodeThirdGeneration->getSourceNode(), nodeSecondGeneration); - ASSERT_EQ(nodeSecondGeneration->getSourceNode(), nodeFirstGeneration); - - // Shallow source node for the forth generation node. - nodeForthGeneration->shallowSourceNode(); - ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeSecondGeneration); - - // Shallow it one more time. - nodeForthGeneration->shallowSourceNode(); - ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeFirstGeneration); - - // Ensure that 3th and 2nd were not affected. - ASSERT_EQ(nodeThirdGeneration->getSourceNode(), nodeSecondGeneration); - ASSERT_EQ(nodeSecondGeneration->getSourceNode(), nodeFirstGeneration); + node5->setLocalData(nullptr); + ASSERT_EQ(node5->getLocalData(), nullptr); } TEST(ShadowNodeTest, handleCloneFunction) {