Skip to content

Commit

Permalink
feat: solve async problem in reduceToValue
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelvesavuori committed Jun 29, 2024
1 parent 97c3ecb commit ef7fe6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getpopcorn/utils",
"version": "0.0.53",
"version": "0.0.54",
"description": "Various common utilities and tools",
"author": "Popcorn Cloud",
"license": "SEE LICENSE IN LICENSE",
Expand Down
14 changes: 9 additions & 5 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ export class Utils {
result: Record<string, any>[] | Promise<Record<string, any>>,
component: FlowComponentRepresentation
) => {
const resolvedResult = await result;
const fn = functions[component.type];
if (fn) {
const resolvedResult = await result;
const nextId =
const nextId = (() => {
// @ts-ignore
resolvedResult?.next !== component.id ? resolvedResult?.next : component.next;
const resolvedId = component?.next || component?.[0]?.next;
return resolvedId !== component.id ? resolvedId : component.next;
})();
component.next = nextId;
// @ts-ignore
const input = resolvedResult?.input || resolvedResult;
return await fn(component, input);
return fn(component, input);
}

return resolvedResult;
},
components
Promise.resolve(components)
);
}

Expand Down

0 comments on commit ef7fe6d

Please sign in to comment.