From 5d39c9abdf9d0dffa28d26e32d6dee3a5750b328 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 28 May 2014 23:25:53 -0700 Subject: [PATCH] Last ugly style guide compliance fixes --- static/cosmopolite.js | 79 ++++++++++++++++++++++--------------------- static/test.js | 34 +++++++++---------- static/verify.sh | 4 +-- 3 files changed, 60 insertions(+), 57 deletions(-) diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 522b728..c8b026d 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -40,25 +40,26 @@ String.prototype.hashCode = function() { /** * @constructor - * @param {?Cosmopolite.typeCallbacks=} callbacks - * @param {?string=} urlPrefix - * @param {?string=} namespace + * @param {?Cosmopolite.typeCallbacks=} opt_callbacks + * @param {?string=} opt_urlPrefix + * @param {?string=} opt_namespace */ -var Cosmopolite = function(callbacks, urlPrefix, namespace) { +var Cosmopolite = function(opt_callbacks, opt_urlPrefix, opt_namespace) { /** * @type {Cosmopolite.typeCallbacks} * @private */ - this.callbacks_ = callbacks || /** @type {Cosmopolite.typeCallbacks} */ ({}); + this.callbacks_ = + opt_callbacks || /** @type {Cosmopolite.typeCallbacks} */ ({}); /** * @type {string} * @private */ - this.urlPrefix_ = urlPrefix || '/cosmopolite'; + this.urlPrefix_ = opt_urlPrefix || '/cosmopolite'; /** * @type {string} * @private */ - this.namespace_ = namespace || 'cosmopolite'; + this.namespace_ = opt_namespace || 'cosmopolite'; /** * @type {Cosmopolite.ChannelState_} @@ -119,7 +120,7 @@ var Cosmopolite = function(callbacks, urlPrefix, namespace) { /** @type {Array.} */ var scriptUrls = [ - '/_ah/channel/jsapi', + '/_ah/channel/jsapi' ]; /** * @type {number} @@ -176,7 +177,7 @@ Cosmopolite.typeMessage; /** * @typedef {{command: string, arguments: Object, - onSuccess: (function(Object)|null|undefined)}} + onSuccess: (function(Object)|null)}} * @private */ Cosmopolite.typeRPC_; @@ -214,7 +215,7 @@ Cosmopolite.ChannelState_ = { // RPC complete, channel opening OPENING: 3, // Channel opened - OPEN: 3, + OPEN: 3 }; @@ -225,7 +226,7 @@ Cosmopolite.ChannelState_ = { */ Cosmopolite.SubscriptionState_ = { 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. * * @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 - * @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} */ -Cosmopolite.prototype.subscribe = function(subject, messages, last_id) { +Cosmopolite.prototype.subscribe = function(subject, opt_messages, opt_last_id) { return new Promise(function(resolve, reject) { /** @type {Cosmopolite.typeSubject} */ var canonicalSubject = this.canonicalSubject_(subject); @@ -267,18 +269,18 @@ Cosmopolite.prototype.subscribe = function(subject, messages, last_id) { this.subscriptions_[subjectString] = { 'messages': [], 'pins': [], - 'state': Cosmopolite.SubscriptionState_.PENDING, + 'state': Cosmopolite.SubscriptionState_.PENDING }; } var args = { - 'subject': canonicalSubject, + 'subject': canonicalSubject }; - if (messages) { - args['messages'] = messages; + if (opt_messages) { + args['messages'] = opt_messages; } - if (last_id != null) { - args['last_id'] = last_id; + if (opt_last_id != null) { + args['last_id'] = opt_last_id; } this.sendRPC_('subscribe', args, function(response) { @@ -317,7 +319,7 @@ Cosmopolite.prototype.unsubscribe = function(subject) { var subjectString = JSON.stringify(canonicalSubject); delete this.subscriptions_[subjectString]; var args = { - 'subject': canonicalSubject, + 'subject': canonicalSubject }; this.sendRPC_('unsubscribe', args, resolve); }.bind(this)); @@ -336,7 +338,7 @@ Cosmopolite.prototype.sendMessage = function(subject, message) { var args = { 'subject': this.canonicalSubject_(subject), 'message': JSON.stringify(message), - 'sender_message_id': this.uuid_(), + 'sender_message_id': this.uuid_() }; // No message left behind. @@ -447,7 +449,7 @@ Cosmopolite.prototype.pin = function(subject, message) { var args = { 'subject': this.canonicalSubject_(subject), '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 args = { 'subject': pin['subject'], - 'sender_message_id': pin['sender_message_id'], + 'sender_message_id': pin['sender_message_id'] }; delete this.pins_[id]; @@ -531,7 +533,7 @@ Cosmopolite.prototype.canonicalSubject_ = function(subject) { } if (typeof(subject) == 'string') { subject = { - 'name': subject, + 'name': subject }; } if (subject['readable_only_by'] === null) { @@ -651,15 +653,15 @@ Cosmopolite.prototype.onMessageSent_ = function( * * @param {string} command Command name to call * @param {Object} args Arguments to pass to server - * @param {?function(Object)=} onSuccess Success callback function + * @param {?function(Object)=} opt_onSuccess Success callback function * @private */ -Cosmopolite.prototype.sendRPC_ = function(command, args, onSuccess) { +Cosmopolite.prototype.sendRPC_ = function(command, args, opt_onSuccess) { /** @type {Cosmopolite.typeRPC_} */ var rpc = { 'command': command, 'arguments': args, - 'onSuccess': onSuccess, + 'onSuccess': opt_onSuccess || null }; if (this.maySendRPC_()) { this.sendRPCs_([rpc]); @@ -678,20 +680,21 @@ Cosmopolite.prototype.sendRPC_ = function(command, args, onSuccess) { * backoff. * * @param {Array.} 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 */ -Cosmopolite.prototype.sendRPCs_ = function(commands, delay) { +Cosmopolite.prototype.sendRPCs_ = function(commands, opt_delay) { if (this.shutdown_ || !commands.length) { return; } var request = { 'instance_id': this.instanceID_, - 'commands': [], + 'commands': [] }; commands.forEach(function(command) { var request_command = { - 'command': command['command'], + 'command': command['command'] }; if ('arguments' in command) { request_command['arguments'] = command['arguments']; @@ -712,7 +715,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) { var retryAfterDelay = (function(newCommands) { var intDelay = xhr.getResponseHeader('Retry-After') || - Math.min(32, Math.max(2, delay || 2)); + Math.min(32, Math.max(2, opt_delay || 2)); console.log( this.loggingPrefix_(), 'RPC failed; will retry in ' + intDelay + ' seconds'); @@ -831,7 +834,7 @@ Cosmopolite.prototype.onReconnect_ = function() { 'command': 'subscribe', 'arguments': { 'subject': canonicalSubject, - 'last_id': last_id, + 'last_id': last_id } }); } @@ -840,7 +843,7 @@ Cosmopolite.prototype.onReconnect_ = function() { var pin = this.pins_[id]; rpcs.push({ 'command': 'pin', - 'arguments': pin, + 'arguments': pin }); } this.sendRPCs_(rpcs); @@ -865,8 +868,8 @@ Cosmopolite.prototype.createChannel_ = function() { var rpcs = [ { 'command': 'createChannel', - 'onSuccess': this.onCreateChannel_, - }, + 'onSuccess': this.onCreateChannel_ + } ]; // sendRPCs instead of sendRPC so we don't queue. this.sendRPCs_(rpcs); @@ -898,7 +901,7 @@ Cosmopolite.prototype.onCreateChannel_ = function(data) { onopen: this.onSocketOpen_.bind(this), onclose: this.onSocketClose_.bind(this), onmessage: this.onSocketMessage_.bind(this), - onerror: this.onSocketError_.bind(this), + onerror: this.onSocketError_.bind(this) }); }; diff --git a/static/test.js b/static/test.js index d4f25c5..d64a746 100644 --- a/static/test.js +++ b/static/test.js @@ -109,7 +109,7 @@ asyncTest('Message round trip', function() { equal(e['message'], message, 'message matches'); cosmo.shutdown(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -127,9 +127,9 @@ asyncTest('Complex object', function() { 'zag': [16, 22, 59, 76], 'boo': { 'nested': 'object', - 10: 100, + 10: 100 }, - 'unicode': '☠☣☃𠜎', + 'unicode': '☠☣☃𠜎' }; var callbacks = { @@ -138,7 +138,7 @@ asyncTest('Complex object', function() { deepEqual(e['message'], message, 'message matches'); cosmo.shutdown(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -190,7 +190,7 @@ asyncTest('Duplicate message suppression', function() { equal(msg['message'], message1, 'message matches'); cosmo.shutdown(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -225,7 +225,7 @@ asyncTest('Message persistence', function() { equal(msg['message'], message, 'message matches'); cosmo2.shutdown(); start(); - }, + } }; var cosmo2 = new Cosmopolite(callbacks, null, namespace); @@ -344,7 +344,7 @@ asyncTest('Reconnect channel', function() { equal(msg['message'], message, 'message matches'); cosmo.shutdown(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -369,13 +369,13 @@ asyncTest('subscribe ACL', function() { cosmo.getProfile().then(function(profile) { cosmo.subscribe({ 'name': subject, - 'readable_only_by': profile, + 'readable_only_by': profile }).then(function() { ok(true, 'correct ACL succeeds'); cosmo.subscribe({ 'name': subject, - 'readable_only_by': tempProfile, + 'readable_only_by': tempProfile }).then(null, function() { ok(true, 'bad ACL fails'); cosmo.shutdown(); @@ -403,13 +403,13 @@ asyncTest('sendMessage ACL', function() { cosmo.getProfile().then(function(profile) { cosmo.sendMessage({ 'name': subject, - 'writable_only_by': profile, + 'writable_only_by': profile }, message).then(function() { ok(true, 'correct ACL succeeds'); cosmo.sendMessage({ 'name': subject, - 'writable_only_by': tempProfile, + 'writable_only_by': tempProfile }, message).then(null, function() { ok(true, 'bad ACL fails'); cosmo.shutdown(); @@ -442,7 +442,7 @@ asyncTest('pin/unpin', function() { equal(message, e['message'], 'onUnpin: message matches'); cosmo.shutdown(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -473,7 +473,7 @@ asyncTest('Repin', function() { 'onUnpin': function(e) { equal(subject, e['subject']['name'], 'onUnpin: subject matches'); equal(message, e['message'], 'onUnpin: message matches'); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -507,7 +507,7 @@ asyncTest('Duplicate subject', function() { cosmo.shutdown(); start(); } - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); @@ -537,7 +537,7 @@ asyncTest('Login', function() { cosmo.shutdown(); logout(); start(); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); }); @@ -575,7 +575,7 @@ asyncTest('Profile merge', function() { }, 'onLogin': function(logout_url) { cosmo.subscribe(subject, -1); - }, + } }; var cosmo = new Cosmopolite(callbacks, null, randstring()); cosmo.sendMessage(subject, message); @@ -596,7 +596,7 @@ asyncTest('Two channels, one client', function() { equal(msg['message'], message, 'message matches'); cosmo1.shutdown(); start(); - }, + } }; var cosmo1 = new Cosmopolite(callbacks, null, namespace); diff --git a/static/verify.sh b/static/verify.sh index 7bf0fba..f003f04 100755 --- a/static/verify.sh +++ b/static/verify.sh @@ -13,5 +13,5 @@ curl \ http://closure-compiler.appspot.com/compile echo -gjslint --strict --disable=0121,0233 cosmopolite.js -gjslint --strict --disable=0121,0233 --nojsdoc test.js +gjslint --strict cosmopolite.js +gjslint --strict --nojsdoc test.js