Skip to content

Commit d1411cc

Browse files
davidaureliofacebook-github-bot
authored andcommitted
Publish events for node allocation and deallocation
Summary: @public Publish two events, `NodeAllocation` and `NodeDeallocation`, in the same places where the global node counter is changed. Reviewed By: SidharthGuglani Differential Revision: D15174858 fbshipit-source-id: 6e4e9add88513b9e987189ca5035d76da2a1de55
1 parent 25ee3e0 commit d1411cc

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "YGNode.h"
1414
#include "YGNodePrint.h"
1515
#include "Yoga-internal.h"
16+
#include "events.h"
1617
#include "instrumentation.h"
1718
#ifdef _MSC_VER
1819
#include <float.h>
@@ -213,6 +214,9 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
213214
YGAssertWithConfig(
214215
config, node != nullptr, "Could not allocate memory for node");
215216
gNodeInstanceCount++;
217+
#ifdef YG_ENABLE_EVENTS
218+
Event::publish<Event::NodeAllocation>(node, {config});
219+
#endif
216220

217221
if (config->useWebDefaults) {
218222
node->getStyle().flexDirection() = YGFlexDirectionRow;
@@ -238,6 +242,9 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
238242
node != nullptr,
239243
"Could not allocate memory for node");
240244
gNodeInstanceCount++;
245+
#ifdef YG_ENABLE_EVENTS
246+
Event::publish<Event::NodeAllocation>(node, {node->getConfig()});
247+
#endif
241248
node->setOwner(nullptr);
242249
return node;
243250
}
@@ -284,6 +291,9 @@ void YGNodeFree(const YGNodeRef node) {
284291
}
285292

286293
node->clearChildren();
294+
#ifdef YG_ENABLE_EVENTS
295+
Event::publish<Event::NodeDeallocation>(node, {node->getConfig()});
296+
#endif
287297
delete node;
288298
gNodeInstanceCount--;
289299
}

ReactCommon/yoga/yoga/events.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <memory>
99
#include <stdexcept>
1010

11+
#include <iostream>
12+
1113
namespace facebook {
1214
namespace yoga {
1315

ReactCommon/yoga/yoga/events.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace facebook {
1515
namespace yoga {
1616

1717
struct Event {
18-
enum Type {};
18+
enum Type { NodeAllocation, NodeDeallocation };
1919
class Data;
2020
using Subscriber = void(const YGNode&, Type, Data);
2121

@@ -51,5 +51,15 @@ struct Event {
5151
static void publish(const YGNode&, Type, const Data&);
5252
};
5353

54+
template <>
55+
struct Event::TypedData<Event::NodeAllocation> {
56+
YGConfig* config;
57+
};
58+
59+
template <>
60+
struct Event::TypedData<Event::NodeDeallocation> {
61+
YGConfig* config;
62+
};
63+
5464
} // namespace yoga
5565
} // namespace facebook

0 commit comments

Comments
 (0)