-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Why not app.use(generator) ? #34
Comments
just because of how we're composing them it basically passes next to all of them first and becomes:
I had thought about doing what you mention but it would require that we use a dispatcher |
+1. i find nesting another function pretty annoying, especially when we're trying to avoid callbacks. |
dispatchers are not great though, and become a reasonable source of slow down when you start mounting a lot of apps, which is one thing I'd like to get "right" with koa. With Connect the dispatcher adds considerable overhead when you have a decent size tree of apps, and it makes composition a lot more difficult / coupled to koa, but I'll see if I can find a decent way around that. If ES6 would allow |
Errrr yeah I just realized how complicated it would make things. Personally, I wouldn't mind performance penalties as long as they aren't crippling. We can always improve the dispatcher (or try to) but changing the middleware signature would be difficult. |
having an intermediate is helpful for debugging though, you can print out the currently executing middleware and mutations made etc, so it might be worth the added complexity, I'll see if I can refactor koa-compose to not be disgusting haha and hopefully the accumulated perf portion is not too bad with lots of mounting, we'll find out! I have it working with the following, but mounting would definitely be much more complex than it is now: app.use(function *(){
console.log('before')
yield 'next';
console.log('after')
}) |
how about just allowing any "falsey" value instead of var next;
app.use(function *(){
console.log('before');
yield next;
console.log('after');
}) meh it doesn't really matter. being able to just do |
yeah fuck it, way too awkward for mounting, we can maybe revisit this in the future, it does look nicer but implementation obscurity is probably not worth it. Closing for now |
You got the code on a branch? I want to check it out. |
@jonathanong https://github.com/koajs/koa/tree/add/dispatcher just enough to get examples/simple.js working |
another nice thing about the dispatcher approach though is we can remove |
Like this
Is there a reason for that?
The text was updated successfully, but these errors were encountered: