Star-crossed

Check member promise chaining psuedo

May 16th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.ajax({
  2.     // Get communities' URL
  3. })
  4.     .then(function (communities) {
  5.         var promises;
  6.         for (var i = 0; i < communities.length; i++) {
  7.             promises.push($.ajax({
  8.                 // Get groups with matching title for matching user on community URL
  9.             }));            
  10.         }
  11.         return $.when.apply(this, promises);
  12.     })
  13.         .then(function (communityMemberships) {
  14.             var communitiesToAdd = communityMemberships.filter(isMember);
  15.             // Code to perform on communities where user is not a member            
  16.         });
  17.        
  18. var isMember = function (membership) {
  19.     return membership == 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment