/*! * ============================================================= * Ender: open module JavaScript framework (https://ender.no.de) * Build: ender build futures * ============================================================= */ /*! * Ender-JS: open module JavaScript framework (client-lib) * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat) * https://ender.no.de * License MIT */ !function(a){function g(a,b){return f(a,b)}function f(a,b,c){g._select&&(typeof a=="string"||a.nodeName||a.length&&"item"in a||a==window)?(c=g._select(a,b),c.selector=a):c=isFinite(a.length)?a:[a];return e(c,f)}function e(a,b){for(var c in b)c!="noConflict"&&c!="_VERSION"&&(a[c]=b[c]);return a}function d(a,c){return b[a]=c}function c(a){var c=b[a]||window[a];if(!c)throw new Error("Requested module '"+a+"' has not been defined.");return c}a.global=a;var b={};a.provide=d,a.require=c,e(g,{_VERSION:"0.2.5",ender:function(a,b){e(b?f:g,a)},fn:a.$&&a.$.fn||{}}),e(f,{forEach:function(a,b,c){for(c=0,l=this.length;c0&&(l=setTimeout(function(){o.deliver(new d(i)),l=undefined},i))}var e={},f={},g=0,h=0,i=0,j,k,l,m=!0,n,o=this;a="undefined"==typeof a?null:a,o.isFuture=c,o.setContext=function(b){a=b},o.setTimeout=function(a){i=a,p()},o.errback=function(){arguments.length<2?o.deliver.call(o,arguments[0]||new Error("`errback` called without Error")):o.deliver.apply(o,arguments)},o.callback=function(){var a=Array.prototype.slice.call(arguments);a.unshift(undefined),o.deliver.apply(o,a)},o.callbackCount=function(){return Object.keys(e).length},o.deliveryCount=function(){return h},o.setAsap=function(a){undefined===a&&(a=!0);if(!0!==a&&!1!==a)throw new Error("Future.setAsap(asap) accepts literal true or false, not "+a);m=a},o.hasCallback=function(){return!!r.apply(o,arguments)},o.removeCallback=function(a,b){var c=r(a,b);c&&(delete e[c.id],f[c.id]=undefined,delete f[c.id]);return o},o.deliver=function(){if(j)throw new Error("`Future().fulfill(err, data, ...)` renders future deliveries useless");var a=Array.prototype.slice.call(arguments);k=a,h+=1,Object.keys(e).forEach(function(b){var c=e[b],d=c.callback,g=c.context;f[b]&&(delete e[b],delete f[b]),d.apply(g,a)}),a[0]&&"FutureTimeout"!==a[0].name&&p();return o},o.fulfill=function(){arguments.length?o.deliver.apply(o,arguments):o.deliver(),j=!0},o.whenever=function(c,d){var i=g,j;if("function"!=typeof c)throw new Error("Future().whenever(callback, [context]): callback must be a function.");if(r(c,d))throw new Error("Future().everytimers is a strict set. Cannot add already subscribed `callback, [context]`.");j=e[i]={id:i,callback:c,context:null===d?null:d||a},m&&h>0&&(j.callback.apply(j.context,k),f[i]&&(delete f[i],delete e[i])),g+=1,g>=b&&q();return o},o.when=function(a,b){f[g]=!0,o.whenever(a,b);return o},n=s(o,["when","whenever"]),o.passable=function(){return n}}function d(a){this.name="FutureTimeout",this.message="timeout "+a+"ms"}function c(a){return a instanceof e}"use strict";var b=Math.pow(2,52);f.isFuture=c,a.exports=f})(),provide("future",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;(function(){function c(a,c){function f(){var b="undefined"!=typeof c?c:this,f,g;d.setContext(b);try{g=a.apply(b,arguments)}catch(h){f=h}d.deliver(f,g);return e}var d=b(),e=d.passable();d.setAsap(!1),f.when=e.when,f.whenever=e.whenever;return f}"use strict";var b=require("future");a.exports=c})(),provide("asyncify",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;(function(){function d(a){return new c(a)}function c(a){function g(g,h){if("function"!=typeof g)throw new Error("`Sequence().then(callback [context])` requires that `callback` be a function and that `context` be `null`, an object, or a function");e.push({callback:g,context:null===h?null:h||a,index:e.length}),c&&(c=!1,f.apply(null,d));return b}function f(){var a=Array.prototype.slice.call(arguments),b=e.shift();d=arguments;b?(a.unshift(f),b.callback.apply(b.context,a)):c=!0}var b=this,c=!0,d,e=[];a=a||null,b.next=f,b.then=g}function b(a){return a instanceof c}"use strict",d.isSequence=b,a.exports=d})(),provide("sequence",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;(function(){function e(a,d,e,f,g){function j(d,e){return function(){var g=Array.prototype.slice.call(arguments),h=b(),j=c();g.unshift(h.deliver),d.apply(f,g),j.then(h.when);return i(a[e],j)}}function i(a,b){function g(a,d){return function(){var e=Array.prototype.slice.call(arguments);b.then(function(){var b=Array.prototype.slice.call(arguments),c=[],g=b.shift();b.forEach(function(a){c.push(a)}),e.forEach(function(a){c.push(a)}),e=undefined,d?(a.apply(f,c),g.apply(null,b)):(c.unshift(g),a.apply(f,c))});return c}}var c={};Object.keys(d).forEach(function(a){c[a]=g(d[a])}),Object.keys(e).forEach(function(a){c[a]=g(e[a],!0)});return c}var h={};"undefined"==typeof f&&(f=null),Object.keys(a).forEach(function(b){h[b]=j(a[b],b)});return h}function d(a,b){"undefined"!=typeof b&&("function"==typeof b.when?b.when(a):"function"==typeof b?b(a):a(b))}"use strict";var b=require("future"),c=require("sequence");a.exports=e})(),provide("chainify",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;"undefined"==typeof process&&(process={}),function(){"use strict",process.EventEmitter=process.EventEmitter||function(){};var a=b.EventEmitter=process.EventEmitter,c=Array.isArray,d=10;a.prototype.setMaxListeners=function(a){this._events||(this._events={}),this._events.maxListeners=a},a.prototype.emit=function(a){if(a==="error")if(!this._events||!this._events.error||c(this._events.error)&&!this._events.error.length)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var b=this._events[a];if(!b)return!1;if(typeof b=="function"){switch(arguments.length){case 1:b.call(this);break;case 2:b.call(this,arguments[1]);break;case 3:b.call(this,arguments[1],arguments[2]);break;default:var d=Array.prototype.slice.call(arguments,1);b.apply(this,d)}return!0}if(c(b)){var d=Array.prototype.slice.call(arguments,1),e=b.slice();for(var f=0,g=e.length;f0&&this._events[a].length>e&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}}else this._events[a]=[this._events[a],b];return this},a.prototype.on=a.prototype.addListener,a.prototype.once=function(a,b){function d(){c.removeListener(a,d),b.apply(this,arguments)}var c=this;d.listener=b,c.on(a,d);return this},a.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var d=this._events[a];if(c(d)){var e=-1;for(var f=0,g=d.length;f | subs1, [subs2, ...])` requires that all additions be completed before the first `when()` or `whenever()`");var a=Array.prototype.slice.call(arguments);if(0===a.length)return c.newCallback();a=Array.isArray(a[0])?a[0]:a,a.forEach(function(a){a.whenever||(g=!0);if(!a.when)throw new Error("`Join().add(future)` requires either a promise or future");f.push(a)})}}function c(a){return a instanceof d}"use strict";var b=require("future");e.isJoin=c,a.exports=e})(),provide("join",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;(function(){function f(a){return new e(a)}function e(a){function q(){n=Array.prototype.slice.call(arguments);"break"===n[0]?(n.shift(),f.deliver.apply(f,n)):p()}function p(){var b=Math.max(g-(d()-j),0);isNaN(b)&&(b=g);if(!l){if(i&&h>=i){f.deliver(new c(i));return}n.unshift(q),setTimeout(function(){j=d();try{o.apply(a,n),h+=1}catch(b){throw b}},b)}}var e=this,f=b(),g=0,h=0,i=0,j,k,l,m,n,o;e.setMaxLoop=function(a){i=a;return e},e.setWait=function(a){g=a;return e},e.setTimeout=function(a){if(k)throw new Error("Can't set timeout, the loop has already begun!");k=a;var b=setTimeout(function(){l=!0,f.deliver(new Error("LoopTimeout"))},k);f.when(function(){clearTimeout(b)});return e},e.run=function(a){n=Array.prototype.slice.call(arguments),o=a,n[0]=undefined,q.apply(e,n);return e},e.when=f.when,e.whenever=f.whenever}function d(){return(new Date).valueOf()}function c(a){this.name="MaxCountReached",this.message="Loop looped "+a+" times"}"use strict";var b=require("future");a.exports=f})(),provide("loop",a.exports),$.ender(a.exports)}(),!function(){var a={exports:{}},b=a.exports;(function(){function c(){var a="You have upgraded to Futures 2.x. See http://github.com/coolaj86/futures for details.";console.log(a);throw new Error(a)}"use strict";var b;a.exports={promise:c,subscription:c,synchronize:c,whilst:c,future:require("future"),forEachAsync:require("forEachAsync"),sequence:require("sequence"),join:require("join"),asyncify:require("asyncify"),loop:require("loop"),chainify:require("chainify")}})(),provide("futures",a.exports),$.ender(a.exports)}()