JSFiddle - React, Tailwind, and code Playground

by kirkchen

HTML

<script src="https://raw.github.com/JeffreyZhao/jscex/master/src/jscex.js"></script>
<script src="https://raw.github.com/JeffreyZhao/jscex/master/src/jscex-parser.js"></script>
<script src="https://raw.github.com/JeffreyZhao/jscex/master/src/jscex-jit.js"></script>
<script src="https://raw.github.com/JeffreyZhao/jscex/master/src/jscex-builderbase.js"></script>
<script src="https://raw.github.com/JeffreyZhao/jscex/master/src/jscex-async.js"></script>
<script src="https://raw.github.com/appendto/jquery-mockjax/master/jquery.mockjax.js"></script>
Result:<span id="result"></span>

JavaScript

$(document).ready(function () {
    var isAjaxMocked = true;
    if (isAjaxMocked) {
        $.mockjax({
            url: '/WebApi/GetUserData.svc',
            status: 200,
            responseTime: 750,
            responseText: { id: 1, name: "Kirk", message: "User Information" }
        });
    }
    
    var Task = Jscex.Async.Task;
    $.ajaxAsync = function (options) {
        return Task.create(function (t) {

            options.success = function (data, textStatus, jqXHR) {
                t.complete("success", {
                    data: data,
                    textStatus: textStatus,
                    jqXHR: jqXHR
                });
            }

            options.error = function (jqXHR, textStatus, errorThrow) {
                t.complete("failure", {
                    jqXHR: jqXHR,
                    textStatus: textStatus,
                    errorThrow: errorThrow
                });
            };

            $.ajax(options);
        });
    };

    var queryAsync = eval(Jscex.compile("async", function () {
        var result = $await($.ajaxAsync({
            url: '/WebApi/GetUserData.svc',
            type: 'GET',
            dataType: "json"
        }));

        $("span#result").text(result.data.message);
    }));

    queryAsync().start();
});