Skip to content

Commit

Permalink
fix(iff): execute iff.else() correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fratzinger committed May 31, 2022
1 parent 97c0fbe commit 0147f67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks/iff-else.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { PredicateFn } from '../types';
export function iffElse (
predicate: boolean | PredicateFn,
trueHooks: Hook | Hook[] | undefined,
falseHooks: Hook | Hook[] | undefined
falseHooks?: Hook | Hook[] | undefined
): Hook {
// fnArgs is [context] for service & permission hooks, [data, connection, context] for event filters
return function (this: any, ctx: HookContext) {
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/iff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export function iff (
...hooks: Hook[]
): IffHook {
const iffWithoutElse = function (context: HookContext) {
return iffElse(predicate, hooks.slice(), undefined)(context);
return iffElse(predicate, hooks.slice())(context);
}
iffWithoutElse.else = (...falseHooks: any[]) => iffElse(true, falseHooks.slice(), []);

iffWithoutElse.else = (...falseHooks: any[]) => (context: HookContext) => iffElse(predicate, hooks.slice(), falseHooks.slice())(context);

return iffWithoutElse;
}

0 comments on commit 0147f67

Please sign in to comment.