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

Middlewares should accept arguments #11

Closed
luciorubeens opened this issue May 21, 2018 · 3 comments
Closed

Middlewares should accept arguments #11

luciorubeens opened this issue May 21, 2018 · 3 comments
Labels
question Further information is requested

Comments

@luciorubeens
Copy link
Contributor

Hey there!

Is there a way in the current version to pass arguments to middlewares?

If not, is this metadata field in the Effect type useful for it?

@JozefFlakus
Copy link
Member

JozefFlakus commented May 21, 2018

Hi,

Sure thing, you can pass as many arguments as you want to middlewares. Just wrap them inside a function with parameters and return an Effect:

export const foo = (bar: string): Effect<HttpRequest> => request$ => request$
  .pipe(
    tap(() => console.log(bar)),
  );

then in middlewares definition:

const middlewares = [
  logger$,
  bodyParser$,
  foo('test'),
];

@JozefFlakus JozefFlakus added the question Further information is requested label May 21, 2018
@luciorubeens
Copy link
Contributor Author

@JozefFlakus Makes sense. Thank you! 👍

Can you explain how this metadata will be used?

@JozefFlakus
Copy link
Member

JozefFlakus commented May 21, 2018

I'm glad that I've helped! :)

Right now metadata field is used only for error middlewares. In this case the so called metadata field will contain throwed error object which you can use for error handling-related logic.

const error$: Effect<EffectResponse, ThrowedError> = (request$, response, error) => request$
  .pipe(
    map(req => ({
      status: // ...
      body:  // ...
    }),
  );

But who knows, maybe in the future we will be able to use this parameter in different way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants