Shortcut calling onMessage for everything in cache.

This commit is contained in:
Ian Gulliver
2016-01-05 20:44:28 -08:00
parent 77227df9aa
commit 5280b710d2

View File

@@ -343,12 +343,13 @@ Cosmopolite.prototype.subscribe = function(subjects, opt_messages, opt_lastID) {
var key = this.messageCacheKeyPrefix_ + subjectString; var key = this.messageCacheKeyPrefix_ + subjectString;
var messageStr = localStorage[key]; var messageStr = localStorage[key];
if (messageStr) { if (messageStr) {
var messages = JSON.parse(messageStr); subscription.messages = JSON.parse(messageStr);
subscription.use_cache = false; // Simplified version of onMessage_, to avoid a bunch of the
messages.forEach(function(msg) { // overhead.
msg['message'] = JSON.stringify(msg['message']); subscription.messages.forEach(function(msg) {
this.onMessage_(msg); this.dispatchEvent(new CustomEvent('message', {
subscription.use_cache = true; 'detail': msg,
}));
}.bind(this)); }.bind(this));
} }
if (subscription.messages.length > 0) { if (subscription.messages.length > 0) {