Fabric: Equality operators for ShadowNode

Summary: Test for equality will be used in ShadowNode Tree Diffing algorithm.

Reviewed By: fkgozali

Differential Revision: D7467802

fbshipit-source-id: 5383add9fc7d7e4a772ca16e70a54f7e0c36823a
This commit is contained in:
Valentin Shergin 2018-04-10 12:45:30 -07:00 committed by Facebook Github Bot
parent 4ebb57b0ba
commit 1f969d3440
2 changed files with 27 additions and 0 deletions

View File

@ -116,6 +116,21 @@ void ShadowNode::clearSourceNode() {
sourceNode_.reset();
}
#pragma mark - Equality
bool ShadowNode::operator==(const ShadowNode& rhs) const {
// Note: Child nodes are not considered as part of instance's value
// and/or identity.
return
tag_ == rhs.tag_ &&
rootTag_ == rhs.rootTag_ &&
props_ == rhs.props_;
}
bool ShadowNode::operator!=(const ShadowNode& rhs) const {
return !(*this == rhs);
}
#pragma mark - DebugStringConvertible
std::string ShadowNode::getDebugName() const {

View File

@ -67,6 +67,18 @@ public:
void replaceChild(const SharedShadowNode &oldChild, const SharedShadowNode &newChild);
void clearSourceNode();
#pragma mark - Equality
/*
* Equality operators.
* Use this to compare `ShadowNode`s values for equality (and non-equality).
* Same values indicates that nodes must not produce mutation instructions
* during tree diffing process.
* Child nodes are not considered as part of the value.
*/
virtual bool operator==(const ShadowNode& rhs) const;
virtual bool operator!=(const ShadowNode& rhs) const;
#pragma mark - DebugStringConvertible
std::string getDebugName() const override;