Skip to content

Commit 142c66f

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Create ShadowNodeFamily inside ComponentDescriptor
Summary: Changelog: [internal] 1. Creates `ShadowNodeFamily` inside `ComponentDescriptor`. 2. As a side effect of this, we no longer need `ComponentDescriptor::createEventEmitter` so it is removed. This is a step in order to merge `StateCoordinator` into `ShadowNodeFamily` and use it as target for state updates. Reviewed By: shergin Differential Revision: D19514906 fbshipit-source-id: 04ad3c621886be56925acd76f9b35a09d8c5e15a
1 parent 7f79b46 commit 142c66f

File tree

7 files changed

+65
-50
lines changed

7 files changed

+65
-50
lines changed

ReactCommon/fabric/core/componentdescriptor/ComponentDescriptor.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ class ComponentDescriptor {
103103
const SharedProps &props,
104104
const RawProps &rawProps) const = 0;
105105

106-
/*
107-
* Creates a new `EventEmitter` object compatible with particular type of
108-
* shadow nodes.
109-
*/
110-
virtual SharedEventEmitter createEventEmitter(
111-
SharedEventTarget eventTarget,
112-
const Tag &tag) const = 0;
113-
114106
/*
115107
* Create an initial State object that represents (and contains) an initial
116108
* State's data which can be constructed based on initial Props.
@@ -127,6 +119,13 @@ class ComponentDescriptor {
127119
const State::Shared &previousState,
128120
const StateData::Shared &data) const = 0;
129121

122+
/*
123+
* Creates a shadow node family for particular node.
124+
*/
125+
virtual ShadowNodeFamily::Shared createFamily(
126+
ShadowNodeFamilyFragment const &fragment,
127+
SharedEventTarget eventTarget) const = 0;
128+
130129
protected:
131130
EventDispatcher::Weak eventDispatcher_;
132131
ContextContainer::Shared contextContainer_;

ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
118118
return ShadowNodeT::Props(rawProps, props);
119119
};
120120

121-
virtual SharedEventEmitter createEventEmitter(
122-
SharedEventTarget eventTarget,
123-
const Tag &tag) const override {
124-
return std::make_shared<ConcreteEventEmitter>(
125-
std::move(eventTarget), tag, eventDispatcher_);
126-
}
127-
128121
virtual State::Shared createInitialState(
129122
ShadowNodeFragment const &fragment,
130123
SurfaceId const surfaceId) const override {
@@ -157,6 +150,17 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
157150
*std::static_pointer_cast<const ConcreteState>(previousState));
158151
}
159152

153+
virtual ShadowNodeFamily::Shared createFamily(
154+
ShadowNodeFamilyFragment const &fragment,
155+
SharedEventTarget eventTarget) const override {
156+
auto eventEmitter = std::make_shared<ConcreteEventEmitter const>(
157+
std::move(eventTarget), fragment.tag, eventDispatcher_);
158+
return std::make_shared<ShadowNodeFamily>(
159+
ShadowNodeFamilyFragment{
160+
fragment.tag, fragment.surfaceId, eventEmitter},
161+
*this);
162+
}
163+
160164
protected:
161165
virtual void adopt(UnsharedShadowNode shadowNode) const {
162166
// Default implementation does nothing.

ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ TEST(ComponentDescriptorTest, createShadowNode) {
2323

2424
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
2525
SharedProps props = descriptor->cloneProps(nullptr, raw);
26-
auto family = std::make_shared<ShadowNodeFamily>(
27-
ShadowNodeFamilyFragment{9, 1, descriptor->createEventEmitter(0, 9)},
28-
*descriptor);
26+
27+
auto family = descriptor->createFamily(
28+
ShadowNodeFamilyFragment{
29+
/* .tag = */ 9,
30+
/* .surfaceId = */ 1,
31+
/* .eventEmitter = */ nullptr,
32+
},
33+
nullptr);
2934

3035
SharedShadowNode node = descriptor->createShadowNode(
3136
ShadowNodeFragment{
@@ -49,9 +54,13 @@ TEST(ComponentDescriptorTest, cloneShadowNode) {
4954

5055
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
5156
SharedProps props = descriptor->cloneProps(nullptr, raw);
52-
auto family = std::make_shared<ShadowNodeFamily>(
53-
ShadowNodeFamilyFragment{9, 1, descriptor->createEventEmitter(0, 9)},
54-
*descriptor);
57+
auto family = descriptor->createFamily(
58+
ShadowNodeFamilyFragment{
59+
/* .tag = */ 9,
60+
/* .surfaceId = */ 1,
61+
/* .eventEmitter = */ nullptr,
62+
},
63+
nullptr);
5564
SharedShadowNode node = descriptor->createShadowNode(
5665
ShadowNodeFragment{
5766
/* .props = */ props,
@@ -73,25 +82,37 @@ TEST(ComponentDescriptorTest, appendChild) {
7382

7483
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
7584
SharedProps props = descriptor->cloneProps(nullptr, raw);
76-
auto family1 = std::make_shared<ShadowNodeFamily>(
77-
ShadowNodeFamilyFragment{1, 1, descriptor->createEventEmitter(0, 9)},
78-
*descriptor);
85+
auto family1 = descriptor->createFamily(
86+
ShadowNodeFamilyFragment{
87+
/* .tag = */ 1,
88+
/* .surfaceId = */ 1,
89+
/* .eventEmitter = */ nullptr,
90+
},
91+
nullptr);
7992
SharedShadowNode node1 = descriptor->createShadowNode(
8093
ShadowNodeFragment{
8194
/* .props = */ props,
8295
},
8396
family1);
84-
auto family2 = std::make_shared<ShadowNodeFamily>(
85-
ShadowNodeFamilyFragment{2, 1, descriptor->createEventEmitter(0, 2)},
86-
*descriptor);
97+
auto family2 = descriptor->createFamily(
98+
ShadowNodeFamilyFragment{
99+
/* .tag = */ 2,
100+
/* .surfaceId = */ 1,
101+
/* .eventEmitter = */ nullptr,
102+
},
103+
nullptr);
87104
SharedShadowNode node2 = descriptor->createShadowNode(
88105
ShadowNodeFragment{
89106
/* .props = */ props,
90107
},
91108
family2);
92-
auto family3 = std::make_shared<ShadowNodeFamily>(
93-
ShadowNodeFamilyFragment{3, 1, descriptor->createEventEmitter(0, 3)},
94-
*descriptor);
109+
auto family3 = descriptor->createFamily(
110+
ShadowNodeFamilyFragment{
111+
/* .tag = */ 3,
112+
/* .surfaceId = */ 1,
113+
/* .eventEmitter = */ nullptr,
114+
},
115+
nullptr);
95116
SharedShadowNode node3 = descriptor->createShadowNode(
96117
ShadowNodeFragment{
97118
/* .props = */ props,

ReactCommon/fabric/element/ComponentBuilder.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ ShadowNode::Shared ComponentBuilder::build(
2525
children.push_back(build(childFragment));
2626
}
2727

28-
auto eventEmitter =
29-
componentDescriptor.createEventEmitter(nullptr, elementFragment.tag);
30-
31-
auto family = std::make_shared<ShadowNodeFamily>(
28+
auto family = componentDescriptor.createFamily(
3229
ShadowNodeFamilyFragment{
33-
elementFragment.tag, elementFragment.surfaceId, eventEmitter},
34-
componentDescriptor);
30+
elementFragment.tag, elementFragment.surfaceId, nullptr},
31+
nullptr);
3532

3633
auto shadowNode = componentDescriptor.createShadowNode(
3734
ShadowNodeFragment{

ReactCommon/fabric/mounting/ShadowTree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ ShadowTree::ShadowTree(
102102
const auto props = std::make_shared<const RootProps>(
103103
*RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext);
104104

105-
auto family = std::make_shared<ShadowNodeFamily>(
105+
auto family = rootComponentDescriptor.createFamily(
106106
ShadowNodeFamilyFragment{surfaceId, surfaceId, noopEventEmitter},
107-
rootComponentDescriptor);
107+
nullptr);
108108
rootShadowNode_ = std::static_pointer_cast<const RootShadowNode>(
109109
rootComponentDescriptor.createShadowNode(
110110
ShadowNodeFragment{

ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,9 @@ SharedShadowNode ComponentDescriptorRegistry::createNode(
172172
auto unifiedComponentName = componentNameByReactViewName(viewName);
173173
auto const &componentDescriptor = this->at(unifiedComponentName);
174174

175-
auto family = std::make_shared<ShadowNodeFamily>(
176-
ShadowNodeFamilyFragment{
177-
tag,
178-
surfaceId,
179-
componentDescriptor.createEventEmitter(std::move(eventTarget), tag)},
180-
componentDescriptor);
175+
auto family = componentDescriptor.createFamily(
176+
ShadowNodeFamilyFragment{tag, surfaceId, nullptr},
177+
std::move(eventTarget));
181178
auto const props =
182179
componentDescriptor.cloneProps(nullptr, RawProps(propsDynamic));
183180
auto const state = componentDescriptor.createInitialState(

ReactCommon/fabric/uimanager/UIManager.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ SharedShadowNode UIManager::createNode(
3333
auto fallbackDescriptor =
3434
componentDescriptorRegistry_->getFallbackComponentDescriptor();
3535

36-
auto family = std::make_shared<ShadowNodeFamily>(
37-
ShadowNodeFamilyFragment{
38-
tag,
39-
surfaceId,
40-
componentDescriptor.createEventEmitter(std::move(eventTarget), tag)},
41-
componentDescriptor);
36+
auto family = componentDescriptor.createFamily(
37+
ShadowNodeFamilyFragment{tag, surfaceId, nullptr},
38+
std::move(eventTarget));
4239
auto const props = componentDescriptor.cloneProps(nullptr, rawProps);
4340
auto const state = componentDescriptor.createInitialState(
4441
ShadowNodeFragment{props}, surfaceId);

0 commit comments

Comments
 (0)