JSFiddle - React, Tailwind, and code Playground

by pomeh

HTML

the intersting part happens in your console

JavaScript

// test case for https://gist.github.com/1321768
// see also http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/




// ###############################
// jQuery.Callbacks implementation
// original code by Addy Osmani
// see https://gist.github.com/1321768
var jCallbacks = (function() {
    var topics = {};

    function jCallbacks(id) {
        var callbacks, method, topic = id && topics[id];

        if (!topic) {
            callbacks = jQuery.Callbacks();
            topic = {
                publish: callbacks.fire,
                subscribe: callbacks.add,
                unsubscribe: callbacks.remove
            };

            if (id) {
                topics[id] = topic;
            }
        }

        return topic;
    };

    return jCallbacks;
}());




// ###############################
// jQuery 1.7 events implementation
// original code by Addy Osmani
// see https://gist.github.com/1321768
var jEvents = (function($) {

    var o = $({});

    function getArgs(id, args) {
        args = Array.prototype.slice.apply(args);
        args.unshift(id);
        return args;
    }

    function jEvents(id) {
        return {
            subscribe: function() {
                o.on.apply(o, getArgs(id, arguments));
            },
            unsubscribe: function() {
                o.off.apply(o, getArgs(id, arguments));
            },
            publish: function() {
                o.trigger.apply(o, getArgs(id, arguments));
            }
        };
    };

    return jEvents;

}(jQuery));



// ##########################
// CustomEvent implementation
// original code by Dean Edwards
// see http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/
var CustomEvent = (function() {
    var topics = {},
        uid = 0,
        dispatchFakeEvent, currentHandler, currentTopic, currentData;


    if (document.addEventListener) {

        document.addEventListener("fakeEvents", function() {
            // execute the callback
           ...