Marionette.CompositeView(2)を更新し続けるために、次の(1)のような長いポーリングモジュールを実装しました。
このポーリングをよりスマートにしたいと思います。
詳細には、このポーリングでコレクションをフェッチするのではなく、新しい要素のみをチェックして、すべてのビューが再度レンダリングされないようにする必要があります。
何か案は?
(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.
});
});