From 9b758fc6e498c3f4f9a85da47974c6c2244d588e Mon Sep 17 00:00:00 2001 From: daffl Date: Sat, 4 Jun 2022 10:27:41 -0700 Subject: [PATCH] fix(hooks): Update regular hook order as suggested in #97 --- main/hooks/src/regular.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main/hooks/src/regular.ts b/main/hooks/src/regular.ts index df1b254..e29cf57 100644 --- a/main/hooks/src/regular.ts +++ b/main/hooks/src/regular.ts @@ -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) => { @@ -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]); }