JSFiddle - React, Tailwind, and code Playground

by Derek Anderson

JavaScript

(function(enyo, scope){
    
    /**
    * _enyo.Once_ returns a function that will only be executed one time no matter
    * how many times it was called.
    *
    * borrowed from underscore
    * 
    * @class  enyo.Once
    * @public
    */
    
    //shortcuts
    var ArrayProto = Array.prototype;
    var slice = ArrayProto.slice;
    
    /**
    * returns a function that will be executed before N times.
    *
    * @method
    * @type {Function}
    * @private
    */
    var before = function(times, func) {
        var memo;
        return function() {
          if (--times > 0) {
            memo = func.apply(this, arguments);
          }
          else func = null;
          return memo;
        };
    };
    
    /**
    * returns a partially applied function, without changing it's 'this' context
    *
    * @method
    * @type {Function}
    * @private
    */
    var partial = function(func) {
        var boundArgs = slice.call(arguments, 1);
        return function() {
          var position = 0;
          var args = boundArgs.slice();
          for (var i = 0, length = args.length; i < length; i++) {
            if (args[i] === enyo) args[i] = arguments[position++];
          }
          while (position < arguments.length) args.push(arguments[position++]);
          return func.apply(this, args);
        };
     };
    
    /**
    * Returns a function that will only be executed once reguardless of how many times it is called.
    *
    * @method
    * @type {Function}
    * @public
    */
    enyo.Once = enyo.Once || partial(before, 2);
 
}(enyo, this));

(function(enyo, scope){
    
    //load share this on the page
    var loadShareThis = enyo.Once(function(callback) {
        enyo.load('//w.sharethis.com/button/buttons.js', 
            callback  
        );
    });

    var checkShareThis = function(callback) {
        //poll to see if sharethis was loaded on the page
        loadShareThis(callback);
        var pollShareThisId =...