JSFiddle - React, Tailwind, and code Playground
by CodeRenaissance
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<div id="test">a</div>
JavaScript
window.mo = window.mo || {};
mo.ActionManager = function actionChainManagerConstructor() {
var staticResolvedDeferred = (new jQuery.Deferred()).resolve();
var isBusy = ko.observable(false);
var actionChain = null;
function doAction(fn) {
var contextActionChain;
if (typeof (fn) === "function") {
isBusy(true);
actionChain = jQuery.when(actionChain).then(fn);
contextActionChain = actionChain;
contextActionChain.done(function () {
if (contextActionChain === actionChain) {
actionChain = null;
isBusy(false);
}
}).fail(function () {
if (window.console && window.console.log) {
window.console.log("Wizard Action Error: %0", {
failureArgs: arguments, actionChain: actionChain
});
}
actionChain = null;
isBusy(false);
});
}
return actionChain ? actionChain.promise() : staticResolvedDeferred.promise();
}
function doWait(waitTime) {
var deferred = new jQuery.Deferred();
actionChain = jQuery.when(actionChain).then(function actionManagerWait() {
setTimeout(function actionManagerWaitComplete() {
deferred.resolve();
}, waitTime || 0);
return deferred.promise();
});
return actionChain.promise();
}
function doWaitFor(fnCheckIsDone, iterationWaitTime, maxAttempts) {
var deferred = new jQuery.Deferred();
var attempts = 0;
if (typeof fnCheckIsDone == "function") {
function attemptWaitFor() {
if (fnCheckIsDone()) {
deferred.resolve();
} else {
setTimeout(iterationWaitTime || 0);
attempts ++;
}
}
...