Fabric: ShadowNode::getSourceNode() was finally removed
Summary: @public Trivial. Reviewed By: mdvacca Differential Revision: D8753905 fbshipit-source-id: 0a0e351dc0f8ff52e685c7d7dc79d0185cfac711
This commit is contained in:
parent
e78bf723bf
commit
7a7f9601bc
|
@ -10,7 +10,7 @@
|
|||
#include <string>
|
||||
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -49,7 +49,6 @@ ShadowNode::ShadowNode(
|
|||
props_(props ? props : shadowNode->props_),
|
||||
eventEmitter_(eventEmitter ? eventEmitter : shadowNode->eventEmitter_),
|
||||
children_(std::make_shared<SharedShadowNodeList>(*(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<DebugStringConvertibleItem>("tag", folly::to<std::string>(tag_)));
|
||||
|
||||
SharedShadowNode sourceNode = getSourceNode();
|
||||
if (sourceNode) {
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>(
|
||||
"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<std::string>(tag_))
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -28,7 +28,6 @@ using UnsharedShadowNode = std::shared_ptr<ShadowNode>;
|
|||
using SharedShadowNodeList = std::vector<std::shared_ptr<const ShadowNode>>;
|
||||
using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
|
||||
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
|
||||
using WeakShadowNode = std::weak_ptr<const ShadowNode>;
|
||||
|
||||
using ShadowNodeCloneFunction = std::function<SharedShadowNode(
|
||||
const SharedShadowNode &shadowNode,
|
||||
|
@ -81,14 +80,6 @@ public:
|
|||
Tag getTag() const;
|
||||
Tag getRootTag() const;
|
||||
|
||||
/*
|
||||
* Returns the node which was used as a prototype in clone constructor.
|
||||
* The node is held as a weak reference so that the method may return
|
||||
* `nullptr` in cases where the node was constructed using the explicit
|
||||
* constructor or the node was already deallocated.
|
||||
*/
|
||||
SharedShadowNode getSourceNode() const;
|
||||
|
||||
/*
|
||||
* Returns a local data associated with the node.
|
||||
* `LocalData` object might be used for data exchange between native view and
|
||||
|
@ -111,15 +102,6 @@ public:
|
|||
*/
|
||||
void setLocalData(const SharedLocalData &localData);
|
||||
|
||||
/*
|
||||
* Replaces the current source node with its source node.
|
||||
* This method might be used for illuminating side-effects caused by the last
|
||||
* cloning operation which are not desirable from the diffing algorithm
|
||||
* perspective.
|
||||
* The node must be unsealed at this point.
|
||||
*/
|
||||
void shallowSourceNode();
|
||||
|
||||
#pragma mark - Equality
|
||||
|
||||
/*
|
||||
|
@ -145,7 +127,6 @@ protected:
|
|||
SharedProps props_;
|
||||
SharedEventEmitter eventEmitter_;
|
||||
SharedShadowNodeSharedList children_;
|
||||
WeakShadowNode sourceNode_;
|
||||
SharedLocalData localData_;
|
||||
|
||||
private:
|
||||
|
|
|
@ -37,7 +37,6 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
|
|||
ASSERT_EQ(node->getEventEmitter(), 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<TestShadowNode>(node4, nullptr, nullptr, nullptr);
|
||||
node5->clearSourceNode();
|
||||
ASSERT_EQ(node5->getSourceNode(), nullptr);
|
||||
}
|
||||
|
||||
TEST(ShadowNodeTest, handleSourceNode) {
|
||||
auto nodeFirstGeneration = std::make_shared<TestShadowNode>(9, 1, std::make_shared<const TestProps>(), nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr);
|
||||
auto nodeSecondGeneration = std::make_shared<TestShadowNode>(nodeFirstGeneration, nullptr, nullptr, nullptr);
|
||||
auto nodeThirdGeneration = std::make_shared<TestShadowNode>(nodeSecondGeneration, nullptr, nullptr, nullptr);
|
||||
auto nodeForthGeneration = std::make_shared<TestShadowNode>(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) {
|
||||
|
|
Loading…
Reference in New Issue