convert
convert copied to clipboard
Passing argument not working?
First off, I do not know if this belongs here in this module, but I'll start here. I'm experimenting with the following code:
var convert = require('koa-convert');
var genbind = require('generator-bind');
function* myGen(i) {
console.log(this.x, i);
}
myGen = genbind({x:666}, myGen);
convert(myGen)(9); // <--- this outputs 666 undefined, was expecting 666 9
I can't seem to pass an argument to the generator function. If this isn't to do with koa-convert then I'm guessing generator-bind is at fault.
I don't think you need generator-bind. e.g.
var convert = require('koa-convert');
// legacy middleware has `this` as context, and first argument as `next` generator
function* myGen(next) {
console.log(this.x);
}
var convertedGen = convert(myGen);
// modern middleware has first argument as context, and second argument as `next` function
convertedGen({x: 666}, function next() { });