clean up ModuleHolder.java

Reviewed By: achen1

Differential Revision: D4548524

fbshipit-source-id: 5fab273e7a461c0312fa555aaccb8869843d9d95
This commit is contained in:
Aaron Chiu 2017-02-13 20:22:14 -08:00 committed by Facebook Github Bot
parent 78801793f3
commit 7c82803c4d
1 changed files with 6 additions and 15 deletions

View File

@ -48,7 +48,7 @@ public class ModuleHolder {
mSupportsWebWorkers = supportsWebWorkers;
mProvider = provider;
if (needsEagerInit) {
mModule = doCreate();
mModule = create();
}
}
@ -91,34 +91,25 @@ public class ModuleHolder {
public synchronized NativeModule getModule() {
if (mModule == null) {
mModule = doCreate();
mModule = create();
}
return mModule;
}
private NativeModule doCreate() {
NativeModule module = create();
mProvider = null;
return module;
}
private NativeModule create() {
boolean isEagerModule = mModule != null;
if (!isEagerModule) {
ReactMarker.logMarker(CREATE_MODULE_START, mName);
}
SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
ReactMarker.logMarker(CREATE_MODULE_START, mName);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createModule")
.arg("name", mName)
.flush();
NativeModule module = assertNotNull(mProvider).get();
mProvider = null;
if (mInitializeNeeded) {
doInitialize(module);
mInitializeNeeded = false;
}
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
if (!isEagerModule) {
ReactMarker.logMarker(CREATE_MODULE_END);
}
ReactMarker.logMarker(CREATE_MODULE_END);
return module;
}