Cache constants for MP Search NativeModules

Summary: TurboModules doesn't cache invocations of getConstants(). This diff looks at which NativeModules' getConstants() methods gets repeated called in Marketplace, and caches those invocations in JS.

Reviewed By: fkgozali

Differential Revision: D21874123

fbshipit-source-id: a44b98b3ac8621f67c9c0f3b7c4003a561d1e15d
This commit is contained in:
Ramanpreet Nara authored and Facebook GitHub Bot committed 2020-06-03 20:48:28 -07:00
1 parent 4e9c428328
commit 96fdaa541e
2 files changed
+51 -2

No files matched your search

@@ -19,4 +19,19 @@ export interface Spec extends TurboModule {
|};
}
export default (TurboModuleRegistry.getEnforcing<Spec>('SourceCode'): Spec);
const NativeModule = TurboModuleRegistry.getEnforcing<Spec>('SourceCode');
let constants = null;
const NativeSourceCode = {
getConstants(): {|
scriptURL: string,
|} {
if (constants == null) {
constants = NativeModule.getConstants();
}
return constants;
},
};
export default NativeSourceCode;