Permalink
Browse files

Made callback optional for follow/unfollow

  • Loading branch information...
1 parent 9d977bc commit 51e8ff4980bca48834d7a12cfe6437b22eb499d4 @chriso committed May 16, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/advanced_structures/SocialGraph.js
View
16 lib/advanced_structures/SocialGraph.js
@@ -48,7 +48,7 @@ SocialGraph.prototype.init = function (prefix) {
* Follow one or more users.
*
* @param {int|SocialGraph|Array} user(s)
- * @param {Function} callback
+ * @param {Function} callback (optional)
* @return this
* @api public
*/
@@ -57,7 +57,11 @@ SocialGraph.prototype.follow = function (users, callback) {
var self = this,
users = this.getKeys(arguments, 'id'),
multi = this.client.multi();
- callback = users.pop();
+ if (typeof users[users.length-1] === 'function') {
+ callback = users.pop();
+ } else {
+ callback = function () {};
+ }
users.forEach(function (user) {
multi.sadd(self.key_prefix + user + ':followers', self.id);
multi.sadd(self.following, user);
@@ -70,7 +74,7 @@ SocialGraph.prototype.follow = function (users, callback) {
* Unfollow one or more users.
*
* @param {int|SocialGraph|Array} user(s)
- * @param {Function} callback
+ * @param {Function} callback (optional)
* @return this
* @api public
*/
@@ -79,7 +83,11 @@ SocialGraph.prototype.unfollow = function (users, callback) {
var self = this,
users = this.getKeys(arguments, 'id'),
multi = this.client.multi();
- callback = users.pop();
+ if (typeof users[users.length-1] === 'function') {
+ callback = users.pop();
+ } else {
+ callback = function () {};
+ }
users.forEach(function (user) {
multi.srem(self.key_prefix + user + ':followers', self.id);
multi.srem(self.following, user);

0 comments on commit 51e8ff4

Please sign in to comment.