Merge pull request #635 from JustinBeckwith/zip

refactor: drop usage of _.zipObject
This commit is contained in:
Michael Lumish 2018-11-15 11:27:33 -08:00 committed by GitHub
commit 7d1c246bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -112,6 +112,23 @@ exports.getMethodType = function(method_definition) {
}
};
/**
* Given an array of property names and an array of values,
* combine the two into an object map.
* Equivalent to _.zipObject.
*
* @private
*
* @param props {Array<String>} Array of property names
* @param values {Array} Array of property values
* @return {Object} An object with the combined values
*/
exports.zipObject = function(props, values) {
return props.reduce((acc, curr, idx) => {
return Object.assign(acc, { [curr]: values[idx] });
}, {});
}
// JSDoc definitions that are used in multiple other modules
/**

View File

@ -25,6 +25,7 @@
var _ = require('lodash');
var client = require('./client');
var common = require('./common');
/**
* Get a function that deserializes a specific type of protobuf.
@ -106,7 +107,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
lodash@3.10.1-compatible functions. A previous version used
_.fromPairs, which would be cleaner, but was introduced in lodash
version 4 */
return _.zipObject(service.children.map(function(method) {
return common.zipObject(service.children.map(function(method) {
return _.camelCase(method.name);
}), service.children.map(function(method) {
return {

View File

@ -25,6 +25,7 @@
var _ = require('lodash');
var client = require('./client');
var common = require('./common');
/**
* Get a function that deserializes a specific type of protobuf.
@ -103,7 +104,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
options) {
var prefix = '/' + fullyQualifiedName(service) + '/';
service.resolveAll();
return _.zipObject(service.methods.map(function(method) {
return common.zipObject(service.methods.map(function(method) {
return _.camelCase(method.name);
}), service.methods.map(function(method) {
return {