Manager of jQuery deferreds by name
promiser is a simple manager of deferreds by name. Rather than creating and maintaining references to
jQuery.Deferred objects, simply register a handler by name and resolve or reject it by name.
promiser;promiser;promiser; // true
The promiser API includes all the methods on the jQuery Deferred object.
Chaining works as expected:
For a more elegant approach, an object can be passed:
It supports the
Promiser can manage other deferred for you:
It can also stop managing a deferred:
var xhr = promiser;
You can even reset a deferred. This provides a clean alternative to passing around references to deferred objects:
Deferreds can be watched for when they are initially created. This makes it easy to only execute something if another object needs it:
// Watch for the first time the 'lazy-data' deferrred it bound topromiser;// This executes the watch handler abovepromiser;
bower install promiser
npm install promiser
promiser.js works in the browser as well as the Node and AMD environments.
promiser object can be used three ways:
// It can be used directlypromiser;
// Create promiser objectsvar p1 = ;p1 instanceof promiser; // true
// Create a new plain objectvar p1 = ;// Extend an existing objectvar p2 = ;