Fabric: Remove tag from ShadowNodeFragment

Summary:
As part of the plan is splitting `ShadowNodeFragment` into two parts. `ShadowNodeFamilyFragment` is already in place. This diff removes use of `ShadowNodeFragment::tag` and goes over all call sites to change it to `ShadowNodeFamilyFragment::tag`.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19115781

fbshipit-source-id: 6ab3464a063c220d0924bf5a69b75449ca178650
This commit is contained in:
Samuel Susla 2019-12-19 13:45:35 -08:00 коммит произвёл Facebook Github Bot
Родитель 90874d974f
Коммит f9c5bf8bee
13 изменённых файлов: 116 добавлений и 122 удалений

Просмотреть файл

@ -41,7 +41,6 @@ RootShadowNode::Unshared RootShadowNode::clone(
auto newRootShadowNode = std::make_shared<RootShadowNode>( auto newRootShadowNode = std::make_shared<RootShadowNode>(
*this, *this,
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
}); });
@ -75,7 +74,6 @@ RootShadowNode::Unshared RootShadowNode::clone(
children[childIndex] = childNode; children[childIndex] = childNode;
childNode = parentNode.clone({ childNode = parentNode.clone({
ShadowNodeFragment::tagPlaceholder(),
ShadowNodeFragment::surfaceIdPlaceholder(), ShadowNodeFragment::surfaceIdPlaceholder(),
ShadowNodeFragment::propsPlaceholder(), ShadowNodeFragment::propsPlaceholder(),
ShadowNodeFragment::eventEmitterPlaceholder(), ShadowNodeFragment::eventEmitterPlaceholder(),

Просмотреть файл

@ -78,7 +78,8 @@ class ComponentDescriptor {
* Creates a new `ShadowNode` of a particular component type. * Creates a new `ShadowNode` of a particular component type.
*/ */
virtual SharedShadowNode createShadowNode( virtual SharedShadowNode createShadowNode(
const ShadowNodeFragment &fragment) const = 0; const ShadowNodeFragment &fragment,
ShadowNodeFamilyFragment const &familyFragment) const = 0;
/* /*
* Clones a `ShadowNode` with optionally new `props` and/or `children`. * Clones a `ShadowNode` with optionally new `props` and/or `children`.

Просмотреть файл

@ -66,15 +66,13 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
} }
SharedShadowNode createShadowNode( SharedShadowNode createShadowNode(
const ShadowNodeFragment &fragment) const override { const ShadowNodeFragment &fragment,
ShadowNodeFamilyFragment const &familyFragment) const override {
assert(std::dynamic_pointer_cast<const ConcreteProps>(fragment.props)); assert(std::dynamic_pointer_cast<const ConcreteProps>(fragment.props));
assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>( assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>(
fragment.eventEmitter)); fragment.eventEmitter));
auto family = std::make_shared<ShadowNodeFamily const>( auto family = std::make_shared<ShadowNodeFamily>(familyFragment, *this);
ShadowNodeFamilyFragment{
fragment.tag, fragment.surfaceId, fragment.eventEmitter},
*this);
auto shadowNode = auto shadowNode =
std::make_shared<ShadowNodeT>(fragment, family, getTraits()); std::make_shared<ShadowNodeT>(fragment, family, getTraits());

Просмотреть файл

@ -74,8 +74,7 @@ ShadowNode::ShadowNode(
: sourceShadowNode.getMostRecentState()), : sourceShadowNode.getMostRecentState()),
family_(sourceShadowNode.family_), family_(sourceShadowNode.family_),
traits_(sourceShadowNode.traits_) { traits_(sourceShadowNode.traits_) {
// `tag`, `surfaceId`, and `eventEmitter` cannot be changed with cloning. // `surfaceId`, and `eventEmitter` cannot be changed with cloning.
assert(fragment.tag == ShadowNodeFragment::tagPlaceholder());
assert(fragment.surfaceId == ShadowNodeFragment::surfaceIdPlaceholder()); assert(fragment.surfaceId == ShadowNodeFragment::surfaceIdPlaceholder());
assert( assert(
fragment.eventEmitter == ShadowNodeFragment::eventEmitterPlaceholder()); fragment.eventEmitter == ShadowNodeFragment::eventEmitterPlaceholder());

Просмотреть файл

@ -10,10 +10,6 @@
namespace facebook { namespace facebook {
namespace react { namespace react {
Tag const ShadowNodeFragment::tagPlaceholder() {
return 0;
}
SurfaceId const ShadowNodeFragment::surfaceIdPlaceholder() { SurfaceId const ShadowNodeFragment::surfaceIdPlaceholder() {
return 0; return 0;
} }
@ -47,8 +43,7 @@ State::Shared const &ShadowNodeFragment::statePlaceholder() {
using Value = ShadowNodeFragment::Value; using Value = ShadowNodeFragment::Value;
Value::Value(ShadowNodeFragment const &fragment) Value::Value(ShadowNodeFragment const &fragment)
: tag_(fragment.tag), : surfaceId_(fragment.surfaceId),
surfaceId_(fragment.surfaceId),
props_(fragment.props), props_(fragment.props),
eventEmitter_(fragment.eventEmitter), eventEmitter_(fragment.eventEmitter),
children_(fragment.children), children_(fragment.children),
@ -57,7 +52,7 @@ Value::Value(ShadowNodeFragment const &fragment)
Value::operator ShadowNodeFragment() const { Value::operator ShadowNodeFragment() const {
return ShadowNodeFragment{ return ShadowNodeFragment{
tag_, surfaceId_, props_, eventEmitter_, children_, localData_, state_}; surfaceId_, props_, eventEmitter_, children_, localData_, state_};
} }
} // namespace react } // namespace react

Просмотреть файл

@ -27,7 +27,6 @@ namespace react {
* fragment content to store or pass the data asynchronously. * fragment content to store or pass the data asynchronously.
*/ */
struct ShadowNodeFragment { struct ShadowNodeFragment {
Tag const tag = tagPlaceholder();
SurfaceId const surfaceId = surfaceIdPlaceholder(); SurfaceId const surfaceId = surfaceIdPlaceholder();
Props::Shared const &props = propsPlaceholder(); Props::Shared const &props = propsPlaceholder();
EventEmitter::Shared const &eventEmitter = eventEmitterPlaceholder(); EventEmitter::Shared const &eventEmitter = eventEmitterPlaceholder();
@ -40,7 +39,6 @@ struct ShadowNodeFragment {
* Use as default arguments as an indication that the field does not need to * Use as default arguments as an indication that the field does not need to
* be changed. * be changed.
*/ */
static Tag const tagPlaceholder();
static SurfaceId const surfaceIdPlaceholder(); static SurfaceId const surfaceIdPlaceholder();
static Props::Shared const &propsPlaceholder(); static Props::Shared const &propsPlaceholder();
static EventEmitter::Shared const &eventEmitterPlaceholder(); static EventEmitter::Shared const &eventEmitterPlaceholder();
@ -66,7 +64,6 @@ struct ShadowNodeFragment {
explicit operator ShadowNodeFragment() const; explicit operator ShadowNodeFragment() const;
private: private:
Tag const tag_;
SurfaceId const surfaceId_; SurfaceId const surfaceId_;
Props::Shared const props_; Props::Shared const props_;
EventEmitter::Shared const eventEmitter_; EventEmitter::Shared const eventEmitter_;

Просмотреть файл

@ -22,12 +22,18 @@ TEST(ComponentDescriptorTest, createShadowNode) {
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc")); const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw); SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node = descriptor->createShadowNode(ShadowNodeFragment{
/* .tag = */ 9, SharedShadowNode node = descriptor->createShadowNode(
/* .surfaceId = */ 1, ShadowNodeFragment{
/* .props = */ props, /* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9), /* .props = */ props,
}); /* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
},
ShadowNodeFamilyFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
ASSERT_EQ(node->getComponentHandle(), TestShadowNode::Handle()); ASSERT_EQ(node->getComponentHandle(), TestShadowNode::Handle());
ASSERT_STREQ(node->getComponentName(), TestShadowNode::Name()); ASSERT_STREQ(node->getComponentName(), TestShadowNode::Name());
@ -44,12 +50,17 @@ TEST(ComponentDescriptorTest, cloneShadowNode) {
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc")); const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw); SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node = descriptor->createShadowNode(ShadowNodeFragment{ SharedShadowNode node = descriptor->createShadowNode(
/* .tag = */ 9, ShadowNodeFragment{
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9), /* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
}); },
ShadowNodeFamilyFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
SharedShadowNode cloned = descriptor->cloneShadowNode(*node, {}); SharedShadowNode cloned = descriptor->cloneShadowNode(*node, {});
ASSERT_STREQ(cloned->getComponentName(), "Test"); ASSERT_STREQ(cloned->getComponentName(), "Test");
@ -65,24 +76,40 @@ TEST(ComponentDescriptorTest, appendChild) {
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc")); const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw); SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node1 = descriptor->createShadowNode(ShadowNodeFragment{
/* .tag = */ 1, SharedShadowNode node1 = descriptor->createShadowNode(
/* .surfaceId = */ 1, ShadowNodeFragment{
/* .props = */ props, /* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 1), /* .props = */ props,
}); /* .eventEmitter = */ descriptor->createEventEmitter(0, 1),
SharedShadowNode node2 = descriptor->createShadowNode(ShadowNodeFragment{ },
/* .tag = */ 2, ShadowNodeFamilyFragment{
/* .surfaceId = */ 1, /* .tag = */ 1,
/* .props = */ props, /* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 2), /* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
}); });
SharedShadowNode node3 = descriptor->createShadowNode(ShadowNodeFragment{ SharedShadowNode node2 = descriptor->createShadowNode(
/* .tag = */ 3, ShadowNodeFragment{
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 3), /* .eventEmitter = */ descriptor->createEventEmitter(0, 2),
}); },
ShadowNodeFamilyFragment{
/* .tag = */ 2,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
SharedShadowNode node3 = descriptor->createShadowNode(
ShadowNodeFragment{
/* .surfaceId = */ 1,
/* .props = */ props,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 3),
},
ShadowNodeFamilyFragment{
/* .tag = */ 3,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
descriptor->appendChild(node1, node2); descriptor->appendChild(node1, node2);
descriptor->appendChild(node1, node3); descriptor->appendChild(node1, node3);

Просмотреть файл

@ -27,7 +27,6 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
componentDescriptor); componentDescriptor);
auto node = std::make_shared<TestShadowNode>( auto node = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -60,7 +59,6 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
componentDescriptor); componentDescriptor);
auto node = std::make_shared<TestShadowNode>( auto node = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -89,7 +87,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
auto props = std::make_shared<const TestProps>(); auto props = std::make_shared<const TestProps>();
auto node1 = std::make_shared<TestShadowNode>( auto node1 = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 1,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -106,7 +103,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
componentDescriptor); componentDescriptor);
auto node2 = std::make_shared<TestShadowNode>( auto node2 = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 2,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -123,7 +119,6 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
componentDescriptor); componentDescriptor);
auto node3 = std::make_shared<TestShadowNode>( auto node3 = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 3,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -173,7 +168,6 @@ TEST(ShadowNodeTest, handleCloneFunction) {
auto firstNode = std::make_shared<TestShadowNode>( auto firstNode = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ std::make_shared<const TestProps>(), /* .props = */ std::make_shared<const TestProps>(),
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -218,7 +212,6 @@ TEST(ShadowNodeTest, handleLocalData) {
auto props = std::make_shared<const TestProps>(); auto props = std::make_shared<const TestProps>();
auto firstNode = std::make_shared<TestShadowNode>( auto firstNode = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -228,7 +221,6 @@ TEST(ShadowNodeTest, handleLocalData) {
ShadowNodeTraits{}); ShadowNodeTraits{});
auto secondNode = std::make_shared<TestShadowNode>( auto secondNode = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -238,7 +230,6 @@ TEST(ShadowNodeTest, handleLocalData) {
ShadowNodeTraits{}); ShadowNodeTraits{});
auto thirdNode = std::make_shared<TestShadowNode>( auto thirdNode = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1, /* .surfaceId = */ 1,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -289,7 +280,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeAA = std::make_shared<TestShadowNode>( auto nodeAA = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -307,7 +297,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeABA = std::make_shared<TestShadowNode>( auto nodeABA = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -325,7 +314,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeABB = std::make_shared<TestShadowNode>( auto nodeABB = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -343,7 +331,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeABC = std::make_shared<TestShadowNode>( auto nodeABC = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -364,7 +351,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeAB = std::make_shared<TestShadowNode>( auto nodeAB = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -382,7 +368,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeAC = std::make_shared<TestShadowNode>( auto nodeAC = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -403,7 +388,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeA = std::make_shared<TestShadowNode>( auto nodeA = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
@ -421,7 +405,6 @@ TEST(ShadowNodeTest, handleBacktracking) {
componentDescriptor); componentDescriptor);
auto nodeZ = std::make_shared<TestShadowNode>( auto nodeZ = std::make_shared<TestShadowNode>(
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(), /* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),

Просмотреть файл

@ -103,12 +103,13 @@ ShadowTree::ShadowTree(
*RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext); *RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext);
rootShadowNode_ = std::static_pointer_cast<const RootShadowNode>( rootShadowNode_ = std::static_pointer_cast<const RootShadowNode>(
rootComponentDescriptor.createShadowNode(ShadowNodeFragment{ rootComponentDescriptor.createShadowNode(
/* .tag = */ surfaceId, ShadowNodeFragment{
/* .surfaceId = */ surfaceId, /* .surfaceId = */ surfaceId,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ noopEventEmitter, /* .eventEmitter = */ noopEventEmitter,
})); },
{surfaceId, surfaceId, noopEventEmitter}));
mountingCoordinator_ = std::make_shared<MountingCoordinator const>( mountingCoordinator_ = std::make_shared<MountingCoordinator const>(
ShadowTreeRevision{rootShadowNode_, 0, {}}); ShadowTreeRevision{rootShadowNode_, 0, {}});
@ -210,7 +211,6 @@ void ShadowTree::commitEmptyTree() const {
return std::make_shared<RootShadowNode>( return std::make_shared<RootShadowNode>(
*oldRootShadowNode, *oldRootShadowNode,
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ ShadowNodeFragment::propsPlaceholder(), /* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .eventEmitter = */ /* .eventEmitter = */

Просмотреть файл

@ -50,8 +50,7 @@ StubViewTree stubViewTreeFromShadowNode(ShadowNode const &rootShadowNode) {
sliceChildShadowNodeViewPairs(rootShadowNode)); sliceChildShadowNodeViewPairs(rootShadowNode));
auto emptyRootShadowNode = rootShadowNode.clone( auto emptyRootShadowNode = rootShadowNode.clone(
ShadowNodeFragment{ShadowNodeFragment::tagPlaceholder(), ShadowNodeFragment{ShadowNodeFragment::surfaceIdPlaceholder(),
ShadowNodeFragment::surfaceIdPlaceholder(),
ShadowNodeFragment::propsPlaceholder(), ShadowNodeFragment::propsPlaceholder(),
ShadowNodeFragment::eventEmitterPlaceholder(), ShadowNodeFragment::eventEmitterPlaceholder(),
ShadowNode::emptySharedShadowNodeSharedList()}); ShadowNode::emptySharedShadowNodeSharedList()});

Просмотреть файл

@ -171,17 +171,18 @@ SharedShadowNode ComponentDescriptorRegistry::createNode(
auto const props = auto const props =
componentDescriptor.cloneProps(nullptr, RawProps(propsDynamic)); componentDescriptor.cloneProps(nullptr, RawProps(propsDynamic));
auto const state = componentDescriptor.createInitialState( auto const state = componentDescriptor.createInitialState(
ShadowNodeFragment{tag, surfaceId, props, eventEmitter}); ShadowNodeFragment{surfaceId, props, eventEmitter});
return componentDescriptor.createShadowNode({ return componentDescriptor.createShadowNode(
/* .tag = */ tag, {
/* .surfaceId = */ surfaceId, /* .surfaceId = */ surfaceId,
/* .props = */ props, /* .props = */ props,
/* .eventEmitter = */ eventEmitter, /* .eventEmitter = */ eventEmitter,
/* .children = */ ShadowNodeFragment::childrenPlaceholder(), /* .children = */ ShadowNodeFragment::childrenPlaceholder(),
/* .localData = */ ShadowNodeFragment::localDataPlaceholder(), /* .localData = */ ShadowNodeFragment::localDataPlaceholder(),
/* .state = */ state, /* .state = */ state,
}); },
{tag, surfaceId, eventEmitter});
} }
void ComponentDescriptorRegistry::setFallbackComponentDescriptor( void ComponentDescriptorRegistry::setFallbackComponentDescriptor(

Просмотреть файл

@ -174,22 +174,21 @@ void Scheduler::renderTemplateToSurface(
uiManager_->getShadowTreeRegistry().visit( uiManager_->getShadowTreeRegistry().visit(
surfaceId, [=](const ShadowTree &shadowTree) { surfaceId, [=](const ShadowTree &shadowTree) {
return shadowTree.tryCommit([&](RootShadowNode::Shared const return shadowTree.tryCommit(
&oldRootShadowNode) { [&](RootShadowNode::Shared const &oldRootShadowNode) {
return std::make_shared<RootShadowNode>( return std::make_shared<RootShadowNode>(
*oldRootShadowNode, *oldRootShadowNode,
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(), /* .surfaceId = */
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
ShadowNodeFragment::surfaceIdPlaceholder(), /* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .props = */ ShadowNodeFragment::propsPlaceholder(), /* .eventEmitter = */
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
ShadowNodeFragment::eventEmitterPlaceholder(), /* .children = */
/* .children = */ std::make_shared<SharedShadowNodeList>(
std::make_shared<SharedShadowNodeList>( SharedShadowNodeList{tree}),
SharedShadowNodeList{tree}), });
}); });
});
}); });
} catch (const std::exception &e) { } catch (const std::exception &e) {
LOG(ERROR) << " >>>> EXCEPTION <<< rendering uiTemplate in " LOG(ERROR) << " >>>> EXCEPTION <<< rendering uiTemplate in "

Просмотреть файл

@ -36,23 +36,24 @@ SharedShadowNode UIManager::createNode(
componentDescriptor.createEventEmitter(std::move(eventTarget), tag); componentDescriptor.createEventEmitter(std::move(eventTarget), tag);
auto const props = componentDescriptor.cloneProps(nullptr, rawProps); auto const props = componentDescriptor.cloneProps(nullptr, rawProps);
auto const state = componentDescriptor.createInitialState( auto const state = componentDescriptor.createInitialState(
ShadowNodeFragment{tag, surfaceId, props, eventEmitter}); ShadowNodeFragment{surfaceId, props, eventEmitter});
auto shadowNode = componentDescriptor.createShadowNode({ auto shadowNode = componentDescriptor.createShadowNode(
/* .tag = */ tag, ShadowNodeFragment{
/* .surfaceId = */ surfaceId, /* .surfaceId = */ surfaceId,
/* .props = */ /* .props = */
fallbackDescriptor != nullptr && fallbackDescriptor != nullptr &&
fallbackDescriptor->getComponentHandle() == fallbackDescriptor->getComponentHandle() ==
componentDescriptor.getComponentHandle() componentDescriptor.getComponentHandle()
? componentDescriptor.cloneProps( ? componentDescriptor.cloneProps(
props, RawProps(folly::dynamic::object("name", name))) props, RawProps(folly::dynamic::object("name", name)))
: props, : props,
/* .eventEmitter = */ eventEmitter, /* .eventEmitter = */ eventEmitter,
/* .children = */ ShadowNodeFragment::childrenPlaceholder(), /* .children = */ ShadowNodeFragment::childrenPlaceholder(),
/* .localData = */ ShadowNodeFragment::localDataPlaceholder(), /* .localData = */ ShadowNodeFragment::localDataPlaceholder(),
/* .state = */ state, /* .state = */ state,
}); },
ShadowNodeFamilyFragment{tag, surfaceId, eventEmitter});
// state->commit(x) associates a ShadowNode with the State object. // state->commit(x) associates a ShadowNode with the State object.
// state->commit(x) must be called before calling updateState; updateState // state->commit(x) must be called before calling updateState; updateState
@ -84,7 +85,6 @@ SharedShadowNode UIManager::cloneNode(
auto clonedShadowNode = componentDescriptor.cloneShadowNode( auto clonedShadowNode = componentDescriptor.cloneShadowNode(
*shadowNode, *shadowNode,
{ {
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ /* .props = */
rawProps ? componentDescriptor.cloneProps( rawProps ? componentDescriptor.cloneProps(
@ -116,7 +116,6 @@ void UIManager::completeSurface(
return std::make_shared<RootShadowNode>( return std::make_shared<RootShadowNode>(
*oldRootShadowNode, *oldRootShadowNode,
ShadowNodeFragment{ ShadowNodeFragment{
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(), /* .surfaceId = */ ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ ShadowNodeFragment::propsPlaceholder(), /* .props = */ ShadowNodeFragment::propsPlaceholder(),
/* .eventEmitter = */ /* .eventEmitter = */
@ -157,7 +156,6 @@ void UIManager::setNativeProps(
return oldRootShadowNode->clone( return oldRootShadowNode->clone(
shadowNode, [&](ShadowNode const &oldShadowNode) { shadowNode, [&](ShadowNode const &oldShadowNode) {
return oldShadowNode.clone({ return oldShadowNode.clone({
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ /* .surfaceId = */
ShadowNodeFragment::surfaceIdPlaceholder(), ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ props, /* .props = */ props,
@ -211,7 +209,6 @@ void UIManager::updateState(
return oldRootShadowNode->clone( return oldRootShadowNode->clone(
shadowNode, [&](ShadowNode const &oldShadowNode) { shadowNode, [&](ShadowNode const &oldShadowNode) {
return oldShadowNode.clone({ return oldShadowNode.clone({
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
/* .surfaceId = */ /* .surfaceId = */
ShadowNodeFragment::surfaceIdPlaceholder(), ShadowNodeFragment::surfaceIdPlaceholder(),
/* .props = */ ShadowNodeFragment::propsPlaceholder(), /* .props = */ ShadowNodeFragment::propsPlaceholder(),