Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBuschmann committed Nov 6, 2024
1 parent 3c77481 commit 8ef23f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/core/compose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ it('should execute middleware handlers in order', async () => {
order.push(middleware1);
return handler(...args);
};
middleware1['meta'] = {1: '1'};
const middleware2 =
(handler) =>
(...args) => {
order.push(middleware2);
return handler(...args);
};
middleware2['meta'] = {2: '2'};

compose(middleware1, middleware2)(async () => {})({});
const composedHandler = compose(middleware1, middleware2)(async () => {});
composedHandler({});

expect(order).toEqual([middleware1, middleware2]);
expect(composedHandler['meta']).toEqual({1: '1', 2: '2'});
});

it('should provide actual handler reference via "actual" property', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,5 @@ export function compose<E1, E2, E3, R1, R2, R3>(
// -> Anyway: This should be fixed in the future
export function compose<E1, E2, R1, R2>(f: Middleware<E1, E2, R1, R2>): Middleware<E1, E2, R1, R2>;
export function compose(...fns) {
return fns.reduce((f, g) => (handler) => Object.assign(f(g(handler)), { actual: handler }));
return fns.reduce((f, g) => (handler) => Object.assign(f(g(handler)), { actual: handler, meta: {...f.meta, ...g.meta} }));
}

0 comments on commit 8ef23f1

Please sign in to comment.