diff --git a/dist/really.0.0.1.min.js b/dist/really.0.0.1.min.js index cfc45f0..8163508 100644 --- a/dist/really.0.0.1.min.js +++ b/dist/really.0.0.1.min.js @@ -2,9 +2,9 @@ * Really.js v0.0.1 * Copyright (C) 2014-2015 Really Inc. * - * Date: Tue Jan 06 2015 17:38:48 + * Date: Sun Jan 18 2015 17:08:07 */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.Really=t()}}(function(){var t;return function n(t,e,r){function o(u,a){if(!e[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var f=e[u]={exports:{}};t[u][0].call(f.exports,function(n){var e=t[u][1][n];return o(e?e:n)},f,f.exports,n,t,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u0)){var e=r.shift();e()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}):function(t){setTimeout(t,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},{}],2:[function(t,n){function e(t){return t?r(t):void 0}function r(t){for(var n in e.prototype)t[n]=e.prototype[n];return t}n.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,n){return this._callbacks=this._callbacks||{},(this._callbacks[t]=this._callbacks[t]||[]).push(n),this},e.prototype.once=function(t,n){function e(){r.off(t,e),n.apply(this,arguments)}var r=this;return this._callbacks=this._callbacks||{},e.fn=n,this.on(t,e),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,n){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var e=this._callbacks[t];if(!e)return this;if(1==arguments.length)return delete this._callbacks[t],this;for(var r,o=0;or;++r)e[r].apply(this,n)}return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks[t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}},{}],3:[function(n,e,r){(function(n){(function(){function o(t,n,e){for(var r=(e||0)-1,o=t?t.length:0;++r-1?0:-1:t?0:-1}function u(t){var n=this.cache,e=typeof t;if("boolean"==e||null==t)n[t]=!0;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?t:k+t,o=n[e]||(n[e]={});"object"==e?(o[r]||(o[r]=[])).push(t):o[r]=!0}}function a(t){return t.charCodeAt(0)}function c(t,n){for(var e=t.criteria,r=n.criteria,o=-1,i=e.length;++oa||"undefined"==typeof u)return 1;if(a>u||"undefined"==typeof a)return-1}}return t.index-n.index}function s(t){var n=-1,e=t.length,r=t[0],o=t[e/2|0],i=t[e-1];if(r&&"object"==typeof r&&o&&"object"==typeof o&&i&&"object"==typeof i)return!1;var a=p();a["false"]=a["null"]=a["true"]=a.undefined=!1;var c=p();for(c.array=t,c.cache=a,c.push=u;++no?0:o);++r=_&&r===o,c=[];if(a){var f=s(n);f?(r=i,n=f):a=!1}for(;++e-1:void 0});return o.pop(),i.pop(),g&&(h(o),h(i)),u}function nn(t,n,e,r,o){(Xr(n)?Jn:co)(n,function(n,i){var u,a,c=n,s=t[i];if(n&&((a=Xr(n))||so(n))){for(var f=r.length;f--;)if(u=r[f]==n){s=o[f];break}if(!u){var l;e&&(c=e(s,n),(l="undefined"!=typeof c)&&(s=c)),l||(s=a?Xr(s)?s:[]:so(s)?s:{}),r.push(n),o.push(s),l||nn(s,n,e,r,o)}}else e&&(c=e(s,n),"undefined"==typeof c&&(c=n)),"undefined"!=typeof c&&(s=c);t[i]=s})}function en(t,n){return t+Nr(Qr()*(n-t+1))}function on(t,n,e){var r=-1,u=sn(),a=t?t.length:0,c=[],f=!n&&a>=_&&u===o,p=e||f?l():c;if(f){var v=s(p);u=i,p=v}for(;++r3&&"function"==typeof n[e-2])var r=b(n[--e-1],n[e--],2);else e>2&&"function"==typeof n[e-1]&&(r=n[--e]);for(var o=v(arguments,1,e),i=-1,u=l(),a=l();++ie?Wr(0,i+e):e)||0,Xr(t)?u=o(t,n,e)>-1:"number"==typeof i?u=(zn(t)?t.indexOf(n,e):o(t,n,e))>-1:co(t,function(t){return++r>=e?!(u=t===n):void 0}),u}function Vn(t,e,r){var o=!0;e=n.createCallback(e,r,3);var i=-1,u=t?t.length:0;if("number"==typeof u)for(;++ii&&(i=s)}else e=null==e&&zn(t)?a:n.createCallback(e,r,3),Jn(t,function(t,n,r){var u=e(t,n,r);u>o&&(o=u,i=t)});return i}function ee(t,e,r){var o=1/0,i=o;if("function"!=typeof e&&r&&r[e]===t&&(e=null),null==e&&Xr(t))for(var u=-1,c=t.length;++us&&(i=s)}else e=null==e&&zn(t)?a:n.createCallback(e,r,3),Jn(t,function(t,n,r){var u=e(t,n,r);o>u&&(o=u,i=t)});return i}function re(t,e,r,o){if(!t)return r;var i=arguments.length<3;e=n.createCallback(e,o,4);var u=-1,a=t.length;if("number"==typeof a)for(i&&(r=t[++u]);++ue?Wr(0,r+e):e||0}else if(e){var i=Ce(t,n);return t[i]===n?i:-1}return o(t,n,e)}function be(t,e,r){var o=0,i=t?t.length:0;if("number"!=typeof e&&null!=e){var u=i;for(e=n.createCallback(e,r,3);u--&&e(t[u],u,t);)o++}else o=null==e||r?1:e||o;return v(t,0,Hr(Wr(0,i-o),i))}function we(){for(var t=[],n=-1,e=arguments.length,r=l(),u=sn(),a=u===o,c=l();++n=_&&s(n?t[n]:c)))}var p=t[0],v=-1,y=p?p.length:0,m=[];t:for(;++ve?Wr(0,r+e):Hr(e,r-1))+1);r--;)if(t[r]===n)return r;return-1}function je(t){for(var n=arguments,e=0,r=n.length,o=t?t.length:0;++ei;){var a=i+u>>>1;r(t[a])1?arguments:arguments[0],n=-1,e=t?ne(ho(t,"length")):0,r=dr(0>e?0:e);++n2?an(t,17,v(arguments,2),null,n):an(t,1,null,null,n)}function ze(t){for(var n=arguments.length>1?Z(arguments,!0,!1,1):kn(t),e=-1,r=n.length;++e2?an(n,19,v(arguments,2),null,t):an(n,3,null,null,t)}function Le(){for(var t=arguments,n=t.length;n--;)if(!Rn(t[n]))throw new jr;return function(){for(var n=arguments,e=t.length;e--;)n=[t[e].apply(this,n)];return n[0]}}function Pe(t,n){return n="number"==typeof n?n:+n||t.length,an(t,4,null,null,null,n)}function qe(t,n,e){var r,o,i,u,a,c,s,f=0,l=!1,p=!0;if(!Rn(t))throw new jr;if(n=Wr(0,n)||0,e===!0){var h=!0;p=!1}else Nn(e)&&(h=e.leading,l="maxWait"in e&&(Wr(n,e.maxWait)||0),p="trailing"in e?e.trailing:p);var d=function(){var e=n-(yo()-u);if(0>=e){o&&Rr(o);var l=s;o=c=s=m,l&&(f=yo(),i=t.apply(a,r),c||o||(r=a=null))}else c=zr(d,e)},v=function(){c&&Rr(c),o=c=s=m,(p||l!==n)&&(f=yo(),i=t.apply(a,r),c||o||(r=a=null))};return function(){if(r=arguments,u=yo(),a=this,s=p&&(c||!h),l===!1)var e=h&&!c;else{o||h||(f=u);var y=l-(u-f),m=0>=y;m?(o&&(o=Rr(o)),f=u,i=t.apply(a,r)):o||(o=zr(v,y))}return m&&c?c=Rr(c):c||n===l||(c=zr(d,n)),e&&(m=!0,i=t.apply(a,r)),!m||c||o||(r=a=null),i}}function Ye(t){if(!Rn(t))throw new jr;var n=v(arguments,1);return zr(function(){t.apply(m,n)},1)}function Fe(t,n){if(!Rn(t))throw new jr;var e=v(arguments,2);return zr(function(){t.apply(m,e)},n)}function Ue(t,n){if(!Rn(t))throw new jr;var e=function(){var r=e.cache,o=n?n.apply(this,arguments):k+arguments[0];return Dr.call(r,o)?r[o]:r[o]=t.apply(this,arguments)};return e.cache={},e}function $e(t){var n,e;if(!Rn(t))throw new jr;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}}function We(t){return an(t,16,v(arguments,1))}function He(t){return an(t,32,null,v(arguments,1))}function Ve(t,n,e){var r=!0,o=!0;if(!Rn(t))throw new jr;return e===!1?r=!1:Nn(e)&&(r="leading"in e?e.leading:r,o="trailing"in e?e.trailing:o),Q.leading=r,Q.maxWait=n,Q.trailing=o,qe(t,n,Q)}function Qe(t,n){return an(n,16,[t])}function Ke(t){return function(){return t}}function Ge(t,n,e){var r=typeof t;if(null==t||"function"==r)return b(t,n,e);if("object"!=r)return er(t);var o=to(t),i=o[0],u=t[i];return 1!=o.length||u!==u||Nn(u)?function(n){for(var e=o.length,r=!1;e--&&(r=tn(n[o[e]],t[o[e]],null,!0)););return r}:function(t){var n=t[i];return u===n&&(0!==u||1/u==1/n)}}function Je(t){return null==t?"":_r(t).replace(oo,cn)}function Xe(t){return t}function Ze(t,r,o){var i=!0,u=r&&kn(r);r&&(o||u.length)||(null==o&&(o=r),a=e,r=t,t=n,u=kn(r)),o===!1?i=!1:Nn(o)&&"chain"in o&&(i=o.chain);var a=t,c=Rn(a);Jn(u,function(n){var e=t[n]=r[n];c&&(a.prototype[n]=function(){var n=this.__chain__,r=this.__wrapped__,o=[r];Ir.apply(o,arguments);var u=e.apply(t,o);if(i||n){if(r===u&&Nn(u))return this;u=new a(u),u.__chain__=n}return u})})}function tr(){return t._=Tr,this}function nr(){}function er(t){return function(n){return n[t]}}function rr(t,n,e){var r=null==t,o=null==n;if(null==e&&("boolean"==typeof t&&o?(e=t,t=1):o||"boolean"!=typeof n||(e=n,o=!0)),r&&o&&(n=1),t=+t||0,o?(n=t,t=0):n=+n||0,e||t%1||n%1){var i=Qr();return Hr(t+i*(n-t+parseFloat("1e-"+((i+"").length-1))),n)}return en(t,n)}function or(t,n){if(t){var e=t[n];return Rn(e)?t[n]():e}}function ir(t,e,r){var o=n.templateSettings;t=_r(t||""),r=uo({},r,o);var i,u=uo({},r.imports,o.imports),a=to(u),c=$n(u),s=0,l=r.interpolate||M,p="__p += '",h=kr((r.escape||M).source+"|"+l.source+"|"+(l===N?E:M).source+"|"+(r.evaluate||M).source+"|$","g");t.replace(h,function(n,e,r,o,u,a){return r||(r=o),p+=t.slice(s,a).replace(I,f),e&&(p+="' +\n__e("+e+") +\n'"),u&&(i=!0,p+="';\n"+u+";\n__p += '"),r&&(p+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),s=a+n.length,n}),p+="';\n";var d=r.variable,v=d;v||(d="obj",p="with ("+d+") {\n"+p+"\n}\n"),p=(i?p.replace(S,""):p).replace(T,"$1").replace(C,"$1;"),p="function("+d+") {\n"+(v?"":d+" || ("+d+" = {});\n")+"var __t, __p = '', __e = _.escape"+(i?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+p+"return __p\n}";var y="\n/*\n//# sourceURL="+(r.sourceURL||"/lodash/template/source["+B++ +"]")+"\n*/";try{var g=mr(a,"return "+p+y).apply(m,c)}catch(b){throw b.source=p,b}return e?g(e):(g.source=p,g)}function ur(t,n,e){t=(t=+t)>-1?t:0;var r=-1,o=dr(t);for(n=b(n,e,1);++r/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:n}},qr||(g=function(){function n(){}return function(e){if(Nn(e)){n.prototype=e;var r=new n;n.prototype=null}return r||t.Object()}}());var Jr=Pr?function(t,n){K.value=n,Pr(t,"__bindData__",K)}:nr,Xr=Yr||function(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Cr.call(t)==P||!1},Zr=function(t){var n,e=t,r=[];if(!e)return r;if(!G[typeof t])return r;for(n in e)Dr.call(e,n)&&r.push(n);return r},to=$r?function(t){return Nn(t)?$r(t):[]}:Zr,no={"&":"&","<":"<",">":">",'"':""","'":"'"},eo=jn(no),ro=kr("("+to(eo).join("|")+")","g"),oo=kr("["+to(no).join("")+"]","g"),io=function(t,n,e){var r,o=t,i=o;if(!o)return i;var u=arguments,a=0,c="number"==typeof e?2:u.length;if(c>3&&"function"==typeof u[c-2])var s=b(u[--c-1],u[c--],2);else c>2&&"function"==typeof u[c-1]&&(s=u[--c]);for(;++a/g,A=RegExp("^["+x+"]*0+(?=.$)"),M=/($^)/,D=/\bthis\b/,I=/['\n\r\t\u2028\u2029\\]/g,z=["Array","Boolean","Date","Function","Math","Number","Object","RegExp","String","_","attachEvent","clearTimeout","isFinite","isNaN","parseInt","setTimeout"],B=0,L="[object Arguments]",P="[object Array]",q="[object Boolean]",Y="[object Date]",F="[object Function]",U="[object Number]",$="[object Object]",W="[object RegExp]",H="[object String]",V={};V[F]=!1,V[L]=V[P]=V[q]=V[Y]=V[U]=V[$]=V[W]=V[H]=!0;var Q={leading:!1,maxWait:0,trailing:!1},K={configurable:!1,enumerable:!1,value:null,writable:!1},G={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},J={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"},X=G[typeof window]&&window||this,Z=G[typeof r]&&r&&!r.nodeType&&r,tn=G[typeof e]&&e&&!e.nodeType&&e,nn=tn&&tn.exports===Z&&Z,en=G[typeof n]&&n;!en||en.global!==en&&en.window!==en||(X=en);var rn=y();"function"==typeof t&&"object"==typeof t.amd&&t.amd?(X._=rn,t(function(){return rn})):Z&&tn?nn?(tn.exports=rn)._=rn:Z._=rn:X._=rn}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(n,e,r){(function(n){/*! +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.Really=t()}}(function(){var t;return function n(t,e,r){function o(u,a){if(!e[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var f=e[u]={exports:{}};t[u][0].call(f.exports,function(n){var e=t[u][1][n];return o(e?e:n)},f,f.exports,n,t,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u0)){var e=r.shift();e()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}):function(t){setTimeout(t,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},{}],2:[function(t,n){function e(t){return t?r(t):void 0}function r(t){for(var n in e.prototype)t[n]=e.prototype[n];return t}n.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,n){return this._callbacks=this._callbacks||{},(this._callbacks[t]=this._callbacks[t]||[]).push(n),this},e.prototype.once=function(t,n){function e(){r.off(t,e),n.apply(this,arguments)}var r=this;return this._callbacks=this._callbacks||{},e.fn=n,this.on(t,e),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,n){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var e=this._callbacks[t];if(!e)return this;if(1==arguments.length)return delete this._callbacks[t],this;for(var r,o=0;or;++r)e[r].apply(this,n)}return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks[t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}},{}],3:[function(n,e,r){(function(n){(function(){function o(t,n,e){for(var r=(e||0)-1,o=t?t.length:0;++r-1?0:-1:t?0:-1}function u(t){var n=this.cache,e=typeof t;if("boolean"==e||null==t)n[t]=!0;else{"number"!=e&&"string"!=e&&(e="object");var r="number"==e?t:k+t,o=n[e]||(n[e]={});"object"==e?(o[r]||(o[r]=[])).push(t):o[r]=!0}}function a(t){return t.charCodeAt(0)}function c(t,n){for(var e=t.criteria,r=n.criteria,o=-1,i=e.length;++oa||"undefined"==typeof u)return 1;if(a>u||"undefined"==typeof a)return-1}}return t.index-n.index}function s(t){var n=-1,e=t.length,r=t[0],o=t[e/2|0],i=t[e-1];if(r&&"object"==typeof r&&o&&"object"==typeof o&&i&&"object"==typeof i)return!1;var a=p();a["false"]=a["null"]=a["true"]=a.undefined=!1;var c=p();for(c.array=t,c.cache=a,c.push=u;++no?0:o);++r=_&&r===o,c=[];if(a){var f=s(n);f?(r=i,n=f):a=!1}for(;++e-1:void 0});return o.pop(),i.pop(),g&&(h(o),h(i)),u}function nn(t,n,e,r,o){(Xr(n)?Jn:co)(n,function(n,i){var u,a,c=n,s=t[i];if(n&&((a=Xr(n))||so(n))){for(var f=r.length;f--;)if(u=r[f]==n){s=o[f];break}if(!u){var l;e&&(c=e(s,n),(l="undefined"!=typeof c)&&(s=c)),l||(s=a?Xr(s)?s:[]:so(s)?s:{}),r.push(n),o.push(s),l||nn(s,n,e,r,o)}}else e&&(c=e(s,n),"undefined"==typeof c&&(c=n)),"undefined"!=typeof c&&(s=c);t[i]=s})}function en(t,n){return t+Nr(Qr()*(n-t+1))}function on(t,n,e){var r=-1,u=sn(),a=t?t.length:0,c=[],f=!n&&a>=_&&u===o,p=e||f?l():c;if(f){var v=s(p);u=i,p=v}for(;++r3&&"function"==typeof n[e-2])var r=b(n[--e-1],n[e--],2);else e>2&&"function"==typeof n[e-1]&&(r=n[--e]);for(var o=v(arguments,1,e),i=-1,u=l(),a=l();++ie?Wr(0,i+e):e)||0,Xr(t)?u=o(t,n,e)>-1:"number"==typeof i?u=(zn(t)?t.indexOf(n,e):o(t,n,e))>-1:co(t,function(t){return++r>=e?!(u=t===n):void 0}),u}function Vn(t,e,r){var o=!0;e=n.createCallback(e,r,3);var i=-1,u=t?t.length:0;if("number"==typeof u)for(;++ii&&(i=s)}else e=null==e&&zn(t)?a:n.createCallback(e,r,3),Jn(t,function(t,n,r){var u=e(t,n,r);u>o&&(o=u,i=t)});return i}function ee(t,e,r){var o=1/0,i=o;if("function"!=typeof e&&r&&r[e]===t&&(e=null),null==e&&Xr(t))for(var u=-1,c=t.length;++us&&(i=s)}else e=null==e&&zn(t)?a:n.createCallback(e,r,3),Jn(t,function(t,n,r){var u=e(t,n,r);o>u&&(o=u,i=t)});return i}function re(t,e,r,o){if(!t)return r;var i=arguments.length<3;e=n.createCallback(e,o,4);var u=-1,a=t.length;if("number"==typeof a)for(i&&(r=t[++u]);++ue?Wr(0,r+e):e||0}else if(e){var i=Ee(t,n);return t[i]===n?i:-1}return o(t,n,e)}function be(t,e,r){var o=0,i=t?t.length:0;if("number"!=typeof e&&null!=e){var u=i;for(e=n.createCallback(e,r,3);u--&&e(t[u],u,t);)o++}else o=null==e||r?1:e||o;return v(t,0,Hr(Wr(0,i-o),i))}function we(){for(var t=[],n=-1,e=arguments.length,r=l(),u=sn(),a=u===o,c=l();++n=_&&s(n?t[n]:c)))}var p=t[0],v=-1,y=p?p.length:0,m=[];t:for(;++ve?Wr(0,r+e):Hr(e,r-1))+1);r--;)if(t[r]===n)return r;return-1}function je(t){for(var n=arguments,e=0,r=n.length,o=t?t.length:0;++ei;){var a=i+u>>>1;r(t[a])1?arguments:arguments[0],n=-1,e=t?ne(ho(t,"length")):0,r=dr(0>e?0:e);++n2?an(t,17,v(arguments,2),null,n):an(t,1,null,null,n)}function ze(t){for(var n=arguments.length>1?Z(arguments,!0,!1,1):kn(t),e=-1,r=n.length;++e2?an(n,19,v(arguments,2),null,t):an(n,3,null,null,t)}function Le(){for(var t=arguments,n=t.length;n--;)if(!Rn(t[n]))throw new jr;return function(){for(var n=arguments,e=t.length;e--;)n=[t[e].apply(this,n)];return n[0]}}function Pe(t,n){return n="number"==typeof n?n:+n||t.length,an(t,4,null,null,null,n)}function qe(t,n,e){var r,o,i,u,a,c,s,f=0,l=!1,p=!0;if(!Rn(t))throw new jr;if(n=Wr(0,n)||0,e===!0){var h=!0;p=!1}else Nn(e)&&(h=e.leading,l="maxWait"in e&&(Wr(n,e.maxWait)||0),p="trailing"in e?e.trailing:p);var d=function(){var e=n-(yo()-u);if(0>=e){o&&Rr(o);var l=s;o=c=s=m,l&&(f=yo(),i=t.apply(a,r),c||o||(r=a=null))}else c=zr(d,e)},v=function(){c&&Rr(c),o=c=s=m,(p||l!==n)&&(f=yo(),i=t.apply(a,r),c||o||(r=a=null))};return function(){if(r=arguments,u=yo(),a=this,s=p&&(c||!h),l===!1)var e=h&&!c;else{o||h||(f=u);var y=l-(u-f),m=0>=y;m?(o&&(o=Rr(o)),f=u,i=t.apply(a,r)):o||(o=zr(v,y))}return m&&c?c=Rr(c):c||n===l||(c=zr(d,n)),e&&(m=!0,i=t.apply(a,r)),!m||c||o||(r=a=null),i}}function Ye(t){if(!Rn(t))throw new jr;var n=v(arguments,1);return zr(function(){t.apply(m,n)},1)}function Fe(t,n){if(!Rn(t))throw new jr;var e=v(arguments,2);return zr(function(){t.apply(m,e)},n)}function Ue(t,n){if(!Rn(t))throw new jr;var e=function(){var r=e.cache,o=n?n.apply(this,arguments):k+arguments[0];return Dr.call(r,o)?r[o]:r[o]=t.apply(this,arguments)};return e.cache={},e}function $e(t){var n,e;if(!Rn(t))throw new jr;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}}function We(t){return an(t,16,v(arguments,1))}function He(t){return an(t,32,null,v(arguments,1))}function Ve(t,n,e){var r=!0,o=!0;if(!Rn(t))throw new jr;return e===!1?r=!1:Nn(e)&&(r="leading"in e?e.leading:r,o="trailing"in e?e.trailing:o),Q.leading=r,Q.maxWait=n,Q.trailing=o,qe(t,n,Q)}function Qe(t,n){return an(n,16,[t])}function Ke(t){return function(){return t}}function Ge(t,n,e){var r=typeof t;if(null==t||"function"==r)return b(t,n,e);if("object"!=r)return er(t);var o=to(t),i=o[0],u=t[i];return 1!=o.length||u!==u||Nn(u)?function(n){for(var e=o.length,r=!1;e--&&(r=tn(n[o[e]],t[o[e]],null,!0)););return r}:function(t){var n=t[i];return u===n&&(0!==u||1/u==1/n)}}function Je(t){return null==t?"":_r(t).replace(oo,cn)}function Xe(t){return t}function Ze(t,r,o){var i=!0,u=r&&kn(r);r&&(o||u.length)||(null==o&&(o=r),a=e,r=t,t=n,u=kn(r)),o===!1?i=!1:Nn(o)&&"chain"in o&&(i=o.chain);var a=t,c=Rn(a);Jn(u,function(n){var e=t[n]=r[n];c&&(a.prototype[n]=function(){var n=this.__chain__,r=this.__wrapped__,o=[r];Ir.apply(o,arguments);var u=e.apply(t,o);if(i||n){if(r===u&&Nn(u))return this;u=new a(u),u.__chain__=n}return u})})}function tr(){return t._=Tr,this}function nr(){}function er(t){return function(n){return n[t]}}function rr(t,n,e){var r=null==t,o=null==n;if(null==e&&("boolean"==typeof t&&o?(e=t,t=1):o||"boolean"!=typeof n||(e=n,o=!0)),r&&o&&(n=1),t=+t||0,o?(n=t,t=0):n=+n||0,e||t%1||n%1){var i=Qr();return Hr(t+i*(n-t+parseFloat("1e-"+((i+"").length-1))),n)}return en(t,n)}function or(t,n){if(t){var e=t[n];return Rn(e)?t[n]():e}}function ir(t,e,r){var o=n.templateSettings;t=_r(t||""),r=uo({},r,o);var i,u=uo({},r.imports,o.imports),a=to(u),c=$n(u),s=0,l=r.interpolate||M,p="__p += '",h=kr((r.escape||M).source+"|"+l.source+"|"+(l===N?C:M).source+"|"+(r.evaluate||M).source+"|$","g");t.replace(h,function(n,e,r,o,u,a){return r||(r=o),p+=t.slice(s,a).replace(I,f),e&&(p+="' +\n__e("+e+") +\n'"),u&&(i=!0,p+="';\n"+u+";\n__p += '"),r&&(p+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),s=a+n.length,n}),p+="';\n";var d=r.variable,v=d;v||(d="obj",p="with ("+d+") {\n"+p+"\n}\n"),p=(i?p.replace(S,""):p).replace(T,"$1").replace(E,"$1;"),p="function("+d+") {\n"+(v?"":d+" || ("+d+" = {});\n")+"var __t, __p = '', __e = _.escape"+(i?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+p+"return __p\n}";var y="\n/*\n//# sourceURL="+(r.sourceURL||"/lodash/template/source["+B++ +"]")+"\n*/";try{var g=mr(a,"return "+p+y).apply(m,c)}catch(b){throw b.source=p,b}return e?g(e):(g.source=p,g)}function ur(t,n,e){t=(t=+t)>-1?t:0;var r=-1,o=dr(t);for(n=b(n,e,1);++r/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:n}},qr||(g=function(){function n(){}return function(e){if(Nn(e)){n.prototype=e;var r=new n;n.prototype=null}return r||t.Object()}}());var Jr=Pr?function(t,n){K.value=n,Pr(t,"__bindData__",K)}:nr,Xr=Yr||function(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Er.call(t)==P||!1},Zr=function(t){var n,e=t,r=[];if(!e)return r;if(!G[typeof t])return r;for(n in e)Dr.call(e,n)&&r.push(n);return r},to=$r?function(t){return Nn(t)?$r(t):[]}:Zr,no={"&":"&","<":"<",">":">",'"':""","'":"'"},eo=jn(no),ro=kr("("+to(eo).join("|")+")","g"),oo=kr("["+to(no).join("")+"]","g"),io=function(t,n,e){var r,o=t,i=o;if(!o)return i;var u=arguments,a=0,c="number"==typeof e?2:u.length;if(c>3&&"function"==typeof u[c-2])var s=b(u[--c-1],u[c--],2);else c>2&&"function"==typeof u[c-1]&&(s=u[--c]);for(;++a/g,A=RegExp("^["+x+"]*0+(?=.$)"),M=/($^)/,D=/\bthis\b/,I=/['\n\r\t\u2028\u2029\\]/g,z=["Array","Boolean","Date","Function","Math","Number","Object","RegExp","String","_","attachEvent","clearTimeout","isFinite","isNaN","parseInt","setTimeout"],B=0,L="[object Arguments]",P="[object Array]",q="[object Boolean]",Y="[object Date]",F="[object Function]",U="[object Number]",$="[object Object]",W="[object RegExp]",H="[object String]",V={};V[F]=!1,V[L]=V[P]=V[q]=V[Y]=V[U]=V[$]=V[W]=V[H]=!0;var Q={leading:!1,maxWait:0,trailing:!1},K={configurable:!1,enumerable:!1,value:null,writable:!1},G={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},J={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"},X=G[typeof window]&&window||this,Z=G[typeof r]&&r&&!r.nodeType&&r,tn=G[typeof e]&&e&&!e.nodeType&&e,nn=tn&&tn.exports===Z&&Z,en=G[typeof n]&&n;!en||en.global!==en&&en.window!==en||(X=en);var rn=y();"function"==typeof t&&"object"==typeof t.amd&&t.amd?(X._=rn,t(function(){return rn})):Z&&tn?nn?(tn.exports=rn)._=rn:Z._=rn:X._=rn}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(n,e,r){(function(n){/*! * * Copyright 2009-2012 Kris Kowal under the terms of the MIT * license found at http://github.com/kriskowal/q/raw/master/LICENSE @@ -30,4 +30,4 @@ * limitations under the License. * */ -!function(n){"use strict";if("function"==typeof bootstrap)bootstrap("promise",n);else if("object"==typeof r&&"object"==typeof e)e.exports=n();else if("function"==typeof t&&t.amd)t(n);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=n}else{if("undefined"==typeof self)throw new Error("This environment was not anticiapted by Q. Please file a bug.");self.Q=n()}}(function(){"use strict";function t(t){return function(){return Q.apply(t,arguments)}}function e(t){return t===Object(t)}function r(t){return"[object StopIteration]"===en(t)||t instanceof $}function o(t,n){if(Y&&n.stack&&"object"==typeof t&&null!==t&&t.stack&&-1===t.stack.indexOf(rn)){for(var e=[],r=n;r;r=r.source)r.stack&&e.unshift(r.stack);e.unshift(t.stack);var o=e.join("\n"+rn+"\n");t.stack=i(o)}}function i(t){for(var n=t.split("\n"),e=[],r=0;r=W&&cn>=r}function s(){if(Y)try{throw new Error}catch(t){var n=t.stack.split("\n"),e=n[0].indexOf("@")>0?n[1]:n[2],r=a(e);if(!r)return;return U=r[0],r[1]}}function f(t,n,e){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn,t.apply(t,arguments)}}function l(t){return t instanceof v?t:b(t)?E(t):C(t)}function p(){function t(t){n=t,i.source=t,G(e,function(n,e){l.nextTick(function(){t.promiseDispatch.apply(t,e)})},void 0),e=void 0,r=void 0}var n,e=[],r=[],o=Z(p.prototype),i=Z(v.prototype);if(i.promiseDispatch=function(t,o,i){var u=K(arguments);e?(e.push(u),"when"===o&&i[1]&&r.push(i[1])):l.nextTick(function(){n.promiseDispatch.apply(n,u)})},i.valueOf=function(){if(e)return i;var t=m(n);return g(t)&&(n=t),t},i.inspect=function(){return n?n.inspect():{state:"pending"}},l.longStackSupport&&Y)try{throw new Error}catch(u){i.stack=u.stack.substring(u.stack.indexOf("\n")+1)}return o.promise=i,o.resolve=function(e){n||t(l(e))},o.fulfill=function(e){n||t(C(e))},o.reject=function(e){n||t(T(e))},o.notify=function(t){n||G(r,function(n,e){l.nextTick(function(){e(t)})},void 0)},o}function h(t){if("function"!=typeof t)throw new TypeError("resolver must be a function.");var n=p();try{t(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}return n.promise}function d(t){return h(function(n,e){for(var r=0,o=t.length;o>r;r++)l(t[r]).then(n,e)})}function v(t,n,e){void 0===n&&(n=function(t){return T(new Error("Promise does not support operation: "+t))}),void 0===e&&(e=function(){return{state:"unknown"}});var r=Z(v.prototype);if(r.promiseDispatch=function(e,o,i){var u;try{u=t[o]?t[o].apply(r,i):n.call(r,o,i)}catch(a){u=T(a)}e&&e(u)},r.inspect=e,e){var o=e();"rejected"===o.state&&(r.exception=o.reason),r.valueOf=function(){var t=e();return"pending"===t.state||"rejected"===t.state?r:t.value}}return r}function y(t,n,e,r){return l(t).then(n,e,r)}function m(t){if(g(t)){var n=t.inspect();if("fulfilled"===n.state)return n.value}return t}function g(t){return t instanceof v}function b(t){return e(t)&&"function"==typeof t.then}function w(t){return g(t)&&"pending"===t.inspect().state}function k(t){return!g(t)||"fulfilled"===t.inspect().state}function _(t){return g(t)&&"rejected"===t.inspect().state}function j(){on.length=0,un.length=0,an||(an=!0)}function x(t,n){an&&(un.push(t),on.push(n&&"undefined"!=typeof n.stack?n.stack:"(no stack) "+n))}function S(t){if(an){var n=J(un,t);-1!==n&&(un.splice(n,1),on.splice(n,1))}}function T(t){var n=v({when:function(n){return n&&S(this),n?n(t):this}},function(){return this},function(){return{state:"rejected",reason:t}});return x(n,t),n}function C(t){return v({when:function(){return t},get:function(n){return t[n]},set:function(n,e){t[n]=e},"delete":function(n){delete t[n]},post:function(n,e){return null===n||void 0===n?t.apply(void 0,e):t[n].apply(t,e)},apply:function(n,e){return t.apply(n,e)},keys:function(){return nn(t)}},void 0,function(){return{state:"fulfilled",value:t}})}function E(t){var n=p();return l.nextTick(function(){try{t.then(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}}),n.promise}function O(t){return v({isDef:function(){}},function(n,e){return I(t,n,e)},function(){return l(t).inspect()})}function R(t,n,e){return l(t).spread(n,e)}function N(t){return function(){function n(t,n){var u;if("undefined"==typeof StopIteration){try{u=e[t](n)}catch(a){return T(a)}return u.done?l(u.value):y(u.value,o,i)}try{u=e[t](n)}catch(a){return r(a)?l(a.value):T(a)}return y(u,o,i)}var e=t.apply(this,arguments),o=n.bind(n,"next"),i=n.bind(n,"throw");return o()}}function A(t){l.done(l.async(t)())}function M(t){throw new $(t)}function D(t){return function(){return R([this,z(arguments)],function(n,e){return t.apply(n,e)})}}function I(t,n,e){return l(t).dispatch(n,e)}function z(t){return y(t,function(t){var n=0,e=p();return G(t,function(r,o,i){var u;g(o)&&"fulfilled"===(u=o.inspect()).state?t[i]=u.value:(++n,y(o,function(r){t[i]=r,0===--n&&e.resolve(t)},e.reject,function(t){e.notify({index:i,value:t})}))},void 0),0===n&&e.resolve(t),e.promise})}function B(t){return y(t,function(t){return t=X(t,l),y(z(X(t,function(t){return y(t,H,H)})),function(){return t})})}function L(t){return l(t).allSettled()}function P(t,n){return l(t).then(void 0,void 0,n)}function q(t,n){return l(t).nodeify(n)}var Y=!1;try{throw new Error}catch(F){Y=!!F.stack}var U,$,W=s(),H=function(){},V=function(){function t(){for(;e.next;){e=e.next;var n=e.task;e.task=void 0;var r=e.domain;r&&(e.domain=void 0,r.enter());try{n()}catch(i){if(u)throw r&&r.exit(),setTimeout(t,0),r&&r.enter(),i;setTimeout(function(){throw i},0)}r&&r.exit()}o=!1}var e={task:void 0,next:null},r=e,o=!1,i=void 0,u=!1;if(V=function(t){r=r.next={task:t,domain:u&&n.domain,next:null},o||(o=!0,i())},"undefined"!=typeof n&&n.nextTick)u=!0,i=function(){n.nextTick(t)};else if("function"==typeof setImmediate)i="undefined"!=typeof window?setImmediate.bind(window,t):function(){setImmediate(t)};else if("undefined"!=typeof MessageChannel){var a=new MessageChannel;a.port1.onmessage=function(){i=c,a.port1.onmessage=t,t()};var c=function(){a.port2.postMessage(0)};i=function(){setTimeout(t,0),c()}}else i=function(){setTimeout(t,0)};return V}(),Q=Function.call,K=t(Array.prototype.slice),G=t(Array.prototype.reduce||function(t,n){var e=0,r=this.length;if(1===arguments.length)for(;;){if(e in this){n=this[e++];break}if(++e>=r)throw new TypeError}for(;r>e;e++)e in this&&(n=t(n,this[e],e));return n}),J=t(Array.prototype.indexOf||function(t){for(var n=0;n2?K(arguments,1):e)}},l.Promise=h,l.promise=h,h.race=d,h.all=z,h.reject=T,h.resolve=l,l.passByCopy=function(t){return t},v.prototype.passByCopy=function(){return this},l.join=function(t,n){return l(t).join(n)},v.prototype.join=function(t){return l([this,t]).spread(function(t,n){if(t===n)return t;throw new Error("Can't join: not the same: "+t+" "+n)})},l.race=d,v.prototype.race=function(){return this.then(l.race)},l.makePromise=v,v.prototype.toString=function(){return"[object Promise]"},v.prototype.then=function(t,n,e){function r(n){try{return"function"==typeof t?t(n):n}catch(e){return T(e)}}function i(t){if("function"==typeof n){o(t,a);try{return n(t)}catch(e){return T(e)}}return T(t)}function u(t){return"function"==typeof e?e(t):t}var a=this,c=p(),s=!1;return l.nextTick(function(){a.promiseDispatch(function(t){s||(s=!0,c.resolve(r(t)))},"when",[function(t){s||(s=!0,c.resolve(i(t)))}])}),a.promiseDispatch(void 0,"when",[void 0,function(t){var n,e=!1;try{n=u(t)}catch(r){if(e=!0,!l.onerror)throw r;l.onerror(r)}e||c.notify(n)}]),c.promise},l.tap=function(t,n){return l(t).tap(n)},v.prototype.tap=function(t){return t=l(t),this.then(function(n){return t.fcall(n).thenResolve(n)})},l.when=y,v.prototype.thenResolve=function(t){return this.then(function(){return t})},l.thenResolve=function(t,n){return l(t).thenResolve(n)},v.prototype.thenReject=function(t){return this.then(function(){throw t})},l.thenReject=function(t,n){return l(t).thenReject(n)},l.nearer=m,l.isPromise=g,l.isPromiseAlike=b,l.isPending=w,v.prototype.isPending=function(){return"pending"===this.inspect().state},l.isFulfilled=k,v.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},l.isRejected=_,v.prototype.isRejected=function(){return"rejected"===this.inspect().state};var on=[],un=[],an=!0;l.resetUnhandledRejections=j,l.getUnhandledReasons=function(){return on.slice()},l.stopUnhandledRejectionTracking=function(){j(),an=!1},j(),l.reject=T,l.fulfill=C,l.master=O,l.spread=R,v.prototype.spread=function(t,n){return this.all().then(function(n){return t.apply(void 0,n)},n)},l.async=N,l.spawn=A,l["return"]=M,l.promised=D,l.dispatch=I,v.prototype.dispatch=function(t,n){var e=this,r=p();return l.nextTick(function(){e.promiseDispatch(r.resolve,t,n)}),r.promise},l.get=function(t,n){return l(t).dispatch("get",[n])},v.prototype.get=function(t){return this.dispatch("get",[t])},l.set=function(t,n,e){return l(t).dispatch("set",[n,e])},v.prototype.set=function(t,n){return this.dispatch("set",[t,n])},l.del=l["delete"]=function(t,n){return l(t).dispatch("delete",[n])},v.prototype.del=v.prototype["delete"]=function(t){return this.dispatch("delete",[t])},l.mapply=l.post=function(t,n,e){return l(t).dispatch("post",[n,e])},v.prototype.mapply=v.prototype.post=function(t,n){return this.dispatch("post",[t,n])},l.send=l.mcall=l.invoke=function(t,n){return l(t).dispatch("post",[n,K(arguments,2)])},v.prototype.send=v.prototype.mcall=v.prototype.invoke=function(t){return this.dispatch("post",[t,K(arguments,1)])},l.fapply=function(t,n){return l(t).dispatch("apply",[void 0,n])},v.prototype.fapply=function(t){return this.dispatch("apply",[void 0,t])},l["try"]=l.fcall=function(t){return l(t).dispatch("apply",[void 0,K(arguments,1)])},v.prototype.fcall=function(){return this.dispatch("apply",[void 0,K(arguments)])},l.fbind=function(t){var n=l(t),e=K(arguments,1);return function(){return n.dispatch("apply",[this,e.concat(K(arguments))])}},v.prototype.fbind=function(){var t=this,n=K(arguments);return function(){return t.dispatch("apply",[this,n.concat(K(arguments))])}},l.keys=function(t){return l(t).dispatch("keys",[])},v.prototype.keys=function(){return this.dispatch("keys",[])},l.all=z,v.prototype.all=function(){return z(this)},l.allResolved=f(B,"allResolved","allSettled"),v.prototype.allResolved=function(){return B(this)},l.allSettled=L,v.prototype.allSettled=function(){return this.then(function(t){return z(X(t,function(t){function n(){return t.inspect()}return t=l(t),t.then(n,n)}))})},l.fail=l["catch"]=function(t,n){return l(t).then(void 0,n)},v.prototype.fail=v.prototype["catch"]=function(t){return this.then(void 0,t)},l.progress=P,v.prototype.progress=function(t){return this.then(void 0,void 0,t)},l.fin=l["finally"]=function(t,n){return l(t)["finally"](n)},v.prototype.fin=v.prototype["finally"]=function(t){return t=l(t),this.then(function(n){return t.fcall().then(function(){return n})},function(n){return t.fcall().then(function(){throw n})})},l.done=function(t,n,e,r){return l(t).done(n,e,r)},v.prototype.done=function(t,e,r){var i=function(t){l.nextTick(function(){if(o(t,u),!l.onerror)throw t;l.onerror(t)})},u=t||e||r?this.then(t,e,r):this;"object"==typeof n&&n&&n.domain&&(i=n.domain.bind(i)),u.then(void 0,i)},l.timeout=function(t,n,e){return l(t).timeout(n,e)},v.prototype.timeout=function(t,n){var e=p(),r=setTimeout(function(){n&&"string"!=typeof n||(n=new Error(n||"Timed out after "+t+" ms"),n.code="ETIMEDOUT"),e.reject(n)},t);return this.then(function(t){clearTimeout(r),e.resolve(t)},function(t){clearTimeout(r),e.reject(t)},e.notify),e.promise},l.delay=function(t,n){return void 0===n&&(n=t,t=void 0),l(t).delay(n)},v.prototype.delay=function(t){return this.then(function(n){var e=p();return setTimeout(function(){e.resolve(n)},t),e.promise})},l.nfapply=function(t,n){return l(t).nfapply(n)},v.prototype.nfapply=function(t){var n=p(),e=K(t);return e.push(n.makeNodeResolver()),this.fapply(e).fail(n.reject),n.promise},l.nfcall=function(t){var n=K(arguments,1);return l(t).nfapply(n)},v.prototype.nfcall=function(){var t=K(arguments),n=p();return t.push(n.makeNodeResolver()),this.fapply(t).fail(n.reject),n.promise},l.nfbind=l.denodeify=function(t){var n=K(arguments,1);return function(){var e=n.concat(K(arguments)),r=p();return e.push(r.makeNodeResolver()),l(t).fapply(e).fail(r.reject),r.promise}},v.prototype.nfbind=v.prototype.denodeify=function(){var t=K(arguments);return t.unshift(this),l.denodeify.apply(void 0,t)},l.nbind=function(t,n){var e=K(arguments,2);return function(){function r(){return t.apply(n,arguments)}var o=e.concat(K(arguments)),i=p();return o.push(i.makeNodeResolver()),l(r).fapply(o).fail(i.reject),i.promise}},v.prototype.nbind=function(){var t=K(arguments,0);return t.unshift(this),l.nbind.apply(void 0,t)},l.nmapply=l.npost=function(t,n,e){return l(t).npost(n,e)},v.prototype.nmapply=v.prototype.npost=function(t,n){var e=K(n||[]),r=p();return e.push(r.makeNodeResolver()),this.dispatch("post",[t,e]).fail(r.reject),r.promise},l.nsend=l.nmcall=l.ninvoke=function(t,n){var e=K(arguments,2),r=p();return e.push(r.makeNodeResolver()),l(t).dispatch("post",[n,e]).fail(r.reject),r.promise},v.prototype.nsend=v.prototype.nmcall=v.prototype.ninvoke=function(t){var n=K(arguments,1),e=p();return n.push(e.makeNodeResolver()),this.dispatch("post",[t,n]).fail(e.reject),e.promise},l.nodeify=q,v.prototype.nodeify=function(t){return t?void this.then(function(n){l.nextTick(function(){t(null,n)})},function(n){l.nextTick(function(){t(n)})}):this};var cn=s();return l})}).call(this,n("_process"))},{_process:1}],5:[function(t,n){function e(t,n){var e;return e=n?new o(t,n):new o(t)}var r=function(){return this}(),o=r.WebSocket||r.MozWebSocket;n.exports=o?e:null,o&&(e.prototype=o.prototype)},{}],6:[function(t,n){n.exports={getAccessToken:function(){return"xxwmn93p0h"}}},{}],7:[function(t,n){var e,r,o,i;o=t("./protocol"),r=t("./really-error"),i=t("lodash"),e=function(){function t(){this.tag=0,this._callbacks={}}var n;return t.prototype.handle=function(t){var n,e;if(!(t.tag in this._callbacks))throw new r("A message with this tag: "+t.tag+" doesn't exist");if(e=t.tag,o.isErrorMessage(t))try{this._callbacks[e].error.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your error callback")}else try{this._callbacks[e].success.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your success callback")}try{this._callbacks[e].complete.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your complete callback")}return delete this._callbacks[e]},t.prototype.add=function(t){var e,r,o,u,a;return null==t&&(t={}),o=t.kind,u=t.success,r=t.error,e=t.complete,null==o&&(o="default"),null==u&&(u=i.noop),null==r&&(r=i.noop),null==e&&(e=i.noop),a=n.call(this),this._callbacks[a]={kind:o,success:u,error:r,complete:e},a},n=function(){return this.tag+=1},t}(),n.exports=e},{"./protocol":10,"./really-error":13,lodash:3}],8:[function(t,n){var e,r,o,i,u;u=t("./protocol"),o=t("q"),r=t("./logger"),i=new r,e=function(){function t(t,n){this.interval=null!=t?t:5e3,this.timeout=null!=n?n:5e3,i.debug("Heartbeat: initialize with interval: "+t+" and timeout: "+n)}var n;return t.prototype.start=function(t){return this.websocket=t,n.call(this),i.debug("Heartbeat: started interval: "+this.interval+" timeout: "+this.timeout)},n=function(){var t,e,r,a;return e=u.heartbeatMessage(),r=this.websocket.send(e),a=function(t){return function(e){var r,u;return u=Date.now(),r=.001*(u-e.timestamp),i.debug("Heartbeat: lag "+r+" second(s)"),o.delay(t.interval).then(function(){return i.debug("Heartbeat interval: "+t.interval+" timeout: "+t.timeout),n.call(t)})}}(this),t=function(){return i.debug("Heartbeat: lag exceed"),this.websocket.disconnect()},r.timeout(this.interval+this.timeout).then(a,t)},t}(),n.exports=e},{"./logger":9,"./protocol":10,q:4}],9:[function(t,n){var e,r,o=[].slice;r=t("lodash"),e=function(){function t(){}return t.prototype.debug=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Debug::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.debug)&&n.apply(console,t),t},t.prototype.info=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Info::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.log)&&n.apply(console,t),t},t.prototype.warn=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Warn::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.warn)&&n.apply(console,t),t},t.prototype.error=function(){var t,n,e,i,u,a;return t=1<=arguments.length?o.call(arguments,0):[],u="Really::Error::",r.isObject(t[0])&&(n=t[0].code,i=t[0].message,e=t[0].errorName,u=""+u+e+"::"+n+":: "+i,t.shift()),t.unshift(u),"undefined"!=typeof console&&null!==console&&null!=(a=console.error)&&a.apply(console,t),t},t}(),n.exports=e},{lodash:3}],10:[function(t,n){var e,r,o,i,u=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};i=t("lodash"),o=t("./authenticator"),e=t("./really-error"),r="0",n.exports={clientVersion:r,commands:{init:"init",create:"create",read:"read",get:"get",update:"update","delete":"delete",heartbeat:"poke",subscribe:"subscribe",unsubscribe:"unsubscribe"},initializationMessage:function(t){if(!i.isString(t))throw new e("You should pass accessToken parameter as String");return{kind:"initialization",data:{cmd:this.commands.init,accessToken:t}}},createMessage:function(t,n){var r;if(!i.isString(t))throw new e("You should pass a resource parameter as String");if(!i.isObject(n)&&!i.isUndefined(n))throw new e("You should pass a body parameter as Object");return r={kind:"create",data:{cmd:this.commands.create,r:t}},n&&(r.body=n),r},readMessage:function(t,n){var r,o,u,a,c,s;r=i.omit(n,function(t){return void 0===t}),c={fields:{valid:i.isArray,message:'You should pass Array for "fields" option'},query:{valid:function(t){return i.isObject(t)&&(i.isString(t.filter)||i.isObject(t.values))},message:'You should pass Object for "query" option'},limit:{valid:i.isNumber,message:'You should pass Number for "limit" option'},skip:{valid:i.isNumber,message:'You should pass Number for "skip" option'},sort:{valid:i.isString,message:'You should pass String for "sort" option'},token:{valid:i.isString,message:'You should pass String for "token" option'},includeTotalCount:{valid:i.isBoolean,message:'You should pass Boolean for "includeTotalCount" option'},paginationToken:{valid:i.isString,message:'You should pass String for "paginationToken" option'},subscribe:{valid:i.isBoolean,message:'You should pass Boolean for "subscribe" option'}};for(a in r){if(s=r[a],!(a in c))throw new e('The option "'+a+"\" isn't supported");if(o=c[a],!o.valid(s))throw new e(o.message)}return u={kind:"read",data:{cmd:this.commands.read,r:t}},r&&(u.data.cmdOpts=r),u},getMessage:function(t,n){var r;if(!i.isArray(n))throw new e("You should pass array or nothing for fields option");return r={kind:"get",data:{cmd:this.commands.get,r:t}},n&&(r.data.cmdOpts={fields:n}),r},updateMessage:function(t,n,r){var o,a,c,s,f,l;if(!(i.isArray(r)&&r.length>0))throw new e("You should pass at least one operation");for(c=["set","addNumber","push","addToSet","insertAt","pull","removeAt"],s=0,f=r.length;f>s;s++)if(a=r[s],l=a.op,u.call(c,l)<0)throw new e('"'+a.op+'" operation you passed is not supported');return o={kind:"update",data:{cmd:this.commands.update,rev:n,r:t,body:{ops:r}}}},deleteMessage:function(t){if(!i.isString(t))throw new e("You should pass a resource parameter as String");return{kind:"delete",data:{cmd:this.commands["delete"],r:t}}},subscribeMessage:function(t){var n,r,o,u;if(!i.isPlainObject(t)&&!i.isArray(t))throw new e("subscription(s) should be either Object or Array of Objects");for(i.isArray(t)||(t=[t]),o=0,u=t.length;u>o;o++)if(r=t[o],!i.isNumber(r.rev)||!i.isString(r.res))throw new e("You must pass string resource and number revision for subscription object");return n={kind:"subscribe",data:{cmd:this.commands.subscribe,subscriptions:t}}},unsubscribeMessage:function(t){var n,r,o,u;if(!i.isPlainObject(t)&&!i.isArray(t))throw new e("subscription(s) should be either Object or Array of Objects");for(i.isArray(t)||(t=[t]),o=0,u=t.length;u>o;o++)if(r=t[o],!i.isNumber(r.rev)||!i.isString(r.res))throw new e("You must pass string resource and number revision for subscription object");return n={kind:"unsubscribe",data:{cmd:this.commands.unsubscribe,subscriptions:t}}},heartbeatMessage:function(){var t;return t=Date.now(),{kind:"poke",data:{cmd:this.commands.heartbeat,timestamp:t}}},isErrorMessage:function(t){return i.has(t,"error")}}},{"./authenticator":6,"./really-error":13,lodash:3}],11:[function(t,n){var e;e=t("./really-error"),n.exports={handle:function(t,n){var r,o;switch(null==n&&(n={}),o=n.r,r=n.evt,r){case"updated":case"deleted":return t.object.emit(""+o+":"+r,n);case"created":return t.collection.emit(""+o+":"+r,n);case"kicked":case"revoked":return t.emit(r,n);default:throw new e("Unknown event: "+r)}}}},{"./really-error":13}],12:[function(t,n){var e,r,o,i,u,a;a=t("lodash"),u=t("./protocol"),i=t("./really-error"),e=t("component-emitter"),a=t("lodash"),r=t("q"),o=function(){function t(t){this.channel=t,e(this)}return t.prototype.create=function(t,n){var e,o,c,s,f,l,p;if(null==n&&(n={}),!a.isString(t))throw new i("Can not be initialized without resource");o=new r.defer,p=n.onSuccess,l=n.onError,f=n.onComplete,e=n.body;try{s=u.createMessage(t,e)}catch(h){return c=h,setTimeout(function(){return o.reject(c)},0),o.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype.read=function(t,n){var e,o,c,s,f,l,p;if(null==n&&(n={}),!a.isString(t))throw new i("Can not be initialized without resource");e=new r.defer,l=n.onSuccess,f=n.onError,s=n.onComplete,p=a.omit(n,["onSuccess","onError","onComplete"]);try{c=u.readMessage(t,p)}catch(h){return o=h,setTimeout(function(){return e.reject(o)},0),e.promise}return this.channel.send(c,{success:l,error:f,complete:s})},t.prototype.onCreate=function(t,n){return this.on(""+t+":created",function(t){return n(t)})},t}(),n.exports=o},{"./protocol":10,"./really-error":13,"component-emitter":2,lodash:3,q:4}],13:[function(t,n){var e,r={}.hasOwnProperty,o=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};e=function(t){function n(t){this.message=null!=t?t:"Unknown Error","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,n),this.name="ReallyError"}return o(n,t),n}(Error),n.exports=e},{}],14:[function(t,n){var e,r,o,i,u,a;u=t("./protocol"),o=t("./really-error"),e=t("component-emitter"),a=t("lodash"),r=t("q"),i=function(){function t(t){this.channel=t,e(this)}return t.prototype.get=function(t,n){var e,i,c,s,f,l,p;if(!a.isString(t))throw new o("Can not be initialized without resource");e=new r.defer,c=n.fields,p=n.onSuccess,l=n.onError,f=n.onComplete;try{s=u.getMessage(t,c)}catch(h){return i=h,setTimeout(function(){return e.reject(i)},0),e.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype.update=function(t,n,e){var i,c,s,f,l,p,h;if(!a.isString(t))throw new o("Can not be initialized without resource");if(i=new r.defer,!e)return i.reject(new o("Can't be called without passing arguments")),i.promise;h=e.ops,p=e.onSuccess,l=e.onError,f=e.onComplete;try{s=u.updateMessage(t,h)}catch(d){return c=d,setTimeout(function(){return i.reject(c)},0),i.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype["delete"]=function(t,n){var e,r,i,c;if(!a.isString(t))throw new o("Can not be initialized without resource");return c=n.onSuccess,i=n.onError,r=n.onComplete,e=u.deleteMessage(t),this.channel.send(e,{success:c,error:i,complete:r})},t.prototype.onUpdate=function(t,n){return this.on(""+t+":updated",function(t){return n(t)})},t.prototype.onDelete=function(t,n){return this.on(""+t+":deleted",function(t){return n(t)})},t}(),n.exports=i},{"./protocol":10,"./really-error":13,"component-emitter":2,lodash:3,q:4}],15:[function(t,n){var e,r,o,i,u,a,c,s;a=t("./transports/webSocket"),u=t("./really-object"),o=t("./really-collection"),i=t("./really-error"),s=t("lodash"),e=t("./push-handler"),c={},r=function(){function t(t,n,r){if(!t||!n)throw new i("Can't initialize Really without passing domain and access token");if(!s.isString(t)||!s.isString(n))throw new i("Only values are allowed for domain and access token");return c[t]?(this.object=c[t].object,this.collection=c[t].collection,this.transport=c[t].transport):(c[t]={},this.transport=new a(t,n,r),this.transport.connect(),c[t].transport=this.transport,this.object=c[t].object=new u(this.transport),this.collection=c[t].collection=new o(this.transport),this.transport.on("message",function(t){return function(n){return s.has(n,"tag")?void 0:e.handle(t,n)}}(this))),this}return t}(),n.exports=r},{"./push-handler":11,"./really-collection":12,"./really-error":13,"./really-object":14,"./transports/webSocket":17,lodash:3}],16:[function(t,n){var e;e=function(){function t(t){this.url=t}return t.prototype.connect=function(){return void 0},t.prototype.disconnect=function(){return void 0},t.prototype.send=function(){return void 0},t.prototype.isConnected=function(){return void 0},t.prototype.on=function(){return void 0},t}(),n.exports=e},{}],17:[function(t,n){var e,r,o,i,u,a,c,s,f,l,p,h,d,v={}.hasOwnProperty,y=function(t,n){function e(){this.constructor=t}for(var r in n)v.call(n,r)&&(t[r]=n[r]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};d=t("lodash"),s=t("../transport"),c=t("../really-error"),f=t("ws"),h=t("../protocol"),r=t("component-emitter"),e=t("../callbacks-buffer"),u=t("../push-handler"),a=t("q"),o=t("../heartbeat"),i=t("../logger"),p=new i,l=function(t){function n(t,n,r){var o;this.domain=t,this.accessToken=n,this.options=null!=r?r:{},this.socket=null,this.callbacksBuffer=new e,this._messagesBuffer=[],this.pushHandler=u,this.initialized=!1,this.url=""+t+"/v"+h.clientVersion+"/socket",o={reconnectionMaxTimeout:3e4,heartbeatTimeout:2e3,heartbeatInterval:5e3,reconnect:!0,onDisconnect:"buffer"},this.options=d.defaults(this.options,o)}var i,s,l;return y(n,t),r(n.prototype),i=function(t){return this.socket.addEventListener("open",function(n){return function(){return n.attempts=0,t.resolve(),l.call(n),n.emit("opened")}}(this)),this.socket.addEventListener("close",function(t){return function(){return t.options.reconnect?(t.emit("reconnecting"),t.reconnect(t.options.reconnectionMaxTimeout)):(t.emit("closed"),t.disconnect())}}(this)),this.socket.addEventListener("error",function(t){return function(){return t.emit("error")}}(this)),this.socket.addEventListener("message",function(t){return function(n){var e;return e=JSON.parse(n.data),d.has(e,"tag")&&t.callbacksBuffer.handle(e),t.emit("message",e)}}(this))},n.prototype.send=function(t,n,e){var r,o,i,u,s,f;return null==n&&(n={}),null==e&&(e=a.defer()),this.isConnected()?(i=t.kind,s=function(t){return"function"==typeof n.success&&n.success(t),e.resolve(t)},o=function(t){return"function"==typeof n.error&&n.error(t),e.reject(t)},r=function(t){return"function"==typeof n.complete?n.complete(t):void 0},t.data.tag=this.callbacksBuffer.add({kind:i,success:s,error:o,complete:r}),this.socket.send(JSON.stringify(t.data)),e.promise):(u=d.isFunction(this.options.onDisconnect)?"custom":this.options.onDisconnect,f=function(r){return function(o){var i,u,a,s,f;null==o&&(o="fail"),s=function(){return e.reject(new c("Connection to the server is not established"))},i=function(){return r._messagesBuffer.push({message:t,options:n,deferred:e})},u=function(){var t;try{return r.options.onDisconnect(r,r._messagesBuffer,c)}catch(n){throw t=n,new c("error invoking custom callback")}},f={fail:s,buffer:i,custom:u};try{return f[o]()}catch(l){if(a=l,a instanceof c)throw a;throw new c("Strategy not found")}}}(this),f(u),e.promise)},l=function(){var t,n,e;return e=function(t){return function(n){var e;return t.initialized=!0,d.flush.call(t),e=new o(t.options.heartbeatInterval,t.options.heartbeatTimeout),e.start(t),t.emit("initialized",n)}}(this),t=function(t){return function(n){return t.initialized=!1,t.emit("initializationError",n)}}(this),n=h.initializationMessage(this.accessToken),this.send(n,{success:e,error:t})},n.prototype.connect=function(t){return null==t&&(t=a.defer()),this.socket=new f(this.url),this.socket.addEventListener("error",d.once(function(){return void 0})),i.call(this,t),t.promise},n.prototype.reconnect=function(t){return this.attempts+=1,this.connect().timeout(t)["catch"](function(){return t=generateTimeout(t),reconnect(t)})},d.flush=function(){return setTimeout(function(t){return function(){var n,e,r,o,i,u,a,c;for(u=t._messagesBuffer,c=[],o=0,i=u.length;i>o;o++)a=u[o],e=a.message,r=a.options,n=a.deferred,c.push(t.send(e,r,n));return c}}(this),0)},n.prototype.isConnected=function(){return this.socket?this.socket.readyState===this.socket.OPEN:!1},n.prototype.isConnecting=function(){return this.socket?this.socket.readyState===this.socket.CONNECTING:!1},s=function(){return this.off()},n.prototype.disconnect=function(){var t;return s.call(this),null!=(t=this.socket)&&t.close(),this.socket=null,this.initialized=!1},n}(s),n.exports=l},{"../callbacks-buffer":7,"../heartbeat":8,"../logger":9,"../protocol":10,"../push-handler":11,"../really-error":13,"../transport":16,"component-emitter":2,lodash:3,q:4,ws:5}]},{},[15])(15)}); \ No newline at end of file +!function(n){"use strict";if("function"==typeof bootstrap)bootstrap("promise",n);else if("object"==typeof r&&"object"==typeof e)e.exports=n();else if("function"==typeof t&&t.amd)t(n);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=n}else{if("undefined"==typeof self)throw new Error("This environment was not anticiapted by Q. Please file a bug.");self.Q=n()}}(function(){"use strict";function t(t){return function(){return Q.apply(t,arguments)}}function e(t){return t===Object(t)}function r(t){return"[object StopIteration]"===en(t)||t instanceof $}function o(t,n){if(Y&&n.stack&&"object"==typeof t&&null!==t&&t.stack&&-1===t.stack.indexOf(rn)){for(var e=[],r=n;r;r=r.source)r.stack&&e.unshift(r.stack);e.unshift(t.stack);var o=e.join("\n"+rn+"\n");t.stack=i(o)}}function i(t){for(var n=t.split("\n"),e=[],r=0;r=W&&cn>=r}function s(){if(Y)try{throw new Error}catch(t){var n=t.stack.split("\n"),e=n[0].indexOf("@")>0?n[1]:n[2],r=a(e);if(!r)return;return U=r[0],r[1]}}function f(t,n,e){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn,t.apply(t,arguments)}}function l(t){return t instanceof v?t:b(t)?C(t):E(t)}function p(){function t(t){n=t,i.source=t,G(e,function(n,e){l.nextTick(function(){t.promiseDispatch.apply(t,e)})},void 0),e=void 0,r=void 0}var n,e=[],r=[],o=Z(p.prototype),i=Z(v.prototype);if(i.promiseDispatch=function(t,o,i){var u=K(arguments);e?(e.push(u),"when"===o&&i[1]&&r.push(i[1])):l.nextTick(function(){n.promiseDispatch.apply(n,u)})},i.valueOf=function(){if(e)return i;var t=m(n);return g(t)&&(n=t),t},i.inspect=function(){return n?n.inspect():{state:"pending"}},l.longStackSupport&&Y)try{throw new Error}catch(u){i.stack=u.stack.substring(u.stack.indexOf("\n")+1)}return o.promise=i,o.resolve=function(e){n||t(l(e))},o.fulfill=function(e){n||t(E(e))},o.reject=function(e){n||t(T(e))},o.notify=function(t){n||G(r,function(n,e){l.nextTick(function(){e(t)})},void 0)},o}function h(t){if("function"!=typeof t)throw new TypeError("resolver must be a function.");var n=p();try{t(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}return n.promise}function d(t){return h(function(n,e){for(var r=0,o=t.length;o>r;r++)l(t[r]).then(n,e)})}function v(t,n,e){void 0===n&&(n=function(t){return T(new Error("Promise does not support operation: "+t))}),void 0===e&&(e=function(){return{state:"unknown"}});var r=Z(v.prototype);if(r.promiseDispatch=function(e,o,i){var u;try{u=t[o]?t[o].apply(r,i):n.call(r,o,i)}catch(a){u=T(a)}e&&e(u)},r.inspect=e,e){var o=e();"rejected"===o.state&&(r.exception=o.reason),r.valueOf=function(){var t=e();return"pending"===t.state||"rejected"===t.state?r:t.value}}return r}function y(t,n,e,r){return l(t).then(n,e,r)}function m(t){if(g(t)){var n=t.inspect();if("fulfilled"===n.state)return n.value}return t}function g(t){return t instanceof v}function b(t){return e(t)&&"function"==typeof t.then}function w(t){return g(t)&&"pending"===t.inspect().state}function k(t){return!g(t)||"fulfilled"===t.inspect().state}function _(t){return g(t)&&"rejected"===t.inspect().state}function j(){on.length=0,un.length=0,an||(an=!0)}function x(t,n){an&&(un.push(t),on.push(n&&"undefined"!=typeof n.stack?n.stack:"(no stack) "+n))}function S(t){if(an){var n=J(un,t);-1!==n&&(un.splice(n,1),on.splice(n,1))}}function T(t){var n=v({when:function(n){return n&&S(this),n?n(t):this}},function(){return this},function(){return{state:"rejected",reason:t}});return x(n,t),n}function E(t){return v({when:function(){return t},get:function(n){return t[n]},set:function(n,e){t[n]=e},"delete":function(n){delete t[n]},post:function(n,e){return null===n||void 0===n?t.apply(void 0,e):t[n].apply(t,e)},apply:function(n,e){return t.apply(n,e)},keys:function(){return nn(t)}},void 0,function(){return{state:"fulfilled",value:t}})}function C(t){var n=p();return l.nextTick(function(){try{t.then(n.resolve,n.reject,n.notify)}catch(e){n.reject(e)}}),n.promise}function O(t){return v({isDef:function(){}},function(n,e){return I(t,n,e)},function(){return l(t).inspect()})}function R(t,n,e){return l(t).spread(n,e)}function N(t){return function(){function n(t,n){var u;if("undefined"==typeof StopIteration){try{u=e[t](n)}catch(a){return T(a)}return u.done?l(u.value):y(u.value,o,i)}try{u=e[t](n)}catch(a){return r(a)?l(a.value):T(a)}return y(u,o,i)}var e=t.apply(this,arguments),o=n.bind(n,"next"),i=n.bind(n,"throw");return o()}}function A(t){l.done(l.async(t)())}function M(t){throw new $(t)}function D(t){return function(){return R([this,z(arguments)],function(n,e){return t.apply(n,e)})}}function I(t,n,e){return l(t).dispatch(n,e)}function z(t){return y(t,function(t){var n=0,e=p();return G(t,function(r,o,i){var u;g(o)&&"fulfilled"===(u=o.inspect()).state?t[i]=u.value:(++n,y(o,function(r){t[i]=r,0===--n&&e.resolve(t)},e.reject,function(t){e.notify({index:i,value:t})}))},void 0),0===n&&e.resolve(t),e.promise})}function B(t){return y(t,function(t){return t=X(t,l),y(z(X(t,function(t){return y(t,H,H)})),function(){return t})})}function L(t){return l(t).allSettled()}function P(t,n){return l(t).then(void 0,void 0,n)}function q(t,n){return l(t).nodeify(n)}var Y=!1;try{throw new Error}catch(F){Y=!!F.stack}var U,$,W=s(),H=function(){},V=function(){function t(){for(;e.next;){e=e.next;var n=e.task;e.task=void 0;var r=e.domain;r&&(e.domain=void 0,r.enter());try{n()}catch(i){if(u)throw r&&r.exit(),setTimeout(t,0),r&&r.enter(),i;setTimeout(function(){throw i},0)}r&&r.exit()}o=!1}var e={task:void 0,next:null},r=e,o=!1,i=void 0,u=!1;if(V=function(t){r=r.next={task:t,domain:u&&n.domain,next:null},o||(o=!0,i())},"undefined"!=typeof n&&n.nextTick)u=!0,i=function(){n.nextTick(t)};else if("function"==typeof setImmediate)i="undefined"!=typeof window?setImmediate.bind(window,t):function(){setImmediate(t)};else if("undefined"!=typeof MessageChannel){var a=new MessageChannel;a.port1.onmessage=function(){i=c,a.port1.onmessage=t,t()};var c=function(){a.port2.postMessage(0)};i=function(){setTimeout(t,0),c()}}else i=function(){setTimeout(t,0)};return V}(),Q=Function.call,K=t(Array.prototype.slice),G=t(Array.prototype.reduce||function(t,n){var e=0,r=this.length;if(1===arguments.length)for(;;){if(e in this){n=this[e++];break}if(++e>=r)throw new TypeError}for(;r>e;e++)e in this&&(n=t(n,this[e],e));return n}),J=t(Array.prototype.indexOf||function(t){for(var n=0;n2?K(arguments,1):e)}},l.Promise=h,l.promise=h,h.race=d,h.all=z,h.reject=T,h.resolve=l,l.passByCopy=function(t){return t},v.prototype.passByCopy=function(){return this},l.join=function(t,n){return l(t).join(n)},v.prototype.join=function(t){return l([this,t]).spread(function(t,n){if(t===n)return t;throw new Error("Can't join: not the same: "+t+" "+n)})},l.race=d,v.prototype.race=function(){return this.then(l.race)},l.makePromise=v,v.prototype.toString=function(){return"[object Promise]"},v.prototype.then=function(t,n,e){function r(n){try{return"function"==typeof t?t(n):n}catch(e){return T(e)}}function i(t){if("function"==typeof n){o(t,a);try{return n(t)}catch(e){return T(e)}}return T(t)}function u(t){return"function"==typeof e?e(t):t}var a=this,c=p(),s=!1;return l.nextTick(function(){a.promiseDispatch(function(t){s||(s=!0,c.resolve(r(t)))},"when",[function(t){s||(s=!0,c.resolve(i(t)))}])}),a.promiseDispatch(void 0,"when",[void 0,function(t){var n,e=!1;try{n=u(t)}catch(r){if(e=!0,!l.onerror)throw r;l.onerror(r)}e||c.notify(n)}]),c.promise},l.tap=function(t,n){return l(t).tap(n)},v.prototype.tap=function(t){return t=l(t),this.then(function(n){return t.fcall(n).thenResolve(n)})},l.when=y,v.prototype.thenResolve=function(t){return this.then(function(){return t})},l.thenResolve=function(t,n){return l(t).thenResolve(n)},v.prototype.thenReject=function(t){return this.then(function(){throw t})},l.thenReject=function(t,n){return l(t).thenReject(n)},l.nearer=m,l.isPromise=g,l.isPromiseAlike=b,l.isPending=w,v.prototype.isPending=function(){return"pending"===this.inspect().state},l.isFulfilled=k,v.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},l.isRejected=_,v.prototype.isRejected=function(){return"rejected"===this.inspect().state};var on=[],un=[],an=!0;l.resetUnhandledRejections=j,l.getUnhandledReasons=function(){return on.slice()},l.stopUnhandledRejectionTracking=function(){j(),an=!1},j(),l.reject=T,l.fulfill=E,l.master=O,l.spread=R,v.prototype.spread=function(t,n){return this.all().then(function(n){return t.apply(void 0,n)},n)},l.async=N,l.spawn=A,l["return"]=M,l.promised=D,l.dispatch=I,v.prototype.dispatch=function(t,n){var e=this,r=p();return l.nextTick(function(){e.promiseDispatch(r.resolve,t,n)}),r.promise},l.get=function(t,n){return l(t).dispatch("get",[n])},v.prototype.get=function(t){return this.dispatch("get",[t])},l.set=function(t,n,e){return l(t).dispatch("set",[n,e])},v.prototype.set=function(t,n){return this.dispatch("set",[t,n])},l.del=l["delete"]=function(t,n){return l(t).dispatch("delete",[n])},v.prototype.del=v.prototype["delete"]=function(t){return this.dispatch("delete",[t])},l.mapply=l.post=function(t,n,e){return l(t).dispatch("post",[n,e])},v.prototype.mapply=v.prototype.post=function(t,n){return this.dispatch("post",[t,n])},l.send=l.mcall=l.invoke=function(t,n){return l(t).dispatch("post",[n,K(arguments,2)])},v.prototype.send=v.prototype.mcall=v.prototype.invoke=function(t){return this.dispatch("post",[t,K(arguments,1)])},l.fapply=function(t,n){return l(t).dispatch("apply",[void 0,n])},v.prototype.fapply=function(t){return this.dispatch("apply",[void 0,t])},l["try"]=l.fcall=function(t){return l(t).dispatch("apply",[void 0,K(arguments,1)])},v.prototype.fcall=function(){return this.dispatch("apply",[void 0,K(arguments)])},l.fbind=function(t){var n=l(t),e=K(arguments,1);return function(){return n.dispatch("apply",[this,e.concat(K(arguments))])}},v.prototype.fbind=function(){var t=this,n=K(arguments);return function(){return t.dispatch("apply",[this,n.concat(K(arguments))])}},l.keys=function(t){return l(t).dispatch("keys",[])},v.prototype.keys=function(){return this.dispatch("keys",[])},l.all=z,v.prototype.all=function(){return z(this)},l.allResolved=f(B,"allResolved","allSettled"),v.prototype.allResolved=function(){return B(this)},l.allSettled=L,v.prototype.allSettled=function(){return this.then(function(t){return z(X(t,function(t){function n(){return t.inspect()}return t=l(t),t.then(n,n)}))})},l.fail=l["catch"]=function(t,n){return l(t).then(void 0,n)},v.prototype.fail=v.prototype["catch"]=function(t){return this.then(void 0,t)},l.progress=P,v.prototype.progress=function(t){return this.then(void 0,void 0,t)},l.fin=l["finally"]=function(t,n){return l(t)["finally"](n)},v.prototype.fin=v.prototype["finally"]=function(t){return t=l(t),this.then(function(n){return t.fcall().then(function(){return n})},function(n){return t.fcall().then(function(){throw n})})},l.done=function(t,n,e,r){return l(t).done(n,e,r)},v.prototype.done=function(t,e,r){var i=function(t){l.nextTick(function(){if(o(t,u),!l.onerror)throw t;l.onerror(t)})},u=t||e||r?this.then(t,e,r):this;"object"==typeof n&&n&&n.domain&&(i=n.domain.bind(i)),u.then(void 0,i)},l.timeout=function(t,n,e){return l(t).timeout(n,e)},v.prototype.timeout=function(t,n){var e=p(),r=setTimeout(function(){n&&"string"!=typeof n||(n=new Error(n||"Timed out after "+t+" ms"),n.code="ETIMEDOUT"),e.reject(n)},t);return this.then(function(t){clearTimeout(r),e.resolve(t)},function(t){clearTimeout(r),e.reject(t)},e.notify),e.promise},l.delay=function(t,n){return void 0===n&&(n=t,t=void 0),l(t).delay(n)},v.prototype.delay=function(t){return this.then(function(n){var e=p();return setTimeout(function(){e.resolve(n)},t),e.promise})},l.nfapply=function(t,n){return l(t).nfapply(n)},v.prototype.nfapply=function(t){var n=p(),e=K(t);return e.push(n.makeNodeResolver()),this.fapply(e).fail(n.reject),n.promise},l.nfcall=function(t){var n=K(arguments,1);return l(t).nfapply(n)},v.prototype.nfcall=function(){var t=K(arguments),n=p();return t.push(n.makeNodeResolver()),this.fapply(t).fail(n.reject),n.promise},l.nfbind=l.denodeify=function(t){var n=K(arguments,1);return function(){var e=n.concat(K(arguments)),r=p();return e.push(r.makeNodeResolver()),l(t).fapply(e).fail(r.reject),r.promise}},v.prototype.nfbind=v.prototype.denodeify=function(){var t=K(arguments);return t.unshift(this),l.denodeify.apply(void 0,t)},l.nbind=function(t,n){var e=K(arguments,2);return function(){function r(){return t.apply(n,arguments)}var o=e.concat(K(arguments)),i=p();return o.push(i.makeNodeResolver()),l(r).fapply(o).fail(i.reject),i.promise}},v.prototype.nbind=function(){var t=K(arguments,0);return t.unshift(this),l.nbind.apply(void 0,t)},l.nmapply=l.npost=function(t,n,e){return l(t).npost(n,e)},v.prototype.nmapply=v.prototype.npost=function(t,n){var e=K(n||[]),r=p();return e.push(r.makeNodeResolver()),this.dispatch("post",[t,e]).fail(r.reject),r.promise},l.nsend=l.nmcall=l.ninvoke=function(t,n){var e=K(arguments,2),r=p();return e.push(r.makeNodeResolver()),l(t).dispatch("post",[n,e]).fail(r.reject),r.promise},v.prototype.nsend=v.prototype.nmcall=v.prototype.ninvoke=function(t){var n=K(arguments,1),e=p();return n.push(e.makeNodeResolver()),this.dispatch("post",[t,n]).fail(e.reject),e.promise},l.nodeify=q,v.prototype.nodeify=function(t){return t?void this.then(function(n){l.nextTick(function(){t(null,n)})},function(n){l.nextTick(function(){t(n)})}):this};var cn=s();return l})}).call(this,n("_process"))},{_process:1}],5:[function(t,n){function e(t,n){var e;return e=n?new o(t,n):new o(t)}var r=function(){return this}(),o=r.WebSocket||r.MozWebSocket;n.exports=o?e:null,o&&(e.prototype=o.prototype)},{}],6:[function(t,n){n.exports={getAccessToken:function(){return"xxwmn93p0h"}}},{}],7:[function(t,n){var e,r,o,i;o=t("./protocol"),r=t("./really-error"),i=t("lodash"),e=function(){function t(){this.tag=0,this._callbacks={}}var n;return t.prototype.handle=function(t){var n,e;if(!(t.tag in this._callbacks))throw new r("A message with this tag: "+t.tag+" doesn't exist");if(e=t.tag,o.isErrorMessage(t))try{this._callbacks[e].error.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your error callback")}else try{this._callbacks[e].success.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your success callback")}try{this._callbacks[e].complete.call(null,t)}catch(i){throw n=i,new r("Error happened when trying to execute your complete callback")}return delete this._callbacks[e]},t.prototype.add=function(t){var e,r,o,u,a;return null==t&&(t={}),o=t.kind,u=t.success,r=t.error,e=t.complete,null==o&&(o="default"),null==u&&(u=i.noop),null==r&&(r=i.noop),null==e&&(e=i.noop),a=n.call(this),this._callbacks[a]={kind:o,success:u,error:r,complete:e},a},n=function(){return this.tag+=1},t}(),n.exports=e},{"./protocol":10,"./really-error":13,lodash:3}],8:[function(t,n){var e,r,o,i,u,a;a=t("./protocol"),i=t("q"),e=t("component-emitter"),o=t("./logger"),u=new o,r=function(){function t(t,n,e){if(this.websocket=t,this.interval=null!=n?n:5e3,this.timeout=null!=e?e:5e3,!this.websocket)throw Error("websocket should be passed");u.debug("Heartbeat: initialize with interval: "+this.interval+" and timeout: "+this.timeout)}var n;return t.prototype.start=function(){return n.call(this),u.debug("Heartbeat: started interval: "+this.interval+" timeout: "+this.timeout)},n=function(){var t,e,r,o;return e=a.heartbeatMessage(),r=this.websocket.send(e),o=function(t){return function(e){var r,o;return o=Date.now(),r=.001*(o-e.timestamp),u.debug("Heartbeat: lag "+r+" second(s)"),i.delay(t.interval).then(function(){return u.debug("Heartbeat interval: "+t.interval+" timeout: "+t.timeout),n.call(t)})}}(this),t=function(t){return function(n){return u.debug("Heartbeat: lag exceed",n),t.stop()}}(this),r.timeout(this.interval+this.timeout).then(o,t)},t.prototype.stop=function(){return this.websocket.socket.close(),this.websocket.emit("heartbeat:lag")},t}(),n.exports=r},{"./logger":9,"./protocol":10,"component-emitter":2,q:4}],9:[function(t,n){var e,r,o=[].slice;r=t("lodash"),e=function(){function t(){}return t.prototype.debug=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Debug::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.debug)&&n.apply(console,t),t},t.prototype.info=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Info::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.log)&&n.apply(console,t),t},t.prototype.warn=function(){var t,n;return t=1<=arguments.length?o.call(arguments,0):[],t.unshift("Really::Warn::"),"undefined"!=typeof console&&null!==console&&null!=(n=console.warn)&&n.apply(console,t),t},t.prototype.error=function(){var t,n,e,i,u,a;return t=1<=arguments.length?o.call(arguments,0):[],u="Really::Error::",r.isObject(t[0])&&(n=t[0].code,i=t[0].message,e=t[0].errorName,u=""+u+e+"::"+n+":: "+i,t.shift()),t.unshift(u),"undefined"!=typeof console&&null!==console&&null!=(a=console.error)&&a.apply(console,t),t},t}(),n.exports=e},{lodash:3}],10:[function(t,n){var e,r,o,i,u=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};i=t("lodash"),o=t("./authenticator"),e=t("./really-error"),r="0",n.exports={clientVersion:r,commands:{init:"initialization",create:"create",read:"read",get:"get",update:"update","delete":"delete",heartbeat:"poke",subscribe:"subscribe",unsubscribe:"unsubscribe"},initializationMessage:function(t){if(!i.isString(t))throw new e("You should pass accessToken parameter as String");return{kind:"initialization",data:{cmd:this.commands.init,accessToken:t}}},createMessage:function(t,n){var r;if(!i.isString(t))throw new e("You should pass a resource parameter as String");if(!i.isObject(n)&&!i.isUndefined(n))throw new e("You should pass a body parameter as Object");return r={kind:"create",data:{cmd:this.commands.create,r:t}},n&&(r.body=n),r},readMessage:function(t,n){var r,o,u,a,c,s;r=i.omit(n,function(t){return void 0===t}),c={fields:{valid:i.isArray,message:'You should pass Array for "fields" option'},query:{valid:function(t){return i.isObject(t)&&(i.isString(t.filter)||i.isObject(t.values))},message:'You should pass Object for "query" option'},limit:{valid:i.isNumber,message:'You should pass Number for "limit" option'},skip:{valid:i.isNumber,message:'You should pass Number for "skip" option'},sort:{valid:i.isString,message:'You should pass String for "sort" option'},token:{valid:i.isString,message:'You should pass String for "token" option'},includeTotalCount:{valid:i.isBoolean,message:'You should pass Boolean for "includeTotalCount" option'},paginationToken:{valid:i.isString,message:'You should pass String for "paginationToken" option'},subscribe:{valid:i.isBoolean,message:'You should pass Boolean for "subscribe" option'}};for(a in r){if(s=r[a],!(a in c))throw new e('The option "'+a+"\" isn't supported");if(o=c[a],!o.valid(s))throw new e(o.message)}return u={kind:"read",data:{cmd:this.commands.read,r:t}},r&&(u.data.cmdOpts=r),u},getMessage:function(t,n){var r;if(!i.isArray(n))throw new e("You should pass array or nothing for fields option");return r={kind:"get",data:{cmd:this.commands.get,r:t}},n&&(r.data.cmdOpts={fields:n}),r},updateMessage:function(t,n,r){var o,a,c,s,f,l;if(!(i.isArray(r)&&r.length>0))throw new e("You should pass at least one operation");for(c=["set","addNumber","push","addToSet","insertAt","pull","removeAt"],s=0,f=r.length;f>s;s++)if(a=r[s],l=a.op,u.call(c,l)<0)throw new e('"'+a.op+'" operation you passed is not supported');return o={kind:"update",data:{cmd:this.commands.update,rev:n,r:t,body:{ops:r}}}},deleteMessage:function(t){if(!i.isString(t))throw new e("You should pass a resource parameter as String");return{kind:"delete",data:{cmd:this.commands["delete"],r:t}}},subscribeMessage:function(t){var n,r,o,u;if(!i.isPlainObject(t)&&!i.isArray(t))throw new e("subscription(s) should be either Object or Array of Objects");for(i.isArray(t)||(t=[t]),o=0,u=t.length;u>o;o++)if(r=t[o],!i.isNumber(r.rev)||!i.isString(r.res))throw new e("You must pass string resource and number revision for subscription object");return n={kind:"subscribe",data:{cmd:this.commands.subscribe,subscriptions:t}}},unsubscribeMessage:function(t){var n,r,o,u;if(!i.isPlainObject(t)&&!i.isArray(t))throw new e("subscription(s) should be either Object or Array of Objects");for(i.isArray(t)||(t=[t]),o=0,u=t.length;u>o;o++)if(r=t[o],!i.isNumber(r.rev)||!i.isString(r.res))throw new e("You must pass string resource and number revision for subscription object");return n={kind:"unsubscribe",data:{cmd:this.commands.unsubscribe,subscriptions:t}}},heartbeatMessage:function(){var t;return t=Date.now(),{kind:"poke",data:{cmd:this.commands.heartbeat,timestamp:t}}},isErrorMessage:function(t){return i.has(t,"error")}}},{"./authenticator":6,"./really-error":13,lodash:3}],11:[function(t,n){var e;e=t("./really-error"),n.exports={handle:function(t,n){var r,o;switch(null==n&&(n={}),o=n.r,r=n.evt,r){case"updated":case"deleted":return t.object.emit(""+o+":"+r,n);case"created":return t.collection.emit(""+o+":"+r,n);case"kicked":case"revoked":return t.emit(r,n);default:throw new e("Unknown event: "+r)}}}},{"./really-error":13}],12:[function(t,n){var e,r,o,i,u,a;a=t("lodash"),u=t("./protocol"),i=t("./really-error"),e=t("component-emitter"),a=t("lodash"),r=t("q"),o=function(){function t(t){this.channel=t,e(this)}return t.prototype.create=function(t,n){var e,o,c,s,f,l,p;if(null==n&&(n={}),!a.isString(t))throw new i("Can not be initialized without resource");o=new r.defer,p=n.onSuccess,l=n.onError,f=n.onComplete,e=n.body;try{s=u.createMessage(t,e)}catch(h){return c=h,setTimeout(function(){return o.reject(c)},0),o.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype.read=function(t,n){var e,o,c,s,f,l,p;if(null==n&&(n={}),!a.isString(t))throw new i("Can not be initialized without resource");e=new r.defer,l=n.onSuccess,f=n.onError,s=n.onComplete,p=a.omit(n,["onSuccess","onError","onComplete"]);try{c=u.readMessage(t,p)}catch(h){return o=h,setTimeout(function(){return e.reject(o)},0),e.promise}return this.channel.send(c,{success:l,error:f,complete:s})},t.prototype.onCreate=function(t,n){return this.on(""+t+":created",function(t){return n(t)})},t}(),n.exports=o},{"./protocol":10,"./really-error":13,"component-emitter":2,lodash:3,q:4}],13:[function(t,n){var e,r={}.hasOwnProperty,o=function(t,n){function e(){this.constructor=t}for(var o in n)r.call(n,o)&&(t[o]=n[o]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};e=function(t){function n(t){this.message=null!=t?t:"Unknown Error","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,n),this.name="ReallyError"}return o(n,t),n}(Error),n.exports=e},{}],14:[function(t,n){var e,r,o,i,u,a;u=t("./protocol"),o=t("./really-error"),e=t("component-emitter"),a=t("lodash"),r=t("q"),i=function(){function t(t){this.channel=t,e(this)}return t.prototype.get=function(t,n){var e,i,c,s,f,l,p;if(!a.isString(t))throw new o("Can not be initialized without resource");e=new r.defer,c=n.fields,p=n.onSuccess,l=n.onError,f=n.onComplete;try{s=u.getMessage(t,c)}catch(h){return i=h,setTimeout(function(){return e.reject(i)},0),e.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype.update=function(t,n,e){var i,c,s,f,l,p,h;if(!a.isString(t))throw new o("Can not be initialized without resource");if(i=new r.defer,!e)return i.reject(new o("Can't be called without passing arguments")),i.promise;h=e.ops,p=e.onSuccess,l=e.onError,f=e.onComplete;try{s=u.updateMessage(t,h)}catch(d){return c=d,setTimeout(function(){return i.reject(c)},0),i.promise}return this.channel.send(s,{success:p,error:l,complete:f})},t.prototype["delete"]=function(t,n){var e,r,i,c;if(!a.isString(t))throw new o("Can not be initialized without resource");return c=n.onSuccess,i=n.onError,r=n.onComplete,e=u.deleteMessage(t),this.channel.send(e,{success:c,error:i,complete:r})},t.prototype.onUpdate=function(t,n){return this.on(""+t+":updated",function(t){return n(t)})},t.prototype.onDelete=function(t,n){return this.on(""+t+":deleted",function(t){return n(t)})},t}(),n.exports=i},{"./protocol":10,"./really-error":13,"component-emitter":2,lodash:3,q:4}],15:[function(t,n){var e,r,o,i,u,a,c,s;a=t("./transports/webSocket"),u=t("./really-object"),o=t("./really-collection"),i=t("./really-error"),s=t("lodash"),e=t("./push-handler"),c={},r=function(){function t(t,n,r){if(!t||!n)throw new i("Can't initialize Really without passing domain and access token");if(!s.isString(t)||!s.isString(n))throw new i("Only values are allowed for domain and access token");return c[t]?(this.object=c[t].object,this.collection=c[t].collection,this.transport=c[t].transport):(c[t]={},this.transport=new a(t,n,r),this.transport.connect(),c[t].transport=this.transport,this.object=c[t].object=new u(this.transport),this.collection=c[t].collection=new o(this.transport),this.transport.on("message",function(t){return function(n){return s.has(n,"tag")?void 0:e.handle(t,n)}}(this))),this}return t}(),n.exports=r},{"./push-handler":11,"./really-collection":12,"./really-error":13,"./really-object":14,"./transports/webSocket":17,lodash:3}],16:[function(t,n){var e;e=function(){function t(t){this.url=t}return t.prototype.connect=function(){return void 0},t.prototype.disconnect=function(){return void 0},t.prototype.send=function(){return void 0},t.prototype.isConnected=function(){return void 0},t.prototype.on=function(){return void 0},t}(),n.exports=e},{}],17:[function(t,n){var e,r,o,i,u,a,c,s,f,l,p,h,d,v={}.hasOwnProperty,y=function(t,n){function e(){this.constructor=t}for(var r in n)v.call(n,r)&&(t[r]=n[r]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};d=t("lodash"),s=t("../transport"),c=t("../really-error"),f=t("ws"),h=t("../protocol"),r=t("component-emitter"),e=t("../callbacks-buffer"),u=t("../push-handler"),a=t("q"),o=t("../heartbeat"),i=t("../logger"),p=new i,l=function(t){function n(t,n,r){var o;this.domain=t,this.accessToken=n,this.options=null!=r?r:{},this.socket=null,this.callbacksBuffer=new e,this._messagesBuffer=[],this.pushHandler=u,this.initialized=!1,this.url=""+t+"/v"+h.clientVersion+"/socket",o={reconnectionMaxTimeout:3e4,heartbeatTimeout:2e3,heartbeatInterval:5e3,reconnect:!0,onDisconnect:"buffer"},this.options=d.defaults(this.options,o)}var i,s,l;return y(n,t),r(n.prototype),i=function(t){return this.socket.addEventListener("open",function(n){return function(){return n.attempts=0,t.resolve(),l.call(n),n.emit("opened")}}(this)),this.socket.addEventListener("close",function(t){return function(){return t.options.reconnect?(t.emit("reconnecting"),t.reconnect(t.options.reconnectionMaxTimeout)):(t.emit("closed"),t.disconnect())}}(this)),this.socket.addEventListener("error",function(t){return function(){return t.emit("error")}}(this)),this.socket.addEventListener("message",function(t){return function(n){var e;return e=JSON.parse(n.data),d.has(e,"tag")&&t.callbacksBuffer.handle(e),t.emit("message",e)}}(this))},n.prototype.send=function(t,n,e){var r,o,i,u,s,f;return null==n&&(n={}),null==e&&(e=a.defer()),this.isConnected()?(i=t.kind,s=function(t){return"function"==typeof n.success&&n.success(t),e.resolve(t)},o=function(t){return"function"==typeof n.error&&n.error(t),e.reject(t)},r=function(t){return"function"==typeof n.complete?n.complete(t):void 0},t.data.tag=this.callbacksBuffer.add({kind:i,success:s,error:o,complete:r}),this.socket.send(JSON.stringify(t.data)),e.promise):(u=d.isFunction(this.options.onDisconnect)?"custom":this.options.onDisconnect,f=function(r){return function(o){var i,u,a,s,f;null==o&&(o="fail"),s=function(){return e.reject(new c("Connection to the server is not established"))},i=function(){return r._messagesBuffer.push({message:t,options:n,deferred:e})},u=function(){var t;try{return r.options.onDisconnect(r,r._messagesBuffer,c)}catch(n){throw t=n,new c("error invoking custom callback")}},f={fail:s,buffer:i,custom:u};try{return f[o]()}catch(l){if(a=l,a instanceof c)throw a;throw new c("Strategy not found")}}}(this),f(u),e.promise)},l=function(){var t,n,e;return e=function(t){return function(n){var e;return t.initialized=!0,d.flush.call(t),e=new o(t,t.options.heartbeatInterval,t.options.heartbeatTimeout),e.start(),t.emit("initialized",n)}}(this),t=function(t){return function(n){return t.initialized=!1,t.emit("initializationError",n)}}(this),n=h.initializationMessage(this.accessToken),this.send(n,{success:e,error:t})},n.prototype.connect=function(t){return null==t&&(t=a.defer()),this.socket=new f(this.url),this.socket.addEventListener("error",d.once(function(){return void 0})),i.call(this,t),t.promise},n.prototype.reconnect=function(t){return this.attempts+=1,this.connect().timeout(t)["catch"](function(){return t=generateTimeout(t),reconnect(t)})},d.flush=function(){return setTimeout(function(t){return function(){var n,e,r,o,i,u,a,c;for(u=t._messagesBuffer,c=[],o=0,i=u.length;i>o;o++)a=u[o],e=a.message,r=a.options,n=a.deferred,c.push(t.send(e,r,n));return c}}(this),0)},n.prototype.isConnected=function(){return this.socket?this.socket.readyState===this.socket.OPEN:!1},n.prototype.isConnecting=function(){return this.socket?this.socket.readyState===this.socket.CONNECTING:!1},s=function(){return this.off()},n.prototype.disconnect=function(){var t;return s.call(this),null!=(t=this.socket)&&t.close(),this.socket=null,this.initialized=!1},n}(s),n.exports=l},{"../callbacks-buffer":7,"../heartbeat":8,"../logger":9,"../protocol":10,"../push-handler":11,"../really-error":13,"../transport":16,"component-emitter":2,lodash:3,q:4,ws:5}]},{},[15])(15)}); \ No newline at end of file diff --git a/dist/really.js b/dist/really.js index 956b6ee..7ef9428 100644 --- a/dist/really.js +++ b/dist/really.js @@ -2,7 +2,7 @@ * Really.js v0.0.1 * Copyright (C) 2014-2015 Really Inc. * - * Date: Tue Jan 06 2015 17:38:48 + * Date: Sun Jan 18 2015 17:08:07 */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Really=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o - logger.debug "Heartbeat: initialize with interval: #{interval} and timeout: #{timeout}" + constructor: (@websocket, @interval = 5e3, @timeout = 5e3) -> + throw Error('websocket should be passed') unless @websocket + + logger.debug "Heartbeat: initialize with interval: #{@interval} and timeout: #{@timeout}" + - start: (@websocket) -> + start: () -> _ping.call(this) logger.debug "Heartbeat: started interval: #{@interval} timeout: #{@timeout}" - + _ping = () -> message = protocol.heartbeatMessage() pingPromise = @websocket.send message success = (data) => now = Date.now() + console.log data.timestamp lag = (now - data.timestamp) * 0.001 logger.debug "Heartbeat: lag #{lag} second(s)" Q.delay(@interval).then => logger.debug "Heartbeat interval: #{@interval} timeout: #{@timeout}" _ping.call(this) - error = () -> - logger.debug 'Heartbeat: lag exceed' - @websocket.disconnect() + error = (error) => + logger.debug 'Heartbeat: lag exceed', error + @stop() pingPromise.timeout(@interval + @timeout).then success, error + stop: () -> + @websocket.socket.close() + @websocket.emit 'heartbeat:lag' + + module.exports = Heartbeat - diff --git a/src/protocol.coffee b/src/protocol.coffee index 9b0c1d5..ea30c5f 100644 --- a/src/protocol.coffee +++ b/src/protocol.coffee @@ -11,7 +11,7 @@ module.exports = clientVersion: VERSION commands: - init: 'init' + init: 'initialization' create: 'create' read: 'read' get: 'get' diff --git a/tests/heartbeat-spec.coffee b/tests/heartbeat-spec.coffee new file mode 100644 index 0000000..38febd2 --- /dev/null +++ b/tests/heartbeat-spec.coffee @@ -0,0 +1,118 @@ +Heartbeat = require('../src/heartbeat') +protocol = require '../src/protocol' +Q = require 'q' + +describe 'Heartbeat', -> + websocket = + send: (message) -> + deferred = Q.defer() + return deferred.promise + + describe 'initialization', -> + it 'should set default interval time and timeout when no parameter passed', -> + heartbeat = new Heartbeat(websocket) + expect(heartbeat.interval).toEqual 5e3 + expect(heartbeat.timeout).toEqual 5e3 + + it 'should take websocket as a parameter', -> + expect -> + heartbeat = new Heartbeat() + .toThrow Error('websocket should be passed') + + describe 'start', -> + it 'should create heartbeat message', -> + heartbeat = new Heartbeat(websocket) + spyOn(protocol, 'heartbeatMessage').and.callFake -> + message = + heartbeat: true + + heartbeat.start(websocket) + expect(protocol.heartbeatMessage).toHaveBeenCalled() + + it 'should send heartbeat message', -> + heartbeat = new Heartbeat(websocket) + spyOn(heartbeat.websocket, 'send').and.callFake -> + deferred = Q.defer() + return deferred.promise + + heartbeat.start() + expect(heartbeat.websocket.send).toHaveBeenCalledWith jasmine.any(Object) + + + it 'should raise promise success when resolved', (done) -> + heartbeat = new Heartbeat(websocket,1000,1000) + spyOn(heartbeat.websocket, 'send').and.callFake () -> + deferred = Q.defer() + deferred.resolve + timestamp: 123 + return deferred.promise + + heartbeat.start() + setTimeout( () -> + expect(heartbeat.websocket.send.calls.count()).toEqual 2 + done() + , 1500) + + it 'should raise promise error when timeout', (done) -> + heartbeat = new Heartbeat(websocket, 1000, 1000) + spyOn(heartbeat, 'stop').and.callThrough() + heartbeat.start() + + setTimeout( () -> + expect(heartbeat.stop).toHaveBeenCalled() + done() + , 2500) + + it 'should raise promise error when rejected', (done) -> + websocket = + send: (message) -> + deferred = Q.defer() + deferred.reject 'ERROR' + return deferred.promise + + heartbeat = new Heartbeat(websocket, 1000, 1000) + + spyOn(heartbeat, 'stop') + + heartbeat.start() + setTimeout( () -> + expect(heartbeat.stop).toHaveBeenCalled() + done() + , 0) + + describe 'stop', -> + it 'should close websocket', (done) -> + websocket = + send: (message) -> + deferred = Q.defer() + deferred.reject 'ERROR' + return deferred.promise + socket: + close: () -> true + + heartbeat = new Heartbeat(websocket, 1000, 1000) + spyOn(heartbeat.websocket.socket, 'close') + heartbeat.start() + setTimeout( () -> + expect(heartbeat.websocket.socket.close).toHaveBeenCalled() + done() + , 0) + + it 'should fire event on websocket', (done) -> + websocket = + emit: (msg) -> true + send: (message) -> + deferred = Q.defer() + deferred.reject 'ERROR' + return deferred.promise + socket: + close: () -> true + + + heartbeat = new Heartbeat(websocket, 1000, 1000) + spyOn(heartbeat.websocket, 'emit') + heartbeat.start() + setTimeout( () -> + expect(heartbeat.websocket.emit).toHaveBeenCalled() + done() + , 0) \ No newline at end of file diff --git a/tests/protocol-spec.coffee b/tests/protocol-spec.coffee index e97fd2e..53c3de9 100644 --- a/tests/protocol-spec.coffee +++ b/tests/protocol-spec.coffee @@ -22,7 +22,7 @@ describe 'protocol', -> expect(message).toEqual kind: 'initialization' data: - cmd: 'init' + cmd: 'initialization' accessToken: 'xxwmn93p0h' describe 'createMessage', ->