Remove some low hanging fruit to speed up startup.
This commit is contained in:
@@ -80,6 +80,10 @@ var BabyStats = function(container) {
|
|||||||
timeout: 60 * 30,
|
timeout: 60 * 30,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
this.tilesByType_ = {};
|
||||||
|
this.tiles_.forEach(function(tile) {
|
||||||
|
this.tilesByType_[tile.type] = tile;
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.intervals_ = {};
|
this.intervals_ = {};
|
||||||
this.displayDates_ = {};
|
this.displayDates_ = {};
|
||||||
@@ -183,16 +187,6 @@ BabyStats.prototype.onMessage_ = function(e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} type
|
|
||||||
* @return {Object}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
BabyStats.prototype.findTile_ = function(type) {
|
|
||||||
return this.tiles_.find(function(tile) { return tile.type == type; });
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {boolean} isEvent
|
* @param {boolean} isEvent
|
||||||
* @param {Cosmopolite.typeMessage} message
|
* @param {Cosmopolite.typeMessage} message
|
||||||
@@ -217,7 +211,7 @@ BabyStats.prototype.handleMessage_ = function(isEvent, message) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var tile = this.findTile_(message.message.type);
|
var tile = this.tilesByType_[message.message.type];
|
||||||
if (tile) {
|
if (tile) {
|
||||||
if (tile.ignore_duplicates && tile.active) {
|
if (tile.ignore_duplicates && tile.active) {
|
||||||
// Ignore (double trigger of a state-based tile)
|
// Ignore (double trigger of a state-based tile)
|
||||||
@@ -228,11 +222,13 @@ BabyStats.prototype.handleMessage_ = function(isEvent, message) {
|
|||||||
tile.active = true;
|
tile.active = true;
|
||||||
tile.messages.push(message);
|
tile.messages.push(message);
|
||||||
(tile.cancels || []).forEach(function(type) {
|
(tile.cancels || []).forEach(function(type) {
|
||||||
tile2 = this.findTile_(type);
|
tile2 = this.tilesByType_[type];
|
||||||
tile2.active = false;
|
tile2.active = false;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
this.updateTileStatus_();
|
if (isEvent) {
|
||||||
this.updateDisplayPage_();
|
this.updateTileStatus_();
|
||||||
|
this.updateDisplayPage_();
|
||||||
|
}
|
||||||
this.updateDisplayDate_(message);
|
this.updateDisplayDate_(message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -853,8 +849,8 @@ BabyStats.prototype.updateTileStatus_ = function() {
|
|||||||
BabyStats.prototype.updateDisplayPage_ = function() {
|
BabyStats.prototype.updateDisplayPage_ = function() {
|
||||||
var now = Date.now() / 1000;
|
var now = Date.now() / 1000;
|
||||||
|
|
||||||
var asleep = this.findTile_('asleep');
|
var asleep = this.tilesByType_['asleep'];
|
||||||
var awake = this.findTile_('awake');
|
var awake = this.tilesByType_['awake'];
|
||||||
if (asleep.active || awake.active) {
|
if (asleep.active || awake.active) {
|
||||||
this.displaySleepSummary_.style.visibility = 'visible';
|
this.displaySleepSummary_.style.visibility = 'visible';
|
||||||
if (asleep.active) {
|
if (asleep.active) {
|
||||||
|
|||||||
Reference in New Issue
Block a user