Debounce gather refreshes

This commit is contained in:
Chris Blanchard 2015-08-28 14:18:09 +01:00
parent dd4c6ddafa
commit 90e6ff758a

View file

@ -24,9 +24,10 @@ var Server = require("./server");
var Gather = require("./gather");
var gather;
var previousGather;
var _ = require("lodash");
module.exports = function (namespace) {
var refreshGather = function () {
var refreshGather = _.debounce(function () {
namespace.sockets.forEach(function (socket) {
socket.emit("gather:refresh", {
gather: gather.toJson(),
@ -36,7 +37,10 @@ module.exports = function (namespace) {
previousGather: previousGather
});
});
};
}, 200, {
leading: true,
trailing: true
});
var newGather = function () {
if (gather) previousGather = gather;