|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
832 bytes
|
| Line | |
|---|
| 1 | import restArguments from './restArguments.js';
|
|---|
| 2 | import isFunction from './isFunction.js';
|
|---|
| 3 | import map from './map.js';
|
|---|
| 4 | import deepGet from './_deepGet.js';
|
|---|
| 5 | import toPath from './_toPath.js';
|
|---|
| 6 |
|
|---|
| 7 | // Invoke a method (with arguments) on every item in a collection.
|
|---|
| 8 | export default restArguments(function(obj, path, args) {
|
|---|
| 9 | var contextPath, func;
|
|---|
| 10 | if (isFunction(path)) {
|
|---|
| 11 | func = path;
|
|---|
| 12 | } else {
|
|---|
| 13 | path = toPath(path);
|
|---|
| 14 | contextPath = path.slice(0, -1);
|
|---|
| 15 | path = path[path.length - 1];
|
|---|
| 16 | }
|
|---|
| 17 | return map(obj, function(context) {
|
|---|
| 18 | var method = func;
|
|---|
| 19 | if (!method) {
|
|---|
| 20 | if (contextPath && contextPath.length) {
|
|---|
| 21 | context = deepGet(context, contextPath);
|
|---|
| 22 | }
|
|---|
| 23 | if (context == null) return void 0;
|
|---|
| 24 | method = context[path];
|
|---|
| 25 | }
|
|---|
| 26 | return method == null ? method : method.apply(context, args);
|
|---|
| 27 | });
|
|---|
| 28 | });
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.