Fix ShadowNode.stateRevision value assignment

Summary:
# Problem

We calculate `stateRevision_` in constructor from children, but children change after shadowNode is initialised and before it is sealed. So the `stateRevision_` we calculate in constructor can be incorrect.

# Solution

Recalculate `stateRevision_` whenever children change. This can happen in two methods `ShadowNode::replaceChild` and `ShadowNode::appendChild`. This diff implements this solution.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D19813840

fbshipit-source-id: 8fc3b6601e4618f4ee5b322eebc230e0bbb92e3a
This commit is contained in:
Samuel Susla
2020-02-10 15:31:46 -08:00
committed by Facebook Github Bot
parent 2c1913f0b3
commit bfa00a5d62
2 changed files with 8 additions and 5 deletions
@@ -178,6 +178,8 @@ void ShadowNode::appendChild(const ShadowNode::Shared &child) {
nonConstChildren->push_back(child);
child->family_->setParent(family_);
stateRevision_ += child->getStateRevision();
}
void ShadowNode::replaceChild(
@@ -186,6 +188,8 @@ void ShadowNode::replaceChild(
int suggestedIndex) {
ensureUnsealed();
stateRevision_ += newChild->getStateRevision() - oldChild.getStateRevision();
cloneChildrenIfShared();
newChild->family_->setParent(family_);
@@ -171,12 +171,11 @@ class ShadowNode : public virtual Sealable,
friend ShadowNodeFamily;
/**
* This number is deterministically, statelessly recomputable (it's dependent
* only on the immutable properties stored in this class). It tells us the
* version of the state of the entire subtree, including this component and
* all descendants.
* This number is deterministically, statelessly recomputable . It tells us
* the version of the state of the entire subtree, including this component
* and all descendants.
*/
int const stateRevision_;
int stateRevision_;
/*
* Clones the list of children (and creates a new `shared_ptr` to it) if