Skip to content

Commit

Permalink
Merge pull request #635 from JustinBeckwith/zip
Browse files Browse the repository at this point in the history
refactor: drop usage of _.zipObject
  • Loading branch information
murgatroid99 committed Nov 15, 2018
2 parents 46f052b + f50ba3a commit 7d1c246
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/grpc-native-core/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/grpc-native-core/src/protobuf_js_5_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/grpc-native-core/src/protobuf_js_6_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7d1c246

Please sign in to comment.