mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a6fffb7cd0
Summary: Previously codegenNativeCommands was just a hint to the babel transform. This meant that in order to use the codegen'd JS command functions it required having the babel transform turned on. We aren't ready to turn the transform on for open source so we are adding runtime behavior to the function that will run when it isn't replaced with the transform. Reviewed By: rickhanlonii Differential Revision: D16574781 fbshipit-source-id: 583e8857f69ae1695445ee887432d15248dd35a9
32 lines
714 B
JavaScript
32 lines
714 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
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import {dispatchCommand} from '../../Libraries/Renderer/shims/ReactNative';
|
|
|
|
type Options<T = string> = $ReadOnly<{|
|
|
supportedCommands: $ReadOnlyArray<T>,
|
|
|}>;
|
|
|
|
function codegenNativeCommands<T: {}>(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;
|