File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 88#include < memory>
99#include < stdexcept>
1010
11+ #include < iostream>
12+
1113namespace facebook {
1214namespace yoga {
1315
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ namespace facebook {
1515namespace yoga {
1616
1717struct 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
You can’t perform that action at this time.
0 commit comments