Skip to content

Commit

Permalink
reimpl object compare for reload
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed May 22, 2019
1 parent 8eddec4 commit 56b7131
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cli/lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultPollInterval = 600;
const uuid = require('uuid/v1');
const debug = require('debug')('microgateway');
const jsdiff = require('diff');
const _ = require('lodash');

const Gateway = function() {};

Expand Down Expand Up @@ -326,19 +327,22 @@ function hasConfigChanged(oldConfig, newConfig) {
//do not compare uid
delete oldConfig['uid'];

var diff = jsdiff.diffWords(JSON.stringify(oldConfig), JSON.stringify(newConfig));
if (diff.length == 1) {

if (_.isEqual(oldConfig, newConfig)) {
debug("no changes detected");
return false;
} else {
diff.forEach(function(part) {
if (part.added)
debug("Added->" + part.value);
else if (part.removed)
debug("Removed->" + part.value);
else
debug("Unchanged->" + part.value);
});
if (debug.enabled) {
var diff = jsdiff.diffWords(JSON.stringify(oldConfig), JSON.stringify(newConfig));
diff.forEach(function(part) {
if (part.added)
debug("Added->" + part.value);
else if (part.removed)
debug("Removed->" + part.value);
else
debug("Unchanged->" + part.value);
});
}
return true;
}
}
Expand Down

0 comments on commit 56b7131

Please sign in to comment.