mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7796b7e9af
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
58 lines
1.2 KiB
C++
58 lines
1.2 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class ShadowNode;
|
|
|
|
/*
|
|
* Represents an entity that receives state update.
|
|
* Practically, just a wrapper around shared a pointer to ShadowNode. We need
|
|
* this mostly to avoid circular dependency problems.
|
|
*/
|
|
class StateTarget {
|
|
public:
|
|
/*
|
|
* Creates an empty target.
|
|
*/
|
|
explicit StateTarget();
|
|
|
|
/*
|
|
* Creates a target which points to a given `ShadowNode`.
|
|
*/
|
|
explicit StateTarget(std::shared_ptr<ShadowNode const> shadowNode);
|
|
|
|
/*
|
|
* Copyable and moveable.
|
|
*/
|
|
StateTarget(const StateTarget &other) = default;
|
|
StateTarget &operator=(const StateTarget &other) = default;
|
|
StateTarget(StateTarget &&other) noexcept = default;
|
|
StateTarget &operator=(StateTarget &&other) = default;
|
|
|
|
/*
|
|
* Returns `true` is the target is not empty.
|
|
*/
|
|
operator bool() const;
|
|
|
|
/*
|
|
* Returns a reference to a stored `ShadowNode`.
|
|
*/
|
|
const ShadowNode &getShadowNode() const;
|
|
|
|
private:
|
|
std::shared_ptr<ShadowNode const> shadowNode_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|