mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
0708e28caf
Summary: * invokeMethod() ends up not useful because each platform has its own way of invoking the platform methods * invalidate() is not necessary because there's already the destructor of each C++ class Reviewed By: mdvacca Differential Revision: D15187833 fbshipit-source-id: 9478ed1e6288da30c67179e03a7bc7da6043280b
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "TurboModule.h"
|
|
|
|
using namespace facebook;
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
TurboModule::TurboModule(const std::string &name, std::shared_ptr<JSCallInvoker> jsInvoker)
|
|
: name_(name),
|
|
jsInvoker_(jsInvoker) {}
|
|
|
|
TurboModule::~TurboModule() {}
|
|
|
|
jsi::Value TurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
|
|
std::string propNameUtf8 = propName.utf8(runtime);
|
|
auto p = methodMap_.find(propNameUtf8);
|
|
if (p == methodMap_.end()) {
|
|
// Method was not found, let JS decide what to do.
|
|
return jsi::Value::undefined();
|
|
}
|
|
MethodMetadata meta = p->second;
|
|
return jsi::Function::createFromHostFunction(
|
|
runtime,
|
|
propName,
|
|
meta.argCount,
|
|
[this, meta](facebook::jsi::Runtime &rt, const facebook::jsi::Value &thisVal, const facebook::jsi::Value *args, size_t count) {
|
|
return meta.invoker(rt, *this, args, count);
|
|
});
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|