Skip to content

Commit

Permalink
Cache constants for MP Home NativeModules
Browse files Browse the repository at this point in the history
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: D21874124

fbshipit-source-id: 03d2318e1b6d00236ef707f9f19a640bf8c08786
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 4, 2020
1 parent fdadff9 commit 4e9c428
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Libraries/Utilities/NativeDeviceInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ export interface Spec extends TurboModule {
}

const NativeModule: Spec = TurboModuleRegistry.getEnforcing<Spec>('DeviceInfo');
let constants = null;

const NativeDeviceInfo = NativeModule;
const NativeDeviceInfo = {
getConstants(): {|
+Dimensions: DimensionsPayload,
+isIPhoneX_deprecated?: boolean,
|} {
if (constants == null) {
constants = NativeModule.getConstants();
}
return constants;
},
};

export default NativeDeviceInfo;

0 comments on commit 4e9c428

Please sign in to comment.