Skip to content

Commit

Permalink
Make generated EventEmitter C++ code not cause compiler warnings
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

While working on implementing [Event Timing API](https://www.w3.org/TR/event-timing/) I've noticed that there are multiple compiler warnings about unused lambda captures, which are coming from generated C++ code for EventEmitters.

This modifies the codegen so that the corresponding lambda doesn't capture event variable if it's not used in the event handler, thus getting rid of warnings.

Reviewed By: christophpurrer

Differential Revision: D42281899

fbshipit-source-id: 98442bb9f3ce374755188d818a9b2d6a8050bf15
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 29, 2022
1 parent 58220b9 commit 988a231
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ void EventPropsNativeComponentViewEventEmitter::onOrientationChange(OnOrientatio
});
}
void EventPropsNativeComponentViewEventEmitter::onEnd(OnEnd event) const {
dispatchEvent(\\"end\\", [event=std::move(event)](jsi::Runtime &runtime) {
dispatchEvent(\\"end\\", [](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
return payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onEventBubblingWithPaperName(OnEventBubblingWithPaperName event) const {
dispatchEvent(\\"eventBubblingWithPaperName\\", [event=std::move(event)](jsi::Runtime &runtime) {
dispatchEvent(\\"eventBubblingWithPaperName\\", [](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
return payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ const ComponentTemplate = ({
structName: string,
dispatchEventName: string,
implementation: string,
}) =>
`
}) => {
const capture = implementation.includes('event')
? 'event=std::move(event)'
: '';
return `
void ${className}EventEmitter::${eventName}(${structName} event) const {
dispatchEvent("${dispatchEventName}", [event=std::move(event)](jsi::Runtime &runtime) {
dispatchEvent("${dispatchEventName}", [${capture}](jsi::Runtime &runtime) {
${implementation}
});
}
`.trim();
};

const BasicComponentTemplate = ({
className,
Expand Down

0 comments on commit 988a231

Please sign in to comment.