Last ugly style guide compliance fixes

This commit is contained in:
Ian Gulliver
2014-05-28 23:25:53 -07:00
parent 10dd0e4db0
commit 5d39c9abdf
3 changed files with 60 additions and 57 deletions

View File

@@ -40,25 +40,26 @@ String.prototype.hashCode = function() {
/** /**
* @constructor * @constructor
* @param {?Cosmopolite.typeCallbacks=} callbacks * @param {?Cosmopolite.typeCallbacks=} opt_callbacks
* @param {?string=} urlPrefix * @param {?string=} opt_urlPrefix
* @param {?string=} namespace * @param {?string=} opt_namespace
*/ */
var Cosmopolite = function(callbacks, urlPrefix, namespace) { var Cosmopolite = function(opt_callbacks, opt_urlPrefix, opt_namespace) {
/** /**
* @type {Cosmopolite.typeCallbacks} * @type {Cosmopolite.typeCallbacks}
* @private * @private
*/ */
this.callbacks_ = callbacks || /** @type {Cosmopolite.typeCallbacks} */ ({}); this.callbacks_ =
opt_callbacks || /** @type {Cosmopolite.typeCallbacks} */ ({});
/** /**
* @type {string} * @type {string}
* @private * @private
*/ */
this.urlPrefix_ = urlPrefix || '/cosmopolite'; this.urlPrefix_ = opt_urlPrefix || '/cosmopolite';
/** /**
* @type {string} * @type {string}
* @private */ * @private */
this.namespace_ = namespace || 'cosmopolite'; this.namespace_ = opt_namespace || 'cosmopolite';
/** /**
* @type {Cosmopolite.ChannelState_} * @type {Cosmopolite.ChannelState_}
@@ -119,7 +120,7 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) {
/** @type {Array.<string>} */ /** @type {Array.<string>} */
var scriptUrls = [ var scriptUrls = [
'/_ah/channel/jsapi', '/_ah/channel/jsapi'
]; ];
/** /**
* @type {number} * @type {number}
@@ -176,7 +177,7 @@ Cosmopolite.typeMessage;
/** /**
* @typedef {{command: string, * @typedef {{command: string,
arguments: Object, arguments: Object,
onSuccess: (function(Object)|null|undefined)}} onSuccess: (function(Object)|null)}}
* @private * @private
*/ */
Cosmopolite.typeRPC_; Cosmopolite.typeRPC_;
@@ -214,7 +215,7 @@ Cosmopolite.ChannelState_ = {
// RPC complete, channel opening // RPC complete, channel opening
OPENING: 3, OPENING: 3,
// Channel opened // Channel opened
OPEN: 3, OPEN: 3
}; };
@@ -225,7 +226,7 @@ Cosmopolite.ChannelState_ = {
*/ */
Cosmopolite.SubscriptionState_ = { Cosmopolite.SubscriptionState_ = {
PENDING: 1, PENDING: 1,
ACTIVE: 2, ACTIVE: 2
}; };
@@ -252,12 +253,13 @@ Cosmopolite.prototype.shutdown = function() {
* Start receiving messages sent to this subject via the onMessage callback. * Start receiving messages sent to this subject via the onMessage callback.
* *
* @param {Cosmopolite.typeSubjectLoose} subject * @param {Cosmopolite.typeSubjectLoose} subject
* @param {?number=} messages Number of recent messages to request; * @param {?number=} opt_messages Number of recent messages to request;
* 0 for none, -1 for all * 0 for none, -1 for all
* @param {?number=} last_id ID of last message received; fetch messages since * @param {?number=} opt_last_id ID of last message received; fetch messages
* since
* @return {Promise} * @return {Promise}
*/ */
Cosmopolite.prototype.subscribe = function(subject, messages, last_id) { Cosmopolite.prototype.subscribe = function(subject, opt_messages, opt_last_id) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
/** @type {Cosmopolite.typeSubject} */ /** @type {Cosmopolite.typeSubject} */
var canonicalSubject = this.canonicalSubject_(subject); var canonicalSubject = this.canonicalSubject_(subject);
@@ -267,18 +269,18 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id) {
this.subscriptions_[subjectString] = { this.subscriptions_[subjectString] = {
'messages': [], 'messages': [],
'pins': [], 'pins': [],
'state': Cosmopolite.SubscriptionState_.PENDING, 'state': Cosmopolite.SubscriptionState_.PENDING
}; };
} }
var args = { var args = {
'subject': canonicalSubject, 'subject': canonicalSubject
}; };
if (messages) { if (opt_messages) {
args['messages'] = messages; args['messages'] = opt_messages;
} }
if (last_id != null) { if (opt_last_id != null) {
args['last_id'] = last_id; args['last_id'] = opt_last_id;
} }
this.sendRPC_('subscribe', args, function(response) { this.sendRPC_('subscribe', args, function(response) {
@@ -317,7 +319,7 @@ Cosmopolite.prototype.unsubscribe = function(subject) {
var subjectString = JSON.stringify(canonicalSubject); var subjectString = JSON.stringify(canonicalSubject);
delete this.subscriptions_[subjectString]; delete this.subscriptions_[subjectString];
var args = { var args = {
'subject': canonicalSubject, 'subject': canonicalSubject
}; };
this.sendRPC_('unsubscribe', args, resolve); this.sendRPC_('unsubscribe', args, resolve);
}.bind(this)); }.bind(this));
@@ -336,7 +338,7 @@ Cosmopolite.prototype.sendMessage = function(subject, message) {
var args = { var args = {
'subject': this.canonicalSubject_(subject), 'subject': this.canonicalSubject_(subject),
'message': JSON.stringify(message), 'message': JSON.stringify(message),
'sender_message_id': this.uuid_(), 'sender_message_id': this.uuid_()
}; };
// No message left behind. // No message left behind.
@@ -447,7 +449,7 @@ Cosmopolite.prototype.pin = function(subject, message) {
var args = { var args = {
'subject': this.canonicalSubject_(subject), 'subject': this.canonicalSubject_(subject),
'message': JSON.stringify(message), 'message': JSON.stringify(message),
'sender_message_id': id, 'sender_message_id': id
}; };
@@ -470,7 +472,7 @@ Cosmopolite.prototype.unpin = function(id) {
var pin = this.pins_[id]; var pin = this.pins_[id];
var args = { var args = {
'subject': pin['subject'], 'subject': pin['subject'],
'sender_message_id': pin['sender_message_id'], 'sender_message_id': pin['sender_message_id']
}; };
delete this.pins_[id]; delete this.pins_[id];
@@ -531,7 +533,7 @@ Cosmopolite.prototype.canonicalSubject_ = function(subject) {
} }
if (typeof(subject) == 'string') { if (typeof(subject) == 'string') {
subject = { subject = {
'name': subject, 'name': subject
}; };
} }
if (subject['readable_only_by'] === null) { if (subject['readable_only_by'] === null) {
@@ -651,15 +653,15 @@ Cosmopolite.prototype.onMessageSent_ = function(
* *
* @param {string} command Command name to call * @param {string} command Command name to call
* @param {Object} args Arguments to pass to server * @param {Object} args Arguments to pass to server
* @param {?function(Object)=} onSuccess Success callback function * @param {?function(Object)=} opt_onSuccess Success callback function
* @private * @private
*/ */
Cosmopolite.prototype.sendRPC_ = function(command, args, onSuccess) { Cosmopolite.prototype.sendRPC_ = function(command, args, opt_onSuccess) {
/** @type {Cosmopolite.typeRPC_} */ /** @type {Cosmopolite.typeRPC_} */
var rpc = { var rpc = {
'command': command, 'command': command,
'arguments': args, 'arguments': args,
'onSuccess': onSuccess, 'onSuccess': opt_onSuccess || null
}; };
if (this.maySendRPC_()) { if (this.maySendRPC_()) {
this.sendRPCs_([rpc]); this.sendRPCs_([rpc]);
@@ -678,20 +680,21 @@ Cosmopolite.prototype.sendRPC_ = function(command, args, onSuccess) {
* backoff. * backoff.
* *
* @param {Array.<Cosmopolite.typeRPC_>} commands List of commands to execute * @param {Array.<Cosmopolite.typeRPC_>} commands List of commands to execute
* @param {number=} delay Seconds waited before executing this call for backoff * @param {number=} opt_delay Seconds waited before executing this call for
* backoff
* @private * @private
*/ */
Cosmopolite.prototype.sendRPCs_ = function(commands, delay) { Cosmopolite.prototype.sendRPCs_ = function(commands, opt_delay) {
if (this.shutdown_ || !commands.length) { if (this.shutdown_ || !commands.length) {
return; return;
} }
var request = { var request = {
'instance_id': this.instanceID_, 'instance_id': this.instanceID_,
'commands': [], 'commands': []
}; };
commands.forEach(function(command) { commands.forEach(function(command) {
var request_command = { var request_command = {
'command': command['command'], 'command': command['command']
}; };
if ('arguments' in command) { if ('arguments' in command) {
request_command['arguments'] = command['arguments']; request_command['arguments'] = command['arguments'];
@@ -712,7 +715,7 @@ 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, opt_delay || 2));
console.log( console.log(
this.loggingPrefix_(), this.loggingPrefix_(),
'RPC failed; will retry in ' + intDelay + ' seconds'); 'RPC failed; will retry in ' + intDelay + ' seconds');
@@ -831,7 +834,7 @@ Cosmopolite.prototype.onReconnect_ = function() {
'command': 'subscribe', 'command': 'subscribe',
'arguments': { 'arguments': {
'subject': canonicalSubject, 'subject': canonicalSubject,
'last_id': last_id, 'last_id': last_id
} }
}); });
} }
@@ -840,7 +843,7 @@ Cosmopolite.prototype.onReconnect_ = function() {
var pin = this.pins_[id]; var pin = this.pins_[id];
rpcs.push({ rpcs.push({
'command': 'pin', 'command': 'pin',
'arguments': pin, 'arguments': pin
}); });
} }
this.sendRPCs_(rpcs); this.sendRPCs_(rpcs);
@@ -865,8 +868,8 @@ Cosmopolite.prototype.createChannel_ = function() {
var rpcs = [ var rpcs = [
{ {
'command': 'createChannel', 'command': 'createChannel',
'onSuccess': this.onCreateChannel_, 'onSuccess': this.onCreateChannel_
}, }
]; ];
// sendRPCs instead of sendRPC so we don't queue. // sendRPCs instead of sendRPC so we don't queue.
this.sendRPCs_(rpcs); this.sendRPCs_(rpcs);
@@ -898,7 +901,7 @@ Cosmopolite.prototype.onCreateChannel_ = function(data) {
onopen: this.onSocketOpen_.bind(this), onopen: this.onSocketOpen_.bind(this),
onclose: this.onSocketClose_.bind(this), onclose: this.onSocketClose_.bind(this),
onmessage: this.onSocketMessage_.bind(this), onmessage: this.onSocketMessage_.bind(this),
onerror: this.onSocketError_.bind(this), onerror: this.onSocketError_.bind(this)
}); });
}; };

View File

@@ -109,7 +109,7 @@ asyncTest('Message round trip', function() {
equal(e['message'], message, 'message matches'); equal(e['message'], message, 'message matches');
cosmo.shutdown(); cosmo.shutdown();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -127,9 +127,9 @@ asyncTest('Complex object', function() {
'zag': [16, 22, 59, 76], 'zag': [16, 22, 59, 76],
'boo': { 'boo': {
'nested': 'object', 'nested': 'object',
10: 100, 10: 100
}, },
'unicode': '☠☣☃𠜎', 'unicode': '☠☣☃𠜎'
}; };
var callbacks = { var callbacks = {
@@ -138,7 +138,7 @@ asyncTest('Complex object', function() {
deepEqual(e['message'], message, 'message matches'); deepEqual(e['message'], message, 'message matches');
cosmo.shutdown(); cosmo.shutdown();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -190,7 +190,7 @@ asyncTest('Duplicate message suppression', function() {
equal(msg['message'], message1, 'message matches'); equal(msg['message'], message1, 'message matches');
cosmo.shutdown(); cosmo.shutdown();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -225,7 +225,7 @@ asyncTest('Message persistence', function() {
equal(msg['message'], message, 'message matches'); equal(msg['message'], message, 'message matches');
cosmo2.shutdown(); cosmo2.shutdown();
start(); start();
}, }
}; };
var cosmo2 = new Cosmopolite(callbacks, null, namespace); var cosmo2 = new Cosmopolite(callbacks, null, namespace);
@@ -344,7 +344,7 @@ asyncTest('Reconnect channel', function() {
equal(msg['message'], message, 'message matches'); equal(msg['message'], message, 'message matches');
cosmo.shutdown(); cosmo.shutdown();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -369,13 +369,13 @@ asyncTest('subscribe ACL', function() {
cosmo.getProfile().then(function(profile) { cosmo.getProfile().then(function(profile) {
cosmo.subscribe({ cosmo.subscribe({
'name': subject, 'name': subject,
'readable_only_by': profile, 'readable_only_by': profile
}).then(function() { }).then(function() {
ok(true, 'correct ACL succeeds'); ok(true, 'correct ACL succeeds');
cosmo.subscribe({ cosmo.subscribe({
'name': subject, 'name': subject,
'readable_only_by': tempProfile, 'readable_only_by': tempProfile
}).then(null, function() { }).then(null, function() {
ok(true, 'bad ACL fails'); ok(true, 'bad ACL fails');
cosmo.shutdown(); cosmo.shutdown();
@@ -403,13 +403,13 @@ asyncTest('sendMessage ACL', function() {
cosmo.getProfile().then(function(profile) { cosmo.getProfile().then(function(profile) {
cosmo.sendMessage({ cosmo.sendMessage({
'name': subject, 'name': subject,
'writable_only_by': profile, 'writable_only_by': profile
}, message).then(function() { }, message).then(function() {
ok(true, 'correct ACL succeeds'); ok(true, 'correct ACL succeeds');
cosmo.sendMessage({ cosmo.sendMessage({
'name': subject, 'name': subject,
'writable_only_by': tempProfile, 'writable_only_by': tempProfile
}, message).then(null, function() { }, message).then(null, function() {
ok(true, 'bad ACL fails'); ok(true, 'bad ACL fails');
cosmo.shutdown(); cosmo.shutdown();
@@ -442,7 +442,7 @@ asyncTest('pin/unpin', function() {
equal(message, e['message'], 'onUnpin: message matches'); equal(message, e['message'], 'onUnpin: message matches');
cosmo.shutdown(); cosmo.shutdown();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -473,7 +473,7 @@ asyncTest('Repin', function() {
'onUnpin': function(e) { 'onUnpin': function(e) {
equal(subject, e['subject']['name'], 'onUnpin: subject matches'); equal(subject, e['subject']['name'], 'onUnpin: subject matches');
equal(message, e['message'], 'onUnpin: message matches'); equal(message, e['message'], 'onUnpin: message matches');
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -507,7 +507,7 @@ asyncTest('Duplicate subject', function() {
cosmo.shutdown(); cosmo.shutdown();
start(); start();
} }
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
@@ -537,7 +537,7 @@ asyncTest('Login', function() {
cosmo.shutdown(); cosmo.shutdown();
logout(); logout();
start(); start();
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
}); });
@@ -575,7 +575,7 @@ asyncTest('Profile merge', function() {
}, },
'onLogin': function(logout_url) { 'onLogin': function(logout_url) {
cosmo.subscribe(subject, -1); cosmo.subscribe(subject, -1);
}, }
}; };
var cosmo = new Cosmopolite(callbacks, null, randstring()); var cosmo = new Cosmopolite(callbacks, null, randstring());
cosmo.sendMessage(subject, message); cosmo.sendMessage(subject, message);
@@ -596,7 +596,7 @@ asyncTest('Two channels, one client', function() {
equal(msg['message'], message, 'message matches'); equal(msg['message'], message, 'message matches');
cosmo1.shutdown(); cosmo1.shutdown();
start(); start();
}, }
}; };
var cosmo1 = new Cosmopolite(callbacks, null, namespace); var cosmo1 = new Cosmopolite(callbacks, null, namespace);

View File

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