return function *dispatch(next) { debug('%s %s', this.method, this.path); var method = this.method; var path = router.opts.routerPath || this.routerPath || this.path; var matched = router.match(path); var route = matched.filter(function (route) { return ~route.methods.indexOf(method); }).shift(); if (this.matched) { this.matched.push.apply(this.matched, matched); } else { this.matched = matched; } // Find route matching requested path and method if (route) { this.captures = route.captures(path, this.captures); this.params = route.params(path, this.captures, this.params); this.route = route; debug('dispatch %s %s', this.route.path, this.route.regexp); var stack = [this.route.middleware].concat(router.stack.middleware.reverse()); var fn = compose(stack); yield* fn.call(this, next); } else { // Could not find any route matching the requested path // simply yield to downstream koa middleware return yield *next; } };
app.callback = function(){ var mw = [respond].concat(this.middleware); var fn = this.experimental ? compose_es7(mw) : co.wrap(compose(mw)); var self = this; if (!this.listeners('error').length) this.on('error', this.onerror); return function(req, res){ res.statusCode = 404; var ctx = self.createContext(req, res); onFinished(res, ctx.onerror); fn.call(ctx).catch(ctx.onerror); } };
function transform(options) { return compose([ transform.less(options), transform.sass(options), transform.stylus(options), transform.jade(options), transform.markdown(options), transform.react(options), transform.coffeescript(options), transform.json(options), // before .js so that they can be required via js plugins.css(options), plugins.html(options), transform.text(options), // after css for .css.js transform.domify(options), // after text for .html.js plugins.js(options), plugins.file(options), ]) }
app.callback = function(){ if (this.experimental) { console.error('Experimental ES7 Async Function support is deprecated. Please look into Koa v2 as the middleware signature has changed.') } var fn = this.experimental ? compose_es7(this.middleware) : co.wrap(compose(this.middleware)); var self = this; if (!this.listeners('error').length) this.on('error', this.onerror); return function(req, res){ res.statusCode = 404; var ctx = self.createContext(req, res); onFinished(res, ctx.onerror); fn.call(ctx).then(function () { respond.call(ctx); }).catch(ctx.onerror); } };
function Walker(options) { if (!(this instanceof Walker)) return new Walker(options) options = options || {} EventEmitter.call(this, options) this.setMaxListeners(0) // all the cached file objects based on the URI this.cache = options.cache || cache() // all the current file objects based on the URI this.files = {} // resolves in progress this.progress = {} // list of middleware this.middleware = [] // the composed middleware function this.downstream = compose(this.middleware) // each entry point will be its own tree this.dependencies = {} }
function composedly() { var args = slice.call(arguments); var fn = compose(args.slice(1)); set(fn, args[0]); return fn; }