mirror of https://github.com/grpc/grpc-node.git
				
				
				
			Merge pull request #639 from JustinBeckwith/flatmap
refactor: drop usage of _.flatMap
This commit is contained in:
		
						commit
						53ab637622
					
				| 
						 | 
				
			
			@ -716,7 +716,7 @@ function _getStreamReadCallback(emitter, call, get_listener, deserialize) {
 | 
			
		|||
 * @return {boolean}
 | 
			
		||||
 */
 | 
			
		||||
function _areBatchRequirementsMet(batch_ops, completed_ops) {
 | 
			
		||||
  var dependencies = _.flatMap(batch_ops, function(op) {
 | 
			
		||||
  var dependencies = common.flatMap(batch_ops, function(op) {
 | 
			
		||||
    return OP_DEPENDENCIES[op] || [];
 | 
			
		||||
  });
 | 
			
		||||
  for (var i = 0; i < dependencies.length; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -752,7 +752,7 @@ function _startBatchIfReady(call, batch, batch_state, callback) {
 | 
			
		|||
    // dependencies are met as a result.
 | 
			
		||||
    call.startBatch(batch, callback);
 | 
			
		||||
    completed_ops = Array.from(new Set(completed_ops.concat(batch_ops)));
 | 
			
		||||
    deferred_batches = _.flatMap(deferred_batches, function(deferred_batch) {
 | 
			
		||||
    deferred_batches = common.flatMap(deferred_batches, function(deferred_batch) {
 | 
			
		||||
      var deferred_batch_ops = Object.keys(deferred_batch).map(Number);
 | 
			
		||||
      if (_areBatchRequirementsMet(deferred_batch_ops, completed_ops)) {
 | 
			
		||||
        call.startBatch(deferred_batch.batch, deferred_batch.callback);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -112,6 +112,21 @@ exports.getMethodType = function(method_definition) {
 | 
			
		|||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Iterate over a collection of items, and run the given handler.
 | 
			
		||||
 * Return the results as a flattened array of values.
 | 
			
		||||
 *
 | 
			
		||||
 * @private
 | 
			
		||||
 *
 | 
			
		||||
 * @param {Array} collection Array of items to process
 | 
			
		||||
 * @param {Function} handler The function to call on each element in the array
 | 
			
		||||
 * @return {Array} A flattened array of results.
 | 
			
		||||
 */
 | 
			
		||||
exports.flatMap = function(collection, handler) {
 | 
			
		||||
  const mapped = collection.map(handler);
 | 
			
		||||
  return mapped.reduce((acc, curr) => acc.concat(curr), []);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Given an array of property names and an array of values,
 | 
			
		||||
 * combine the two into an object map.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue