Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing argument not working? #7

Open
basickarl opened this issue Oct 11, 2016 · 1 comment
Open

Passing argument not working? #7

basickarl opened this issue Oct 11, 2016 · 1 comment

Comments

@basickarl
Copy link

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.

@gyson
Copy link
Member

gyson commented Oct 12, 2016

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() {  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants