In order to keep update a Marionette.CompositeView (2) I implemented a long polling module which looks like the following (1).
I would like to make this polling smarter.
In detail I would like that this polling should not fetch the collection but check only the new elements to avoid rendering all the view again.
Any ideas?
(1)
define([
'underscore'
], function (_) {
"use strict";
return {
executePolling: function () {
this.fetch({success : this.onFetch});
},
startPolling: function () {
_.bindAll(this, 'onFetch', 'executePolling');
this.minutes = 1;
this.polling = true;
this.executePolling();
},
stopPolling: function () {
this.polling = false;
},
onFetch: function () {
if (this.polling) {
setTimeout(this.executePolling, 1000 * 60 * this.minutes);
}
}
};
});
(2)
define([
'underscore'
], function (_) {
"use strict";
return Marionette.CompositeView.extend({
initialize: function () {
this.collection.startPolling();
}
// some code.
});
});