Giter Club home page Giter Club logo

Comments (11)

tj avatar tj commented on April 16, 2024 1

maybe we'll see it changed:

screen shot 2013-08-22 at 6 33 44 pm

from koa.

tj avatar tj commented on April 16, 2024

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.

jonathanong avatar jonathanong commented on April 16, 2024

+1. i find nesting another function pretty annoying, especially when we're trying to avoid callbacks.

from koa.

tj avatar tj commented on April 16, 2024

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.

jonathanong avatar jonathanong commented on April 16, 2024

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.

tj avatar tj commented on April 16, 2024

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.

jonathanong avatar jonathanong commented on April 16, 2024

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.

tj avatar tj commented on April 16, 2024

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.

jonathanong avatar jonathanong commented on April 16, 2024

You got the code on a branch? I want to check it out.

from koa.

tj avatar tj commented on April 16, 2024

@jonathanong https://github.com/koajs/koa/tree/add/dispatcher

just enough to get examples/simple.js working

from koa.

tj avatar tj commented on April 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.