Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

invoke.js 827B

123456789101112131415161718192021222324252627
  1. import restArguments from './restArguments.js';
  2. import isFunction from './isFunction.js';
  3. import isArray from './isArray.js';
  4. import map from './map.js';
  5. import deepGet from './_deepGet.js';
  6. // Invoke a method (with arguments) on every item in a collection.
  7. export default restArguments(function(obj, path, args) {
  8. var contextPath, func;
  9. if (isFunction(path)) {
  10. func = path;
  11. } else if (isArray(path)) {
  12. contextPath = path.slice(0, -1);
  13. path = path[path.length - 1];
  14. }
  15. return map(obj, function(context) {
  16. var method = func;
  17. if (!method) {
  18. if (contextPath && contextPath.length) {
  19. context = deepGet(context, contextPath);
  20. }
  21. if (context == null) return void 0;
  22. method = context[path];
  23. }
  24. return method == null ? method : method.apply(context, args);
  25. });
  26. });