baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript

Home Page:https://baconjs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using with specific lib is returning null error for instance method

iDVB opened this issue · comments

You can see the details over at the home-controller issues.

However, here is it again...

I'm finding that the links() function of other lib does not seem to work with Bacon like many other typical functions of other popular libs. Eg. fs.readFile().

It's entirely possible that I'm doing something wrong, but something just doesn't seem right.
Something like this works... (non-home-controller)

var Bacon = require('baconjs').Bacon,
    fs = require('fs');
var read = Bacon.fromNodeCallback(fs.readFile, 'input.txt');
read.onError(function(error) { console.log("Reading failed: " + error); });
read.onValue(function(value) { console.log("Read contents: " + value); });

Also, this DOES work (home-controller)

plm.serial(PLM_SERIAL_COM, function(){
    console.log('CONNECTED!');
    plm.links(null, function(error, link){
        console.log(link);
    })
});

However, this does NOT work (home-controller)

plm.serial(PLM_SERIAL_COM, function(){
    console.log('CONNECTED!');
    var linksStream = Bacon.fromNodeCallback(plm.links, null);
    linksStream.onValue(function(link){
        console.log(link);
    });
});

The error is the more interesting thing to me...

TypeError: Cannot call method 'firstLink' of null
    at Insteon.links (/Users/me/Projects/leaf-box/node_modules/home-controller/lib/Insteon/index.js:1113:17)

When I go into /lib/Insteon/index.html adding console.log(this) consoles out null. However, when I console the same in the typical, non-FRP version of home-controller it of course consoles out the plm/Insteon instance.

Any idea why this would happen?