Created
May 15, 2013 19:37
-
-
Save chaffeqa/5586705 to your computer and use it in GitHub Desktop.
simple module for chaining something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_this( blah ){ | |
var deferred = jQuery.Deferred(); | |
function build(){ | |
var d = jQuery.Deferred(); | |
console.log("build",blah) | |
setTimeout(function(){ d.resolve(); },1000) | |
return d.promise(); | |
} | |
function show(){ | |
var d = jQuery.Deferred(); | |
console.log("show",blah) | |
setTimeout(function(){ d.resolve(); },1000) | |
return d.promise(); | |
} | |
function animate(){ | |
var d = jQuery.Deferred(); | |
console.log("animate",blah) | |
setTimeout(function(){ d.resolve(); },1000) | |
return d.promise(); | |
} | |
function hide(){ | |
var d = jQuery.Deferred(); | |
console.log("hide",blah) | |
setTimeout(function(){ d.resolve(); },1000) | |
return d.promise(); | |
} | |
function destroy(){ | |
var d = jQuery.Deferred(); | |
console.log("destroy",blah) | |
setTimeout(function(){ d.resolve(); },1000) | |
return d.promise(); | |
} | |
build().then(function(){ | |
return animate().then(function(){ | |
return hide().then(function(){ | |
return destroy().then(function(){ | |
console.log("DONE", blah); | |
return deferred.resolve('ha'); | |
}) | |
}) | |
}) | |
}) | |
return deferred.promise(); | |
} | |
var test_this( 'variable' ); | |
test_this.then(function(v){ | |
console.log("finished chain: ", v); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment