-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow CxxModules to implement methods with two callbacks #21586
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Looks pretty good to me, some questions:
|
AppState itself is pretty platform specific. And the one I'm working on isn't one of the base RN platforms. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@@ -114,6 +114,25 @@ auto SampleCxxModule::getMethods() -> std::vector<Method> { | |||
sample_->hello(); | |||
return nullptr; | |||
}, SyncTag), | |||
Method("addIfPositiveAsPromise", [this](dynamic args, Callback cb, Callback cbError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the capture of this
is actually not used, failing the build internally:
react-native-github/ReactCommon/cxxreact/SampleCxxModule.cpp:117:39: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
Method("addIfPositiveAsPromise", [this](dynamic args, Callback cb, Callback cbError) {
^
react-native-github/ReactCommon/cxxreact/SampleCxxModule.cpp:126:37: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
Method("addIfPositiveAsAsync", [this](dynamic args, Callback cb, Callback cbError) {
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I can remove that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fkgozali has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
REDMOND\acoates merged commit 8826d8b into |
) Summary: When writing a native module in C++ using CxxModule, its not currently possible to write async methods which take two callbacks, that shouldn't be projected to JS as a promise. I hit this when trying to implement the AppState module in c++. AppState has a single method on it, getCurrentAppState, which takes two callbacks (a success and a failure callback). This change adds a couple of new CxxModule::Method ctors, which allow devs to specify that they want two callbacks, but not a promise. This is done using an extra tag in the ctor, similar to how you specify that you want to make a synchronous method. I used the existing AsyncTag to indicate that the 2 callback version should be async, and not a promise. Pull Request resolved: facebook#21586 Reviewed By: shergin Differential Revision: D10520204 Pulled By: fkgozali fbshipit-source-id: bcb2dbd91cba3c1db987dc18960247218fdbc032
When writing a native module in C++ using CxxModule, its not currently possible to write async methods which take two callbacks, that shouldn't be projected to JS as a promise. I hit this when trying to implement the AppState module in c++. AppState has a single method on it, getCurrentAppState, which takes two callbacks (a success and a failure callback).
This change adds a couple of new CxxModule::Method ctors, which allow devs to specify that they want two callbacks, but not a promise. This is done using an extra tag in the ctor, similar to how you specify that you want to make a synchronous method. I used the existing AsyncTag to indicate that the 2 callback version should be async, and not a promise.
Test Plan:
Implemented the AppState module using a CxxModule for an out of tree platform. Added sample usage to the Sample CxxModule.
Release Notes:
Help reviewers and the release process by writing your own release notes. See below for an example.
[MINOR] [ENHANCEMENT] [CxxModule.h] - Allow CxxModules to implement functions which take two callbacks