diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 2313be859..c2da0db17 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -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 { diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index 2efadda40..f03acb107 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -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;