From 793de0944f0e794e202f56f635367d060475b49d Mon Sep 17 00:00:00 2001 From: Mike Smullin Date: Wed, 26 Nov 2014 20:32:07 -0700 Subject: [PATCH] make work with RequireJS --- coffee/async2.coffee | 6 ++- js/async2.js | 93 +++++++++++++++++++++++-------------------- js/async2.min.js | 9 +---- js/async2.min.js.gz | Bin 1285 -> 1289 bytes 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/coffee/async2.coffee b/coffee/async2.coffee index 78310e1..66172e1 100644 --- a/coffee/async2.coffee +++ b/coffee/async2.coffee @@ -1,8 +1,10 @@ not ((context, definition) -> - if 'function' is typeof require and + if 'function' is typeof define # RequireJS + return define definition + else if 'function' is typeof require and # Node.JS/CommonJS typeof exports is typeof module return module.exports = definition - return context['async'] = definition + return context['async'] = definition # Browser )(this, (-> # constructor # the if statement is for jQuery-like instantiation diff --git a/js/async2.js b/js/async2.js index bdbc5d8..2f1756c 100644 --- a/js/async2.js +++ b/js/async2.js @@ -1,7 +1,8 @@ -// Generated by CoffeeScript 1.4.0 - +// Generated by CoffeeScript 1.7.1 !(function(context, definition) { - if ('function' === typeof require && typeof exports === typeof module) { + if ('function' === typeof define) { + return define(definition); + } else if ('function' === typeof require && typeof exports === typeof module) { return module.exports = definition; } return context['async'] = definition; @@ -31,57 +32,60 @@ } }; A.prototype._next = function(parallel) { - var _this = this; - return function() { - _this.processed++; - if (arguments[0]) { - return _this._apply(arguments); - } - _this.afterEach_callback.apply(_this._next(!_this.afterEach_callback.length), arguments); - if (!parallel || _this.processed === _this.beginning_length) { - while (_this._apply(arguments) && parallel) {} - } - }; + return (function(_this) { + return function() { + _this.processed++; + if (arguments[0]) { + return _this._apply(arguments); + } + _this.afterEach_callback.apply(_this._next(!_this.afterEach_callback.length), arguments); + if (!parallel || _this.processed === _this.beginning_length) { + while (_this._apply(arguments) && parallel) {} + } + }; + })(this); }; A.prototype._push = function(args, parallel) { - var dont_end, key, task, _fn, - _this = this; + var dont_end, key, task, _fn; task = args[0]; '[object Function]' === Object.prototype.toString.call(task) && (dont_end = task = [task]); - _fn = function(cb, parallel) { - _this.beginning_length++; - return _this.a.push(function() { - var next; - _this.a.pop(); - _this.beforeEach_callback.apply(_this._next(!_this.beforeEach_callback.length), arguments); - args = Array.prototype.slice.apply(arguments).slice(1); - cb.apply((next = _this._next(parallel)), args.concat(next)); - return parallel && (1 === _this.a.length || !!_this._apply(arguments)); - }); - }; + _fn = (function(_this) { + return function(cb, parallel) { + _this.beginning_length++; + return _this.a.push(function() { + var next; + _this.a.pop(); + _this.beforeEach_callback.apply(_this._next(!_this.beforeEach_callback.length), arguments); + args = Array.prototype.slice.apply(arguments).slice(1); + cb.apply((next = _this._next(parallel)), args.concat(next)); + return parallel && (1 === _this.a.length || !!_this._apply(arguments)); + }); + }; + })(this); for (key in task) { _fn(task[key], parallel === null ? !task[key].length : parallel); } return (dont_end ? this : this.end(typeof args[1] === 'function' ? args[1] : function() {})); }; A.prototype.end = A.prototype["finally"] = A.prototype.ensure = A.prototype.afterAll = A.prototype.after = A.prototype.complete = A.prototype.done = A.prototype.go = function(cb) { - var _this = this; if (this.processing) { return; } this.processing = true; - this.a.push(function() { - _this.a.pop(); - if (arguments[0]) { - _this.error_callback.apply(_this._next(!_this.error_callback.length), arguments); - } else { - _this.success_callback.apply(_this._next(!_this.success_callback.length), arguments); - } - if (typeof cb === 'function') { - cb.apply(null, arguments); - } - return _this._reset(); - }); + this.a.push((function(_this) { + return function() { + _this.a.pop(); + if (arguments[0]) { + _this.error_callback.apply(_this._next(!_this.error_callback.length), arguments); + } else { + _this.success_callback.apply(_this._next(!_this.success_callback.length), arguments); + } + if (typeof cb === 'function') { + cb.apply(null, arguments); + } + return _this._reset(); + }; + })(this)); this.a.reverse(); (this.begin_callback = this.begin_callback || function() {}) && (this.beforeAll_callback = this.beforeAll_callback || function() {}) && (this.beforeEach_callback = this.beforeEach_callback || function() {}) && (this.afterEach_callback = this.afterEach_callback || function() {}) && (this.error_callback = this.error_callback || function() {}) && (this.success_callback = this.success_callback || function() {}); this.beforeAll_callback.apply(this._next(!this.beforeAll_callback.length), arguments); @@ -120,10 +124,11 @@ return A; }; A.whilst = function(test, iterator, cb) { - var _this = this; - (test() && iterator(function(err) { - return (!!err && cb(err)) || _this.whilst(test, iterator, cb); - })) || cb(); + (test() && iterator((function(_this) { + return function(err) { + return (!!err && cb(err)) || _this.whilst(test, iterator, cb); + }; + })(this))) || cb(); }; A.delay = function(ms, f) { return setTimeout(f, ms); diff --git a/js/async2.min.js b/js/async2.min.js index 256bbc1..0770814 100644 --- a/js/async2.min.js +++ b/js/async2.min.js @@ -1,8 +1 @@ -!function(a,d){return"function"===typeof require&&typeof exports===typeof module?module.exports=d:a.async=d}(this,function(){var a,d,c;a=function(){if("undefined"===typeof this.serial){var g=new a,b;for(b in arguments[0])g[b](arguments[0][b]);return g}this.a=[];this._reset();this.beginning_results=[].slice.call(arguments,0)};a.prototype._reset=function(){this.beginning_results=[];this.beginning_length=0;this.processing=!1;return this.processed=0};a.prototype._apply=function(a){if(this.a.length)return(a[0]? -this.a.splice(0,this.a.length)[0]:this.a[this.a.length-1]).apply({},a)};a.prototype._next=function(a){var b=this;return function(){b.processed++;if(arguments[0])return b._apply(arguments);b.afterEach_callback.apply(b._next(!b.afterEach_callback.length),arguments);if(!a||b.processed===b.beginning_length)for(;b._apply(arguments)&&a;);}};a.prototype._push=function(a,b){var c,d,e,h,f=this;e=a[0];"[object Function]"===Object.prototype.toString.call(e)&&(c=e=[e]);h=function(b,c){f.beginning_length++;return f.a.push(function(){var d; -f.a.pop();f.beforeEach_callback.apply(f._next(!f.beforeEach_callback.length),arguments);a=Array.prototype.slice.apply(arguments).slice(1);b.apply(d=f._next(c),a.concat(d));return c&&(1===f.a.length||!!f._apply(arguments))})};for(d in e)h(e[d],null===b?!e[d].length:b);return c?this:this.end("function"===typeof a[1]?a[1]:function(){})};a.prototype.end=a.prototype["finally"]=a.prototype.ensure=a.prototype.afterAll=a.prototype.after=a.prototype.complete=a.prototype.done=a.prototype.go=function(a){var b= -this;if(!this.processing)return this.processing=!0,this.a.push(function(){b.a.pop();arguments[0]?b.error_callback.apply(b._next(!b.error_callback.length),arguments):b.success_callback.apply(b._next(!b.success_callback.length),arguments);"function"===typeof a&&a.apply(null,arguments);return b._reset()}),this.a.reverse(),(this.begin_callback=this.begin_callback||function(){})&&(this.beforeAll_callback=this.beforeAll_callback||function(){})&&(this.beforeEach_callback=this.beforeEach_callback||function(){})&& -(this.afterEach_callback=this.afterEach_callback||function(){})&&(this.error_callback=this.error_callback||function(){})&&(this.success_callback=this.success_callback||function(){}),this.beforeAll_callback.apply(this._next(!this.beforeAll_callback.length),arguments),this._apply([null].concat(this.beginning_results)),this};a.prototype.serial=a.prototype.series=a.prototype.blocking=a.prototype.waterfall=function(){return this._push(arguments,!1)};a.prototype.parallel=a.prototype.nonblocking=function(){return this._push(arguments, -!0)};a.prototype["do"]=a.prototype.then=a.prototype["try"]=a.prototype.begin=a.prototype.start=a.prototype.auto=function(){return this._push(arguments,null)};a.prototype["new"]=a.prototype.flow=a.prototype["with"]=function(){this.beginning_results=[].slice.call(arguments,0);return this};(d=function(a){return function(b){this[a+"_callback"]=b;return this}})&&(a.prototype.beforeAll=a.prototype.before=d("beforeAll"))&&(a.prototype.beforeEach=d("beforeEach"))&&(a.prototype.afterEach=a.prototype.between= -a.prototype.inbetween=d("afterEach"))&&(a.prototype.error=a.prototype["catch"]=a.prototype.rescue=d("error"))&&(a.prototype.success=a.prototype["else"]=d("success"));(c=function(c){return function(){var b;return(b=new a)[c].apply(b,arguments)}})&&(a.serial=a.series=a.blocking=a.waterfall=c("serial"))&&(a.parallel=a.nonblocking=c("parallel"))&&(a["do"]=a.then=a["try"]=a.begin=a.start=a.auto=c("do"))&&(a.end=a["finally"]=a.ensure=a.afterAll=a.after=a.complete=a.done=a.go=c("end"))&&(a["new"]=a.flow= -a["with"]=c("new"))&&(a.beforeAll=a.before=c("beforeAll"))&&(a.beforeEach=c("beforeEach"))&&(a.afterEach=a.between=a.inbetween=c("afterEach"))&&(a.error=a["catch"]=a.rescue=c("error"))&&(a.success=a["else"]=c("success"));a.q={};a.nextTickGroup=a.push=function(c,b){a.q[c]=a.q[c]||new a;a.q[c].serial(b).go();return a};a.whilst=function(a,b,c){var d=this;a()&&b(function(e){return!!e&&c(e)||d.whilst(a,b,c)})||c()};a.delay=function(a,b){return setTimeout(b,a)};return a}()); +!function(e,t){if("function"===typeof define){return define(t)}else if("function"===typeof require&&typeof exports===typeof module){return module.exports=t}return e["async"]=t}(this,function(){var e,t,n;e=function(){if(typeof this.serial==="undefined"){var n=new e,r;for(r in arguments[0]){n[r](arguments[0][r])}return n}this.a=[];this._reset();this.beginning_results=[].slice.call(arguments,0)};e.prototype._reset=function(){this.beginning_results=[];this.beginning_length=0;this.processing=false;return this.processed=0};e.prototype._apply=function(e){if(this.a.length){return(e[0]?this.a.splice(0,this.a.length)[0]:this.a[this.a.length-1]).apply({},e)}};e.prototype._next=function(e){return function(t){return function(){t.processed++;if(arguments[0]){return t._apply(arguments)}t.afterEach_callback.apply(t._next(!t.afterEach_callback.length),arguments);if(!e||t.processed===t.beginning_length){while(t._apply(arguments)&&e){}}}}(this)};e.prototype._push=function(e,t){var n,r,i,s;i=e[0];"[object Function]"===Object.prototype.toString.call(i)&&(n=i=[i]);s=function(t){return function(n,r){t.beginning_length++;return t.a.push(function(){var i;t.a.pop();t.beforeEach_callback.apply(t._next(!t.beforeEach_callback.length),arguments);e=Array.prototype.slice.apply(arguments).slice(1);n.apply(i=t._next(r),e.concat(i));return r&&(1===t.a.length||!!t._apply(arguments))})}}(this);for(r in i){s(i[r],t===null?!i[r].length:t)}return n?this:this.end(typeof e[1]==="function"?e[1]:function(){})};e.prototype.end=e.prototype["finally"]=e.prototype.ensure=e.prototype.afterAll=e.prototype.after=e.prototype.complete=e.prototype.done=e.prototype.go=function(e){if(this.processing){return}this.processing=true;this.a.push(function(t){return function(){t.a.pop();if(arguments[0]){t.error_callback.apply(t._next(!t.error_callback.length),arguments)}else{t.success_callback.apply(t._next(!t.success_callback.length),arguments)}if(typeof e==="function"){e.apply(null,arguments)}return t._reset()}}(this));this.a.reverse();(this.begin_callback=this.begin_callback||function(){})&&(this.beforeAll_callback=this.beforeAll_callback||function(){})&&(this.beforeEach_callback=this.beforeEach_callback||function(){})&&(this.afterEach_callback=this.afterEach_callback||function(){})&&(this.error_callback=this.error_callback||function(){})&&(this.success_callback=this.success_callback||function(){});this.beforeAll_callback.apply(this._next(!this.beforeAll_callback.length),arguments);this._apply([null].concat(this.beginning_results));return this};e.prototype.serial=e.prototype.series=e.prototype.blocking=e.prototype.waterfall=function(){return this._push(arguments,false)};e.prototype.parallel=e.prototype.nonblocking=function(){return this._push(arguments,true)};e.prototype["do"]=e.prototype.then=e.prototype["try"]=e.prototype.begin=e.prototype.start=e.prototype.auto=function(){return this._push(arguments,null)};e.prototype["new"]=e.prototype.flow=e.prototype["with"]=function(){this.beginning_results=[].slice.call(arguments,0);return this};(t=function(e){return function(t){this[e+"_callback"]=t;return this}})&&(e.prototype.beforeAll=e.prototype.before=t("beforeAll"))&&(e.prototype.beforeEach=t("beforeEach"))&&(e.prototype.afterEach=e.prototype.between=e.prototype.inbetween=t("afterEach"))&&(e.prototype.error=e.prototype["catch"]=e.prototype.rescue=t("error"))&&(e.prototype.success=e.prototype["else"]=t("success"));(n=function(t){return function(){var n;return(n=new e)[t].apply(n,arguments)}})&&(e.serial=e.series=e.blocking=e.waterfall=n("serial"))&&(e.parallel=e.nonblocking=n("parallel"))&&(e["do"]=e.then=e["try"]=e.begin=e.start=e.auto=n("do"))&&(e.end=e["finally"]=e.ensure=e.afterAll=e.after=e.complete=e.done=e.go=n("end"))&&(e["new"]=e.flow=e["with"]=n("new"))&&(e.beforeAll=e.before=n("beforeAll"))&&(e.beforeEach=n("beforeEach"))&&(e.afterEach=e.between=e.inbetween=n("afterEach"))&&(e.error=e["catch"]=e.rescue=n("error"))&&(e.success=e["else"]=n("success"));e.q={};e.nextTickGroup=e.push=function(t,n){e.q[t]=e.q[t]||new e;e.q[t].serial(n).go();return e};e.whilst=function(e,t,n){e()&&t(function(r){return function(i){return!!i&&n(i)||r.whilst(e,t,n)}}(this))||n()};e.delay=function(e,t){return setTimeout(t,e)};return e}()) diff --git a/js/async2.min.js.gz b/js/async2.min.js.gz index 0c7ba445e00a6ba264d0377a4f1dacadc6b01799..414359d29086cf3808f816af6cbd84895b7db0ab 100644 GIT binary patch literal 1289 zcmV+k1@`(MiwFq$ns!tG17UM{ZeuboZE0>UYI6XMSHW)MI1Ih-S0p|J66!VD>li{Y zhuuByVdrK91J_{^Ow3k#ANm1l`6usVeqEfsO1X4w>d`}W5 zNf=}5a)M^R+QFU+pjQd1lfo{EqIalUSS=Vyc<;D`&Bm_b*Qt@J9Tnc1U007@`(@_T z)ZNOVNXqsis$`2YqK>>xhoI^8XDL@0dMa{Yo)}}Yr)Yz$1y&^ySE78mgkkmtIl?8-G4+X=aWh z*Lw=|9z`MGmkNTg!4D!e6=9~vdp$hl7@D~U+UbFnRuKw-=KqnhU$fnLAC=6gk?6 zs#KT`>MkQOF;AwB4#KzFdOcG+dZ(^#V`Jg;+7gcaBUR`_banl_)=TT^iyHfiAym&9 z5Ifh)pm^HqCN^~2XD#{SW%eGy1dW-uE)wj0n7Ru#(@?GLBm^RZ@~?G06$X;3c{|mh zLfc&B8*h+gWZdez+Xh367;juS-f&m{gVVICxJqA}A()QwK1 zL=O-~AQ~~8_(|WoDTJl|D1>EzOT%)yZ$?CaqV%Lo$F*&)0zyLx(V17O-q8Wr`%jenRI>HD^af zy_#wci}Pjr6IGQB^R-RcG#D45of8{X3_&fuW6$*gX<;a4 zVCaEQ%z@8`+z7N0USbAb7F0fzEPzA=paC`mSVRC8$llpi_YD0seB;&YKeFjg8fC$R zkDs`DFnC9lu>R+EGq}n7l?4b96thW&b^zM5{={fi@U>vP5sXlc6P27ol{?XT%{Lpp zzTKqtXWa}l2*yK9^V>mPUZQUk>lmk&Z~P6K4xcam!8e9UDE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