UNPKG

@magnetarjs/core

Version:
18 lines (17 loc) 724 B
/** * Executes given function array with given args-array deconstructed, it will always use replace the first param with whatever the response of each function was. */ export function executeOnFns(params) { const { modifyReadResultFns, cacheStoreFns, payload, docMetaData } = params; let newPayload = payload; for (const fn of modifyReadResultFns) { // we only want to execute these when there is a payload if (newPayload) newPayload = fn(newPayload, docMetaData); } for (const fn of cacheStoreFns) { // we only want to execute these always, regardless wether or not there's a payload newPayload = fn(newPayload, docMetaData); } return newPayload; }