From 715b0a556079a21ff5cdf4ee389b8b477f4cd9a0 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 14 Nov 2018 18:55:57 -0800 Subject: [PATCH 1/2] refactor: drop usage of _.zipObject --- packages/grpc-native-core/src/common.js | 14 ++++++++++++++ .../grpc-native-core/src/protobuf_js_5_common.js | 3 ++- .../grpc-native-core/src/protobuf_js_6_common.js | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/grpc-native-core/src/common.js b/packages/grpc-native-core/src/common.js index 0c35296a..197cd7d8 100644 --- a/packages/grpc-native-core/src/common.js +++ b/packages/grpc-native-core/src/common.js @@ -112,6 +112,20 @@ 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. + * @param props {Array} 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 /** diff --git a/packages/grpc-native-core/src/protobuf_js_5_common.js b/packages/grpc-native-core/src/protobuf_js_5_common.js index 3be4ef04..1e6cc810 100644 --- a/packages/grpc-native-core/src/protobuf_js_5_common.js +++ b/packages/grpc-native-core/src/protobuf_js_5_common.js @@ -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 { diff --git a/packages/grpc-native-core/src/protobuf_js_6_common.js b/packages/grpc-native-core/src/protobuf_js_6_common.js index 04121ad4..db346116 100644 --- a/packages/grpc-native-core/src/protobuf_js_6_common.js +++ b/packages/grpc-native-core/src/protobuf_js_6_common.js @@ -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 { From f50ba3af4bfca3cb05457958a72d231523410938 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 15 Nov 2018 10:41:20 -0800 Subject: [PATCH 2/2] Update common.js --- packages/grpc-native-core/src/common.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/grpc-native-core/src/common.js b/packages/grpc-native-core/src/common.js index 197cd7d8..c3c76989 100644 --- a/packages/grpc-native-core/src/common.js +++ b/packages/grpc-native-core/src/common.js @@ -116,6 +116,9 @@ 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} Array of property names * @param values {Array} Array of property values * @return {Object} An object with the combined values