Files
react-native/ReactCommon/fabric/core/state/State.cpp
T
Samuel SuslaandFacebook Github Bot 7796b7e9af 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
2019-10-21 17:18:36 -07:00

55 lines
1.5 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "State.h"
#include <glog/logging.h>
#include <react/core/ShadowNode.h>
#include <react/core/ShadowNodeFragment.h>
#include <react/core/State.h>
#include <react/core/StateTarget.h>
#include <react/core/StateUpdate.h>
#ifdef ANDROID
#include <folly/dynamic.h>
#endif
namespace facebook {
namespace react {
State::State(State const &state) : stateCoordinator_(state.stateCoordinator_){};
State::State(StateCoordinator::Shared const &stateCoordinator)
: stateCoordinator_(stateCoordinator){};
void State::commit(std::shared_ptr<ShadowNode const> const &shadowNode) const {
stateCoordinator_->setTarget(StateTarget{shadowNode});
}
State::Shared State::getMostRecentState() const {
auto target = stateCoordinator_->getTarget();
return target ? target.getShadowNode().getState()
: ShadowNodeFragment::statePlaceholder();
}
#ifdef ANDROID
const folly::dynamic State::getDynamic() const {
LOG(FATAL)
<< "State::getDynamic should never be called (some virtual method of a concrete implementation should be called instead)";
abort();
return folly::dynamic::object();
}
void State::updateState(folly::dynamic data) const {
LOG(FATAL)
<< "State::updateState should never be called (some virtual method of a concrete implementation should be called instead).";
abort();
}
#endif
} // namespace react
} // namespace facebook