From 33112a1c20a053934536f0c78f3d1d3f951446eb Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 28 Aug 2019 21:08:27 -0700 Subject: [PATCH] Fabric: Making `State::getMostRecentState` public Summary: That was always part of design, that's okay to get a newer state from any other state. We will need it in the future diffs. Reviewed By: sammy-SC Differential Revision: D17053429 fbshipit-source-id: 2174e7d6e3a1ed231f7f6e238d216d0b09ec8797 --- ReactCommon/fabric/core/shadownode/ShadowNode.cpp | 2 +- ReactCommon/fabric/core/state/State.cpp | 2 +- ReactCommon/fabric/core/state/State.h | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index c8b4e5967a..59b3629f3a 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -122,7 +122,7 @@ const State::Shared &ShadowNode::getState() const { State::Shared ShadowNode::getMostRecentState() const { if (state_) { - auto commitedState = state_->getCommitedState(); + auto commitedState = state_->getMostRecentState(); // Commited state can be `null` in case if no one node was commited yet; // in this case we return own `state`. diff --git a/ReactCommon/fabric/core/state/State.cpp b/ReactCommon/fabric/core/state/State.cpp index 7bc51a9e04..9c6f03662c 100644 --- a/ReactCommon/fabric/core/state/State.cpp +++ b/ReactCommon/fabric/core/state/State.cpp @@ -30,7 +30,7 @@ void State::commit(const ShadowNode &shadowNode) const { stateCoordinator_->setTarget(StateTarget{shadowNode}); } -State::Shared State::getCommitedState() const { +State::Shared State::getMostRecentState() const { auto target = stateCoordinator_->getTarget(); return target ? target.getShadowNode().getState() : ShadowNodeFragment::statePlaceholder(); diff --git a/ReactCommon/fabric/core/state/State.h b/ReactCommon/fabric/core/state/State.h index 6ab0c921af..6587159280 100644 --- a/ReactCommon/fabric/core/state/State.h +++ b/ReactCommon/fabric/core/state/State.h @@ -28,6 +28,13 @@ class State { explicit State(StateCoordinator::Shared const &stateCoordinator); virtual ~State() = default; + /* +   * Returns a momentary value of the most recently committed state +   * associated with a family of nodes which this state belongs to. +   * Sequential calls might return different values. + */ + State::Shared getMostRecentState() const; + #ifdef ANDROID virtual const folly::dynamic getDynamic() const; virtual void updateState(folly::dynamic data) const; @@ -45,11 +52,6 @@ class State { */ void commit(const ShadowNode &shadowNode) const; - /* - * Must be used by `ShadowNode` *only*. - */ - State::Shared getCommitedState() const; - /* * Indicates that the state was committed once and then was replaced by a * newer one.