Skip to content

Commit 0d89653

Browse files
davidaureliofacebook-github-bot
authored andcommitted
Move YG_ENABLE_EVENTS checks to event.h
Summary: Instead of checking whether `YG_ENABLE_EVENTS` is defined for every publish, we simply wrap the body of the `publish` function macro that delegates to the method that actually publishes the event. This way we get 1. easier to write code where we publish events 2. more type safety when editing, enabling editors/IDEs to show errors without knowing about `YG_ENABLE_EVENTS` Reviewed By: SidharthGuglani Differential Revision: D16049888 fbshipit-source-id: cbf362d6f7be5053c3f377125d303b7137d6a241
1 parent 792f715 commit 0d89653

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
213213
const YGNodeRef node = new YGNode{config};
214214
YGAssertWithConfig(
215215
config, node != nullptr, "Could not allocate memory for node");
216-
#ifdef YG_ENABLE_EVENTS
217216
Event::publish<Event::NodeAllocation>(node, {config});
218-
#endif
219217

220218
return node;
221219
}
@@ -235,9 +233,7 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
235233
oldNode->getConfig(),
236234
node != nullptr,
237235
"Could not allocate memory for node");
238-
#ifdef YG_ENABLE_EVENTS
239236
Event::publish<Event::NodeAllocation>(node, {node->getConfig()});
240-
#endif
241237
node->setOwner(nullptr);
242238
return node;
243239
}
@@ -256,9 +252,7 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) {
256252
auto config = YGConfigClone(*oldNode->getConfig());
257253
auto node = new YGNode{*oldNode, config};
258254
node->setOwner(nullptr);
259-
#ifdef YG_ENABLE_EVENTS
260255
Event::publish<Event::NodeAllocation>(node, {node->getConfig()});
261-
#endif
262256

263257
YGVector vec = YGVector();
264258
vec.reserve(oldNode->getChildren().size());
@@ -286,9 +280,7 @@ void YGNodeFree(const YGNodeRef node) {
286280
}
287281

288282
node->clearChildren();
289-
#ifdef YG_ENABLE_EVENTS
290283
Event::publish<Event::NodeDeallocation>(node, {node->getConfig()});
291-
#endif
292284
delete node;
293285
}
294286

@@ -1637,9 +1629,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16371629
ownerWidth),
16381630
YGDimensionHeight);
16391631
} else {
1640-
#ifdef YG_ENABLE_EVENTS
16411632
Event::publish<Event::MeasureCallbackStart>(node);
1642-
#endif
16431633

16441634
// Measure the text under the current constraints.
16451635
const YGSize measuredSize = marker::MarkerSection<YGMarkerMeasure>::wrap(
@@ -1653,7 +1643,6 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16531643

16541644
layoutMarkerData.measureCallbacks += 1;
16551645

1656-
#ifdef YG_ENABLE_EVENTS
16571646
Event::publish<Event::MeasureCallbackEnd>(
16581647
node,
16591648
{layoutContext,
@@ -1663,7 +1652,6 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16631652
heightMeasureMode,
16641653
measuredSize.width,
16651654
measuredSize.height});
1666-
#endif
16671655

16681656
node->setLayoutMeasuredDimension(
16691657
YGNodeBoundAxis(
@@ -3956,7 +3944,6 @@ bool YGLayoutNodeInternal(
39563944

39573945
layout->generationCount = generationCount;
39583946

3959-
#ifdef YG_ENABLE_EVENTS
39603947
LayoutType layoutType;
39613948
if (performLayout) {
39623949
layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout
@@ -3967,7 +3954,6 @@ bool YGLayoutNodeInternal(
39673954
: LayoutType::kMeasure;
39683955
}
39693956
Event::publish<Event::NodeLayout>(node, {layoutType, layoutContext});
3970-
#endif
39713957

39723958
return (needToVisitNode || cachedResults == nullptr);
39733959
}
@@ -4076,9 +4062,7 @@ void YGNodeCalculateLayoutWithContext(
40764062
const YGDirection ownerDirection,
40774063
void* layoutContext) {
40784064

4079-
#ifdef YG_ENABLE_EVENTS
40804065
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
4081-
#endif
40824066
marker::MarkerSection<YGMarkerLayout> marker{node};
40834067

40844068
// Increment the generation count. This will force the recursive routine to
@@ -4158,10 +4142,7 @@ void YGNodeCalculateLayoutWithContext(
41584142
}
41594143

41604144
marker.end();
4161-
4162-
#ifdef YG_ENABLE_EVENTS
41634145
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker.data});
4164-
#endif
41654146

41664147
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
41674148
// aren't sure whether client's of yoga have gotten rid off this flag or not.

ReactCommon/yoga/yoga/event/event.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ struct Event {
6060

6161
template <Type E>
6262
static void publish(const YGNode& node, const TypedData<E>& eventData = {}) {
63+
#ifdef YG_ENABLE_EVENTS
6364
publish(node, E, Data{eventData});
65+
#endif
6466
}
6567

6668
template <Type E>

0 commit comments

Comments
 (0)