Fabric: Fixed order of instructions in Differentiator

Summary:
@public
Previously Differentiator might generate some `remove` instruction that refers to already `deleted` node. That diffs fixes that.

Reviewed By: fkgozali

Differential Revision: D8596536

fbshipit-source-id: 88117962f93e52167dbcb6525f2cc36758a367e7
This commit is contained in:
Valentin Shergin 2018-06-22 15:33:30 -07:00 committed by Facebook Github Bot
parent b1c4fee6af
commit 250cc3c594
1 changed files with 7 additions and 6 deletions

View File

@ -39,6 +39,7 @@ static void calculateMutationInstructions(
TreeMutationInstructionList removeInstructions = {};
TreeMutationInstructionList replaceInstructions = {};
TreeMutationInstructionList downwardInstructions = {};
TreeMutationInstructionList destructionDownwardInstructions = {};
// Stage 1: Collectings Updates
for (index = 0; index < oldChildNodes->size() && index < newChildNodes->size(); index++) {
@ -62,7 +63,7 @@ static void calculateMutationInstructions(
}
calculateMutationInstructions(
downwardInstructions,
*(newChildNode->getChildren()->size() ? &downwardInstructions : &destructionDownwardInstructions),
oldChildNode,
oldChildNode->getChildren(),
newChildNode->getChildren()
@ -90,7 +91,7 @@ static void calculateMutationInstructions(
newChildSourceNode ? newChildSourceNode->getChildren() : ShadowNode::emptySharedShadowNodeSharedList();
calculateMutationInstructions(
downwardInstructions,
*(newChildNode->getChildren()->size() ? &downwardInstructions : &destructionDownwardInstructions),
newChildNode,
newChildSourceChildNodes,
newChildNode->getChildren()
@ -125,7 +126,7 @@ static void calculateMutationInstructions(
);
calculateMutationInstructions(
downwardInstructions,
destructionDownwardInstructions,
oldChildNode,
oldChildNode->getChildren(),
ShadowNode::emptySharedShadowNodeSharedList()
@ -149,15 +150,15 @@ static void calculateMutationInstructions(
}
// All instructions in an optimal order:
instructions.insert(instructions.end(), destructionDownwardInstructions.begin(), destructionDownwardInstructions.end());
instructions.insert(instructions.end(), replaceInstructions.begin(), replaceInstructions.end());
instructions.insert(instructions.end(), removeInstructions.begin(), removeInstructions.end());
instructions.insert(instructions.end(), deleteInstructions.begin(), deleteInstructions.end());
instructions.insert(instructions.end(), createInstructions.begin(), createInstructions.end());
instructions.insert(instructions.end(), insertInstructions.begin(), insertInstructions.end());
instructions.insert(instructions.end(), downwardInstructions.begin(), downwardInstructions.end());
instructions.insert(instructions.end(), insertInstructions.begin(), insertInstructions.end());
instructions.insert(instructions.end(), deleteInstructions.begin(), deleteInstructions.end());
}
void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode oldRootShadowNode,