Run a koax middleware stack.
This is the raw middleware stack runner. The basic principal of the runner is that values that are yielded in the middleware stack are dispatched back through the middleware stack to get resolved. yielded functors (arrays, generators, and iterators) aren't dispatched directly - instead the functors values are mapped, using predefined mapping functions, over the middleware stack.
$ npm install @koax/run
import run from '@koax/run'
let dispatch = run([
function * (action, next) {
if (action === 'foo') return 'bar'
else if (action === 'qux') return yield 'foo'
return next()
},
function * (action, next) {
if (action === 'multi') return yield ['foo', 'qux']
return next()
}
])
dispatch('foo').then((res) => res) // => 'bar'
disaptch('qux').then((res) => res) // => 'bar'
disaptch('multi').then((res) => res) // => ['bar', 'bar']
middleware
- koax middleware arrayctx
- ctx for middleware stack
Returns: dispatch function: dispatch(action, next)
MIT