Skip to content

Deferred JS Library - Alternative to JQuery Deferred

Notifications You must be signed in to change notification settings

Dunstonhary/Deferred

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

#Deferred.JS

Intro

  • Deferred.JS makes it easy to handle asynchronous process (like AJAX, etc).
  • Deferred.JS is a alternative to JQuery Deferred objects. (Acts same as JQuery Deferred).
  • Read Motivation to know why you should move from JQuery Deferred to Deferred.JS.
  • To migrate from JQuery Deferred to Deferred.JS refer Migration.

Installation

Just include Deferred.js file in your page.

Eg:

<script src="/js/Deferred.js"></script>

And start using it.

Code Example

// Simple asynchronous function written using Deferred object
function after1Second() {
	var deferred = new dfrd.Deferred();
	setTimeout( function() { deferred.resolve( 'after 1 second' ); }, 1000 );
	return deferred;
}

// Now easily handle asynchronous process
after1Second().done( function( message ) { console.log( 'This is printed ' + message ); } );
console.log( 'Called after1Second() method' );

In the same way you can handle all asynchronous process. The most frequently used asynchronous process is AJAX.

Doc

Methods are same as JQuery Deferred. So you can refer JQuery Deferred Official Doc.

  • dfrd.version --> Returns version of deferred object.
  • dfrd.when( deferred1, deferred2, .... ); --> Returns a deferred object which will be resolved on all the given deferreds are resolved.
  • dfrd.addScopeTo( <scopeKey> ); --> Adds Deferred methods to the given scope key.

Migration

To migrate from JQuery Deferred object to this, just replace "$.Deferred" with "dfrd.Deferred".

Eg:

var deferred = new $.Deferred(); --> var deferred = new dfrd.Deferred();

Or

Just add dfrd.addScopeTo( '$' );.

Motivation

  • Plain Javascript codes are much faster than any Javascript library (Eg. JQuery, Dojo, Underscore, Prototype JS, Ext JS, YUI, Moo Tools). Refer Vanilla-JS for bechmark test on various JS library.

  • But people find tough to handle asynchronous process without JQuery Deferred objects, so they will be forced to include entire JQuery library into their page (since JQuery Deferred is completely dependent on JQuery helper methods).

  • So we made a indepenent, efficient and light weight library dedicated only for handling asynchronous process.

Contributors

  • Sundarasan Natarajan

About

Deferred JS Library - Alternative to JQuery Deferred

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.5%
  • HTML 1.5%