Skip to content

Instantly share code, notes, and snippets.

@aschearer
Created May 24, 2013
Embed
What would you like to do?
// Updates the player object in Azure Mobile Services and then the player's games
function update(item, user, request) {
var gamesTable = tables.getTable('GameData');
request.execute({
success: function(result) {
// Asychronously update games the player is part of
gamesTable.where(function(player)
{
return this.OwnerId == player.PlayerId ||
this.OpponentId == player.PlayerId
}, item)
.read({
success: function(games) {
games.forEach(function(game) {
if (game.OwnerId == item.PlayerId) {
game.OwnerName = item.Name;
game.OwnerAvatar = item.AvatarType;
} else {
game.OpponentName = item.Name;
game.OpponentAvatar = item.AvatarType;
}
gamesTable.update(game);
});
}
});
// Respond to the player immediately so the UI isn't blocked
request.respond();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment