puredom-sync

1.2.1 • Public • Published

puredom-sync VersionBuild Status

A puredom plugin that lets you chain sequential asynchronous functions.


What it Does

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(): Run everything in the order I say

.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(): Run everything at once

.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(): Let me know when sync() is done

.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");
});

License

BSD 3-Clause, see LICENSE.

Package Sidebar

Install

npm i puredom-sync

Weekly Downloads

1

Version

1.2.1

License

none

Last publish

Collaborators

  • developit