Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created June 22, 2012 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save togakangaroo/2975072 to your computer and use it in GitHub Desktop.
Save togakangaroo/2975072 to your computer and use it in GitHub Desktop.
I guess its my turn to write a flow control library
###
My tiny little flow control library.
Usage:
$.Deferred.invoke func, context, ...args
func - Function with its two final parameters being onSuccess and onError
context - context to bind to 'this' when func is invoked
args - flat list of arguments
Returns:
jQuery Deferred object
gettingFs = $.Deferred.invoke(window.requestFileSystem, window, TEMPORARY, 0);
gettingFs.done(function(fileSystem) {console.log("ok", fileSystem) });
gettingFs.error(function(err){console.log("error", err)});
###
slice = Array.prototype.slice
$.extend $.Deferred,
invoke: (func,ctx) ->
args = slice.call arguments, 2
$.Deferred (d) ->
args.push -> d.resolve.apply d, arguments
args.push -> d.reject.apply d, arguments
func.apply ctx, args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment