Whitespace for strict linting.

This commit is contained in:
Ian Gulliver
2014-05-28 21:52:12 -07:00
parent 9e791bcf3b
commit d5941a49f7
2 changed files with 68 additions and 23 deletions

View File

@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/** /**
* Java-compatible hash calculation * Java-compatible hash calculation
* *
@@ -36,6 +37,7 @@ String.prototype.hashCode = function() {
}; };
/** /**
* @constructor * @constructor
* @param {?Cosmopolite.typeCallbacks=} callbacks * @param {?Cosmopolite.typeCallbacks=} callbacks
@@ -98,7 +100,7 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) {
if (this.messageQueueKey_ in localStorage) { if (this.messageQueueKey_ in localStorage) {
/** @type {Array.<Cosmopolite.typeMessage>} */ /** @type {Array.<Cosmopolite.typeMessage>} */
var messages = /** @type {Array.<Cosmopolite.typeMessage>} */ var messages = /** @type {Array.<Cosmopolite.typeMessage>} */
(JSON.parse(localStorage[this.messageQueueKey_])); (JSON.parse(localStorage[this.messageQueueKey_]));
if (messages.length) { if (messages.length) {
console.log( console.log(
this.loggingPrefix_(), '(re-)sending queued messages:', messages); this.loggingPrefix_(), '(re-)sending queued messages:', messages);
@@ -108,8 +110,8 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) {
// message's client_message_id, which is intentionally not exposed via // message's client_message_id, which is intentionally not exposed via
// the sendMessage API // the sendMessage API
this.sendRPC_( this.sendRPC_(
'sendMessage', message, 'sendMessage', message,
this.onMessageSent_.bind(this, message, null, null)); this.onMessageSent_.bind(this, message, null, null));
}, this); }, this);
} else { } else {
localStorage[this.messageQueueKey_] = JSON.stringify([]); localStorage[this.messageQueueKey_] = JSON.stringify([]);
@@ -133,6 +135,7 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) {
}, this); }, this);
}; };
/** @typedef {{onConnect: (function()|undefined), /** @typedef {{onConnect: (function()|undefined),
onDisconnect: (function()|undefined), onDisconnect: (function()|undefined),
onLogin: (function(string, string)|undefined), onLogin: (function(string, string)|undefined),
@@ -142,21 +145,25 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) {
onUnpin: (function(Cosmopolite.typeMessage)|undefined)}} */ onUnpin: (function(Cosmopolite.typeMessage)|undefined)}} */
Cosmopolite.typeCallbacks; Cosmopolite.typeCallbacks;
/** /**
* @typedef {{event_type: string}} * @typedef {{event_type: string}}
* @private * @private
*/ */
Cosmopolite.typeEvent_; Cosmopolite.typeEvent_;
/** @typedef {{event_type: string, /** @typedef {{event_type: string,
profile: string, profile: string,
google_user: string}} */ google_user: string}} */
Cosmopolite.typeLogin; Cosmopolite.typeLogin;
/** @typedef {{event_type: string, /** @typedef {{event_type: string,
profile: string}} */ profile: string}} */
Cosmopolite.typeLogout; Cosmopolite.typeLogout;
/** @typedef {{event_type: string, /** @typedef {{event_type: string,
id: number, id: number,
created: number, created: number,
@@ -165,6 +172,7 @@ Cosmopolite.typeLogout;
message: *}} */ message: *}} */
Cosmopolite.typeMessage; Cosmopolite.typeMessage;
/** /**
* @typedef {{command: string, * @typedef {{command: string,
arguments: Object, arguments: Object,
@@ -173,14 +181,17 @@ Cosmopolite.typeMessage;
*/ */
Cosmopolite.typeRPC_; Cosmopolite.typeRPC_;
/** @typedef {{name: string, /** @typedef {{name: string,
readable_only_by: (string|undefined), readable_only_by: (string|undefined),
writable_only_by: (string|undefined)}} */ writable_only_by: (string|undefined)}} */
Cosmopolite.typeSubject; Cosmopolite.typeSubject;
/** @typedef {(Cosmopolite.typeSubject|string|number)} */ /** @typedef {(Cosmopolite.typeSubject|string|number)} */
Cosmopolite.typeSubjectLoose; Cosmopolite.typeSubjectLoose;
/** /**
* @typedef {{messages: Array.<Cosmopolite.typeMessage>, * @typedef {{messages: Array.<Cosmopolite.typeMessage>,
pins: Array.<Cosmopolite.typeMessage>, pins: Array.<Cosmopolite.typeMessage>,
@@ -234,6 +245,7 @@ Cosmopolite.prototype.shutdown = function() {
} }
}; };
/** /**
* Subscribe to a subject. * Subscribe to a subject.
* *
@@ -274,7 +286,7 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id) {
// without waiting for the promise, but do our best // without waiting for the promise, but do our best
if (subjectString in this.subscriptions_) { if (subjectString in this.subscriptions_) {
this.subscriptions_[subjectString].state = this.subscriptions_[subjectString].state =
Cosmopolite.SubscriptionState_.ACTIVE; Cosmopolite.SubscriptionState_.ACTIVE;
} }
/** @type {string} */ /** @type {string} */
var result = response['result']; var result = response['result'];
@@ -287,6 +299,7 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id) {
}.bind(this)); }.bind(this));
}; };
/** /**
* Unsubscribe from a subject and destroy all listeners. * Unsubscribe from a subject and destroy all listeners.
* *
@@ -310,6 +323,7 @@ Cosmopolite.prototype.unsubscribe = function(subject) {
}.bind(this)); }.bind(this));
}; };
/** /**
* Post a message to the given subject, storing it and notifying all listeners. * Post a message to the given subject, storing it and notifying all listeners.
* *
@@ -331,11 +345,12 @@ Cosmopolite.prototype.sendMessage = function(subject, message) {
localStorage[this.messageQueueKey_] = JSON.stringify(messageQueue); localStorage[this.messageQueueKey_] = JSON.stringify(messageQueue);
this.sendRPC_( this.sendRPC_(
'sendMessage', args, 'sendMessage', args,
this.onMessageSent_.bind(this, args, resolve, reject)); this.onMessageSent_.bind(this, args, resolve, reject));
}.bind(this)); }.bind(this));
}; };
/** /**
* Fetch all received messages for a subject * Fetch all received messages for a subject
* *
@@ -351,6 +366,7 @@ Cosmopolite.prototype.getMessages = function(subject) {
return this.subscriptions_[subjectString].messages; return this.subscriptions_[subjectString].messages;
}; };
/** /**
* Fetch the most recent message for a subject * Fetch the most recent message for a subject
* *
@@ -368,6 +384,7 @@ Cosmopolite.prototype.getLastMessage = function(subject) {
} }
}; };
/** /**
* Fetch all current pins for a subject * Fetch all current pins for a subject
* *
@@ -383,6 +400,7 @@ Cosmopolite.prototype.getPins = function(subject) {
return this.subscriptions_[subjectString].pins; return this.subscriptions_[subjectString].pins;
}; };
/** /**
* Fetch our profile ID. * Fetch our profile ID.
* *
@@ -398,7 +416,8 @@ Cosmopolite.prototype.getProfile = function() {
}.bind(this)); }.bind(this));
}; };
/**
/**
* Return our current profile ID, if known. * Return our current profile ID, if known.
* *
* @return {?string} Profile ID. * @return {?string} Profile ID.
@@ -408,6 +427,7 @@ Cosmopolite.prototype.currentProfile = function() {
return this.profile_; return this.profile_;
}; };
/** /**
* Pin a message to the given subject, storing it and notifying all listeners. * Pin a message to the given subject, storing it and notifying all listeners.
* *
@@ -438,6 +458,7 @@ Cosmopolite.prototype.pin = function(subject, message) {
}.bind(this)); }.bind(this));
}; };
/** /**
* Unpin a message from the given subject, storing it and notifying listeners. * Unpin a message from the given subject, storing it and notifying listeners.
* *
@@ -458,6 +479,7 @@ Cosmopolite.prototype.unpin = function(id) {
}.bind(this)); }.bind(this));
}; };
/** /**
* Generate a string identifying us to be included in log messages. * Generate a string identifying us to be included in log messages.
* *
@@ -473,6 +495,7 @@ Cosmopolite.prototype.loggingPrefix_ = function() {
} }
}; };
/** /**
* Generate a v4 UUID. * Generate a v4 UUID.
* *
@@ -492,6 +515,7 @@ Cosmopolite.prototype.uuid_ = function() {
}); });
}; };
/** /**
* Canonicalize a subject name or object * Canonicalize a subject name or object
* *
@@ -537,6 +561,7 @@ Cosmopolite.prototype.onLoad_ = function() {
this.createChannel_(); this.createChannel_();
}; };
/** /**
* Callback for a message from another browser window * Callback for a message from another browser window
* *
@@ -563,6 +588,7 @@ Cosmopolite.prototype.onReceiveMessage_ = function(data) {
} }
}; };
/** /**
* Register onReceiveMessage to receive callbacks * Register onReceiveMessage to receive callbacks
* *
@@ -587,6 +613,7 @@ Cosmopolite.prototype.registerMessageHandlers_ = function() {
window.addEventListener('message', this.messageHandler_); window.addEventListener('message', this.messageHandler_);
}; };
/** /**
* Callback for a sendMessage RPC ack by the server. * Callback for a sendMessage RPC ack by the server.
* *
@@ -616,6 +643,7 @@ Cosmopolite.prototype.onMessageSent_ = function(
} }
}; };
/** /**
* Send a single RPC to the server. * Send a single RPC to the server.
* *
@@ -641,6 +669,7 @@ Cosmopolite.prototype.sendRPC_ = function(command, args, onSuccess) {
} }
}; };
/** /**
* Send one or more RPCs to the server. * Send one or more RPCs to the server.
* *
@@ -674,7 +703,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
} }
if (this.namespace_ + ':google_user_id' in localStorage) { if (this.namespace_ + ':google_user_id' in localStorage) {
request['google_user_id'] = request['google_user_id'] =
localStorage[this.namespace_ + ':google_user_id']; localStorage[this.namespace_ + ':google_user_id'];
} }
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@@ -682,11 +711,11 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
var retryAfterDelay = (function(newCommands) { var retryAfterDelay = (function(newCommands) {
var intDelay = var intDelay =
xhr.getResponseHeader('Retry-After') || xhr.getResponseHeader('Retry-After') ||
Math.min(32, Math.max(2, delay || 2)); Math.min(32, Math.max(2, delay || 2));
console.log( console.log(
this.loggingPrefix_(), this.loggingPrefix_(),
'RPC failed; will retry in ' + intDelay + ' seconds'); 'RPC failed; will retry in ' + intDelay + ' seconds');
var retry = (function() { var retry = (function() {
this.sendRPCs_(newCommands, Math.pow(intDelay, 2)); this.sendRPCs_(newCommands, Math.pow(intDelay, 2));
}).bind(this); }).bind(this);
@@ -702,7 +731,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
if ('google_user_id' in data) { if ('google_user_id' in data) {
localStorage[this.namespace_ + ':google_user_id'] = localStorage[this.namespace_ + ':google_user_id'] =
data['google_user_id']; data['google_user_id'];
} }
if ('client_id' in data) { if ('client_id' in data) {
localStorage[this.namespace_ + ':client_id'] = data['client_id']; localStorage[this.namespace_ + ':client_id'] = data['client_id'];
@@ -715,7 +744,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
} }
if (data['status'] != 'ok') { if (data['status'] != 'ok') {
console.log(this.loggingPrefix_(), console.log(this.loggingPrefix_(),
'server returned unknown status:', data['status']); 'server returned unknown status:', data['status']);
// TODO(flamingcow): Refresh the page? Show an alert? // TODO(flamingcow): Refresh the page? Show an alert?
return; return;
} }
@@ -750,6 +779,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
xhr.send(JSON.stringify(request)); xhr.send(JSON.stringify(request));
}; };
/** /**
* Are we currently clear to put RPCs on the wire? * Are we currently clear to put RPCs on the wire?
* *
@@ -769,6 +799,7 @@ Cosmopolite.prototype.maySendRPC_ = function() {
return true; return true;
}; };
/** /**
* Handle tasks needed after reconnecting the channel * Handle tasks needed after reconnecting the channel
* *
@@ -787,7 +818,7 @@ Cosmopolite.prototype.onReconnect_ = function() {
var subscription = this.subscriptions_[subject]; var subscription = this.subscriptions_[subject];
/** @type {Cosmopolite.typeSubject} */ /** @type {Cosmopolite.typeSubject} */
var canonicalSubject = var canonicalSubject =
/** @type {Cosmopolite.typeSubject} */ (JSON.parse(subject)); /** @type {Cosmopolite.typeSubject} */ (JSON.parse(subject));
if (subscription.state != Cosmopolite.SubscriptionState_.ACTIVE) { if (subscription.state != Cosmopolite.SubscriptionState_.ACTIVE) {
continue; continue;
} }
@@ -815,6 +846,7 @@ Cosmopolite.prototype.onReconnect_ = function() {
this.sendRPCs_(rpcs); this.sendRPCs_(rpcs);
}; };
/** /**
* Send RPC to create a server -> client channel * Send RPC to create a server -> client channel
* *
@@ -840,6 +872,7 @@ Cosmopolite.prototype.createChannel_ = function() {
this.sendRPCs_(rpcs); this.sendRPCs_(rpcs);
}; };
/** /**
* Callback for channel creation on the server side * Callback for channel creation on the server side
* *
@@ -869,6 +902,7 @@ Cosmopolite.prototype.onCreateChannel_ = function(data) {
}); });
}; };
/** /**
* Callback from channel library for successful open * Callback from channel library for successful open
* *
@@ -893,6 +927,7 @@ Cosmopolite.prototype.onSocketOpen_ = function() {
this.onReconnect_(); this.onReconnect_();
}; };
/** /**
* Callback from channel library for closure; reopen. * Callback from channel library for closure; reopen.
* *
@@ -927,6 +962,7 @@ Cosmopolite.prototype.onSocketClose_ = function() {
this.createChannel_(); this.createChannel_();
}; };
/** /**
* Callback from channel library for message reception over channel * Callback from channel library for message reception over channel
* *
@@ -938,6 +974,7 @@ Cosmopolite.prototype.onSocketMessage_ = function(msg) {
/** @type {Cosmopolite.typeEvent_} */ (JSON.parse(msg.data))); /** @type {Cosmopolite.typeEvent_} */ (JSON.parse(msg.data)));
}; };
/** /**
* Callback from channel library for error on channel * Callback from channel library for error on channel
* *
@@ -951,6 +988,7 @@ Cosmopolite.prototype.onSocketError_ = function(msg) {
} }
}; };
/** /**
* Callback on receiving a 'close' event from the server * Callback on receiving a 'close' event from the server
* *
@@ -963,6 +1001,7 @@ Cosmopolite.prototype.onClose_ = function() {
} }
}; };
/** /**
* Callback on receiving a 'login' event from the server * Callback on receiving a 'login' event from the server
* *
@@ -977,6 +1016,7 @@ Cosmopolite.prototype.onLogin_ = function(e) {
} }
}; };
/** /**
* Callback on receiving a 'logout' event from the server * Callback on receiving a 'logout' event from the server
* *
@@ -986,10 +1026,11 @@ Cosmopolite.prototype.onLogin_ = function(e) {
Cosmopolite.prototype.onLogout_ = function(e) { Cosmopolite.prototype.onLogout_ = function(e) {
if (this.callbacks_.onLogout) { if (this.callbacks_.onLogout) {
this.callbacks_.onLogout( this.callbacks_.onLogout(
this.urlPrefix_ + '/auth/login'); this.urlPrefix_ + '/auth/login');
} }
}; };
/** /**
* Callback on receiving a 'message' event from the server * Callback on receiving a 'message' event from the server
* *
@@ -1003,8 +1044,8 @@ Cosmopolite.prototype.onMessage_ = function(e) {
var subscription = this.subscriptions_[subjectString]; var subscription = this.subscriptions_[subjectString];
if (!subscription) { if (!subscription) {
console.log( console.log(
this.loggingPrefix_(), this.loggingPrefix_(),
'message from unrecognized subject:', e); 'message from unrecognized subject:', e);
return; return;
} }
/** @type {boolean} */ /** @type {boolean} */
@@ -1035,6 +1076,7 @@ Cosmopolite.prototype.onMessage_ = function(e) {
} }
}; };
/** /**
* Callback on receiving a 'pin' event from the server * Callback on receiving a 'pin' event from the server
* *
@@ -1048,8 +1090,8 @@ Cosmopolite.prototype.onPin_ = function(e) {
var subscription = this.subscriptions_[subjectString]; var subscription = this.subscriptions_[subjectString];
if (!subscription) { if (!subscription) {
console.log( console.log(
this.loggingPrefix_(), this.loggingPrefix_(),
'message from unrecognized subject:', e); 'message from unrecognized subject:', e);
return; return;
} }
/** @type {boolean} */ /** @type {boolean} */
@@ -1068,6 +1110,7 @@ Cosmopolite.prototype.onPin_ = function(e) {
} }
}; };
/** /**
* Callback on receiving an 'unpin' event from the server * Callback on receiving an 'unpin' event from the server
* *
@@ -1081,8 +1124,8 @@ Cosmopolite.prototype.onUnpin_ = function(e) {
var subscription = this.subscriptions_[subjectString]; var subscription = this.subscriptions_[subjectString];
if (!subscription) { if (!subscription) {
console.log( console.log(
this.loggingPrefix_(), this.loggingPrefix_(),
'message from unrecognized subject:', e); 'message from unrecognized subject:', e);
return; return;
} }
/** @type {?number} */ /** @type {?number} */
@@ -1105,6 +1148,7 @@ Cosmopolite.prototype.onUnpin_ = function(e) {
} }
}; };
/** /**
* Callback for Cosmopolite event (received via channel or pseudo-channel) * Callback for Cosmopolite event (received via channel or pseudo-channel)
* *
@@ -1149,6 +1193,7 @@ Cosmopolite.prototype.onServerEvent_ = function(e) {
} }
}; };
/** @type {function(new:Cosmopolite, /** @type {function(new:Cosmopolite,
?Cosmopolite.typeCallbacks=, ?Cosmopolite.typeCallbacks=,
?string=, ?string=,

View File

@@ -13,4 +13,4 @@ curl \
http://closure-compiler.appspot.com/compile http://closure-compiler.appspot.com/compile
echo echo
gjslint --disable=0121 cosmopolite.js gjslint --strict --disable=0121,0233 cosmopolite.js