Is it possible to have the get-records-list
event to wait for promises before resolving? I can’t seem to get this to work.
Things I’ve tried:
- Using the
get-records-list:before
event to initialize the data object. Theget-records-list
event does not wait for the get-records:before to resolve. - a myriad of code adjustments including an async addEventListerne request (e.g.
window.addEventListener('get-records-team', async (e) => await onRecords(e));
) - PreventDefault / stopPropogation
Video demonstration / explanation:
My current code:
async function getData(source) {
// make data request to external API
let res = await ASP.Read(source);
// adjust response object to mimic Softr data object, then return
let data = JSON.parse(res);
return data.map(n => ({
id: n.Key,
fields: n
}));
}
async function onRecords(e) {
let recs = e.detail;
let data = await contacts;
for (n in data) { recs.push(data[n]) };
}
window.addEventListener('get-records-team', onRecords );
// fetch data on page load
let contacts = getData('contact');