« index
Coverage for /Users/kris/q-io/http-apps/chain.js : 90%
22 lines |
20 run |
2 missing |
1 partial |
7 blocks |
5 blocks run |
2 blocks missing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | module.exports = Chain; function Chain(end) { var self = Object.create(Chain.prototype); self.end = end || function (next) { return next; }; return self; }; Chain.prototype.use = function (App /*, ...args*/) { if (!App) throw new Error("App is not defined after " + this.app); var args = Array.prototype.slice.call(arguments, 1); var self = this; this.end = (function (End) { return function Self(next) { if (self.end !== Self && !next) throw new Error("App chain is broken after " + App);"App chain is broken after " + App); return End(App.apply(null, [next].concat(args))); }; })(this.end); this.app = App; return this; }; |