坚持比较两个值

时间:2015-12-27 13:37:17

标签: javascript node.js

我正在为Kodi构建一个javascript远程,我只会在发生更改时发送数据。我坚持这种代码的和平。它将检查每x秒的值,但我只想在值发生变化时执行某些操作。有人可以对此有所了解吗?

every((0.35).second(), function() {
  var kodi_api_request = {"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1};
  var kodi = encodeURIComponent(JSON.stringify(kodi_api_request));
  var previous = {};
  var stuff = request
  .get('http://localhost:8080/jsonrpc?request=' + kodi, function (error, response, data) {
    var newdata = data
    if (previous !== newdata) {
      console.log('changed');
      previous = newdata;
      console.log(newdata);
    } else {
      console.log('Error!');
    }
  });
});

0 个答案:

没有答案