I have a data-provider component that houses common calculations I need to perform in my workflows. When the calculations are complete, the data-provider component fires an event "calculated_results" with the results. The data-provider component shares its context so that its calculation workflow can be triggered outside the component. Now, here is my problem. I need a way to halt my workflows until I get the data from the data-provider needed to continue the workflow. That is, I need to halt the workflow until the calculated_results event fires. I was hoping I could do this with a custom action using an eventListener (code below), but it doesn't seem to work. It doesn't seem to recognize any event called "calculated_results". Does toddle have an internal representation of this component event that I need to be using?
function waitForEvent(args, ctx) {
// Get parameters
const eventToWaitFor = args.eventName;
const timeoutMs = isNumber(args.timeoutMs) ? args.timeoutMs : 30000;
// Handler for the event
const handleEvent = (event) => {
clearTimeout(timeout);
document.removeEventListener(eventToWaitFor, handleEvent);
ctx.triggerActionEvent('success', {
event: eventToWaitFor,
data: event.detail
});
};
// Set up timeout
const timeout = setTimeout(() => {
document.removeEventListener(eventToWaitFor, handleEvent);
ctx.triggerActionEvent('timeout', {
error: 'Waiting for ${eventToWaitFor} timed out after ${timeoutMs}ms',
event: eventToWaitFor
});
}, timeoutMs);
// Listen for the specified event
document.addEventListener(eventToWaitFor, handleEvent);
}