JSFiddle - React, Tailwind, and code Playground
by lukemartin
HTML
<div class="moduleOne" id="m1_1">Module 1_1</div>
<div class="moduleTwo" id="m2_1">Module 2_1</div>
JavaScript
/*
Copyright (c) 2010,2011,2012 Morgan Roderick http://roderick.dk
License: MIT - http://mrgnrdrck.mit-license.org
https://github.com/mroderick/PubSubJS
*/
/*jslint white:true, plusplus:true, stupid:true*/
/*global
setTimeout,
module,
exports,
define,
require,
window
*/
(function(root, factory){
'use strict';
// CommonJS
if (typeof exports === 'object'){
module.exports = factory();
// AMD
} else if (typeof define === 'function' && define.amd){
define(factory);
// Browser
} else {
root.PubSub = factory();
}
}( ( typeof window === 'object' && window ) || this, function(){
'use strict';
var PubSub = {
name: 'PubSubJS',
version: '1.3.9'
},
messages = {},
lastUid = -1;
/**
* Returns a function that throws the passed exception, for use as argument for setTimeout
* @param { Object } ex An Error object
*/
function throwException( ex ){
return function reThrowException(){
throw ex;
};
}
function callSubscriberWithDelayedExceptions( subscriber, message, data ){
try {
subscriber( message, data );
} catch( ex ){
setTimeout( throwException( ex ), 0);
}
}
function callSubscriberWithImmediateExceptions( subscriber, message, data ){
subscriber( message, data );
}
function deliverMessage( originalMessage, matchedMessage, data, immediateExceptions ){
var subscribers = messages[matchedMessage],
callSubscriber = immediateExceptions ? callSubscriberWithImmediateExceptions : callSubscriberWithDelayedExceptions,
i, j;
if ( !messages.hasOwnProperty( matchedMessage ) ) {
return;
}
// do not cache the length of the subscribers array, as it might change if there are unsubscribtions
// by subscribers during delivery of a topic
// see https://github.com/mroderick/PubSubJS/issues/26
for ( i = 0; i < subscribers.length; i++ ){
callSubscriber( subscribers[i].func, originalMessage, data );
}
}
function createDeliveryFunction( message, data, immediateExceptions ){
return function...