mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
96fdaa541e
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
38 lines
807 B
JavaScript
38 lines
807 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {TurboModule} from '../../TurboModule/RCTExport';
|
|
import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
|
|
|
|
export interface Spec extends TurboModule {
|
|
+getConstants: () => {|
|
|
scriptURL: string,
|
|
|};
|
|
}
|
|
|
|
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;
|