A puredom plugin that lets you chain sequential asynchronous functions.
Normally, puredom's chained selection functions run in parallel (asynchronously). They do not wait for pending operations to finish before moving on to the next chained call.
This is ideal for many cases, but it can become cumbersome when chaining animation callbacks.
To solve this problem, puredom.async adds a few selector functions: sync()
, async()
and then()
.
.sync()
switches the chain into "sync" mode. In this mode,
all chained selection functions you call will run in order.
puredom('.foo') // anything that returns a selection
.sync() // switch the chain to sync mode
.fadeOut('slow') // fade out the selection
.fadeIn('fast') // `-> fade the selection back in
.hide(); // `-> finally, hide the selection
.async()
reverts the chain back to puredom's normal (asynchronous) mode.
// selection in sync mode:
var sel = puredom('.foo').sync();
// these animations run sequentially:
sel.fadeIn().fadeOut();
// back to async: (this runs prior to the animations!)
console.log(sel.async().width());
.then()
lets you specify a function to call once the synchronous
chain's current operations have finished executing:
puredom('.foo').sync().fadeIn().fadeOut().then(function() {
alert("fade in and out have completed");
});
BSD 3-Clause, see LICENSE
.