Fabric: Introducting ShadowNode.sourceNode, the node used in copy-constructor

Summary: We will need this later in the diffing alogrithm.

Reviewed By: fkgozali

Differential Revision: D7330337

fbshipit-source-id: 3da44a62e4d5f30deed28b18a5779544153244f3
This commit is contained in:
Valentin Shergin 2018-03-19 16:51:39 -07:00 committed by Facebook Github Bot
parent 39383d1189
commit b808bfdce2
2 changed files with 23 additions and 4 deletions

View File

@ -41,7 +41,8 @@ ShadowNode::ShadowNode(
tag_(shadowNode->tag_), tag_(shadowNode->tag_),
instanceHandle_(shadowNode->instanceHandle_), instanceHandle_(shadowNode->instanceHandle_),
props_(props ? props : shadowNode->props_), props_(props ? props : shadowNode->props_),
children_(children ? children : shadowNode->children_) {} children_(children ? children : shadowNode->children_),
sourceNode_(shadowNode) {}
#pragma mark - Getters #pragma mark - Getters
@ -57,7 +58,9 @@ Tag ShadowNode::getTag() const {
return tag_; return tag_;
} }
#pragma mark - Mutating Methods SharedShadowNode ShadowNode::getSourceNode() const {
return sourceNode_;
}
void ShadowNode::sealRecursive() const { void ShadowNode::sealRecursive() const {
if (getSealed()) { if (getSealed()) {
@ -73,6 +76,8 @@ void ShadowNode::sealRecursive() const {
} }
} }
#pragma mark - Mutating Methods
void ShadowNode::appendChild(const SharedShadowNode &child) { void ShadowNode::appendChild(const SharedShadowNode &child) {
ensureUnsealed(); ensureUnsealed();
@ -95,6 +100,11 @@ void ShadowNode::replaceChild(const SharedShadowNode &oldChild, const SharedShad
children_ = std::make_shared<const SharedShadowNodeList>(nonConstChildrenCopy); children_ = std::make_shared<const SharedShadowNodeList>(nonConstChildrenCopy);
} }
void ShadowNode::clearSourceNode() {
ensureUnsealed();
sourceNode_ = nullptr;
}
#pragma mark - DebugStringConvertible #pragma mark - DebugStringConvertible
std::string ShadowNode::getDebugName() const { std::string ShadowNode::getDebugName() const {
@ -127,6 +137,13 @@ SharedDebugStringConvertibleList ShadowNode::getDebugProps() const {
list.push_back(std::make_shared<DebugStringConvertibleItem>("handle", std::to_string((size_t)instanceHandle_))); list.push_back(std::make_shared<DebugStringConvertibleItem>("handle", std::to_string((size_t)instanceHandle_)));
} }
if (sourceNode_) {
list.push_back(std::make_shared<DebugStringConvertibleItem>(
"source",
sourceNode_->getDebugDescription({.maximumDepth = 1, .format = false})
));
}
SharedDebugStringConvertibleList propsList = props_->getDebugProps(); SharedDebugStringConvertibleList propsList = props_->getDebugProps();
std::move(propsList.begin(), propsList.end(), std::back_inserter(list)); std::move(propsList.begin(), propsList.end(), std::back_inserter(list));
return list; return list;

View File

@ -55,13 +55,14 @@ public:
SharedShadowNodeSharedList getChildren() const; SharedShadowNodeSharedList getChildren() const;
SharedProps getProps() const; SharedProps getProps() const;
Tag getTag() const; Tag getTag() const;
SharedShadowNode getSourceNode() const;
void sealRecursive() const;
#pragma mark - Mutating Methods #pragma mark - Mutating Methods
void sealRecursive() const;
void appendChild(const SharedShadowNode &child); void appendChild(const SharedShadowNode &child);
void replaceChild(const SharedShadowNode &oldChild, const SharedShadowNode &newChild); void replaceChild(const SharedShadowNode &oldChild, const SharedShadowNode &newChild);
void clearSourceNode();
#pragma mark - DebugStringConvertible #pragma mark - DebugStringConvertible
@ -76,6 +77,7 @@ protected:
InstanceHandle instanceHandle_; InstanceHandle instanceHandle_;
SharedProps props_; SharedProps props_;
SharedShadowNodeSharedList children_; SharedShadowNodeSharedList children_;
SharedShadowNode sourceNode_;
}; };
} // namespace react } // namespace react