I have this method loadAllCustomObjects
that calls the async
function loadCustomObject
(which does a fetch
) multiple times and reduces the results:
export default class CustomObjectLoader {
static async loadAllCustomObjects(elements) {
const customObjectTypes = getCustomObjectTypes(elements);
console.log('loadAllCustomObjects', customObjectTypes);
const customObjectsData = await customObjectTypes.reduce(async (allData, elementType) => {
allData[elementType] = await loadCustomObject(elementType)
return allData;
}, {});
console.log('customObjectsData', _.keys(customObjectsData));
return customObjectsData;
}
}
However, reduce
returns too early, and this is the log statements:
loadAllCustomObjects [ 'slider', 'twitter-share-button' ]
customObjectsData [ 'slider' ]
How can I make it complete all the objects in customObjectTypes
?