Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants