JSFiddle - React, Tailwind, and code Playground

by Ryan Duffy

HTML

<script src="https://parse.com/downloads/javascript/parse/latest/min.js"></script>

JavaScript

enyo.kind({
    name:"Parse.RestClient",
    kind:"Component",
    published:{
        applicationId:"",
        key:""
    },
    events:{
        onAdd:"",
        onUpdate:"",
        onGet:"",
        onRemove:"",
        onSearch:"",
        onError:""
    },
    parse:{
        host:"api.parse.com",
        version:"1"
    },
    getUrl:function(id, endpoint, className) {
        var p = ["https://",this.parse.host,this.parse.version,endpoint,className];
        if(id) {
            p.push(id);
        }
        
        return p.join("/");
    },
    call:function(config) {
        config = enyo.mixin(config, {
            endpoint:"classes",
            method:"GET"
        });
        
        var x = new enyo.Ajax({
            method:config.method,
            url:this.getUrl(config.id, config.endpoint, config.className),
            cacheBust:false,
            contentType:"application/json",
            headers:{
                "X-Parse-Application-Id":this.applicationId,
                "X-Parse-REST-API-Key":this.key
            }
        });
        
        x.go(config.data);
        x.error(this, function(sender, response) {
            this.doError({response:response});
        });
        
        if(config.event) {
            x.response(this, function(sender, response) {
                var stop = false;
                var e = {
                    response:response,
                    stop:function() {
                        stop = true;
                    }
                };
                
                this[config.event](e);
                
                if(stop) {
                    x.fail();
                } else {
                    return response;
                }
            });
        }
        
        if(config.callback) {
            x.response(function(sender, response) {
                config.callback(sender, {response:response});
            });
        }
    },
    add:function(className, o, callback) {
  ...