Skip to content

Commit

Permalink
fix(hooks): Update regular hook order as suggested in #97
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jun 4, 2022
1 parent bbd1979 commit 9b758fc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main/hooks/src/regular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export const runHook = (hook: RegularMiddleware, context: any, type?: string) =>
});
};

export const runHooks = (hooks: RegularMiddleware[]) => (context: any) => hooks.reduce(
(promise, hook) => promise.then(() => runHook(hook, context)),
Promise.resolve(context),
);
export const runHooks = (hooks: RegularMiddleware[]) =>
(context: any) =>
hooks.reduce(
(promise, hook) => promise.then(() => runHook(hook, context)),
Promise.resolve(context),
);

export function fromBeforeHook(hook: RegularMiddleware) {
return (context: any, next: any) => {
Expand Down Expand Up @@ -63,5 +65,5 @@ export function collect(
const afterHooks = [...after].reverse().map(fromAfterHook);
const errorHooks = error.length ? [fromErrorHook(runHooks(error))] : [];

return compose([...errorHooks, ...afterHooks, ...beforeHooks]);
return compose([...errorHooks, ...beforeHooks, ...afterHooks]);
}

0 comments on commit 9b758fc

Please sign in to comment.