From d062cc252efbd22cb469c22c8b373d17acee86a4 Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Thu, 8 Jun 2017 11:45:27 -0700 Subject: [PATCH] Promise support for C++ bridge Summary: Looks like `CxxModule::Method` already supports 0..2 callbacks. Based on Obj-C implementation (RCTModuleMethod.m:492) and JS bridge code (NativeModules.js:76), 2 callbacks native method is transformed to JS promise by JS part of the bridge. Reviewed By: javache Differential Revision: D5207852 fbshipit-source-id: 5aad86d45b97397f2bc3a4dbc648a60d96a4689e --- ReactCommon/cxxreact/CxxNativeModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ReactCommon/cxxreact/CxxNativeModule.cpp b/ReactCommon/cxxreact/CxxNativeModule.cpp index 314d3837a..664c9ab84 100644 --- a/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -57,7 +57,8 @@ std::vector CxxNativeModule::getMethods() { std::vector descs; for (auto& method : methods_) { assert(method.func || method.syncFunc); - descs.emplace_back(method.name, method.func ? "async" : "sync"); + auto methodType = method.func ? (method.callbacks == 2 ? "promise" : "async") : "sync"; + descs.emplace_back(method.name, methodType); } return descs; }