Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/calculated-field-types/map-reduce.js
const Promise = require("bluebird"); | const Promise = require("bluebird"); | ||||
module.exports = function(App) { | module.exports = function(App) { | ||||
return { | return { | ||||
name: "map-reduce", | name: "map-reduce", | ||||
calculate: function(context, params, item) { | calculate(context, params, item) { | ||||
const action_arguments = [ | const action_arguments = [ | ||||
context, | context, | ||||
params.source.subject_path, | params.source.subject_path, | ||||
params.source.action_name, | params.source.action_name, | ||||
params.source.params, | params.source.params, | ||||
].map(function(element) { | ].map( | ||||
if (element instanceof Function) { | element => | ||||
return element(context, params, item); | element instanceof Function | ||||
} else { | ? element(context, params, item) | ||||
return element; | : element | ||||
} | ); | ||||
}); | |||||
return Promise.all(action_arguments) | return Promise.all(action_arguments) | ||||
.then(function(fulfilled_action_arguments) { | .then(fulfilled_action_arguments => { | ||||
return App.run_action.apply( | return App.run_action.apply( | ||||
App, | App, | ||||
fulfilled_action_arguments | fulfilled_action_arguments | ||||
); | ); | ||||
}) | }) | ||||
.map(params.map) | .map(params.map) | ||||
.reduce(params.reduce[0], params.reduce[1]); | .reduce(params.reduce[0], params.reduce[1]); | ||||
}, | }, | ||||
}; | }; | ||||
}; | }; |