function UpdatedData(channel) { this.channel = channel; this.values = []; }; UpdatedData.prototype.softPush = function(value) { for (var i = 0, len = this.values.length; i < len; i++) { var item = this.values[i].value; if (!this.equals(item, value)) continue; if (item.timer) clearTimeout(item.timer); this.values[i] = {value: value, copy: duplicate(value)}; value.timer = setTimeout(timeoutFunc, 12*1000, {elem: this.values[i], channel: this.channel}); return; } this.values.push({value: value, copy: duplicate(value)}); }; UpdatedData.prototype.equals = function(first, second) { if (first.plugin === second.plugin && first.plugin_instance === second.plugin_instance && first.type === second.type && first.type_instance === second.type_instance) return true; return false }; UpdatedData.prototype.getValues = function() { var returned = []; for (var i = 0, len = this.values.length; i < len; i++) { var item = this.values[i].copy; returned.push(item); } return returned; }; function timeoutFunc(map) { map.elem.value.isValid = map.elem.copy.isValid = false; clearTimeout(map.elem.value.timer); map.channel.emit('channel_data', JSON.stringify(map.elem.copy)); map.elem.value.timer = setTimeout(timeoutFunc, 12*1000, map); }; function duplicate(object) { return JSON.parse(JSON.stringify(object)); }; module.exports = UpdatedData;