A framework for building native applications using React
Add EventEmitter C++ bridging type (#44808)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44808
Adds an `AsyncEventEmitter` class which can be used as a property of currently C++ only Turbo Modules to send type safe data back to JavaScript.
Adding support for ObjC / Java Turbo Modules is possible, straight forward and can be added as an afterthought.
It implements this interface
```
export type EventEmitter<T> = {
addListener(handler: (T) => mixed): EventSubscription,
};
```
## Hybrid
It is a 'hybrid' object.
1.) You `addListener(handler: (T) => mixed)` in JavaScript for emitted events (coming from C++, native code)
2.) You `emit(...Arg)` events in C++, native code (getting sent to JavaScript)
## Changelog:
[General] [Added] - Add EventEmitter C++ bridging type
## Facebook:
Apps usually create custom functionality to achieve this kind of behavior - e.g. https://www.internalfb.com/code/fbsource/[e72bd42a028a]/arvr/js/apps/RemoteDesktopCompanion/shared/turbo_modules/TMSubscription.h
Reviewed By: javache
Differential Revision: D57424391
fbshipit-source-id: 4999cafe9daeac125712a4bb7679d7acb9a6c389 C
Christoph Purrer committed
2a0a11256a9919c70989aef00631da3a0f4afb25
Parent: d3e3e2a
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
on 6/11/2024, 10:00:16 PM