JSFiddle - React, Tailwind, and code Playground

by olvlvl

HTML

<p>With <a href="https://github.com/olvlvl/IDependOnYou">IDependOnYou</a> the alerts pop in the right order.</p>

<p>Tested with Firefox 28, 29; and Chome 34</p>

JavaScript

var IDependOnYou,define,require;!function(){"use strict";var a=[],b=[],c=[],d=function(a,b){this.dependencyList=a,this.callback=b};d.prototype={isReady:function(){for(var a=this.dependencyList,b=0,d=a.length;d>b;b++){var e=a[b];if(!(e in c))return!1}return!0},initialize:function(){for(var d,a=[],b=this.dependencyList,e=0,f=b.length;f>e;e++)d=b[e],a.push(c[d]);return this.callback.apply(null,a)}};var e=function(a,b,c){this.id=a,this.dependencyList=b,this.callback=c};e.prototype=Object.create(d.prototype);var f=function(){};f.prototype={require:function(b,c){var e=new d(b,c);return a.push(e),this.checkPending(),this},define:function(c,d,f){var g=new e(c,d,f);return a.push(g),b[c]=g,this.checkPending(),this},checkPending:function(){for(var b=0;b<a.length;){var d=a[b];if(d.isReady()){var f=d.initialize();d instanceof e&&(c[d.id]=f),a.splice(b,1),b=0}else b++}}},IDependOnYou=new f,"bind"in Function.prototype?(require=IDependOnYou.require.bind(IDependOnYou),define=IDependOnYou.define.bind(IDependOnYou)):(require=function(){return IDependOnYou.require.apply(IDependOnYou,arguments)},define=function(){return IDependOnYou.define.apply(IDependOnYou,arguments)}),define.amd={engine:"IDependOnYou"}}();

define('one', [], function() {

    alert('here0')

    return 'one'
    
})

define('two', [ 'one' ], function(one) {

    alert('here1')

    return 'two'
       
})

require([ 'two' ], function(two) {
    
    alert('here2')
    
})

document.addEventListener('DOMContentLoaded', function() {
    
   alert('here3')
   
})