JSFiddle - React, Tailwind, and code Playground

by Bhavin Surela

HTML

<div id="result">
</div>

JavaScript

/*
Just a rough idea about how we can format our javascript going forward with the rest api and dust templates, we can use backbone.js and other client side library, however that comes with many things than we may not require at this moment. This i believe will separate, rendering logic with api calling and will also force to keep the restful url and return codes "restfull".

we can obviously make it better, but i just rough it in so we get an idea.
*/

// basemodel.js file.
var ModelPrototype = function(){
  
    this.initialize=function(){
        $("#result").append("<p> calling initialize for "+this.name+"</p>");
    }
    this.setBaseUrl=function(){
        $("#result").append("<p>setting Base Url "+this.name+"</p>");
    }
    this.url=""
    
    // set this object after model intialize from server.
    // url can be passed if we want to override the base url
    this.save=function(data,success,error,url){
        // do a put request, format url based on base url
    }
    
    this.insert=function(data,success,error,url){
        // do a post request,format url based on base url
    }
    
    this.delete=function(success,error,url){
        // do delete request,format url based on base url
    }
    
    this.get=function(success,error,url){
        // do a get call
         $("#result").append("<p>Doing get call "+this.name+"</p>");
        var randomValue = Math.random() < 0.5 ? true : false;
        if(randomValue === true){
            success();
        } else {
            error();
        }
        
    }
    
    // may be holds last returned json object form the ajax call    
    this.returnedObject=null;
};

// this can be extended as required
var Model = function(name){
    this.name=name;
};
Model.prototype = new ModelPrototype();


var ioModel = new Model("IOModel");
var otherModel = new Model("Other");

ioModel.setBaseUrl();
ioModel.initialize();

otherModel.setBaseUrl();
otherModel.initialize();

var ViewPrototype = function(){
    // idea...