Skip to content

Commit

Permalink
fix: return the result of fireEvent in our async wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrawlings committed Apr 10, 2020
1 parent cd3d4df commit 71fdfd1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,32 @@ export type InternalEventNames = typeof INTERNAL_EVENTS[number];

export type FireFunction = (
...params: Parameters<originalFireFunction>
) => Promise<void>;
) => Promise<ReturnType<originalFireFunction>>;

export type FireObject = {
[K in EventType]: (
...params: Parameters<originalFireObject[keyof originalFireObject]>
) => Promise<void>;
) => Promise<ReturnType<originalFireFunction>>;
};

export const fireEvent = (async (...params) => {
failIfNoWindow();
originalFireEvent(...params);
const result = originalFireEvent(...params);
await wait();
return result;
}) as FireFunction & FireObject;

Object.keys(originalFireEvent).forEach((eventName: EventType) => {
const fire = originalFireEvent[eventName];
fireEvent[eventName] = async (...params) => {
failIfNoWindow();
fire(...params);
const result = fire(...params);

// TODO: this waits for a possible update using setTimeout(0) which should
// be sufficient, but ideally we would hook into the Marko lifecycle to
// determine when all pending updates are complete.
await wait();
return result;
};
});

Expand Down

0 comments on commit 71fdfd1

Please sign in to comment.