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

(req, res) signature #69

Closed
jonathanong opened this issue Nov 4, 2013 · 5 comments
Closed

(req, res) signature #69

jonathanong opened this issue Nov 4, 2013 · 5 comments

Comments

@jonathanong
Copy link
Member

reopening a clean issue. references: #34 #36

@jonathanong
Copy link
Member Author

since we're doing this.request and this.response, would be nice if the signature was:

app.use(function* (req, res) {
  assert(this.request === req);
  assert(this.response === res);
})

because doing this.request and this.response or var req = this.request would be pretty annoying. of course this shouldn't be necessary since a lot of properties are delegated to this, but i don't see the harm of passing these as arguments. it would also make it more similar to express, especially if you decided to make express 4.0 an opinionated version of koa.

@jonathanong
Copy link
Member Author

possible implementation: koajs/compose#1

variable arity would be pretty simple to do if we compose this way.

@tj
Copy link
Member

tj commented Nov 8, 2013

the one thing I like about not using arguments at all is that it frees up args for stuff like koa-route parameters. which could still use this.request but then it kind of diverges more from other koa related code, but definitely worth a consideration it does look better than if (this.response.header[blahblah]). The other reason I like it being on this is that it's reasonably obvious that those are not node's request/response objects since it doesn't match express

hopefully we don't even use those very much in every-day koa code, it just gets awkward with a few of those properties we had. On the other hand I'm totally cool with just doing this.params again in koa-route, not a huge deal

@jonathanong
Copy link
Member Author

hmmm i'm actually liking doing this.request and this.response and it's probably better for users not to worry about arity (as you know, i hate when people check a function's arity. :P). should we close this?

@tj
Copy link
Member

tj commented Nov 15, 2013

yeah might as well close for now I don't have super strong opinions on it, keeps the signature nice and clean :D

@tj tj closed this as completed Nov 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants