Files
react-native/Libraries/Utilities/codegenNativeCommands.js
T
Marshall Roch b044ece594 presuppress Flow v0.201 errors
Summary: Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D43720099

fbshipit-source-id: 6931548c90deb82cfc7e3d8173ccfc6aa7f0e1c8
2023-03-02 08:43:56 -08:00

32 lines
830 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
const {dispatchCommand} = require('../ReactNative/RendererProxy');
type Options<T = string> = $ReadOnly<{|
supportedCommands: $ReadOnlyArray<T>,
|}>;
function codegenNativeCommands<T: interface {}>(options: Options<$Keys<T>>): T {
const commandObj: {[$Keys<T>]: (...$ReadOnlyArray<mixed>) => void} = {};
options.supportedCommands.forEach(command => {
// $FlowFixMe[missing-local-annot]
commandObj[command] = (ref, ...args) => {
// $FlowFixMe[incompatible-call]
dispatchCommand(ref, command, args);
};
});
return ((commandObj: any): T);
}
export default codegenNativeCommands;