JSFiddle - React, Tailwind, and code Playground

by Ryan Duffy

HTML

<script src="https://parse.com/downloads/javascript/parse-1.2.7.min.js"></script>
<div id="log"></div>

JavaScript

Parse.initialize("HEQgylGqAigFiwXGvez036LTifhOwKbWC2yWtQtT", "lFxoC1umnxqGtEXFOcL2KbJXvHP7JksTYVFZePjo");

var Event = {
    CreateGame: 0,
    InvitePlayer: 1,
    AckInvitation: 2,
    MarkReady: 3,
    Bid: 4,
    Call: 5
};

function log(s) {
    var d = document.createElement("div");
    d.innerText = s;
    document.getElementById("log").appendChild(d);
}

function login(user) {
    log(user+" logging in");
    return Parse.User.logIn(user, user);
}

function erik() { return login("erik"); }
function ryan() { return login("ryan"); }    
function bock() { return login("bock"); }

function event(type, game, data) {
    var e = new Parse.Object("Event");
    e.set("type", type);
    e.set("game", game);
    e.set("data", data);
    return e.save();
}

var game;
erik().then(
    function() {
        log("Creating game");
        return event(Event.CreateGame);
    }
).then(
    function(newGameEvent) {
        log("inviting ryan");
        game = newGameEvent.get("game");
        return event(Event.InvitePlayer, game, {user:"ryan"});
    }
).then(
    function() {
        log("inviting bock");
        return event(Event.InvitePlayer, game, {user:"bock"});
    }
).then(ryan).then(
    function() {
        log("ryan accepting invitation");
        return event(Event.AckInvitation, game, {accept:true});
    }
).then(bock).then(
    function() {
        log("bock accepting invitation");
        return event(Event.AckInvitation, game, {accept:true});
    }
).then(erik).then(
    function() {
        log("marking ready");
        return event(Event.MarkReady, game, {ready:true});
    }
).then(
    function() {
        log("erik bidding 5 5s");
        return event(Event.Bid, game, {number:5, count:5});
    }
).then(ryan).then(
    function() {
        log("ryan bidding 5 5s");
        return event(Event.Bid, game, {number:5, count:5});
    }
).then(bock).then(
    function() {
        log("bock calling");
        return event(Event.Call, game);
    }
).then(
   ...