0.3.7 • Published 9 years ago
@koax/compose v0.3.7
compose
Compose koax middleware.
Installation
$ npm install @koax/compose
Usage
var compose = require('compose')
var composed = compose([function * (action, next) {
if (action === 'foo') return 'bar'
yield 'woot'
return next()
}, function * (action, next) {
if (action === 'bar') return 'qux'
yield 'narf'
return next()
}])
composed('foo')() // => 'bar' (done)
composed('bar')() // => 'woot', 'qux' (done)
composed('dup')() // => 'woot', 'narf', 'dup' (done)
API
compose(middleware)
middleware
- compose the given middleware
Returns: a generator of the same form as the middleware
middleware
/**
* The middleware signature
* @param {Mixed} action an immutable action that middleware can process
* @param {Function} next pass execution to next middleware (can yield or return)
* @param {Object} ctx the global context
* @return {Mixed} whatever your heart desires
*/
function * middleware (action, next, ctx) {
}
License
MIT