Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} }));
}
Loading