From e0e9c1549e9f4bf15060dd40764c838865fa593f Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 6 Jul 2018 14:34:38 -0700 Subject: [PATCH] Fabric: Improved prettyprinting of TreeMutationInstruction Summary: @public Quite trivial... and nice. Reviewed By: mdvacca Differential Revision: D8709951 fbshipit-source-id: 63e53eb85361fe3a0a0ecd7f21bf4c7db049d5bf --- .../uimanager/TreeMutationInstruction.cpp | 17 ++++++++++++++++- .../fabric/uimanager/TreeMutationInstruction.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp b/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp index c5f074537..630e13202 100644 --- a/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp +++ b/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp @@ -150,6 +150,21 @@ std::string TreeMutationInstruction::getDebugName() const { } }; +std::string TreeMutationInstruction::getDebugValue() const { + switch (type_) { + case Creation: + return "[*" + folly::to(newChildNode_->getTag()) + "]"; + case Deletion: + return "[~" + folly::to(oldChildNode_->getTag()) + "]"; + case Insertion: + return "[" + folly::to(newChildNode_->getTag()) + "->" + folly::to(parentNode_->getTag()) + "]"; + case Removal: + return "[" + folly::to(oldChildNode_->getTag()) + "<~" + folly::to(parentNode_->getTag()) + "]"; + case Replacement: + return "[=" + folly::to(oldChildNode_->getTag()) + "]"; + } +}; + SharedDebugStringConvertibleList TreeMutationInstruction::getDebugProps() const { DebugStringConvertibleOptions options = {.maximumDepth = 1, .format = false}; @@ -176,7 +191,7 @@ SharedDebugStringConvertibleList TreeMutationInstruction::getDebugProps() const }; case Replacement: return SharedDebugStringConvertibleList { - std::make_shared("parentNode", parentNode_->getDebugDescription(options)), + std::make_shared("parentNode", parentNode_ ? parentNode_->getDebugDescription(options) : "nullptr"), std::make_shared("oldChildNode", oldChildNode_->getDebugDescription(options)), std::make_shared("newChildNode", newChildNode_->getDebugDescription(options)), std::make_shared("index", folly::to(index_)) diff --git a/ReactCommon/fabric/uimanager/TreeMutationInstruction.h b/ReactCommon/fabric/uimanager/TreeMutationInstruction.h index 920cd27f8..c27e6f71f 100644 --- a/ReactCommon/fabric/uimanager/TreeMutationInstruction.h +++ b/ReactCommon/fabric/uimanager/TreeMutationInstruction.h @@ -96,6 +96,7 @@ public: #pragma mark - DebugStringConvertible std::string getDebugName() const override; + std::string getDebugValue() const override; SharedDebugStringConvertibleList getDebugProps() const override; private: