将 Highland 与节点客户端结合使用

Using Highland in combination with node-client

我正在尝试使用 highland in combination with the heroku-client。但在 heroku 客户端内部它使用 this,即使我尝试 bind 绑定它,该函数也会给出错误消息,其中有对 this 的引用我无法让它工作。

对不对,代码看起来像这样

const Heroku = require('heroku-client');
const hl = require('highland');
var hk = new Heroku({
  token: process.env.HEROKU_API_TOKEN
});
var list = hl.wrapCallback(hk.apps().list.bind(hk));
list().toArray((a) => 'console.log(a)')

因此此代码片段失败并显示以下错误消息:

...node_modules/heroku-client/lib/resourceBuilder.js:35
if (this.params.length !== pathParams.length) {
               ^

TypeError: Cannot read property 'length' of undefined

哟! :-)

您绑定到 hk 而不是 hk.apps() return,这是 list 函数所依赖的(它是 hk.apps() returns)

试试这个:

const Heroku = require('heroku-client');
const hl = require('highland');
const hk = new Heroku({
  token: process.env.HEROKU_API_TOKEN
});
const hkApps = hk.apps();
const list = hl.wrapCallback(hkApps.list.bind(hkApps));
list().toArray((a) => 'console.log(a)')