Skip to content

Commit

Permalink
TurboModule::emitDeviceEvent doesn't require jsi::Runtime argument an…
Browse files Browse the repository at this point in the history
…ymore (facebook#43376)

Summary:

## Changelog:
[Internal] - 

Make it possible to call `emitDeviceEvent` from C++ TurboModules without the need to explicitly provide the reference to `jsi::Runtime`, as in some contexts (when we call e.g. not from the JS thread itself) it may be hard to get hold of.

Reviewed By: rubennorte

Differential Revision: D54643903
  • Loading branch information
rshest authored and facebook-github-bot committed Mar 8, 2024
1 parent 7bb84ef commit e56ec03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ TurboModule::TurboModule(
: name_(std::move(name)), jsInvoker_(std::move(jsInvoker)) {}

void TurboModule::emitDeviceEvent(
jsi::Runtime& runtime,
const std::string& eventName,
ArgFactory argFactory) {
jsInvoker_->invokeAsync([eventName, argFactory](jsi::Runtime& rt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ class JSI_EXPORT TurboModule : public facebook::jsi::HostObject {
* });
*/
void emitDeviceEvent(
jsi::Runtime& runtime,
const std::string& eventName,
ArgFactory argFactory = nullptr);

// Backwards compatibility version
void emitDeviceEvent(
jsi::Runtime& /*runtime*/,
const std::string& eventName,
ArgFactory argFactory = nullptr) {
emitDeviceEvent(eventName, std::move(argFactory));
}

virtual jsi::Value create(
jsi::Runtime& runtime,
const jsi::PropNameID& propName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ void NativeCxxModuleExample::emitCustomDeviceEvent(
// Test emitting device events (RCTDeviceEventEmitter.emit) from C++
// TurboModule with arbitrary arguments
emitDeviceEvent(
rt,
eventName.utf8(rt).c_str(),
[](jsi::Runtime& rt, std::vector<jsi::Value>& args) {
args.emplace_back(jsi::Value(true));
Expand Down

0 comments on commit e56ec03

Please sign in to comment.