mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
05418f8fcc
Summary: Flow is changing the behavior of object types to no longer be valid supertypes of classes. This replaces object types when they appear as supertypes of classes to be interfaces to avoid errors when this change rolls out. Changelog: [Internal] Reviewed By: pieterv Differential Revision: D27193522 fbshipit-source-id: c3e3fca8a4cacd90770a95b773ff2c659774b9a6
30 lines
709 B
JavaScript
30 lines
709 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.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
import {dispatchCommand} from '../../Libraries/Renderer/shims/ReactNative';
|
|
|
|
type Options<T = string> = $ReadOnly<{|
|
|
supportedCommands: $ReadOnlyArray<T>,
|
|
|}>;
|
|
|
|
function codegenNativeCommands<T: interface {}>(options: Options<$Keys<T>>): T {
|
|
const commandObj = {};
|
|
|
|
options.supportedCommands.forEach(command => {
|
|
commandObj[command] = (ref, ...args) => {
|
|
dispatchCommand(ref, command, args);
|
|
};
|
|
});
|
|
|
|
return ((commandObj: any): T);
|
|
}
|
|
|
|
export default codegenNativeCommands;
|