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
2020-06-03 20:48:28 -07:00
committed by Facebook GitHub Bot
parent 4e9c428328
commit 96fdaa541e
2 changed files with 51 additions and 2 deletions
@@ -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;