Implement lazy discovery scaffolding for loading NativeModules on demand.

Reviewed By: javache

Differential Revision: D5364734

fbshipit-source-id: 5162f7d41434a3ba38c82fa610e84f865bfacf50
This commit is contained in:
Dmitry Zakharov authored and Facebook Github Bot committed 2017-08-11 06:41:33 -07:00
1 parent 21b1ed3115
commit cf38b083dd
6 files changed
+174 -98

No files matched your search

+8 -1
View File
@@ -33,7 +33,9 @@ class RN_EXPORT ModuleRegistry {
// notifyCatalystInstanceInitialized: this is really only used by view-related code
// notifyCatalystInstanceDestroy: use RAII instead
ModuleRegistry(std::vector<std::unique_ptr<NativeModule>> modules);
using ModuleNotFoundCallback = std::function<bool(const std::string &name)>;
ModuleRegistry(std::vector<std::unique_ptr<NativeModule>> modules, ModuleNotFoundCallback callback = nullptr);
void registerModules(std::vector<std::unique_ptr<NativeModule>> modules);
std::vector<std::string> moduleNames();
@@ -56,6 +58,11 @@ class RN_EXPORT ModuleRegistry {
// This is populated with modules that are requested via getConfig but are unknown.
// An error will be thrown if they are subsquently added to the registry.
std::unordered_set<std::string> unknownModules_;
// Function will be called if a module was requested but was not found.
// If the function returns true, ModuleRegistry will try to find the module again (assuming it's registered)
// If the functon returns false, ModuleRegistry will not try to find the module and return nullptr instead.
ModuleNotFoundCallback moduleNotFoundCallback_;
};
}