mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Provide sync vs async interface for bundle loading via parameter
Reviewed By: javache Differential Revision: D5104317 fbshipit-source-id: ffacb57d85c24795a3acc2faba2ff5824cc739b2
This commit is contained in:
committed by
Facebook Github Bot
parent
d59fd9e419
commit
f46eaa30cf
@@ -20,8 +20,6 @@
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
using namespace detail;
|
||||
|
||||
Instance::~Instance() {
|
||||
if (nativeToJsBridge_) {
|
||||
nativeToJsBridge_->destroy();
|
||||
@@ -48,64 +46,56 @@ void Instance::initializeBridge(
|
||||
CHECK(nativeToJsBridge_);
|
||||
}
|
||||
|
||||
void Instance::loadApplication(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("reactbridge_xplat_loadApplication", "sourceURL", sourceURL);
|
||||
nativeToJsBridge_->loadApplication(std::move(unbundle), std::move(string), std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadApplicationSync(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
std::unique_lock<std::mutex> lock(m_syncMutex);
|
||||
m_syncCV.wait(lock, [this] { return m_syncReady; });
|
||||
|
||||
SystraceSection s("reactbridge_xplat_loadApplicationSync", "sourceURL", sourceURL);
|
||||
nativeToJsBridge_->loadApplicationSync(std::move(unbundle), std::move(string), std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::setSourceURL(std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("reactbridge_xplat_setSourceURL",
|
||||
"sourceURL", sourceURL);
|
||||
SystraceSection s("reactbridge_xplat_setSourceURL", "sourceURL", sourceURL);
|
||||
|
||||
nativeToJsBridge_->loadApplication(nullptr, nullptr, std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("reactbridge_xplat_loadScriptFromString",
|
||||
"sourceURL", sourceURL);
|
||||
nativeToJsBridge_->loadApplication(nullptr, std::move(string), std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadScriptFromStringSync(std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
std::unique_lock<std::mutex> lock(m_syncMutex);
|
||||
m_syncCV.wait(lock, [this] { return m_syncReady; });
|
||||
|
||||
nativeToJsBridge_->loadApplicationSync(nullptr, std::move(string), std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadScriptFromFile(const std::string& filename,
|
||||
const std::string& sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("reactbridge_xplat_loadScriptFromFile",
|
||||
"fileName", filename);
|
||||
|
||||
std::unique_ptr<const JSBigFileString> script;
|
||||
|
||||
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
||||
[&filename, &script]() {
|
||||
script = JSBigFileString::fromPath(filename);
|
||||
});
|
||||
|
||||
nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL);
|
||||
std::string sourceURL,
|
||||
bool loadSynchronously) {
|
||||
SystraceSection s("reactbridge_xplat_loadScriptFromString", "sourceURL", sourceURL);
|
||||
if (loadSynchronously) {
|
||||
loadApplicationSync(nullptr, std::move(string), std::move(sourceURL));
|
||||
} else {
|
||||
loadApplicationSync(nullptr, std::move(string), std::move(sourceURL));
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::loadUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
nativeToJsBridge_->loadApplication(std::move(unbundle), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadUnbundleSync(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL) {
|
||||
std::unique_lock<std::mutex> lock(m_syncMutex);
|
||||
m_syncCV.wait(lock, [this] { return m_syncReady; });
|
||||
|
||||
SystraceSection s("reactbridge_xplat_loadApplicationSync");
|
||||
nativeToJsBridge_->loadApplicationSync(std::move(unbundle), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
}
|
||||
std::string startupScriptSourceURL,
|
||||
bool loadSynchronously) {
|
||||
if (loadSynchronously) {
|
||||
loadApplicationSync(std::move(unbundle), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
} else {
|
||||
loadApplication(std::move(unbundle), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
}
|
||||
}
|
||||
|
||||
bool Instance::supportsProfiling() {
|
||||
return nativeToJsBridge_->supportsProfiling();
|
||||
|
||||
Reference in New Issue
Block a user