JSFiddle - React, Tailwind, and code Playground
by stevegreatrex
HTML
<script src="https://raw.github.com/stevegreatrex/JsUtils/master/JsUtils/pubsub.js"></script>
<ul id="out"></ul>
JavaScript
$(function() {
var addListItem = function(text) {
$("<li>").text(text).appendTo("#out");
};
$.subscribe("counterchanged", function() {
addListItem("sync handler");
});
$.subscribe("counterchanged", {
async: true,
callback: function() {
addListItem("async handler");
}
});
for (var i=0; i < 5; i++) {
addListItem(i+1);
if (i === 3) {
$.publish("counterchanged");
}
}
});