JSFiddle - React, Tailwind, and code Playground

by nathan

JavaScript

var datasources = (function () {
    return {
        define : function () {
        }
    };
}());

var localDb = datasources.define(),
    serverDb = datasources.define();

var orm = (function () {
    "use strict";
    var orm, // the core function which is returned for public use
        Type, // the constructor for a new type (ie, table in object form)
        types = []; // list of created types by name

    // Function which is returned. This is just a getter, but is extended with methods
    orm = function (name) {
        return types[name];
    };
    // The constructor for the types (table representations)
    Type = function (def, methods) {
        var constructor, // the object constructor
            i,
            j,
            thisType = this, // so that we can reference the generic object within the record objects
            validAlways = function () { return true; }; // default validation function

        // Create the constructor for the objects now, so that we can extend its prototype
        constructor = function (vals) {
            var i;
            for (i in thisType.schema) {
                if (thisType.schema.hasOwnProperty(i)) {
                    if (vals[i] !== undefined) {
                        this[i] = vals[i];
                    } else {
                        this[i] = thisType.schema[i].defaultValue;
                    }
                }
            }
        };
        constructor.prototype.generic = thisType;
        for (i in def) {
            if (def.hasOwnProperty(i)) {
                if (typeof def[i] === 'string') {
                    // if the field name has a string as it's value, make this the type
                    def[i] = {
                        type : def[i]
                    };
                } else if (typeof def[i] === 'boolean') {
                    // if the field name has a boolean, make this the required value
                    def[i] = {
                        required : def[i]
 ...