Last active
December 25, 2015 03:09
Revisions
-
togakangaroo renamed this gist
Oct 9, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
togakangaroo revised this gist
Oct 9, 2013 . 1 changed file with 1 addition and 7 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -27,14 +27,8 @@ defr.defaultConversion = (fn, ctx) -> (args...) -> $.Deferred (d) -> fn.apply ctx, (_.union args, [d.resolve, d.reject] ) logResults = (text, continueWith) -> -> w.logResults.last = ctx: @, args: (_.toArray arguments), text: text (w.logResults.stack = w.logResults.stack || []).push w.logResults.last console.log text||"", this, arguments continueWith?.apply @, arguments -
togakangaroo created this gist
Oct 9, 2013 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ w = window w.defr = (fnOrCtx, fnOrUndef) -> ctx = if fnOrUndef then fnOrCtx else window fn = if fnOrUndef then fnOrUndef else fnOrCtx submittedArgs = null getDeferredGenerator = (_.find(defr.conversions, (c)->c.canAdapt fn, ctx)?.adapt || defr.defaultConversion) getDeferred = _.wrap getDeferredGenerator(fn, ctx), (fn, args...) -> submittedArgs = _.toArray args fn.apply @, args _.compose ((d)-> d.fail (logResults "error", -> console.log this, "fn", fn, "ctx", ctx, "args", submittedArgs)), getDeferred defr.conversions = [ { canAdapt: (fn, ctx) -> fn instanceof FileReader adapt: (reader) -> (startRead) -> $.Deferred (d) -> reader.onerror = reader.onabort = d.reject reader.onloadend = (e, args...) -> d.resolve.apply @, (_.union [e.target.result], [e], args) startRead(reader) } { canAdapt: (fn) -> (_.isArray fn) and _.all fn, (x) -> x.done && x.pipe && x.fail && x.then; adapt: (deferreds) -> -> $.when.apply $, deferreds } ] defr.defaultConversion = (fn, ctx) -> (args...) -> $.Deferred (d) -> fn.apply ctx, (_.union args, [d.resolve, d.reject] ) w.logResults = (text, continueWith) -> -> w.logResults.last = ctx: @, args: (_.toArray arguments), text: text (w.logResults.stack = w.logResults.stack || []).push w.logResults.last console.log text||"", this, arguments continueWith?.apply @, arguments w.ok = logResults "ok" w.err = logResults "error" w.storageInfo = w.storageInfo || w.webkitStorageInfo w.requestFileSystem = w.requestFileSystem || w.webkitRequestFileSystem