Comments (11)
maybe we'll see it changed:
from koa.
just because of how we're composing them it basically passes next to all of them first and becomes:
b(c(d(e(f(notfound)))))
I had thought about doing what you mention but it would require that we use a dispatcher
from koa.
+1. i find nesting another function pretty annoying, especially when we're trying to avoid callbacks.
from koa.
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 yield;
as yield undefined;
we could just have yield and that's it. I'll try this out again and see what impact it has, it also means we can't use co due to how it's designed
from koa.
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.
from koa.
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')
})
from koa.
how about just allowing any "falsey" value instead of 'next'
?
var next;
app.use(function *(){
console.log('before');
yield next;
console.log('after');
})
meh it doesn't really matter. being able to just do yield 0
would be nice though.
from koa.
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
from koa.
You got the code on a branch? I want to check it out.
from koa.
@jonathanong https://github.com/koajs/koa/tree/add/dispatcher
just enough to get examples/simple.js working
from koa.
another nice thing about the dispatcher approach though is we can remove downstream
, since we can check that it's reached the furthest downstream middleware
from koa.
Related Issues (20)
- [fix] ctx.request.origin ignores proxy flag (X-Forwarded-Proto) HOT 2
- Issue with reassigning ctx.query and type preservation HOT 2
- [feat] send json type content when call ctx.throw HOT 1
- [fix] Has callback() changed return type? Now error from eslint HOT 5
- [feat] Could a listen() shortcut function be added also for http2? HOT 3
- [fix] Some things cannot be found in the database where condition search, unless the where condition search ID HOT 3
- koa 2.14.7 No generics,I want to be able to add generics HOT 1
- [feat] when will koa 3.0 be released? HOT 3
- Koa main website example code snippets disappear HOT 4
- [feat] Objects as middleware HOT 6
- [feat] Support Web (WHATWG) stream, Blob and Response HOT 2
- Consider alternatives to http-assert (including none at all) HOT 4
- [fix] Send response as buffer HOT 4
- async issue on app.listen(...) HOT 4
- [fix] I can not get query parameters about Korean HOT 3
- [feat] Spanish translation for docs
- Routing sucks, moving back to express. HOT 1
- [fix] ctx value persists to next request after mutating ctx object HOT 3
- if "\@" in url ,the redirect result doesn't match the host of the new URL() HOT 2
- [feat] Replace npm dependency "only"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koa.