Only re-render network status when it changes
// FREEBIE
This commit is contained in:
parent
3f05c8ff87
commit
587e5265c5
1 changed files with 16 additions and 9 deletions
|
@ -5,10 +5,11 @@
|
||||||
|
|
||||||
Whisper.NetworkStatusView = Whisper.View.extend({
|
Whisper.NetworkStatusView = Whisper.View.extend({
|
||||||
className: 'network-status',
|
className: 'network-status',
|
||||||
|
templateName: 'networkStatus',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
|
|
||||||
var renderIntervalHandle = setInterval(this.render.bind(this), 5000);
|
var renderIntervalHandle = setInterval(this.update.bind(this), 5000);
|
||||||
extension.windows.onClosed(function () { clearInterval(renderIntervalHandle); });
|
extension.windows.onClosed(function () { clearInterval(renderIntervalHandle); });
|
||||||
|
|
||||||
setTimeout(this.finishConnectingGracePeriod.bind(this), 5000);
|
setTimeout(this.finishConnectingGracePeriod.bind(this), 5000);
|
||||||
|
@ -16,8 +17,11 @@
|
||||||
this.withinConnectingGracePeriod = true;
|
this.withinConnectingGracePeriod = true;
|
||||||
this.setSocketReconnectInterval(null);
|
this.setSocketReconnectInterval(null);
|
||||||
|
|
||||||
window.addEventListener('online', this.render.bind(this));
|
window.addEventListener('online', this.update.bind(this));
|
||||||
window.addEventListener('offline', this.render.bind(this));
|
window.addEventListener('offline', this.update.bind(this));
|
||||||
|
|
||||||
|
this.model = new Backbone.Model();
|
||||||
|
this.listenTo(this.model, 'change', this.onChange);
|
||||||
},
|
},
|
||||||
finishConnectingGracePeriod: function() {
|
finishConnectingGracePeriod: function() {
|
||||||
this.withinConnectingGracePeriod = false;
|
this.withinConnectingGracePeriod = false;
|
||||||
|
@ -72,18 +76,21 @@
|
||||||
hasInterruption: hasInterruption
|
hasInterruption: hasInterruption
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
render: function() {
|
update: function() {
|
||||||
var status = this.getNetworkStatus();
|
var status = this.getNetworkStatus();
|
||||||
|
this.model.set(status);
|
||||||
if (status.hasInterruption) {
|
},
|
||||||
|
render_attributes: function() {
|
||||||
|
return this.model.attributes;
|
||||||
|
},
|
||||||
|
onChange: function() {
|
||||||
|
this.render();
|
||||||
|
if (this.model.attributes.hasInterruption) {
|
||||||
this.$el.slideDown();
|
this.$el.slideDown();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
}
|
}
|
||||||
var template = Whisper.View.Templates['networkStatus'];
|
|
||||||
this.$el.html(Mustache.render(template, status, Whisper.View.Templates));
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue