Skip to content

Commit 0147f67

Browse files
committed
fix(iff): execute iff.else() correctly
1 parent 97c0fbe commit 0147f67

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/hooks/iff-else.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { PredicateFn } from '../types';
1010
export function iffElse (
1111
predicate: boolean | PredicateFn,
1212
trueHooks: Hook | Hook[] | undefined,
13-
falseHooks: Hook | Hook[] | undefined
13+
falseHooks?: Hook | Hook[] | undefined
1414
): Hook {
1515
// fnArgs is [context] for service & permission hooks, [data, connection, context] for event filters
1616
return function (this: any, ctx: HookContext) {

src/hooks/iff.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ export function iff (
1111
...hooks: Hook[]
1212
): IffHook {
1313
const iffWithoutElse = function (context: HookContext) {
14-
return iffElse(predicate, hooks.slice(), undefined)(context);
14+
return iffElse(predicate, hooks.slice())(context);
1515
}
16-
iffWithoutElse.else = (...falseHooks: any[]) => iffElse(true, falseHooks.slice(), []);
16+
17+
iffWithoutElse.else = (...falseHooks: any[]) => (context: HookContext) => iffElse(predicate, hooks.slice(), falseHooks.slice())(context);
1718

1819
return iffWithoutElse;
1920
}

0 commit comments

Comments
 (0)