rxjs-rails 2.3.22 → 2.3.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +178 -146
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1706 -1156
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +4 -4
  7. data/vendor/assets/javascripts/rx.all.js +1529 -1125
  8. data/vendor/assets/javascripts/rx.all.min.js +4 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +15 -79
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +15 -79
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.js +38 -15
  14. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.binding.js +42 -54
  16. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.coincidence.js +6 -6
  18. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  19. data/vendor/assets/javascripts/rx.compat.js +1234 -828
  20. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  21. data/vendor/assets/javascripts/rx.experimental.js +12 -6
  22. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  23. data/vendor/assets/javascripts/rx.joinpatterns.js +15 -11
  24. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  25. data/vendor/assets/javascripts/rx.js +1159 -791
  26. data/vendor/assets/javascripts/rx.lite.compat.js +1264 -920
  27. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  28. data/vendor/assets/javascripts/rx.lite.extras.js +99 -27
  29. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  30. data/vendor/assets/javascripts/rx.lite.js +1192 -886
  31. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  32. data/vendor/assets/javascripts/rx.min.js +2 -2
  33. data/vendor/assets/javascripts/rx.testing.js +64 -63
  34. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  35. data/vendor/assets/javascripts/rx.time.js +32 -35
  36. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  37. metadata +3 -3
@@ -1,4 +1,4 @@
1
1
  /* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
2
- (function(a){function b(){if(this.isDisposed)throw new Error(Z)}function c(a,b){if($&&b.stack&&"object"==typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(cb)){for(var c=[],e=b;e;e=e.source)e.stack&&c.unshift(e.stack);c.unshift(a.stack);var f=c.join("\n"+cb+"\n");a.stack=d(f)}}function d(a){for(var b=a.split("\n"),c=[],d=0,g=b.length;g>d;d++){var h=b[d];e(h)||f(h)||!h||c.push(h)}return c.join("\n")}function e(a){var b=h(a);if(!b)return!1;var c=b[0],d=b[1];return c===ab&&d>=bb&&Oc>=d}function f(a){return-1!==a.indexOf("(module.js:")||-1!==a.indexOf("(node.js:")}function g(){if($)try{throw new Error}catch(a){var b=a.stack.split("\n"),c=b[0].indexOf("@")>0?b[1]:b[2],d=h(c);if(!d)return;return ab=d[0],d[1]}}function h(a){var b=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(a);if(b)return[b[1],Number(b[2])];var c=/at ([^ ]+):(\d+):(?:\d+)$/.exec(a);if(c)return[c[1],Number(c[2])];var d=/.*@(.+):(\d+)$/.exec(a);return d?[d[1],Number(d[2])]:void 0}function i(a){var b=typeof a;return a&&("function"==b||"object"==b)||!1}function j(a){var b=[];if(!i(a))return b;Cb.nonEnumArgs&&a.length&&Db(a)&&(a=Fb.call(a));var c=Cb.enumPrototypes&&"function"==typeof a,d=Cb.enumErrorProps&&(a===wb||a instanceof Error);for(var e in a)c&&"prototype"==e||d&&("message"==e||"name"==e)||b.push(e);if(Cb.nonEnumShadows&&a!==xb){var f=a.constructor,g=-1,h=Ab.length;if(a===(f&&f.prototype))var j=a===yb?sb:a===wb?nb:tb.call(a),k=Bb[j];for(;++g<h;)e=Ab[g],k&&k[e]||!ub.call(a,e)||b.push(e)}return b}function k(a,b,c){for(var d=-1,e=c(a),f=e.length;++d<f;){var g=e[d];if(b(a[g],g,a)===!1)break}return a}function l(a,b){return k(a,b,j)}function m(a){return"function"!=typeof a.toString&&"string"==typeof(a+"")}function n(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;var e=typeof a,f=typeof b;if(a===a&&(null==a||null==b||"function"!=e&&"object"!=e&&"function"!=f&&"object"!=f))return!1;var g=tb.call(a),h=tb.call(b);if(g==jb&&(g=qb),h==jb&&(h=qb),g!=h)return!1;switch(g){case lb:case mb:return+a==+b;case pb:return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case rb:case sb:return a==String(b)}var i=g==kb;if(!i){if(g!=qb||!Cb.nodeClass&&(m(a)||m(b)))return!1;var j=!Cb.argsObject&&Db(a)?Object:a.constructor,k=!Cb.argsObject&&Db(b)?Object:b.constructor;if(!(j==k||ub.call(a,"constructor")&&ub.call(b,"constructor")||X(j)&&j instanceof j&&X(k)&&k instanceof k||!("constructor"in a&&"constructor"in b)))return!1}c||(c=[]),d||(d=[]);for(var o=c.length;o--;)if(c[o]==a)return d[o]==b;var p=0,q=!0;if(c.push(a),d.push(b),i){if(o=a.length,p=b.length,q=p==o)for(;p--;){var r=b[p];if(!(q=n(a[p],r,c,d)))break}}else l(b,function(b,e,f){return ub.call(f,e)?(p++,q=ub.call(a,e)&&n(a[e],b,c,d)):void 0}),q&&l(a,function(a,b,c){return ub.call(c,b)?q=--p>-1:void 0});return c.pop(),d.pop(),q}function o(a,b){return 1===a.length&&Array.isArray(a[b])?a[b]:Fb.call(a)}function p(a,b){for(var c=new Array(a),d=0;a>d;d++)c[d]=b();return c}function q(a,b){this.id=a,this.value=b}function r(a,b){this.scheduler=a,this.disposable=b,this.isDisposed=!1}function t(){this._s=s}function u(){this._s=s,this._l=s.length,this._i=0}function v(a){this._a=a}function w(a){this._a=a,this._l=A(a),this._i=0}function x(a){return"number"==typeof a&&J.isFinite(a)}function y(b){var c,d=b[db];if(!d&&"string"==typeof b)return c=new t(b),c[db]();if(!d&&b.length!==a)return c=new v(b),c[db]();if(!d)throw new TypeError("Object is not iterable");return b[db]()}function z(a){var b=+a;return 0===b?b:isNaN(b)?b:0>b?-1:1}function A(a){var b=+a.length;return isNaN(b)?0:0!==b&&x(b)?(b=z(b)*Math.floor(Math.abs(b)),0>=b?0:b>yc?yc:b):b}function B(a,b){return Q(a)||(a=$b),new Jc(function(c){var d=0,e=b.length;return a.scheduleRecursive(function(a){e>d?(c.onNext(b[d++]),a()):c.onCompleted()})})}function C(a,b){return new Jc(function(c){var d=new Sb,e=new Tb;return e.setDisposable(d),d.setDisposable(a.subscribe(c.onNext.bind(c),function(a){var d,f;try{f=b(a)}catch(g){return void c.onError(g)}W(f)&&(f=vc(f)),d=new Sb,e.setDisposable(d),d.setDisposable(f.subscribe(c))},c.onCompleted.bind(c))),e},a)}function D(a,b){var c=this;return new Jc(function(d){var e=0,f=a.length;return c.subscribe(function(c){if(f>e){var g,h=a[e++];try{g=b(c,h)}catch(i){return void d.onError(i)}d.onNext(g)}else d.onCompleted()},d.onError.bind(d),d.onCompleted.bind(d))},c)}function E(a,b,c){return a.map(function(d,e){var f=b.call(c,d,e,a);return W(f)&&(f=vc(f)),(gb(f)||fb(f))&&(f=zc(f)),f}).concatAll()}function F(a,b,c){for(var d=0,e=a.length;e>d;d++)if(c(a[d],b))return d;return-1}function G(a){this.comparer=a,this.set=[]}function H(a,b,c){return a.map(function(d,e){var f=b.call(c,d,e,a);return W(f)&&(f=vc(f)),(gb(f)||fb(f))&&(f=zc(f)),f}).mergeAll()}var I={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},J=I[typeof window]&&window||this,K=I[typeof exports]&&exports&&!exports.nodeType&&exports,L=I[typeof module]&&module&&!module.nodeType&&module,M=L&&L.exports===K&&K,N=I[typeof global]&&global;!N||N.global!==N&&N.window!==N||(J=N);var O={internals:{},config:{Promise:J.Promise},helpers:{}},P=O.helpers.noop=function(){},Q=(O.helpers.notDefined=function(a){return"undefined"==typeof a},O.helpers.isScheduler=function(a){return a instanceof O.Scheduler}),R=O.helpers.identity=function(a){return a},S=(O.helpers.pluck=function(a){return function(b){return b[a]}},O.helpers.just=function(a){return function(){return a}},O.helpers.defaultNow=function(){return Date.now?Date.now:function(){return+new Date}}()),T=O.helpers.defaultComparer=function(a,b){return Eb(a,b)},U=O.helpers.defaultSubComparer=function(a,b){return a>b?1:b>a?-1:0},V=(O.helpers.defaultKeySerializer=function(a){return a.toString()},O.helpers.defaultError=function(a){throw a}),W=O.helpers.isPromise=function(a){return!!a&&"function"==typeof a.then},X=(O.helpers.asArray=function(){return Array.prototype.slice.call(arguments)},O.helpers.not=function(a){return!a},O.helpers.isFunction=function(){var a=function(a){return"function"==typeof a||!1};return a(/x/)&&(a=function(a){return"function"==typeof a&&"[object Function]"==tb.call(a)}),a}()),Y="Argument out of range",Z="Object has been disposed";O.config.longStackSupport=!1;var $=!1;try{throw new Error}catch(_){$=!!_.stack}var ab,bb=g(),cb="From previous event:",db="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";J.Set&&"function"==typeof(new J.Set)["@@iterator"]&&(db="@@iterator");var eb=O.doneEnumerator={done:!0,value:a},fb=O.helpers.isIterable=function(b){return b[db]!==a},gb=O.helpers.isArrayLike=function(b){return b&&b.length!==a};O.helpers.iterator=db;var hb,ib=O.helpers.deprecate=function(){},jb="[object Arguments]",kb="[object Array]",lb="[object Boolean]",mb="[object Date]",nb="[object Error]",ob="[object Function]",pb="[object Number]",qb="[object Object]",rb="[object RegExp]",sb="[object String]",tb=Object.prototype.toString,ub=Object.prototype.hasOwnProperty,vb=tb.call(arguments)==jb,wb=Error.prototype,xb=Object.prototype,yb=String.prototype,zb=xb.propertyIsEnumerable;zb||(zb=xb.propertyIsEnumerable=function(a){for(var b in this)if(b===a)return!0;return!1});try{hb=!(tb.call(document)==qb&&!({toString:0}+""))}catch(_){hb=!0}var Ab=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Bb={};Bb[kb]=Bb[mb]=Bb[pb]={constructor:!0,toLocaleString:!0,toString:!0,valueOf:!0},Bb[lb]=Bb[sb]={constructor:!0,toString:!0,valueOf:!0},Bb[nb]=Bb[ob]=Bb[rb]={constructor:!0,toString:!0},Bb[qb]={constructor:!0};var Cb={};!function(){var a=function(){this.x=1},b=[];a.prototype={valueOf:1,y:1};for(var c in new a)b.push(c);for(c in arguments);Cb.enumErrorProps=zb.call(wb,"message")||zb.call(wb,"name"),Cb.enumPrototypes=zb.call(a,"prototype"),Cb.nonEnumArgs=0!=c,Cb.nonEnumShadows=!/valueOf/.test(b)}(1);var Db=function(a){return a&&"object"==typeof a?tb.call(a)==jb:!1};vb||(Db=function(a){return a&&"object"==typeof a?ub.call(a,"callee"):!1});var Eb=O.internals.isEqual=function(a,b){return n(a,b,[],[])},Fb=Array.prototype.slice,Gb=({}.hasOwnProperty,this.inherits=O.internals.inherits=function(a,b){function c(){this.constructor=a}c.prototype=b.prototype,a.prototype=new c}),Hb=O.internals.addProperties=function(a){for(var b=Fb.call(arguments,1),c=0,d=b.length;d>c;c++){var e=b[c];for(var f in e)a[f]=e[f]}},Ib=O.internals.addRef=function(a,b){return new Jc(function(c){return new Nb(b.getDisposable(),a.subscribe(c))})};Function.prototype.bind||(Function.prototype.bind=function(a){var b=this,c=Fb.call(arguments,1),d=function(){function e(){}if(this instanceof d){e.prototype=b.prototype;var f=new e,g=b.apply(f,c.concat(Fb.call(arguments)));return Object(g)===g?g:f}return b.apply(a,c.concat(Fb.call(arguments)))};return d}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;if(null==this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;f>d;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}});var Jb=Object("a"),Kb="a"!=Jb[0]||!(0 in Jb);Array.prototype.every||(Array.prototype.every=function(a){var b=Object(this),c=Kb&&{}.toString.call(this)==sb?this.split(""):b,d=c.length>>>0,e=arguments[1];if({}.toString.call(a)!=ob)throw new TypeError(a+" is not a function");for(var f=0;d>f;f++)if(f in c&&!a.call(e,c[f],f,b))return!1;return!0}),Array.prototype.map||(Array.prototype.map=function(a){var b=Object(this),c=Kb&&{}.toString.call(this)==sb?this.split(""):b,d=c.length>>>0,e=Array(d),f=arguments[1];if({}.toString.call(a)!=ob)throw new TypeError(a+" is not a function");for(var g=0;d>g;g++)g in c&&(e[g]=a.call(f,c[g],g,b));return e}),Array.prototype.filter||(Array.prototype.filter=function(a){for(var b,c=[],d=new Object(this),e=0,f=d.length>>>0;f>e;e++)b=d[e],e in d&&a.call(arguments[1],b,e,d)&&c.push(b);return c}),Array.isArray||(Array.isArray=function(a){return{}.toString.call(a)==kb}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!==d?d=0:0!==d&&1/0!=d&&d!==-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),q.prototype.compareTo=function(a){var b=this.value.compareTo(a.value);return 0===b&&(b=this.id-a.id),b};var Lb=O.internals.PriorityQueue=function(a){this.items=new Array(a),this.length=0},Mb=Lb.prototype;Mb.isHigherPriority=function(a,b){return this.items[a].compareTo(this.items[b])<0},Mb.percolate=function(a){if(!(a>=this.length||0>a)){var b=a-1>>1;if(!(0>b||b===a)&&this.isHigherPriority(a,b)){var c=this.items[a];this.items[a]=this.items[b],this.items[b]=c,this.percolate(b)}}},Mb.heapify=function(a){if(+a||(a=0),!(a>=this.length||0>a)){var b=2*a+1,c=2*a+2,d=a;if(b<this.length&&this.isHigherPriority(b,d)&&(d=b),c<this.length&&this.isHigherPriority(c,d)&&(d=c),d!==a){var e=this.items[a];this.items[a]=this.items[d],this.items[d]=e,this.heapify(d)}}},Mb.peek=function(){return this.items[0].value},Mb.removeAt=function(a){this.items[a]=this.items[--this.length],delete this.items[this.length],this.heapify()},Mb.dequeue=function(){var a=this.peek();return this.removeAt(0),a},Mb.enqueue=function(a){var b=this.length++;this.items[b]=new q(Lb.count++,a),this.percolate(b)},Mb.remove=function(a){for(var b=0;b<this.length;b++)if(this.items[b].value===a)return this.removeAt(b),!0;return!1},Lb.count=0;var Nb=O.CompositeDisposable=function(){this.disposables=o(arguments,0),this.isDisposed=!1,this.length=this.disposables.length},Ob=Nb.prototype;Ob.add=function(a){this.isDisposed?a.dispose():(this.disposables.push(a),this.length++)},Ob.remove=function(a){var b=!1;if(!this.isDisposed){var c=this.disposables.indexOf(a);-1!==c&&(b=!0,this.disposables.splice(c,1),this.length--,a.dispose())}return b},Ob.dispose=function(){if(!this.isDisposed){this.isDisposed=!0;var a=this.disposables.slice(0);this.disposables=[],this.length=0;for(var b=0,c=a.length;c>b;b++)a[b].dispose()}},Ob.toArray=function(){return this.disposables.slice(0)};var Pb=O.Disposable=function(a){this.isDisposed=!1,this.action=a||P};Pb.prototype.dispose=function(){this.isDisposed||(this.action(),this.isDisposed=!0)};var Qb=Pb.create=function(a){return new Pb(a)},Rb=Pb.empty={dispose:P},Sb=O.SingleAssignmentDisposable=function(){function a(){this.isDisposed=!1,this.current=null}var b=a.prototype;return b.getDisposable=function(){return this.current},b.setDisposable=function(a){var b,c=this.isDisposed;c||(b=this.current,this.current=a),b&&b.dispose(),c&&a&&a.dispose()},b.dispose=function(){var a;this.isDisposed||(this.isDisposed=!0,a=this.current,this.current=null),a&&a.dispose()},a}(),Tb=O.SerialDisposable=Sb,Ub=O.RefCountDisposable=function(){function a(a){this.disposable=a,this.disposable.count++,this.isInnerDisposed=!1}function b(a){this.underlyingDisposable=a,this.isDisposed=!1,this.isPrimaryDisposed=!1,this.count=0}return a.prototype.dispose=function(){this.disposable.isDisposed||this.isInnerDisposed||(this.isInnerDisposed=!0,this.disposable.count--,0===this.disposable.count&&this.disposable.isPrimaryDisposed&&(this.disposable.isDisposed=!0,this.disposable.underlyingDisposable.dispose()))},b.prototype.dispose=function(){this.isDisposed||this.isPrimaryDisposed||(this.isPrimaryDisposed=!0,0===this.count&&(this.isDisposed=!0,this.underlyingDisposable.dispose()))},b.prototype.getDisposable=function(){return this.isDisposed?Rb:new a(this)},b}();r.prototype.dispose=function(){var a=this;this.scheduler.schedule(function(){a.isDisposed||(a.isDisposed=!0,a.disposable.dispose())})};var Vb=O.internals.ScheduledItem=function(a,b,c,d,e){this.scheduler=a,this.state=b,this.action=c,this.dueTime=d,this.comparer=e||U,this.disposable=new Sb};Vb.prototype.invoke=function(){this.disposable.setDisposable(this.invokeCore())},Vb.prototype.compareTo=function(a){return this.comparer(this.dueTime,a.dueTime)},Vb.prototype.isCancelled=function(){return this.disposable.isDisposed},Vb.prototype.invokeCore=function(){return this.action(this.scheduler,this.state)};var Wb=O.Scheduler=function(){function a(a,b,c,d){this.now=a,this._schedule=b,this._scheduleRelative=c,this._scheduleAbsolute=d}function b(a,b){return b(),Rb}var c=a.prototype;return c.schedule=function(a){return this._schedule(a,b)},c.scheduleWithState=function(a,b){return this._schedule(a,b)},c.scheduleWithRelative=function(a,c){return this._scheduleRelative(c,a,b)},c.scheduleWithRelativeAndState=function(a,b,c){return this._scheduleRelative(a,b,c)},c.scheduleWithAbsolute=function(a,c){return this._scheduleAbsolute(c,a,b)},c.scheduleWithAbsoluteAndState=function(a,b,c){return this._scheduleAbsolute(a,b,c)},a.now=S,a.normalize=function(a){return 0>a&&(a=0),a},a}(),Xb=Wb.normalize;!function(a){function b(a,b){var c=b.first,d=b.second,e=new Nb,f=function(b){d(b,function(b){var c=!1,d=!1,g=a.scheduleWithState(b,function(a,b){return c?e.remove(g):d=!0,f(b),Rb});d||(e.add(g),c=!0)})};return f(c),e}function c(a,b,c){var d=b.first,e=b.second,f=new Nb,g=function(b){e(b,function(b,d){var e=!1,h=!1,i=a[c].call(a,b,d,function(a,b){return e?f.remove(i):h=!0,g(b),Rb});h||(f.add(i),e=!0)})};return g(d),f}function d(a,b){a(function(c){b(a,c)})}a.scheduleRecursive=function(a){return this.scheduleRecursiveWithState(a,function(a,b){a(function(){b(a)})})},a.scheduleRecursiveWithState=function(a,c){return this.scheduleWithState({first:a,second:c},b)},a.scheduleRecursiveWithRelative=function(a,b){return this.scheduleRecursiveWithRelativeAndState(b,a,d)},a.scheduleRecursiveWithRelativeAndState=function(a,b,d){return this._scheduleRelative({first:a,second:d},b,function(a,b){return c(a,b,"scheduleWithRelativeAndState")})},a.scheduleRecursiveWithAbsolute=function(a,b){return this.scheduleRecursiveWithAbsoluteAndState(b,a,d)},a.scheduleRecursiveWithAbsoluteAndState=function(a,b,d){return this._scheduleAbsolute({first:a,second:d},b,function(a,b){return c(a,b,"scheduleWithAbsoluteAndState")})}}(Wb.prototype),function(){Wb.prototype.schedulePeriodic=function(a,b){return this.schedulePeriodicWithState(null,a,b)},Wb.prototype.schedulePeriodicWithState=function(a,b,c){if("undefined"==typeof J.setInterval)throw new Error("Periodic scheduling not supported.");var d=a,e=J.setInterval(function(){d=c(d)},b);return Qb(function(){J.clearInterval(e)})}}(Wb.prototype),function(a){a.catchError=a["catch"]=function(a){return new dc(this,a)}}(Wb.prototype);var Yb,Zb=(O.internals.SchedulePeriodicRecursive=function(){function a(a,b){b(0,this._period);try{this._state=this._action(this._state)}catch(c){throw this._cancel.dispose(),c}}function b(a,b,c,d){this._scheduler=a,this._state=b,this._period=c,this._action=d}return b.prototype.start=function(){var b=new Sb;return this._cancel=b,b.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0,this._period,a.bind(this))),b},b}(),Wb.immediate=function(){function a(a,b){return b(this,a)}function b(a,b,c){for(var d=Xb(b);d-this.now()>0;);return c(this,a)}function c(a,b,c){return this.scheduleWithRelativeAndState(a,b-this.now(),c)}return new Wb(S,a,b,c)}()),$b=Wb.currentThread=function(){function a(a){for(var b;a.length>0;)if(b=a.dequeue(),!b.isCancelled()){for(;b.dueTime-Wb.now()>0;);b.isCancelled()||b.invoke()}}function b(a,b){return this.scheduleWithRelativeAndState(a,0,b)}function c(b,c,d){var f=this.now()+Wb.normalize(c),g=new Vb(this,b,d,f);if(e)e.enqueue(g);else{e=new Lb(4),e.enqueue(g);try{a(e)}catch(h){throw h}finally{e=null}}return g.disposable}function d(a,b,c){return this.scheduleWithRelativeAndState(a,b-this.now(),c)}var e,f=new Wb(S,b,c,d);return f.scheduleRequired=function(){return!e},f.ensureTrampoline=function(a){e?a():this.schedule(a)},f}(),_b=P,ac=function(){var a,b=P;if("WScript"in this)a=function(a,b){WScript.Sleep(b),a()};else{if(!J.setTimeout)throw new Error("No concurrency detected!");a=J.setTimeout,b=J.clearTimeout}return{setTimeout:a,clearTimeout:b}}(),bc=ac.setTimeout,cc=ac.clearTimeout;!function(){function a(){if(!J.postMessage||J.importScripts)return!1;var a=!1,b=J.onmessage;return J.onmessage=function(){a=!0},J.postMessage("","*"),J.onmessage=b,a}var b=RegExp("^"+String(tb).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$"),c="function"==typeof(c=N&&M&&N.setImmediate)&&!b.test(c)&&c,d="function"==typeof(d=N&&M&&N.clearImmediate)&&!b.test(d)&&d;if("function"==typeof c)Yb=c,_b=d;else if("undefined"!=typeof process&&"[object process]"==={}.toString.call(process))Yb=process.nextTick;else if(a()){var e="ms.rx.schedule"+Math.random(),f={},g=0,h=function(a){if("string"==typeof a.data&&a.data.substring(0,e.length)===e){var b=a.data.substring(e.length),c=f[b];c(),delete f[b]}};J.addEventListener?J.addEventListener("message",h,!1):J.attachEvent("onmessage",h,!1),Yb=function(a){var b=g++;f[b]=a,J.postMessage(e+b,"*")}}else if(J.MessageChannel){var i=new J.MessageChannel,j={},k=0;i.port1.onmessage=function(a){var b=a.data,c=j[b];c(),delete j[b]},Yb=function(a){var b=k++;j[b]=a,i.port2.postMessage(b)}}else"document"in J&&"onreadystatechange"in J.document.createElement("script")?Yb=function(a){var b=J.document.createElement("script");b.onreadystatechange=function(){a(),b.onreadystatechange=null,b.parentNode.removeChild(b),b=null},J.document.documentElement.appendChild(b)}:(Yb=function(a){return bc(a,0)},_b=cc)}();var dc=(Wb.timeout=function(){function a(a,b){var c=this,d=new Sb,e=Yb(function(){d.isDisposed||d.setDisposable(b(c,a))});return new Nb(d,Qb(function(){_b(e)}))}function b(a,b,c){var d=this,e=Wb.normalize(b);if(0===e)return d.scheduleWithState(a,c);var f=new Sb,g=bc(function(){f.isDisposed||f.setDisposable(c(d,a))},e);return new Nb(f,Qb(function(){cc(g)}))}function c(a,b,c){return this.scheduleWithRelativeAndState(a,b-this.now(),c)}return new Wb(S,a,b,c)}(),function(a){function b(a,b){return this._scheduler.scheduleWithState(a,this._wrap(b))}function c(a,b,c){return this._scheduler.scheduleWithRelativeAndState(a,b,this._wrap(c))}function d(a,b,c){return this._scheduler.scheduleWithAbsoluteAndState(a,b,this._wrap(c))}function e(e,f){this._scheduler=e,this._handler=f,this._recursiveOriginal=null,this._recursiveWrapper=null,a.call(this,this._scheduler.now.bind(this._scheduler),b,c,d)}return Gb(e,a),e.prototype._clone=function(a){return new e(a,this._handler)},e.prototype._wrap=function(a){var b=this;return function(c,d){try{return a(b._getRecursiveWrapper(c),d)}catch(e){if(!b._handler(e))throw e;return Rb}}},e.prototype._getRecursiveWrapper=function(a){if(this._recursiveOriginal!==a){this._recursiveOriginal=a;var b=this._clone(a);b._recursiveOriginal=a,b._recursiveWrapper=b,this._recursiveWrapper=b}return this._recursiveWrapper},e.prototype.schedulePeriodicWithState=function(a,b,c){var d=this,e=!1,f=new Sb;return f.setDisposable(this._scheduler.schedulePeriodicWithState(a,b,function(a){if(e)return null;try{return c(a)}catch(b){if(e=!0,!d._handler(b))throw b;return f.dispose(),null}})),f},e}(Wb)),ec=O.Notification=function(){function a(a,b){this.hasValue=null==b?!1:b,this.kind=a}return a.prototype.accept=function(a,b,c){return a&&"object"==typeof a?this._acceptObservable(a):this._accept(a,b,c)},a.prototype.toObservable=function(a){var b=this;return Q(a)||(a=Zb),new Jc(function(c){return a.schedule(function(){b._acceptObservable(c),"N"===b.kind&&c.onCompleted()})})},a}(),fc=ec.createOnNext=function(){function a(a){return a(this.value)}function b(a){return a.onNext(this.value)}function c(){return"OnNext("+this.value+")"}return function(d){var e=new ec("N",!0);return e.value=d,e._accept=a,e._acceptObservable=b,e.toString=c,e}}(),gc=ec.createOnError=function(){function a(a,b){return b(this.exception)}function b(a){return a.onError(this.exception)}function c(){return"OnError("+this.exception+")"}return function(d){var e=new ec("E");return e.exception=d,e._accept=a,e._acceptObservable=b,e.toString=c,e}}(),hc=ec.createOnCompleted=function(){function a(a,b,c){return c()}function b(a){return a.onCompleted()}function c(){return"OnCompleted()"}return function(){var d=new ec("C");return d._accept=a,d._acceptObservable=b,d.toString=c,d}}(),ic=O.internals.Enumerator=function(a){this._next=a};ic.prototype.next=function(){return this._next()},ic.prototype[db]=function(){return this};var jc=O.internals.Enumerable=function(a){this._iterator=a};jc.prototype[db]=function(){return this._iterator()},jc.prototype.concat=function(){var a=this;return new Jc(function(b){var c;try{c=a[db]()}catch(d){return void b.onError(d)}var e,f=new Tb,g=Zb.scheduleRecursive(function(a){var d;if(!e){try{d=c.next()}catch(g){return void b.onError(g)}if(d.done)return void b.onCompleted();var h=d.value;W(h)&&(h=vc(h));var i=new Sb;f.setDisposable(i),i.setDisposable(h.subscribe(b.onNext.bind(b),b.onError.bind(b),function(){a()}))}});return new Nb(f,g,Qb(function(){e=!0}))})},jc.prototype.catchError=function(){var a=this;return new Jc(function(b){var c;try{c=a[db]()}catch(d){return void b.onError(d)}var e,f,g=new Tb,h=Zb.scheduleRecursive(function(a){if(!e){var d;try{d=c.next()}catch(h){return void b.onError(h)}if(d.done)return void(f?b.onError(f):b.onCompleted());var i=d.value;W(i)&&(i=vc(i));var j=new Sb;g.setDisposable(j),j.setDisposable(i.subscribe(b.onNext.bind(b),function(b){f=b,a()},b.onCompleted.bind(b)))}});return new Nb(g,h,Qb(function(){e=!0}))})};var kc=jc.repeat=function(a,b){return null==b&&(b=-1),new jc(function(){var c=b;return new ic(function(){return 0===c?eb:(c>0&&c--,{done:!1,value:a})})})},lc=jc.of=function(a,b,c){return b||(b=R),new jc(function(){var d=-1;return new ic(function(){return++d<a.length?{done:!1,value:b.call(c,a[d],d,a)}:eb})})},mc=O.Observer=function(){};mc.prototype.toNotifier=function(){var a=this;return function(b){return b.accept(a)}},mc.prototype.asObserver=function(){return new qc(this.onNext.bind(this),this.onError.bind(this),this.onCompleted.bind(this))},mc.prototype.checked=function(){return new rc(this)};var nc=mc.create=function(a,b,c){return a||(a=P),b||(b=V),c||(c=P),new qc(a,b,c)};mc.fromNotifier=function(a,b){return new qc(function(c){return a.call(b,fc(c))},function(c){return a.call(b,gc(c))},function(){return a.call(b,hc())})},mc.prototype.notifyOn=function(a){return new tc(a,this)};var oc,pc=O.internals.AbstractObserver=function(a){function b(){this.isStopped=!1,a.call(this)}return Gb(b,a),b.prototype.onNext=function(a){this.isStopped||this.next(a)},b.prototype.onError=function(a){this.isStopped||(this.isStopped=!0,this.error(a))},b.prototype.onCompleted=function(){this.isStopped||(this.isStopped=!0,this.completed())},b.prototype.dispose=function(){this.isStopped=!0},b.prototype.fail=function(a){return this.isStopped?!1:(this.isStopped=!0,this.error(a),!0)},b}(mc),qc=O.AnonymousObserver=function(a){function b(b,c,d){a.call(this),this._onNext=b,this._onError=c,this._onCompleted=d}return Gb(b,a),b.prototype.next=function(a){this._onNext(a)},b.prototype.error=function(a){this._onError(a)},b.prototype.completed=function(){this._onCompleted()},b}(pc),rc=function(a){function b(b){a.call(this),this._observer=b,this._state=0}Gb(b,a);var c=b.prototype;return c.onNext=function(a){this.checkAccess();try{this._observer.onNext(a)}catch(b){throw b}finally{this._state=0}},c.onError=function(a){this.checkAccess();try{this._observer.onError(a)}catch(b){throw b}finally{this._state=2}},c.onCompleted=function(){this.checkAccess();try{this._observer.onCompleted()}catch(a){throw a}finally{this._state=2}},c.checkAccess=function(){if(1===this._state)throw new Error("Re-entrancy detected");if(2===this._state)throw new Error("Observer completed");0===this._state&&(this._state=1)},b}(mc),sc=O.internals.ScheduledObserver=function(a){function b(b,c){a.call(this),this.scheduler=b,this.observer=c,this.isAcquired=!1,this.hasFaulted=!1,this.queue=[],this.disposable=new Tb}return Gb(b,a),b.prototype.next=function(a){var b=this;this.queue.push(function(){b.observer.onNext(a)})},b.prototype.error=function(a){var b=this;this.queue.push(function(){b.observer.onError(a)})},b.prototype.completed=function(){var a=this;this.queue.push(function(){a.observer.onCompleted()})},b.prototype.ensureActive=function(){var a=!1,b=this;!this.hasFaulted&&this.queue.length>0&&(a=!this.isAcquired,this.isAcquired=!0),a&&this.disposable.setDisposable(this.scheduler.scheduleRecursive(function(a){var c;if(!(b.queue.length>0))return void(b.isAcquired=!1);c=b.queue.shift();try{c()}catch(d){throw b.queue=[],b.hasFaulted=!0,d}a()}))},b.prototype.dispose=function(){a.prototype.dispose.call(this),this.disposable.dispose()},b}(pc),tc=function(a){function b(b,c,d){a.call(this,b,c),this._cancel=d}return Gb(b,a),b.prototype.next=function(b){a.prototype.next.call(this,b),this.ensureActive()},b.prototype.error=function(b){a.prototype.error.call(this,b),this.ensureActive()},b.prototype.completed=function(){a.prototype.completed.call(this),this.ensureActive()},b.prototype.dispose=function(){a.prototype.dispose.call(this),this._cancel&&this._cancel.dispose(),this._cancel=null},b}(sc),uc=O.Observable=function(){function a(a){if(O.config.longStackSupport&&$){try{throw new Error}catch(b){this.stack=b.stack.substring(b.stack.indexOf("\n")+1)}var d=this;this._subscribe=function(b){var e=b.onError.bind(b);return b.onError=function(a){c(a,d),e(a)},a(b)}}else this._subscribe=a}return oc=a.prototype,oc.subscribe=oc.forEach=function(a,b,c){return this._subscribe("object"==typeof a?a:nc(a,b,c))},oc.subscribeOnNext=function(a,b){return this._subscribe(nc(2===arguments.length?function(c){a.call(b,c)}:a))},oc.subscribeOnError=function(a,b){return this._subscribe(nc(null,2===arguments.length?function(c){a.call(b,c)}:a))},oc.subscribeOnCompleted=function(a,b){return this._subscribe(nc(null,null,2===arguments.length?function(){a.call(b)}:a))},a}();oc.observeOn=function(a){var b=this;return new Jc(function(c){return b.subscribe(new tc(a,c))},b)},oc.subscribeOn=function(a){var b=this;return new Jc(function(c){var d=new Sb,e=new Tb;return e.setDisposable(d),d.setDisposable(a.schedule(function(){e.setDisposable(new r(a,b.subscribe(c)))})),e},b)};var vc=uc.fromPromise=function(a){return wc(function(){var b=new O.AsyncSubject;return a.then(function(a){b.onNext(a),b.onCompleted()},b.onError.bind(b)),b})};oc.toPromise=function(a){if(a||(a=O.config.Promise),!a)throw new TypeError("Promise type not provided nor in Rx.config.Promise");var b=this;return new a(function(a,c){var d,e=!1;b.subscribe(function(a){d=a,e=!0},c,function(){e&&a(d)})})},oc.toArray=function(){var a=this;return new Jc(function(b){var c=[];return a.subscribe(c.push.bind(c),b.onError.bind(b),function(){b.onNext(c),b.onCompleted()})},a)},uc.create=uc.createWithDisposable=function(a,b){return new Jc(a,b)};var wc=uc.defer=function(a){return new Jc(function(b){var c;try{c=a()}catch(d){return Dc(d).subscribe(b)}return W(c)&&(c=vc(c)),c.subscribe(b)})},xc=uc.empty=function(a){return Q(a)||(a=Zb),new Jc(function(b){return a.schedule(function(){b.onCompleted()})})},yc=Math.pow(2,53)-1;t.prototype[db]=function(){return new u(this._s)},u.prototype[db]=function(){return this},u.prototype.next=function(){if(this._i<this._l){var a=this._s.charAt(this._i++);return{done:!1,value:a}}return eb},v.prototype[db]=function(){return new w(this._a)},w.prototype[db]=function(){return this},w.prototype.next=function(){if(this._i<this._l){var a=this._a[this._i++];return{done:!1,value:a}}return eb};var zc=uc.from=function(a,b,c,d){if(null==a)throw new Error("iterable cannot be null.");if(b&&!X(b))throw new Error("mapFn when provided must be a function");Q(d)||(d=$b);var e=Object(a),f=y(e);return new Jc(function(a){var e=0;return d.scheduleRecursive(function(d){var g;try{g=f.next()}catch(h){return void a.onError(h)}if(g.done)return void a.onCompleted();var i=g.value;if(b&&X(b))try{i=b.call(c,i,e)}catch(h){return void a.onError(h)}a.onNext(i),e++,d()})})},Ac=uc.fromArray=function(a,b){return ib("fromArray","from"),Q(b)||(b=$b),new Jc(function(c){var d=0,e=a.length;return b.scheduleRecursive(function(b){e>d?(c.onNext(a[d++]),b()):c.onCompleted()})})};uc.generate=function(a,b,c,d,e){return Q(e)||(e=$b),new Jc(function(f){var g=!0,h=a;return e.scheduleRecursive(function(a){var e,i;try{g?g=!1:h=c(h),e=b(h),e&&(i=d(h))}catch(j){return void f.onError(j)}e?(f.onNext(i),a()):f.onCompleted()})})};var Bc=uc.never=function(){return new Jc(function(){return Rb})};uc.of=function(){return B(null,arguments)},uc.ofWithScheduler=function(a){return B(a,Fb.call(arguments,1))},uc.range=function(a,b,c){return Q(c)||(c=$b),new Jc(function(d){return c.scheduleRecursiveWithState(0,function(c,e){b>c?(d.onNext(a+c),e(c+1)):d.onCompleted()})})},uc.repeat=function(a,b,c){return Q(c)||(c=$b),Cc(a,c).repeat(null==b?-1:b)};var Cc=uc["return"]=uc.just=function(a,b){return Q(b)||(b=Zb),new Jc(function(c){return b.schedule(function(){c.onNext(a),c.onCompleted()})})};uc.returnValue=function(){return ib("returnValue","return or just"),Cc.apply(null,arguments)};var Dc=uc["throw"]=uc.throwException=uc.throwError=function(a,b){return Q(b)||(b=Zb),new Jc(function(c){return b.schedule(function(){c.onError(a)})})};uc.using=function(a,b){return new Jc(function(c){var d,e,f=Rb;try{d=a(),d&&(f=d),e=b(d)}catch(g){return new Nb(Dc(g).subscribe(c),f)}return new Nb(e.subscribe(c),f)})},oc.amb=function(a){var b=this;return new Jc(function(c){function d(){f||(f=g,j.dispose())}function e(){f||(f=h,i.dispose())}var f,g="L",h="R",i=new Sb,j=new Sb;return W(a)&&(a=vc(a)),i.setDisposable(b.subscribe(function(a){d(),f===g&&c.onNext(a)},function(a){d(),f===g&&c.onError(a)},function(){d(),f===g&&c.onCompleted()})),j.setDisposable(a.subscribe(function(a){e(),f===h&&c.onNext(a)},function(a){e(),f===h&&c.onError(a)},function(){e(),f===h&&c.onCompleted()})),new Nb(i,j)})},uc.amb=function(){function a(a,b){return a.amb(b)}for(var b=Bc(),c=o(arguments,0),d=0,e=c.length;e>d;d++)b=a(b,c[d]);return b},oc["catch"]=oc.catchError=function(a){return"function"==typeof a?C(this,a):Ec([this,a])},oc.catchException=function(a){return ib("catchException","catch or catchError"),this.catchError(a)
3
- };var Ec=uc.catchError=uc["catch"]=function(){return lc(o(arguments,0)).catchError()};uc.catchException=function(){return ib("catchException","catch or catchError"),Ec.apply(null,arguments)},oc.combineLatest=function(){var a=Fb.call(arguments);return Array.isArray(a[0])?a[0].unshift(this):a.unshift(this),Fc.apply(this,a)};var Fc=uc.combineLatest=function(){var a=Fb.call(arguments),b=a.pop();return Array.isArray(a[0])&&(a=a[0]),new Jc(function(c){function d(a){var d;if(h[a]=!0,i||(i=h.every(R))){try{d=b.apply(null,k)}catch(e){return void c.onError(e)}c.onNext(d)}else j.filter(function(b,c){return c!==a}).every(R)&&c.onCompleted()}function e(a){j[a]=!0,j.every(R)&&c.onCompleted()}for(var f=function(){return!1},g=a.length,h=p(g,f),i=!1,j=p(g,f),k=new Array(g),l=new Array(g),m=0;g>m;m++)!function(b){var f=a[b],g=new Sb;W(f)&&(f=vc(f)),g.setDisposable(f.subscribe(function(a){k[b]=a,d(b)},c.onError.bind(c),function(){e(b)})),l[b]=g}(m);return new Nb(l)},this)};oc.concat=function(){var a=Fb.call(arguments,0);return a.unshift(this),Gc.apply(this,a)};var Gc=uc.concat=function(){return lc(o(arguments,0)).concat()};oc.concatAll=function(){return this.merge(1)},oc.concatObservable=function(){return ib("concatObservable","concatAll"),this.merge(1)},oc.merge=function(a){if("number"!=typeof a)return Hc(this,a);var b=this;return new Jc(function(c){function d(a){var b=new Sb;f.add(b),W(a)&&(a=vc(a)),b.setDisposable(a.subscribe(c.onNext.bind(c),c.onError.bind(c),function(){f.remove(b),h.length>0?d(h.shift()):(e--,g&&0===e&&c.onCompleted())}))}var e=0,f=new Nb,g=!1,h=[];return f.add(b.subscribe(function(b){a>e?(e++,d(b)):h.push(b)},c.onError.bind(c),function(){g=!0,0===e&&c.onCompleted()})),f},b)};var Hc=uc.merge=function(){var a,b;return arguments[0]?Q(arguments[0])?(a=arguments[0],b=Fb.call(arguments,1)):(a=Zb,b=Fb.call(arguments,0)):(a=Zb,b=Fb.call(arguments,1)),Array.isArray(b[0])&&(b=b[0]),B(a,b).mergeAll()};oc.mergeAll=function(){var a=this;return new Jc(function(b){var c=new Nb,d=!1,e=new Sb;return c.add(e),e.setDisposable(a.subscribe(function(a){var e=new Sb;c.add(e),W(a)&&(a=vc(a)),e.setDisposable(a.subscribe(b.onNext.bind(b),b.onError.bind(b),function(){c.remove(e),d&&1===c.length&&b.onCompleted()}))},b.onError.bind(b),function(){d=!0,1===c.length&&b.onCompleted()})),c},a)},oc.mergeObservable=function(){return ib("mergeObservable","mergeAll"),this.mergeAll.apply(this,arguments)},oc.onErrorResumeNext=function(a){if(!a)throw new Error("Second observable is required");return Ic([this,a])};var Ic=uc.onErrorResumeNext=function(){var a=o(arguments,0);return new Jc(function(b){var c=0,d=new Tb,e=Zb.scheduleRecursive(function(e){var f,g;c<a.length?(f=a[c++],W(f)&&(f=vc(f)),g=new Sb,d.setDisposable(g),g.setDisposable(f.subscribe(b.onNext.bind(b),e,e))):b.onCompleted()});return new Nb(d,e)})};oc.skipUntil=function(a){var b=this;return new Jc(function(c){var d=!1,e=new Nb(b.subscribe(function(a){d&&c.onNext(a)},c.onError.bind(c),function(){d&&c.onCompleted()}));W(a)&&(a=vc(a));var f=new Sb;return e.add(f),f.setDisposable(a.subscribe(function(){d=!0,f.dispose()},c.onError.bind(c),function(){f.dispose()})),e},b)},oc["switch"]=oc.switchLatest=function(){var a=this;return new Jc(function(b){var c=!1,d=new Tb,e=!1,f=0,g=a.subscribe(function(a){var g=new Sb,h=++f;c=!0,d.setDisposable(g),W(a)&&(a=vc(a)),g.setDisposable(a.subscribe(function(a){f===h&&b.onNext(a)},function(a){f===h&&b.onError(a)},function(){f===h&&(c=!1,e&&b.onCompleted())}))},b.onError.bind(b),function(){e=!0,!c&&b.onCompleted()});return new Nb(g,d)},a)},oc.takeUntil=function(a){var b=this;return new Jc(function(c){return W(a)&&(a=vc(a)),new Nb(b.subscribe(c),a.subscribe(c.onCompleted.bind(c),c.onError.bind(c),P))},b)},oc.zip=function(){if(Array.isArray(arguments[0]))return D.apply(this,arguments);var a=this,b=Fb.call(arguments),c=b.pop();return b.unshift(a),new Jc(function(d){function e(b){var e,f;if(h.every(function(a){return a.length>0})){try{f=h.map(function(a){return a.shift()}),e=c.apply(a,f)}catch(g){return void d.onError(g)}d.onNext(e)}else i.filter(function(a,c){return c!==b}).every(R)&&d.onCompleted()}function f(a){i[a]=!0,i.every(function(a){return a})&&d.onCompleted()}for(var g=b.length,h=p(g,function(){return[]}),i=p(g,function(){return!1}),j=new Array(g),k=0;g>k;k++)!function(a){var c=b[a],g=new Sb;W(c)&&(c=vc(c)),g.setDisposable(c.subscribe(function(b){h[a].push(b),e(a)},d.onError.bind(d),function(){f(a)})),j[a]=g}(k);return new Nb(j)},a)},uc.zip=function(){var a=Fb.call(arguments,0),b=a.shift();return b.zip.apply(b,a)},uc.zipArray=function(){var a=o(arguments,0);return new Jc(function(b){function c(a){if(f.every(function(a){return a.length>0})){var c=f.map(function(a){return a.shift()});b.onNext(c)}else if(g.filter(function(b,c){return c!==a}).every(R))return void b.onCompleted()}function d(a){return g[a]=!0,g.every(R)?void b.onCompleted():void 0}for(var e=a.length,f=p(e,function(){return[]}),g=p(e,function(){return!1}),h=new Array(e),i=0;e>i;i++)!function(e){h[e]=new Sb,h[e].setDisposable(a[e].subscribe(function(a){f[e].push(a),c(e)},b.onError.bind(b),function(){d(e)}))}(i);var j=new Nb(h);return j.add(Qb(function(){for(var a=0,b=f.length;b>a;a++)f[a]=[]})),j})},oc.asObservable=function(){return new Jc(this.subscribe.bind(this),this)},oc.bufferWithCount=function(a,b){return"number"!=typeof b&&(b=a),this.windowWithCount(a,b).selectMany(function(a){return a.toArray()}).where(function(a){return a.length>0})},oc.dematerialize=function(){var a=this;return new Jc(function(b){return a.subscribe(function(a){return a.accept(b)},b.onError.bind(b),b.onCompleted.bind(b))},this)},oc.distinctUntilChanged=function(a,b){var c=this;return a||(a=R),b||(b=T),new Jc(function(d){var e,f=!1;return c.subscribe(function(c){var g,h=!1;try{g=a(c)}catch(i){return void d.onError(i)}if(f)try{h=b(e,g)}catch(i){return void d.onError(i)}f&&h||(f=!0,e=g,d.onNext(c))},d.onError.bind(d),d.onCompleted.bind(d))},this)},oc["do"]=oc.tap=function(a,b,c){var d,e=this;return"function"==typeof a?d=a:(d=a.onNext.bind(a),b=a.onError.bind(a),c=a.onCompleted.bind(a)),new Jc(function(a){return e.subscribe(function(b){try{d(b)}catch(c){a.onError(c)}a.onNext(b)},function(c){if(b)try{b(c)}catch(d){a.onError(d)}a.onError(c)},function(){if(c)try{c()}catch(b){a.onError(b)}a.onCompleted()})},this)},oc.doAction=function(){return ib("doAction","do or tap"),this.tap.apply(this,arguments)},oc.doOnNext=oc.tapOnNext=function(a,b){return this.tap(2===arguments.length?function(c){a.call(b,c)}:a)},oc.doOnError=oc.tapOnError=function(a,b){return this.tap(P,2===arguments.length?function(c){a.call(b,c)}:a)},oc.doOnCompleted=oc.tapOnCompleted=function(a,b){return this.tap(P,null,2===arguments.length?function(){a.call(b)}:a)},oc["finally"]=oc.ensure=function(a){var b=this;return new Jc(function(c){var d;try{d=b.subscribe(c)}catch(e){throw a(),e}return Qb(function(){try{d.dispose()}catch(b){throw b}finally{a()}})},this)},oc.finallyAction=function(a){return ib("finallyAction","finally or ensure"),this.ensure(a)},oc.ignoreElements=function(){var a=this;return new Jc(function(b){return a.subscribe(P,b.onError.bind(b),b.onCompleted.bind(b))},a)},oc.materialize=function(){var a=this;return new Jc(function(b){return a.subscribe(function(a){b.onNext(fc(a))},function(a){b.onNext(gc(a)),b.onCompleted()},function(){b.onNext(hc()),b.onCompleted()})},a)},oc.repeat=function(a){return kc(this,a).concat()},oc.retry=function(a){return kc(this,a).catchError()},oc.scan=function(){var a,b,c=!1,d=this;return 2===arguments.length?(c=!0,a=arguments[0],b=arguments[1]):b=arguments[0],new Jc(function(e){var f,g,h;return d.subscribe(function(d){!h&&(h=!0);try{f?g=b(g,d):(g=c?b(a,d):d,f=!0)}catch(i){return void e.onError(i)}e.onNext(g)},e.onError.bind(e),function(){!h&&c&&e.onNext(a),e.onCompleted()})},d)},oc.skipLast=function(a){var b=this;return new Jc(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&c.onNext(d.shift())},c.onError.bind(c),c.onCompleted.bind(c))},b)},oc.startWith=function(){var a,b,c=0;return arguments.length&&Q(arguments[0])?(b=arguments[0],c=1):b=Zb,a=Fb.call(arguments,c),lc([Ac(a,b),this]).concat()},oc.takeLast=function(a){var b=this;return new Jc(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&d.shift()},c.onError.bind(c),function(){for(;d.length>0;)c.onNext(d.shift());c.onCompleted()})},b)},oc.takeLastBuffer=function(a){var b=this;return new Jc(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&d.shift()},c.onError.bind(c),function(){c.onNext(d),c.onCompleted()})},b)},oc.windowWithCount=function(a,b){var c=this;if(+a||(a=0),1/0===Math.abs(a)&&(a=0),0>=a)throw new Error(Y);if(null==b&&(b=a),+b||(b=0),1/0===Math.abs(b)&&(b=0),0>=b)throw new Error(Y);return new Jc(function(d){function e(){var a=new Mc;i.push(a),d.onNext(Ib(a,g))}var f=new Sb,g=new Ub(f),h=0,i=[];return e(),f.setDisposable(c.subscribe(function(c){for(var d=0,f=i.length;f>d;d++)i[d].onNext(c);var g=h-a+1;g>=0&&g%b===0&&i.shift().onCompleted(),++h%b===0&&e()},function(a){for(;i.length>0;)i.shift().onError(a);d.onError(a)},function(){for(;i.length>0;)i.shift().onCompleted();d.onCompleted()})),g},c)},oc.selectConcat=oc.concatMap=function(a,b,c){return X(a)&&X(b)?this.concatMap(function(c,d){var e=a(c,d);return W(e)&&(e=vc(e)),(gb(e)||fb(e))&&(e=zc(e)),e.map(function(a,e){return b(c,a,d,e)})}):X(a)?E(this,a,c):E(this,function(){return a})},oc.concatMapObserver=oc.selectConcatObserver=function(a,b,c,d){var e=this;return new Jc(function(f){var g=0;return e.subscribe(function(b){var c;try{c=a.call(d,b,g++)}catch(e){return void f.onError(e)}W(c)&&(c=vc(c)),f.onNext(c)},function(a){var c;try{c=b.call(d,a)}catch(e){return void f.onError(e)}W(c)&&(c=vc(c)),f.onNext(c),f.onCompleted()},function(){var a;try{a=c.call(d)}catch(b){return void f.onError(b)}W(a)&&(a=vc(a)),f.onNext(a),f.onCompleted()})},this).concatAll()},oc.defaultIfEmpty=function(b){var c=this;return b===a&&(b=null),new Jc(function(a){var d=!1;return c.subscribe(function(b){d=!0,a.onNext(b)},a.onError.bind(a),function(){!d&&a.onNext(b),a.onCompleted()})},this)},G.prototype.push=function(a){var b=-1===F(this.set,a,this.comparer);return b&&this.set.push(a),b},oc.distinct=function(a,b){var c=this;return b||(b=T),new Jc(function(d){var e=new G(b);return c.subscribe(function(b){var c=b;if(a)try{c=a(b)}catch(f){return void d.onError(f)}e.push(c)&&d.onNext(b)},d.onError.bind(d),d.onCompleted.bind(d))},this)},oc.select=oc.map=function(a,b){var c=X(a)?a:function(){return a},d=this;return new Jc(function(a){var e=0;return d.subscribe(function(f){var g;try{g=c.call(b,f,e++,d)}catch(h){return void a.onError(h)}a.onNext(g)},a.onError.bind(a),a.onCompleted.bind(a))},d)},oc.pluck=function(a){return this.map(function(b){return b[a]})},oc.selectMany=oc.flatMap=function(a,b,c){return X(a)&&X(b)?this.flatMap(function(c,d){var e=a(c,d);return W(e)&&(e=vc(e)),(gb(e)||fb(e))&&(e=zc(e)),e.map(function(a,e){return b(c,a,d,e)})},c):X(a)?H(this,a,c):H(this,function(){return a})},oc.flatMapObserver=oc.selectManyObserver=function(a,b,c,d){var e=this;return new Jc(function(f){var g=0;return e.subscribe(function(b){var c;try{c=a.call(d,b,g++)}catch(e){return void f.onError(e)}W(c)&&(c=vc(c)),f.onNext(c)},function(a){var c;try{c=b.call(d,a)}catch(e){return void f.onError(e)}W(c)&&(c=vc(c)),f.onNext(c),f.onCompleted()},function(){var a;try{a=c.call(d)}catch(b){return void f.onError(b)}W(a)&&(a=vc(a)),f.onNext(a),f.onCompleted()})},e).mergeAll()},oc.selectSwitch=oc.flatMapLatest=oc.switchMap=function(a,b){return this.select(a,b).switchLatest()},oc.skip=function(a){if(0>a)throw new Error(Y);var b=this;return new Jc(function(c){var d=a;return b.subscribe(function(a){0>=d?c.onNext(a):d--},c.onError.bind(c),c.onCompleted.bind(c))},b)},oc.skipWhile=function(a,b){var c=this;return new Jc(function(d){var e=0,f=!1;return c.subscribe(function(g){if(!f)try{f=!a.call(b,g,e++,c)}catch(h){return void d.onError(h)}f&&d.onNext(g)},d.onError.bind(d),d.onCompleted.bind(d))},c)},oc.take=function(a,b){if(0>a)throw new RangeError(Y);if(0===a)return xc(b);var c=this;return new Jc(function(b){var d=a;return c.subscribe(function(a){d-->0&&(b.onNext(a),0===d&&b.onCompleted())},b.onError.bind(b),b.onCompleted.bind(b))},c)},oc.takeWhile=function(a,b){var c=this;return new Jc(function(d){var e=0,f=!0;return c.subscribe(function(g){if(f){try{f=a.call(b,g,e++,c)}catch(h){return void d.onError(h)}f?d.onNext(g):d.onCompleted()}},d.onError.bind(d),d.onCompleted.bind(d))},c)},oc.where=oc.filter=function(a,b){var c=this;return new Jc(function(d){var e=0;return c.subscribe(function(f){var g;try{g=a.call(b,f,e++,c)}catch(h){return void d.onError(h)}g&&d.onNext(f)},d.onError.bind(d),d.onCompleted.bind(d))},c)},oc.transduce=function(a){function b(a){return{init:function(){return a},step:function(a,b){return a.onNext(b)},result:function(a){return a.onCompleted()}}}var c=this;return new Jc(function(d){var e=a(b(d));return c.subscribe(function(a){try{e.step(d,a)}catch(b){d.onError(b)}},d.onError.bind(d),function(){e.result(d)})},c)};var Jc=O.AnonymousObservable=function(a){function b(a){return a&&"function"==typeof a.dispose?a:"function"==typeof a?Qb(a):Rb}function c(d,e){function f(a){var c=function(){try{e.setDisposable(b(d(e)))}catch(a){if(!e.fail(a))throw a}},e=new Kc(a);return $b.scheduleRequired()?$b.schedule(c):c(),e}return this.source=e,this instanceof c?void a.call(this,f):new c(d)}return Gb(c,a),c}(uc),Kc=function(a){function b(b){a.call(this),this.observer=b,this.m=new Sb}Gb(b,a);var c=b.prototype;return c.next=function(a){var b=!1;try{this.observer.onNext(a),b=!0}catch(c){throw c}finally{!b&&this.dispose()}},c.error=function(a){try{this.observer.onError(a)}catch(b){throw b}finally{this.dispose()}},c.completed=function(){try{this.observer.onCompleted()}catch(a){throw a}finally{this.dispose()}},c.setDisposable=function(a){this.m.setDisposable(a)},c.getDisposable=function(){return this.m.getDisposable()},c.dispose=function(){a.prototype.dispose.call(this),this.m.dispose()},b}(pc),Lc=function(a,b){this.subject=a,this.observer=b};Lc.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var a=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(a,1),this.observer=null}};var Mc=O.Subject=function(a){function c(a){return b.call(this),this.isStopped?this.exception?(a.onError(this.exception),Rb):(a.onCompleted(),Rb):(this.observers.push(a),new Lc(this,a))}function d(){a.call(this,c),this.isDisposed=!1,this.isStopped=!1,this.observers=[]}return Gb(d,a),Hb(d.prototype,mc,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(b.call(this),!this.isStopped){var a=this.observers.slice(0);this.isStopped=!0;for(var c=0,d=a.length;d>c;c++)a[c].onCompleted();this.observers=[]}},onError:function(a){if(b.call(this),!this.isStopped){var c=this.observers.slice(0);this.isStopped=!0,this.exception=a;for(var d=0,e=c.length;e>d;d++)c[d].onError(a);this.observers=[]}},onNext:function(a){if(b.call(this),!this.isStopped)for(var c=this.observers.slice(0),d=0,e=c.length;e>d;d++)c[d].onNext(a)},dispose:function(){this.isDisposed=!0,this.observers=null}}),d.create=function(a,b){return new Nc(a,b)},d}(uc),Nc=(O.AsyncSubject=function(a){function c(a){if(b.call(this),!this.isStopped)return this.observers.push(a),new Lc(this,a);var c=this.exception,d=this.hasValue,e=this.value;return c?a.onError(c):d?(a.onNext(e),a.onCompleted()):a.onCompleted(),Rb}function d(){a.call(this,c),this.isDisposed=!1,this.isStopped=!1,this.value=null,this.hasValue=!1,this.observers=[],this.exception=null}return Gb(d,a),Hb(d.prototype,mc,{hasObservers:function(){return b.call(this),this.observers.length>0},onCompleted:function(){var a,c,d;if(b.call(this),!this.isStopped){this.isStopped=!0;var e=this.observers.slice(0),f=this.value,g=this.hasValue;if(g)for(c=0,d=e.length;d>c;c++)a=e[c],a.onNext(f),a.onCompleted();else for(c=0,d=e.length;d>c;c++)e[c].onCompleted();this.observers=[]}},onError:function(a){if(b.call(this),!this.isStopped){var c=this.observers.slice(0);this.isStopped=!0,this.exception=a;for(var d=0,e=c.length;e>d;d++)c[d].onError(a);this.observers=[]}},onNext:function(a){b.call(this),this.isStopped||(this.value=a,this.hasValue=!0)},dispose:function(){this.isDisposed=!0,this.observers=null,this.exception=null,this.value=null}}),d}(uc),O.AnonymousSubject=function(a){function b(b,c){this.observer=b,this.observable=c,a.call(this,this.observable.subscribe.bind(this.observable))}return Gb(b,a),Hb(b.prototype,mc,{onCompleted:function(){this.observer.onCompleted()},onError:function(a){this.observer.onError(a)},onNext:function(a){this.observer.onNext(a)}}),b}(uc));"function"==typeof define&&"object"==typeof define.amd&&define.amd?(J.Rx=O,define(function(){return O})):K&&L?M?(L.exports=O).Rx=O:K.Rx=O:J.Rx=O;var Oc=g()}).call(this);
2
+ (function(a){function b(a){if(a.isDisposed)throw new Error(eb)}function c(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(a[c]);return b}function d(a,b){if(fb&&b.stack&&"object"==typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(jb)){for(var c=[],d=b;d;d=d.source)d.stack&&c.unshift(d.stack);c.unshift(a.stack);var f=c.join("\n"+jb+"\n");a.stack=e(f)}}function e(a){for(var b=a.split("\n"),c=[],d=0,e=b.length;e>d;d++){var h=b[d];f(h)||g(h)||!h||c.push(h)}return c.join("\n")}function f(a){var b=i(a);if(!b)return!1;var c=b[0],d=b[1];return c===hb&&d>=ib&&dd>=d}function g(a){return-1!==a.indexOf("(module.js:")||-1!==a.indexOf("(node.js:")}function h(){if(fb)try{throw new Error}catch(a){var b=a.stack.split("\n"),c=b[0].indexOf("@")>0?b[1]:b[2],d=i(c);if(!d)return;return hb=d[0],d[1]}}function i(a){var b=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(a);if(b)return[b[1],Number(b[2])];var c=/at ([^ ]+):(\d+):(?:\d+)$/.exec(a);if(c)return[c[1],Number(c[2])];var d=/.*@(.+):(\d+)$/.exec(a);return d?[d[1],Number(d[2])]:void 0}function j(a){var b=[];if(!Lb(a))return b;Kb.nonEnumArgs&&a.length&&Mb(a)&&(a=Ob.call(a));var c=Kb.enumPrototypes&&"function"==typeof a,d=Kb.enumErrorProps&&(a===Fb||a instanceof Error);for(var e in a)c&&"prototype"==e||d&&("message"==e||"name"==e)||b.push(e);if(Kb.nonEnumShadows&&a!==Gb){var f=a.constructor,g=-1,h=rb;if(a===(f&&f.prototype))var i=a===Hb?Bb:a===Fb?wb:Cb.call(a),j=Jb[i];for(;++g<h;)e=qb[g],j&&j[e]||!Db.call(a,e)||b.push(e)}return b}function k(a,b,c){for(var d=-1,e=c(a),f=e.length;++d<f;){var g=e[d];if(b(a[g],g,a)===!1)break}return a}function l(a,b){return k(a,b,j)}function m(a){return"function"!=typeof a.toString&&"string"==typeof(a+"")}function n(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;var e=typeof a,f=typeof b;if(a===a&&(null==a||null==b||"function"!=e&&"object"!=e&&"function"!=f&&"object"!=f))return!1;var g=Cb.call(a),h=Cb.call(b);if(g==sb&&(g=zb),h==sb&&(h=zb),g!=h)return!1;switch(g){case ub:case vb:return+a==+b;case yb:return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case Ab:case Bb:return a==String(b)}var i=g==tb;if(!i){if(g!=zb||!Kb.nodeClass&&(m(a)||m(b)))return!1;var j=!Kb.argsObject&&Mb(a)?Object:a.constructor,k=!Kb.argsObject&&Mb(b)?Object:b.constructor;if(!(j==k||Db.call(a,"constructor")&&Db.call(b,"constructor")||cb(j)&&j instanceof j&&cb(k)&&k instanceof k||!("constructor"in a&&"constructor"in b)))return!1}c||(c=[]),d||(d=[]);for(var o=c.length;o--;)if(c[o]==a)return d[o]==b;var p=0,q=!0;if(c.push(a),d.push(b),i){if(o=a.length,p=b.length,q=p==o)for(;p--;){var r=b[p];if(!(q=n(a[p],r,c,d)))break}}else l(b,function(b,e,f){return Db.call(f,e)?(p++,q=Db.call(a,e)&&n(a[e],b,c,d)):void 0}),q&&l(a,function(a,b,c){return Db.call(c,b)?q=--p>-1:void 0});return c.pop(),d.pop(),q}function o(a,b){for(var c=new Array(a),d=0;a>d;d++)c[d]=b();return c}function p(a){throw a}function q(a,b){this.id=a,this.value=b}function r(a,b){this.scheduler=a,this.disposable=b,this.isDisposed=!1}function t(a,b){b.isDisposed||(b.isDisposed=!0,b.disposable.dispose())}function u(a){this.observer=a,this.a=[],this.isStopped=!1}function v(){this._s=s}function w(){this._s=s,this._l=s.length,this._i=0}function x(a){this._a=a}function y(a){this._a=a,this._l=C(a),this._i=0}function z(a){return"number"==typeof a&&Q.isFinite(a)}function A(b){var c,d=b[kb];if(!d&&"string"==typeof b)return c=new v(b),c[kb]();if(!d&&b.length!==a)return c=new x(b),c[kb]();if(!d)throw new TypeError("Object is not iterable");return b[kb]()}function B(a){var b=+a;return 0===b?b:isNaN(b)?b:0>b?-1:1}function C(a){var b=+a.length;return isNaN(b)?0:0!==b&&z(b)?(b=B(b)*Math.floor(Math.abs(b)),0>=b?0:b>Kc?Kc:b):b}function D(a,b){this.observer=a,this.parent=b}function E(a,b){return new Mc(b,a)}function F(a,b){return new $c(function(c){var d=new _b,e=new ac;return e.setDisposable(d),d.setDisposable(a.subscribe(function(a){c.onNext(a)},function(a){try{var d=b(a)}catch(f){return c.onError(f)}bb(d)&&(d=Ec(d));var g=new _b;e.setDisposable(g),g.setDisposable(d.subscribe(c))},function(a){c.onCompleted(a)})),e},a)}function G(a,b){var c=this;return new $c(function(d){var e=0,f=a.length;return c.subscribe(function(c){if(f>e){var g,h=a[e++];try{g=b(c,h)}catch(i){return d.onError(i)}d.onNext(g)}else d.onCompleted()},function(a){d.onError(a)},function(){d.onCompleted()})},c)}function H(){return!1}function I(){return[]}function J(a,b,c){var d=pb(b,c,3);return a.map(function(b,c){var e=d(b,c,a);return bb(e)&&(e=Ec(e)),(nb(e)||mb(e))&&(e=Lc(e)),e}).concatAll()}function K(a,b,c){for(var d=0,e=a.length;e>d;d++)if(c(a[d],b))return d;return-1}function L(a){this.comparer=a,this.set=[]}function M(a,b,c){this.observer=a,this.selector=b,this.source=c,this.i=0,this.isStopped=!1}function N(a,b,c){var d=pb(b,c,3);return a.map(function(b,c){var e=d(b,c,a);return bb(e)&&(e=Ec(e)),(nb(e)||mb(e))&&(e=Lc(e)),e}).mergeAll()}function O(a,b,c){this.observer=a,this.predicate=b,this.source=c,this.i=0,this.isStopped=!1}var P={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},Q=P[typeof window]&&window||this,R=P[typeof exports]&&exports&&!exports.nodeType&&exports,S=P[typeof module]&&module&&!module.nodeType&&module,T=S&&S.exports===R&&R,U=P[typeof global]&&global;!U||U.global!==U&&U.window!==U||(Q=U);var V={internals:{},config:{Promise:Q.Promise},helpers:{}},W=V.helpers.noop=function(){},X=(V.helpers.notDefined=function(a){return"undefined"==typeof a},V.helpers.isScheduler=function(a){return a instanceof V.Scheduler}),Y=V.helpers.identity=function(a){return a},Z=(V.helpers.pluck=function(a){return function(b){return b[a]}},V.helpers.just=function(a){return function(){return a}},V.helpers.defaultNow=function(){return Date.now?Date.now:function(){return+new Date}}()),$=V.helpers.defaultComparer=function(a,b){return Nb(a,b)},_=V.helpers.defaultSubComparer=function(a,b){return a>b?1:b>a?-1:0},ab=(V.helpers.defaultKeySerializer=function(a){return a.toString()},V.helpers.defaultError=function(a){throw a}),bb=V.helpers.isPromise=function(a){return!!a&&"function"==typeof a.then},cb=(V.helpers.asArray=function(){return Array.prototype.slice.call(arguments)},V.helpers.not=function(a){return!a},V.helpers.isFunction=function(){var a=function(a){return"function"==typeof a||!1};return a(/x/)&&(a=function(a){return"function"==typeof a&&"[object Function]"==Cb.call(a)}),a}()),db="Argument out of range",eb="Object has been disposed";V.config.longStackSupport=!1;var fb=!1;try{throw new Error}catch(gb){fb=!!gb.stack}var hb,ib=h(),jb="From previous event:",kb="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";Q.Set&&"function"==typeof(new Q.Set)["@@iterator"]&&(kb="@@iterator");var lb=V.doneEnumerator={done:!0,value:a},mb=V.helpers.isIterable=function(b){return b[kb]!==a},nb=V.helpers.isArrayLike=function(b){return b&&b.length!==a};V.helpers.iterator=kb;var ob,pb=V.internals.bindCallback=function(a,b,c){if("undefined"==typeof b)return a;switch(c){case 0:return function(){return a.call(b)};case 1:return function(c){return a.call(b,c)};case 2:return function(c,d){return a.call(b,c,d)};case 3:return function(c,d,e){return a.call(b,c,d,e)}}return function(){return a.apply(b,arguments)}},qb=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],rb=qb.length,sb="[object Arguments]",tb="[object Array]",ub="[object Boolean]",vb="[object Date]",wb="[object Error]",xb="[object Function]",yb="[object Number]",zb="[object Object]",Ab="[object RegExp]",Bb="[object String]",Cb=Object.prototype.toString,Db=Object.prototype.hasOwnProperty,Eb=Cb.call(arguments)==sb,Fb=Error.prototype,Gb=Object.prototype,Hb=String.prototype,Ib=Gb.propertyIsEnumerable;try{ob=!(Cb.call(document)==zb&&!({toString:0}+""))}catch(gb){ob=!0}var Jb={};Jb[tb]=Jb[vb]=Jb[yb]={constructor:!0,toLocaleString:!0,toString:!0,valueOf:!0},Jb[ub]=Jb[Bb]={constructor:!0,toString:!0,valueOf:!0},Jb[wb]=Jb[xb]=Jb[Ab]={constructor:!0,toString:!0},Jb[zb]={constructor:!0};var Kb={};!function(){var a=function(){this.x=1},b=[];a.prototype={valueOf:1,y:1};for(var c in new a)b.push(c);for(c in arguments);Kb.enumErrorProps=Ib.call(Fb,"message")||Ib.call(Fb,"name"),Kb.enumPrototypes=Ib.call(a,"prototype"),Kb.nonEnumArgs=0!=c,Kb.nonEnumShadows=!/valueOf/.test(b)}(1);var Lb=V.internals.isObject=function(a){var b=typeof a;return a&&("function"==b||"object"==b)||!1},Mb=function(a){return a&&"object"==typeof a?Cb.call(a)==sb:!1};Eb||(Mb=function(a){return a&&"object"==typeof a?Db.call(a,"callee"):!1});var Nb=V.internals.isEqual=function(a,b){return n(a,b,[],[])},Ob=({}.hasOwnProperty,Array.prototype.slice),Pb=this.inherits=V.internals.inherits=function(a,b){function c(){this.constructor=a}c.prototype=b.prototype,a.prototype=new c},Qb=V.internals.addProperties=function(a){for(var b=[],c=1,d=arguments.length;d>c;c++)b.push(arguments[c]);for(var e=0,f=b.length;f>e;e++){var g=b[e];for(var h in g)a[h]=g[h]}},Rb=V.internals.addRef=function(a,b){return new $c(function(c){return new Wb(b.getDisposable(),a.subscribe(c))})};Function.prototype.bind||(Function.prototype.bind=function(a){var b=this,c=Ob.call(arguments,1),d=function(){function e(){}if(this instanceof d){e.prototype=b.prototype;var f=new e,g=b.apply(f,c.concat(Ob.call(arguments)));return Object(g)===g?g:f}return b.apply(a,c.concat(Ob.call(arguments)))};return d}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;if(null==this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;f>d;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}});var Sb=Object("a"),Tb="a"!=Sb[0]||!(0 in Sb);Array.prototype.every||(Array.prototype.every=function(a){var b=Object(this),c=Tb&&{}.toString.call(this)==Bb?this.split(""):b,d=c.length>>>0,e=arguments[1];if({}.toString.call(a)!=xb)throw new TypeError(a+" is not a function");for(var f=0;d>f;f++)if(f in c&&!a.call(e,c[f],f,b))return!1;return!0}),Array.prototype.map||(Array.prototype.map=function(a){var b=Object(this),c=Tb&&{}.toString.call(this)==Bb?this.split(""):b,d=c.length>>>0,e=Array(d),f=arguments[1];if({}.toString.call(a)!=xb)throw new TypeError(a+" is not a function");for(var g=0;d>g;g++)g in c&&(e[g]=a.call(f,c[g],g,b));return e}),Array.prototype.filter||(Array.prototype.filter=function(a){for(var b,c=[],d=new Object(this),e=0,f=d.length>>>0;f>e;e++)b=d[e],e in d&&a.call(arguments[1],b,e,d)&&c.push(b);return c}),Array.isArray||(Array.isArray=function(a){return{}.toString.call(a)==tb}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!==d?d=0:0!==d&&1/0!=d&&d!==-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Object.prototype.propertyIsEnumerable||(Object.prototype.propertyIsEnumerable=function(a){for(var b in this)if(b===a)return!0;return!1}),Object.keys||(Object.keys=function(){"use strict";var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString");return function(c){if("object"!=typeof c&&("function"!=typeof c||null===c))throw new TypeError("Object.keys called on non-object");var d,e,f=[];for(d in c)a.call(c,d)&&f.push(d);if(b)for(e=0;rb>e;e++)a.call(c,qb[e])&&f.push(qb[e]);return f}}()),q.prototype.compareTo=function(a){var b=this.value.compareTo(a.value);return 0===b&&(b=this.id-a.id),b};var Ub=V.internals.PriorityQueue=function(a){this.items=new Array(a),this.length=0},Vb=Ub.prototype;Vb.isHigherPriority=function(a,b){return this.items[a].compareTo(this.items[b])<0},Vb.percolate=function(a){if(!(a>=this.length||0>a)){var b=a-1>>1;if(!(0>b||b===a)&&this.isHigherPriority(a,b)){var c=this.items[a];this.items[a]=this.items[b],this.items[b]=c,this.percolate(b)}}},Vb.heapify=function(a){if(+a||(a=0),!(a>=this.length||0>a)){var b=2*a+1,c=2*a+2,d=a;if(b<this.length&&this.isHigherPriority(b,d)&&(d=b),c<this.length&&this.isHigherPriority(c,d)&&(d=c),d!==a){var e=this.items[a];this.items[a]=this.items[d],this.items[d]=e,this.heapify(d)}}},Vb.peek=function(){return this.items[0].value},Vb.removeAt=function(b){this.items[b]=this.items[--this.length],this.items[this.length]=a,this.heapify()},Vb.dequeue=function(){var a=this.peek();return this.removeAt(0),a},Vb.enqueue=function(a){var b=this.length++;this.items[b]=new q(Ub.count++,a),this.percolate(b)},Vb.remove=function(a){for(var b=0;b<this.length;b++)if(this.items[b].value===a)return this.removeAt(b),!0;return!1},Ub.count=0;var Wb=V.CompositeDisposable=function(){var a=[];if(Array.isArray(arguments[0]))a=arguments[0];else{var b=arguments.length;a=new Array(b);for(var c=0;b>c;c++)a[c]=arguments[c]}this.disposables=a,this.isDisposed=!1,this.length=a.length},Xb=Wb.prototype;Xb.add=function(a){this.isDisposed?a.dispose():(this.disposables.push(a),this.length++)},Xb.remove=function(a){var b=!1;if(!this.isDisposed){var c=this.disposables.indexOf(a);-1!==c&&(b=!0,this.disposables.splice(c,1),this.length--,a.dispose())}return b},Xb.dispose=function(){if(!this.isDisposed){this.isDisposed=!0;for(var a=this.disposables.length,b=new Array(a),c=0;a>c;c++)b[c]=this.disposables[c];for(this.disposables=[],this.length=0,c=0;a>c;c++)b[c].dispose()}};var Yb=V.Disposable=function(a){this.isDisposed=!1,this.action=a||W};Yb.prototype.dispose=function(){this.isDisposed||(this.action(),this.isDisposed=!0)};var Zb=Yb.create=function(a){return new Yb(a)},$b=Yb.empty={dispose:W},_b=V.SingleAssignmentDisposable=function(){function a(){this.isDisposed=!1,this.current=null}var b=a.prototype;return b.getDisposable=function(){return this.current},b.setDisposable=function(a){var b=this.isDisposed;if(!b){var c=this.current;this.current=a}c&&c.dispose(),b&&a&&a.dispose()},b.dispose=function(){if(!this.isDisposed){this.isDisposed=!0;var a=this.current;this.current=null}a&&a.dispose()},a}(),ac=V.SerialDisposable=_b,bc=V.RefCountDisposable=function(){function a(a){this.disposable=a,this.disposable.count++,this.isInnerDisposed=!1}function b(a){this.underlyingDisposable=a,this.isDisposed=!1,this.isPrimaryDisposed=!1,this.count=0}return a.prototype.dispose=function(){this.disposable.isDisposed||this.isInnerDisposed||(this.isInnerDisposed=!0,this.disposable.count--,0===this.disposable.count&&this.disposable.isPrimaryDisposed&&(this.disposable.isDisposed=!0,this.disposable.underlyingDisposable.dispose()))},b.prototype.dispose=function(){this.isDisposed||this.isPrimaryDisposed||(this.isPrimaryDisposed=!0,0===this.count&&(this.isDisposed=!0,this.underlyingDisposable.dispose()))},b.prototype.getDisposable=function(){return this.isDisposed?$b:new a(this)},b}();r.prototype.dispose=function(){this.scheduler.scheduleWithState(this,t)};var cc=V.internals.ScheduledItem=function(a,b,c,d,e){this.scheduler=a,this.state=b,this.action=c,this.dueTime=d,this.comparer=e||_,this.disposable=new _b};cc.prototype.invoke=function(){this.disposable.setDisposable(this.invokeCore())},cc.prototype.compareTo=function(a){return this.comparer(this.dueTime,a.dueTime)},cc.prototype.isCancelled=function(){return this.disposable.isDisposed},cc.prototype.invokeCore=function(){return this.action(this.scheduler,this.state)};{var dc=V.Scheduler=function(){function a(a,b,c,d){this.now=a,this._schedule=b,this._scheduleRelative=c,this._scheduleAbsolute=d}function b(a,b){return b(),$b}var c=a.prototype;return c.schedule=function(a){return this._schedule(a,b)},c.scheduleWithState=function(a,b){return this._schedule(a,b)},c.scheduleWithRelative=function(a,c){return this._scheduleRelative(c,a,b)},c.scheduleWithRelativeAndState=function(a,b,c){return this._scheduleRelative(a,b,c)},c.scheduleWithAbsolute=function(a,c){return this._scheduleAbsolute(c,a,b)},c.scheduleWithAbsoluteAndState=function(a,b,c){return this._scheduleAbsolute(a,b,c)},a.now=Z,a.normalize=function(a){return 0>a&&(a=0),a},a}();dc.normalize}!function(a){function b(a,b){var c=b.first,d=b.second,e=new Wb,f=function(b){d(b,function(b){var c=!1,d=!1,g=a.scheduleWithState(b,function(a,b){return c?e.remove(g):d=!0,f(b),$b});d||(e.add(g),c=!0)})};return f(c),e}function c(a,b,c){var d=b.first,e=b.second,f=new Wb,g=function(b){e(b,function(b,d){var e=!1,h=!1,i=a[c](b,d,function(a,b){return e?f.remove(i):h=!0,g(b),$b});h||(f.add(i),e=!0)})};return g(d),f}function d(a,b){a(function(c){b(a,c)})}a.scheduleRecursive=function(a){return this.scheduleRecursiveWithState(a,function(a,b){a(function(){b(a)})})},a.scheduleRecursiveWithState=function(a,c){return this.scheduleWithState({first:a,second:c},b)},a.scheduleRecursiveWithRelative=function(a,b){return this.scheduleRecursiveWithRelativeAndState(b,a,d)},a.scheduleRecursiveWithRelativeAndState=function(a,b,d){return this._scheduleRelative({first:a,second:d},b,function(a,b){return c(a,b,"scheduleWithRelativeAndState")})},a.scheduleRecursiveWithAbsolute=function(a,b){return this.scheduleRecursiveWithAbsoluteAndState(b,a,d)},a.scheduleRecursiveWithAbsoluteAndState=function(a,b,d){return this._scheduleAbsolute({first:a,second:d},b,function(a,b){return c(a,b,"scheduleWithAbsoluteAndState")})}}(dc.prototype),function(){dc.prototype.schedulePeriodic=function(a,b){return this.schedulePeriodicWithState(null,a,b)},dc.prototype.schedulePeriodicWithState=function(a,b,c){if("undefined"==typeof Q.setInterval)throw new Error("Periodic scheduling not supported.");var d=a,e=Q.setInterval(function(){d=c(d)},b);return Zb(function(){Q.clearInterval(e)})}}(dc.prototype),function(a){a.catchError=a["catch"]=function(a){return new lc(this,a)}}(dc.prototype);var ec,fc=(V.internals.SchedulePeriodicRecursive=function(){function a(a,b){b(0,this._period);try{this._state=this._action(this._state)}catch(c){throw this._cancel.dispose(),c}}function b(a,b,c,d){this._scheduler=a,this._state=b,this._period=c,this._action=d}return b.prototype.start=function(){var b=new _b;return this._cancel=b,b.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0,this._period,a.bind(this))),b},b}(),dc.immediate=function(){function a(a,b){return b(this,a)}function b(){throw new Error("Not supported")}return new dc(Z,a,b,b)}()),gc=dc.currentThread=function(){function a(a){for(;a.length>0;){var b=a.dequeue();b.isCancelled()||!b.isCancelled()&&b.invoke()}}function b(b,c){var e=new cc(this,b,c,this.now());if(d)d.enqueue(e);else{d=new Ub(4),d.enqueue(e);try{a(d)}catch(f){throw f}finally{d=null}}return e.disposable}function c(){throw new Error("Not supported")}var d,e=new dc(Z,b,c,c);return e.scheduleRequired=function(){return!d},e.ensureTrampoline=function(a){d?a():this.schedule(a)},e}(),hc=W,ic=function(){var a,b=W;if("WScript"in this)a=function(a,b){WScript.Sleep(b),a()};else{if(!Q.setTimeout)throw new Error("No concurrency detected!");a=Q.setTimeout,b=Q.clearTimeout}return{setTimeout:a,clearTimeout:b}}(),jc=ic.setTimeout,kc=ic.clearTimeout;!function(){function a(){if(!Q.postMessage||Q.importScripts)return!1;var a=!1,b=Q.onmessage;return Q.onmessage=function(){a=!0},Q.postMessage("","*"),Q.onmessage=b,a}var b=RegExp("^"+String(Cb).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$"),c="function"==typeof(c=U&&T&&U.setImmediate)&&!b.test(c)&&c,d="function"==typeof(d=U&&T&&U.clearImmediate)&&!b.test(d)&&d;if("function"==typeof c)ec=c,hc=d;else if("undefined"!=typeof process&&"[object process]"==={}.toString.call(process))ec=process.nextTick;else if(a()){var e="ms.rx.schedule"+Math.random(),f={},g=0,h=function(a){if("string"==typeof a.data&&a.data.substring(0,e.length)===e){var b=a.data.substring(e.length),c=f[b];c(),delete f[b]}};Q.addEventListener?Q.addEventListener("message",h,!1):Q.attachEvent("onmessage",h,!1),ec=function(a){var b=g++;f[b]=a,Q.postMessage(e+b,"*")}}else if(Q.MessageChannel){var i=new Q.MessageChannel,j={},k=0;i.port1.onmessage=function(a){var b=a.data,c=j[b];c(),delete j[b]},ec=function(a){var b=k++;j[b]=a,i.port2.postMessage(b)}}else"document"in Q&&"onreadystatechange"in Q.document.createElement("script")?ec=function(a){var b=Q.document.createElement("script");b.onreadystatechange=function(){a(),b.onreadystatechange=null,b.parentNode.removeChild(b),b=null},Q.document.documentElement.appendChild(b)}:(ec=function(a){return jc(a,0)},hc=kc)}();var lc=(dc.timeout=function(){function a(a,b){var c=this,d=new _b,e=ec(function(){d.isDisposed||d.setDisposable(b(c,a))});return new Wb(d,Zb(function(){hc(e)}))}function b(a,b,c){var d=this,e=dc.normalize(b);if(0===e)return d.scheduleWithState(a,c);var f=new _b,g=jc(function(){f.isDisposed||f.setDisposable(c(d,a))},e);return new Wb(f,Zb(function(){kc(g)}))}function c(a,b,c){return this.scheduleWithRelativeAndState(a,b-this.now(),c)}return new dc(Z,a,b,c)}(),function(a){function b(a,b){return this._scheduler.scheduleWithState(a,this._wrap(b))}function c(a,b,c){return this._scheduler.scheduleWithRelativeAndState(a,b,this._wrap(c))}function d(a,b,c){return this._scheduler.scheduleWithAbsoluteAndState(a,b,this._wrap(c))}function e(e,f){this._scheduler=e,this._handler=f,this._recursiveOriginal=null,this._recursiveWrapper=null,a.call(this,this._scheduler.now.bind(this._scheduler),b,c,d)}return Pb(e,a),e.prototype._clone=function(a){return new e(a,this._handler)},e.prototype._wrap=function(a){var b=this;return function(c,d){try{return a(b._getRecursiveWrapper(c),d)}catch(e){if(!b._handler(e))throw e;return $b}}},e.prototype._getRecursiveWrapper=function(a){if(this._recursiveOriginal!==a){this._recursiveOriginal=a;var b=this._clone(a);b._recursiveOriginal=a,b._recursiveWrapper=b,this._recursiveWrapper=b}return this._recursiveWrapper},e.prototype.schedulePeriodicWithState=function(a,b,c){var d=this,e=!1,f=new _b;return f.setDisposable(this._scheduler.schedulePeriodicWithState(a,b,function(a){if(e)return null;try{return c(a)}catch(b){if(e=!0,!d._handler(b))throw b;return f.dispose(),null}})),f},e}(dc)),mc=V.Notification=function(){function a(a,b){this.hasValue=null==b?!1:b,this.kind=a}return a.prototype.accept=function(a,b,c){return a&&"object"==typeof a?this._acceptObservable(a):this._accept(a,b,c)},a.prototype.toObservable=function(a){var b=this;return X(a)||(a=fc),new $c(function(c){return a.schedule(function(){b._acceptObservable(c),"N"===b.kind&&c.onCompleted()})})},a}(),nc=mc.createOnNext=function(){function a(a){return a(this.value)}function b(a){return a.onNext(this.value)}function c(){return"OnNext("+this.value+")"}return function(d){var e=new mc("N",!0);return e.value=d,e._accept=a,e._acceptObservable=b,e.toString=c,e}}(),oc=mc.createOnError=function(){function a(a,b){return b(this.exception)}function b(a){return a.onError(this.exception)}function c(){return"OnError("+this.exception+")"}return function(d){var e=new mc("E");return e.exception=d,e._accept=a,e._acceptObservable=b,e.toString=c,e}}(),pc=mc.createOnCompleted=function(){function a(a,b,c){return c()}function b(a){return a.onCompleted()}function c(){return"OnCompleted()"}return function(){var d=new mc("C");return d._accept=a,d._acceptObservable=b,d.toString=c,d}}(),qc=V.internals.Enumerator=function(a){this._next=a};qc.prototype.next=function(){return this._next()},qc.prototype[kb]=function(){return this};var rc=V.internals.Enumerable=function(a){this._iterator=a};rc.prototype[kb]=function(){return this._iterator()},rc.prototype.concat=function(){var a=this;return new $c(function(b){var c,d=a[kb](),e=new ac,f=fc.scheduleRecursive(function(a){if(!c){try{var f=d.next()}catch(g){return b.onError(g)}if(f.done)return b.onCompleted();var h=f.value;bb(h)&&(h=Ec(h));var i=new _b;e.setDisposable(i),i.setDisposable(h.subscribe(function(a){b.onNext(a)},function(a){b.onError(a)},a))}});return new Wb(e,f,Zb(function(){c=!0}))})},rc.prototype.catchError=function(){var a=this;return new $c(function(b){var c,d=a[kb](),e=new ac,f=fc.scheduleRecursiveWithState(null,function(a,f){if(!c){try{var g=d.next()}catch(h){return observer.onError(h)}if(g.done)return void(null!==a?b.onError(a):b.onCompleted());var i=g.value;bb(i)&&(i=Ec(i));var j=new _b;e.setDisposable(j),j.setDisposable(i.subscribe(function(a){b.onNext(a)},f,function(){b.onCompleted()}))}});return new Wb(e,f,Zb(function(){c=!0}))})},rc.prototype.catchErrorWhen=function(a){var b=this;return new $c(function(c){var d,e,f=new bd,g=new bd,h=a(f),i=h.subscribe(g),j=b[kb](),k=new ac,l=fc.scheduleRecursive(function(a){if(!d){try{var b=j.next()}catch(h){return c.onError(h)}if(b.done)return void(e?c.onError(e):c.onCompleted());var i=b.value;bb(i)&&(i=Ec(i));var l=new _b,m=new _b;k.setDisposable(new Wb(m,l)),l.setDisposable(i.subscribe(function(a){c.onNext(a)},function(b){m.setDisposable(g.subscribe(a,function(a){c.onError(a)},function(){c.onCompleted()})),f.onNext(b)},function(){c.onCompleted()}))}});return new Wb(i,k,l,Zb(function(){d=!0}))})};var sc=rc.repeat=function(a,b){return null==b&&(b=-1),new rc(function(){var c=b;return new qc(function(){return 0===c?lb:(c>0&&c--,{done:!1,value:a})})})},tc=rc.of=function(a,b,c){if(b)var d=pb(b,c,3);return new rc(function(){var c=-1;return new qc(function(){return++c<a.length?{done:!1,value:b?d(a[c],c,a):a[c]}:lb})})},uc=V.Observer=function(){};uc.prototype.toNotifier=function(){var a=this;return function(b){return b.accept(a)}},uc.prototype.asObserver=function(){return new yc(this.onNext.bind(this),this.onError.bind(this),this.onCompleted.bind(this))},uc.prototype.checked=function(){return new zc(this)};var vc=uc.create=function(a,b,c){return a||(a=W),b||(b=ab),c||(c=W),new yc(a,b,c)};uc.fromNotifier=function(a,b){return new yc(function(c){return a.call(b,nc(c))},function(c){return a.call(b,oc(c))},function(){return a.call(b,pc())})},uc.prototype.notifyOn=function(a){return new Bc(a,this)},uc.prototype.makeSafe=function(a){return new AnonymousSafeObserver(this._onNext,this._onError,this._onCompleted,a)};var wc,xc=V.internals.AbstractObserver=function(a){function b(){this.isStopped=!1,a.call(this)}function c(){throw new Error("Method not implemented")}return Pb(b,a),b.prototype.next=c,b.prototype.error=c,b.prototype.completed=c,b.prototype.onNext=function(a){this.isStopped||this.next(a)},b.prototype.onError=function(a){this.isStopped||(this.isStopped=!0,this.error(a))},b.prototype.onCompleted=function(){this.isStopped||(this.isStopped=!0,this.completed())},b.prototype.dispose=function(){this.isStopped=!0},b.prototype.fail=function(a){return this.isStopped?!1:(this.isStopped=!0,this.error(a),!0)},b}(uc),yc=V.AnonymousObserver=function(a){function b(b,c,d){a.call(this),this._onNext=b,this._onError=c,this._onCompleted=d}return Pb(b,a),b.prototype.next=function(a){this._onNext(a)},b.prototype.error=function(a){this._onError(a)},b.prototype.completed=function(){this._onCompleted()},b}(xc),zc=function(a){function b(b){a.call(this),this._observer=b,this._state=0}Pb(b,a);var c=b.prototype;return c.onNext=function(a){this.checkAccess();try{this._observer.onNext(a)}catch(b){throw b}finally{this._state=0}},c.onError=function(a){this.checkAccess();try{this._observer.onError(a)}catch(b){throw b}finally{this._state=2}},c.onCompleted=function(){this.checkAccess();try{this._observer.onCompleted()}catch(a){throw a}finally{this._state=2}},c.checkAccess=function(){if(1===this._state)throw new Error("Re-entrancy detected");if(2===this._state)throw new Error("Observer completed");0===this._state&&(this._state=1)},b}(uc),Ac=V.internals.ScheduledObserver=function(a){function b(b,c){a.call(this),this.scheduler=b,this.observer=c,this.isAcquired=!1,this.hasFaulted=!1,this.queue=[],this.disposable=new ac}return Pb(b,a),b.prototype.next=function(a){var b=this;this.queue.push(function(){b.observer.onNext(a)})},b.prototype.error=function(a){var b=this;this.queue.push(function(){b.observer.onError(a)})},b.prototype.completed=function(){var a=this;this.queue.push(function(){a.observer.onCompleted()})},b.prototype.ensureActive=function(){var a=!1,b=this;!this.hasFaulted&&this.queue.length>0&&(a=!this.isAcquired,this.isAcquired=!0),a&&this.disposable.setDisposable(this.scheduler.scheduleRecursive(function(a){var c;if(!(b.queue.length>0))return void(b.isAcquired=!1);c=b.queue.shift();try{c()}catch(d){throw b.queue=[],b.hasFaulted=!0,d}a()}))},b.prototype.dispose=function(){a.prototype.dispose.call(this),this.disposable.dispose()},b}(xc),Bc=function(a){function b(b,c,d){a.call(this,b,c),this._cancel=d}return Pb(b,a),b.prototype.next=function(b){a.prototype.next.call(this,b),this.ensureActive()},b.prototype.error=function(b){a.prototype.error.call(this,b),this.ensureActive()},b.prototype.completed=function(){a.prototype.completed.call(this),this.ensureActive()},b.prototype.dispose=function(){a.prototype.dispose.call(this),this._cancel&&this._cancel.dispose(),this._cancel=null},b}(Ac),Cc=V.Observable=function(){function a(a){if(V.config.longStackSupport&&fb){try{throw new Error}catch(b){this.stack=b.stack.substring(b.stack.indexOf("\n")+1)}var c=this;this._subscribe=function(b){var e=b.onError.bind(b);return b.onError=function(a){d(a,c),e(a)},a.call(c,b)}}else this._subscribe=a}return wc=a.prototype,wc.subscribe=wc.forEach=function(a,b,c){return this._subscribe("object"==typeof a?a:vc(a,b,c))},wc.subscribeOnNext=function(a,b){return this._subscribe(vc("undefined"!=typeof b?function(c){a.call(b,c)}:a))},wc.subscribeOnError=function(a,b){return this._subscribe(vc(null,"undefined"!=typeof b?function(c){a.call(b,c)}:a))},wc.subscribeOnCompleted=function(a,b){return this._subscribe(vc(null,null,"undefined"!=typeof b?function(){a.call(b)}:a))},a}(),Dc=V.ObservableBase=function(a){function b(a){return a&&"function"==typeof a.dispose?a:"function"==typeof a?Zb(a):$b}function c(a,c){var d=c[0],e=c[1];try{d.setDisposable(b(e.subscribeCore(d)))}catch(f){if(!d.fail(f))throw f}}function d(a){var b=new _c(a),d=[b,this];return gc.scheduleRequired()?gc.scheduleWithState(d,c):c(null,d),b}function e(){a.call(this,d)}return Pb(e,a),e.prototype.subscribeCore=function(){throw new Error("Not implemeneted")},e}(Cc);wc.observeOn=function(a){var b=this;return new $c(function(c){return b.subscribe(new Bc(a,c))},b)},wc.subscribeOn=function(a){var b=this;return new $c(function(c){var d=new _b,e=new ac;return e.setDisposable(d),d.setDisposable(a.schedule(function(){e.setDisposable(new r(a,b.subscribe(c)))})),e},b)};var Ec=Cc.fromPromise=function(a){return Gc(function(){var b=new V.AsyncSubject;return a.then(function(a){b.onNext(a),b.onCompleted()},b.onError.bind(b)),b})};wc.toPromise=function(a){if(a||(a=V.config.Promise),!a)throw new TypeError("Promise type not provided nor in Rx.config.Promise");var b=this;return new a(function(a,c){var d,e=!1;b.subscribe(function(a){d=a,e=!0},c,function(){e&&a(d)})})};var Fc=function(a){function b(b){this.source=b,a.call(this)}return Pb(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new u(a))},b}(Dc);u.prototype.onNext=function(a){this.isStopped||this.a.push(a)},u.prototype.onError=function(a){this.isStopped||(this.isStopped=!0,this.observer.onError(a))},u.prototype.onCompleted=function(){this.isStopped||(this.isStopped=!0,this.observer.onNext(this.a),this.observer.onCompleted())},u.prototype.dispose=function(){this.isStopped=!0},u.prototype.fail=function(a){return this.isStopped?!1:(this.isStopped=!0,this.observer.onError(a),!0)},wc.toArray=function(){return new Fc(this)},Cc.create=Cc.createWithDisposable=function(a,b){return new $c(a,b)};var Gc=Cc.defer=function(a){return new $c(function(b){var c;try{c=a()}catch(d){return Sc(d).subscribe(b)}return bb(c)&&(c=Ec(c)),c.subscribe(b)})},Hc=Cc.empty=function(a){return X(a)||(a=fc),new $c(function(b){return a.schedule(function(){b.onCompleted()})})},Ic=function(a){function b(b,c,d){this.iterable=b,this.mapper=c,this.scheduler=d,a.call(this)}return Pb(b,a),b.prototype.subscribeCore=function(a){var b=new Jc(a,this);return b.run()},b}(Dc),Jc=function(){function a(a,b){this.observer=a,this.parent=b}return a.prototype.run=function(){function a(a,b){try{var f=c.next()}catch(g){return d.onError(g)}if(f.done)return d.onCompleted();
3
+ var h=f.value;if(e)try{h=e(h,a)}catch(g){return d.onError(g)}d.onNext(h),b(a+1)}var b=Object(this.parent.iterable),c=A(b),d=this.observer,e=this.parent.mapper;return this.parent.scheduler.scheduleRecursiveWithState(0,a)},a}(),Kc=Math.pow(2,53)-1;v.prototype[kb]=function(){return new w(this._s)},w.prototype[kb]=function(){return this},w.prototype.next=function(){return this._i<this._l?{done:!1,value:this._s.charAt(this._i++)}:lb},x.prototype[kb]=function(){return new y(this._a)},y.prototype[kb]=function(){return this},y.prototype.next=function(){return this._i<this._l?{done:!1,value:this._a[this._i++]}:lb};var Lc=Cc.from=function(a,b,c,d){if(null==a)throw new Error("iterable cannot be null.");if(b&&!cb(b))throw new Error("mapFn when provided must be a function");if(b)var e=pb(b,c,2);return X(d)||(d=gc),new Ic(a,e,d)},Mc=function(a){function b(b,c){this.args=b,this.scheduler=c||gc,a.call(this)}return Pb(b,a),b.prototype.subscribeCore=function(a){var b=new D(a,this);return b.run()},b}(Dc);D.prototype.run=function(){function a(a,e){d>a?(b.onNext(c[a]),e(a+1)):b.onCompleted()}var b=this.observer,c=this.parent.args,d=c.length;return this.parent.scheduler.scheduleRecursiveWithState(0,a)};var Nc=Cc.fromArray=function(a,b){return new Mc(a,b)};Cc.generate=function(a,b,c,d,e){return X(e)||(e=gc),new $c(function(f){var g=!0,h=a;return e.scheduleRecursive(function(a){var e,i;try{g?g=!1:h=c(h),e=b(h),e&&(i=d(h))}catch(j){return void f.onError(j)}e?(f.onNext(i),a()):f.onCompleted()})})};var Oc=Cc.never=function(){return new $c(function(){return $b})};Cc.of=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];return new Mc(b)},Cc.ofWithScheduler=function(a){for(var b=arguments.length,c=new Array(b-1),d=1;b>d;d++)c[d-1]=arguments[d];return new Mc(c,a)},Cc.pairs=function(a,b){return b||(b=V.Scheduler.currentThread),new $c(function(c){var d=Object.keys(a),e=d.length;return b.scheduleRecursiveWithState(0,function(b,f){if(e>b){var g=d[b];c.onNext([g,a[g]]),f(b+1)}else c.onCompleted()})})};var Pc=function(a){function b(b,c,d){this.start=b,this.count=c,this.scheduler=d,a.call(this)}return Pb(b,a),b.prototype.subscribeCore=function(a){var b=new Qc(a,this);return b.run()},b}(Dc),Qc=function(){function a(a,b){this.observer=a,this.parent=b}return a.prototype.run=function(){function a(a,e){c>a?(d.onNext(b+a),e(a+1)):d.onCompleted()}var b=this.parent.start,c=this.parent.count,d=this.observer;return this.parent.scheduler.scheduleRecursiveWithState(0,a)},a}();Cc.range=function(a,b,c){return X(c)||(c=gc),new Pc(a,b,c)},Cc.repeat=function(a,b,c){return X(c)||(c=gc),Rc(a,c).repeat(null==b?-1:b)};var Rc=Cc["return"]=Cc.just=function(a,b){return X(b)||(b=fc),new $c(function(c){return b.schedule(function(){c.onNext(a),c.onCompleted()})})};Cc.returnValue=function(){return Rc.apply(null,arguments)};var Sc=Cc["throw"]=Cc.throwError=function(a,b){return X(b)||(b=fc),new $c(function(c){return b.schedule(function(){c.onError(a)})})};Cc.throwException=function(){return Cc.throwError.apply(null,arguments)},Cc.using=function(a,b){return new $c(function(c){var d,e,f=$b;try{d=a(),d&&(f=d),e=b(d)}catch(g){return new Wb(Sc(g).subscribe(c),f)}return new Wb(e.subscribe(c),f)})},wc.amb=function(a){var b=this;return new $c(function(c){function d(){f||(f=g,j.dispose())}function e(){f||(f=h,i.dispose())}var f,g="L",h="R",i=new _b,j=new _b;return bb(a)&&(a=Ec(a)),i.setDisposable(b.subscribe(function(a){d(),f===g&&c.onNext(a)},function(a){d(),f===g&&c.onError(a)},function(){d(),f===g&&c.onCompleted()})),j.setDisposable(a.subscribe(function(a){e(),f===h&&c.onNext(a)},function(a){e(),f===h&&c.onError(a)},function(){e(),f===h&&c.onCompleted()})),new Wb(i,j)})},Cc.amb=function(){function a(a,b){return a.amb(b)}var b=Oc(),c=[];if(Array.isArray(arguments[0]))c=arguments[0];else for(var d=0,e=arguments.length;e>d;d++)c.push(arguments[d]);for(var d=0,e=c.length;e>d;d++)b=a(b,c[d]);return b},wc["catch"]=wc.catchError=wc.catchException=function(a){return"function"==typeof a?F(this,a):Tc([this,a])};var Tc=Cc.catchError=Cc["catch"]=Cc.catchException=function(){var a=[];if(Array.isArray(arguments[0]))a=arguments[0];else for(var b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);return tc(a).catchError()};wc.combineLatest=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];return Array.isArray(b[0])?b[0].unshift(this):b.unshift(this),Uc.apply(this,b)};var Uc=Cc.combineLatest=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];var d=b.pop();return a--,Array.isArray(b[0])&&(b=b[0]),new $c(function(c){function e(a){if(h[a]=!0,i||(i=h.every(Y))){try{var b=d.apply(null,k)}catch(e){return void c.onError(e)}c.onNext(b)}else j.filter(function(b,c){return c!==a}).every(Y)&&c.onCompleted()}function f(a){j[a]=!0,j.every(Y)&&c.onCompleted()}for(var g=function(){return!1},h=o(a,g),i=!1,j=o(a,g),k=new Array(a),l=new Array(a),m=0;a>m;m++)!function(a){var d=b[a],g=new _b;bb(d)&&(d=Ec(d)),g.setDisposable(d.subscribe(function(b){k[a]=b,e(a)},function(a){c.onError(a)},function(){f(a)})),l[a]=g}(m);return new Wb(l)},this)};wc.concat=function(){for(var a=[],b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);return a.unshift(this),Vc.apply(null,a)};var Vc=Cc.concat=function(){var a;if(Array.isArray(arguments[0]))a=arguments[0];else{a=new Array(arguments.length);for(var b=0,c=arguments.length;c>b;b++)a[b]=arguments[b]}return tc(a).concat()};wc.concatAll=wc.concatObservable=function(){return this.merge(1)},wc.merge=function(a){if("number"!=typeof a)return Wc(this,a);var b=this;return new $c(function(c){function d(a){var b=new _b;f.add(b),bb(a)&&(a=Ec(a)),b.setDisposable(a.subscribe(function(a){c.onNext(a)},function(a){c.onError(a)},function(){f.remove(b),h.length>0?d(h.shift()):(e--,g&&0===e&&c.onCompleted())}))}var e=0,f=new Wb,g=!1,h=[];return f.add(b.subscribe(function(b){a>e?(e++,d(b)):h.push(b)},function(a){c.onError(a)},function(){g=!0,0===e&&c.onCompleted()})),f},b)};var Wc=Cc.merge=function(){var a,b,c=[],d=arguments.length;if(arguments[0])if(X(arguments[0]))for(a=arguments[0],b=1;d>b;b++)c.push(arguments[b]);else for(a=fc,b=0;d>b;b++)c.push(arguments[b]);else for(a=fc,b=1;d>b;b++)c.push(arguments[b]);return Array.isArray(c[0])&&(c=c[0]),E(a,c).mergeAll()};wc.mergeAll=wc.mergeObservable=function(){var a=this;return new $c(function(b){var c=new Wb,d=!1,e=new _b;return c.add(e),e.setDisposable(a.subscribe(function(a){var e=new _b;c.add(e),bb(a)&&(a=Ec(a)),e.setDisposable(a.subscribe(function(a){b.onNext(a)},function(a){b.onError(a)},function(){c.remove(e),d&&1===c.length&&b.onCompleted()}))},function(a){b.onError(a)},function(){d=!0,1===c.length&&b.onCompleted()})),c},a)},wc.onErrorResumeNext=function(a){if(!a)throw new Error("Second observable is required");return Xc([this,a])};var Xc=Cc.onErrorResumeNext=function(){var a=[];if(Array.isArray(arguments[0]))a=arguments[0];else for(var b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);return new $c(function(b){var c=0,d=new ac,e=fc.scheduleRecursive(function(e){var f,g;c<a.length?(f=a[c++],bb(f)&&(f=Ec(f)),g=new _b,d.setDisposable(g),g.setDisposable(f.subscribe(b.onNext.bind(b),e,e))):b.onCompleted()});return new Wb(d,e)})};wc.skipUntil=function(a){var b=this;return new $c(function(c){var d=!1,e=new Wb(b.subscribe(function(a){d&&c.onNext(a)},function(a){c.onError(a)},function(){d&&c.onCompleted()}));bb(a)&&(a=Ec(a));var f=new _b;return e.add(f),f.setDisposable(a.subscribe(function(){d=!0,f.dispose()},function(a){c.onError(a)},function(){f.dispose()})),e},b)},wc["switch"]=wc.switchLatest=function(){var a=this;return new $c(function(b){var c=!1,d=new ac,e=!1,f=0,g=a.subscribe(function(a){var g=new _b,h=++f;c=!0,d.setDisposable(g),bb(a)&&(a=Ec(a)),g.setDisposable(a.subscribe(function(a){f===h&&b.onNext(a)},function(a){f===h&&b.onError(a)},function(){f===h&&(c=!1,e&&b.onCompleted())}))},function(a){b.onError(a)},function(){e=!0,!c&&b.onCompleted()});return new Wb(g,d)},a)},wc.takeUntil=function(a){var b=this;return new $c(function(c){return bb(a)&&(a=Ec(a)),new Wb(b.subscribe(c),a.subscribe(function(){c.onCompleted()},function(a){c.onError(a)},W))},b)},wc.withLatestFrom=function(){for(var a=[],b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);var d=a.pop(),e=this;if("undefined"==typeof e)throw new Error("Source observable not found for withLatestFrom().");if("function"!=typeof d)throw new Error("withLatestFrom() expects a resultSelector function.");return Array.isArray(a[0])&&(a=a[0]),new $c(function(b){for(var c=function(){return!1},f=a.length,g=o(f,c),h=!1,i=new Array(f),j=new Array(f+1),k=0;f>k;k++)!function(c){var d=a[c],e=new _b;bb(d)&&(d=Ec(d)),e.setDisposable(d.subscribe(function(a){i[c]=a,g[c]=!0,h=g.every(Y)},b.onError.bind(b),function(){})),j[c]=e}(k);var l=new _b;return l.setDisposable(e.subscribe(function(a){var c,e=[a].concat(i);if(h){try{c=d.apply(null,e)}catch(f){return void b.onError(f)}b.onNext(c)}},b.onError.bind(b),function(){b.onCompleted()})),j[f]=l,new Wb(j)},this)},wc.zip=function(){if(Array.isArray(arguments[0]))return G.apply(this,arguments);for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];var d=this,e=b.pop();return b.unshift(d),new $c(function(a){function c(b){var c,f;if(h.every(function(a){return a.length>0})){try{f=h.map(function(a){return a.shift()}),c=e.apply(d,f)}catch(g){return void a.onError(g)}a.onNext(c)}else i.filter(function(a,c){return c!==b}).every(Y)&&a.onCompleted()}function f(b){i[b]=!0,i.every(function(a){return a})&&a.onCompleted()}for(var g=b.length,h=o(g,I),i=o(g,H),j=new Array(g),k=0;g>k;k++)!function(d){var e=b[d],g=new _b;bb(e)&&(e=Ec(e)),g.setDisposable(e.subscribe(function(a){h[d].push(a),c(d)},function(b){a.onError(b)},function(){f(d)})),j[d]=g}(k);return new Wb(j)},d)},Cc.zip=function(){for(var a=arguments.length,b=new Array(a),c=0;a>c;c++)b[c]=arguments[c];var d=b.shift();return d.zip.apply(d,b)},Cc.zipArray=function(){var a;if(Array.isArray(arguments[0]))a=arguments[0];else{var b=arguments.length;a=new Array(b);for(var c=0;b>c;c++)a[c]=arguments[c]}return new $c(function(b){function c(a){if(f.every(function(a){return a.length>0})){var c=f.map(function(a){return a.shift()});b.onNext(c)}else if(g.filter(function(b,c){return c!==a}).every(Y))return void b.onCompleted()}function d(a){return g[a]=!0,g.every(Y)?void b.onCompleted():void 0}for(var e=a.length,f=o(e,function(){return[]}),g=o(e,function(){return!1}),h=new Array(e),i=0;e>i;i++)!function(e){h[e]=new _b,h[e].setDisposable(a[e].subscribe(function(a){f[e].push(a),c(e)},function(a){b.onError(a)},function(){d(e)}))}(i);return new Wb(h)})},wc.asObservable=function(){var a=this;return new $c(function(b){return a.subscribe(b)},this)},wc.bufferWithCount=function(a,b){return"number"!=typeof b&&(b=a),this.windowWithCount(a,b).selectMany(function(a){return a.toArray()}).where(function(a){return a.length>0})},wc.dematerialize=function(){var a=this;return new $c(function(b){return a.subscribe(function(a){return a.accept(b)},function(a){b.onError(a)},function(){b.onCompleted()})},this)},wc.distinctUntilChanged=function(a,b){var c=this;return b||(b=$),new $c(function(d){var e,f=!1;return c.subscribe(function(c){var g=c;if(a)try{g=a(c)}catch(h){return void d.onError(h)}if(f)try{var i=b(e,g)}catch(h){return void d.onError(h)}f&&i||(f=!0,e=g,d.onNext(c))},function(a){d.onError(a)},function(){d.onCompleted()})},this)},wc["do"]=wc.tap=wc.doAction=function(a,b,c){var d=this,e="function"==typeof a||"undefined"==typeof a?vc(a||W,b||W,c||W):a;return new $c(function(a){return d.subscribe(function(b){try{e.onNext(b)}catch(c){a.onError(c)}a.onNext(b)},function(b){try{e.onError(b)}catch(c){a.onError(c)}a.onError(b)},function(){try{e.onCompleted()}catch(b){a.onError(b)}a.onCompleted()})},this)},wc.doOnNext=wc.tapOnNext=function(a,b){return this.tap("undefined"!=typeof b?function(c){a.call(b,c)}:a)},wc.doOnError=wc.tapOnError=function(a,b){return this.tap(W,"undefined"!=typeof b?function(c){a.call(b,c)}:a)},wc.doOnCompleted=wc.tapOnCompleted=function(a,b){return this.tap(W,null,"undefined"!=typeof b?function(){a.call(b)}:a)},wc["finally"]=wc.ensure=function(a){var b=this;return new $c(function(c){var d;try{d=b.subscribe(c)}catch(e){throw a(),e}return Zb(function(){try{d.dispose()}catch(b){throw b}finally{a()}})},this)},wc.finallyAction=function(a){return this.ensure(a)},wc.ignoreElements=function(){var a=this;return new $c(function(b){return a.subscribe(W,function(a){b.onError(a)},function(){b.onCompleted()})},a)},wc.materialize=function(){var a=this;return new $c(function(b){return a.subscribe(function(a){b.onNext(nc(a))},function(a){b.onNext(oc(a)),b.onCompleted()},function(){b.onNext(pc()),b.onCompleted()})},a)},wc.repeat=function(a){return sc(this,a).concat()},wc.retry=function(a){return sc(this,a).catchError()},wc.retryWhen=function(a){return sc(this).catchErrorWhen(a)},wc.scan=function(){var a,b,c=!1,d=this;return 2===arguments.length?(c=!0,a=arguments[0],b=arguments[1]):b=arguments[0],new $c(function(e){var f,g,h;return d.subscribe(function(d){!h&&(h=!0);try{f?g=b(g,d):(g=c?b(a,d):d,f=!0)}catch(i){return void e.onError(i)}e.onNext(g)},function(a){e.onError(a)},function(){!h&&c&&e.onNext(a),e.onCompleted()})},d)},wc.skipLast=function(a){var b=this;return new $c(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&c.onNext(d.shift())},function(a){c.onError(a)},function(){c.onCompleted()})},b)},wc.startWith=function(){var a,b=0;arguments.length&&X(arguments[0])?(a=arguments[0],b=1):a=fc;for(var c=[],d=b,e=arguments.length;e>d;d++)c.push(arguments[d]);return tc([Nc(c,a),this]).concat()},wc.takeLast=function(a){var b=this;return new $c(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&d.shift()},function(a){c.onError(a)},function(){for(;d.length>0;)c.onNext(d.shift());c.onCompleted()})},b)},wc.takeLastBuffer=function(a){var b=this;return new $c(function(c){var d=[];return b.subscribe(function(b){d.push(b),d.length>a&&d.shift()},function(a){c.onError(a)},function(){c.onNext(d),c.onCompleted()})},b)},wc.windowWithCount=function(a,b){var c=this;if(+a||(a=0),1/0===Math.abs(a)&&(a=0),0>=a)throw new Error(db);if(null==b&&(b=a),+b||(b=0),1/0===Math.abs(b)&&(b=0),0>=b)throw new Error(db);return new $c(function(d){function e(){var a=new bd;i.push(a),d.onNext(Rb(a,g))}var f=new _b,g=new bc(f),h=0,i=[];return e(),f.setDisposable(c.subscribe(function(c){for(var d=0,f=i.length;f>d;d++)i[d].onNext(c);var g=h-a+1;g>=0&&g%b===0&&i.shift().onCompleted(),++h%b===0&&e()},function(a){for(;i.length>0;)i.shift().onError(a);d.onError(a)},function(){for(;i.length>0;)i.shift().onCompleted();d.onCompleted()})),g},c)},wc.selectConcat=wc.concatMap=function(a,b,c){return cb(a)&&cb(b)?this.concatMap(function(c,d){var e=a(c,d);return bb(e)&&(e=Ec(e)),(nb(e)||mb(e))&&(e=Lc(e)),e.map(function(a,e){return b(c,a,d,e)})}):cb(a)?J(this,a,c):J(this,function(){return a})},wc.concatMapObserver=wc.selectConcatObserver=function(a,b,c,d){var e=this,f=pb(a,d,2),g=pb(b,d,1),h=pb(c,d,0);return new $c(function(a){var b=0;return e.subscribe(function(c){var d;try{d=f(c,b++)}catch(e){return void a.onError(e)}bb(d)&&(d=Ec(d)),a.onNext(d)},function(b){var c;try{c=g(b)}catch(d){return void a.onError(d)}bb(c)&&(c=Ec(c)),a.onNext(c),a.onCompleted()},function(){var b;try{b=h()}catch(c){return void a.onError(c)}bb(b)&&(b=Ec(b)),a.onNext(b),a.onCompleted()})},this).concatAll()},wc.defaultIfEmpty=function(b){var c=this;return b===a&&(b=null),new $c(function(a){var d=!1;return c.subscribe(function(b){d=!0,a.onNext(b)},function(b){a.onError(b)},function(){!d&&a.onNext(b),a.onCompleted()})},c)},L.prototype.push=function(a){var b=-1===K(this.set,a,this.comparer);return b&&this.set.push(a),b},wc.distinct=function(a,b){var c=this;return b||(b=$),new $c(function(d){var e=new L(b);return c.subscribe(function(b){var c=b;if(a)try{c=a(b)}catch(f){return void d.onError(f)}e.push(c)&&d.onNext(b)},function(a){d.onError(a)},function(){d.onCompleted()})},this)};var Yc=function(a){function b(b,c,d){this.source=b,this.selector=pb(c,d,3),a.call(this)}return Pb(b,a),b.prototype.internalMap=function(a,c){var d=this;return new b(this.source,function(b,c,e){return a(d.selector(b,c,e),c,e)},c)},b.prototype.subscribeCore=function(a){return this.source.subscribe(new M(a,this.selector,this))},b}(Dc);M.prototype.onNext=function(a){if(!this.isStopped){try{var b=this.selector(a,this.i++,this.source)}catch(c){return this.observer.onError(c)}this.observer.onNext(b)}},M.prototype.onError=function(a){this.isStopped||(this.isStopped=!0,this.observer.onError(a))},M.prototype.onCompleted=function(){this.isStopped||(this.isStopped=!0,this.observer.onCompleted())},M.prototype.dispose=function(){this.isStopped=!0},M.prototype.fail=function(a){return this.isStopped?!1:(this.isStopped=!0,this.observer.onError(a),!0)},wc.map=wc.select=function(a,b){var c="function"==typeof a?a:function(){return a};return this instanceof Yc?this.internalMap(c,b):new Yc(this,c,b)},wc.pluck=function(){var b=arguments,c=arguments.length;if(0===c)throw new Error("List of properties cannot be empty.");return this.map(function(d){for(var e=d,f=0;c>f;f++){var g=e[b[f]];if("undefined"==typeof g)return a;e=g}return e})},wc.selectMany=wc.flatMap=function(a,b,c){return cb(a)&&cb(b)?this.flatMap(function(c,d){var e=a(c,d);return bb(e)&&(e=Ec(e)),(nb(e)||mb(e))&&(e=Lc(e)),e.map(function(a,e){return b(c,a,d,e)})},c):cb(a)?N(this,a,c):N(this,function(){return a})},wc.flatMapObserver=wc.selectManyObserver=function(a,b,c,d){var e=this;return new $c(function(f){var g=0;return e.subscribe(function(b){var c;try{c=a.call(d,b,g++)}catch(e){return void f.onError(e)}bb(c)&&(c=Ec(c)),f.onNext(c)},function(a){var c;try{c=b.call(d,a)}catch(e){return void f.onError(e)}bb(c)&&(c=Ec(c)),f.onNext(c),f.onCompleted()},function(){var a;try{a=c.call(d)}catch(b){return void f.onError(b)}bb(a)&&(a=Ec(a)),f.onNext(a),f.onCompleted()})},e).mergeAll()},wc.selectSwitch=wc.flatMapLatest=wc.switchMap=function(a,b){return this.select(a,b).switchLatest()},wc.skip=function(a){if(0>a)throw new Error(db);var b=this;return new $c(function(c){var d=a;return b.subscribe(function(a){0>=d?c.onNext(a):d--},function(a){c.onError(a)},function(){c.onCompleted()})},b)},wc.skipWhile=function(a,b){var c=this,d=pb(a,b,3);return new $c(function(a){var b=0,e=!1;return c.subscribe(function(f){if(!e)try{e=!d(f,b++,c)}catch(g){return void a.onError(g)}e&&a.onNext(f)},function(b){a.onError(b)},function(){a.onCompleted()})},c)},wc.take=function(a,b){if(0>a)throw new RangeError(db);if(0===a)return Hc(b);var c=this;return new $c(function(b){var d=a;return c.subscribe(function(a){d-->0&&(b.onNext(a),0===d&&b.onCompleted())},function(a){b.onError(a)},function(){b.onCompleted()})},c)},wc.takeWhile=function(a,b){var c=this,d=pb(a,b,3);return new $c(function(a){var b=0,e=!0;return c.subscribe(function(f){if(e){try{e=d(f,b++,c)}catch(g){return void a.onError(g)}e?a.onNext(f):a.onCompleted()}},function(b){a.onError(b)},function(){a.onCompleted()})},c)};var Zc=function(a){function b(b,c,d){this.source=b,this.predicate=pb(c,d,3),a.call(this)}return Pb(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new O(a,this.predicate,this))},b.prototype.internalFilter=function(a,c){var d=this;return new b(this.source,function(b,c,e){return d.predicate(b,c,e)&&a(b,c,e)},c)},b}(Dc);O.prototype.onNext=function(a){if(!this.isStopped){try{var b=this.predicate(a,this.i++,this.source)}catch(c){return this.observer.onError(c)}b&&this.observer.onNext(a)}},O.prototype.onError=function(a){this.isStopped||(this.isStopped=!0,this.observer.onError(a))},O.prototype.onCompleted=function(){this.isStopped||(this.isStopped=!0,this.observer.onCompleted())},O.prototype.dispose=function(){this.isStopped=!0},O.prototype.fail=function(a){return this.isStopped?!1:(this.isStopped=!0,this.observer.onError(a),!0)},wc.filter=wc.where=function(a,b){return this instanceof Zc?this.internalFilter(a,b):new Zc(this,a,b)},wc.transduce=function(a){function b(a){return{init:function(){return a},step:function(a,b){return a.onNext(b)},result:function(a){return a.onCompleted()}}}var c=this;return new $c(function(d){var e=a(b(d));return c.subscribe(function(a){try{e.step(d,a)}catch(b){d.onError(b)}},d.onError.bind(d),function(){e.result(d)})},c)};var $c=V.AnonymousObservable=function(a){function b(a){return a&&"function"==typeof a.dispose?a:"function"==typeof a?Zb(a):$b}function c(a,c){var d=c[0],e=c[1];try{d.setDisposable(b(e(d)))}catch(f){if(!d.fail(f))throw f}}function d(b,d){function e(a){var d=new _c(a),e=[d,b];return gc.scheduleRequired()?gc.scheduleWithState(e,c):c(null,e),d}this.source=d,a.call(this,e)}return Pb(d,a),d}(Cc),_c=function(a){function b(b){a.call(this),this.observer=b,this.m=new _b}Pb(b,a);var c=b.prototype;return c.next=function(a){var b=!1;try{this.observer.onNext(a),b=!0}catch(c){return p(c)}finally{!b&&this.dispose()}},c.error=function(a){try{this.observer.onError(a)}catch(b){return p(b)}finally{this.dispose()}},c.completed=function(){try{this.observer.onCompleted()}catch(a){return p(a)}finally{this.dispose()}},c.setDisposable=function(a){this.m.setDisposable(a)},c.getDisposable=function(){return this.m.getDisposable()},c.dispose=function(){a.prototype.dispose.call(this),this.m.dispose()},b}(xc),ad=function(a,b){this.subject=a,this.observer=b};ad.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var a=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(a,1),this.observer=null}};var bd=V.Subject=function(a){function d(a){return b(this),this.isStopped?this.hasError?(a.onError(this.error),$b):(a.onCompleted(),$b):(this.observers.push(a),new ad(this,a))}function e(){a.call(this,d),this.isDisposed=!1,this.isStopped=!1,this.observers=[],this.hasError=!1}return Pb(e,a),Qb(e.prototype,uc.prototype,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(b(this),!this.isStopped){this.isStopped=!0;for(var a=0,d=c(this.observers),e=d.length;e>a;a++)d[a].onCompleted();this.observers.length=0}},onError:function(a){if(b(this),!this.isStopped){this.isStopped=!0,this.error=a,this.hasError=!0;for(var d=0,e=c(this.observers),f=e.length;f>d;d++)e[d].onError(a);this.observers.length=0}},onNext:function(a){if(b(this),!this.isStopped)for(var d=0,e=c(this.observers),f=e.length;f>d;d++)e[d].onNext(a)},dispose:function(){this.isDisposed=!0,this.observers=null}}),e.create=function(a,b){return new cd(a,b)},e}(Cc),cd=(V.AsyncSubject=function(a){function d(a){return b(this),this.isStopped?(this.hasError?a.onError(this.error):this.hasValue?(a.onNext(this.value),a.onCompleted()):a.onCompleted(),$b):(this.observers.push(a),new ad(this,a))}function e(){a.call(this,d),this.isDisposed=!1,this.isStopped=!1,this.hasValue=!1,this.observers=[],this.hasError=!1}return Pb(e,a),Qb(e.prototype,uc,{hasObservers:function(){return b(this),this.observers.length>0},onCompleted:function(){var a,d;if(b(this),!this.isStopped){this.isStopped=!0;var e=c(this.observers),d=e.length;if(this.hasValue)for(a=0;d>a;a++){var f=e[a];f.onNext(this.value),f.onCompleted()}else for(a=0;d>a;a++)e[a].onCompleted();this.observers.length=0}},onError:function(a){if(b(this),!this.isStopped){this.isStopped=!0,this.hasError=!0,this.error=a;for(var d=0,e=c(this.observers),f=e.length;f>d;d++)e[d].onError(a);this.observers.length=0}},onNext:function(a){b(this),this.isStopped||(this.value=a,this.hasValue=!0)},dispose:function(){this.isDisposed=!0,this.observers=null,this.exception=null,this.value=null}}),e}(Cc),V.AnonymousSubject=function(a){function b(a){return this.observable.subscribe(a)}function c(c,d){this.observer=c,this.observable=d,a.call(this,b)}return Pb(c,a),Qb(c.prototype,uc.prototype,{onCompleted:function(){this.observer.onCompleted()},onError:function(a){this.observer.onError(a)},onNext:function(a){this.observer.onNext(a)}}),c}(Cc));"function"==typeof define&&"object"==typeof define.amd&&define.amd?(Q.Rx=V,define(function(){return V})):R&&S?T?(S.exports=V).Rx=V:R.Rx=V:Q.Rx=V;var dd=h()}).call(this);
4
4
  //# sourceMappingURL=rx.compat.map
@@ -52,6 +52,7 @@
52
52
  AsyncSubject = Rx.AsyncSubject,
53
53
  Observer = Rx.Observer,
54
54
  inherits = Rx.internals.inherits,
55
+ bindCallback = Rx.internals.bindCallback,
55
56
  addProperties = Rx.internals.addProperties,
56
57
  helpers = Rx.helpers,
57
58
  noop = helpers.noop,
@@ -269,7 +270,12 @@
269
270
  * @returns {Observable} An observable sequence with an array collecting the last elements of all the input sequences.
270
271
  */
271
272
  Observable.forkJoin = function () {
272
- var allSources = argsOrArray(arguments, 0);
273
+ var allSources = [];
274
+ if (Array.isArray(arguments[0])) {
275
+ allSources = arguments[0];
276
+ } else {
277
+ for(var i = 0, len = arguments.length; i < len; i++) { allSources.push(arguments[i]); }
278
+ }
273
279
  return new AnonymousObservable(function (subscriber) {
274
280
  var count = allSources.length;
275
281
  if (count === 0) {
@@ -330,7 +336,6 @@
330
336
  */
331
337
  observableProto.forkJoin = function (second, resultSelector) {
332
338
  var first = this;
333
-
334
339
  return new AnonymousObservable(function (observer) {
335
340
  var leftStopped = false, rightStopped = false,
336
341
  hasLeft = false, hasRight = false,
@@ -526,7 +531,8 @@
526
531
  * @returns {Observable} An exclusive observable with only the results that happen when subscribed.
527
532
  */
528
533
  observableProto.exclusiveMap = function (selector, thisArg) {
529
- var sources = this;
534
+ var sources = this,
535
+ selectorFunc = bindCallback(selector, thisArg, 3);
530
536
  return new AnonymousObservable(function (observer) {
531
537
  var index = 0,
532
538
  hasCurrent = false,
@@ -551,7 +557,7 @@
551
557
  function (x) {
552
558
  var result;
553
559
  try {
554
- result = selector.call(thisArg, x, index++, innerSource);
560
+ result = selectorFunc(x, index++, innerSource);
555
561
  } catch (e) {
556
562
  observer.onError(e);
557
563
  return;
@@ -559,7 +565,7 @@
559
565
 
560
566
  observer.onNext(result);
561
567
  },
562
- observer.onError.bind(observer),
568
+ function (e) { observer.onError(e); },
563
569
  function () {
564
570
  g.remove(innerSubscription);
565
571
  hasCurrent = false;
@@ -570,7 +576,7 @@
570
576
  }));
571
577
  }
572
578
  },
573
- observer.onError.bind(observer),
579
+ function (e) { observer.onError(e); },
574
580
  function () {
575
581
  isStopped = true;
576
582
  if (g.length === 1 && !hasCurrent) {
@@ -1,3 +1,3 @@
1
1
  /* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
2
- (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return 1===a.length&&Array.isArray(a[b])?a[b]:v.call(a)}function f(a,b){return new r(function(){return new q(function(){return a()?{done:!1,value:b}:{done:!0,value:d}})})}var g=c.Observable,h=g.prototype,i=c.AnonymousObservable,j=g.concat,k=g.defer,l=g.empty,m=c.Disposable.empty,n=c.CompositeDisposable,o=c.SerialDisposable,p=c.SingleAssignmentDisposable,q=c.internals.Enumerator,r=c.internals.Enumerable,s=r.of,t=c.Scheduler.immediate,u=c.Scheduler.currentThread,v=Array.prototype.slice,w=c.AsyncSubject,x=c.Observer,y=c.internals.inherits,z=c.internals.addProperties,A=c.helpers,B=A.noop,C=A.isPromise,D=A.isScheduler,E=g.fromPromise,F="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";a.Set&&"function"==typeof(new a.Set)["@@iterator"]&&(F="@@iterator");c.doneEnumerator={done:!0,value:d},c.helpers.isIterable=function(a){return a[F]!==d},c.helpers.isArrayLike=function(a){return a&&a.length!==d};c.helpers.iterator=F,h.letBind=h.let=function(a){return a(this)},g["if"]=g.ifThen=function(a,b,c){return k(function(){return c||(c=l()),C(b)&&(b=E(b)),C(c)&&(c=E(c)),"function"==typeof c.now&&(c=l(c)),a()?b:c})},g["for"]=g.forIn=function(a,b,c){return s(a,b,c).concat()};var G=g["while"]=g.whileDo=function(a,b){return C(b)&&(b=E(b)),f(a,b).concat()};h.doWhile=function(a){return j([this,G(a,this)])},g["case"]=g.switchCase=function(a,b,c){return k(function(){C(c)&&(c=E(c)),c||(c=l()),"function"==typeof c.now&&(c=l(c));var d=b[a()];return C(d)&&(d=E(d)),d||c})},h.expand=function(a,b){D(b)||(b=t);var c=this;return new i(function(d){var e=[],f=new o,g=new n(f),h=0,i=!1,j=function(){var c=!1;e.length>0&&(c=!i,i=!0),c&&f.setDisposable(b.scheduleRecursive(function(b){var c;if(!(e.length>0))return void(i=!1);c=e.shift();var f=new p;g.add(f),f.setDisposable(c.subscribe(function(b){d.onNext(b);var c=null;try{c=a(b)}catch(f){d.onError(f)}e.push(c),h++,j()},d.onError.bind(d),function(){g.remove(f),h--,0===h&&d.onCompleted()})),b()}))};return e.push(c),h++,j(),g},this)},g.forkJoin=function(){var a=e(arguments,0);return new i(function(b){var c=a.length;if(0===c)return b.onCompleted(),m;for(var d=new n,e=!1,f=new Array(c),g=new Array(c),h=new Array(c),i=0;c>i;i++)!function(i){var j=a[i];C(j)&&(j=E(j)),d.add(j.subscribe(function(a){e||(f[i]=!0,h[i]=a)},function(a){e=!0,b.onError(a),d.dispose()},function(){if(!e){if(!f[i])return void b.onCompleted();g[i]=!0;for(var a=0;c>a;a++)if(!g[a])return;e=!0,b.onNext(h),b.onCompleted()}}))}(i);return d})},h.forkJoin=function(a,b){var c=this;return new i(function(d){var e,f,g=!1,h=!1,i=!1,j=!1,k=new p,l=new p;return C(a)&&(a=E(a)),k.setDisposable(c.subscribe(function(a){i=!0,e=a},function(a){l.dispose(),d.onError(a)},function(){if(g=!0,h)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),l.setDisposable(a.subscribe(function(a){j=!0,f=a},function(a){k.dispose(),d.onError(a)},function(){if(h=!0,g)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),new n(k,l)},c)},h.manySelect=function(a,b){D(b)||(b=t);var c=this;return k(function(){var d;return c.map(function(a){var b=new H(a);return d&&d.onNext(a),d=b,b}).tap(B,function(a){d&&d.onError(a)},function(){d&&d.onCompleted()}).observeOn(b).map(a)},c)};var H=function(a){function b(a){var b=this,c=new n;return c.add(u.schedule(function(){a.onNext(b.head),c.add(b.tail.mergeAll().subscribe(a))})),c}function c(c){a.call(this,b),this.head=c,this.tail=new w}return y(c,a),z(c.prototype,x,{onCompleted:function(){this.onNext(g.empty())},onError:function(a){this.onNext(g.throwException(a))},onNext:function(a){this.tail.onNext(a),this.tail.onCompleted()}}),c}(g);return h.exclusive=function(){var a=this;return new i(function(b){var c=!1,d=!1,e=new p,f=new n;return f.add(e),e.setDisposable(a.subscribe(function(a){if(!c){c=!0,C(a)&&(a=E(a));var e=new p;f.add(e),e.setDisposable(a.subscribe(b.onNext.bind(b),b.onError.bind(b),function(){f.remove(e),c=!1,d&&1===f.length&&b.onCompleted()}))}},b.onError.bind(b),function(){d=!0,c||1!==f.length||b.onCompleted()})),f},this)},h.exclusiveMap=function(a,b){var c=this;return new i(function(d){var e=0,f=!1,g=!0,h=new p,i=new n;return i.add(h),h.setDisposable(c.subscribe(function(c){f||(f=!0,innerSubscription=new p,i.add(innerSubscription),C(c)&&(c=E(c)),innerSubscription.setDisposable(c.subscribe(function(f){var g;try{g=a.call(b,f,e++,c)}catch(h){return void d.onError(h)}d.onNext(g)},d.onError.bind(d),function(){i.remove(innerSubscription),f=!1,g&&1===i.length&&d.onCompleted()})))},d.onError.bind(d),function(){g=!0,1!==i.length||f||d.onCompleted()})),i},this)},c});
2
+ (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return new q(function(){return new p(function(){return a()?{done:!1,value:b}:{done:!0,value:d}})})}var f=c.Observable,g=f.prototype,h=c.AnonymousObservable,i=f.concat,j=f.defer,k=f.empty,l=c.Disposable.empty,m=c.CompositeDisposable,n=c.SerialDisposable,o=c.SingleAssignmentDisposable,p=c.internals.Enumerator,q=c.internals.Enumerable,r=q.of,s=c.Scheduler.immediate,t=c.Scheduler.currentThread,u=(Array.prototype.slice,c.AsyncSubject),v=c.Observer,w=c.internals.inherits,x=c.internals.bindCallback,y=c.internals.addProperties,z=c.helpers,A=z.noop,B=z.isPromise,C=z.isScheduler,D=f.fromPromise,E="function"==typeof Symbol&&Symbol.iterator||"_es6shim_iterator_";a.Set&&"function"==typeof(new a.Set)["@@iterator"]&&(E="@@iterator");c.doneEnumerator={done:!0,value:d},c.helpers.isIterable=function(a){return a[E]!==d},c.helpers.isArrayLike=function(a){return a&&a.length!==d};c.helpers.iterator=E,g.letBind=g.let=function(a){return a(this)},f["if"]=f.ifThen=function(a,b,c){return j(function(){return c||(c=k()),B(b)&&(b=D(b)),B(c)&&(c=D(c)),"function"==typeof c.now&&(c=k(c)),a()?b:c})},f["for"]=f.forIn=function(a,b,c){return r(a,b,c).concat()};var F=f["while"]=f.whileDo=function(a,b){return B(b)&&(b=D(b)),e(a,b).concat()};g.doWhile=function(a){return i([this,F(a,this)])},f["case"]=f.switchCase=function(a,b,c){return j(function(){B(c)&&(c=D(c)),c||(c=k()),"function"==typeof c.now&&(c=k(c));var d=b[a()];return B(d)&&(d=D(d)),d||c})},g.expand=function(a,b){C(b)||(b=s);var c=this;return new h(function(d){var e=[],f=new n,g=new m(f),h=0,i=!1,j=function(){var c=!1;e.length>0&&(c=!i,i=!0),c&&f.setDisposable(b.scheduleRecursive(function(b){var c;if(!(e.length>0))return void(i=!1);c=e.shift();var f=new o;g.add(f),f.setDisposable(c.subscribe(function(b){d.onNext(b);var c=null;try{c=a(b)}catch(f){d.onError(f)}e.push(c),h++,j()},d.onError.bind(d),function(){g.remove(f),h--,0===h&&d.onCompleted()})),b()}))};return e.push(c),h++,j(),g},this)},f.forkJoin=function(){var a=[];if(Array.isArray(arguments[0]))a=arguments[0];else for(var b=0,c=arguments.length;c>b;b++)a.push(arguments[b]);return new h(function(b){var c=a.length;if(0===c)return b.onCompleted(),l;for(var d=new m,e=!1,f=new Array(c),g=new Array(c),h=new Array(c),i=0;c>i;i++)!function(i){var j=a[i];B(j)&&(j=D(j)),d.add(j.subscribe(function(a){e||(f[i]=!0,h[i]=a)},function(a){e=!0,b.onError(a),d.dispose()},function(){if(!e){if(!f[i])return void b.onCompleted();g[i]=!0;for(var a=0;c>a;a++)if(!g[a])return;e=!0,b.onNext(h),b.onCompleted()}}))}(i);return d})},g.forkJoin=function(a,b){var c=this;return new h(function(d){var e,f,g=!1,h=!1,i=!1,j=!1,k=new o,l=new o;return B(a)&&(a=D(a)),k.setDisposable(c.subscribe(function(a){i=!0,e=a},function(a){l.dispose(),d.onError(a)},function(){if(g=!0,h)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),l.setDisposable(a.subscribe(function(a){j=!0,f=a},function(a){k.dispose(),d.onError(a)},function(){if(h=!0,g)if(i)if(j){var a;try{a=b(e,f)}catch(c){return void d.onError(c)}d.onNext(a),d.onCompleted()}else d.onCompleted();else d.onCompleted()})),new m(k,l)},c)},g.manySelect=function(a,b){C(b)||(b=s);var c=this;return j(function(){var d;return c.map(function(a){var b=new G(a);return d&&d.onNext(a),d=b,b}).tap(A,function(a){d&&d.onError(a)},function(){d&&d.onCompleted()}).observeOn(b).map(a)},c)};var G=function(a){function b(a){var b=this,c=new m;return c.add(t.schedule(function(){a.onNext(b.head),c.add(b.tail.mergeAll().subscribe(a))})),c}function c(c){a.call(this,b),this.head=c,this.tail=new u}return w(c,a),y(c.prototype,v,{onCompleted:function(){this.onNext(f.empty())},onError:function(a){this.onNext(f.throwException(a))},onNext:function(a){this.tail.onNext(a),this.tail.onCompleted()}}),c}(f);return g.exclusive=function(){var a=this;return new h(function(b){var c=!1,d=!1,e=new o,f=new m;return f.add(e),e.setDisposable(a.subscribe(function(a){if(!c){c=!0,B(a)&&(a=D(a));var e=new o;f.add(e),e.setDisposable(a.subscribe(b.onNext.bind(b),b.onError.bind(b),function(){f.remove(e),c=!1,d&&1===f.length&&b.onCompleted()}))}},b.onError.bind(b),function(){d=!0,c||1!==f.length||b.onCompleted()})),f},this)},g.exclusiveMap=function(a,b){var c=this,d=x(a,b,3);return new h(function(a){var b=0,e=!1,f=!0,g=new o,h=new m;return h.add(g),g.setDisposable(c.subscribe(function(c){e||(e=!0,innerSubscription=new o,h.add(innerSubscription),B(c)&&(c=D(c)),innerSubscription.setDisposable(c.subscribe(function(e){var f;try{f=d(e,b++,c)}catch(g){return void a.onError(g)}a.onNext(f)},function(b){a.onError(b)},function(){h.remove(innerSubscription),e=!1,f&&1===h.length&&a.onCompleted()})))},function(b){a.onError(b)},function(){f=!0,1!==h.length||e||a.onCompleted()})),h},this)},c});
3
3
  //# sourceMappingURL=rx.experimental.map
@@ -197,7 +197,6 @@
197
197
  };
198
198
 
199
199
  var JoinObserver = (function (__super__) {
200
-
201
200
  inherits(JoinObserver, __super__);
202
201
 
203
202
  function JoinObserver(source, onError) {
@@ -215,8 +214,7 @@
215
214
  JoinObserverPrototype.next = function (notification) {
216
215
  if (!this.isDisposed) {
217
216
  if (notification.kind === 'E') {
218
- this.onError(notification.exception);
219
- return;
217
+ return this.onError(notification.exception);
220
218
  }
221
219
  this.queue.push(notification);
222
220
  var activePlans = this.activePlans.slice(0);
@@ -266,7 +264,7 @@
266
264
  /**
267
265
  * Matches when the observable sequence has an available value and projects the value.
268
266
  *
269
- * @param selector Selector that will be invoked for values in the source sequence.
267
+ * @param {Function} selector Selector that will be invoked for values in the source sequence.
270
268
  * @returns {Plan} Plan that produces the projected values, to be fed (with other plans) to the when operator.
271
269
  */
272
270
  observableProto.thenDo = function (selector) {
@@ -280,28 +278,34 @@
280
278
  * @returns {Observable} Observable sequence with the results form matching several patterns.
281
279
  */
282
280
  Observable.when = function () {
283
- var plans = argsOrArray(arguments, 0);
284
- return new AnonymousObservable(function (observer) {
281
+ var len = arguments.length, plans;
282
+ if (Array.isArray(arguments[0])) {
283
+ plans = arguments[0];
284
+ } else {
285
+ plans = new Array(len);
286
+ for(var i = 0; i < len; i++) { plans[i] = arguments[i]; }
287
+ }
288
+ return new AnonymousObservable(function (o) {
285
289
  var activePlans = [],
286
290
  externalSubscriptions = new Map();
287
291
  var outObserver = observerCreate(
288
- observer.onNext.bind(observer),
292
+ function (x) { o.onNext(x); },
289
293
  function (err) {
290
294
  externalSubscriptions.forEach(function (v) { v.onError(err); });
291
- observer.onError(err);
295
+ o.onError(err);
292
296
  },
293
- observer.onCompleted.bind(observer)
297
+ function (x) { o.onCompleted(); }
294
298
  );
295
299
  try {
296
300
  for (var i = 0, len = plans.length; i < len; i++) {
297
301
  activePlans.push(plans[i].activate(externalSubscriptions, outObserver, function (activePlan) {
298
302
  var idx = activePlans.indexOf(activePlan);
299
303
  activePlans.splice(idx, 1);
300
- activePlans.length === 0 && observer.onCompleted();
304
+ activePlans.length === 0 && o.onCompleted();
301
305
  }));
302
306
  }
303
307
  } catch (e) {
304
- observableThrow(e).subscribe(observer);
308
+ observableThrow(e).subscribe(o);
305
309
  }
306
310
  var group = new CompositeDisposable();
307
311
  externalSubscriptions.forEach(function (joinObserver) {
@@ -1,3 +1,3 @@
1
1
  /* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
2
- (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return 1===a.length&&Array.isArray(a[b])?a[b]:t.call(a)}function f(a){this.patterns=a}function g(a,b){this.expression=a,this.selector=b}function h(a,b,c){var d=a.get(b);if(!d){var e=new v(b,c);return a.set(b,e),e}return d}function i(a,b,c){this.joinObserverArray=a,this.onNext=b,this.onCompleted=c,this.joinObservers=new u;for(var d=0,e=this.joinObserverArray.length;e>d;d++){var f=this.joinObserverArray[d];this.joinObservers.set(f,f)}}var j=c.Observable,k=j.prototype,l=c.AnonymousObservable,m=j.throwException,n=c.Observer.create,o=c.SingleAssignmentDisposable,p=c.CompositeDisposable,q=c.internals.AbstractObserver,r=c.helpers.noop,s=(c.internals.isEqual,c.internals.inherits),t=(c.internals.Enumerable,c.internals.Enumerator,c.iterator,c.doneEnumerator,Array.prototype.slice),u=a.Map||function(){function a(){this._keys=[],this._values=[]}return a.prototype.get=function(a){var b=this._keys.indexOf(a);return-1!==b?this._values[b]:d},a.prototype.set=function(a,b){var c=this._keys.indexOf(a);-1!==c&&(this._values[c]=b),this._values[this._keys.push(a)-1]=b},a.prototype.forEach=function(a,b){for(var c=0,d=this._keys.length;d>c;c++)a.call(b,this._values[c],this._keys[c])},a}();f.prototype.and=function(a){return new f(this.patterns.concat(a))},f.prototype.thenDo=function(a){return new g(this,a)},g.prototype.activate=function(a,b,c){for(var d=this,e=[],f=0,g=this.expression.patterns.length;g>f;f++)e.push(h(a,this.expression.patterns[f],b.onError.bind(b)));var j=new i(e,function(){var a;try{a=d.selector.apply(d,arguments)}catch(c){return void b.onError(c)}b.onNext(a)},function(){for(var a=0,b=e.length;b>a;a++)e[a].removeActivePlan(j);c(j)});for(f=0,g=e.length;g>f;f++)e[f].addActivePlan(j);return j},i.prototype.dequeue=function(){this.joinObservers.forEach(function(a){a.queue.shift()})},i.prototype.match=function(){var a,b,c=!0;for(a=0,b=this.joinObserverArray.length;b>a;a++)if(0===this.joinObserverArray[a].queue.length){c=!1;break}if(c){var d=[],e=!1;for(a=0,b=this.joinObserverArray.length;b>a;a++)d.push(this.joinObserverArray[a].queue[0]),"C"===this.joinObserverArray[a].queue[0].kind&&(e=!0);if(e)this.onCompleted();else{this.dequeue();var f=[];for(a=0,b=d.length;a<d.length;a++)f.push(d[a].value);this.onNext.apply(this,f)}}};var v=function(a){function b(b,c){a.call(this),this.source=b,this.onError=c,this.queue=[],this.activePlans=[],this.subscription=new o,this.isDisposed=!1}s(b,a);var c=b.prototype;return c.next=function(a){if(!this.isDisposed){if("E"===a.kind)return void this.onError(a.exception);this.queue.push(a);for(var b=this.activePlans.slice(0),c=0,d=b.length;d>c;c++)b[c].match()}},c.error=r,c.completed=r,c.addActivePlan=function(a){this.activePlans.push(a)},c.subscribe=function(){this.subscription.setDisposable(this.source.materialize().subscribe(this))},c.removeActivePlan=function(a){this.activePlans.splice(this.activePlans.indexOf(a),1),0===this.activePlans.length&&this.dispose()},c.dispose=function(){a.prototype.dispose.call(this),this.isDisposed||(this.isDisposed=!0,this.subscription.dispose())},b}(q);return k.and=function(a){return new f([this,a])},k.thenDo=function(a){return new f([this]).thenDo(a)},j.when=function(){var a=e(arguments,0);return new l(function(b){var c=[],d=new u,e=n(b.onNext.bind(b),function(a){d.forEach(function(b){b.onError(a)}),b.onError(a)},b.onCompleted.bind(b));try{for(var f=0,g=a.length;g>f;f++)c.push(a[f].activate(d,e,function(a){var d=c.indexOf(a);c.splice(d,1),0===c.length&&b.onCompleted()}))}catch(h){m(h).subscribe(b)}var i=new p;return d.forEach(function(a){a.subscribe(),i.add(a)}),i})},c});
2
+ (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a){this.patterns=a}function f(a,b){this.expression=a,this.selector=b}function g(a,b,c){var d=a.get(b);if(!d){var e=new t(b,c);return a.set(b,e),e}return d}function h(a,b,c){this.joinObserverArray=a,this.onNext=b,this.onCompleted=c,this.joinObservers=new s;for(var d=0,e=this.joinObserverArray.length;e>d;d++){var f=this.joinObserverArray[d];this.joinObservers.set(f,f)}}var i=c.Observable,j=i.prototype,k=c.AnonymousObservable,l=i.throwException,m=c.Observer.create,n=c.SingleAssignmentDisposable,o=c.CompositeDisposable,p=c.internals.AbstractObserver,q=c.helpers.noop,r=(c.internals.isEqual,c.internals.inherits),s=(c.internals.Enumerable,c.internals.Enumerator,c.iterator,c.doneEnumerator,Array.prototype.slice,a.Map||function(){function a(){this._keys=[],this._values=[]}return a.prototype.get=function(a){var b=this._keys.indexOf(a);return-1!==b?this._values[b]:d},a.prototype.set=function(a,b){var c=this._keys.indexOf(a);-1!==c&&(this._values[c]=b),this._values[this._keys.push(a)-1]=b},a.prototype.forEach=function(a,b){for(var c=0,d=this._keys.length;d>c;c++)a.call(b,this._values[c],this._keys[c])},a}());e.prototype.and=function(a){return new e(this.patterns.concat(a))},e.prototype.thenDo=function(a){return new f(this,a)},f.prototype.activate=function(a,b,c){for(var d=this,e=[],f=0,i=this.expression.patterns.length;i>f;f++)e.push(g(a,this.expression.patterns[f],b.onError.bind(b)));var j=new h(e,function(){var a;try{a=d.selector.apply(d,arguments)}catch(c){return void b.onError(c)}b.onNext(a)},function(){for(var a=0,b=e.length;b>a;a++)e[a].removeActivePlan(j);c(j)});for(f=0,i=e.length;i>f;f++)e[f].addActivePlan(j);return j},h.prototype.dequeue=function(){this.joinObservers.forEach(function(a){a.queue.shift()})},h.prototype.match=function(){var a,b,c=!0;for(a=0,b=this.joinObserverArray.length;b>a;a++)if(0===this.joinObserverArray[a].queue.length){c=!1;break}if(c){var d=[],e=!1;for(a=0,b=this.joinObserverArray.length;b>a;a++)d.push(this.joinObserverArray[a].queue[0]),"C"===this.joinObserverArray[a].queue[0].kind&&(e=!0);if(e)this.onCompleted();else{this.dequeue();var f=[];for(a=0,b=d.length;a<d.length;a++)f.push(d[a].value);this.onNext.apply(this,f)}}};var t=function(a){function b(b,c){a.call(this),this.source=b,this.onError=c,this.queue=[],this.activePlans=[],this.subscription=new n,this.isDisposed=!1}r(b,a);var c=b.prototype;return c.next=function(a){if(!this.isDisposed){if("E"===a.kind)return this.onError(a.exception);this.queue.push(a);for(var b=this.activePlans.slice(0),c=0,d=b.length;d>c;c++)b[c].match()}},c.error=q,c.completed=q,c.addActivePlan=function(a){this.activePlans.push(a)},c.subscribe=function(){this.subscription.setDisposable(this.source.materialize().subscribe(this))},c.removeActivePlan=function(a){this.activePlans.splice(this.activePlans.indexOf(a),1),0===this.activePlans.length&&this.dispose()},c.dispose=function(){a.prototype.dispose.call(this),this.isDisposed||(this.isDisposed=!0,this.subscription.dispose())},b}(p);return j.and=function(a){return new e([this,a])},j.thenDo=function(a){return new e([this]).thenDo(a)},i.when=function(){var a,b=arguments.length;if(Array.isArray(arguments[0]))a=arguments[0];else{a=new Array(b);for(var c=0;b>c;c++)a[c]=arguments[c]}return new k(function(b){var c=[],d=new s,e=m(function(a){b.onNext(a)},function(a){d.forEach(function(b){b.onError(a)}),b.onError(a)},function(){b.onCompleted()});try{for(var f=0,g=a.length;g>f;f++)c.push(a[f].activate(d,e,function(a){var d=c.indexOf(a);c.splice(d,1),0===c.length&&b.onCompleted()}))}catch(h){l(h).subscribe(b)}var i=new o;return d.forEach(function(a){a.subscribe(),i.add(a)}),i})},c});
3
3
  //# sourceMappingURL=rx.joinpatterns.map
@@ -24,7 +24,7 @@
24
24
  var Rx = {
25
25
  internals: {},
26
26
  config: {
27
- Promise: root.Promise,
27
+ Promise: root.Promise
28
28
  },
29
29
  helpers: { }
30
30
  };
@@ -64,7 +64,8 @@
64
64
  var sequenceContainsNoElements = 'Sequence contains no elements.';
65
65
  var argumentOutOfRange = 'Argument out of range';
66
66
  var objectDisposed = 'Object has been disposed';
67
- function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
67
+ function checkDisposed(self) { if (self.isDisposed) { throw new Error(objectDisposed); } }
68
+ function cloneArray(arr) { for(var a = [], i = 0, len = arr.length; i < len; i++) { a.push(arr[i]); } return a;}
68
69
 
69
70
  Rx.config.longStackSupport = false;
70
71
  var hasStacks = false;
@@ -182,11 +183,41 @@
182
183
 
183
184
  Rx.helpers.iterator = $iterator$;
184
185
 
185
- var deprecate = Rx.helpers.deprecate = function (name, alternative) {
186
- /*if (typeof console !== "undefined" && typeof console.warn === "function") {
187
- console.warn(name + ' is deprecated, use ' + alternative + ' instead.', new Error('').stack);
188
- }*/
189
- }
186
+ var bindCallback = Rx.internals.bindCallback = function (func, thisArg, argCount) {
187
+ if (typeof thisArg === 'undefined') { return func; }
188
+ switch(argCount) {
189
+ case 0:
190
+ return function() {
191
+ return func.call(thisArg)
192
+ };
193
+ case 1:
194
+ return function(arg) {
195
+ return func.call(thisArg, arg);
196
+ }
197
+ case 2:
198
+ return function(value, index) {
199
+ return func.call(thisArg, value, index);
200
+ };
201
+ case 3:
202
+ return function(value, index, collection) {
203
+ return func.call(thisArg, value, index, collection);
204
+ };
205
+ }
206
+
207
+ return function() {
208
+ return func.apply(thisArg, arguments);
209
+ };
210
+ };
211
+
212
+ /** Used to determine if values are of the language type Object */
213
+ var dontEnums = ['toString',
214
+ 'toLocaleString',
215
+ 'valueOf',
216
+ 'hasOwnProperty',
217
+ 'isPrototypeOf',
218
+ 'propertyIsEnumerable',
219
+ 'constructor'],
220
+ dontEnumsLength = dontEnums.length;
190
221
 
191
222
  /** `Object#toString` result shortcuts */
192
223
  var argsClass = '[object Arguments]',
@@ -209,24 +240,12 @@
209
240
  stringProto = String.prototype,
210
241
  propertyIsEnumerable = objectProto.propertyIsEnumerable;
211
242
 
212
- // Fix for Tessel
213
- if (!propertyIsEnumerable) {
214
- propertyIsEnumerable = objectProto.propertyIsEnumerable = function (key) {
215
- for (var k in this) { if (k === key) { return true; } }
216
- return false;
217
- };
218
- }
219
-
220
243
  try {
221
244
  supportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
222
245
  } catch (e) {
223
246
  supportNodeClass = true;
224
247
  }
225
248
 
226
- var shadowedProps = [
227
- 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'
228
- ];
229
-
230
249
  var nonEnumProps = {};
231
250
  nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
232
251
  nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
@@ -255,14 +274,10 @@
255
274
  support.nonEnumShadows = !/valueOf/.test(props);
256
275
  }(1));
257
276
 
258
- function isObject(value) {
259
- // check if the value is the ECMAScript language type of Object
260
- // http://es5.github.io/#x8
261
- // and avoid a V8 bug
262
- // https://code.google.com/p/v8/issues/detail?id=2291
277
+ var isObject = Rx.internals.isObject = function(value) {
263
278
  var type = typeof value;
264
279
  return value && (type == 'function' || type == 'object') || false;
265
- }
280
+ };
266
281
 
267
282
  function keysIn(object) {
268
283
  var result = [];
@@ -285,14 +300,14 @@
285
300
  if (support.nonEnumShadows && object !== objectProto) {
286
301
  var ctor = object.constructor,
287
302
  index = -1,
288
- length = shadowedProps.length;
303
+ length = dontEnumsLength;
289
304
 
290
305
  if (object === (ctor && ctor.prototype)) {
291
306
  var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),
292
307
  nonEnum = nonEnumProps[className];
293
308
  }
294
309
  while (++index < length) {
295
- key = shadowedProps[index];
310
+ key = dontEnums[index];
296
311
  if (!(nonEnum && nonEnum[key]) && hasOwnProperty.call(object, key)) {
297
312
  result.push(key);
298
313
  }
@@ -479,13 +494,8 @@
479
494
  return result;
480
495
  }
481
496
 
482
- var slice = Array.prototype.slice;
483
- function argsOrArray(args, idx) {
484
- return args.length === 1 && Array.isArray(args[idx]) ?
485
- args[idx] :
486
- slice.call(args);
487
- }
488
- var hasProp = {}.hasOwnProperty;
497
+ var hasProp = {}.hasOwnProperty,
498
+ slice = Array.prototype.slice;
489
499
 
490
500
  var inherits = this.inherits = Rx.internals.inherits = function (child, parent) {
491
501
  function __() { this.constructor = child; }
@@ -494,9 +504,9 @@
494
504
  };
495
505
 
496
506
  var addProperties = Rx.internals.addProperties = function (obj) {
497
- var sources = slice.call(arguments, 1);
498
- for (var i = 0, len = sources.length; i < len; i++) {
499
- var source = sources[i];
507
+ for(var sources = [], i = 1, len = arguments.length; i < len; i++) { sources.push(arguments[i]); }
508
+ for (var idx = 0, ln = sources.length; idx < ln; idx++) {
509
+ var source = sources[idx];
500
510
  for (var prop in source) {
501
511
  obj[prop] = source[prop];
502
512
  }
@@ -518,6 +528,25 @@
518
528
  return a;
519
529
  }
520
530
 
531
+ var errorObj = {e: {}};
532
+ var tryCatchTarget;
533
+ function tryCatcher() {
534
+ try {
535
+ return tryCatchTarget.apply(this, arguments);
536
+ } catch (e) {
537
+ errorObj.e = e;
538
+ return errorObj;
539
+ }
540
+ }
541
+ function tryCatch(fn) {
542
+ if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
543
+ tryCatchTarget = fn;
544
+ return tryCatcher;
545
+ }
546
+ function thrower(e) {
547
+ throw e;
548
+ }
549
+
521
550
  // Collections
522
551
  function IndexedItem(id, value) {
523
552
  this.id = id;
@@ -577,7 +606,7 @@
577
606
 
578
607
  priorityProto.removeAt = function (index) {
579
608
  this.items[index] = this.items[--this.length];
580
- delete this.items[this.length];
609
+ this.items[this.length] = undefined;
581
610
  this.heapify();
582
611
  };
583
612
 
@@ -609,9 +638,17 @@
609
638
  * @constructor
610
639
  */
611
640
  var CompositeDisposable = Rx.CompositeDisposable = function () {
612
- this.disposables = argsOrArray(arguments, 0);
641
+ var args = [];
642
+ if (Array.isArray(arguments[0])) {
643
+ args = arguments[0];
644
+ } else {
645
+ var len = arguments.length;
646
+ args = new Array(len);
647
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
648
+ }
649
+ this.disposables = args;
613
650
  this.isDisposed = false;
614
- this.length = this.disposables.length;
651
+ this.length = args.length;
615
652
  };
616
653
 
617
654
  var CompositeDisposablePrototype = CompositeDisposable.prototype;
@@ -654,28 +691,19 @@
654
691
  CompositeDisposablePrototype.dispose = function () {
655
692
  if (!this.isDisposed) {
656
693
  this.isDisposed = true;
657
- var currentDisposables = this.disposables.slice(0);
694
+ var len = this.disposables.length, currentDisposables = new Array(len);
695
+ for(var i = 0; i < len; i++) { currentDisposables[i] = this.disposables[i]; }
658
696
  this.disposables = [];
659
697
  this.length = 0;
660
698
 
661
- for (var i = 0, len = currentDisposables.length; i < len; i++) {
699
+ for (i = 0; i < len; i++) {
662
700
  currentDisposables[i].dispose();
663
701
  }
664
702
  }
665
703
  };
666
704
 
667
- /**
668
- * Converts the existing CompositeDisposable to an array of disposables
669
- * @returns {Array} An array of disposable objects.
670
- */
671
- CompositeDisposablePrototype.toArray = function () {
672
- return this.disposables.slice(0);
673
- };
674
-
675
705
  /**
676
706
  * Provides a set of static methods for creating Disposables.
677
- *
678
- * @constructor
679
707
  * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
680
708
  */
681
709
  var Disposable = Rx.Disposable = function (action) {
@@ -724,9 +752,9 @@
724
752
  * @param {Disposable} value The new underlying disposable.
725
753
  */
726
754
  booleanDisposablePrototype.setDisposable = function (value) {
727
- var shouldDispose = this.isDisposed, old;
755
+ var shouldDispose = this.isDisposed;
728
756
  if (!shouldDispose) {
729
- old = this.current;
757
+ var old = this.current;
730
758
  this.current = value;
731
759
  }
732
760
  old && old.dispose();
@@ -737,10 +765,9 @@
737
765
  * Disposes the underlying disposable as well as all future replacements.
738
766
  */
739
767
  booleanDisposablePrototype.dispose = function () {
740
- var old;
741
768
  if (!this.isDisposed) {
742
769
  this.isDisposed = true;
743
- old = this.current;
770
+ var old = this.current;
744
771
  this.current = null;
745
772
  }
746
773
  old && old.dispose();
@@ -750,83 +777,80 @@
750
777
  }());
751
778
  var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
752
779
 
753
- /**
754
- * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
755
- */
756
- var RefCountDisposable = Rx.RefCountDisposable = (function () {
780
+ /**
781
+ * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
782
+ */
783
+ var RefCountDisposable = Rx.RefCountDisposable = (function () {
784
+
785
+ function InnerDisposable(disposable) {
786
+ this.disposable = disposable;
787
+ this.disposable.count++;
788
+ this.isInnerDisposed = false;
789
+ }
757
790
 
758
- function InnerDisposable(disposable) {
759
- this.disposable = disposable;
760
- this.disposable.count++;
761
- this.isInnerDisposed = false;
791
+ InnerDisposable.prototype.dispose = function () {
792
+ if (!this.disposable.isDisposed && !this.isInnerDisposed) {
793
+ this.isInnerDisposed = true;
794
+ this.disposable.count--;
795
+ if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
796
+ this.disposable.isDisposed = true;
797
+ this.disposable.underlyingDisposable.dispose();
762
798
  }
799
+ }
800
+ };
763
801
 
764
- InnerDisposable.prototype.dispose = function () {
765
- if (!this.disposable.isDisposed) {
766
- if (!this.isInnerDisposed) {
767
- this.isInnerDisposed = true;
768
- this.disposable.count--;
769
- if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
770
- this.disposable.isDisposed = true;
771
- this.disposable.underlyingDisposable.dispose();
772
- }
773
- }
774
- }
775
- };
802
+ /**
803
+ * Initializes a new instance of the RefCountDisposable with the specified disposable.
804
+ * @constructor
805
+ * @param {Disposable} disposable Underlying disposable.
806
+ */
807
+ function RefCountDisposable(disposable) {
808
+ this.underlyingDisposable = disposable;
809
+ this.isDisposed = false;
810
+ this.isPrimaryDisposed = false;
811
+ this.count = 0;
812
+ }
776
813
 
777
- /**
778
- * Initializes a new instance of the RefCountDisposable with the specified disposable.
779
- * @constructor
780
- * @param {Disposable} disposable Underlying disposable.
781
- */
782
- function RefCountDisposable(disposable) {
783
- this.underlyingDisposable = disposable;
784
- this.isDisposed = false;
785
- this.isPrimaryDisposed = false;
786
- this.count = 0;
814
+ /**
815
+ * Disposes the underlying disposable only when all dependent disposables have been disposed
816
+ */
817
+ RefCountDisposable.prototype.dispose = function () {
818
+ if (!this.isDisposed && !this.isPrimaryDisposed) {
819
+ this.isPrimaryDisposed = true;
820
+ if (this.count === 0) {
821
+ this.isDisposed = true;
822
+ this.underlyingDisposable.dispose();
787
823
  }
824
+ }
825
+ };
788
826
 
789
- /**
790
- * Disposes the underlying disposable only when all dependent disposables have been disposed
791
- */
792
- RefCountDisposable.prototype.dispose = function () {
793
- if (!this.isDisposed) {
794
- if (!this.isPrimaryDisposed) {
795
- this.isPrimaryDisposed = true;
796
- if (this.count === 0) {
797
- this.isDisposed = true;
798
- this.underlyingDisposable.dispose();
799
- }
800
- }
801
- }
802
- };
827
+ /**
828
+ * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
829
+ * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
830
+ */
831
+ RefCountDisposable.prototype.getDisposable = function () {
832
+ return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
833
+ };
803
834
 
804
- /**
805
- * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
806
- * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
807
- */
808
- RefCountDisposable.prototype.getDisposable = function () {
809
- return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
810
- };
835
+ return RefCountDisposable;
836
+ })();
811
837
 
812
- return RefCountDisposable;
813
- })();
838
+ function ScheduledDisposable(scheduler, disposable) {
839
+ this.scheduler = scheduler;
840
+ this.disposable = disposable;
841
+ this.isDisposed = false;
842
+ }
814
843
 
815
- function ScheduledDisposable(scheduler, disposable) {
816
- this.scheduler = scheduler;
817
- this.disposable = disposable;
818
- this.isDisposed = false;
844
+ function scheduleItem(s, self) {
845
+ if (!self.isDisposed) {
846
+ self.isDisposed = true;
847
+ self.disposable.dispose();
819
848
  }
849
+ }
820
850
 
821
- ScheduledDisposable.prototype.dispose = function () {
822
- var parent = this;
823
- this.scheduler.schedule(function () {
824
- if (!parent.isDisposed) {
825
- parent.isDisposed = true;
826
- parent.disposable.dispose();
827
- }
828
- });
829
- };
851
+ ScheduledDisposable.prototype.dispose = function () {
852
+ this.scheduler.scheduleWithState(this, scheduleItem);
853
+ };
830
854
 
831
855
  var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
832
856
  this.scheduler = scheduler;
@@ -979,7 +1003,7 @@
979
1003
  recursiveAction = function (state1) {
980
1004
  action(state1, function (state2, dueTime1) {
981
1005
  var isAdded = false, isDone = false,
982
- d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
1006
+ d = scheduler[method](state2, dueTime1, function (scheduler1, state3) {
983
1007
  if (isAdded) {
984
1008
  group.remove(d);
985
1009
  } else {
@@ -1147,18 +1171,9 @@
1147
1171
  var immediateScheduler = Scheduler.immediate = (function () {
1148
1172
 
1149
1173
  function scheduleNow(state, action) { return action(this, state); }
1174
+ function notSupported() { throw new Error('Not supported'); }
1150
1175
 
1151
- function scheduleRelative(state, dueTime, action) {
1152
- var dt = normalizeTime(dueTime);
1153
- while (dt - this.now() > 0) { }
1154
- return action(this, state);
1155
- }
1156
-
1157
- function scheduleAbsolute(state, dueTime, action) {
1158
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1159
- }
1160
-
1161
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1176
+ return new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1162
1177
  }());
1163
1178
 
1164
1179
  /**
@@ -1168,27 +1183,16 @@
1168
1183
  var queue;
1169
1184
 
1170
1185
  function runTrampoline (q) {
1171
- var item;
1172
1186
  while (q.length > 0) {
1173
- item = q.dequeue();
1187
+ var item = q.dequeue();
1174
1188
  if (!item.isCancelled()) {
1175
- // Note, do not schedule blocking work!
1176
- while (item.dueTime - Scheduler.now() > 0) {
1177
- }
1178
- if (!item.isCancelled()) {
1179
- item.invoke();
1180
- }
1189
+ !item.isCancelled() && item.invoke();
1181
1190
  }
1182
1191
  }
1183
1192
  }
1184
1193
 
1185
1194
  function scheduleNow(state, action) {
1186
- return this.scheduleWithRelativeAndState(state, 0, action);
1187
- }
1188
-
1189
- function scheduleRelative(state, dueTime, action) {
1190
- var dt = this.now() + Scheduler.normalize(dueTime),
1191
- si = new ScheduledItem(this, state, action, dt);
1195
+ var si = new ScheduledItem(this, state, action, this.now());
1192
1196
 
1193
1197
  if (!queue) {
1194
1198
  queue = new PriorityQueue(4);
@@ -1206,11 +1210,9 @@
1206
1210
  return si.disposable;
1207
1211
  }
1208
1212
 
1209
- function scheduleAbsolute(state, dueTime, action) {
1210
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1211
- }
1213
+ function notSupported() { throw new Error('Not supported'); }
1212
1214
 
1213
- var currentScheduler = new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1215
+ var currentScheduler = new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1214
1216
 
1215
1217
  currentScheduler.scheduleRequired = function () { return !queue; };
1216
1218
  currentScheduler.ensureTrampoline = function (action) {
@@ -1577,31 +1579,20 @@
1577
1579
 
1578
1580
  Enumerable.prototype.concat = function () {
1579
1581
  var sources = this;
1580
- return new AnonymousObservable(function (observer) {
1581
- var e;
1582
- try {
1583
- e = sources[$iterator$]();
1584
- } catch (err) {
1585
- observer.onError(err);
1586
- return;
1587
- }
1582
+ return new AnonymousObservable(function (o) {
1583
+ var e = sources[$iterator$]();
1588
1584
 
1589
- var isDisposed,
1590
- subscription = new SerialDisposable();
1585
+ var isDisposed, subscription = new SerialDisposable();
1591
1586
  var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1592
- var currentItem;
1593
1587
  if (isDisposed) { return; }
1594
-
1595
1588
  try {
1596
- currentItem = e.next();
1589
+ var currentItem = e.next();
1597
1590
  } catch (ex) {
1598
- observer.onError(ex);
1599
- return;
1591
+ return o.onError(ex);
1600
1592
  }
1601
1593
 
1602
1594
  if (currentItem.done) {
1603
- observer.onCompleted();
1604
- return;
1595
+ return o.onCompleted();
1605
1596
  }
1606
1597
 
1607
1598
  // Check if promise
@@ -1611,9 +1602,9 @@
1611
1602
  var d = new SingleAssignmentDisposable();
1612
1603
  subscription.setDisposable(d);
1613
1604
  d.setDisposable(currentValue.subscribe(
1614
- observer.onNext.bind(observer),
1615
- observer.onError.bind(observer),
1616
- function () { self(); })
1605
+ function(x) { o.onNext(x); },
1606
+ function(err) { o.onError(err); },
1607
+ self)
1617
1608
  );
1618
1609
  });
1619
1610
 
@@ -1625,14 +1616,55 @@
1625
1616
 
1626
1617
  Enumerable.prototype.catchError = function () {
1627
1618
  var sources = this;
1628
- return new AnonymousObservable(function (observer) {
1629
- var e;
1630
- try {
1631
- e = sources[$iterator$]();
1632
- } catch (err) {
1633
- observer.onError(err);
1634
- return;
1635
- }
1619
+ return new AnonymousObservable(function (o) {
1620
+ var e = sources[$iterator$]();
1621
+
1622
+ var isDisposed, subscription = new SerialDisposable();
1623
+ var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
1624
+ if (isDisposed) { return; }
1625
+
1626
+ try {
1627
+ var currentItem = e.next();
1628
+ } catch (ex) {
1629
+ return observer.onError(ex);
1630
+ }
1631
+
1632
+ if (currentItem.done) {
1633
+ if (lastException !== null) {
1634
+ o.onError(lastException);
1635
+ } else {
1636
+ o.onCompleted();
1637
+ }
1638
+ return;
1639
+ }
1640
+
1641
+ // Check if promise
1642
+ var currentValue = currentItem.value;
1643
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1644
+
1645
+ var d = new SingleAssignmentDisposable();
1646
+ subscription.setDisposable(d);
1647
+ d.setDisposable(currentValue.subscribe(
1648
+ function(x) { o.onNext(x); },
1649
+ self,
1650
+ function() { o.onCompleted(); }));
1651
+ });
1652
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1653
+ isDisposed = true;
1654
+ }));
1655
+ });
1656
+ };
1657
+
1658
+
1659
+ Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
1660
+ var sources = this;
1661
+ return new AnonymousObservable(function (o) {
1662
+ var exceptions = new Subject(),
1663
+ notifier = new Subject(),
1664
+ handled = notificationHandler(exceptions),
1665
+ notificationDisposable = handled.subscribe(notifier);
1666
+
1667
+ var e = sources[$iterator$]();
1636
1668
 
1637
1669
  var isDisposed,
1638
1670
  lastException,
@@ -1640,19 +1672,17 @@
1640
1672
  var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1641
1673
  if (isDisposed) { return; }
1642
1674
 
1643
- var currentItem;
1644
1675
  try {
1645
- currentItem = e.next();
1676
+ var currentItem = e.next();
1646
1677
  } catch (ex) {
1647
- observer.onError(ex);
1648
- return;
1678
+ return o.onError(ex);
1649
1679
  }
1650
1680
 
1651
1681
  if (currentItem.done) {
1652
1682
  if (lastException) {
1653
- observer.onError(lastException);
1683
+ o.onError(lastException);
1654
1684
  } else {
1655
- observer.onCompleted();
1685
+ o.onCompleted();
1656
1686
  }
1657
1687
  return;
1658
1688
  }
@@ -1661,17 +1691,24 @@
1661
1691
  var currentValue = currentItem.value;
1662
1692
  isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1663
1693
 
1664
- var d = new SingleAssignmentDisposable();
1665
- subscription.setDisposable(d);
1666
- d.setDisposable(currentValue.subscribe(
1667
- observer.onNext.bind(observer),
1694
+ var outer = new SingleAssignmentDisposable();
1695
+ var inner = new SingleAssignmentDisposable();
1696
+ subscription.setDisposable(new CompositeDisposable(inner, outer));
1697
+ outer.setDisposable(currentValue.subscribe(
1698
+ function(x) { o.onNext(x); },
1668
1699
  function (exn) {
1669
- lastException = exn;
1670
- self();
1700
+ inner.setDisposable(notifier.subscribe(self, function(ex) {
1701
+ o.onError(ex);
1702
+ }, function() {
1703
+ o.onCompleted();
1704
+ }));
1705
+
1706
+ exceptions.onNext(exn);
1671
1707
  },
1672
- observer.onCompleted.bind(observer)));
1708
+ function() { o.onCompleted(); }));
1673
1709
  });
1674
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1710
+
1711
+ return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
1675
1712
  isDisposed = true;
1676
1713
  }));
1677
1714
  });
@@ -1690,13 +1727,15 @@
1690
1727
  };
1691
1728
 
1692
1729
  var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
1693
- selector || (selector = identity);
1730
+ if (selector) {
1731
+ var selectorFn = bindCallback(selector, thisArg, 3);
1732
+ }
1694
1733
  return new Enumerable(function () {
1695
1734
  var index = -1;
1696
1735
  return new Enumerator(
1697
1736
  function () {
1698
1737
  return ++index < source.length ?
1699
- { done: false, value: selector.call(thisArg, source[index], index, source) } :
1738
+ { done: false, value: !selector ? source[index] : selectorFn(source[index], index, source) } :
1700
1739
  doneEnumerator;
1701
1740
  });
1702
1741
  });
@@ -1772,6 +1811,10 @@
1772
1811
  return new ObserveOnObserver(scheduler, this);
1773
1812
  };
1774
1813
 
1814
+ Observer.prototype.makeSafe = function(disposable) {
1815
+ return new AnonymousSafeObserver(this._onNext, this._onError, this._onCompleted, disposable);
1816
+ };
1817
+
1775
1818
  /**
1776
1819
  * Abstract base class for implementations of the Observer class.
1777
1820
  * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
@@ -1787,6 +1830,15 @@
1787
1830
  __super__.call(this);
1788
1831
  }
1789
1832
 
1833
+ function notImplemented() {
1834
+ throw new Error('Method not implemented');
1835
+ }
1836
+
1837
+ // Must be implemented by other observers
1838
+ AbstractObserver.prototype.next = notImplemented;
1839
+ AbstractObserver.prototype.error = notImplemented;
1840
+ AbstractObserver.prototype.completed = notImplemented;
1841
+
1790
1842
  /**
1791
1843
  * Notifies the observer of a new element in the sequence.
1792
1844
  * @param {Any} value Next element in the sequence.
@@ -2053,7 +2105,7 @@
2053
2105
  oldOnError(err);
2054
2106
  };
2055
2107
 
2056
- return subscribe(observer);
2108
+ return subscribe.call(self, observer);
2057
2109
  };
2058
2110
  } else {
2059
2111
  this._subscribe = subscribe;
@@ -2082,7 +2134,7 @@
2082
2134
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2083
2135
  */
2084
2136
  observableProto.subscribeOnNext = function (onNext, thisArg) {
2085
- return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2137
+ return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
2086
2138
  };
2087
2139
 
2088
2140
  /**
@@ -2092,7 +2144,7 @@
2092
2144
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2093
2145
  */
2094
2146
  observableProto.subscribeOnError = function (onError, thisArg) {
2095
- return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2147
+ return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
2096
2148
  };
2097
2149
 
2098
2150
  /**
@@ -2102,12 +2154,58 @@
2102
2154
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2103
2155
  */
2104
2156
  observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2105
- return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2157
+ return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
2106
2158
  };
2107
2159
 
2108
2160
  return Observable;
2109
2161
  })();
2110
2162
 
2163
+ var ObservableBase = Rx.ObservableBase = (function (__super__) {
2164
+
2165
+ inherits(ObservableBase, __super__);
2166
+
2167
+ // Fix subscriber to check for undefined or function returned to decorate as Disposable
2168
+ function fixSubscriber(subscriber) {
2169
+ if (subscriber && typeof subscriber.dispose === 'function') { return subscriber; }
2170
+
2171
+ return typeof subscriber === 'function' ?
2172
+ disposableCreate(subscriber) :
2173
+ disposableEmpty;
2174
+ }
2175
+
2176
+ function setDisposable(s, state) {
2177
+ var ado = state[0], self = state[1];
2178
+ try {
2179
+ ado.setDisposable(fixSubscriber(self.subscribeCore(ado)));
2180
+ } catch (e) {
2181
+ if (!ado.fail(e)) { throw e; }
2182
+ }
2183
+ }
2184
+
2185
+ function subscribe(observer) {
2186
+ var ado = new AutoDetachObserver(observer), state = [ado, this];
2187
+
2188
+ if (currentThreadScheduler.scheduleRequired()) {
2189
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
2190
+ } else {
2191
+ setDisposable(null, state);
2192
+ }
2193
+
2194
+ return ado;
2195
+ }
2196
+
2197
+ function ObservableBase() {
2198
+ __super__.call(this, subscribe);
2199
+ }
2200
+
2201
+ ObservableBase.prototype.subscribeCore = function(observer) {
2202
+ throw new Error('Not implemeneted');
2203
+ }
2204
+
2205
+ return ObservableBase;
2206
+
2207
+ }(Observable));
2208
+
2111
2209
  /**
2112
2210
  * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2113
2211
  *
@@ -2193,22 +2291,56 @@
2193
2291
  });
2194
2292
  };
2195
2293
 
2294
+ var ToArrayObservable = (function(__super__) {
2295
+ inherits(ToArrayObservable, __super__);
2296
+ function ToArrayObservable(source) {
2297
+ this.source = source;
2298
+ __super__.call(this);
2299
+ }
2300
+
2301
+ ToArrayObservable.prototype.subscribeCore = function(observer) {
2302
+ return this.source.subscribe(new ToArrayObserver(observer));
2303
+ };
2304
+
2305
+ return ToArrayObservable;
2306
+ }(ObservableBase));
2307
+
2308
+ function ToArrayObserver(observer) {
2309
+ this.observer = observer;
2310
+ this.a = [];
2311
+ this.isStopped = false;
2312
+ }
2313
+ ToArrayObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
2314
+ ToArrayObserver.prototype.onError = function (e) {
2315
+ if (!this.isStopped) {
2316
+ this.isStopped = true;
2317
+ this.observer.onError(e);
2318
+ }
2319
+ };
2320
+ ToArrayObserver.prototype.onCompleted = function () {
2321
+ if (!this.isStopped) {
2322
+ this.isStopped = true;
2323
+ this.observer.onNext(this.a);
2324
+ this.observer.onCompleted();
2325
+ }
2326
+ };
2327
+ ToArrayObserver.prototype.dispose = function () { this.isStopped = true; }
2328
+ ToArrayObserver.prototype.fail = function (e) {
2329
+ if (!this.isStopped) {
2330
+ this.isStopped = true;
2331
+ this.observer.onError(e);
2332
+ return true;
2333
+ }
2334
+
2335
+ return false;
2336
+ };
2337
+
2196
2338
  /**
2197
- * Creates an array from an observable sequence.
2198
- * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2199
- */
2339
+ * Creates an array from an observable sequence.
2340
+ * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2341
+ */
2200
2342
  observableProto.toArray = function () {
2201
- var source = this;
2202
- return new AnonymousObservable(function(observer) {
2203
- var arr = [];
2204
- return source.subscribe(
2205
- arr.push.bind(arr),
2206
- observer.onError.bind(observer),
2207
- function () {
2208
- observer.onNext(arr);
2209
- observer.onCompleted();
2210
- });
2211
- }, source);
2343
+ return new ToArrayObservable(this);
2212
2344
  };
2213
2345
 
2214
2346
  /**
@@ -2263,6 +2395,65 @@
2263
2395
  });
2264
2396
  };
2265
2397
 
2398
+ var FromObservable = (function(__super__) {
2399
+ inherits(FromObservable, __super__);
2400
+ function FromObservable(iterable, mapper, scheduler) {
2401
+ this.iterable = iterable;
2402
+ this.mapper = mapper;
2403
+ this.scheduler = scheduler;
2404
+ __super__.call(this);
2405
+ }
2406
+
2407
+ FromObservable.prototype.subscribeCore = function (observer) {
2408
+ var sink = new FromSink(observer, this);
2409
+ return sink.run();
2410
+ };
2411
+
2412
+ return FromObservable;
2413
+ }(ObservableBase));
2414
+
2415
+ var FromSink = (function () {
2416
+ function FromSink(observer, parent) {
2417
+ this.observer = observer;
2418
+ this.parent = parent;
2419
+ }
2420
+
2421
+ FromSink.prototype.run = function () {
2422
+ var list = Object(this.parent.iterable),
2423
+ it = getIterable(list),
2424
+ observer = this.observer,
2425
+ mapper = this.parent.mapper;
2426
+
2427
+ function loopRecursive(i, recurse) {
2428
+ try {
2429
+ var next = it.next();
2430
+ } catch (e) {
2431
+ return observer.onError(e);
2432
+ }
2433
+ if (next.done) {
2434
+ return observer.onCompleted();
2435
+ }
2436
+
2437
+ var result = next.value;
2438
+
2439
+ if (mapper) {
2440
+ try {
2441
+ result = mapper(result, i);
2442
+ } catch (e) {
2443
+ return observer.onError(e);
2444
+ }
2445
+ }
2446
+
2447
+ observer.onNext(result);
2448
+ recurse(i + 1);
2449
+ }
2450
+
2451
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2452
+ };
2453
+
2454
+ return FromSink;
2455
+ }());
2456
+
2266
2457
  var maxSafeInteger = Math.pow(2, 53) - 1;
2267
2458
 
2268
2459
  function StringIterable(str) {
@@ -2284,12 +2475,7 @@
2284
2475
  };
2285
2476
 
2286
2477
  StringIterator.prototype.next = function () {
2287
- if (this._i < this._l) {
2288
- var val = this._s.charAt(this._i++);
2289
- return { done: false, value: val };
2290
- } else {
2291
- return doneEnumerator;
2292
- }
2478
+ return this._i < this._l ? { done: false, value: this._s.charAt(this._i++) } : doneEnumerator;
2293
2479
  };
2294
2480
 
2295
2481
  function ArrayIterable(a) {
@@ -2311,12 +2497,7 @@
2311
2497
  };
2312
2498
 
2313
2499
  ArrayIterator.prototype.next = function () {
2314
- if (this._i < this._l) {
2315
- var val = this._a[this._i++];
2316
- return { done: false, value: val };
2317
- } else {
2318
- return doneEnumerator;
2319
- }
2500
+ return this._i < this._l ? { done: false, value: this._a[this._i++] } : doneEnumerator;
2320
2501
  };
2321
2502
 
2322
2503
  function numberIsFinite(value) {
@@ -2359,12 +2540,12 @@
2359
2540
  }
2360
2541
 
2361
2542
  /**
2362
- * This method creates a new Observable sequence from an array-like or iterable object.
2363
- * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
2364
- * @param {Function} [mapFn] Map function to call on every element of the array.
2365
- * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2366
- * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2367
- */
2543
+ * This method creates a new Observable sequence from an array-like or iterable object.
2544
+ * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
2545
+ * @param {Function} [mapFn] Map function to call on every element of the array.
2546
+ * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2547
+ * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2548
+ */
2368
2549
  var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2369
2550
  if (iterable == null) {
2370
2551
  throw new Error('iterable cannot be null.')
@@ -2372,61 +2553,56 @@
2372
2553
  if (mapFn && !isFunction(mapFn)) {
2373
2554
  throw new Error('mapFn when provided must be a function');
2374
2555
  }
2556
+ if (mapFn) {
2557
+ var mapper = bindCallback(mapFn, thisArg, 2);
2558
+ }
2375
2559
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2376
- var list = Object(iterable), it = getIterable(list);
2377
- return new AnonymousObservable(function (observer) {
2378
- var i = 0;
2379
- return scheduler.scheduleRecursive(function (self) {
2380
- var next;
2381
- try {
2382
- next = it.next();
2383
- } catch (e) {
2384
- observer.onError(e);
2385
- return;
2386
- }
2387
- if (next.done) {
2388
- observer.onCompleted();
2389
- return;
2390
- }
2560
+ return new FromObservable(iterable, mapper, scheduler);
2561
+ }
2391
2562
 
2392
- var result = next.value;
2563
+ var FromArrayObservable = (function(__super__) {
2564
+ inherits(FromArrayObservable, __super__);
2565
+ function FromArrayObservable(args, scheduler) {
2566
+ this.args = args;
2567
+ this.scheduler = scheduler || currentThreadScheduler;
2568
+ __super__.call(this);
2569
+ }
2393
2570
 
2394
- if (mapFn && isFunction(mapFn)) {
2395
- try {
2396
- result = mapFn.call(thisArg, result, i);
2397
- } catch (e) {
2398
- observer.onError(e);
2399
- return;
2400
- }
2401
- }
2571
+ FromArrayObservable.prototype.subscribeCore = function (observer) {
2572
+ var sink = new FromArraySink(observer, this);
2573
+ return sink.run();
2574
+ };
2402
2575
 
2403
- observer.onNext(result);
2404
- i++;
2405
- self();
2406
- });
2407
- });
2576
+ return FromArrayObservable;
2577
+ }(ObservableBase));
2578
+
2579
+ function FromArraySink(observer, parent) {
2580
+ this.observer = observer;
2581
+ this.parent = parent;
2582
+ }
2583
+
2584
+ FromArraySink.prototype.run = function () {
2585
+ var observer = this.observer, args = this.parent.args, len = args.length;
2586
+ function loopRecursive(i, recurse) {
2587
+ if (i < len) {
2588
+ observer.onNext(args[i]);
2589
+ recurse(i + 1);
2590
+ } else {
2591
+ observer.onCompleted();
2592
+ }
2593
+ }
2594
+
2595
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2408
2596
  };
2409
2597
 
2410
2598
  /**
2411
- * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2412
- * @deprecated use Observable.from or Observable.of
2413
- * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2414
- * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2415
- */
2599
+ * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2600
+ * @deprecated use Observable.from or Observable.of
2601
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2602
+ * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2603
+ */
2416
2604
  var observableFromArray = Observable.fromArray = function (array, scheduler) {
2417
- deprecate('fromArray', 'from');
2418
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2419
- return new AnonymousObservable(function (observer) {
2420
- var count = 0, len = array.length;
2421
- return scheduler.scheduleRecursive(function (self) {
2422
- if (count < len) {
2423
- observer.onNext(array[count++]);
2424
- self();
2425
- } else {
2426
- observer.onCompleted();
2427
- }
2428
- });
2429
- });
2605
+ return new FromArrayObservable(array, scheduler)
2430
2606
  };
2431
2607
 
2432
2608
  /**
@@ -2483,55 +2659,45 @@
2483
2659
  };
2484
2660
 
2485
2661
  function observableOf (scheduler, array) {
2486
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2487
- return new AnonymousObservable(function (observer) {
2488
- var count = 0, len = array.length;
2489
- return scheduler.scheduleRecursive(function (self) {
2490
- if (count < len) {
2491
- observer.onNext(array[count++]);
2492
- self();
2493
- } else {
2494
- observer.onCompleted();
2495
- }
2496
- });
2497
- });
2662
+ return new FromArrayObservable(array, scheduler);
2498
2663
  }
2499
2664
 
2500
2665
  /**
2501
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2502
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2503
- */
2666
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2667
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2668
+ */
2504
2669
  Observable.of = function () {
2505
- return observableOf(null, arguments);
2670
+ var len = arguments.length, args = new Array(len);
2671
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2672
+ return new FromArrayObservable(args);
2506
2673
  };
2507
2674
 
2508
2675
  /**
2509
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2510
- * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2511
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2512
- */
2676
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2677
+ * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2678
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2679
+ */
2513
2680
  Observable.ofWithScheduler = function (scheduler) {
2514
- return observableOf(scheduler, slice.call(arguments, 1));
2681
+ var len = arguments.length, args = new Array(len - 1);
2682
+ for(var i = 1; i < len; i++) { args[i - 1] = arguments[i]; }
2683
+ return new FromArrayObservable(args, scheduler);
2515
2684
  };
2516
2685
 
2517
2686
  /**
2518
- * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2519
- *
2520
- * @example
2521
- * var res = Rx.Observable.range(0, 10);
2522
- * var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
2523
- * @param {Number} start The value of the first integer in the sequence.
2524
- * @param {Number} count The number of sequential integers to generate.
2525
- * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2526
- * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2687
+ * Convert an object into an observable sequence of [key, value] pairs.
2688
+ * @param {Object} obj The object to inspect.
2689
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2690
+ * @returns {Observable} An observable sequence of [key, value] pairs from the object.
2527
2691
  */
2528
- Observable.range = function (start, count, scheduler) {
2529
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2692
+ Observable.pairs = function (obj, scheduler) {
2693
+ scheduler || (scheduler = Rx.Scheduler.currentThread);
2530
2694
  return new AnonymousObservable(function (observer) {
2531
- return scheduler.scheduleRecursiveWithState(0, function (i, self) {
2532
- if (i < count) {
2533
- observer.onNext(start + i);
2534
- self(i + 1);
2695
+ var keys = Object.keys(obj), len = keys.length;
2696
+ return scheduler.scheduleRecursiveWithState(0, function (idx, self) {
2697
+ if (idx < len) {
2698
+ var key = keys[idx];
2699
+ observer.onNext([key, obj[key]]);
2700
+ self(idx + 1);
2535
2701
  } else {
2536
2702
  observer.onCompleted();
2537
2703
  }
@@ -2539,6 +2705,58 @@
2539
2705
  });
2540
2706
  };
2541
2707
 
2708
+ var RangeObservable = (function(__super__) {
2709
+ inherits(RangeObservable, __super__);
2710
+ function RangeObservable(start, count, scheduler) {
2711
+ this.start = start;
2712
+ this.count = count;
2713
+ this.scheduler = scheduler;
2714
+ __super__.call(this);
2715
+ }
2716
+
2717
+ RangeObservable.prototype.subscribeCore = function (observer) {
2718
+ var sink = new RangeSink(observer, this);
2719
+ return sink.run();
2720
+ };
2721
+
2722
+ return RangeObservable;
2723
+ }(ObservableBase));
2724
+
2725
+ var RangeSink = (function () {
2726
+ function RangeSink(observer, parent) {
2727
+ this.observer = observer;
2728
+ this.parent = parent;
2729
+ }
2730
+
2731
+ RangeSink.prototype.run = function () {
2732
+ var start = this.parent.start, count = this.parent.count, observer = this.observer;
2733
+ function loopRecursive(i, recurse) {
2734
+ if (i < count) {
2735
+ observer.onNext(start + i);
2736
+ recurse(i + 1);
2737
+ } else {
2738
+ observer.onCompleted();
2739
+ }
2740
+ }
2741
+
2742
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2743
+ };
2744
+
2745
+ return RangeSink;
2746
+ }());
2747
+
2748
+ /**
2749
+ * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2750
+ * @param {Number} start The value of the first integer in the sequence.
2751
+ * @param {Number} count The number of sequential integers to generate.
2752
+ * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2753
+ * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2754
+ */
2755
+ Observable.range = function (start, count, scheduler) {
2756
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2757
+ return new RangeObservable(start, count, scheduler);
2758
+ };
2759
+
2542
2760
  /**
2543
2761
  * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
2544
2762
  *
@@ -2560,10 +2778,6 @@
2560
2778
  /**
2561
2779
  * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
2562
2780
  * There is an alias called 'just', and 'returnValue' for browsers <IE9.
2563
- *
2564
- * @example
2565
- * var res = Rx.Observable.return(42);
2566
- * var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
2567
2781
  * @param {Mixed} value Single element in the resulting observable sequence.
2568
2782
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2569
2783
  * @returns {Observable} An observable sequence containing the single specified element.
@@ -2580,26 +2794,32 @@
2580
2794
 
2581
2795
  /** @deprecated use return or just */
2582
2796
  Observable.returnValue = function () {
2583
- deprecate('returnValue', 'return or just');
2797
+ //deprecate('returnValue', 'return or just');
2584
2798
  return observableReturn.apply(null, arguments);
2585
2799
  };
2586
2800
 
2587
2801
  /**
2588
2802
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2589
2803
  * There is an alias to this method called 'throwError' for browsers <IE9.
2590
- * @param {Mixed} exception An object used for the sequence's termination.
2804
+ * @param {Mixed} error An object used for the sequence's termination.
2591
2805
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2592
2806
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2593
2807
  */
2594
- var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
2808
+ var observableThrow = Observable['throw'] = Observable.throwError = function (error, scheduler) {
2595
2809
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2596
2810
  return new AnonymousObservable(function (observer) {
2597
2811
  return scheduler.schedule(function () {
2598
- observer.onError(exception);
2812
+ observer.onError(error);
2599
2813
  });
2600
2814
  });
2601
2815
  };
2602
2816
 
2817
+ /** @deprecated use #some instead */
2818
+ Observable.throwException = function () {
2819
+ //deprecate('throwException', 'throwError');
2820
+ return Observable.throwError.apply(null, arguments);
2821
+ };
2822
+
2603
2823
  /**
2604
2824
  * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2605
2825
  * @param {Function} resourceFactory Factory function to obtain a resource object.
@@ -2695,8 +2915,13 @@
2695
2915
  * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
2696
2916
  */
2697
2917
  Observable.amb = function () {
2698
- var acc = observableNever(),
2699
- items = argsOrArray(arguments, 0);
2918
+ var acc = observableNever(), items = [];
2919
+ if (Array.isArray(arguments[0])) {
2920
+ items = arguments[0];
2921
+ } else {
2922
+ for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
2923
+ }
2924
+
2700
2925
  function func(previous, current) {
2701
2926
  return previous.amb(current);
2702
2927
  }
@@ -2707,23 +2932,21 @@
2707
2932
  };
2708
2933
 
2709
2934
  function observableCatchHandler(source, handler) {
2710
- return new AnonymousObservable(function (observer) {
2935
+ return new AnonymousObservable(function (o) {
2711
2936
  var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2712
2937
  subscription.setDisposable(d1);
2713
- d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2714
- var d, result;
2938
+ d1.setDisposable(source.subscribe(function (x) { o.onNext(x); }, function (e) {
2715
2939
  try {
2716
- result = handler(exception);
2940
+ var result = handler(e);
2717
2941
  } catch (ex) {
2718
- observer.onError(ex);
2719
- return;
2942
+ return o.onError(ex);
2720
2943
  }
2721
2944
  isPromise(result) && (result = observableFromPromise(result));
2722
2945
 
2723
- d = new SingleAssignmentDisposable();
2946
+ var d = new SingleAssignmentDisposable();
2724
2947
  subscription.setDisposable(d);
2725
- d.setDisposable(result.subscribe(observer));
2726
- }, observer.onCompleted.bind(observer)));
2948
+ d.setDisposable(result.subscribe(o));
2949
+ }, function (x) { o.onCompleted(x); }));
2727
2950
 
2728
2951
  return subscription;
2729
2952
  }, source);
@@ -2737,35 +2960,25 @@
2737
2960
  * @param {Mixed} handlerOrSecond Exception handler function that returns an observable sequence given the error that occurred in the first sequence, or a second observable sequence used to produce results when an error occurred in the first sequence.
2738
2961
  * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2739
2962
  */
2740
- observableProto['catch'] = observableProto.catchError = function (handlerOrSecond) {
2963
+ observableProto['catch'] = observableProto.catchError = observableProto.catchException = function (handlerOrSecond) {
2741
2964
  return typeof handlerOrSecond === 'function' ?
2742
2965
  observableCatchHandler(this, handlerOrSecond) :
2743
2966
  observableCatch([this, handlerOrSecond]);
2744
2967
  };
2745
2968
 
2746
- /**
2747
- * @deprecated use #catch or #catchError instead.
2748
- */
2749
- observableProto.catchException = function (handlerOrSecond) {
2750
- deprecate('catchException', 'catch or catchError');
2751
- return this.catchError(handlerOrSecond);
2752
- };
2753
-
2754
2969
  /**
2755
2970
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2756
2971
  * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
2757
2972
  * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
2758
2973
  */
2759
- var observableCatch = Observable.catchError = Observable['catch'] = function () {
2760
- return enumerableOf(argsOrArray(arguments, 0)).catchError();
2761
- };
2762
-
2763
- /**
2764
- * @deprecated use #catch or #catchError instead.
2765
- */
2766
- Observable.catchException = function () {
2767
- deprecate('catchException', 'catch or catchError');
2768
- return observableCatch.apply(null, arguments);
2974
+ var observableCatch = Observable.catchError = Observable['catch'] = Observable.catchException = function () {
2975
+ var items = [];
2976
+ if (Array.isArray(arguments[0])) {
2977
+ items = arguments[0];
2978
+ } else {
2979
+ for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
2980
+ }
2981
+ return enumerableOf(items).catchError();
2769
2982
  };
2770
2983
 
2771
2984
  /**
@@ -2778,7 +2991,8 @@
2778
2991
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2779
2992
  */
2780
2993
  observableProto.combineLatest = function () {
2781
- var args = slice.call(arguments);
2994
+ var len = arguments.length, args = new Array(len);
2995
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2782
2996
  if (Array.isArray(args[0])) {
2783
2997
  args[0].unshift(this);
2784
2998
  } else {
@@ -2796,54 +3010,51 @@
2796
3010
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2797
3011
  */
2798
3012
  var combineLatest = Observable.combineLatest = function () {
2799
- var args = slice.call(arguments), resultSelector = args.pop();
2800
-
2801
- if (Array.isArray(args[0])) {
2802
- args = args[0];
2803
- }
3013
+ var len = arguments.length, args = new Array(len);
3014
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3015
+ var resultSelector = args.pop();
3016
+ len--;
3017
+ Array.isArray(args[0]) && (args = args[0]);
2804
3018
 
2805
- return new AnonymousObservable(function (observer) {
3019
+ return new AnonymousObservable(function (o) {
2806
3020
  var falseFactory = function () { return false; },
2807
- n = args.length,
2808
- hasValue = arrayInitialize(n, falseFactory),
3021
+ hasValue = arrayInitialize(len, falseFactory),
2809
3022
  hasValueAll = false,
2810
- isDone = arrayInitialize(n, falseFactory),
2811
- values = new Array(n);
3023
+ isDone = arrayInitialize(len, falseFactory),
3024
+ values = new Array(len);
2812
3025
 
2813
3026
  function next(i) {
2814
- var res;
2815
3027
  hasValue[i] = true;
2816
3028
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2817
3029
  try {
2818
- res = resultSelector.apply(null, values);
3030
+ var res = resultSelector.apply(null, values);
2819
3031
  } catch (ex) {
2820
- observer.onError(ex);
3032
+ o.onError(ex);
2821
3033
  return;
2822
3034
  }
2823
- observer.onNext(res);
3035
+ o.onNext(res);
2824
3036
  } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2825
- observer.onCompleted();
3037
+ o.onCompleted();
2826
3038
  }
2827
3039
  }
2828
3040
 
2829
3041
  function done (i) {
2830
3042
  isDone[i] = true;
2831
- if (isDone.every(identity)) {
2832
- observer.onCompleted();
2833
- }
3043
+ isDone.every(identity) && o.onCompleted();
2834
3044
  }
2835
3045
 
2836
- var subscriptions = new Array(n);
2837
- for (var idx = 0; idx < n; idx++) {
3046
+ var subscriptions = new Array(len);
3047
+ for (var idx = 0; idx < len; idx++) {
2838
3048
  (function (i) {
2839
3049
  var source = args[i], sad = new SingleAssignmentDisposable();
2840
3050
  isPromise(source) && (source = observableFromPromise(source));
2841
3051
  sad.setDisposable(source.subscribe(function (x) {
2842
- values[i] = x;
2843
- next(i);
2844
- }, observer.onError.bind(observer), function () {
2845
- done(i);
2846
- }));
3052
+ values[i] = x;
3053
+ next(i);
3054
+ },
3055
+ function(e) { o.onError(e); },
3056
+ function () { done(i); }
3057
+ ));
2847
3058
  subscriptions[i] = sad;
2848
3059
  }(idx));
2849
3060
  }
@@ -2852,19 +3063,15 @@
2852
3063
  }, this);
2853
3064
  };
2854
3065
 
2855
- /**
2856
- * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
2857
- *
2858
- * @example
2859
- * 1 - concatenated = xs.concat(ys, zs);
2860
- * 2 - concatenated = xs.concat([ys, zs]);
2861
- * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
2862
- */
2863
- observableProto.concat = function () {
2864
- var items = slice.call(arguments, 0);
2865
- items.unshift(this);
2866
- return observableConcat.apply(this, items);
2867
- };
3066
+ /**
3067
+ * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
3068
+ * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
3069
+ */
3070
+ observableProto.concat = function () {
3071
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3072
+ args.unshift(this);
3073
+ return observableConcat.apply(null, args);
3074
+ };
2868
3075
 
2869
3076
  /**
2870
3077
  * Concatenates all the observable sequences.
@@ -2872,20 +3079,21 @@
2872
3079
  * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
2873
3080
  */
2874
3081
  var observableConcat = Observable.concat = function () {
2875
- return enumerableOf(argsOrArray(arguments, 0)).concat();
3082
+ var args;
3083
+ if (Array.isArray(arguments[0])) {
3084
+ args = arguments[0];
3085
+ } else {
3086
+ args = new Array(arguments.length);
3087
+ for(var i = 0, len = arguments.length; i < len; i++) { args[i] = arguments[i]; }
3088
+ }
3089
+ return enumerableOf(args).concat();
2876
3090
  };
2877
3091
 
2878
3092
  /**
2879
3093
  * Concatenates an observable sequence of observable sequences.
2880
3094
  * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
2881
3095
  */
2882
- observableProto.concatAll = function () {
2883
- return this.merge(1);
2884
- };
2885
-
2886
- /** @deprecated Use `concatAll` instead. */
2887
- observableProto.concatObservable = function () {
2888
- deprecate('concatObservable', 'concatAll');
3096
+ observableProto.concatAll = observableProto.concatObservable = function () {
2889
3097
  return this.merge(1);
2890
3098
  };
2891
3099
 
@@ -2902,7 +3110,7 @@
2902
3110
  observableProto.merge = function (maxConcurrentOrOther) {
2903
3111
  if (typeof maxConcurrentOrOther !== 'number') { return observableMerge(this, maxConcurrentOrOther); }
2904
3112
  var sources = this;
2905
- return new AnonymousObservable(function (observer) {
3113
+ return new AnonymousObservable(function (o) {
2906
3114
  var activeCount = 0, group = new CompositeDisposable(), isStopped = false, q = [];
2907
3115
 
2908
3116
  function subscribe(xs) {
@@ -2912,13 +3120,13 @@
2912
3120
  // Check for promises support
2913
3121
  isPromise(xs) && (xs = observableFromPromise(xs));
2914
3122
 
2915
- subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
3123
+ subscription.setDisposable(xs.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
2916
3124
  group.remove(subscription);
2917
3125
  if (q.length > 0) {
2918
3126
  subscribe(q.shift());
2919
3127
  } else {
2920
3128
  activeCount--;
2921
- isStopped && activeCount === 0 && observer.onCompleted();
3129
+ isStopped && activeCount === 0 && o.onCompleted();
2922
3130
  }
2923
3131
  }));
2924
3132
  }
@@ -2929,9 +3137,9 @@
2929
3137
  } else {
2930
3138
  q.push(innerSource);
2931
3139
  }
2932
- }, observer.onError.bind(observer), function () {
3140
+ }, function (e) { o.onError(e); }, function () {
2933
3141
  isStopped = true;
2934
- activeCount === 0 && observer.onCompleted();
3142
+ activeCount === 0 && o.onCompleted();
2935
3143
  }));
2936
3144
  return group;
2937
3145
  }, sources);
@@ -2943,16 +3151,16 @@
2943
3151
  * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
2944
3152
  */
2945
3153
  var observableMerge = Observable.merge = function () {
2946
- var scheduler, sources;
3154
+ var scheduler, sources = [], i, len = arguments.length;
2947
3155
  if (!arguments[0]) {
2948
3156
  scheduler = immediateScheduler;
2949
- sources = slice.call(arguments, 1);
3157
+ for(i = 1; i < len; i++) { sources.push(arguments[i]); }
2950
3158
  } else if (isScheduler(arguments[0])) {
2951
3159
  scheduler = arguments[0];
2952
- sources = slice.call(arguments, 1);
3160
+ for(i = 1; i < len; i++) { sources.push(arguments[i]); }
2953
3161
  } else {
2954
3162
  scheduler = immediateScheduler;
2955
- sources = slice.call(arguments, 0);
3163
+ for(i = 0; i < len; i++) { sources.push(arguments[i]); }
2956
3164
  }
2957
3165
  if (Array.isArray(sources[0])) {
2958
3166
  sources = sources[0];
@@ -2964,9 +3172,9 @@
2964
3172
  * Merges an observable sequence of observable sequences into an observable sequence.
2965
3173
  * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2966
3174
  */
2967
- observableProto.mergeAll = function () {
3175
+ observableProto.mergeAll = observableProto.mergeObservable = function () {
2968
3176
  var sources = this;
2969
- return new AnonymousObservable(function (observer) {
3177
+ return new AnonymousObservable(function (o) {
2970
3178
  var group = new CompositeDisposable(),
2971
3179
  isStopped = false,
2972
3180
  m = new SingleAssignmentDisposable();
@@ -2979,26 +3187,18 @@
2979
3187
  // Check for promises support
2980
3188
  isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
2981
3189
 
2982
- innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
3190
+ innerSubscription.setDisposable(innerSource.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
2983
3191
  group.remove(innerSubscription);
2984
- isStopped && group.length === 1 && observer.onCompleted();
3192
+ isStopped && group.length === 1 && o.onCompleted();
2985
3193
  }));
2986
- }, observer.onError.bind(observer), function () {
3194
+ }, function (e) { o.onError(e); }, function () {
2987
3195
  isStopped = true;
2988
- group.length === 1 && observer.onCompleted();
3196
+ group.length === 1 && o.onCompleted();
2989
3197
  }));
2990
3198
  return group;
2991
3199
  }, sources);
2992
3200
  };
2993
3201
 
2994
- /**
2995
- * @deprecated use #mergeAll instead.
2996
- */
2997
- observableProto.mergeObservable = function () {
2998
- deprecate('mergeObservable', 'mergeAll');
2999
- return this.mergeAll.apply(this, arguments);
3000
- };
3001
-
3002
3202
  /**
3003
3203
  * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
3004
3204
  * @param {Observable} second Second observable sequence used to produce results after the first sequence terminates.
@@ -3018,7 +3218,12 @@
3018
3218
  * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
3019
3219
  */
3020
3220
  var onErrorResumeNext = Observable.onErrorResumeNext = function () {
3021
- var sources = argsOrArray(arguments, 0);
3221
+ var sources = [];
3222
+ if (Array.isArray(arguments[0])) {
3223
+ sources = arguments[0];
3224
+ } else {
3225
+ for(var i = 0, len = arguments.length; i < len; i++) { sources.push(arguments[i]); }
3226
+ }
3022
3227
  return new AnonymousObservable(function (observer) {
3023
3228
  var pos = 0, subscription = new SerialDisposable(),
3024
3229
  cancelable = immediateScheduler.scheduleRecursive(function (self) {
@@ -3044,12 +3249,12 @@
3044
3249
  */
3045
3250
  observableProto.skipUntil = function (other) {
3046
3251
  var source = this;
3047
- return new AnonymousObservable(function (observer) {
3252
+ return new AnonymousObservable(function (o) {
3048
3253
  var isOpen = false;
3049
3254
  var disposables = new CompositeDisposable(source.subscribe(function (left) {
3050
- isOpen && observer.onNext(left);
3051
- }, observer.onError.bind(observer), function () {
3052
- isOpen && observer.onCompleted();
3255
+ isOpen && o.onNext(left);
3256
+ }, function (e) { o.onError(e); }, function () {
3257
+ isOpen && o.onCompleted();
3053
3258
  }));
3054
3259
 
3055
3260
  isPromise(other) && (other = observableFromPromise(other));
@@ -3059,7 +3264,7 @@
3059
3264
  rightSubscription.setDisposable(other.subscribe(function () {
3060
3265
  isOpen = true;
3061
3266
  rightSubscription.dispose();
3062
- }, observer.onError.bind(observer), function () {
3267
+ }, function (e) { o.onError(e); }, function () {
3063
3268
  rightSubscription.dispose();
3064
3269
  }));
3065
3270
 
@@ -3097,7 +3302,7 @@
3097
3302
  }
3098
3303
  }));
3099
3304
  },
3100
- observer.onError.bind(observer),
3305
+ function (e) { observer.onError(e); },
3101
3306
  function () {
3102
3307
  isStopped = true;
3103
3308
  !hasLatest && observer.onCompleted();
@@ -3113,15 +3318,79 @@
3113
3318
  */
3114
3319
  observableProto.takeUntil = function (other) {
3115
3320
  var source = this;
3116
- return new AnonymousObservable(function (observer) {
3321
+ return new AnonymousObservable(function (o) {
3117
3322
  isPromise(other) && (other = observableFromPromise(other));
3118
3323
  return new CompositeDisposable(
3119
- source.subscribe(observer),
3120
- other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
3324
+ source.subscribe(o),
3325
+ other.subscribe(function () { o.onCompleted(); }, function (e) { o.onError(e); }, noop)
3121
3326
  );
3122
3327
  }, source);
3123
3328
  };
3124
3329
 
3330
+ /**
3331
+ * Merges the specified observable sequences into one observable sequence by using the selector function only when the (first) source observable sequence produces an element.
3332
+ *
3333
+ * @example
3334
+ * 1 - obs = obs1.withLatestFrom(obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
3335
+ * 2 - obs = obs1.withLatestFrom([obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
3336
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3337
+ */
3338
+ observableProto.withLatestFrom = function () {
3339
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3340
+ var resultSelector = args.pop(), source = this;
3341
+
3342
+ if (typeof source === 'undefined') {
3343
+ throw new Error('Source observable not found for withLatestFrom().');
3344
+ }
3345
+ if (typeof resultSelector !== 'function') {
3346
+ throw new Error('withLatestFrom() expects a resultSelector function.');
3347
+ }
3348
+ if (Array.isArray(args[0])) {
3349
+ args = args[0];
3350
+ }
3351
+
3352
+ return new AnonymousObservable(function (observer) {
3353
+ var falseFactory = function () { return false; },
3354
+ n = args.length,
3355
+ hasValue = arrayInitialize(n, falseFactory),
3356
+ hasValueAll = false,
3357
+ values = new Array(n);
3358
+
3359
+ var subscriptions = new Array(n + 1);
3360
+ for (var idx = 0; idx < n; idx++) {
3361
+ (function (i) {
3362
+ var other = args[i], sad = new SingleAssignmentDisposable();
3363
+ isPromise(other) && (other = observableFromPromise(other));
3364
+ sad.setDisposable(other.subscribe(function (x) {
3365
+ values[i] = x;
3366
+ hasValue[i] = true;
3367
+ hasValueAll = hasValue.every(identity);
3368
+ }, observer.onError.bind(observer), function () {}));
3369
+ subscriptions[i] = sad;
3370
+ }(idx));
3371
+ }
3372
+
3373
+ var sad = new SingleAssignmentDisposable();
3374
+ sad.setDisposable(source.subscribe(function (x) {
3375
+ var res;
3376
+ var allValues = [x].concat(values);
3377
+ if (!hasValueAll) return;
3378
+ try {
3379
+ res = resultSelector.apply(null, allValues);
3380
+ } catch (ex) {
3381
+ observer.onError(ex);
3382
+ return;
3383
+ }
3384
+ observer.onNext(res);
3385
+ }, observer.onError.bind(observer), function () {
3386
+ observer.onCompleted();
3387
+ }));
3388
+ subscriptions[n] = sad;
3389
+
3390
+ return new CompositeDisposable(subscriptions);
3391
+ }, this);
3392
+ };
3393
+
3125
3394
  function zipArray(second, resultSelector) {
3126
3395
  var first = this;
3127
3396
  return new AnonymousObservable(function (observer) {
@@ -3132,36 +3401,39 @@
3132
3401
  try {
3133
3402
  result = resultSelector(left, right);
3134
3403
  } catch (e) {
3135
- observer.onError(e);
3136
- return;
3404
+ return observer.onError(e);
3137
3405
  }
3138
3406
  observer.onNext(result);
3139
3407
  } else {
3140
3408
  observer.onCompleted();
3141
3409
  }
3142
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3410
+ }, function (e) { observer.onError(e); }, function () { observer.onCompleted(); });
3143
3411
  }, first);
3144
3412
  }
3145
3413
 
3414
+ function falseFactory() { return false; }
3415
+ function emptyArrayFactory() { return []; }
3416
+
3146
3417
  /**
3147
3418
  * Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences or an array have produced an element at a corresponding index.
3148
- * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
3419
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
3149
3420
  *
3150
3421
  * @example
3151
3422
  * 1 - res = obs1.zip(obs2, fn);
3152
3423
  * 1 - res = x1.zip([1,2,3], fn);
3153
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3424
+ * @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
3154
3425
  */
3155
3426
  observableProto.zip = function () {
3156
- if (Array.isArray(arguments[0])) {
3157
- return zipArray.apply(this, arguments);
3158
- }
3159
- var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
3160
- sources.unshift(parent);
3427
+ if (Array.isArray(arguments[0])) { return zipArray.apply(this, arguments); }
3428
+ var len = arguments.length, args = new Array(len);
3429
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3430
+
3431
+ var parent = this, resultSelector = args.pop();
3432
+ args.unshift(parent);
3161
3433
  return new AnonymousObservable(function (observer) {
3162
- var n = sources.length,
3163
- queues = arrayInitialize(n, function () { return []; }),
3164
- isDone = arrayInitialize(n, function () { return false; });
3434
+ var n = args.length,
3435
+ queues = arrayInitialize(n, emptyArrayFactory),
3436
+ isDone = arrayInitialize(n, falseFactory);
3165
3437
 
3166
3438
  function next(i) {
3167
3439
  var res, queuedValues;
@@ -3189,12 +3461,12 @@
3189
3461
  var subscriptions = new Array(n);
3190
3462
  for (var idx = 0; idx < n; idx++) {
3191
3463
  (function (i) {
3192
- var source = sources[i], sad = new SingleAssignmentDisposable();
3464
+ var source = args[i], sad = new SingleAssignmentDisposable();
3193
3465
  isPromise(source) && (source = observableFromPromise(source));
3194
3466
  sad.setDisposable(source.subscribe(function (x) {
3195
3467
  queues[i].push(x);
3196
3468
  next(i);
3197
- }, observer.onError.bind(observer), function () {
3469
+ }, function (e) { observer.onError(e); }, function () {
3198
3470
  done(i);
3199
3471
  }));
3200
3472
  subscriptions[i] = sad;
@@ -3212,7 +3484,9 @@
3212
3484
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3213
3485
  */
3214
3486
  Observable.zip = function () {
3215
- var args = slice.call(arguments, 0), first = args.shift();
3487
+ var len = arguments.length, args = new Array(len);
3488
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3489
+ var first = args.shift();
3216
3490
  return first.zip.apply(first, args);
3217
3491
  };
3218
3492
 
@@ -3222,7 +3496,14 @@
3222
3496
  * @returns {Observable} An observable sequence containing lists of elements at corresponding indexes.
3223
3497
  */
3224
3498
  Observable.zipArray = function () {
3225
- var sources = argsOrArray(arguments, 0);
3499
+ var sources;
3500
+ if (Array.isArray(arguments[0])) {
3501
+ sources = arguments[0];
3502
+ } else {
3503
+ var len = arguments.length;
3504
+ sources = new Array(len);
3505
+ for(var i = 0; i < len; i++) { sources[i] = arguments[i]; }
3506
+ }
3226
3507
  return new AnonymousObservable(function (observer) {
3227
3508
  var n = sources.length,
3228
3509
  queues = arrayInitialize(n, function () { return []; }),
@@ -3253,17 +3534,13 @@
3253
3534
  subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
3254
3535
  queues[i].push(x);
3255
3536
  next(i);
3256
- }, observer.onError.bind(observer), function () {
3537
+ }, function (e) { observer.onError(e); }, function () {
3257
3538
  done(i);
3258
3539
  }));
3259
3540
  })(idx);
3260
3541
  }
3261
3542
 
3262
- var compositeDisposable = new CompositeDisposable(subscriptions);
3263
- compositeDisposable.add(disposableCreate(function () {
3264
- for (var qIdx = 0, qLen = queues.length; qIdx < qLen; qIdx++) { queues[qIdx] = []; }
3265
- }));
3266
- return compositeDisposable;
3543
+ return new CompositeDisposable(subscriptions);
3267
3544
  });
3268
3545
  };
3269
3546
 
@@ -3272,7 +3549,8 @@
3272
3549
  * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3273
3550
  */
3274
3551
  observableProto.asObservable = function () {
3275
- return new AnonymousObservable(this.subscribe.bind(this), this);
3552
+ var source = this;
3553
+ return new AnonymousObservable(function (o) { return source.subscribe(o); }, this);
3276
3554
  };
3277
3555
 
3278
3556
  /**
@@ -3302,8 +3580,8 @@
3302
3580
  */
3303
3581
  observableProto.dematerialize = function () {
3304
3582
  var source = this;
3305
- return new AnonymousObservable(function (observer) {
3306
- return source.subscribe(function (x) { return x.accept(observer); }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3583
+ return new AnonymousObservable(function (o) {
3584
+ return source.subscribe(function (x) { return x.accept(o); }, function(e) { o.onError(e); }, function () { o.onCompleted(); });
3307
3585
  }, this);
3308
3586
  };
3309
3587
 
@@ -3320,32 +3598,33 @@
3320
3598
  */
3321
3599
  observableProto.distinctUntilChanged = function (keySelector, comparer) {
3322
3600
  var source = this;
3323
- keySelector || (keySelector = identity);
3324
3601
  comparer || (comparer = defaultComparer);
3325
- return new AnonymousObservable(function (observer) {
3602
+ return new AnonymousObservable(function (o) {
3326
3603
  var hasCurrentKey = false, currentKey;
3327
3604
  return source.subscribe(function (value) {
3328
- var comparerEquals = false, key;
3605
+ var key = value;
3606
+ if (keySelector) {
3329
3607
  try {
3330
3608
  key = keySelector(value);
3331
3609
  } catch (e) {
3332
- observer.onError(e);
3610
+ o.onError(e);
3333
3611
  return;
3334
3612
  }
3335
- if (hasCurrentKey) {
3336
- try {
3337
- comparerEquals = comparer(currentKey, key);
3338
- } catch (e) {
3339
- observer.onError(e);
3340
- return;
3341
- }
3342
- }
3343
- if (!hasCurrentKey || !comparerEquals) {
3344
- hasCurrentKey = true;
3345
- currentKey = key;
3346
- observer.onNext(value);
3613
+ }
3614
+ if (hasCurrentKey) {
3615
+ try {
3616
+ var comparerEquals = comparer(currentKey, key);
3617
+ } catch (e) {
3618
+ o.onError(e);
3619
+ return;
3347
3620
  }
3348
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3621
+ }
3622
+ if (!hasCurrentKey || !comparerEquals) {
3623
+ hasCurrentKey = true;
3624
+ currentKey = key;
3625
+ o.onNext(value);
3626
+ }
3627
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3349
3628
  }, this);
3350
3629
  };
3351
3630
 
@@ -3357,51 +3636,36 @@
3357
3636
  * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
3358
3637
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3359
3638
  */
3360
- observableProto['do'] = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3361
- var source = this, onNextFunc;
3362
- if (typeof observerOrOnNext === 'function') {
3363
- onNextFunc = observerOrOnNext;
3364
- } else {
3365
- onNextFunc = observerOrOnNext.onNext.bind(observerOrOnNext);
3366
- onError = observerOrOnNext.onError.bind(observerOrOnNext);
3367
- onCompleted = observerOrOnNext.onCompleted.bind(observerOrOnNext);
3368
- }
3639
+ observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
3640
+ var source = this, tapObserver = typeof observerOrOnNext === 'function' || typeof observerOrOnNext === 'undefined'?
3641
+ observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
3642
+ observerOrOnNext;
3369
3643
  return new AnonymousObservable(function (observer) {
3370
3644
  return source.subscribe(function (x) {
3371
3645
  try {
3372
- onNextFunc(x);
3646
+ tapObserver.onNext(x);
3373
3647
  } catch (e) {
3374
3648
  observer.onError(e);
3375
3649
  }
3376
3650
  observer.onNext(x);
3377
3651
  }, function (err) {
3378
- if (onError) {
3379
3652
  try {
3380
- onError(err);
3653
+ tapObserver.onError(err);
3381
3654
  } catch (e) {
3382
3655
  observer.onError(e);
3383
3656
  }
3384
- }
3385
3657
  observer.onError(err);
3386
3658
  }, function () {
3387
- if (onCompleted) {
3388
- try {
3389
- onCompleted();
3390
- } catch (e) {
3391
- observer.onError(e);
3392
- }
3659
+ try {
3660
+ tapObserver.onCompleted();
3661
+ } catch (e) {
3662
+ observer.onError(e);
3393
3663
  }
3394
3664
  observer.onCompleted();
3395
3665
  });
3396
3666
  }, this);
3397
3667
  };
3398
3668
 
3399
- /** @deprecated use #do or #tap instead. */
3400
- observableProto.doAction = function () {
3401
- deprecate('doAction', 'do or tap');
3402
- return this.tap.apply(this, arguments);
3403
- };
3404
-
3405
3669
  /**
3406
3670
  * Invokes an action for each element in the observable sequence.
3407
3671
  * This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
@@ -3410,7 +3674,7 @@
3410
3674
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3411
3675
  */
3412
3676
  observableProto.doOnNext = observableProto.tapOnNext = function (onNext, thisArg) {
3413
- return this.tap(arguments.length === 2 ? function (x) { onNext.call(thisArg, x); } : onNext);
3677
+ return this.tap(typeof thisArg !== 'undefined' ? function (x) { onNext.call(thisArg, x); } : onNext);
3414
3678
  };
3415
3679
 
3416
3680
  /**
@@ -3421,7 +3685,7 @@
3421
3685
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3422
3686
  */
3423
3687
  observableProto.doOnError = observableProto.tapOnError = function (onError, thisArg) {
3424
- return this.tap(noop, arguments.length === 2 ? function (e) { onError.call(thisArg, e); } : onError);
3688
+ return this.tap(noop, typeof thisArg !== 'undefined' ? function (e) { onError.call(thisArg, e); } : onError);
3425
3689
  };
3426
3690
 
3427
3691
  /**
@@ -3432,7 +3696,7 @@
3432
3696
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3433
3697
  */
3434
3698
  observableProto.doOnCompleted = observableProto.tapOnCompleted = function (onCompleted, thisArg) {
3435
- return this.tap(noop, null, arguments.length === 2 ? function () { onCompleted.call(thisArg); } : onCompleted);
3699
+ return this.tap(noop, null, typeof thisArg !== 'undefined' ? function () { onCompleted.call(thisArg); } : onCompleted);
3436
3700
  };
3437
3701
 
3438
3702
  /**
@@ -3466,7 +3730,7 @@
3466
3730
  * @deprecated use #finally or #ensure instead.
3467
3731
  */
3468
3732
  observableProto.finallyAction = function (action) {
3469
- deprecate('finallyAction', 'finally or ensure');
3733
+ //deprecate('finallyAction', 'finally or ensure');
3470
3734
  return this.ensure(action);
3471
3735
  };
3472
3736
 
@@ -3476,8 +3740,8 @@
3476
3740
  */
3477
3741
  observableProto.ignoreElements = function () {
3478
3742
  var source = this;
3479
- return new AnonymousObservable(function (observer) {
3480
- return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3743
+ return new AnonymousObservable(function (o) {
3744
+ return source.subscribe(noop, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3481
3745
  }, source);
3482
3746
  };
3483
3747
 
@@ -3523,6 +3787,19 @@
3523
3787
  return enumerableRepeat(this, retryCount).catchError();
3524
3788
  };
3525
3789
 
3790
+ /**
3791
+ * Repeats the source observable sequence upon error each time the notifier emits or until it successfully terminates.
3792
+ * if the notifier completes, the observable sequence completes.
3793
+ *
3794
+ * @example
3795
+ * var timer = Observable.timer(500);
3796
+ * var source = observable.retryWhen(timer);
3797
+ * @param {Observable} [notifier] An observable that triggers the retries or completes the observable with onNext or onCompleted respectively.
3798
+ * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3799
+ */
3800
+ observableProto.retryWhen = function (notifier) {
3801
+ return enumerableRepeat(this).catchErrorWhen(notifier);
3802
+ };
3526
3803
  /**
3527
3804
  * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3528
3805
  * For aggregation behavior with no intermediate results, see Observable.aggregate.
@@ -3542,7 +3819,7 @@
3542
3819
  } else {
3543
3820
  accumulator = arguments[0];
3544
3821
  }
3545
- return new AnonymousObservable(function (observer) {
3822
+ return new AnonymousObservable(function (o) {
3546
3823
  var hasAccumulation, accumulation, hasValue;
3547
3824
  return source.subscribe (
3548
3825
  function (x) {
@@ -3555,16 +3832,16 @@
3555
3832
  hasAccumulation = true;
3556
3833
  }
3557
3834
  } catch (e) {
3558
- observer.onError(e);
3835
+ o.onError(e);
3559
3836
  return;
3560
3837
  }
3561
3838
 
3562
- observer.onNext(accumulation);
3839
+ o.onNext(accumulation);
3563
3840
  },
3564
- observer.onError.bind(observer),
3841
+ function (e) { o.onError(e); },
3565
3842
  function () {
3566
- !hasValue && hasSeed && observer.onNext(seed);
3567
- observer.onCompleted();
3843
+ !hasValue && hasSeed && o.onNext(seed);
3844
+ o.onCompleted();
3568
3845
  }
3569
3846
  );
3570
3847
  }, source);
@@ -3580,12 +3857,12 @@
3580
3857
  */
3581
3858
  observableProto.skipLast = function (count) {
3582
3859
  var source = this;
3583
- return new AnonymousObservable(function (observer) {
3860
+ return new AnonymousObservable(function (o) {
3584
3861
  var q = [];
3585
3862
  return source.subscribe(function (x) {
3586
3863
  q.push(x);
3587
- q.length > count && observer.onNext(q.shift());
3588
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3864
+ q.length > count && o.onNext(q.shift());
3865
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3589
3866
  }, source);
3590
3867
  };
3591
3868
 
@@ -3605,8 +3882,8 @@
3605
3882
  } else {
3606
3883
  scheduler = immediateScheduler;
3607
3884
  }
3608
- values = slice.call(arguments, start);
3609
- return enumerableOf([observableFromArray(values, scheduler), this]).concat();
3885
+ for(var args = [], i = start, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3886
+ return enumerableOf([observableFromArray(args, scheduler), this]).concat();
3610
3887
  };
3611
3888
 
3612
3889
  /**
@@ -3619,14 +3896,14 @@
3619
3896
  */
3620
3897
  observableProto.takeLast = function (count) {
3621
3898
  var source = this;
3622
- return new AnonymousObservable(function (observer) {
3899
+ return new AnonymousObservable(function (o) {
3623
3900
  var q = [];
3624
3901
  return source.subscribe(function (x) {
3625
3902
  q.push(x);
3626
3903
  q.length > count && q.shift();
3627
- }, observer.onError.bind(observer), function () {
3628
- while (q.length > 0) { observer.onNext(q.shift()); }
3629
- observer.onCompleted();
3904
+ }, function (e) { o.onError(e); }, function () {
3905
+ while (q.length > 0) { o.onNext(q.shift()); }
3906
+ o.onCompleted();
3630
3907
  });
3631
3908
  }, source);
3632
3909
  };
@@ -3642,14 +3919,14 @@
3642
3919
  */
3643
3920
  observableProto.takeLastBuffer = function (count) {
3644
3921
  var source = this;
3645
- return new AnonymousObservable(function (observer) {
3922
+ return new AnonymousObservable(function (o) {
3646
3923
  var q = [];
3647
3924
  return source.subscribe(function (x) {
3648
3925
  q.push(x);
3649
3926
  q.length > count && q.shift();
3650
- }, observer.onError.bind(observer), function () {
3651
- observer.onNext(q);
3652
- observer.onCompleted();
3927
+ }, function (e) { o.onError(e); }, function () {
3928
+ o.onNext(q);
3929
+ o.onCompleted();
3653
3930
  });
3654
3931
  }, source);
3655
3932
  };
@@ -3708,8 +3985,9 @@
3708
3985
  };
3709
3986
 
3710
3987
  function concatMap(source, selector, thisArg) {
3988
+ var selectorFunc = bindCallback(selector, thisArg, 3);
3711
3989
  return source.map(function (x, i) {
3712
- var result = selector.call(thisArg, x, i, source);
3990
+ var result = selectorFunc(x, i, source);
3713
3991
  isPromise(result) && (result = observableFromPromise(result));
3714
3992
  (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3715
3993
  return result;
@@ -3761,15 +4039,17 @@
3761
4039
  * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence.
3762
4040
  */
3763
4041
  observableProto.concatMapObserver = observableProto.selectConcatObserver = function(onNext, onError, onCompleted, thisArg) {
3764
- var source = this;
4042
+ var source = this,
4043
+ onNextFunc = bindCallback(onNext, thisArg, 2),
4044
+ onErrorFunc = bindCallback(onError, thisArg, 1),
4045
+ onCompletedFunc = bindCallback(onCompleted, thisArg, 0);
3765
4046
  return new AnonymousObservable(function (observer) {
3766
4047
  var index = 0;
3767
-
3768
4048
  return source.subscribe(
3769
4049
  function (x) {
3770
4050
  var result;
3771
4051
  try {
3772
- result = onNext.call(thisArg, x, index++);
4052
+ result = onNextFunc(x, index++);
3773
4053
  } catch (e) {
3774
4054
  observer.onError(e);
3775
4055
  return;
@@ -3780,7 +4060,7 @@
3780
4060
  function (err) {
3781
4061
  var result;
3782
4062
  try {
3783
- result = onError.call(thisArg, err);
4063
+ result = onErrorFunc(err);
3784
4064
  } catch (e) {
3785
4065
  observer.onError(e);
3786
4066
  return;
@@ -3792,7 +4072,7 @@
3792
4072
  function () {
3793
4073
  var result;
3794
4074
  try {
3795
- result = onCompleted.call(thisArg);
4075
+ result = onCompletedFunc();
3796
4076
  } catch (e) {
3797
4077
  observer.onError(e);
3798
4078
  return;
@@ -3822,11 +4102,13 @@
3822
4102
  return source.subscribe(function (x) {
3823
4103
  found = true;
3824
4104
  observer.onNext(x);
3825
- }, observer.onError.bind(observer), function () {
4105
+ },
4106
+ function (e) { observer.onError(e); },
4107
+ function () {
3826
4108
  !found && observer.onNext(defaultValue);
3827
4109
  observer.onCompleted();
3828
4110
  });
3829
- }, this);
4111
+ }, source);
3830
4112
  };
3831
4113
 
3832
4114
  // Swap out for Array.findIndex
@@ -3862,7 +4144,7 @@
3862
4144
  observableProto.distinct = function (keySelector, comparer) {
3863
4145
  var source = this;
3864
4146
  comparer || (comparer = defaultComparer);
3865
- return new AnonymousObservable(function (observer) {
4147
+ return new AnonymousObservable(function (o) {
3866
4148
  var hashSet = new HashSet(comparer);
3867
4149
  return source.subscribe(function (x) {
3868
4150
  var key = x;
@@ -3871,48 +4153,106 @@
3871
4153
  try {
3872
4154
  key = keySelector(x);
3873
4155
  } catch (e) {
3874
- observer.onError(e);
4156
+ o.onError(e);
3875
4157
  return;
3876
4158
  }
3877
4159
  }
3878
- hashSet.push(key) && observer.onNext(x);
4160
+ hashSet.push(key) && o.onNext(x);
3879
4161
  },
3880
- observer.onError.bind(observer),
3881
- observer.onCompleted.bind(observer));
4162
+ function (e) { o.onError(e); }, function () { o.onCompleted(); });
3882
4163
  }, this);
3883
4164
  };
3884
4165
 
4166
+ var MapObservable = (function (__super__) {
4167
+ inherits(MapObservable, __super__);
4168
+
4169
+ function MapObservable(source, selector, thisArg) {
4170
+ this.source = source;
4171
+ this.selector = bindCallback(selector, thisArg, 3);
4172
+ __super__.call(this);
4173
+ }
4174
+
4175
+ MapObservable.prototype.internalMap = function (selector, thisArg) {
4176
+ var self = this;
4177
+ return new MapObservable(this.source, function (x, i, o) { return selector(self.selector(x, i, o), i, o); }, thisArg)
4178
+ };
4179
+
4180
+ MapObservable.prototype.subscribeCore = function (observer) {
4181
+ return this.source.subscribe(new MapObserver(observer, this.selector, this));
4182
+ };
4183
+
4184
+ return MapObservable;
4185
+
4186
+ }(ObservableBase));
4187
+
4188
+ function MapObserver(observer, selector, source) {
4189
+ this.observer = observer;
4190
+ this.selector = selector;
4191
+ this.source = source;
4192
+ this.i = 0;
4193
+ this.isStopped = false;
4194
+ }
4195
+
4196
+ MapObserver.prototype.onNext = function(x) {
4197
+ if (this.isStopped) { return; }
4198
+ try {
4199
+ var result = this.selector(x, this.i++, this.source);
4200
+ } catch (e) {
4201
+ return this.observer.onError(e);
4202
+ }
4203
+ this.observer.onNext(result);
4204
+ };
4205
+ MapObserver.prototype.onError = function (e) {
4206
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4207
+ };
4208
+ MapObserver.prototype.onCompleted = function () {
4209
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4210
+ };
4211
+ MapObserver.prototype.dispose = function() { this.isStopped = true; };
4212
+ MapObserver.prototype.fail = function (e) {
4213
+ if (!this.isStopped) {
4214
+ this.isStopped = true;
4215
+ this.observer.onError(e);
4216
+ return true;
4217
+ }
4218
+
4219
+ return false;
4220
+ };
4221
+
3885
4222
  /**
3886
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
3887
- * @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
3888
- * @param {Any} [thisArg] Object to use as this when executing callback.
3889
- * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
3890
- */
3891
- observableProto.select = observableProto.map = function (selector, thisArg) {
3892
- var selectorFn = isFunction(selector) ? selector : function () { return selector; },
3893
- source = this;
3894
- return new AnonymousObservable(function (observer) {
3895
- var count = 0;
3896
- return source.subscribe(function (value) {
3897
- var result;
3898
- try {
3899
- result = selectorFn.call(thisArg, value, count++, source);
3900
- } catch (e) {
3901
- observer.onError(e);
3902
- return;
3903
- }
3904
- observer.onNext(result);
3905
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3906
- }, source);
4223
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
4224
+ * @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
4225
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4226
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
4227
+ */
4228
+ observableProto.map = observableProto.select = function (selector, thisArg) {
4229
+ var selectorFn = typeof selector === 'function' ? selector : function () { return selector; };
4230
+ return this instanceof MapObservable ?
4231
+ this.internalMap(selectorFn, thisArg) :
4232
+ new MapObservable(this, selectorFn, thisArg);
3907
4233
  };
3908
4234
 
3909
4235
  /**
3910
- * Retrieves the value of a specified property from all elements in the Observable sequence.
3911
- * @param {String} prop The property to pluck.
4236
+ * Retrieves the value of a specified nested property from all elements in
4237
+ * the Observable sequence.
4238
+ * @param {Arguments} arguments The nested properties to pluck.
3912
4239
  * @returns {Observable} Returns a new Observable sequence of property values.
3913
4240
  */
3914
- observableProto.pluck = function (prop) {
3915
- return this.map(function (x) { return x[prop]; });
4241
+ observableProto.pluck = function () {
4242
+ var args = arguments, len = arguments.length;
4243
+ if (len === 0) { throw new Error('List of properties cannot be empty.'); }
4244
+ return this.map(function (x) {
4245
+ var currentProp = x;
4246
+ for (var i = 0; i < len; i++) {
4247
+ var p = currentProp[args[i]];
4248
+ if (typeof p !== 'undefined') {
4249
+ currentProp = p;
4250
+ } else {
4251
+ return undefined;
4252
+ }
4253
+ }
4254
+ return currentProp;
4255
+ });
3916
4256
  };
3917
4257
 
3918
4258
  /**
@@ -3968,8 +4308,9 @@
3968
4308
  };
3969
4309
 
3970
4310
  function flatMap(source, selector, thisArg) {
4311
+ var selectorFunc = bindCallback(selector, thisArg, 3);
3971
4312
  return source.map(function (x, i) {
3972
- var result = selector.call(thisArg, x, i, source);
4313
+ var result = selectorFunc(x, i, source);
3973
4314
  isPromise(result) && (result = observableFromPromise(result));
3974
4315
  (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3975
4316
  return result;
@@ -4032,15 +4373,15 @@
4032
4373
  observableProto.skip = function (count) {
4033
4374
  if (count < 0) { throw new Error(argumentOutOfRange); }
4034
4375
  var source = this;
4035
- return new AnonymousObservable(function (observer) {
4376
+ return new AnonymousObservable(function (o) {
4036
4377
  var remaining = count;
4037
4378
  return source.subscribe(function (x) {
4038
4379
  if (remaining <= 0) {
4039
- observer.onNext(x);
4380
+ o.onNext(x);
4040
4381
  } else {
4041
4382
  remaining--;
4042
4383
  }
4043
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4384
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4044
4385
  }, source);
4045
4386
  };
4046
4387
 
@@ -4055,20 +4396,21 @@
4055
4396
  * @returns {Observable} An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
4056
4397
  */
4057
4398
  observableProto.skipWhile = function (predicate, thisArg) {
4058
- var source = this;
4059
- return new AnonymousObservable(function (observer) {
4399
+ var source = this,
4400
+ callback = bindCallback(predicate, thisArg, 3);
4401
+ return new AnonymousObservable(function (o) {
4060
4402
  var i = 0, running = false;
4061
4403
  return source.subscribe(function (x) {
4062
4404
  if (!running) {
4063
4405
  try {
4064
- running = !predicate.call(thisArg, x, i++, source);
4406
+ running = !callback(x, i++, source);
4065
4407
  } catch (e) {
4066
- observer.onError(e);
4408
+ o.onError(e);
4067
4409
  return;
4068
4410
  }
4069
4411
  }
4070
- running && observer.onNext(x);
4071
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4412
+ running && o.onNext(x);
4413
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4072
4414
  }, source);
4073
4415
  };
4074
4416
 
@@ -4085,14 +4427,14 @@
4085
4427
  if (count < 0) { throw new RangeError(argumentOutOfRange); }
4086
4428
  if (count === 0) { return observableEmpty(scheduler); }
4087
4429
  var source = this;
4088
- return new AnonymousObservable(function (observer) {
4430
+ return new AnonymousObservable(function (o) {
4089
4431
  var remaining = count;
4090
4432
  return source.subscribe(function (x) {
4091
4433
  if (remaining-- > 0) {
4092
- observer.onNext(x);
4093
- remaining === 0 && observer.onCompleted();
4434
+ o.onNext(x);
4435
+ remaining === 0 && o.onCompleted();
4094
4436
  }
4095
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4437
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4096
4438
  }, source);
4097
4439
  };
4098
4440
 
@@ -4104,52 +4446,92 @@
4104
4446
  * @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
4105
4447
  */
4106
4448
  observableProto.takeWhile = function (predicate, thisArg) {
4107
- var source = this;
4108
- return new AnonymousObservable(function (observer) {
4449
+ var source = this,
4450
+ callback = bindCallback(predicate, thisArg, 3);
4451
+ return new AnonymousObservable(function (o) {
4109
4452
  var i = 0, running = true;
4110
4453
  return source.subscribe(function (x) {
4111
4454
  if (running) {
4112
4455
  try {
4113
- running = predicate.call(thisArg, x, i++, source);
4456
+ running = callback(x, i++, source);
4114
4457
  } catch (e) {
4115
- observer.onError(e);
4458
+ o.onError(e);
4116
4459
  return;
4117
4460
  }
4118
4461
  if (running) {
4119
- observer.onNext(x);
4462
+ o.onNext(x);
4120
4463
  } else {
4121
- observer.onCompleted();
4464
+ o.onCompleted();
4122
4465
  }
4123
4466
  }
4124
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4467
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4125
4468
  }, source);
4126
4469
  };
4127
4470
 
4471
+ var FilterObservable = (function (__super__) {
4472
+ inherits(FilterObservable, __super__);
4473
+
4474
+ function FilterObservable(source, predicate, thisArg) {
4475
+ this.source = source;
4476
+ this.predicate = bindCallback(predicate, thisArg, 3);
4477
+ __super__.call(this);
4478
+ }
4479
+
4480
+ FilterObservable.prototype.subscribeCore = function (observer) {
4481
+ return this.source.subscribe(new FilterObserver(observer, this.predicate, this));
4482
+ };
4483
+
4484
+ FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
4485
+ var self = this;
4486
+ return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate(x, i, o); }, thisArg);
4487
+ };
4488
+
4489
+ return FilterObservable;
4490
+
4491
+ }(ObservableBase));
4492
+
4493
+ function FilterObserver(observer, predicate, source) {
4494
+ this.observer = observer;
4495
+ this.predicate = predicate;
4496
+ this.source = source;
4497
+ this.i = 0;
4498
+ this.isStopped = false;
4499
+ }
4500
+
4501
+ FilterObserver.prototype.onNext = function(x) {
4502
+ if (this.isStopped) { return; }
4503
+ try {
4504
+ var shouldYield = this.predicate(x, this.i++, this.source);
4505
+ } catch (e) {
4506
+ return this.observer.onError(e);
4507
+ }
4508
+ shouldYield && this.observer.onNext(x);
4509
+ };
4510
+ FilterObserver.prototype.onError = function (e) {
4511
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4512
+ };
4513
+ FilterObserver.prototype.onCompleted = function () {
4514
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4515
+ };
4516
+ FilterObserver.prototype.dispose = function() { this.isStopped = true; };
4517
+ FilterObserver.prototype.fail = function (e) {
4518
+ if (!this.isStopped) {
4519
+ this.isStopped = true;
4520
+ this.observer.onError(e);
4521
+ return true;
4522
+ }
4523
+ return false;
4524
+ };
4525
+
4128
4526
  /**
4129
- * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4130
- *
4131
- * @example
4132
- * var res = source.where(function (value) { return value < 10; });
4133
- * var res = source.where(function (value, index) { return value < 10 || index < 10; });
4134
- * @param {Function} predicate A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
4135
- * @param {Any} [thisArg] Object to use as this when executing callback.
4136
- * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4137
- */
4138
- observableProto.where = observableProto.filter = function (predicate, thisArg) {
4139
- var source = this;
4140
- return new AnonymousObservable(function (observer) {
4141
- var count = 0;
4142
- return source.subscribe(function (value) {
4143
- var shouldRun;
4144
- try {
4145
- shouldRun = predicate.call(thisArg, value, count++, source);
4146
- } catch (e) {
4147
- observer.onError(e);
4148
- return;
4149
- }
4150
- shouldRun && observer.onNext(value);
4151
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4152
- }, source);
4527
+ * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4528
+ * @param {Function} predicate A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
4529
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4530
+ * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4531
+ */
4532
+ observableProto.filter = observableProto.where = function (predicate, thisArg) {
4533
+ return this instanceof FilterObservable ? this.internalFilter(predicate, thisArg) :
4534
+ new FilterObservable(this, predicate, thisArg);
4153
4535
  };
4154
4536
 
4155
4537
  /**
@@ -4202,31 +4584,29 @@
4202
4584
  disposableEmpty;
4203
4585
  }
4204
4586
 
4587
+ function setDisposable(s, state) {
4588
+ var ado = state[0], subscribe = state[1];
4589
+ try {
4590
+ ado.setDisposable(fixSubscriber(subscribe(ado)));
4591
+ } catch (e) {
4592
+ if (!ado.fail(e)) { throw e; }
4593
+ }
4594
+ }
4595
+
4205
4596
  function AnonymousObservable(subscribe, parent) {
4206
4597
  this.source = parent;
4207
- if (!(this instanceof AnonymousObservable)) {
4208
- return new AnonymousObservable(subscribe);
4209
- }
4210
4598
 
4211
4599
  function s(observer) {
4212
- var setDisposable = function () {
4213
- try {
4214
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4215
- } catch (e) {
4216
- if (!autoDetachObserver.fail(e)) {
4217
- throw e;
4218
- }
4219
- }
4220
- };
4221
4600
 
4222
- var autoDetachObserver = new AutoDetachObserver(observer);
4601
+ var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
4602
+
4223
4603
  if (currentThreadScheduler.scheduleRequired()) {
4224
- currentThreadScheduler.schedule(setDisposable);
4604
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
4225
4605
  } else {
4226
- setDisposable();
4606
+ setDisposable(null, state);
4227
4607
  }
4228
4608
 
4229
- return autoDetachObserver;
4609
+ return ado;
4230
4610
  }
4231
4611
 
4232
4612
  __super__.call(this, s);
@@ -4253,7 +4633,7 @@
4253
4633
  this.observer.onNext(value);
4254
4634
  noError = true;
4255
4635
  } catch (e) {
4256
- throw e;
4636
+ return thrower(e);
4257
4637
  } finally {
4258
4638
  !noError && this.dispose();
4259
4639
  }
@@ -4263,7 +4643,7 @@
4263
4643
  try {
4264
4644
  this.observer.onError(err);
4265
4645
  } catch (e) {
4266
- throw e;
4646
+ return thrower(e);
4267
4647
  } finally {
4268
4648
  this.dispose();
4269
4649
  }
@@ -4273,7 +4653,7 @@
4273
4653
  try {
4274
4654
  this.observer.onCompleted();
4275
4655
  } catch (e) {
4276
- throw e;
4656
+ return thrower(e);
4277
4657
  } finally {
4278
4658
  this.dispose();
4279
4659
  }
@@ -4290,130 +4670,121 @@
4290
4670
  return AutoDetachObserver;
4291
4671
  }(AbstractObserver));
4292
4672
 
4293
- /** @private */
4294
- var InnerSubscription = function (subject, observer) {
4295
- this.subject = subject;
4296
- this.observer = observer;
4297
- };
4673
+ var InnerSubscription = function (subject, observer) {
4674
+ this.subject = subject;
4675
+ this.observer = observer;
4676
+ };
4298
4677
 
4299
- /**
4300
- * @private
4301
- * @memberOf InnerSubscription
4302
- */
4303
- InnerSubscription.prototype.dispose = function () {
4304
- if (!this.subject.isDisposed && this.observer !== null) {
4305
- var idx = this.subject.observers.indexOf(this.observer);
4306
- this.subject.observers.splice(idx, 1);
4307
- this.observer = null;
4308
- }
4309
- };
4678
+ InnerSubscription.prototype.dispose = function () {
4679
+ if (!this.subject.isDisposed && this.observer !== null) {
4680
+ var idx = this.subject.observers.indexOf(this.observer);
4681
+ this.subject.observers.splice(idx, 1);
4682
+ this.observer = null;
4683
+ }
4684
+ };
4685
+
4686
+ /**
4687
+ * Represents an object that is both an observable sequence as well as an observer.
4688
+ * Each notification is broadcasted to all subscribed observers.
4689
+ */
4690
+ var Subject = Rx.Subject = (function (__super__) {
4691
+ function subscribe(observer) {
4692
+ checkDisposed(this);
4693
+ if (!this.isStopped) {
4694
+ this.observers.push(observer);
4695
+ return new InnerSubscription(this, observer);
4696
+ }
4697
+ if (this.hasError) {
4698
+ observer.onError(this.error);
4699
+ return disposableEmpty;
4700
+ }
4701
+ observer.onCompleted();
4702
+ return disposableEmpty;
4703
+ }
4704
+
4705
+ inherits(Subject, __super__);
4310
4706
 
4311
4707
  /**
4312
- * Represents an object that is both an observable sequence as well as an observer.
4313
- * Each notification is broadcasted to all subscribed observers.
4708
+ * Creates a subject.
4314
4709
  */
4315
- var Subject = Rx.Subject = (function (_super) {
4316
- function subscribe(observer) {
4317
- checkDisposed.call(this);
4318
- if (!this.isStopped) {
4319
- this.observers.push(observer);
4320
- return new InnerSubscription(this, observer);
4321
- }
4322
- if (this.exception) {
4323
- observer.onError(this.exception);
4324
- return disposableEmpty;
4325
- }
4326
- observer.onCompleted();
4327
- return disposableEmpty;
4328
- }
4710
+ function Subject() {
4711
+ __super__.call(this, subscribe);
4712
+ this.isDisposed = false,
4713
+ this.isStopped = false,
4714
+ this.observers = [];
4715
+ this.hasError = false;
4716
+ }
4329
4717
 
4330
- inherits(Subject, _super);
4331
-
4332
- /**
4333
- * Creates a subject.
4334
- * @constructor
4335
- */
4336
- function Subject() {
4337
- _super.call(this, subscribe);
4338
- this.isDisposed = false,
4339
- this.isStopped = false,
4340
- this.observers = [];
4718
+ addProperties(Subject.prototype, Observer.prototype, {
4719
+ /**
4720
+ * Indicates whether the subject has observers subscribed to it.
4721
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4722
+ */
4723
+ hasObservers: function () { return this.observers.length > 0; },
4724
+ /**
4725
+ * Notifies all subscribed observers about the end of the sequence.
4726
+ */
4727
+ onCompleted: function () {
4728
+ checkDisposed(this);
4729
+ if (!this.isStopped) {
4730
+ this.isStopped = true;
4731
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4732
+ os[i].onCompleted();
4733
+ }
4734
+
4735
+ this.observers.length = 0;
4341
4736
  }
4737
+ },
4738
+ /**
4739
+ * Notifies all subscribed observers about the exception.
4740
+ * @param {Mixed} error The exception to send to all observers.
4741
+ */
4742
+ onError: function (error) {
4743
+ checkDisposed(this);
4744
+ if (!this.isStopped) {
4745
+ this.isStopped = true;
4746
+ this.error = error;
4747
+ this.hasError = true;
4748
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4749
+ os[i].onError(error);
4750
+ }
4342
4751
 
4343
- addProperties(Subject.prototype, Observer, {
4344
- /**
4345
- * Indicates whether the subject has observers subscribed to it.
4346
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4347
- */
4348
- hasObservers: function () {
4349
- return this.observers.length > 0;
4350
- },
4351
- /**
4352
- * Notifies all subscribed observers about the end of the sequence.
4353
- */
4354
- onCompleted: function () {
4355
- checkDisposed.call(this);
4356
- if (!this.isStopped) {
4357
- var os = this.observers.slice(0);
4358
- this.isStopped = true;
4359
- for (var i = 0, len = os.length; i < len; i++) {
4360
- os[i].onCompleted();
4361
- }
4362
-
4363
- this.observers = [];
4364
- }
4365
- },
4366
- /**
4367
- * Notifies all subscribed observers about the exception.
4368
- * @param {Mixed} error The exception to send to all observers.
4369
- */
4370
- onError: function (exception) {
4371
- checkDisposed.call(this);
4372
- if (!this.isStopped) {
4373
- var os = this.observers.slice(0);
4374
- this.isStopped = true;
4375
- this.exception = exception;
4376
- for (var i = 0, len = os.length; i < len; i++) {
4377
- os[i].onError(exception);
4378
- }
4379
-
4380
- this.observers = [];
4381
- }
4382
- },
4383
- /**
4384
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
4385
- * @param {Mixed} value The value to send to all observers.
4386
- */
4387
- onNext: function (value) {
4388
- checkDisposed.call(this);
4389
- if (!this.isStopped) {
4390
- var os = this.observers.slice(0);
4391
- for (var i = 0, len = os.length; i < len; i++) {
4392
- os[i].onNext(value);
4393
- }
4394
- }
4395
- },
4396
- /**
4397
- * Unsubscribe all observers and release resources.
4398
- */
4399
- dispose: function () {
4400
- this.isDisposed = true;
4401
- this.observers = null;
4402
- }
4403
- });
4752
+ this.observers.length = 0;
4753
+ }
4754
+ },
4755
+ /**
4756
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
4757
+ * @param {Mixed} value The value to send to all observers.
4758
+ */
4759
+ onNext: function (value) {
4760
+ checkDisposed(this);
4761
+ if (!this.isStopped) {
4762
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4763
+ os[i].onNext(value);
4764
+ }
4765
+ }
4766
+ },
4767
+ /**
4768
+ * Unsubscribe all observers and release resources.
4769
+ */
4770
+ dispose: function () {
4771
+ this.isDisposed = true;
4772
+ this.observers = null;
4773
+ }
4774
+ });
4404
4775
 
4405
- /**
4406
- * Creates a subject from the specified observer and observable.
4407
- * @param {Observer} observer The observer used to send messages to the subject.
4408
- * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
4409
- * @returns {Subject} Subject implemented using the given observer and observable.
4410
- */
4411
- Subject.create = function (observer, observable) {
4412
- return new AnonymousSubject(observer, observable);
4413
- };
4776
+ /**
4777
+ * Creates a subject from the specified observer and observable.
4778
+ * @param {Observer} observer The observer used to send messages to the subject.
4779
+ * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
4780
+ * @returns {Subject} Subject implemented using the given observer and observable.
4781
+ */
4782
+ Subject.create = function (observer, observable) {
4783
+ return new AnonymousSubject(observer, observable);
4784
+ };
4414
4785
 
4415
- return Subject;
4416
- }(Observable));
4786
+ return Subject;
4787
+ }(Observable));
4417
4788
 
4418
4789
  /**
4419
4790
  * Represents the result of an asynchronous operation.
@@ -4422,21 +4793,17 @@
4422
4793
  var AsyncSubject = Rx.AsyncSubject = (function (__super__) {
4423
4794
 
4424
4795
  function subscribe(observer) {
4425
- checkDisposed.call(this);
4796
+ checkDisposed(this);
4426
4797
 
4427
4798
  if (!this.isStopped) {
4428
4799
  this.observers.push(observer);
4429
4800
  return new InnerSubscription(this, observer);
4430
4801
  }
4431
4802
 
4432
- var ex = this.exception,
4433
- hv = this.hasValue,
4434
- v = this.value;
4435
-
4436
- if (ex) {
4437
- observer.onError(ex);
4438
- } else if (hv) {
4439
- observer.onNext(v);
4803
+ if (this.hasError) {
4804
+ observer.onError(this.error);
4805
+ } else if (this.hasValue) {
4806
+ observer.onNext(this.value);
4440
4807
  observer.onCompleted();
4441
4808
  } else {
4442
4809
  observer.onCompleted();
@@ -4456,10 +4823,9 @@
4456
4823
 
4457
4824
  this.isDisposed = false;
4458
4825
  this.isStopped = false;
4459
- this.value = null;
4460
4826
  this.hasValue = false;
4461
4827
  this.observers = [];
4462
- this.exception = null;
4828
+ this.hasError = false;
4463
4829
  }
4464
4830
 
4465
4831
  addProperties(AsyncSubject.prototype, Observer, {
@@ -4468,34 +4834,32 @@
4468
4834
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4469
4835
  */
4470
4836
  hasObservers: function () {
4471
- checkDisposed.call(this);
4837
+ checkDisposed(this);
4472
4838
  return this.observers.length > 0;
4473
4839
  },
4474
4840
  /**
4475
4841
  * Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
4476
4842
  */
4477
4843
  onCompleted: function () {
4478
- var o, i, len;
4479
- checkDisposed.call(this);
4844
+ var i, len;
4845
+ checkDisposed(this);
4480
4846
  if (!this.isStopped) {
4481
4847
  this.isStopped = true;
4482
- var os = this.observers.slice(0),
4483
- v = this.value,
4484
- hv = this.hasValue;
4485
-
4486
- if (hv) {
4487
- for (i = 0, len = os.length; i < len; i++) {
4488
- o = os[i];
4489
- o.onNext(v);
4848
+ var os = cloneArray(this.observers), len = os.length;
4849
+
4850
+ if (this.hasValue) {
4851
+ for (i = 0; i < len; i++) {
4852
+ var o = os[i];
4853
+ o.onNext(this.value);
4490
4854
  o.onCompleted();
4491
4855
  }
4492
4856
  } else {
4493
- for (i = 0, len = os.length; i < len; i++) {
4857
+ for (i = 0; i < len; i++) {
4494
4858
  os[i].onCompleted();
4495
4859
  }
4496
4860
  }
4497
4861
 
4498
- this.observers = [];
4862
+ this.observers.length = 0;
4499
4863
  }
4500
4864
  },
4501
4865
  /**
@@ -4503,17 +4867,17 @@
4503
4867
  * @param {Mixed} error The Error to send to all observers.
4504
4868
  */
4505
4869
  onError: function (error) {
4506
- checkDisposed.call(this);
4870
+ checkDisposed(this);
4507
4871
  if (!this.isStopped) {
4508
- var os = this.observers.slice(0);
4509
4872
  this.isStopped = true;
4510
- this.exception = error;
4873
+ this.hasError = true;
4874
+ this.error = error;
4511
4875
 
4512
- for (var i = 0, len = os.length; i < len; i++) {
4876
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4513
4877
  os[i].onError(error);
4514
4878
  }
4515
4879
 
4516
- this.observers = [];
4880
+ this.observers.length = 0;
4517
4881
  }
4518
4882
  },
4519
4883
  /**
@@ -4521,7 +4885,7 @@
4521
4885
  * @param {Mixed} value The value to store in the subject.
4522
4886
  */
4523
4887
  onNext: function (value) {
4524
- checkDisposed.call(this);
4888
+ checkDisposed(this);
4525
4889
  if (this.isStopped) { return; }
4526
4890
  this.value = value;
4527
4891
  this.hasValue = true;
@@ -4543,18 +4907,22 @@
4543
4907
  var AnonymousSubject = Rx.AnonymousSubject = (function (__super__) {
4544
4908
  inherits(AnonymousSubject, __super__);
4545
4909
 
4910
+ function subscribe(observer) {
4911
+ return this.observable.subscribe(observer);
4912
+ }
4913
+
4546
4914
  function AnonymousSubject(observer, observable) {
4547
4915
  this.observer = observer;
4548
4916
  this.observable = observable;
4549
- __super__.call(this, this.observable.subscribe.bind(this.observable));
4917
+ __super__.call(this, subscribe);
4550
4918
  }
4551
4919
 
4552
- addProperties(AnonymousSubject.prototype, Observer, {
4920
+ addProperties(AnonymousSubject.prototype, Observer.prototype, {
4553
4921
  onCompleted: function () {
4554
4922
  this.observer.onCompleted();
4555
4923
  },
4556
- onError: function (exception) {
4557
- this.observer.onError(exception);
4924
+ onError: function (error) {
4925
+ this.observer.onError(error);
4558
4926
  },
4559
4927
  onNext: function (value) {
4560
4928
  this.observer.onNext(value);
@@ -4564,23 +4932,23 @@
4564
4932
  return AnonymousSubject;
4565
4933
  }(Observable));
4566
4934
 
4567
- if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
4568
- root.Rx = Rx;
4935
+ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
4936
+ root.Rx = Rx;
4569
4937
 
4570
- define(function() {
4571
- return Rx;
4572
- });
4573
- } else if (freeExports && freeModule) {
4574
- // in Node.js or RingoJS
4575
- if (moduleExports) {
4576
- (freeModule.exports = Rx).Rx = Rx;
4577
- } else {
4578
- freeExports.Rx = Rx;
4579
- }
4938
+ define(function() {
4939
+ return Rx;
4940
+ });
4941
+ } else if (freeExports && freeModule) {
4942
+ // in Node.js or RingoJS
4943
+ if (moduleExports) {
4944
+ (freeModule.exports = Rx).Rx = Rx;
4580
4945
  } else {
4581
- // in a browser or Rhino
4582
- root.Rx = Rx;
4946
+ freeExports.Rx = Rx;
4583
4947
  }
4948
+ } else {
4949
+ // in a browser or Rhino
4950
+ root.Rx = Rx;
4951
+ }
4584
4952
 
4585
4953
  // All code before this point will be filtered from stack traces.
4586
4954
  var rEndingLine = captureLine();