mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-20 10:24:08 +08:00
Fabric: ShadowNodeFragment::Value - owning counterpart of ShadowNodeFragment
Summary: `ShadowNodeFragment` is very cheap by design because it does not own stuff it contains, so it's great. But... sometimes we need to own the stuff (e.g. to pass it on the other thread), in those cases we can use `ShadowNodeFragment::Value` now. `ShadowNodeFragment::Value` cannot be used alone, it needs to be constructed from `ShadowNodeFragment` and then used as opaque object and then it can be converted to ``ShadowNodeFragment`. We will need it soon. Reviewed By: mdvacca Differential Revision: D15039136 fbshipit-source-id: d40875cac05f4088358d8d418007d17df9ff14f4
This commit is contained in:
committed by
Facebook Github Bot
parent
035e0403bb
commit
2a55939f20
@@ -44,5 +44,21 @@ State::Shared const &ShadowNodeFragment::statePlaceholder() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
using Value = ShadowNodeFragment::Value;
|
||||
|
||||
Value::Value(ShadowNodeFragment const &fragment)
|
||||
: tag_(fragment.tag),
|
||||
surfaceId_(fragment.surfaceId),
|
||||
props_(fragment.props),
|
||||
eventEmitter_(fragment.eventEmitter),
|
||||
children_(fragment.children),
|
||||
localData_(fragment.localData),
|
||||
state_(fragment.state) {}
|
||||
|
||||
Value::operator ShadowNodeFragment() const {
|
||||
return ShadowNodeFragment{
|
||||
tag_, surfaceId_, props_, eventEmitter_, children_, localData_, state_};
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace react {
|
||||
* Note: Most of the fields are `const &` references (essentially just raw
|
||||
* pointers) which means that the Fragment does not copy/store them nor
|
||||
* retain ownership of them.
|
||||
* Use `ShadowNodeFragment::Value` (see below) to create an owning copy of the
|
||||
* fragment content to store or pass the data asynchronously.
|
||||
*/
|
||||
struct ShadowNodeFragment {
|
||||
Tag const tag = tagPlaceholder();
|
||||
@@ -45,6 +47,33 @@ struct ShadowNodeFragment {
|
||||
static ShadowNode::SharedListOfShared const &childrenPlaceholder();
|
||||
static LocalData::Shared const &localDataPlaceholder();
|
||||
static State::Shared const &statePlaceholder();
|
||||
|
||||
/*
|
||||
* `ShadowNodeFragment` is not owning data-structure, it only stores raw
|
||||
* pointers to the data. `ShadowNodeFragment::Value` is a convenient owning
|
||||
* counterpart of that.
|
||||
*/
|
||||
class Value final {
|
||||
public:
|
||||
/*
|
||||
* Creates an object with given `ShadowNodeFragment`.
|
||||
*/
|
||||
Value(ShadowNodeFragment const &fragment);
|
||||
|
||||
/*
|
||||
* Creates a `ShadowNodeFragment` from the object.
|
||||
*/
|
||||
explicit operator ShadowNodeFragment() const;
|
||||
|
||||
private:
|
||||
Tag const tag_;
|
||||
SurfaceId const surfaceId_;
|
||||
Props::Shared const props_;
|
||||
EventEmitter::Shared const eventEmitter_;
|
||||
ShadowNode::SharedListOfShared const children_;
|
||||
LocalData::Shared const localData_;
|
||||
State::Shared const state_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user