Permalink
Browse files

Removed asynchronous pattern from the really synchronous functions:

* Group#count
* Group#getUsers
* Group#hasClient
* User#getGroups
* nowjs#getGroups
  • Loading branch information...
1 parent ee1e703 commit a9dc3ceb9705ec4edf85bdd8118f06da7d264d65 @ayatkevich ayatkevich committed Dec 12, 2011
Showing with 19 additions and 23 deletions.
  1. +10 −12 lib/group.js
  2. +5 −7 lib/now.js
  3. +4 −4 lib/user.js
View
@@ -50,15 +50,14 @@ exports.initialize = function (nowjs) {
* @description Used to find the cardinality of the group (how
* many users it contains).
- * @param {Function} callback Called with a Number corresponding to
- * the group's user count.
+ * @return {Number} A number corresponding to the group's user count.
* @example everyone.count(function (ct) {
* console.log(ct);
* });
*/
- Group.prototype.count = function (callback) {
- callback(Object.keys(this.users).length);
+ Group.prototype.count = function () {
+ return Object.keys(this.users).length;
};
/**
@@ -69,17 +68,17 @@ exports.initialize = function (nowjs) {
* @description Used to retrieve a list of the client IDs
* corresponding to all users in the group.
- * @param {Function} callback Called with an Array of Strings
- * corresponding to the client IDs of all users in the group.
+ * @return {Array} An Array of Strings corresponding to the client IDs of all
+ * users in the group.
* @example everyone.getUsers(function (users) {
* for (var i = 0; i < users.length; i++) console.log(users[i]);
* });
* @see nowjs#getClient
*/
- Group.prototype.getUsers = function (callback) {
- callback(Object.keys(this.users));
+ Group.prototype.getUsers = function () {
+ return Object.keys(this.users);
};
/**
@@ -267,17 +266,16 @@ exports.initialize = function (nowjs) {
* @param {String} clientId The client ID associated with the target
* user.
- * @param {Function} callback Called with a Boolean indicating the
- * user's membership in the group.
+ * @return {Boolean} indicating the user's membership in the group.
* @example group.hasClient('1234567890', function (bool) {
* if (bool) {
* console.log('User is a member of `group`.');
* }
* });
*/
- Group.prototype.hasClient = function (clientId, callback) {
- callback(this.users[clientId] !== undefined);
+ Group.prototype.hasClient = function (clientId) {
+ return this.users[clientId] !== undefined;
};
/**
View
@@ -70,8 +70,7 @@ Now.prototype.getClient = function (id, callback) {
* array) of all groups that have been created and passes it in to the
* supplied callback.
- * @param {Function} callback Takes one argument, an array of all
- * groups that have been created.
+ * @return {Array} an array of all groups that have been created.
* @example nowjs.on('connect', function () {
* var self = this;
@@ -80,8 +79,8 @@ Now.prototype.getClient = function (id, callback) {
* });
* });
*/
-Now.prototype.getGroups = function (callback) {
- callback(Object.keys(this.groups));
+Now.prototype.getGroups = function () {
+ return Object.keys(this.groups);
};
/**
@@ -183,9 +182,8 @@ Now.prototype.initialize = function (server, options) {
};
Now.prototype.addSupportServer = function(host, port){
- var server = new this.Support(host, port);
- return server;
-}
+ return new this.Support(host, port);
+};
exports.Now = Now;
View
@@ -158,8 +158,8 @@ exports.initialize = function (nowjs) {
* @description Used to retrieve a list of the group names
* corresponding to all groups the user is in.
- * @param {Function} callback Called with an Array of Strings
- * corresponding to the various group names.
+ * @return {Array} an Array of Strings corresponding to the various group
+ * names.
* @example everyone.now.broadcast = function (message) {
* var name = this.now.name;
@@ -171,8 +171,8 @@ exports.initialize = function (nowjs) {
* }
* });
*/
- User.prototype.getGroups = function (callback) {
- callback(Object.keys(this.groups));
+ User.prototype.getGroups = function () {
+ return Object.keys(this.groups);
};
/** @private */

0 comments on commit a9dc3ce

Please sign in to comment.