Skip to content

Commit

Permalink
Fabric: Introducting ShadowNode.sourceNode, the node used in copy-c…
Browse files Browse the repository at this point in the history
…onstructor

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

Reviewed By: fkgozali

Differential Revision: D7330337

fbshipit-source-id: 3da44a62e4d5f30deed28b18a5779544153244f3
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 20, 2018
1 parent 39383d1 commit b808bfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 19 additions & 2 deletions ReactCommon/fabric/core/shadownode/ShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ ShadowNode::ShadowNode(
tag_(shadowNode->tag_),
instanceHandle_(shadowNode->instanceHandle_),
props_(props ? props : shadowNode->props_),
children_(children ? children : shadowNode->children_) {}
children_(children ? children : shadowNode->children_),
sourceNode_(shadowNode) {}

#pragma mark - Getters

Expand All @@ -57,7 +58,9 @@ Tag ShadowNode::getTag() const {
return tag_;
}

#pragma mark - Mutating Methods
SharedShadowNode ShadowNode::getSourceNode() const {
return sourceNode_;
}

void ShadowNode::sealRecursive() const {
if (getSealed()) {
Expand All @@ -73,6 +76,8 @@ void ShadowNode::sealRecursive() const {
}
}

#pragma mark - Mutating Methods

void ShadowNode::appendChild(const SharedShadowNode &child) {
ensureUnsealed();

Expand All @@ -95,6 +100,11 @@ void ShadowNode::replaceChild(const SharedShadowNode &oldChild, const SharedShad
children_ = std::make_shared<const SharedShadowNodeList>(nonConstChildrenCopy);
}

void ShadowNode::clearSourceNode() {
ensureUnsealed();
sourceNode_ = nullptr;
}

#pragma mark - DebugStringConvertible

std::string ShadowNode::getDebugName() const {
Expand Down Expand Up @@ -127,6 +137,13 @@ SharedDebugStringConvertibleList ShadowNode::getDebugProps() const {
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();
std::move(propsList.begin(), propsList.end(), std::back_inserter(list));
return list;
Expand Down
6 changes: 4 additions & 2 deletions ReactCommon/fabric/core/shadownode/ShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ class ShadowNode:
SharedShadowNodeSharedList getChildren() const;
SharedProps getProps() const;
Tag getTag() const;
SharedShadowNode getSourceNode() const;
void sealRecursive() const;

#pragma mark - Mutating Methods

void sealRecursive() const;

void appendChild(const SharedShadowNode &child);
void replaceChild(const SharedShadowNode &oldChild, const SharedShadowNode &newChild);
void clearSourceNode();

#pragma mark - DebugStringConvertible

Expand All @@ -76,6 +77,7 @@ class ShadowNode:
InstanceHandle instanceHandle_;
SharedProps props_;
SharedShadowNodeSharedList children_;
SharedShadowNode sourceNode_;
};

} // namespace react
Expand Down

0 comments on commit b808bfd

Please sign in to comment.