Avoid use of shared_from_this in StateTarget
Summary: `StateTarget` no longer uses `shared_from_this`, this allows us to remove need for `enable_shared_from_this` I decided to put `state->commit` call inside `ShadowTree.cpp` because I needed to have access to `shared_ptr` of shadow node from outside of the class itself. `state->commit` was originally designed to be only called by `ShadowNode` but this does not seem to be the case anymore since it is called from `UIManager` as well. changelog: [internal] Reviewed By: shergin Differential Revision: D18032532 fbshipit-source-id: 75c874fd04f86adc07bfddbef3a0384e17c2067b
This commit is contained in:
Родитель
32b2020031
Коммит
7796b7e9af
|
@ -224,9 +224,6 @@ void ShadowNode::cloneChildrenIfShared() {
|
|||
|
||||
void ShadowNode::setMounted(bool mounted) const {
|
||||
family_->eventEmitter_->setEnabled(mounted);
|
||||
if (mounted && state_) {
|
||||
state_->commit(*this);
|
||||
}
|
||||
}
|
||||
|
||||
AncestorList ShadowNode::getAncestors(
|
||||
|
|
|
@ -40,8 +40,7 @@ using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
|
|||
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
|
||||
|
||||
class ShadowNode : public virtual Sealable,
|
||||
public virtual DebugStringConvertible,
|
||||
public std::enable_shared_from_this<ShadowNode> {
|
||||
public virtual DebugStringConvertible {
|
||||
public:
|
||||
using Shared = std::shared_ptr<ShadowNode const>;
|
||||
using Weak = std::weak_ptr<ShadowNode const>;
|
||||
|
|
|
@ -26,7 +26,7 @@ State::State(State const &state) : stateCoordinator_(state.stateCoordinator_){};
|
|||
State::State(StateCoordinator::Shared const &stateCoordinator)
|
||||
: stateCoordinator_(stateCoordinator){};
|
||||
|
||||
void State::commit(const ShadowNode &shadowNode) const {
|
||||
void State::commit(std::shared_ptr<ShadowNode const> const &shadowNode) const {
|
||||
stateCoordinator_->setTarget(StateTarget{shadowNode});
|
||||
}
|
||||
|
||||
|
|
|
@ -40,18 +40,13 @@ class State {
|
|||
virtual void updateState(folly::dynamic data) const;
|
||||
#endif
|
||||
|
||||
void commit(std::shared_ptr<ShadowNode const> const &shadowNode) const;
|
||||
|
||||
protected:
|
||||
StateCoordinator::Shared stateCoordinator_;
|
||||
|
||||
private:
|
||||
friend class ShadowNode;
|
||||
friend class StateCoordinator;
|
||||
friend class UIManager;
|
||||
|
||||
/*
|
||||
* Must be used by `ShadowNode` *only*.
|
||||
*/
|
||||
void commit(const ShadowNode &shadowNode) const;
|
||||
|
||||
/*
|
||||
* Indicates that the state was committed once and then was replaced by a
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace react {
|
|||
|
||||
StateTarget::StateTarget() : shadowNode_(nullptr) {}
|
||||
|
||||
StateTarget::StateTarget(const ShadowNode &shadowNode)
|
||||
: shadowNode_(shadowNode.shared_from_this()) {}
|
||||
StateTarget::StateTarget(std::shared_ptr<ShadowNode const> shadowNode)
|
||||
: shadowNode_(shadowNode) {}
|
||||
|
||||
StateTarget::operator bool() const {
|
||||
return (bool)shadowNode_;
|
||||
|
|
|
@ -29,7 +29,7 @@ class StateTarget {
|
|||
/*
|
||||
* Creates a target which points to a given `ShadowNode`.
|
||||
*/
|
||||
explicit StateTarget(const ShadowNode &shadowNode);
|
||||
explicit StateTarget(std::shared_ptr<ShadowNode const> shadowNode);
|
||||
|
||||
/*
|
||||
* Copyable and moveable.
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static void CommitState(ShadowNode::Shared const &shadowNode) {
|
||||
auto state = shadowNode->getState();
|
||||
if (state) {
|
||||
state->commit(shadowNode);
|
||||
}
|
||||
}
|
||||
|
||||
static void updateMountedFlag(
|
||||
const SharedShadowNodeList &oldChildren,
|
||||
const SharedShadowNodeList &newChildren) {
|
||||
|
@ -58,6 +65,7 @@ static void updateMountedFlag(
|
|||
}
|
||||
|
||||
newChild->setMounted(true);
|
||||
CommitState(newChild);
|
||||
oldChild->setMounted(false);
|
||||
|
||||
updateMountedFlag(oldChild->getChildren(), newChild->getChildren());
|
||||
|
@ -69,6 +77,7 @@ static void updateMountedFlag(
|
|||
for (index = lastIndexAfterFirstStage; index < newChildren.size(); index++) {
|
||||
const auto &newChild = newChildren[index];
|
||||
newChild->setMounted(true);
|
||||
CommitState(newChild);
|
||||
updateMountedFlag({}, newChild->getChildren());
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ SharedShadowNode UIManager::createNode(
|
|||
// explicitly associate the ShadowNode with the State here so that updateState
|
||||
// is always safe and effectful.
|
||||
if (state) {
|
||||
state->commit(*shadowNode);
|
||||
state->commit(shadowNode);
|
||||
}
|
||||
|
||||
if (delegate_) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче