@connected/react
Version:
The hassle free way to call your server-side code
21 lines • 927 B
JavaScript
export default function buildCommands(instance, constructorParameters, resolver) {
const commands = {};
const anInstance = instance;
const prototype = Object.getPrototypeOf(instance);
const properties = Object.getOwnPropertyNames(prototype);
for (let i = 0; i < properties.length; i += 1) {
const property = properties[i];
const existingMethod = anInstance[property];
if (property !== 'constructor' && typeof existingMethod === 'function') {
commands[property] = (...parameters) => {
const fn = () => resolver(existingMethod.bind(instance), parameters, existingMethod.meta);
fn.parameters = parameters;
fn.constructorParameters = constructorParameters;
fn.meta = existingMethod.meta;
return fn;
};
}
}
return commands;
}
//# sourceMappingURL=build-commands.js.map