Fabric: Improved signature of calculateMutationInstructions

Summary: Apparently, `calculateMutationInstructions` must also produce mutation instructions for root node as well. To make it possible we have to change the signature of the function and weak some restrictions in TreeMutationInstruction.

Reviewed By: fkgozali

Differential Revision: D7958248

fbshipit-source-id: 4109a6bce3a77f7eb89157201fd0e80f98487dbd
This commit is contained in:
Valentin Shergin authored and Facebook Github Bot committed 2018-05-15 23:58:59 -07:00
1 parent 10c5368c37
commit 57d69772b7
4 files changed
+32 -8

No files matched your search

@@ -5,7 +5,7 @@
namespace facebook {
namespace react {
void calculateMutationInstructions(
static void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode parentNode,
SharedShadowNodeSharedList oldChildNodes,
@@ -154,5 +154,33 @@ void calculateMutationInstructions(
instructions.insert(instructions.end(), downwardInstructions.begin(), downwardInstructions.end());
}
void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode oldRootShadowNode,
SharedShadowNode newRootShadowNode
) {
// Root shadow nodes must have same tag.
assert(oldRootShadowNode->getTag() == newRootShadowNode->getTag());
if (*oldRootShadowNode != *newRootShadowNode) {
instructions.push_back(
TreeMutationInstruction::Replace(
nullptr,
oldRootShadowNode,
newRootShadowNode,
-1
)
);
}
calculateMutationInstructions(
instructions,
oldRootShadowNode,
oldRootShadowNode->getChildren(),
newRootShadowNode->getChildren()
);
}
} // namespace react
} // namespace facebook
@@ -15,9 +15,8 @@ namespace react {
*/
void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode parentNode,
SharedShadowNodeSharedList oldChildNodes,
SharedShadowNodeSharedList newChildNodes
SharedShadowNode oldNode,
SharedShadowNode newNode
);
} // namespace react
+1 -2
View File
@@ -69,8 +69,7 @@ void ShadowTree::complete(UnsharedRootShadowNode newRootShadowNode) {
calculateMutationInstructions(
instructions,
oldRootShadowNode,
oldRootShadowNode->ShadowNode::getChildren(),
newRootShadowNode->ShadowNode::getChildren()
newRootShadowNode
);
if (commit(newRootShadowNode)) {
@@ -82,10 +82,8 @@ const TreeMutationInstruction TreeMutationInstruction::Replace(
SharedShadowNode newChildNode,
int index
) {
assert(parentNode);
assert(oldChildNode);
assert(newChildNode);
assert(index != -1);
return TreeMutationInstruction(
Replacement,