all files / src/ bindActionData.js

100% Statements 21/21
100% Branches 12/12
100% Functions 5/5
100% Lines 8/8
6 statements, 1 function, 4 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18         1147× 1036×         111× 978×   54×    
import mapValues from './mapValues';
 
/**
 * Adds additional properties to the results of the function or map of functions passed
 */
export default function bindActionData(action, data) {
  if (typeof action === 'function') {
    return (...args) => ({
      ...action(...args),
      ...data
    });
  }
  if (typeof action === 'object') {
    return mapValues(action, value => bindActionData(value, data));
  }
  return action;
}