don't call OnBatchComplete on specific modules unless we need to

Summary:
Don't call OnBatchComplete on NativeModules that have'nt been initialized.
Also a follow up to D4479604. This also removes the extra allocation of OnBatchCompleteListener per NativeModule that implements OnBatchCompleteListener.

This means NativeModules which implement OnBatchCompleteListener will have to be explicitly initialized or called into before the OnBatchCompleteListener of that NativeModule will be triggered.

Reviewed By: javache

Differential Revision: D4483682

fbshipit-source-id: 6a9431c82f72d17605d1c1e0ee9194f8d8fc2ddc
This commit is contained in:
Aaron Chiu authored and Facebook Github Bot committed 2017-02-09 22:30:03 -08:00
1 parent 6a5225fb22
commit 53a7d5822b
3 files changed
+13 -16

No files matched your search

@@ -113,18 +113,10 @@ public class NativeModuleRegistryBuilder {
}
public NativeModuleRegistry build() {
ArrayList<OnBatchCompleteListener> batchCompleteListenerModules = new ArrayList<>();
ArrayList<ModuleHolder> batchCompleteListenerModules = new ArrayList<>();
for (Map.Entry<Class<? extends NativeModule>, ModuleHolder> entry : mModules.entrySet()) {
Class<? extends NativeModule> type = entry.getKey();
if (OnBatchCompleteListener.class.isAssignableFrom(type)) {
final ModuleHolder moduleHolder = entry.getValue();
batchCompleteListenerModules.add(new OnBatchCompleteListener() {
@Override
public void onBatchComplete() {
OnBatchCompleteListener listener = (OnBatchCompleteListener) moduleHolder.getModule();
listener.onBatchComplete();
}
});
if (OnBatchCompleteListener.class.isAssignableFrom(entry.getKey())) {
batchCompleteListenerModules.add(entry.getValue());
}
}