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,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,c){return new o(function(d){var e=!1,f=null,g=[];return a.subscribe(function(a){var h,i;try{i=b(a)}catch(j){return void d.onError(j)}if(h=0,e)try{h=c(i,f)}catch(k){return void d.onError(k)}else e=!0,f=i;h>0&&(f=i,g=[]),h>=0&&g.push(a)},d.onError.bind(d),function(){d.onNext(g),d.onCompleted()})},a)}function f(a){if(0===a.length)throw new Error(D);return a[0]}function g(a,b,c,d){if(0>b)throw new Error(C);return new o(function(e){var f=b;return a.subscribe(function(a){0===f--&&(e.onNext(a),e.onCompleted())},e.onError.bind(e),function(){c?(e.onNext(d),e.onCompleted()):e.onError(new Error(C))})},a)}function h(a,b,c){return new o(function(d){var e=c,f=!1;return a.subscribe(function(a){f?d.onError(new Error("Sequence contains more than one element")):(e=a,f=!0)},d.onError.bind(d),function(){f||b?(d.onNext(e),d.onCompleted()):d.onError(new Error(D))})},a)}function i(a,b,c){return new o(function(d){return a.subscribe(function(a){d.onNext(a),d.onCompleted()},d.onError.bind(d),function(){b?(d.onNext(c),d.onCompleted()):d.onError(new Error(D))})},a)}function j(a,b,c){return new o(function(d){var e=c,f=!1;return a.subscribe(function(a){e=a,f=!0},d.onError.bind(d),function(){f||b?(d.onNext(e),d.onCompleted()):d.onError(new Error(D))})},a)}function k(a,b,c,e){return new o(function(f){var g=0;return a.subscribe(function(d){var h;try{h=b.call(c,d,g,a)}catch(i){return void f.onError(i)}h?(f.onNext(e?g:d),f.onCompleted()):g++},f.onError.bind(f),function(){f.onNext(e?-1:d),f.onCompleted()})},a)}var l=c.Observable,m=l.prototype,n=c.CompositeDisposable,o=c.AnonymousObservable,p=c.Disposable.empty,q=(c.internals.isEqual,c.helpers),r=q.not,s=q.defaultComparer,t=q.identity,u=q.defaultSubComparer,v=q.isFunction,w=q.isPromise,x=q.isArrayLike,y=q.isIterable,z=l.fromPromise,A=l.from,B=q.deprecate,C="Argument out of range",D="Sequence contains no elements.";return m.finalValue=function(){var a=this;return new o(function(b){var c,d=!1;return a.subscribe(function(a){d=!0,c=a},b.onError.bind(b),function(){d?(b.onNext(c),b.onCompleted()):b.onError(new Error(D))})},a)},m.aggregate=function(){B("aggregate","reduce");var a,b,c;return 2===arguments.length?(a=arguments[0],b=!0,c=arguments[1]):c=arguments[0],b?this.scan(a,c).startWith(a).finalValue():this.scan(c).finalValue()},m.reduce=function(a){var b,c;return 2===arguments.length&&(c=!0,b=arguments[1]),c?this.scan(b,a).startWith(b).finalValue():this.scan(a).finalValue()},m.some=function(a,b){var c=this;return a?c.filter(a,b).some():new o(function(a){return c.subscribe(function(){a.onNext(!0),a.onCompleted()},a.onError.bind(a),function(){a.onNext(!1),a.onCompleted()})},c)},m.any=function(){return B("any","some"),this.some.apply(this,arguments)},m.isEmpty=function(){return this.any().map(r)},m.every=function(a,b){return this.filter(function(b){return!a(b)},b).some().map(r)},m.all=function(){return B("all","every"),this.every.apply(this,arguments)},m.contains=function(a,b){function c(a,b){return 0===a&&0===b||a===b||isNaN(a)&&isNaN(b)}var d=this;return new o(function(e){var f=0,g=+b||0;return 1/0===Math.abs(g)&&(g=0),0>g?(e.onNext(!1),e.onCompleted(),p):d.subscribe(function(b){f++>=g&&c(b,a)&&(e.onNext(!0),e.onCompleted())},e.onError.bind(e),function(){e.onNext(!1),e.onCompleted()})},this)},m.count=function(a,b){return a?this.where(a,b).count():this.aggregate(0,function(a){return a+1})},m.indexOf=function(a,b){var c=this;return new o(function(d){var e=0,f=+b||0;return 1/0===Math.abs(f)&&(f=0),0>f?(d.onNext(-1),d.onCompleted(),p):c.subscribe(function(b){e>=f&&b===a&&(d.onNext(e),d.onCompleted()),e++},d.onError.bind(d),function(){d.onNext(-1),d.onCompleted()})},c)},m.sum=function(a,b){return a&&v(a)?this.map(a,b).sum():this.reduce(function(a,b){return a+b},0)},m.minBy=function(a,b){return b||(b=u),e(this,a,function(a,c){return-1*b(a,c)})},m.min=function(a){return this.minBy(t,a).map(function(a){return f(a)})},m.maxBy=function(a,b){return b||(b=u),e(this,a,b)},m.max=function(a){return this.maxBy(t,a).map(function(a){return f(a)})},m.average=function(a,b){return a&&v(a)?this.select(a,b).average():this.scan({sum:0,count:0},function(a,b){return{sum:a.sum+b,count:a.count+1}}).finalValue().map(function(a){if(0===a.count)throw new Error("The input sequence was empty");return a.sum/a.count})},m.sequenceEqual=function(a,b){var c=this;return b||(b=s),new o(function(d){var e=!1,f=!1,g=[],h=[],i=c.subscribe(function(a){var c,e;if(h.length>0){e=h.shift();try{c=b(e,a)}catch(i){return void d.onError(i)}c||(d.onNext(!1),d.onCompleted())}else f?(d.onNext(!1),d.onCompleted()):g.push(a)},d.onError.bind(d),function(){e=!0,0===g.length&&(h.length>0?(d.onNext(!1),d.onCompleted()):f&&(d.onNext(!0),d.onCompleted()))});(x(a)||y(a))&&(a=A(a)),w(a)&&(a=z(a));var j=a.subscribe(function(a){var c;if(g.length>0){var f=g.shift();try{c=b(f,a)}catch(i){return void d.onError(i)}c||(d.onNext(!1),d.onCompleted())}else e?(d.onNext(!1),d.onCompleted()):h.push(a)},d.onError.bind(d),function(){f=!0,0===h.length&&(g.length>0?(d.onNext(!1),d.onCompleted()):e&&(d.onNext(!0),d.onCompleted()))});return new n(i,j)},c)},m.elementAt=function(a){return g(this,a,!1)},m.elementAtOrDefault=function(a,b){return g(this,a,!0,b)},m.single=function(a,b){return a&&v(a)?this.where(a,b).single():h(this,!1)},m.singleOrDefault=function(a,b,c){return a&&v(a)?this.where(a,c).singleOrDefault(null,b):h(this,!0,b)},m.first=function(a,b){return a?this.where(a,b).first():i(this,!1)},m.firstOrDefault=function(a,b){return a?this.where(a).firstOrDefault(null,b):i(this,!0,b)},m.last=function(a,b){return a?this.where(a,b).last():j(this,!1)},m.lastOrDefault=function(a,b,c){return a?this.where(a,c).lastOrDefault(null,b):j(this,!0,b)},m.find=function(a,b){return k(this,a,b,!1)},m.findIndex=function(a,b){return k(this,a,b,!0)},m.toSet=function(){if("undefined"==typeof a.Set)throw new TypeError;var b=this;return new o(function(c){var d=new a.Set;return b.subscribe(d.add.bind(d),c.onError.bind(c),function(){c.onNext(d),c.onCompleted()})},b)},m.toMap=function(b,c){if("undefined"==typeof a.Map)throw new TypeError;var d=this;return new o(function(e){var f=new a.Map;return d.subscribe(function(a){var d;try{d=b(a)}catch(g){return void e.onError(g)}var h=a;if(c)try{h=c(a)}catch(g){return void e.onError(g)}f.set(d,h)},e.onError.bind(e),function(){e.onNext(f),e.onCompleted()})},d)},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,c){return new o(function(d){var e=!1,f=null,g=[];return a.subscribe(function(a){var h,i;try{i=b(a)}catch(j){return void d.onError(j)}if(h=0,e)try{h=c(i,f)}catch(k){return void d.onError(k)}else e=!0,f=i;h>0&&(f=i,g=[]),h>=0&&g.push(a)},function(a){d.onError(a)},function(){d.onNext(g),d.onCompleted()})},a)}function f(a){if(0===a.length)throw new Error(D);return a[0]}function g(a,b,c,d){if(0>b)throw new Error(C);return new o(function(e){var f=b;return a.subscribe(function(a){0===f--&&(e.onNext(a),e.onCompleted())},function(a){e.onError(a)},function(){c?(e.onNext(d),e.onCompleted()):e.onError(new Error(C))})},a)}function h(a,b,c){return new o(function(d){var e=c,f=!1;return a.subscribe(function(a){f?d.onError(new Error("Sequence contains more than one element")):(e=a,f=!0)},function(a){d.onError(a)},function(){f||b?(d.onNext(e),d.onCompleted()):d.onError(new Error(D))})},a)}function i(a,b,c){return new o(function(d){return a.subscribe(function(a){d.onNext(a),d.onCompleted()},function(a){d.onError(a)},function(){b?(d.onNext(c),d.onCompleted()):d.onError(new Error(D))})},a)}function j(a,b,c){return new o(function(d){var e=c,f=!1;return a.subscribe(function(a){e=a,f=!0},function(a){d.onError(a)},function(){f||b?(d.onNext(e),d.onCompleted()):d.onError(new Error(D))})},a)}function k(a,b,c,e){var f=B(b,c,3);return new o(function(b){var c=0;return a.subscribe(function(d){var g;try{g=f(d,c,a)}catch(h){return void b.onError(h)}g?(b.onNext(e?c:d),b.onCompleted()):c++},function(a){b.onError(a)},function(){b.onNext(e?-1:d),b.onCompleted()})},a)}var l=c.Observable,m=l.prototype,n=c.CompositeDisposable,o=c.AnonymousObservable,p=c.Disposable.empty,q=(c.internals.isEqual,c.helpers),r=q.not,s=q.defaultComparer,t=q.identity,u=q.defaultSubComparer,v=q.isFunction,w=q.isPromise,x=q.isArrayLike,y=q.isIterable,z=l.fromPromise,A=l.from,B=c.internals.bindCallback,C="Argument out of range",D="Sequence contains no elements.";return m.aggregate=function(){var a,b,c=!1,d=this;return 2===arguments.length?(c=!0,b=arguments[0],a=arguments[1]):a=arguments[0],new o(function(e){var f,g,h;return d.subscribe(function(d){!h&&(h=!0);try{f?g=a(g,d):(g=c?a(b,d):d,f=!0)}catch(i){return void e.onError(i)}},function(a){e.onError(a)},function(){h&&e.onNext(g),!h&&c&&e.onNext(b),!h&&!c&&e.onError(new Error(D)),e.onCompleted()})},d)},m.reduce=function(a){var b,c=!1,d=this;return 2===arguments.length&&(c=!0,b=arguments[1]),new o(function(e){var f,g,h;return d.subscribe(function(d){!h&&(h=!0);try{f?g=a(g,d):(g=c?a(b,d):d,f=!0)}catch(i){return void e.onError(i)}},function(a){e.onError(a)},function(){h&&e.onNext(g),!h&&c&&e.onNext(b),!h&&!c&&e.onError(new Error(D)),e.onCompleted()})},d)},m.some=function(a,b){var c=this;return a?c.filter(a,b).some():new o(function(a){return c.subscribe(function(){a.onNext(!0),a.onCompleted()},function(b){a.onError(b)},function(){a.onNext(!1),a.onCompleted()})},c)},m.any=function(){return this.some.apply(this,arguments)},m.isEmpty=function(){return this.any().map(r)},m.every=function(a,b){return this.filter(function(b){return!a(b)},b).some().map(r)},m.all=function(){return this.every.apply(this,arguments)},m.includes=function(a,b){function c(a,b){return 0===a&&0===b||a===b||isNaN(a)&&isNaN(b)}var d=this;return new o(function(e){var f=0,g=+b||0;return 1/0===Math.abs(g)&&(g=0),0>g?(e.onNext(!1),e.onCompleted(),p):d.subscribe(function(b){f++>=g&&c(b,a)&&(e.onNext(!0),e.onCompleted())},function(a){e.onError(a)},function(){e.onNext(!1),e.onCompleted()})},this)},m.contains=function(a,b){m.includes(a,b)},m.count=function(a,b){return a?this.filter(a,b).count():this.reduce(function(a){return a+1},0)},m.indexOf=function(a,b){var c=this;return new o(function(d){var e=0,f=+b||0;return 1/0===Math.abs(f)&&(f=0),0>f?(d.onNext(-1),d.onCompleted(),p):c.subscribe(function(b){e>=f&&b===a&&(d.onNext(e),d.onCompleted()),e++},function(a){d.onError(a)},function(){d.onNext(-1),d.onCompleted()})},c)},m.sum=function(a,b){return a&&v(a)?this.map(a,b).sum():this.reduce(function(a,b){return a+b},0)},m.minBy=function(a,b){return b||(b=u),e(this,a,function(a,c){return-1*b(a,c)})},m.min=function(a){return this.minBy(t,a).map(function(a){return f(a)})},m.maxBy=function(a,b){return b||(b=u),e(this,a,b)},m.max=function(a){return this.maxBy(t,a).map(function(a){return f(a)})},m.average=function(a,b){return a&&v(a)?this.map(a,b).average():this.reduce(function(a,b){return{sum:a.sum+b,count:a.count+1}},{sum:0,count:0}).map(function(a){if(0===a.count)throw new Error(D);return a.sum/a.count})},m.sequenceEqual=function(a,b){var c=this;return b||(b=s),new o(function(d){var e=!1,f=!1,g=[],h=[],i=c.subscribe(function(a){var c,e;if(h.length>0){e=h.shift();try{c=b(e,a)}catch(i){return void d.onError(i)}c||(d.onNext(!1),d.onCompleted())}else f?(d.onNext(!1),d.onCompleted()):g.push(a)},function(a){d.onError(a)},function(){e=!0,0===g.length&&(h.length>0?(d.onNext(!1),d.onCompleted()):f&&(d.onNext(!0),d.onCompleted()))});(x(a)||y(a))&&(a=A(a)),w(a)&&(a=z(a));var j=a.subscribe(function(a){var c;if(g.length>0){var f=g.shift();try{c=b(f,a)}catch(i){return void d.onError(i)}c||(d.onNext(!1),d.onCompleted())}else e?(d.onNext(!1),d.onCompleted()):h.push(a)},function(a){d.onError(a)},function(){f=!0,0===h.length&&(g.length>0?(d.onNext(!1),d.onCompleted()):e&&(d.onNext(!0),d.onCompleted()))});return new n(i,j)},c)},m.elementAt=function(a){return g(this,a,!1)},m.elementAtOrDefault=function(a,b){return g(this,a,!0,b)},m.single=function(a,b){return a&&v(a)?this.where(a,b).single():h(this,!1)},m.singleOrDefault=function(a,b,c){return a&&v(a)?this.filter(a,c).singleOrDefault(null,b):h(this,!0,b)},m.first=function(a,b){return a?this.where(a,b).first():i(this,!1)},m.firstOrDefault=function(a,b){return a?this.where(a).firstOrDefault(null,b):i(this,!0,b)},m.last=function(a,b){return a?this.where(a,b).last():j(this,!1)},m.lastOrDefault=function(a,b,c){return a?this.where(a,c).lastOrDefault(null,b):j(this,!0,b)},m.find=function(a,b){return k(this,a,b,!1)},m.findIndex=function(a,b){return k(this,a,b,!0)},m.toSet=function(){if("undefined"==typeof a.Set)throw new TypeError;var b=this;return new o(function(c){var d=new a.Set;return b.subscribe(function(a){d.add(a)},function(a){c.onError(a)},function(){c.onNext(d),c.onCompleted()})},b)},m.toMap=function(b,c){if("undefined"==typeof a.Map)throw new TypeError;var d=this;return new o(function(e){var f=new a.Map;return d.subscribe(function(a){var d;try{d=b(a)}catch(g){return void e.onError(g)}var h=a;if(c)try{h=c(a)}catch(g){return void e.onError(g)}f.set(d,h)},function(a){e.onError(a)},function(){e.onNext(f),e.onCompleted()})},d)},c});
3
3
  //# sourceMappingURL=rx.aggregates.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
  // Utilities
522
551
  if (!Function.prototype.bind) {
523
552
  Function.prototype.bind = function (that) {
@@ -542,37 +571,36 @@
542
571
  };
543
572
  }
544
573
 
545
- if (!Array.prototype.forEach) {
546
-
547
- Array.prototype.forEach = function (callback, thisArg) {
548
- var T, k;
574
+ if (!Array.prototype.forEach) {
575
+ Array.prototype.forEach = function (callback, thisArg) {
576
+ var T, k;
549
577
 
550
- if (this == null) {
551
- throw new TypeError(" this is null or not defined");
552
- }
578
+ if (this == null) {
579
+ throw new TypeError(" this is null or not defined");
580
+ }
553
581
 
554
- var O = Object(this);
555
- var len = O.length >>> 0;
582
+ var O = Object(this);
583
+ var len = O.length >>> 0;
556
584
 
557
- if (typeof callback !== "function") {
558
- throw new TypeError(callback + " is not a function");
559
- }
585
+ if (typeof callback !== "function") {
586
+ throw new TypeError(callback + " is not a function");
587
+ }
560
588
 
561
- if (arguments.length > 1) {
562
- T = thisArg;
563
- }
589
+ if (arguments.length > 1) {
590
+ T = thisArg;
591
+ }
564
592
 
565
- k = 0;
566
- while (k < len) {
567
- var kValue;
568
- if (k in O) {
569
- kValue = O[k];
570
- callback.call(T, kValue, k, O);
593
+ k = 0;
594
+ while (k < len) {
595
+ var kValue;
596
+ if (k in O) {
597
+ kValue = O[k];
598
+ callback.call(T, kValue, k, O);
599
+ }
600
+ k++;
571
601
  }
572
- k++;
573
- }
574
- };
575
- }
602
+ };
603
+ }
576
604
 
577
605
  var boxedString = Object("a"),
578
606
  splitString = boxedString[0] != "a" || !(0 in boxedString);
@@ -669,6 +697,45 @@ if (!Array.prototype.forEach) {
669
697
  };
670
698
  }
671
699
 
700
+ // Fix for Tessel
701
+ if (!Object.prototype.propertyIsEnumerable) {
702
+ Object.prototype.propertyIsEnumerable = function (key) {
703
+ for (var k in this) { if (k === key) { return true; } }
704
+ return false;
705
+ };
706
+ }
707
+
708
+ if (!Object.keys) {
709
+ Object.keys = (function() {
710
+ 'use strict';
711
+ var hasOwnProperty = Object.prototype.hasOwnProperty,
712
+ hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString');
713
+
714
+ return function(obj) {
715
+ if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
716
+ throw new TypeError('Object.keys called on non-object');
717
+ }
718
+
719
+ var result = [], prop, i;
720
+
721
+ for (prop in obj) {
722
+ if (hasOwnProperty.call(obj, prop)) {
723
+ result.push(prop);
724
+ }
725
+ }
726
+
727
+ if (hasDontEnumBug) {
728
+ for (i = 0; i < dontEnumsLength; i++) {
729
+ if (hasOwnProperty.call(obj, dontEnums[i])) {
730
+ result.push(dontEnums[i]);
731
+ }
732
+ }
733
+ }
734
+ return result;
735
+ };
736
+ }());
737
+ }
738
+
672
739
  // Collections
673
740
  function IndexedItem(id, value) {
674
741
  this.id = id;
@@ -728,7 +795,7 @@ if (!Array.prototype.forEach) {
728
795
 
729
796
  priorityProto.removeAt = function (index) {
730
797
  this.items[index] = this.items[--this.length];
731
- delete this.items[this.length];
798
+ this.items[this.length] = undefined;
732
799
  this.heapify();
733
800
  };
734
801
 
@@ -760,9 +827,17 @@ if (!Array.prototype.forEach) {
760
827
  * @constructor
761
828
  */
762
829
  var CompositeDisposable = Rx.CompositeDisposable = function () {
763
- this.disposables = argsOrArray(arguments, 0);
830
+ var args = [];
831
+ if (Array.isArray(arguments[0])) {
832
+ args = arguments[0];
833
+ } else {
834
+ var len = arguments.length;
835
+ args = new Array(len);
836
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
837
+ }
838
+ this.disposables = args;
764
839
  this.isDisposed = false;
765
- this.length = this.disposables.length;
840
+ this.length = args.length;
766
841
  };
767
842
 
768
843
  var CompositeDisposablePrototype = CompositeDisposable.prototype;
@@ -805,28 +880,19 @@ if (!Array.prototype.forEach) {
805
880
  CompositeDisposablePrototype.dispose = function () {
806
881
  if (!this.isDisposed) {
807
882
  this.isDisposed = true;
808
- var currentDisposables = this.disposables.slice(0);
883
+ var len = this.disposables.length, currentDisposables = new Array(len);
884
+ for(var i = 0; i < len; i++) { currentDisposables[i] = this.disposables[i]; }
809
885
  this.disposables = [];
810
886
  this.length = 0;
811
887
 
812
- for (var i = 0, len = currentDisposables.length; i < len; i++) {
888
+ for (i = 0; i < len; i++) {
813
889
  currentDisposables[i].dispose();
814
890
  }
815
891
  }
816
892
  };
817
893
 
818
- /**
819
- * Converts the existing CompositeDisposable to an array of disposables
820
- * @returns {Array} An array of disposable objects.
821
- */
822
- CompositeDisposablePrototype.toArray = function () {
823
- return this.disposables.slice(0);
824
- };
825
-
826
894
  /**
827
895
  * Provides a set of static methods for creating Disposables.
828
- *
829
- * @constructor
830
896
  * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
831
897
  */
832
898
  var Disposable = Rx.Disposable = function (action) {
@@ -875,9 +941,9 @@ if (!Array.prototype.forEach) {
875
941
  * @param {Disposable} value The new underlying disposable.
876
942
  */
877
943
  booleanDisposablePrototype.setDisposable = function (value) {
878
- var shouldDispose = this.isDisposed, old;
944
+ var shouldDispose = this.isDisposed;
879
945
  if (!shouldDispose) {
880
- old = this.current;
946
+ var old = this.current;
881
947
  this.current = value;
882
948
  }
883
949
  old && old.dispose();
@@ -888,10 +954,9 @@ if (!Array.prototype.forEach) {
888
954
  * Disposes the underlying disposable as well as all future replacements.
889
955
  */
890
956
  booleanDisposablePrototype.dispose = function () {
891
- var old;
892
957
  if (!this.isDisposed) {
893
958
  this.isDisposed = true;
894
- old = this.current;
959
+ var old = this.current;
895
960
  this.current = null;
896
961
  }
897
962
  old && old.dispose();
@@ -901,83 +966,80 @@ if (!Array.prototype.forEach) {
901
966
  }());
902
967
  var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
903
968
 
969
+ /**
970
+ * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
971
+ */
972
+ var RefCountDisposable = Rx.RefCountDisposable = (function () {
973
+
974
+ function InnerDisposable(disposable) {
975
+ this.disposable = disposable;
976
+ this.disposable.count++;
977
+ this.isInnerDisposed = false;
978
+ }
979
+
980
+ InnerDisposable.prototype.dispose = function () {
981
+ if (!this.disposable.isDisposed && !this.isInnerDisposed) {
982
+ this.isInnerDisposed = true;
983
+ this.disposable.count--;
984
+ if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
985
+ this.disposable.isDisposed = true;
986
+ this.disposable.underlyingDisposable.dispose();
987
+ }
988
+ }
989
+ };
990
+
991
+ /**
992
+ * Initializes a new instance of the RefCountDisposable with the specified disposable.
993
+ * @constructor
994
+ * @param {Disposable} disposable Underlying disposable.
995
+ */
996
+ function RefCountDisposable(disposable) {
997
+ this.underlyingDisposable = disposable;
998
+ this.isDisposed = false;
999
+ this.isPrimaryDisposed = false;
1000
+ this.count = 0;
1001
+ }
1002
+
904
1003
  /**
905
- * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
1004
+ * Disposes the underlying disposable only when all dependent disposables have been disposed
906
1005
  */
907
- var RefCountDisposable = Rx.RefCountDisposable = (function () {
908
-
909
- function InnerDisposable(disposable) {
910
- this.disposable = disposable;
911
- this.disposable.count++;
912
- this.isInnerDisposed = false;
913
- }
914
-
915
- InnerDisposable.prototype.dispose = function () {
916
- if (!this.disposable.isDisposed) {
917
- if (!this.isInnerDisposed) {
918
- this.isInnerDisposed = true;
919
- this.disposable.count--;
920
- if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
921
- this.disposable.isDisposed = true;
922
- this.disposable.underlyingDisposable.dispose();
923
- }
924
- }
925
- }
926
- };
1006
+ RefCountDisposable.prototype.dispose = function () {
1007
+ if (!this.isDisposed && !this.isPrimaryDisposed) {
1008
+ this.isPrimaryDisposed = true;
1009
+ if (this.count === 0) {
1010
+ this.isDisposed = true;
1011
+ this.underlyingDisposable.dispose();
1012
+ }
1013
+ }
1014
+ };
927
1015
 
928
- /**
929
- * Initializes a new instance of the RefCountDisposable with the specified disposable.
930
- * @constructor
931
- * @param {Disposable} disposable Underlying disposable.
932
- */
933
- function RefCountDisposable(disposable) {
934
- this.underlyingDisposable = disposable;
935
- this.isDisposed = false;
936
- this.isPrimaryDisposed = false;
937
- this.count = 0;
938
- }
939
-
940
- /**
941
- * Disposes the underlying disposable only when all dependent disposables have been disposed
942
- */
943
- RefCountDisposable.prototype.dispose = function () {
944
- if (!this.isDisposed) {
945
- if (!this.isPrimaryDisposed) {
946
- this.isPrimaryDisposed = true;
947
- if (this.count === 0) {
948
- this.isDisposed = true;
949
- this.underlyingDisposable.dispose();
950
- }
951
- }
952
- }
953
- };
1016
+ /**
1017
+ * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
1018
+ * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
1019
+ */
1020
+ RefCountDisposable.prototype.getDisposable = function () {
1021
+ return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
1022
+ };
954
1023
 
955
- /**
956
- * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
957
- * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
958
- */
959
- RefCountDisposable.prototype.getDisposable = function () {
960
- return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
961
- };
1024
+ return RefCountDisposable;
1025
+ })();
962
1026
 
963
- return RefCountDisposable;
964
- })();
1027
+ function ScheduledDisposable(scheduler, disposable) {
1028
+ this.scheduler = scheduler;
1029
+ this.disposable = disposable;
1030
+ this.isDisposed = false;
1031
+ }
965
1032
 
966
- function ScheduledDisposable(scheduler, disposable) {
967
- this.scheduler = scheduler;
968
- this.disposable = disposable;
969
- this.isDisposed = false;
1033
+ function scheduleItem(s, self) {
1034
+ if (!self.isDisposed) {
1035
+ self.isDisposed = true;
1036
+ self.disposable.dispose();
970
1037
  }
1038
+ }
971
1039
 
972
- ScheduledDisposable.prototype.dispose = function () {
973
- var parent = this;
974
- this.scheduler.schedule(function () {
975
- if (!parent.isDisposed) {
976
- parent.isDisposed = true;
977
- parent.disposable.dispose();
978
- }
979
- });
980
- };
1040
+ ScheduledDisposable.prototype.dispose = function () {
1041
+ this.scheduler.scheduleWithState(this, scheduleItem);
1042
+ };
981
1043
 
982
1044
  var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
983
1045
  this.scheduler = scheduler;
@@ -1130,7 +1192,7 @@ if (!Array.prototype.forEach) {
1130
1192
  recursiveAction = function (state1) {
1131
1193
  action(state1, function (state2, dueTime1) {
1132
1194
  var isAdded = false, isDone = false,
1133
- d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
1195
+ d = scheduler[method](state2, dueTime1, function (scheduler1, state3) {
1134
1196
  if (isAdded) {
1135
1197
  group.remove(d);
1136
1198
  } else {
@@ -1298,18 +1360,9 @@ if (!Array.prototype.forEach) {
1298
1360
  var immediateScheduler = Scheduler.immediate = (function () {
1299
1361
 
1300
1362
  function scheduleNow(state, action) { return action(this, state); }
1363
+ function notSupported() { throw new Error('Not supported'); }
1301
1364
 
1302
- function scheduleRelative(state, dueTime, action) {
1303
- var dt = normalizeTime(dueTime);
1304
- while (dt - this.now() > 0) { }
1305
- return action(this, state);
1306
- }
1307
-
1308
- function scheduleAbsolute(state, dueTime, action) {
1309
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1310
- }
1311
-
1312
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1365
+ return new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1313
1366
  }());
1314
1367
 
1315
1368
  /**
@@ -1319,27 +1372,16 @@ if (!Array.prototype.forEach) {
1319
1372
  var queue;
1320
1373
 
1321
1374
  function runTrampoline (q) {
1322
- var item;
1323
1375
  while (q.length > 0) {
1324
- item = q.dequeue();
1376
+ var item = q.dequeue();
1325
1377
  if (!item.isCancelled()) {
1326
- // Note, do not schedule blocking work!
1327
- while (item.dueTime - Scheduler.now() > 0) {
1328
- }
1329
- if (!item.isCancelled()) {
1330
- item.invoke();
1331
- }
1378
+ !item.isCancelled() && item.invoke();
1332
1379
  }
1333
1380
  }
1334
1381
  }
1335
1382
 
1336
1383
  function scheduleNow(state, action) {
1337
- return this.scheduleWithRelativeAndState(state, 0, action);
1338
- }
1339
-
1340
- function scheduleRelative(state, dueTime, action) {
1341
- var dt = this.now() + Scheduler.normalize(dueTime),
1342
- si = new ScheduledItem(this, state, action, dt);
1384
+ var si = new ScheduledItem(this, state, action, this.now());
1343
1385
 
1344
1386
  if (!queue) {
1345
1387
  queue = new PriorityQueue(4);
@@ -1357,11 +1399,9 @@ if (!Array.prototype.forEach) {
1357
1399
  return si.disposable;
1358
1400
  }
1359
1401
 
1360
- function scheduleAbsolute(state, dueTime, action) {
1361
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1362
- }
1402
+ function notSupported() { throw new Error('Not supported'); }
1363
1403
 
1364
- var currentScheduler = new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1404
+ var currentScheduler = new Scheduler(defaultNow, scheduleNow, notSupported, notSupported);
1365
1405
 
1366
1406
  currentScheduler.scheduleRequired = function () { return !queue; };
1367
1407
  currentScheduler.ensureTrampoline = function (action) {
@@ -1728,31 +1768,20 @@ if (!Array.prototype.forEach) {
1728
1768
 
1729
1769
  Enumerable.prototype.concat = function () {
1730
1770
  var sources = this;
1731
- return new AnonymousObservable(function (observer) {
1732
- var e;
1733
- try {
1734
- e = sources[$iterator$]();
1735
- } catch (err) {
1736
- observer.onError(err);
1737
- return;
1738
- }
1771
+ return new AnonymousObservable(function (o) {
1772
+ var e = sources[$iterator$]();
1739
1773
 
1740
- var isDisposed,
1741
- subscription = new SerialDisposable();
1774
+ var isDisposed, subscription = new SerialDisposable();
1742
1775
  var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1743
- var currentItem;
1744
1776
  if (isDisposed) { return; }
1745
-
1746
1777
  try {
1747
- currentItem = e.next();
1778
+ var currentItem = e.next();
1748
1779
  } catch (ex) {
1749
- observer.onError(ex);
1750
- return;
1780
+ return o.onError(ex);
1751
1781
  }
1752
1782
 
1753
1783
  if (currentItem.done) {
1754
- observer.onCompleted();
1755
- return;
1784
+ return o.onCompleted();
1756
1785
  }
1757
1786
 
1758
1787
  // Check if promise
@@ -1762,9 +1791,9 @@ if (!Array.prototype.forEach) {
1762
1791
  var d = new SingleAssignmentDisposable();
1763
1792
  subscription.setDisposable(d);
1764
1793
  d.setDisposable(currentValue.subscribe(
1765
- observer.onNext.bind(observer),
1766
- observer.onError.bind(observer),
1767
- function () { self(); })
1794
+ function(x) { o.onNext(x); },
1795
+ function(err) { o.onError(err); },
1796
+ self)
1768
1797
  );
1769
1798
  });
1770
1799
 
@@ -1776,14 +1805,55 @@ if (!Array.prototype.forEach) {
1776
1805
 
1777
1806
  Enumerable.prototype.catchError = function () {
1778
1807
  var sources = this;
1779
- return new AnonymousObservable(function (observer) {
1780
- var e;
1781
- try {
1782
- e = sources[$iterator$]();
1783
- } catch (err) {
1784
- observer.onError(err);
1785
- return;
1786
- }
1808
+ return new AnonymousObservable(function (o) {
1809
+ var e = sources[$iterator$]();
1810
+
1811
+ var isDisposed, subscription = new SerialDisposable();
1812
+ var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
1813
+ if (isDisposed) { return; }
1814
+
1815
+ try {
1816
+ var currentItem = e.next();
1817
+ } catch (ex) {
1818
+ return observer.onError(ex);
1819
+ }
1820
+
1821
+ if (currentItem.done) {
1822
+ if (lastException !== null) {
1823
+ o.onError(lastException);
1824
+ } else {
1825
+ o.onCompleted();
1826
+ }
1827
+ return;
1828
+ }
1829
+
1830
+ // Check if promise
1831
+ var currentValue = currentItem.value;
1832
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1833
+
1834
+ var d = new SingleAssignmentDisposable();
1835
+ subscription.setDisposable(d);
1836
+ d.setDisposable(currentValue.subscribe(
1837
+ function(x) { o.onNext(x); },
1838
+ self,
1839
+ function() { o.onCompleted(); }));
1840
+ });
1841
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1842
+ isDisposed = true;
1843
+ }));
1844
+ });
1845
+ };
1846
+
1847
+
1848
+ Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
1849
+ var sources = this;
1850
+ return new AnonymousObservable(function (o) {
1851
+ var exceptions = new Subject(),
1852
+ notifier = new Subject(),
1853
+ handled = notificationHandler(exceptions),
1854
+ notificationDisposable = handled.subscribe(notifier);
1855
+
1856
+ var e = sources[$iterator$]();
1787
1857
 
1788
1858
  var isDisposed,
1789
1859
  lastException,
@@ -1791,19 +1861,17 @@ if (!Array.prototype.forEach) {
1791
1861
  var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1792
1862
  if (isDisposed) { return; }
1793
1863
 
1794
- var currentItem;
1795
1864
  try {
1796
- currentItem = e.next();
1865
+ var currentItem = e.next();
1797
1866
  } catch (ex) {
1798
- observer.onError(ex);
1799
- return;
1867
+ return o.onError(ex);
1800
1868
  }
1801
1869
 
1802
1870
  if (currentItem.done) {
1803
1871
  if (lastException) {
1804
- observer.onError(lastException);
1872
+ o.onError(lastException);
1805
1873
  } else {
1806
- observer.onCompleted();
1874
+ o.onCompleted();
1807
1875
  }
1808
1876
  return;
1809
1877
  }
@@ -1812,17 +1880,24 @@ if (!Array.prototype.forEach) {
1812
1880
  var currentValue = currentItem.value;
1813
1881
  isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1814
1882
 
1815
- var d = new SingleAssignmentDisposable();
1816
- subscription.setDisposable(d);
1817
- d.setDisposable(currentValue.subscribe(
1818
- observer.onNext.bind(observer),
1883
+ var outer = new SingleAssignmentDisposable();
1884
+ var inner = new SingleAssignmentDisposable();
1885
+ subscription.setDisposable(new CompositeDisposable(inner, outer));
1886
+ outer.setDisposable(currentValue.subscribe(
1887
+ function(x) { o.onNext(x); },
1819
1888
  function (exn) {
1820
- lastException = exn;
1821
- self();
1889
+ inner.setDisposable(notifier.subscribe(self, function(ex) {
1890
+ o.onError(ex);
1891
+ }, function() {
1892
+ o.onCompleted();
1893
+ }));
1894
+
1895
+ exceptions.onNext(exn);
1822
1896
  },
1823
- observer.onCompleted.bind(observer)));
1897
+ function() { o.onCompleted(); }));
1824
1898
  });
1825
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1899
+
1900
+ return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
1826
1901
  isDisposed = true;
1827
1902
  }));
1828
1903
  });
@@ -1841,13 +1916,15 @@ if (!Array.prototype.forEach) {
1841
1916
  };
1842
1917
 
1843
1918
  var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
1844
- selector || (selector = identity);
1919
+ if (selector) {
1920
+ var selectorFn = bindCallback(selector, thisArg, 3);
1921
+ }
1845
1922
  return new Enumerable(function () {
1846
1923
  var index = -1;
1847
1924
  return new Enumerator(
1848
1925
  function () {
1849
1926
  return ++index < source.length ?
1850
- { done: false, value: selector.call(thisArg, source[index], index, source) } :
1927
+ { done: false, value: !selector ? source[index] : selectorFn(source[index], index, source) } :
1851
1928
  doneEnumerator;
1852
1929
  });
1853
1930
  });
@@ -1923,6 +2000,10 @@ if (!Array.prototype.forEach) {
1923
2000
  return new ObserveOnObserver(scheduler, this);
1924
2001
  };
1925
2002
 
2003
+ Observer.prototype.makeSafe = function(disposable) {
2004
+ return new AnonymousSafeObserver(this._onNext, this._onError, this._onCompleted, disposable);
2005
+ };
2006
+
1926
2007
  /**
1927
2008
  * Abstract base class for implementations of the Observer class.
1928
2009
  * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
@@ -1938,6 +2019,15 @@ if (!Array.prototype.forEach) {
1938
2019
  __super__.call(this);
1939
2020
  }
1940
2021
 
2022
+ function notImplemented() {
2023
+ throw new Error('Method not implemented');
2024
+ }
2025
+
2026
+ // Must be implemented by other observers
2027
+ AbstractObserver.prototype.next = notImplemented;
2028
+ AbstractObserver.prototype.error = notImplemented;
2029
+ AbstractObserver.prototype.completed = notImplemented;
2030
+
1941
2031
  /**
1942
2032
  * Notifies the observer of a new element in the sequence.
1943
2033
  * @param {Any} value Next element in the sequence.
@@ -2204,7 +2294,7 @@ if (!Array.prototype.forEach) {
2204
2294
  oldOnError(err);
2205
2295
  };
2206
2296
 
2207
- return subscribe(observer);
2297
+ return subscribe.call(self, observer);
2208
2298
  };
2209
2299
  } else {
2210
2300
  this._subscribe = subscribe;
@@ -2233,7 +2323,7 @@ if (!Array.prototype.forEach) {
2233
2323
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2234
2324
  */
2235
2325
  observableProto.subscribeOnNext = function (onNext, thisArg) {
2236
- return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2326
+ return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
2237
2327
  };
2238
2328
 
2239
2329
  /**
@@ -2243,7 +2333,7 @@ if (!Array.prototype.forEach) {
2243
2333
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2244
2334
  */
2245
2335
  observableProto.subscribeOnError = function (onError, thisArg) {
2246
- return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2336
+ return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
2247
2337
  };
2248
2338
 
2249
2339
  /**
@@ -2253,12 +2343,58 @@ if (!Array.prototype.forEach) {
2253
2343
  * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
2254
2344
  */
2255
2345
  observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2256
- return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2346
+ return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
2257
2347
  };
2258
2348
 
2259
2349
  return Observable;
2260
2350
  })();
2261
2351
 
2352
+ var ObservableBase = Rx.ObservableBase = (function (__super__) {
2353
+
2354
+ inherits(ObservableBase, __super__);
2355
+
2356
+ // Fix subscriber to check for undefined or function returned to decorate as Disposable
2357
+ function fixSubscriber(subscriber) {
2358
+ if (subscriber && typeof subscriber.dispose === 'function') { return subscriber; }
2359
+
2360
+ return typeof subscriber === 'function' ?
2361
+ disposableCreate(subscriber) :
2362
+ disposableEmpty;
2363
+ }
2364
+
2365
+ function setDisposable(s, state) {
2366
+ var ado = state[0], self = state[1];
2367
+ try {
2368
+ ado.setDisposable(fixSubscriber(self.subscribeCore(ado)));
2369
+ } catch (e) {
2370
+ if (!ado.fail(e)) { throw e; }
2371
+ }
2372
+ }
2373
+
2374
+ function subscribe(observer) {
2375
+ var ado = new AutoDetachObserver(observer), state = [ado, this];
2376
+
2377
+ if (currentThreadScheduler.scheduleRequired()) {
2378
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
2379
+ } else {
2380
+ setDisposable(null, state);
2381
+ }
2382
+
2383
+ return ado;
2384
+ }
2385
+
2386
+ function ObservableBase() {
2387
+ __super__.call(this, subscribe);
2388
+ }
2389
+
2390
+ ObservableBase.prototype.subscribeCore = function(observer) {
2391
+ throw new Error('Not implemeneted');
2392
+ }
2393
+
2394
+ return ObservableBase;
2395
+
2396
+ }(Observable));
2397
+
2262
2398
  /**
2263
2399
  * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2264
2400
  *
@@ -2344,22 +2480,56 @@ if (!Array.prototype.forEach) {
2344
2480
  });
2345
2481
  };
2346
2482
 
2483
+ var ToArrayObservable = (function(__super__) {
2484
+ inherits(ToArrayObservable, __super__);
2485
+ function ToArrayObservable(source) {
2486
+ this.source = source;
2487
+ __super__.call(this);
2488
+ }
2489
+
2490
+ ToArrayObservable.prototype.subscribeCore = function(observer) {
2491
+ return this.source.subscribe(new ToArrayObserver(observer));
2492
+ };
2493
+
2494
+ return ToArrayObservable;
2495
+ }(ObservableBase));
2496
+
2497
+ function ToArrayObserver(observer) {
2498
+ this.observer = observer;
2499
+ this.a = [];
2500
+ this.isStopped = false;
2501
+ }
2502
+ ToArrayObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
2503
+ ToArrayObserver.prototype.onError = function (e) {
2504
+ if (!this.isStopped) {
2505
+ this.isStopped = true;
2506
+ this.observer.onError(e);
2507
+ }
2508
+ };
2509
+ ToArrayObserver.prototype.onCompleted = function () {
2510
+ if (!this.isStopped) {
2511
+ this.isStopped = true;
2512
+ this.observer.onNext(this.a);
2513
+ this.observer.onCompleted();
2514
+ }
2515
+ };
2516
+ ToArrayObserver.prototype.dispose = function () { this.isStopped = true; }
2517
+ ToArrayObserver.prototype.fail = function (e) {
2518
+ if (!this.isStopped) {
2519
+ this.isStopped = true;
2520
+ this.observer.onError(e);
2521
+ return true;
2522
+ }
2523
+
2524
+ return false;
2525
+ };
2526
+
2347
2527
  /**
2348
- * Creates an array from an observable sequence.
2349
- * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2350
- */
2528
+ * Creates an array from an observable sequence.
2529
+ * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2530
+ */
2351
2531
  observableProto.toArray = function () {
2352
- var source = this;
2353
- return new AnonymousObservable(function(observer) {
2354
- var arr = [];
2355
- return source.subscribe(
2356
- arr.push.bind(arr),
2357
- observer.onError.bind(observer),
2358
- function () {
2359
- observer.onNext(arr);
2360
- observer.onCompleted();
2361
- });
2362
- }, source);
2532
+ return new ToArrayObservable(this);
2363
2533
  };
2364
2534
 
2365
2535
  /**
@@ -2414,13 +2584,72 @@ if (!Array.prototype.forEach) {
2414
2584
  });
2415
2585
  };
2416
2586
 
2417
- var maxSafeInteger = Math.pow(2, 53) - 1;
2587
+ var FromObservable = (function(__super__) {
2588
+ inherits(FromObservable, __super__);
2589
+ function FromObservable(iterable, mapper, scheduler) {
2590
+ this.iterable = iterable;
2591
+ this.mapper = mapper;
2592
+ this.scheduler = scheduler;
2593
+ __super__.call(this);
2594
+ }
2418
2595
 
2419
- function StringIterable(str) {
2420
- this._s = s;
2421
- }
2596
+ FromObservable.prototype.subscribeCore = function (observer) {
2597
+ var sink = new FromSink(observer, this);
2598
+ return sink.run();
2599
+ };
2422
2600
 
2423
- StringIterable.prototype[$iterator$] = function () {
2601
+ return FromObservable;
2602
+ }(ObservableBase));
2603
+
2604
+ var FromSink = (function () {
2605
+ function FromSink(observer, parent) {
2606
+ this.observer = observer;
2607
+ this.parent = parent;
2608
+ }
2609
+
2610
+ FromSink.prototype.run = function () {
2611
+ var list = Object(this.parent.iterable),
2612
+ it = getIterable(list),
2613
+ observer = this.observer,
2614
+ mapper = this.parent.mapper;
2615
+
2616
+ function loopRecursive(i, recurse) {
2617
+ try {
2618
+ var next = it.next();
2619
+ } catch (e) {
2620
+ return observer.onError(e);
2621
+ }
2622
+ if (next.done) {
2623
+ return observer.onCompleted();
2624
+ }
2625
+
2626
+ var result = next.value;
2627
+
2628
+ if (mapper) {
2629
+ try {
2630
+ result = mapper(result, i);
2631
+ } catch (e) {
2632
+ return observer.onError(e);
2633
+ }
2634
+ }
2635
+
2636
+ observer.onNext(result);
2637
+ recurse(i + 1);
2638
+ }
2639
+
2640
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2641
+ };
2642
+
2643
+ return FromSink;
2644
+ }());
2645
+
2646
+ var maxSafeInteger = Math.pow(2, 53) - 1;
2647
+
2648
+ function StringIterable(str) {
2649
+ this._s = s;
2650
+ }
2651
+
2652
+ StringIterable.prototype[$iterator$] = function () {
2424
2653
  return new StringIterator(this._s);
2425
2654
  };
2426
2655
 
@@ -2435,12 +2664,7 @@ if (!Array.prototype.forEach) {
2435
2664
  };
2436
2665
 
2437
2666
  StringIterator.prototype.next = function () {
2438
- if (this._i < this._l) {
2439
- var val = this._s.charAt(this._i++);
2440
- return { done: false, value: val };
2441
- } else {
2442
- return doneEnumerator;
2443
- }
2667
+ return this._i < this._l ? { done: false, value: this._s.charAt(this._i++) } : doneEnumerator;
2444
2668
  };
2445
2669
 
2446
2670
  function ArrayIterable(a) {
@@ -2462,12 +2686,7 @@ if (!Array.prototype.forEach) {
2462
2686
  };
2463
2687
 
2464
2688
  ArrayIterator.prototype.next = function () {
2465
- if (this._i < this._l) {
2466
- var val = this._a[this._i++];
2467
- return { done: false, value: val };
2468
- } else {
2469
- return doneEnumerator;
2470
- }
2689
+ return this._i < this._l ? { done: false, value: this._a[this._i++] } : doneEnumerator;
2471
2690
  };
2472
2691
 
2473
2692
  function numberIsFinite(value) {
@@ -2510,12 +2729,12 @@ if (!Array.prototype.forEach) {
2510
2729
  }
2511
2730
 
2512
2731
  /**
2513
- * This method creates a new Observable sequence from an array-like or iterable object.
2514
- * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
2515
- * @param {Function} [mapFn] Map function to call on every element of the array.
2516
- * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2517
- * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2518
- */
2732
+ * This method creates a new Observable sequence from an array-like or iterable object.
2733
+ * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
2734
+ * @param {Function} [mapFn] Map function to call on every element of the array.
2735
+ * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2736
+ * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2737
+ */
2519
2738
  var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2520
2739
  if (iterable == null) {
2521
2740
  throw new Error('iterable cannot be null.')
@@ -2523,61 +2742,56 @@ if (!Array.prototype.forEach) {
2523
2742
  if (mapFn && !isFunction(mapFn)) {
2524
2743
  throw new Error('mapFn when provided must be a function');
2525
2744
  }
2745
+ if (mapFn) {
2746
+ var mapper = bindCallback(mapFn, thisArg, 2);
2747
+ }
2526
2748
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2527
- var list = Object(iterable), it = getIterable(list);
2528
- return new AnonymousObservable(function (observer) {
2529
- var i = 0;
2530
- return scheduler.scheduleRecursive(function (self) {
2531
- var next;
2532
- try {
2533
- next = it.next();
2534
- } catch (e) {
2535
- observer.onError(e);
2536
- return;
2537
- }
2538
- if (next.done) {
2539
- observer.onCompleted();
2540
- return;
2541
- }
2749
+ return new FromObservable(iterable, mapper, scheduler);
2750
+ }
2542
2751
 
2543
- var result = next.value;
2752
+ var FromArrayObservable = (function(__super__) {
2753
+ inherits(FromArrayObservable, __super__);
2754
+ function FromArrayObservable(args, scheduler) {
2755
+ this.args = args;
2756
+ this.scheduler = scheduler || currentThreadScheduler;
2757
+ __super__.call(this);
2758
+ }
2544
2759
 
2545
- if (mapFn && isFunction(mapFn)) {
2546
- try {
2547
- result = mapFn.call(thisArg, result, i);
2548
- } catch (e) {
2549
- observer.onError(e);
2550
- return;
2551
- }
2552
- }
2760
+ FromArrayObservable.prototype.subscribeCore = function (observer) {
2761
+ var sink = new FromArraySink(observer, this);
2762
+ return sink.run();
2763
+ };
2553
2764
 
2554
- observer.onNext(result);
2555
- i++;
2556
- self();
2557
- });
2558
- });
2765
+ return FromArrayObservable;
2766
+ }(ObservableBase));
2767
+
2768
+ function FromArraySink(observer, parent) {
2769
+ this.observer = observer;
2770
+ this.parent = parent;
2771
+ }
2772
+
2773
+ FromArraySink.prototype.run = function () {
2774
+ var observer = this.observer, args = this.parent.args, len = args.length;
2775
+ function loopRecursive(i, recurse) {
2776
+ if (i < len) {
2777
+ observer.onNext(args[i]);
2778
+ recurse(i + 1);
2779
+ } else {
2780
+ observer.onCompleted();
2781
+ }
2782
+ }
2783
+
2784
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2559
2785
  };
2560
2786
 
2561
2787
  /**
2562
- * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2563
- * @deprecated use Observable.from or Observable.of
2564
- * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2565
- * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2566
- */
2788
+ * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2789
+ * @deprecated use Observable.from or Observable.of
2790
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2791
+ * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2792
+ */
2567
2793
  var observableFromArray = Observable.fromArray = function (array, scheduler) {
2568
- deprecate('fromArray', 'from');
2569
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2570
- return new AnonymousObservable(function (observer) {
2571
- var count = 0, len = array.length;
2572
- return scheduler.scheduleRecursive(function (self) {
2573
- if (count < len) {
2574
- observer.onNext(array[count++]);
2575
- self();
2576
- } else {
2577
- observer.onCompleted();
2578
- }
2579
- });
2580
- });
2794
+ return new FromArrayObservable(array, scheduler)
2581
2795
  };
2582
2796
 
2583
2797
  /**
@@ -2624,35 +2838,28 @@ if (!Array.prototype.forEach) {
2624
2838
  };
2625
2839
 
2626
2840
  function observableOf (scheduler, array) {
2627
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2628
- return new AnonymousObservable(function (observer) {
2629
- var count = 0, len = array.length;
2630
- return scheduler.scheduleRecursive(function (self) {
2631
- if (count < len) {
2632
- observer.onNext(array[count++]);
2633
- self();
2634
- } else {
2635
- observer.onCompleted();
2636
- }
2637
- });
2638
- });
2841
+ return new FromArrayObservable(array, scheduler);
2639
2842
  }
2640
2843
 
2641
2844
  /**
2642
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2643
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2644
- */
2845
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2846
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2847
+ */
2645
2848
  Observable.of = function () {
2646
- return observableOf(null, arguments);
2849
+ var len = arguments.length, args = new Array(len);
2850
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2851
+ return new FromArrayObservable(args);
2647
2852
  };
2648
2853
 
2649
2854
  /**
2650
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2651
- * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2652
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2653
- */
2855
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2856
+ * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2857
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2858
+ */
2654
2859
  Observable.ofWithScheduler = function (scheduler) {
2655
- return observableOf(scheduler, slice.call(arguments, 1));
2860
+ var len = arguments.length, args = new Array(len - 1);
2861
+ for(var i = 1; i < len; i++) { args[i - 1] = arguments[i]; }
2862
+ return new FromArrayObservable(args, scheduler);
2656
2863
  };
2657
2864
 
2658
2865
  /**
@@ -2666,23 +2873,20 @@ if (!Array.prototype.forEach) {
2666
2873
  };
2667
2874
 
2668
2875
  /**
2669
- * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2670
- *
2671
- * @example
2672
- * var res = Rx.Observable.range(0, 10);
2673
- * var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
2674
- * @param {Number} start The value of the first integer in the sequence.
2675
- * @param {Number} count The number of sequential integers to generate.
2676
- * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2677
- * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2876
+ * Convert an object into an observable sequence of [key, value] pairs.
2877
+ * @param {Object} obj The object to inspect.
2878
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2879
+ * @returns {Observable} An observable sequence of [key, value] pairs from the object.
2678
2880
  */
2679
- Observable.range = function (start, count, scheduler) {
2680
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2881
+ Observable.pairs = function (obj, scheduler) {
2882
+ scheduler || (scheduler = Rx.Scheduler.currentThread);
2681
2883
  return new AnonymousObservable(function (observer) {
2682
- return scheduler.scheduleRecursiveWithState(0, function (i, self) {
2683
- if (i < count) {
2684
- observer.onNext(start + i);
2685
- self(i + 1);
2884
+ var keys = Object.keys(obj), len = keys.length;
2885
+ return scheduler.scheduleRecursiveWithState(0, function (idx, self) {
2886
+ if (idx < len) {
2887
+ var key = keys[idx];
2888
+ observer.onNext([key, obj[key]]);
2889
+ self(idx + 1);
2686
2890
  } else {
2687
2891
  observer.onCompleted();
2688
2892
  }
@@ -2690,6 +2894,58 @@ if (!Array.prototype.forEach) {
2690
2894
  });
2691
2895
  };
2692
2896
 
2897
+ var RangeObservable = (function(__super__) {
2898
+ inherits(RangeObservable, __super__);
2899
+ function RangeObservable(start, count, scheduler) {
2900
+ this.start = start;
2901
+ this.count = count;
2902
+ this.scheduler = scheduler;
2903
+ __super__.call(this);
2904
+ }
2905
+
2906
+ RangeObservable.prototype.subscribeCore = function (observer) {
2907
+ var sink = new RangeSink(observer, this);
2908
+ return sink.run();
2909
+ };
2910
+
2911
+ return RangeObservable;
2912
+ }(ObservableBase));
2913
+
2914
+ var RangeSink = (function () {
2915
+ function RangeSink(observer, parent) {
2916
+ this.observer = observer;
2917
+ this.parent = parent;
2918
+ }
2919
+
2920
+ RangeSink.prototype.run = function () {
2921
+ var start = this.parent.start, count = this.parent.count, observer = this.observer;
2922
+ function loopRecursive(i, recurse) {
2923
+ if (i < count) {
2924
+ observer.onNext(start + i);
2925
+ recurse(i + 1);
2926
+ } else {
2927
+ observer.onCompleted();
2928
+ }
2929
+ }
2930
+
2931
+ return this.parent.scheduler.scheduleRecursiveWithState(0, loopRecursive);
2932
+ };
2933
+
2934
+ return RangeSink;
2935
+ }());
2936
+
2937
+ /**
2938
+ * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
2939
+ * @param {Number} start The value of the first integer in the sequence.
2940
+ * @param {Number} count The number of sequential integers to generate.
2941
+ * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
2942
+ * @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
2943
+ */
2944
+ Observable.range = function (start, count, scheduler) {
2945
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2946
+ return new RangeObservable(start, count, scheduler);
2947
+ };
2948
+
2693
2949
  /**
2694
2950
  * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
2695
2951
  *
@@ -2711,10 +2967,6 @@ if (!Array.prototype.forEach) {
2711
2967
  /**
2712
2968
  * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
2713
2969
  * There is an alias called 'just', and 'returnValue' for browsers <IE9.
2714
- *
2715
- * @example
2716
- * var res = Rx.Observable.return(42);
2717
- * var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
2718
2970
  * @param {Mixed} value Single element in the resulting observable sequence.
2719
2971
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2720
2972
  * @returns {Observable} An observable sequence containing the single specified element.
@@ -2731,26 +2983,32 @@ if (!Array.prototype.forEach) {
2731
2983
 
2732
2984
  /** @deprecated use return or just */
2733
2985
  Observable.returnValue = function () {
2734
- deprecate('returnValue', 'return or just');
2986
+ //deprecate('returnValue', 'return or just');
2735
2987
  return observableReturn.apply(null, arguments);
2736
2988
  };
2737
2989
 
2738
2990
  /**
2739
2991
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2740
2992
  * There is an alias to this method called 'throwError' for browsers <IE9.
2741
- * @param {Mixed} exception An object used for the sequence's termination.
2993
+ * @param {Mixed} error An object used for the sequence's termination.
2742
2994
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2743
2995
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2744
2996
  */
2745
- var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
2997
+ var observableThrow = Observable['throw'] = Observable.throwError = function (error, scheduler) {
2746
2998
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2747
2999
  return new AnonymousObservable(function (observer) {
2748
3000
  return scheduler.schedule(function () {
2749
- observer.onError(exception);
3001
+ observer.onError(error);
2750
3002
  });
2751
3003
  });
2752
3004
  };
2753
3005
 
3006
+ /** @deprecated use #some instead */
3007
+ Observable.throwException = function () {
3008
+ //deprecate('throwException', 'throwError');
3009
+ return Observable.throwError.apply(null, arguments);
3010
+ };
3011
+
2754
3012
  /**
2755
3013
  * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
2756
3014
  * @param {Function} resourceFactory Factory function to obtain a resource object.
@@ -2846,8 +3104,13 @@ if (!Array.prototype.forEach) {
2846
3104
  * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
2847
3105
  */
2848
3106
  Observable.amb = function () {
2849
- var acc = observableNever(),
2850
- items = argsOrArray(arguments, 0);
3107
+ var acc = observableNever(), items = [];
3108
+ if (Array.isArray(arguments[0])) {
3109
+ items = arguments[0];
3110
+ } else {
3111
+ for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
3112
+ }
3113
+
2851
3114
  function func(previous, current) {
2852
3115
  return previous.amb(current);
2853
3116
  }
@@ -2858,23 +3121,21 @@ if (!Array.prototype.forEach) {
2858
3121
  };
2859
3122
 
2860
3123
  function observableCatchHandler(source, handler) {
2861
- return new AnonymousObservable(function (observer) {
3124
+ return new AnonymousObservable(function (o) {
2862
3125
  var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2863
3126
  subscription.setDisposable(d1);
2864
- d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2865
- var d, result;
3127
+ d1.setDisposable(source.subscribe(function (x) { o.onNext(x); }, function (e) {
2866
3128
  try {
2867
- result = handler(exception);
3129
+ var result = handler(e);
2868
3130
  } catch (ex) {
2869
- observer.onError(ex);
2870
- return;
3131
+ return o.onError(ex);
2871
3132
  }
2872
3133
  isPromise(result) && (result = observableFromPromise(result));
2873
3134
 
2874
- d = new SingleAssignmentDisposable();
3135
+ var d = new SingleAssignmentDisposable();
2875
3136
  subscription.setDisposable(d);
2876
- d.setDisposable(result.subscribe(observer));
2877
- }, observer.onCompleted.bind(observer)));
3137
+ d.setDisposable(result.subscribe(o));
3138
+ }, function (x) { o.onCompleted(x); }));
2878
3139
 
2879
3140
  return subscription;
2880
3141
  }, source);
@@ -2888,35 +3149,25 @@ if (!Array.prototype.forEach) {
2888
3149
  * @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.
2889
3150
  * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2890
3151
  */
2891
- observableProto['catch'] = observableProto.catchError = function (handlerOrSecond) {
3152
+ observableProto['catch'] = observableProto.catchError = observableProto.catchException = function (handlerOrSecond) {
2892
3153
  return typeof handlerOrSecond === 'function' ?
2893
3154
  observableCatchHandler(this, handlerOrSecond) :
2894
3155
  observableCatch([this, handlerOrSecond]);
2895
3156
  };
2896
3157
 
2897
- /**
2898
- * @deprecated use #catch or #catchError instead.
2899
- */
2900
- observableProto.catchException = function (handlerOrSecond) {
2901
- deprecate('catchException', 'catch or catchError');
2902
- return this.catchError(handlerOrSecond);
2903
- };
2904
-
2905
3158
  /**
2906
3159
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2907
3160
  * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
2908
3161
  * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
2909
3162
  */
2910
- var observableCatch = Observable.catchError = Observable['catch'] = function () {
2911
- return enumerableOf(argsOrArray(arguments, 0)).catchError();
2912
- };
2913
-
2914
- /**
2915
- * @deprecated use #catch or #catchError instead.
2916
- */
2917
- Observable.catchException = function () {
2918
- deprecate('catchException', 'catch or catchError');
2919
- return observableCatch.apply(null, arguments);
3163
+ var observableCatch = Observable.catchError = Observable['catch'] = Observable.catchException = function () {
3164
+ var items = [];
3165
+ if (Array.isArray(arguments[0])) {
3166
+ items = arguments[0];
3167
+ } else {
3168
+ for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
3169
+ }
3170
+ return enumerableOf(items).catchError();
2920
3171
  };
2921
3172
 
2922
3173
  /**
@@ -2929,7 +3180,8 @@ if (!Array.prototype.forEach) {
2929
3180
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2930
3181
  */
2931
3182
  observableProto.combineLatest = function () {
2932
- var args = slice.call(arguments);
3183
+ var len = arguments.length, args = new Array(len);
3184
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2933
3185
  if (Array.isArray(args[0])) {
2934
3186
  args[0].unshift(this);
2935
3187
  } else {
@@ -2947,54 +3199,51 @@ if (!Array.prototype.forEach) {
2947
3199
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2948
3200
  */
2949
3201
  var combineLatest = Observable.combineLatest = function () {
2950
- var args = slice.call(arguments), resultSelector = args.pop();
3202
+ var len = arguments.length, args = new Array(len);
3203
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3204
+ var resultSelector = args.pop();
3205
+ len--;
3206
+ Array.isArray(args[0]) && (args = args[0]);
2951
3207
 
2952
- if (Array.isArray(args[0])) {
2953
- args = args[0];
2954
- }
2955
-
2956
- return new AnonymousObservable(function (observer) {
3208
+ return new AnonymousObservable(function (o) {
2957
3209
  var falseFactory = function () { return false; },
2958
- n = args.length,
2959
- hasValue = arrayInitialize(n, falseFactory),
3210
+ hasValue = arrayInitialize(len, falseFactory),
2960
3211
  hasValueAll = false,
2961
- isDone = arrayInitialize(n, falseFactory),
2962
- values = new Array(n);
3212
+ isDone = arrayInitialize(len, falseFactory),
3213
+ values = new Array(len);
2963
3214
 
2964
3215
  function next(i) {
2965
- var res;
2966
3216
  hasValue[i] = true;
2967
3217
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2968
3218
  try {
2969
- res = resultSelector.apply(null, values);
3219
+ var res = resultSelector.apply(null, values);
2970
3220
  } catch (ex) {
2971
- observer.onError(ex);
3221
+ o.onError(ex);
2972
3222
  return;
2973
3223
  }
2974
- observer.onNext(res);
3224
+ o.onNext(res);
2975
3225
  } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2976
- observer.onCompleted();
3226
+ o.onCompleted();
2977
3227
  }
2978
3228
  }
2979
3229
 
2980
3230
  function done (i) {
2981
3231
  isDone[i] = true;
2982
- if (isDone.every(identity)) {
2983
- observer.onCompleted();
2984
- }
3232
+ isDone.every(identity) && o.onCompleted();
2985
3233
  }
2986
3234
 
2987
- var subscriptions = new Array(n);
2988
- for (var idx = 0; idx < n; idx++) {
3235
+ var subscriptions = new Array(len);
3236
+ for (var idx = 0; idx < len; idx++) {
2989
3237
  (function (i) {
2990
3238
  var source = args[i], sad = new SingleAssignmentDisposable();
2991
3239
  isPromise(source) && (source = observableFromPromise(source));
2992
3240
  sad.setDisposable(source.subscribe(function (x) {
2993
- values[i] = x;
2994
- next(i);
2995
- }, observer.onError.bind(observer), function () {
2996
- done(i);
2997
- }));
3241
+ values[i] = x;
3242
+ next(i);
3243
+ },
3244
+ function(e) { o.onError(e); },
3245
+ function () { done(i); }
3246
+ ));
2998
3247
  subscriptions[i] = sad;
2999
3248
  }(idx));
3000
3249
  }
@@ -3003,19 +3252,15 @@ if (!Array.prototype.forEach) {
3003
3252
  }, this);
3004
3253
  };
3005
3254
 
3006
- /**
3007
- * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
3008
- *
3009
- * @example
3010
- * 1 - concatenated = xs.concat(ys, zs);
3011
- * 2 - concatenated = xs.concat([ys, zs]);
3012
- * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
3013
- */
3014
- observableProto.concat = function () {
3015
- var items = slice.call(arguments, 0);
3016
- items.unshift(this);
3017
- return observableConcat.apply(this, items);
3018
- };
3255
+ /**
3256
+ * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
3257
+ * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
3258
+ */
3259
+ observableProto.concat = function () {
3260
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3261
+ args.unshift(this);
3262
+ return observableConcat.apply(null, args);
3263
+ };
3019
3264
 
3020
3265
  /**
3021
3266
  * Concatenates all the observable sequences.
@@ -3023,20 +3268,21 @@ if (!Array.prototype.forEach) {
3023
3268
  * @returns {Observable} An observable sequence that contains the elements of each given sequence, in sequential order.
3024
3269
  */
3025
3270
  var observableConcat = Observable.concat = function () {
3026
- return enumerableOf(argsOrArray(arguments, 0)).concat();
3271
+ var args;
3272
+ if (Array.isArray(arguments[0])) {
3273
+ args = arguments[0];
3274
+ } else {
3275
+ args = new Array(arguments.length);
3276
+ for(var i = 0, len = arguments.length; i < len; i++) { args[i] = arguments[i]; }
3277
+ }
3278
+ return enumerableOf(args).concat();
3027
3279
  };
3028
3280
 
3029
3281
  /**
3030
3282
  * Concatenates an observable sequence of observable sequences.
3031
3283
  * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
3032
3284
  */
3033
- observableProto.concatAll = function () {
3034
- return this.merge(1);
3035
- };
3036
-
3037
- /** @deprecated Use `concatAll` instead. */
3038
- observableProto.concatObservable = function () {
3039
- deprecate('concatObservable', 'concatAll');
3285
+ observableProto.concatAll = observableProto.concatObservable = function () {
3040
3286
  return this.merge(1);
3041
3287
  };
3042
3288
 
@@ -3053,7 +3299,7 @@ if (!Array.prototype.forEach) {
3053
3299
  observableProto.merge = function (maxConcurrentOrOther) {
3054
3300
  if (typeof maxConcurrentOrOther !== 'number') { return observableMerge(this, maxConcurrentOrOther); }
3055
3301
  var sources = this;
3056
- return new AnonymousObservable(function (observer) {
3302
+ return new AnonymousObservable(function (o) {
3057
3303
  var activeCount = 0, group = new CompositeDisposable(), isStopped = false, q = [];
3058
3304
 
3059
3305
  function subscribe(xs) {
@@ -3063,13 +3309,13 @@ if (!Array.prototype.forEach) {
3063
3309
  // Check for promises support
3064
3310
  isPromise(xs) && (xs = observableFromPromise(xs));
3065
3311
 
3066
- subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
3312
+ subscription.setDisposable(xs.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
3067
3313
  group.remove(subscription);
3068
3314
  if (q.length > 0) {
3069
3315
  subscribe(q.shift());
3070
3316
  } else {
3071
3317
  activeCount--;
3072
- isStopped && activeCount === 0 && observer.onCompleted();
3318
+ isStopped && activeCount === 0 && o.onCompleted();
3073
3319
  }
3074
3320
  }));
3075
3321
  }
@@ -3080,9 +3326,9 @@ if (!Array.prototype.forEach) {
3080
3326
  } else {
3081
3327
  q.push(innerSource);
3082
3328
  }
3083
- }, observer.onError.bind(observer), function () {
3329
+ }, function (e) { o.onError(e); }, function () {
3084
3330
  isStopped = true;
3085
- activeCount === 0 && observer.onCompleted();
3331
+ activeCount === 0 && o.onCompleted();
3086
3332
  }));
3087
3333
  return group;
3088
3334
  }, sources);
@@ -3094,16 +3340,16 @@ if (!Array.prototype.forEach) {
3094
3340
  * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
3095
3341
  */
3096
3342
  var observableMerge = Observable.merge = function () {
3097
- var scheduler, sources;
3343
+ var scheduler, sources = [], i, len = arguments.length;
3098
3344
  if (!arguments[0]) {
3099
3345
  scheduler = immediateScheduler;
3100
- sources = slice.call(arguments, 1);
3346
+ for(i = 1; i < len; i++) { sources.push(arguments[i]); }
3101
3347
  } else if (isScheduler(arguments[0])) {
3102
3348
  scheduler = arguments[0];
3103
- sources = slice.call(arguments, 1);
3349
+ for(i = 1; i < len; i++) { sources.push(arguments[i]); }
3104
3350
  } else {
3105
3351
  scheduler = immediateScheduler;
3106
- sources = slice.call(arguments, 0);
3352
+ for(i = 0; i < len; i++) { sources.push(arguments[i]); }
3107
3353
  }
3108
3354
  if (Array.isArray(sources[0])) {
3109
3355
  sources = sources[0];
@@ -3115,9 +3361,9 @@ if (!Array.prototype.forEach) {
3115
3361
  * Merges an observable sequence of observable sequences into an observable sequence.
3116
3362
  * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
3117
3363
  */
3118
- observableProto.mergeAll = function () {
3364
+ observableProto.mergeAll = observableProto.mergeObservable = function () {
3119
3365
  var sources = this;
3120
- return new AnonymousObservable(function (observer) {
3366
+ return new AnonymousObservable(function (o) {
3121
3367
  var group = new CompositeDisposable(),
3122
3368
  isStopped = false,
3123
3369
  m = new SingleAssignmentDisposable();
@@ -3130,26 +3376,18 @@ if (!Array.prototype.forEach) {
3130
3376
  // Check for promises support
3131
3377
  isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3132
3378
 
3133
- innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
3379
+ innerSubscription.setDisposable(innerSource.subscribe(function (x) { o.onNext(x); }, function (e) { o.onError(e); }, function () {
3134
3380
  group.remove(innerSubscription);
3135
- isStopped && group.length === 1 && observer.onCompleted();
3381
+ isStopped && group.length === 1 && o.onCompleted();
3136
3382
  }));
3137
- }, observer.onError.bind(observer), function () {
3383
+ }, function (e) { o.onError(e); }, function () {
3138
3384
  isStopped = true;
3139
- group.length === 1 && observer.onCompleted();
3385
+ group.length === 1 && o.onCompleted();
3140
3386
  }));
3141
3387
  return group;
3142
3388
  }, sources);
3143
3389
  };
3144
3390
 
3145
- /**
3146
- * @deprecated use #mergeAll instead.
3147
- */
3148
- observableProto.mergeObservable = function () {
3149
- deprecate('mergeObservable', 'mergeAll');
3150
- return this.mergeAll.apply(this, arguments);
3151
- };
3152
-
3153
3391
  /**
3154
3392
  * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
3155
3393
  * @param {Observable} second Second observable sequence used to produce results after the first sequence terminates.
@@ -3169,7 +3407,12 @@ if (!Array.prototype.forEach) {
3169
3407
  * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
3170
3408
  */
3171
3409
  var onErrorResumeNext = Observable.onErrorResumeNext = function () {
3172
- var sources = argsOrArray(arguments, 0);
3410
+ var sources = [];
3411
+ if (Array.isArray(arguments[0])) {
3412
+ sources = arguments[0];
3413
+ } else {
3414
+ for(var i = 0, len = arguments.length; i < len; i++) { sources.push(arguments[i]); }
3415
+ }
3173
3416
  return new AnonymousObservable(function (observer) {
3174
3417
  var pos = 0, subscription = new SerialDisposable(),
3175
3418
  cancelable = immediateScheduler.scheduleRecursive(function (self) {
@@ -3195,12 +3438,12 @@ if (!Array.prototype.forEach) {
3195
3438
  */
3196
3439
  observableProto.skipUntil = function (other) {
3197
3440
  var source = this;
3198
- return new AnonymousObservable(function (observer) {
3441
+ return new AnonymousObservable(function (o) {
3199
3442
  var isOpen = false;
3200
3443
  var disposables = new CompositeDisposable(source.subscribe(function (left) {
3201
- isOpen && observer.onNext(left);
3202
- }, observer.onError.bind(observer), function () {
3203
- isOpen && observer.onCompleted();
3444
+ isOpen && o.onNext(left);
3445
+ }, function (e) { o.onError(e); }, function () {
3446
+ isOpen && o.onCompleted();
3204
3447
  }));
3205
3448
 
3206
3449
  isPromise(other) && (other = observableFromPromise(other));
@@ -3210,7 +3453,7 @@ if (!Array.prototype.forEach) {
3210
3453
  rightSubscription.setDisposable(other.subscribe(function () {
3211
3454
  isOpen = true;
3212
3455
  rightSubscription.dispose();
3213
- }, observer.onError.bind(observer), function () {
3456
+ }, function (e) { o.onError(e); }, function () {
3214
3457
  rightSubscription.dispose();
3215
3458
  }));
3216
3459
 
@@ -3248,7 +3491,7 @@ if (!Array.prototype.forEach) {
3248
3491
  }
3249
3492
  }));
3250
3493
  },
3251
- observer.onError.bind(observer),
3494
+ function (e) { observer.onError(e); },
3252
3495
  function () {
3253
3496
  isStopped = true;
3254
3497
  !hasLatest && observer.onCompleted();
@@ -3264,15 +3507,79 @@ if (!Array.prototype.forEach) {
3264
3507
  */
3265
3508
  observableProto.takeUntil = function (other) {
3266
3509
  var source = this;
3267
- return new AnonymousObservable(function (observer) {
3510
+ return new AnonymousObservable(function (o) {
3268
3511
  isPromise(other) && (other = observableFromPromise(other));
3269
3512
  return new CompositeDisposable(
3270
- source.subscribe(observer),
3271
- other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
3513
+ source.subscribe(o),
3514
+ other.subscribe(function () { o.onCompleted(); }, function (e) { o.onError(e); }, noop)
3272
3515
  );
3273
3516
  }, source);
3274
3517
  };
3275
3518
 
3519
+ /**
3520
+ * Merges the specified observable sequences into one observable sequence by using the selector function only when the (first) source observable sequence produces an element.
3521
+ *
3522
+ * @example
3523
+ * 1 - obs = obs1.withLatestFrom(obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
3524
+ * 2 - obs = obs1.withLatestFrom([obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
3525
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3526
+ */
3527
+ observableProto.withLatestFrom = function () {
3528
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
3529
+ var resultSelector = args.pop(), source = this;
3530
+
3531
+ if (typeof source === 'undefined') {
3532
+ throw new Error('Source observable not found for withLatestFrom().');
3533
+ }
3534
+ if (typeof resultSelector !== 'function') {
3535
+ throw new Error('withLatestFrom() expects a resultSelector function.');
3536
+ }
3537
+ if (Array.isArray(args[0])) {
3538
+ args = args[0];
3539
+ }
3540
+
3541
+ return new AnonymousObservable(function (observer) {
3542
+ var falseFactory = function () { return false; },
3543
+ n = args.length,
3544
+ hasValue = arrayInitialize(n, falseFactory),
3545
+ hasValueAll = false,
3546
+ values = new Array(n);
3547
+
3548
+ var subscriptions = new Array(n + 1);
3549
+ for (var idx = 0; idx < n; idx++) {
3550
+ (function (i) {
3551
+ var other = args[i], sad = new SingleAssignmentDisposable();
3552
+ isPromise(other) && (other = observableFromPromise(other));
3553
+ sad.setDisposable(other.subscribe(function (x) {
3554
+ values[i] = x;
3555
+ hasValue[i] = true;
3556
+ hasValueAll = hasValue.every(identity);
3557
+ }, observer.onError.bind(observer), function () {}));
3558
+ subscriptions[i] = sad;
3559
+ }(idx));
3560
+ }
3561
+
3562
+ var sad = new SingleAssignmentDisposable();
3563
+ sad.setDisposable(source.subscribe(function (x) {
3564
+ var res;
3565
+ var allValues = [x].concat(values);
3566
+ if (!hasValueAll) return;
3567
+ try {
3568
+ res = resultSelector.apply(null, allValues);
3569
+ } catch (ex) {
3570
+ observer.onError(ex);
3571
+ return;
3572
+ }
3573
+ observer.onNext(res);
3574
+ }, observer.onError.bind(observer), function () {
3575
+ observer.onCompleted();
3576
+ }));
3577
+ subscriptions[n] = sad;
3578
+
3579
+ return new CompositeDisposable(subscriptions);
3580
+ }, this);
3581
+ };
3582
+
3276
3583
  function zipArray(second, resultSelector) {
3277
3584
  var first = this;
3278
3585
  return new AnonymousObservable(function (observer) {
@@ -3283,36 +3590,39 @@ if (!Array.prototype.forEach) {
3283
3590
  try {
3284
3591
  result = resultSelector(left, right);
3285
3592
  } catch (e) {
3286
- observer.onError(e);
3287
- return;
3593
+ return observer.onError(e);
3288
3594
  }
3289
3595
  observer.onNext(result);
3290
3596
  } else {
3291
3597
  observer.onCompleted();
3292
3598
  }
3293
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3599
+ }, function (e) { observer.onError(e); }, function () { observer.onCompleted(); });
3294
3600
  }, first);
3295
3601
  }
3296
3602
 
3603
+ function falseFactory() { return false; }
3604
+ function emptyArrayFactory() { return []; }
3605
+
3297
3606
  /**
3298
3607
  * 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.
3299
- * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
3608
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
3300
3609
  *
3301
3610
  * @example
3302
3611
  * 1 - res = obs1.zip(obs2, fn);
3303
3612
  * 1 - res = x1.zip([1,2,3], fn);
3304
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3613
+ * @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
3305
3614
  */
3306
3615
  observableProto.zip = function () {
3307
- if (Array.isArray(arguments[0])) {
3308
- return zipArray.apply(this, arguments);
3309
- }
3310
- var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
3311
- sources.unshift(parent);
3616
+ if (Array.isArray(arguments[0])) { return zipArray.apply(this, arguments); }
3617
+ var len = arguments.length, args = new Array(len);
3618
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3619
+
3620
+ var parent = this, resultSelector = args.pop();
3621
+ args.unshift(parent);
3312
3622
  return new AnonymousObservable(function (observer) {
3313
- var n = sources.length,
3314
- queues = arrayInitialize(n, function () { return []; }),
3315
- isDone = arrayInitialize(n, function () { return false; });
3623
+ var n = args.length,
3624
+ queues = arrayInitialize(n, emptyArrayFactory),
3625
+ isDone = arrayInitialize(n, falseFactory);
3316
3626
 
3317
3627
  function next(i) {
3318
3628
  var res, queuedValues;
@@ -3340,12 +3650,12 @@ if (!Array.prototype.forEach) {
3340
3650
  var subscriptions = new Array(n);
3341
3651
  for (var idx = 0; idx < n; idx++) {
3342
3652
  (function (i) {
3343
- var source = sources[i], sad = new SingleAssignmentDisposable();
3653
+ var source = args[i], sad = new SingleAssignmentDisposable();
3344
3654
  isPromise(source) && (source = observableFromPromise(source));
3345
3655
  sad.setDisposable(source.subscribe(function (x) {
3346
3656
  queues[i].push(x);
3347
3657
  next(i);
3348
- }, observer.onError.bind(observer), function () {
3658
+ }, function (e) { observer.onError(e); }, function () {
3349
3659
  done(i);
3350
3660
  }));
3351
3661
  subscriptions[i] = sad;
@@ -3363,7 +3673,9 @@ if (!Array.prototype.forEach) {
3363
3673
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3364
3674
  */
3365
3675
  Observable.zip = function () {
3366
- var args = slice.call(arguments, 0), first = args.shift();
3676
+ var len = arguments.length, args = new Array(len);
3677
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3678
+ var first = args.shift();
3367
3679
  return first.zip.apply(first, args);
3368
3680
  };
3369
3681
 
@@ -3373,7 +3685,14 @@ if (!Array.prototype.forEach) {
3373
3685
  * @returns {Observable} An observable sequence containing lists of elements at corresponding indexes.
3374
3686
  */
3375
3687
  Observable.zipArray = function () {
3376
- var sources = argsOrArray(arguments, 0);
3688
+ var sources;
3689
+ if (Array.isArray(arguments[0])) {
3690
+ sources = arguments[0];
3691
+ } else {
3692
+ var len = arguments.length;
3693
+ sources = new Array(len);
3694
+ for(var i = 0; i < len; i++) { sources[i] = arguments[i]; }
3695
+ }
3377
3696
  return new AnonymousObservable(function (observer) {
3378
3697
  var n = sources.length,
3379
3698
  queues = arrayInitialize(n, function () { return []; }),
@@ -3404,17 +3723,13 @@ if (!Array.prototype.forEach) {
3404
3723
  subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
3405
3724
  queues[i].push(x);
3406
3725
  next(i);
3407
- }, observer.onError.bind(observer), function () {
3726
+ }, function (e) { observer.onError(e); }, function () {
3408
3727
  done(i);
3409
3728
  }));
3410
3729
  })(idx);
3411
3730
  }
3412
3731
 
3413
- var compositeDisposable = new CompositeDisposable(subscriptions);
3414
- compositeDisposable.add(disposableCreate(function () {
3415
- for (var qIdx = 0, qLen = queues.length; qIdx < qLen; qIdx++) { queues[qIdx] = []; }
3416
- }));
3417
- return compositeDisposable;
3732
+ return new CompositeDisposable(subscriptions);
3418
3733
  });
3419
3734
  };
3420
3735
 
@@ -3423,7 +3738,8 @@ if (!Array.prototype.forEach) {
3423
3738
  * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3424
3739
  */
3425
3740
  observableProto.asObservable = function () {
3426
- return new AnonymousObservable(this.subscribe.bind(this), this);
3741
+ var source = this;
3742
+ return new AnonymousObservable(function (o) { return source.subscribe(o); }, this);
3427
3743
  };
3428
3744
 
3429
3745
  /**
@@ -3453,8 +3769,8 @@ if (!Array.prototype.forEach) {
3453
3769
  */
3454
3770
  observableProto.dematerialize = function () {
3455
3771
  var source = this;
3456
- return new AnonymousObservable(function (observer) {
3457
- return source.subscribe(function (x) { return x.accept(observer); }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3772
+ return new AnonymousObservable(function (o) {
3773
+ return source.subscribe(function (x) { return x.accept(o); }, function(e) { o.onError(e); }, function () { o.onCompleted(); });
3458
3774
  }, this);
3459
3775
  };
3460
3776
 
@@ -3471,32 +3787,33 @@ if (!Array.prototype.forEach) {
3471
3787
  */
3472
3788
  observableProto.distinctUntilChanged = function (keySelector, comparer) {
3473
3789
  var source = this;
3474
- keySelector || (keySelector = identity);
3475
3790
  comparer || (comparer = defaultComparer);
3476
- return new AnonymousObservable(function (observer) {
3791
+ return new AnonymousObservable(function (o) {
3477
3792
  var hasCurrentKey = false, currentKey;
3478
3793
  return source.subscribe(function (value) {
3479
- var comparerEquals = false, key;
3794
+ var key = value;
3795
+ if (keySelector) {
3480
3796
  try {
3481
3797
  key = keySelector(value);
3482
3798
  } catch (e) {
3483
- observer.onError(e);
3799
+ o.onError(e);
3484
3800
  return;
3485
3801
  }
3486
- if (hasCurrentKey) {
3487
- try {
3488
- comparerEquals = comparer(currentKey, key);
3489
- } catch (e) {
3490
- observer.onError(e);
3491
- return;
3492
- }
3493
- }
3494
- if (!hasCurrentKey || !comparerEquals) {
3495
- hasCurrentKey = true;
3496
- currentKey = key;
3497
- observer.onNext(value);
3802
+ }
3803
+ if (hasCurrentKey) {
3804
+ try {
3805
+ var comparerEquals = comparer(currentKey, key);
3806
+ } catch (e) {
3807
+ o.onError(e);
3808
+ return;
3498
3809
  }
3499
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3810
+ }
3811
+ if (!hasCurrentKey || !comparerEquals) {
3812
+ hasCurrentKey = true;
3813
+ currentKey = key;
3814
+ o.onNext(value);
3815
+ }
3816
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3500
3817
  }, this);
3501
3818
  };
3502
3819
 
@@ -3508,51 +3825,36 @@ if (!Array.prototype.forEach) {
3508
3825
  * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
3509
3826
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3510
3827
  */
3511
- observableProto['do'] = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3512
- var source = this, onNextFunc;
3513
- if (typeof observerOrOnNext === 'function') {
3514
- onNextFunc = observerOrOnNext;
3515
- } else {
3516
- onNextFunc = observerOrOnNext.onNext.bind(observerOrOnNext);
3517
- onError = observerOrOnNext.onError.bind(observerOrOnNext);
3518
- onCompleted = observerOrOnNext.onCompleted.bind(observerOrOnNext);
3519
- }
3828
+ observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
3829
+ var source = this, tapObserver = typeof observerOrOnNext === 'function' || typeof observerOrOnNext === 'undefined'?
3830
+ observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
3831
+ observerOrOnNext;
3520
3832
  return new AnonymousObservable(function (observer) {
3521
3833
  return source.subscribe(function (x) {
3522
3834
  try {
3523
- onNextFunc(x);
3835
+ tapObserver.onNext(x);
3524
3836
  } catch (e) {
3525
3837
  observer.onError(e);
3526
3838
  }
3527
3839
  observer.onNext(x);
3528
3840
  }, function (err) {
3529
- if (onError) {
3530
3841
  try {
3531
- onError(err);
3842
+ tapObserver.onError(err);
3532
3843
  } catch (e) {
3533
3844
  observer.onError(e);
3534
3845
  }
3535
- }
3536
3846
  observer.onError(err);
3537
3847
  }, function () {
3538
- if (onCompleted) {
3539
- try {
3540
- onCompleted();
3541
- } catch (e) {
3542
- observer.onError(e);
3543
- }
3848
+ try {
3849
+ tapObserver.onCompleted();
3850
+ } catch (e) {
3851
+ observer.onError(e);
3544
3852
  }
3545
3853
  observer.onCompleted();
3546
3854
  });
3547
3855
  }, this);
3548
3856
  };
3549
3857
 
3550
- /** @deprecated use #do or #tap instead. */
3551
- observableProto.doAction = function () {
3552
- deprecate('doAction', 'do or tap');
3553
- return this.tap.apply(this, arguments);
3554
- };
3555
-
3556
3858
  /**
3557
3859
  * Invokes an action for each element in the observable sequence.
3558
3860
  * 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.
@@ -3561,7 +3863,7 @@ if (!Array.prototype.forEach) {
3561
3863
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3562
3864
  */
3563
3865
  observableProto.doOnNext = observableProto.tapOnNext = function (onNext, thisArg) {
3564
- return this.tap(arguments.length === 2 ? function (x) { onNext.call(thisArg, x); } : onNext);
3866
+ return this.tap(typeof thisArg !== 'undefined' ? function (x) { onNext.call(thisArg, x); } : onNext);
3565
3867
  };
3566
3868
 
3567
3869
  /**
@@ -3572,7 +3874,7 @@ if (!Array.prototype.forEach) {
3572
3874
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3573
3875
  */
3574
3876
  observableProto.doOnError = observableProto.tapOnError = function (onError, thisArg) {
3575
- return this.tap(noop, arguments.length === 2 ? function (e) { onError.call(thisArg, e); } : onError);
3877
+ return this.tap(noop, typeof thisArg !== 'undefined' ? function (e) { onError.call(thisArg, e); } : onError);
3576
3878
  };
3577
3879
 
3578
3880
  /**
@@ -3583,7 +3885,7 @@ if (!Array.prototype.forEach) {
3583
3885
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3584
3886
  */
3585
3887
  observableProto.doOnCompleted = observableProto.tapOnCompleted = function (onCompleted, thisArg) {
3586
- return this.tap(noop, null, arguments.length === 2 ? function () { onCompleted.call(thisArg); } : onCompleted);
3888
+ return this.tap(noop, null, typeof thisArg !== 'undefined' ? function () { onCompleted.call(thisArg); } : onCompleted);
3587
3889
  };
3588
3890
 
3589
3891
  /**
@@ -3617,7 +3919,7 @@ if (!Array.prototype.forEach) {
3617
3919
  * @deprecated use #finally or #ensure instead.
3618
3920
  */
3619
3921
  observableProto.finallyAction = function (action) {
3620
- deprecate('finallyAction', 'finally or ensure');
3922
+ //deprecate('finallyAction', 'finally or ensure');
3621
3923
  return this.ensure(action);
3622
3924
  };
3623
3925
 
@@ -3627,8 +3929,8 @@ if (!Array.prototype.forEach) {
3627
3929
  */
3628
3930
  observableProto.ignoreElements = function () {
3629
3931
  var source = this;
3630
- return new AnonymousObservable(function (observer) {
3631
- return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3932
+ return new AnonymousObservable(function (o) {
3933
+ return source.subscribe(noop, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3632
3934
  }, source);
3633
3935
  };
3634
3936
 
@@ -3674,6 +3976,19 @@ if (!Array.prototype.forEach) {
3674
3976
  return enumerableRepeat(this, retryCount).catchError();
3675
3977
  };
3676
3978
 
3979
+ /**
3980
+ * Repeats the source observable sequence upon error each time the notifier emits or until it successfully terminates.
3981
+ * if the notifier completes, the observable sequence completes.
3982
+ *
3983
+ * @example
3984
+ * var timer = Observable.timer(500);
3985
+ * var source = observable.retryWhen(timer);
3986
+ * @param {Observable} [notifier] An observable that triggers the retries or completes the observable with onNext or onCompleted respectively.
3987
+ * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3988
+ */
3989
+ observableProto.retryWhen = function (notifier) {
3990
+ return enumerableRepeat(this).catchErrorWhen(notifier);
3991
+ };
3677
3992
  /**
3678
3993
  * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
3679
3994
  * For aggregation behavior with no intermediate results, see Observable.aggregate.
@@ -3693,7 +4008,7 @@ if (!Array.prototype.forEach) {
3693
4008
  } else {
3694
4009
  accumulator = arguments[0];
3695
4010
  }
3696
- return new AnonymousObservable(function (observer) {
4011
+ return new AnonymousObservable(function (o) {
3697
4012
  var hasAccumulation, accumulation, hasValue;
3698
4013
  return source.subscribe (
3699
4014
  function (x) {
@@ -3706,16 +4021,16 @@ if (!Array.prototype.forEach) {
3706
4021
  hasAccumulation = true;
3707
4022
  }
3708
4023
  } catch (e) {
3709
- observer.onError(e);
4024
+ o.onError(e);
3710
4025
  return;
3711
4026
  }
3712
4027
 
3713
- observer.onNext(accumulation);
4028
+ o.onNext(accumulation);
3714
4029
  },
3715
- observer.onError.bind(observer),
4030
+ function (e) { o.onError(e); },
3716
4031
  function () {
3717
- !hasValue && hasSeed && observer.onNext(seed);
3718
- observer.onCompleted();
4032
+ !hasValue && hasSeed && o.onNext(seed);
4033
+ o.onCompleted();
3719
4034
  }
3720
4035
  );
3721
4036
  }, source);
@@ -3731,12 +4046,12 @@ if (!Array.prototype.forEach) {
3731
4046
  */
3732
4047
  observableProto.skipLast = function (count) {
3733
4048
  var source = this;
3734
- return new AnonymousObservable(function (observer) {
4049
+ return new AnonymousObservable(function (o) {
3735
4050
  var q = [];
3736
4051
  return source.subscribe(function (x) {
3737
4052
  q.push(x);
3738
- q.length > count && observer.onNext(q.shift());
3739
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4053
+ q.length > count && o.onNext(q.shift());
4054
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
3740
4055
  }, source);
3741
4056
  };
3742
4057
 
@@ -3756,8 +4071,8 @@ if (!Array.prototype.forEach) {
3756
4071
  } else {
3757
4072
  scheduler = immediateScheduler;
3758
4073
  }
3759
- values = slice.call(arguments, start);
3760
- return enumerableOf([observableFromArray(values, scheduler), this]).concat();
4074
+ for(var args = [], i = start, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
4075
+ return enumerableOf([observableFromArray(args, scheduler), this]).concat();
3761
4076
  };
3762
4077
 
3763
4078
  /**
@@ -3770,14 +4085,14 @@ if (!Array.prototype.forEach) {
3770
4085
  */
3771
4086
  observableProto.takeLast = function (count) {
3772
4087
  var source = this;
3773
- return new AnonymousObservable(function (observer) {
4088
+ return new AnonymousObservable(function (o) {
3774
4089
  var q = [];
3775
4090
  return source.subscribe(function (x) {
3776
4091
  q.push(x);
3777
4092
  q.length > count && q.shift();
3778
- }, observer.onError.bind(observer), function () {
3779
- while (q.length > 0) { observer.onNext(q.shift()); }
3780
- observer.onCompleted();
4093
+ }, function (e) { o.onError(e); }, function () {
4094
+ while (q.length > 0) { o.onNext(q.shift()); }
4095
+ o.onCompleted();
3781
4096
  });
3782
4097
  }, source);
3783
4098
  };
@@ -3793,14 +4108,14 @@ if (!Array.prototype.forEach) {
3793
4108
  */
3794
4109
  observableProto.takeLastBuffer = function (count) {
3795
4110
  var source = this;
3796
- return new AnonymousObservable(function (observer) {
4111
+ return new AnonymousObservable(function (o) {
3797
4112
  var q = [];
3798
4113
  return source.subscribe(function (x) {
3799
4114
  q.push(x);
3800
4115
  q.length > count && q.shift();
3801
- }, observer.onError.bind(observer), function () {
3802
- observer.onNext(q);
3803
- observer.onCompleted();
4116
+ }, function (e) { o.onError(e); }, function () {
4117
+ o.onNext(q);
4118
+ o.onCompleted();
3804
4119
  });
3805
4120
  }, source);
3806
4121
  };
@@ -3859,8 +4174,9 @@ if (!Array.prototype.forEach) {
3859
4174
  };
3860
4175
 
3861
4176
  function concatMap(source, selector, thisArg) {
4177
+ var selectorFunc = bindCallback(selector, thisArg, 3);
3862
4178
  return source.map(function (x, i) {
3863
- var result = selector.call(thisArg, x, i, source);
4179
+ var result = selectorFunc(x, i, source);
3864
4180
  isPromise(result) && (result = observableFromPromise(result));
3865
4181
  (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3866
4182
  return result;
@@ -3912,15 +4228,17 @@ if (!Array.prototype.forEach) {
3912
4228
  * @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.
3913
4229
  */
3914
4230
  observableProto.concatMapObserver = observableProto.selectConcatObserver = function(onNext, onError, onCompleted, thisArg) {
3915
- var source = this;
4231
+ var source = this,
4232
+ onNextFunc = bindCallback(onNext, thisArg, 2),
4233
+ onErrorFunc = bindCallback(onError, thisArg, 1),
4234
+ onCompletedFunc = bindCallback(onCompleted, thisArg, 0);
3916
4235
  return new AnonymousObservable(function (observer) {
3917
4236
  var index = 0;
3918
-
3919
4237
  return source.subscribe(
3920
4238
  function (x) {
3921
4239
  var result;
3922
4240
  try {
3923
- result = onNext.call(thisArg, x, index++);
4241
+ result = onNextFunc(x, index++);
3924
4242
  } catch (e) {
3925
4243
  observer.onError(e);
3926
4244
  return;
@@ -3931,7 +4249,7 @@ if (!Array.prototype.forEach) {
3931
4249
  function (err) {
3932
4250
  var result;
3933
4251
  try {
3934
- result = onError.call(thisArg, err);
4252
+ result = onErrorFunc(err);
3935
4253
  } catch (e) {
3936
4254
  observer.onError(e);
3937
4255
  return;
@@ -3943,7 +4261,7 @@ if (!Array.prototype.forEach) {
3943
4261
  function () {
3944
4262
  var result;
3945
4263
  try {
3946
- result = onCompleted.call(thisArg);
4264
+ result = onCompletedFunc();
3947
4265
  } catch (e) {
3948
4266
  observer.onError(e);
3949
4267
  return;
@@ -3973,11 +4291,13 @@ if (!Array.prototype.forEach) {
3973
4291
  return source.subscribe(function (x) {
3974
4292
  found = true;
3975
4293
  observer.onNext(x);
3976
- }, observer.onError.bind(observer), function () {
4294
+ },
4295
+ function (e) { observer.onError(e); },
4296
+ function () {
3977
4297
  !found && observer.onNext(defaultValue);
3978
4298
  observer.onCompleted();
3979
4299
  });
3980
- }, this);
4300
+ }, source);
3981
4301
  };
3982
4302
 
3983
4303
  // Swap out for Array.findIndex
@@ -4013,7 +4333,7 @@ if (!Array.prototype.forEach) {
4013
4333
  observableProto.distinct = function (keySelector, comparer) {
4014
4334
  var source = this;
4015
4335
  comparer || (comparer = defaultComparer);
4016
- return new AnonymousObservable(function (observer) {
4336
+ return new AnonymousObservable(function (o) {
4017
4337
  var hashSet = new HashSet(comparer);
4018
4338
  return source.subscribe(function (x) {
4019
4339
  var key = x;
@@ -4022,14 +4342,13 @@ if (!Array.prototype.forEach) {
4022
4342
  try {
4023
4343
  key = keySelector(x);
4024
4344
  } catch (e) {
4025
- observer.onError(e);
4345
+ o.onError(e);
4026
4346
  return;
4027
4347
  }
4028
4348
  }
4029
- hashSet.push(key) && observer.onNext(x);
4349
+ hashSet.push(key) && o.onNext(x);
4030
4350
  },
4031
- observer.onError.bind(observer),
4032
- observer.onCompleted.bind(observer));
4351
+ function (e) { o.onError(e); }, function () { o.onCompleted(); });
4033
4352
  }, this);
4034
4353
  };
4035
4354
 
@@ -4143,46 +4462,106 @@ if (!Array.prototype.forEach) {
4143
4462
  observer.onCompleted();
4144
4463
  }));
4145
4464
 
4146
- return refCountDisposable;
4147
- }, source);
4465
+ return refCountDisposable;
4466
+ }, source);
4467
+ };
4468
+
4469
+ var MapObservable = (function (__super__) {
4470
+ inherits(MapObservable, __super__);
4471
+
4472
+ function MapObservable(source, selector, thisArg) {
4473
+ this.source = source;
4474
+ this.selector = bindCallback(selector, thisArg, 3);
4475
+ __super__.call(this);
4476
+ }
4477
+
4478
+ MapObservable.prototype.internalMap = function (selector, thisArg) {
4479
+ var self = this;
4480
+ return new MapObservable(this.source, function (x, i, o) { return selector(self.selector(x, i, o), i, o); }, thisArg)
4481
+ };
4482
+
4483
+ MapObservable.prototype.subscribeCore = function (observer) {
4484
+ return this.source.subscribe(new MapObserver(observer, this.selector, this));
4485
+ };
4486
+
4487
+ return MapObservable;
4488
+
4489
+ }(ObservableBase));
4490
+
4491
+ function MapObserver(observer, selector, source) {
4492
+ this.observer = observer;
4493
+ this.selector = selector;
4494
+ this.source = source;
4495
+ this.i = 0;
4496
+ this.isStopped = false;
4497
+ }
4498
+
4499
+ MapObserver.prototype.onNext = function(x) {
4500
+ if (this.isStopped) { return; }
4501
+ try {
4502
+ var result = this.selector(x, this.i++, this.source);
4503
+ } catch (e) {
4504
+ return this.observer.onError(e);
4505
+ }
4506
+ this.observer.onNext(result);
4507
+ };
4508
+ MapObserver.prototype.onError = function (e) {
4509
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4510
+ };
4511
+ MapObserver.prototype.onCompleted = function () {
4512
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4513
+ };
4514
+ MapObserver.prototype.dispose = function() { this.isStopped = true; };
4515
+ MapObserver.prototype.fail = function (e) {
4516
+ if (!this.isStopped) {
4517
+ this.isStopped = true;
4518
+ this.observer.onError(e);
4519
+ return true;
4520
+ }
4521
+
4522
+ return false;
4148
4523
  };
4149
4524
 
4150
4525
  /**
4151
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
4152
- * @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.
4153
- * @param {Any} [thisArg] Object to use as this when executing callback.
4154
- * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
4155
- */
4156
- observableProto.select = observableProto.map = function (selector, thisArg) {
4157
- var selectorFn = isFunction(selector) ? selector : function () { return selector; },
4158
- source = this;
4159
- return new AnonymousObservable(function (observer) {
4160
- var count = 0;
4161
- return source.subscribe(function (value) {
4162
- var result;
4163
- try {
4164
- result = selectorFn.call(thisArg, value, count++, source);
4165
- } catch (e) {
4166
- observer.onError(e);
4167
- return;
4168
- }
4169
- observer.onNext(result);
4170
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4171
- }, source);
4526
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
4527
+ * @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.
4528
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4529
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
4530
+ */
4531
+ observableProto.map = observableProto.select = function (selector, thisArg) {
4532
+ var selectorFn = typeof selector === 'function' ? selector : function () { return selector; };
4533
+ return this instanceof MapObservable ?
4534
+ this.internalMap(selectorFn, thisArg) :
4535
+ new MapObservable(this, selectorFn, thisArg);
4172
4536
  };
4173
4537
 
4174
4538
  /**
4175
- * Retrieves the value of a specified property from all elements in the Observable sequence.
4176
- * @param {String} prop The property to pluck.
4539
+ * Retrieves the value of a specified nested property from all elements in
4540
+ * the Observable sequence.
4541
+ * @param {Arguments} arguments The nested properties to pluck.
4177
4542
  * @returns {Observable} Returns a new Observable sequence of property values.
4178
4543
  */
4179
- observableProto.pluck = function (prop) {
4180
- return this.map(function (x) { return x[prop]; });
4544
+ observableProto.pluck = function () {
4545
+ var args = arguments, len = arguments.length;
4546
+ if (len === 0) { throw new Error('List of properties cannot be empty.'); }
4547
+ return this.map(function (x) {
4548
+ var currentProp = x;
4549
+ for (var i = 0; i < len; i++) {
4550
+ var p = currentProp[args[i]];
4551
+ if (typeof p !== 'undefined') {
4552
+ currentProp = p;
4553
+ } else {
4554
+ return undefined;
4555
+ }
4556
+ }
4557
+ return currentProp;
4558
+ });
4181
4559
  };
4182
4560
 
4183
4561
  function flatMap(source, selector, thisArg) {
4562
+ var selectorFunc = bindCallback(selector, thisArg, 3);
4184
4563
  return source.map(function (x, i) {
4185
- var result = selector.call(thisArg, x, i, source);
4564
+ var result = selectorFunc(x, i, source);
4186
4565
  isPromise(result) && (result = observableFromPromise(result));
4187
4566
  (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
4188
4567
  return result;
@@ -4297,15 +4676,15 @@ if (!Array.prototype.forEach) {
4297
4676
  observableProto.skip = function (count) {
4298
4677
  if (count < 0) { throw new Error(argumentOutOfRange); }
4299
4678
  var source = this;
4300
- return new AnonymousObservable(function (observer) {
4679
+ return new AnonymousObservable(function (o) {
4301
4680
  var remaining = count;
4302
4681
  return source.subscribe(function (x) {
4303
4682
  if (remaining <= 0) {
4304
- observer.onNext(x);
4683
+ o.onNext(x);
4305
4684
  } else {
4306
4685
  remaining--;
4307
4686
  }
4308
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4687
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4309
4688
  }, source);
4310
4689
  };
4311
4690
 
@@ -4320,20 +4699,21 @@ if (!Array.prototype.forEach) {
4320
4699
  * @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.
4321
4700
  */
4322
4701
  observableProto.skipWhile = function (predicate, thisArg) {
4323
- var source = this;
4324
- return new AnonymousObservable(function (observer) {
4702
+ var source = this,
4703
+ callback = bindCallback(predicate, thisArg, 3);
4704
+ return new AnonymousObservable(function (o) {
4325
4705
  var i = 0, running = false;
4326
4706
  return source.subscribe(function (x) {
4327
4707
  if (!running) {
4328
4708
  try {
4329
- running = !predicate.call(thisArg, x, i++, source);
4709
+ running = !callback(x, i++, source);
4330
4710
  } catch (e) {
4331
- observer.onError(e);
4711
+ o.onError(e);
4332
4712
  return;
4333
4713
  }
4334
4714
  }
4335
- running && observer.onNext(x);
4336
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4715
+ running && o.onNext(x);
4716
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4337
4717
  }, source);
4338
4718
  };
4339
4719
 
@@ -4350,14 +4730,14 @@ if (!Array.prototype.forEach) {
4350
4730
  if (count < 0) { throw new RangeError(argumentOutOfRange); }
4351
4731
  if (count === 0) { return observableEmpty(scheduler); }
4352
4732
  var source = this;
4353
- return new AnonymousObservable(function (observer) {
4733
+ return new AnonymousObservable(function (o) {
4354
4734
  var remaining = count;
4355
4735
  return source.subscribe(function (x) {
4356
4736
  if (remaining-- > 0) {
4357
- observer.onNext(x);
4358
- remaining === 0 && observer.onCompleted();
4737
+ o.onNext(x);
4738
+ remaining === 0 && o.onCompleted();
4359
4739
  }
4360
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4740
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4361
4741
  }, source);
4362
4742
  };
4363
4743
 
@@ -4369,81 +4749,103 @@ if (!Array.prototype.forEach) {
4369
4749
  * @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.
4370
4750
  */
4371
4751
  observableProto.takeWhile = function (predicate, thisArg) {
4372
- var source = this;
4373
- return new AnonymousObservable(function (observer) {
4752
+ var source = this,
4753
+ callback = bindCallback(predicate, thisArg, 3);
4754
+ return new AnonymousObservable(function (o) {
4374
4755
  var i = 0, running = true;
4375
4756
  return source.subscribe(function (x) {
4376
4757
  if (running) {
4377
4758
  try {
4378
- running = predicate.call(thisArg, x, i++, source);
4759
+ running = callback(x, i++, source);
4379
4760
  } catch (e) {
4380
- observer.onError(e);
4761
+ o.onError(e);
4381
4762
  return;
4382
4763
  }
4383
4764
  if (running) {
4384
- observer.onNext(x);
4765
+ o.onNext(x);
4385
4766
  } else {
4386
- observer.onCompleted();
4767
+ o.onCompleted();
4387
4768
  }
4388
4769
  }
4389
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4770
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4390
4771
  }, source);
4391
4772
  };
4392
4773
 
4393
- /**
4394
- * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4395
- *
4396
- * @example
4397
- * var res = source.where(function (value) { return value < 10; });
4398
- * var res = source.where(function (value, index) { return value < 10 || index < 10; });
4399
- * @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.
4400
- * @param {Any} [thisArg] Object to use as this when executing callback.
4401
- * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4402
- */
4403
- observableProto.where = observableProto.filter = function (predicate, thisArg) {
4404
- var source = this;
4405
- return new AnonymousObservable(function (observer) {
4406
- var count = 0;
4407
- return source.subscribe(function (value) {
4408
- var shouldRun;
4409
- try {
4410
- shouldRun = predicate.call(thisArg, value, count++, source);
4411
- } catch (e) {
4412
- observer.onError(e);
4413
- return;
4414
- }
4415
- shouldRun && observer.onNext(value);
4416
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4417
- }, source);
4774
+ var FilterObservable = (function (__super__) {
4775
+ inherits(FilterObservable, __super__);
4776
+
4777
+ function FilterObservable(source, predicate, thisArg) {
4778
+ this.source = source;
4779
+ this.predicate = bindCallback(predicate, thisArg, 3);
4780
+ __super__.call(this);
4781
+ }
4782
+
4783
+ FilterObservable.prototype.subscribeCore = function (observer) {
4784
+ return this.source.subscribe(new FilterObserver(observer, this.predicate, this));
4785
+ };
4786
+
4787
+ FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
4788
+ var self = this;
4789
+ return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate(x, i, o); }, thisArg);
4790
+ };
4791
+
4792
+ return FilterObservable;
4793
+
4794
+ }(ObservableBase));
4795
+
4796
+ function FilterObserver(observer, predicate, source) {
4797
+ this.observer = observer;
4798
+ this.predicate = predicate;
4799
+ this.source = source;
4800
+ this.i = 0;
4801
+ this.isStopped = false;
4802
+ }
4803
+
4804
+ FilterObserver.prototype.onNext = function(x) {
4805
+ if (this.isStopped) { return; }
4806
+ try {
4807
+ var shouldYield = this.predicate(x, this.i++, this.source);
4808
+ } catch (e) {
4809
+ return this.observer.onError(e);
4810
+ }
4811
+ shouldYield && this.observer.onNext(x);
4812
+ };
4813
+ FilterObserver.prototype.onError = function (e) {
4814
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4815
+ };
4816
+ FilterObserver.prototype.onCompleted = function () {
4817
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4818
+ };
4819
+ FilterObserver.prototype.dispose = function() { this.isStopped = true; };
4820
+ FilterObserver.prototype.fail = function (e) {
4821
+ if (!this.isStopped) {
4822
+ this.isStopped = true;
4823
+ this.observer.onError(e);
4824
+ return true;
4825
+ }
4826
+ return false;
4418
4827
  };
4419
4828
 
4420
- observableProto.finalValue = function () {
4421
- var source = this;
4422
- return new AnonymousObservable(function (observer) {
4423
- var hasValue = false, value;
4424
- return source.subscribe(function (x) {
4425
- hasValue = true;
4426
- value = x;
4427
- }, observer.onError.bind(observer), function () {
4428
- if (!hasValue) {
4429
- observer.onError(new Error(sequenceContainsNoElements));
4430
- } else {
4431
- observer.onNext(value);
4432
- observer.onCompleted();
4433
- }
4434
- });
4435
- }, source);
4829
+ /**
4830
+ * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4831
+ * @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.
4832
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4833
+ * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4834
+ */
4835
+ observableProto.filter = observableProto.where = function (predicate, thisArg) {
4836
+ return this instanceof FilterObservable ? this.internalFilter(predicate, thisArg) :
4837
+ new FilterObservable(this, predicate, thisArg);
4436
4838
  };
4437
4839
 
4438
4840
  function extremaBy(source, keySelector, comparer) {
4439
- return new AnonymousObservable(function (observer) {
4841
+ return new AnonymousObservable(function (o) {
4440
4842
  var hasValue = false, lastKey = null, list = [];
4441
4843
  return source.subscribe(function (x) {
4442
4844
  var comparison, key;
4443
4845
  try {
4444
4846
  key = keySelector(x);
4445
4847
  } catch (ex) {
4446
- observer.onError(ex);
4848
+ o.onError(ex);
4447
4849
  return;
4448
4850
  }
4449
4851
  comparison = 0;
@@ -4454,7 +4856,7 @@ if (!Array.prototype.forEach) {
4454
4856
  try {
4455
4857
  comparison = comparer(key, lastKey);
4456
4858
  } catch (ex1) {
4457
- observer.onError(ex1);
4859
+ o.onError(ex1);
4458
4860
  return;
4459
4861
  }
4460
4862
  }
@@ -4463,9 +4865,9 @@ if (!Array.prototype.forEach) {
4463
4865
  list = [];
4464
4866
  }
4465
4867
  if (comparison >= 0) { list.push(x); }
4466
- }, observer.onError.bind(observer), function () {
4467
- observer.onNext(list);
4468
- observer.onCompleted();
4868
+ }, function (e) { o.onError(e); }, function () {
4869
+ o.onNext(list);
4870
+ o.onCompleted();
4469
4871
  });
4470
4872
  }, source);
4471
4873
  }
@@ -4484,16 +4886,41 @@ if (!Array.prototype.forEach) {
4484
4886
  * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4485
4887
  */
4486
4888
  observableProto.aggregate = function () {
4487
- deprecate('aggregate', 'reduce');
4488
- var seed, hasSeed, accumulator;
4889
+ //deprecate('aggregate', 'reduce');
4890
+ var hasSeed = false, accumulator, seed, source = this;
4489
4891
  if (arguments.length === 2) {
4490
- seed = arguments[0];
4491
4892
  hasSeed = true;
4893
+ seed = arguments[0];
4492
4894
  accumulator = arguments[1];
4493
4895
  } else {
4494
4896
  accumulator = arguments[0];
4495
4897
  }
4496
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4898
+ return new AnonymousObservable(function (o) {
4899
+ var hasAccumulation, accumulation, hasValue;
4900
+ return source.subscribe (
4901
+ function (x) {
4902
+ !hasValue && (hasValue = true);
4903
+ try {
4904
+ if (hasAccumulation) {
4905
+ accumulation = accumulator(accumulation, x);
4906
+ } else {
4907
+ accumulation = hasSeed ? accumulator(seed, x) : x;
4908
+ hasAccumulation = true;
4909
+ }
4910
+ } catch (e) {
4911
+ o.onError(e);
4912
+ return;
4913
+ }
4914
+ },
4915
+ function (e) { o.onError(e); },
4916
+ function () {
4917
+ hasValue && o.onNext(accumulation);
4918
+ !hasValue && hasSeed && o.onNext(seed);
4919
+ !hasValue && !hasSeed && o.onError(new Error(sequenceContainsNoElements));
4920
+ o.onCompleted();
4921
+ }
4922
+ );
4923
+ }, source);
4497
4924
  };
4498
4925
 
4499
4926
  /**
@@ -4504,12 +4931,37 @@ if (!Array.prototype.forEach) {
4504
4931
  * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4505
4932
  */
4506
4933
  observableProto.reduce = function (accumulator) {
4507
- var seed, hasSeed;
4934
+ var hasSeed = false, seed, source = this;
4508
4935
  if (arguments.length === 2) {
4509
4936
  hasSeed = true;
4510
4937
  seed = arguments[1];
4511
4938
  }
4512
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4939
+ return new AnonymousObservable(function (o) {
4940
+ var hasAccumulation, accumulation, hasValue;
4941
+ return source.subscribe (
4942
+ function (x) {
4943
+ !hasValue && (hasValue = true);
4944
+ try {
4945
+ if (hasAccumulation) {
4946
+ accumulation = accumulator(accumulation, x);
4947
+ } else {
4948
+ accumulation = hasSeed ? accumulator(seed, x) : x;
4949
+ hasAccumulation = true;
4950
+ }
4951
+ } catch (e) {
4952
+ o.onError(e);
4953
+ return;
4954
+ }
4955
+ },
4956
+ function (e) { o.onError(e); },
4957
+ function () {
4958
+ hasValue && o.onNext(accumulation);
4959
+ !hasValue && hasSeed && o.onNext(seed);
4960
+ !hasValue && !hasSeed && o.onError(new Error(sequenceContainsNoElements));
4961
+ o.onCompleted();
4962
+ }
4963
+ );
4964
+ }, source);
4513
4965
  };
4514
4966
 
4515
4967
  /**
@@ -4525,7 +4977,7 @@ if (!Array.prototype.forEach) {
4525
4977
  return source.subscribe(function () {
4526
4978
  observer.onNext(true);
4527
4979
  observer.onCompleted();
4528
- }, observer.onError.bind(observer), function () {
4980
+ }, function (e) { observer.onError(e); }, function () {
4529
4981
  observer.onNext(false);
4530
4982
  observer.onCompleted();
4531
4983
  });
@@ -4534,7 +4986,7 @@ if (!Array.prototype.forEach) {
4534
4986
 
4535
4987
  /** @deprecated use #some instead */
4536
4988
  observableProto.any = function () {
4537
- deprecate('any', 'some');
4989
+ //deprecate('any', 'some');
4538
4990
  return this.some.apply(this, arguments);
4539
4991
  };
4540
4992
 
@@ -4558,60 +5010,65 @@ if (!Array.prototype.forEach) {
4558
5010
 
4559
5011
  /** @deprecated use #every instead */
4560
5012
  observableProto.all = function () {
4561
- deprecate('all', 'every');
5013
+ //deprecate('all', 'every');
4562
5014
  return this.every.apply(this, arguments);
4563
5015
  };
4564
5016
 
4565
5017
  /**
4566
- * Determines whether an observable sequence contains a specified element with an optional equality comparer.
5018
+ * Determines whether an observable sequence includes a specified element with an optional equality comparer.
4567
5019
  * @param searchElement The value to locate in the source sequence.
4568
5020
  * @param {Number} [fromIndex] An equality comparer to compare elements.
4569
- * @returns {Observable} An observable sequence containing a single element determining whether the source sequence contains an element that has the specified value from the given index.
5021
+ * @returns {Observable} An observable sequence containing a single element determining whether the source sequence includes an element that has the specified value from the given index.
4570
5022
  */
4571
- observableProto.contains = function (searchElement, fromIndex) {
5023
+ observableProto.includes = function (searchElement, fromIndex) {
4572
5024
  var source = this;
4573
5025
  function comparer(a, b) {
4574
5026
  return (a === 0 && b === 0) || (a === b || (isNaN(a) && isNaN(b)));
4575
5027
  }
4576
- return new AnonymousObservable(function (observer) {
5028
+ return new AnonymousObservable(function (o) {
4577
5029
  var i = 0, n = +fromIndex || 0;
4578
5030
  Math.abs(n) === Infinity && (n = 0);
4579
5031
  if (n < 0) {
4580
- observer.onNext(false);
4581
- observer.onCompleted();
5032
+ o.onNext(false);
5033
+ o.onCompleted();
4582
5034
  return disposableEmpty;
4583
5035
  }
4584
5036
  return source.subscribe(
4585
5037
  function (x) {
4586
5038
  if (i++ >= n && comparer(x, searchElement)) {
4587
- observer.onNext(true);
4588
- observer.onCompleted();
5039
+ o.onNext(true);
5040
+ o.onCompleted();
4589
5041
  }
4590
5042
  },
4591
- observer.onError.bind(observer),
5043
+ function (e) { o.onError(e); },
4592
5044
  function () {
4593
- observer.onNext(false);
4594
- observer.onCompleted();
5045
+ o.onNext(false);
5046
+ o.onCompleted();
4595
5047
  });
4596
5048
  }, this);
4597
5049
  };
4598
5050
 
4599
- /**
4600
- * Returns an observable sequence containing a value that represents how many elements in the specified observable sequence satisfy a condition if provided, else the count of items.
4601
- * @example
4602
- * res = source.count();
4603
- * res = source.count(function (x) { return x > 3; });
4604
- * @param {Function} [predicate]A function to test each element for a condition.
4605
- * @param {Any} [thisArg] Object to use as this when executing callback.
4606
- * @returns {Observable} An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function if provided, else the count of items in the sequence.
4607
- */
4608
- observableProto.count = function (predicate, thisArg) {
4609
- return predicate ?
4610
- this.where(predicate, thisArg).count() :
4611
- this.aggregate(0, function (count) {
4612
- return count + 1;
4613
- });
4614
- };
5051
+ /**
5052
+ * @deprecated use #includes instead.
5053
+ */
5054
+ observableProto.contains = function (searchElement, fromIndex) {
5055
+ //deprecate('contains', 'includes');
5056
+ observableProto.includes(searchElement, fromIndex);
5057
+ };
5058
+ /**
5059
+ * Returns an observable sequence containing a value that represents how many elements in the specified observable sequence satisfy a condition if provided, else the count of items.
5060
+ * @example
5061
+ * res = source.count();
5062
+ * res = source.count(function (x) { return x > 3; });
5063
+ * @param {Function} [predicate]A function to test each element for a condition.
5064
+ * @param {Any} [thisArg] Object to use as this when executing callback.
5065
+ * @returns {Observable} An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function if provided, else the count of items in the sequence.
5066
+ */
5067
+ observableProto.count = function (predicate, thisArg) {
5068
+ return predicate ?
5069
+ this.filter(predicate, thisArg).count() :
5070
+ this.reduce(function (count) { return count + 1; }, 0);
5071
+ };
4615
5072
 
4616
5073
  /**
4617
5074
  * Returns the first index at which a given element can be found in the observable sequence, or -1 if it is not present.
@@ -4621,26 +5078,26 @@ if (!Array.prototype.forEach) {
4621
5078
  */
4622
5079
  observableProto.indexOf = function(searchElement, fromIndex) {
4623
5080
  var source = this;
4624
- return new AnonymousObservable(function (observer) {
5081
+ return new AnonymousObservable(function (o) {
4625
5082
  var i = 0, n = +fromIndex || 0;
4626
5083
  Math.abs(n) === Infinity && (n = 0);
4627
5084
  if (n < 0) {
4628
- observer.onNext(-1);
4629
- observer.onCompleted();
5085
+ o.onNext(-1);
5086
+ o.onCompleted();
4630
5087
  return disposableEmpty;
4631
5088
  }
4632
5089
  return source.subscribe(
4633
5090
  function (x) {
4634
5091
  if (i >= n && x === searchElement) {
4635
- observer.onNext(i);
4636
- observer.onCompleted();
5092
+ o.onNext(i);
5093
+ o.onCompleted();
4637
5094
  }
4638
5095
  i++;
4639
5096
  },
4640
- observer.onError.bind(observer),
5097
+ function (e) { o.onError(e); },
4641
5098
  function () {
4642
- observer.onNext(-1);
4643
- observer.onCompleted();
5099
+ o.onNext(-1);
5100
+ o.onCompleted();
4644
5101
  });
4645
5102
  }, source);
4646
5103
  };
@@ -4654,9 +5111,7 @@ if (!Array.prototype.forEach) {
4654
5111
  observableProto.sum = function (keySelector, thisArg) {
4655
5112
  return keySelector && isFunction(keySelector) ?
4656
5113
  this.map(keySelector, thisArg).sum() :
4657
- this.reduce(function (prev, curr) {
4658
- return prev + curr;
4659
- }, 0);
5114
+ this.reduce(function (prev, curr) { return prev + curr; }, 0);
4660
5115
  };
4661
5116
 
4662
5117
  /**
@@ -4719,16 +5174,14 @@ if (!Array.prototype.forEach) {
4719
5174
  */
4720
5175
  observableProto.average = function (keySelector, thisArg) {
4721
5176
  return keySelector && isFunction(keySelector) ?
4722
- this.select(keySelector, thisArg).average() :
4723
- this.scan({sum: 0, count: 0 }, function (prev, cur) {
5177
+ this.map(keySelector, thisArg).average() :
5178
+ this.reduce(function (prev, cur) {
4724
5179
  return {
4725
5180
  sum: prev.sum + cur,
4726
5181
  count: prev.count + 1
4727
5182
  };
4728
- }).finalValue().map(function (s) {
4729
- if (s.count === 0) {
4730
- throw new Error('The input sequence was empty');
4731
- }
5183
+ }, {sum: 0, count: 0 }).map(function (s) {
5184
+ if (s.count === 0) { throw new Error(sequenceContainsNoElements); }
4732
5185
  return s.sum / s.count;
4733
5186
  });
4734
5187
  };
@@ -4748,7 +5201,7 @@ if (!Array.prototype.forEach) {
4748
5201
  observableProto.sequenceEqual = function (second, comparer) {
4749
5202
  var first = this;
4750
5203
  comparer || (comparer = defaultComparer);
4751
- return new AnonymousObservable(function (observer) {
5204
+ return new AnonymousObservable(function (o) {
4752
5205
  var donel = false, doner = false, ql = [], qr = [];
4753
5206
  var subscription1 = first.subscribe(function (x) {
4754
5207
  var equal, v;
@@ -4757,28 +5210,28 @@ if (!Array.prototype.forEach) {
4757
5210
  try {
4758
5211
  equal = comparer(v, x);
4759
5212
  } catch (e) {
4760
- observer.onError(e);
5213
+ o.onError(e);
4761
5214
  return;
4762
5215
  }
4763
5216
  if (!equal) {
4764
- observer.onNext(false);
4765
- observer.onCompleted();
5217
+ o.onNext(false);
5218
+ o.onCompleted();
4766
5219
  }
4767
5220
  } else if (doner) {
4768
- observer.onNext(false);
4769
- observer.onCompleted();
5221
+ o.onNext(false);
5222
+ o.onCompleted();
4770
5223
  } else {
4771
5224
  ql.push(x);
4772
5225
  }
4773
- }, observer.onError.bind(observer), function () {
5226
+ }, function(e) { o.onError(e); }, function () {
4774
5227
  donel = true;
4775
5228
  if (ql.length === 0) {
4776
5229
  if (qr.length > 0) {
4777
- observer.onNext(false);
4778
- observer.onCompleted();
5230
+ o.onNext(false);
5231
+ o.onCompleted();
4779
5232
  } else if (doner) {
4780
- observer.onNext(true);
4781
- observer.onCompleted();
5233
+ o.onNext(true);
5234
+ o.onCompleted();
4782
5235
  }
4783
5236
  }
4784
5237
  });
@@ -4792,28 +5245,28 @@ if (!Array.prototype.forEach) {
4792
5245
  try {
4793
5246
  equal = comparer(v, x);
4794
5247
  } catch (exception) {
4795
- observer.onError(exception);
5248
+ o.onError(exception);
4796
5249
  return;
4797
5250
  }
4798
5251
  if (!equal) {
4799
- observer.onNext(false);
4800
- observer.onCompleted();
5252
+ o.onNext(false);
5253
+ o.onCompleted();
4801
5254
  }
4802
5255
  } else if (donel) {
4803
- observer.onNext(false);
4804
- observer.onCompleted();
5256
+ o.onNext(false);
5257
+ o.onCompleted();
4805
5258
  } else {
4806
5259
  qr.push(x);
4807
5260
  }
4808
- }, observer.onError.bind(observer), function () {
5261
+ }, function(e) { o.onError(e); }, function () {
4809
5262
  doner = true;
4810
5263
  if (qr.length === 0) {
4811
5264
  if (ql.length > 0) {
4812
- observer.onNext(false);
4813
- observer.onCompleted();
5265
+ o.onNext(false);
5266
+ o.onCompleted();
4814
5267
  } else if (donel) {
4815
- observer.onNext(true);
4816
- observer.onCompleted();
5268
+ o.onNext(true);
5269
+ o.onCompleted();
4817
5270
  }
4818
5271
  }
4819
5272
  });
@@ -4823,19 +5276,19 @@ if (!Array.prototype.forEach) {
4823
5276
 
4824
5277
  function elementAtOrDefault(source, index, hasDefault, defaultValue) {
4825
5278
  if (index < 0) { throw new Error(argumentOutOfRange); }
4826
- return new AnonymousObservable(function (observer) {
5279
+ return new AnonymousObservable(function (o) {
4827
5280
  var i = index;
4828
5281
  return source.subscribe(function (x) {
4829
5282
  if (i-- === 0) {
4830
- observer.onNext(x);
4831
- observer.onCompleted();
5283
+ o.onNext(x);
5284
+ o.onCompleted();
4832
5285
  }
4833
- }, observer.onError.bind(observer), function () {
5286
+ }, function (e) { o.onError(e); }, function () {
4834
5287
  if (!hasDefault) {
4835
- observer.onError(new Error(argumentOutOfRange));
5288
+ o.onError(new Error(argumentOutOfRange));
4836
5289
  } else {
4837
- observer.onNext(defaultValue);
4838
- observer.onCompleted();
5290
+ o.onNext(defaultValue);
5291
+ o.onCompleted();
4839
5292
  }
4840
5293
  });
4841
5294
  }, source);
@@ -4866,21 +5319,21 @@ if (!Array.prototype.forEach) {
4866
5319
  };
4867
5320
 
4868
5321
  function singleOrDefaultAsync(source, hasDefault, defaultValue) {
4869
- return new AnonymousObservable(function (observer) {
5322
+ return new AnonymousObservable(function (o) {
4870
5323
  var value = defaultValue, seenValue = false;
4871
5324
  return source.subscribe(function (x) {
4872
5325
  if (seenValue) {
4873
- observer.onError(new Error('Sequence contains more than one element'));
5326
+ o.onError(new Error('Sequence contains more than one element'));
4874
5327
  } else {
4875
5328
  value = x;
4876
5329
  seenValue = true;
4877
5330
  }
4878
- }, observer.onError.bind(observer), function () {
5331
+ }, function (e) { o.onError(e); }, function () {
4879
5332
  if (!seenValue && !hasDefault) {
4880
- observer.onError(new Error(sequenceContainsNoElements));
5333
+ o.onError(new Error(sequenceContainsNoElements));
4881
5334
  } else {
4882
- observer.onNext(value);
4883
- observer.onCompleted();
5335
+ o.onNext(value);
5336
+ o.onCompleted();
4884
5337
  }
4885
5338
  });
4886
5339
  }, source);
@@ -4913,21 +5366,21 @@ if (!Array.prototype.forEach) {
4913
5366
  */
4914
5367
  observableProto.singleOrDefault = function (predicate, defaultValue, thisArg) {
4915
5368
  return predicate && isFunction(predicate) ?
4916
- this.where(predicate, thisArg).singleOrDefault(null, defaultValue) :
5369
+ this.filter(predicate, thisArg).singleOrDefault(null, defaultValue) :
4917
5370
  singleOrDefaultAsync(this, true, defaultValue);
4918
5371
  };
4919
5372
 
4920
5373
  function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4921
- return new AnonymousObservable(function (observer) {
5374
+ return new AnonymousObservable(function (o) {
4922
5375
  return source.subscribe(function (x) {
4923
- observer.onNext(x);
4924
- observer.onCompleted();
4925
- }, observer.onError.bind(observer), function () {
5376
+ o.onNext(x);
5377
+ o.onCompleted();
5378
+ }, function (e) { o.onError(e); }, function () {
4926
5379
  if (!hasDefault) {
4927
- observer.onError(new Error(sequenceContainsNoElements));
5380
+ o.onError(new Error(sequenceContainsNoElements));
4928
5381
  } else {
4929
- observer.onNext(defaultValue);
4930
- observer.onCompleted();
5382
+ o.onNext(defaultValue);
5383
+ o.onCompleted();
4931
5384
  }
4932
5385
  });
4933
5386
  }, source);
@@ -4962,17 +5415,17 @@ if (!Array.prototype.forEach) {
4962
5415
  };
4963
5416
 
4964
5417
  function lastOrDefaultAsync(source, hasDefault, defaultValue) {
4965
- return new AnonymousObservable(function (observer) {
5418
+ return new AnonymousObservable(function (o) {
4966
5419
  var value = defaultValue, seenValue = false;
4967
5420
  return source.subscribe(function (x) {
4968
5421
  value = x;
4969
5422
  seenValue = true;
4970
- }, observer.onError.bind(observer), function () {
5423
+ }, function (e) { o.onError(e); }, function () {
4971
5424
  if (!seenValue && !hasDefault) {
4972
- observer.onError(new Error(sequenceContainsNoElements));
5425
+ o.onError(new Error(sequenceContainsNoElements));
4973
5426
  } else {
4974
- observer.onNext(value);
4975
- observer.onCompleted();
5427
+ o.onNext(value);
5428
+ o.onCompleted();
4976
5429
  }
4977
5430
  });
4978
5431
  }, source);
@@ -5004,25 +5457,26 @@ if (!Array.prototype.forEach) {
5004
5457
  };
5005
5458
 
5006
5459
  function findValue (source, predicate, thisArg, yieldIndex) {
5007
- return new AnonymousObservable(function (observer) {
5460
+ var callback = bindCallback(predicate, thisArg, 3);
5461
+ return new AnonymousObservable(function (o) {
5008
5462
  var i = 0;
5009
5463
  return source.subscribe(function (x) {
5010
5464
  var shouldRun;
5011
5465
  try {
5012
- shouldRun = predicate.call(thisArg, x, i, source);
5466
+ shouldRun = callback(x, i, source);
5013
5467
  } catch (e) {
5014
- observer.onError(e);
5468
+ o.onError(e);
5015
5469
  return;
5016
5470
  }
5017
5471
  if (shouldRun) {
5018
- observer.onNext(yieldIndex ? i : x);
5019
- observer.onCompleted();
5472
+ o.onNext(yieldIndex ? i : x);
5473
+ o.onCompleted();
5020
5474
  } else {
5021
5475
  i++;
5022
5476
  }
5023
- }, observer.onError.bind(observer), function () {
5024
- observer.onNext(yieldIndex ? -1 : undefined);
5025
- observer.onCompleted();
5477
+ }, function (e) { o.onError(e); }, function () {
5478
+ o.onNext(yieldIndex ? -1 : undefined);
5479
+ o.onCompleted();
5026
5480
  });
5027
5481
  }, source);
5028
5482
  }
@@ -5048,7 +5502,6 @@ if (!Array.prototype.forEach) {
5048
5502
  return findValue(this, predicate, thisArg, true);
5049
5503
  };
5050
5504
 
5051
-
5052
5505
  /**
5053
5506
  * Converts the observable sequence to a Set if it exists.
5054
5507
  * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
@@ -5056,19 +5509,18 @@ if (!Array.prototype.forEach) {
5056
5509
  observableProto.toSet = function () {
5057
5510
  if (typeof root.Set === 'undefined') { throw new TypeError(); }
5058
5511
  var source = this;
5059
- return new AnonymousObservable(function (observer) {
5512
+ return new AnonymousObservable(function (o) {
5060
5513
  var s = new root.Set();
5061
5514
  return source.subscribe(
5062
- s.add.bind(s),
5063
- observer.onError.bind(observer),
5515
+ function (x) { s.add(x); },
5516
+ function (e) { o.onError(e); },
5064
5517
  function () {
5065
- observer.onNext(s);
5066
- observer.onCompleted();
5518
+ o.onNext(s);
5519
+ o.onCompleted();
5067
5520
  });
5068
5521
  }, source);
5069
5522
  };
5070
5523
 
5071
-
5072
5524
  /**
5073
5525
  * Converts the observable sequence to a Map if it exists.
5074
5526
  * @param {Function} keySelector A function which produces the key for the Map.
@@ -5078,7 +5530,7 @@ if (!Array.prototype.forEach) {
5078
5530
  observableProto.toMap = function (keySelector, elementSelector) {
5079
5531
  if (typeof root.Map === 'undefined') { throw new TypeError(); }
5080
5532
  var source = this;
5081
- return new AnonymousObservable(function (observer) {
5533
+ return new AnonymousObservable(function (o) {
5082
5534
  var m = new root.Map();
5083
5535
  return source.subscribe(
5084
5536
  function (x) {
@@ -5086,7 +5538,7 @@ if (!Array.prototype.forEach) {
5086
5538
  try {
5087
5539
  key = keySelector(x);
5088
5540
  } catch (e) {
5089
- observer.onError(e);
5541
+ o.onError(e);
5090
5542
  return;
5091
5543
  }
5092
5544
 
@@ -5095,23 +5547,24 @@ if (!Array.prototype.forEach) {
5095
5547
  try {
5096
5548
  element = elementSelector(x);
5097
5549
  } catch (e) {
5098
- observer.onError(e);
5550
+ o.onError(e);
5099
5551
  return;
5100
5552
  }
5101
5553
  }
5102
5554
 
5103
5555
  m.set(key, element);
5104
5556
  },
5105
- observer.onError.bind(observer),
5557
+ function (e) { o.onError(e); },
5106
5558
  function () {
5107
- observer.onNext(m);
5108
- observer.onCompleted();
5559
+ o.onNext(m);
5560
+ o.onCompleted();
5109
5561
  });
5110
5562
  }, source);
5111
5563
  };
5112
5564
 
5113
5565
  var fnString = 'function',
5114
- throwString = 'throw';
5566
+ throwString = 'throw',
5567
+ isObject = Rx.internals.isObject;
5115
5568
 
5116
5569
  function toThunk(obj, ctx) {
5117
5570
  if (Array.isArray(obj)) { return objectToThunk.call(ctx, obj); }
@@ -5207,10 +5660,6 @@ if (!Array.prototype.forEach) {
5207
5660
  return obj && typeof obj.next === fnString && typeof obj[throwString] === fnString;
5208
5661
  }
5209
5662
 
5210
- function isObject(val) {
5211
- return val && val.constructor === Object;
5212
- }
5213
-
5214
5663
  /*
5215
5664
  * Spawns a generator function which allows for Promises, Observable sequences, Arrays, Objects, Generators and functions.
5216
5665
  * @param {Function} The spawning function.
@@ -5224,14 +5673,14 @@ if (!Array.prototype.forEach) {
5224
5673
  gen = fn;
5225
5674
 
5226
5675
  if (isGenFun) {
5227
- var args = slice.call(arguments),
5228
- len = args.length,
5676
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
5677
+ var len = args.length,
5229
5678
  hasCallback = len && typeof args[len - 1] === fnString;
5230
5679
 
5231
- done = hasCallback ? args.pop() : error;
5680
+ done = hasCallback ? args.pop() : handleError;
5232
5681
  gen = fn.apply(this, args);
5233
5682
  } else {
5234
- done = done || error;
5683
+ done = done || handleError;
5235
5684
  }
5236
5685
 
5237
5686
  next();
@@ -5245,7 +5694,7 @@ if (!Array.prototype.forEach) {
5245
5694
 
5246
5695
  // multiple args
5247
5696
  if (arguments.length > 2) {
5248
- res = slice.call(arguments, 1);
5697
+ for(var res = [], i = 1, len = arguments.length; i < len; i++) { res.push(arguments[i]); }
5249
5698
  }
5250
5699
 
5251
5700
  if (err) {
@@ -5300,41 +5749,7 @@ if (!Array.prototype.forEach) {
5300
5749
  }
5301
5750
  };
5302
5751
 
5303
- /**
5304
- * Takes a function with a callback and turns it into a thunk.
5305
- * @param {Function} A function with a callback such as fs.readFile
5306
- * @returns {Function} A function, when executed will continue the state machine.
5307
- */
5308
- Rx.denodify = function (fn) {
5309
- return function () {
5310
- var args = slice.call(arguments),
5311
- results,
5312
- called,
5313
- callback;
5314
-
5315
- args.push(function() {
5316
- results = arguments;
5317
-
5318
- if (callback && !called) {
5319
- called = true;
5320
- cb.apply(this, results);
5321
- }
5322
- });
5323
-
5324
- fn.apply(this, args);
5325
-
5326
- return function (fn) {
5327
- callback = fn;
5328
-
5329
- if (results && !called) {
5330
- called = true;
5331
- fn.apply(this, results);
5332
- }
5333
- }
5334
- }
5335
- };
5336
-
5337
- function error(err) {
5752
+ function handleError(err) {
5338
5753
  if (!err) { return; }
5339
5754
  timeoutScheduler.schedule(function() {
5340
5755
  throw err;
@@ -5400,7 +5815,7 @@ if (!Array.prototype.forEach) {
5400
5815
  */
5401
5816
  Observable.fromCallback = function (func, context, selector) {
5402
5817
  return function () {
5403
- var args = slice.call(arguments, 0);
5818
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
5404
5819
 
5405
5820
  return new AnonymousObservable(function (observer) {
5406
5821
  function handler() {
@@ -5410,8 +5825,7 @@ if (!Array.prototype.forEach) {
5410
5825
  try {
5411
5826
  results = selector(results);
5412
5827
  } catch (err) {
5413
- observer.onError(err);
5414
- return;
5828
+ return observer.onError(err);
5415
5829
  }
5416
5830
 
5417
5831
  observer.onNext(results);
@@ -5441,7 +5855,7 @@ if (!Array.prototype.forEach) {
5441
5855
  */
5442
5856
  Observable.fromNodeCallback = function (func, context, selector) {
5443
5857
  return function () {
5444
- var args = slice.call(arguments, 0);
5858
+ for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
5445
5859
 
5446
5860
  return new AnonymousObservable(function (observer) {
5447
5861
  function handler(err) {
@@ -5450,14 +5864,13 @@ if (!Array.prototype.forEach) {
5450
5864
  return;
5451
5865
  }
5452
5866
 
5453
- var results = slice.call(arguments, 1);
5867
+ for(var results = [], i = 1, len = arguments.length; i < len; i++) { results.push(arguments[i]); }
5454
5868
 
5455
5869
  if (selector) {
5456
5870
  try {
5457
5871
  results = selector(results);
5458
5872
  } catch (e) {
5459
- observer.onError(e);
5460
- return;
5873
+ return observer.onError(e);
5461
5874
  }
5462
5875
  observer.onNext(results);
5463
5876
  } else {
@@ -5575,19 +5988,6 @@ if (!Array.prototype.forEach) {
5575
5988
  */
5576
5989
  Rx.config.useNativeEvents = false;
5577
5990
 
5578
- // Check for Angular/jQuery/Zepto support
5579
- var jq =
5580
- !!root.angular && !!angular.element ? angular.element :
5581
- (!!root.jQuery ? root.jQuery : (
5582
- !!root.Zepto ? root.Zepto : null));
5583
-
5584
- // Check for ember
5585
- var ember = !!root.Ember && typeof root.Ember.addListener === 'function';
5586
-
5587
- // Check for Backbone.Marionette. Note if using AMD add Marionette as a dependency of rxjs
5588
- // for proper loading order!
5589
- var marionette = !!root.Backbone && !!root.Backbone.Marionette;
5590
-
5591
5991
  /**
5592
5992
  * Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList.
5593
5993
  *
@@ -5610,25 +6010,13 @@ if (!Array.prototype.forEach) {
5610
6010
 
5611
6011
  // Use only if non-native events are allowed
5612
6012
  if (!Rx.config.useNativeEvents) {
5613
- if (marionette) {
6013
+ // Handles jq, Angular.js, Zepto, Marionette, Ember.js
6014
+ if (typeof element.on === 'function' && typeof element.off === 'function') {
5614
6015
  return fromEventPattern(
5615
6016
  function (h) { element.on(eventName, h); },
5616
6017
  function (h) { element.off(eventName, h); },
5617
6018
  selector);
5618
6019
  }
5619
- if (ember) {
5620
- return fromEventPattern(
5621
- function (h) { Ember.addListener(element, eventName, h); },
5622
- function (h) { Ember.removeListener(element, eventName, h); },
5623
- selector);
5624
- }
5625
- if (jq) {
5626
- var $elem = jq(element);
5627
- return fromEventPattern(
5628
- function (h) { $elem.on(eventName, h); },
5629
- function (h) { $elem.off(eventName, h); },
5630
- selector);
5631
- }
5632
6020
  }
5633
6021
  return new AnonymousObservable(function (observer) {
5634
6022
  return createEventListener(
@@ -5756,7 +6144,7 @@ if (!Array.prototype.forEach) {
5756
6144
  };
5757
6145
 
5758
6146
  function combineLatestSource(source, subject, resultSelector) {
5759
- return new AnonymousObservable(function (observer) {
6147
+ return new AnonymousObservable(function (o) {
5760
6148
  var hasValue = [false, false],
5761
6149
  hasValueAll = false,
5762
6150
  isDone = false,
@@ -5769,20 +6157,20 @@ if (!Array.prototype.forEach) {
5769
6157
  hasValue[i] = true;
5770
6158
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
5771
6159
  if (err) {
5772
- observer.onError(err);
6160
+ o.onError(err);
5773
6161
  return;
5774
6162
  }
5775
6163
 
5776
6164
  try {
5777
6165
  res = resultSelector.apply(null, values);
5778
6166
  } catch (ex) {
5779
- observer.onError(ex);
6167
+ o.onError(ex);
5780
6168
  return;
5781
6169
  }
5782
- observer.onNext(res);
6170
+ o.onNext(res);
5783
6171
  }
5784
6172
  if (isDone && values[1]) {
5785
- observer.onCompleted();
6173
+ o.onCompleted();
5786
6174
  }
5787
6175
  }
5788
6176
 
@@ -5793,20 +6181,20 @@ if (!Array.prototype.forEach) {
5793
6181
  },
5794
6182
  function (e) {
5795
6183
  if (values[1]) {
5796
- observer.onError(e);
6184
+ o.onError(e);
5797
6185
  } else {
5798
6186
  err = e;
5799
6187
  }
5800
6188
  },
5801
6189
  function () {
5802
6190
  isDone = true;
5803
- values[1] && observer.onCompleted();
6191
+ values[1] && o.onCompleted();
5804
6192
  }),
5805
6193
  subject.subscribe(
5806
6194
  function (x) {
5807
6195
  next(x, 1);
5808
6196
  },
5809
- observer.onError.bind(observer),
6197
+ function (e) { o.onError(e); },
5810
6198
  function () {
5811
6199
  isDone = true;
5812
6200
  next(true, 1);
@@ -5819,7 +6207,7 @@ if (!Array.prototype.forEach) {
5819
6207
 
5820
6208
  inherits(PausableBufferedObservable, __super__);
5821
6209
 
5822
- function subscribe(observer) {
6210
+ function subscribe(o) {
5823
6211
  var q = [], previousShouldFire;
5824
6212
 
5825
6213
  var subscription =
@@ -5836,14 +6224,14 @@ if (!Array.prototype.forEach) {
5836
6224
  // change in shouldFire
5837
6225
  if (results.shouldFire) {
5838
6226
  while (q.length > 0) {
5839
- observer.onNext(q.shift());
6227
+ o.onNext(q.shift());
5840
6228
  }
5841
6229
  }
5842
6230
  } else {
5843
6231
  previousShouldFire = results.shouldFire;
5844
6232
  // new data
5845
6233
  if (results.shouldFire) {
5846
- observer.onNext(results.data);
6234
+ o.onNext(results.data);
5847
6235
  } else {
5848
6236
  q.push(results.data);
5849
6237
  }
@@ -5852,16 +6240,16 @@ if (!Array.prototype.forEach) {
5852
6240
  function (err) {
5853
6241
  // Empty buffer before sending error
5854
6242
  while (q.length > 0) {
5855
- observer.onNext(q.shift());
6243
+ o.onNext(q.shift());
5856
6244
  }
5857
- observer.onError(err);
6245
+ o.onError(err);
5858
6246
  },
5859
6247
  function () {
5860
6248
  // Empty buffer before sending completion
5861
6249
  while (q.length > 0) {
5862
- observer.onNext(q.shift());
6250
+ o.onNext(q.shift());
5863
6251
  }
5864
- observer.onCompleted();
6252
+ o.onCompleted();
5865
6253
  }
5866
6254
  );
5867
6255
  return subscription;
@@ -6034,6 +6422,160 @@ if (!Array.prototype.forEach) {
6034
6422
  return new ControlledObservable(this, enableQueue);
6035
6423
  };
6036
6424
 
6425
+ var StopAndWaitObservable = (function (__super__) {
6426
+
6427
+ function subscribe (observer) {
6428
+ this.subscription = this.source.subscribe(new StopAndWaitObserver(observer, this, this.subscription));
6429
+
6430
+ var self = this;
6431
+ timeoutScheduler.schedule(function () { self.source.request(1); });
6432
+
6433
+ return this.subscription;
6434
+ }
6435
+
6436
+ inherits(StopAndWaitObservable, __super__);
6437
+
6438
+ function StopAndWaitObservable (source) {
6439
+ __super__.call(this, subscribe, source);
6440
+ this.source = source;
6441
+ }
6442
+
6443
+ var StopAndWaitObserver = (function (__sub__) {
6444
+
6445
+ inherits(StopAndWaitObserver, __sub__);
6446
+
6447
+ function StopAndWaitObserver (observer, observable, cancel) {
6448
+ __sub__.call(this);
6449
+ this.observer = observer;
6450
+ this.observable = observable;
6451
+ this.cancel = cancel;
6452
+ }
6453
+
6454
+ var stopAndWaitObserverProto = StopAndWaitObserver.prototype;
6455
+
6456
+ stopAndWaitObserverProto.completed = function () {
6457
+ this.observer.onCompleted();
6458
+ this.dispose();
6459
+ };
6460
+
6461
+ stopAndWaitObserverProto.error = function (error) {
6462
+ this.observer.onError(error);
6463
+ this.dispose();
6464
+ }
6465
+
6466
+ stopAndWaitObserverProto.next = function (value) {
6467
+ this.observer.onNext(value);
6468
+
6469
+ var self = this;
6470
+ timeoutScheduler.schedule(function () {
6471
+ self.observable.source.request(1);
6472
+ });
6473
+ };
6474
+
6475
+ stopAndWaitObserverProto.dispose = function () {
6476
+ this.observer = null;
6477
+ if (this.cancel) {
6478
+ this.cancel.dispose();
6479
+ this.cancel = null;
6480
+ }
6481
+ __sub__.prototype.dispose.call(this);
6482
+ };
6483
+
6484
+ return StopAndWaitObserver;
6485
+ }(AbstractObserver));
6486
+
6487
+ return StopAndWaitObservable;
6488
+ }(Observable));
6489
+
6490
+
6491
+ /**
6492
+ * Attaches a stop and wait observable to the current observable.
6493
+ * @returns {Observable} A stop and wait observable.
6494
+ */
6495
+ ControlledObservable.prototype.stopAndWait = function () {
6496
+ return new StopAndWaitObservable(this);
6497
+ };
6498
+
6499
+ var WindowedObservable = (function (__super__) {
6500
+
6501
+ function subscribe (observer) {
6502
+ this.subscription = this.source.subscribe(new WindowedObserver(observer, this, this.subscription));
6503
+
6504
+ var self = this;
6505
+ timeoutScheduler.schedule(function () {
6506
+ self.source.request(self.windowSize);
6507
+ });
6508
+
6509
+ return this.subscription;
6510
+ }
6511
+
6512
+ inherits(WindowedObservable, __super__);
6513
+
6514
+ function WindowedObservable(source, windowSize) {
6515
+ __super__.call(this, subscribe, source);
6516
+ this.source = source;
6517
+ this.windowSize = windowSize;
6518
+ }
6519
+
6520
+ var WindowedObserver = (function (__sub__) {
6521
+
6522
+ inherits(WindowedObserver, __sub__);
6523
+
6524
+ function WindowedObserver(observer, observable, cancel) {
6525
+ this.observer = observer;
6526
+ this.observable = observable;
6527
+ this.cancel = cancel;
6528
+ this.received = 0;
6529
+ }
6530
+
6531
+ var windowedObserverPrototype = WindowedObserver.prototype;
6532
+
6533
+ windowedObserverPrototype.completed = function () {
6534
+ this.observer.onCompleted();
6535
+ this.dispose();
6536
+ };
6537
+
6538
+ windowedObserverPrototype.error = function (error) {
6539
+ this.observer.onError(error);
6540
+ this.dispose();
6541
+ };
6542
+
6543
+ windowedObserverPrototype.next = function (value) {
6544
+ this.observer.onNext(value);
6545
+
6546
+ this.received = ++this.received % this.observable.windowSize;
6547
+ if (this.received === 0) {
6548
+ var self = this;
6549
+ timeoutScheduler.schedule(function () {
6550
+ self.observable.source.request(self.observable.windowSize);
6551
+ });
6552
+ }
6553
+ };
6554
+
6555
+ windowedObserverPrototype.dispose = function () {
6556
+ this.observer = null;
6557
+ if (this.cancel) {
6558
+ this.cancel.dispose();
6559
+ this.cancel = null;
6560
+ }
6561
+ __sub__.prototype.dispose.call(this);
6562
+ };
6563
+
6564
+ return WindowedObserver;
6565
+ }(AbstractObserver));
6566
+
6567
+ return WindowedObservable;
6568
+ }(Observable));
6569
+
6570
+ /**
6571
+ * Creates a sliding windowed observable based upon the window size.
6572
+ * @param {Number} windowSize The number of items in the window
6573
+ * @returns {Observable} A windowed observable based upon the window size.
6574
+ */
6575
+ ControlledObservable.prototype.windowed = function (windowSize) {
6576
+ return new WindowedObservable(this, windowSize);
6577
+ };
6578
+
6037
6579
  /**
6038
6580
  * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
6039
6581
  * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
@@ -6175,23 +6717,18 @@ if (!Array.prototype.forEach) {
6175
6717
  return this.replay(null, bufferSize, window, scheduler).refCount();
6176
6718
  };
6177
6719
 
6178
- /** @private */
6179
- var InnerSubscription = function (subject, observer) {
6180
- this.subject = subject;
6181
- this.observer = observer;
6182
- };
6720
+ var InnerSubscription = function (subject, observer) {
6721
+ this.subject = subject;
6722
+ this.observer = observer;
6723
+ };
6183
6724
 
6184
- /**
6185
- * @private
6186
- * @memberOf InnerSubscription
6187
- */
6188
- InnerSubscription.prototype.dispose = function () {
6189
- if (!this.subject.isDisposed && this.observer !== null) {
6190
- var idx = this.subject.observers.indexOf(this.observer);
6191
- this.subject.observers.splice(idx, 1);
6192
- this.observer = null;
6193
- }
6194
- };
6725
+ InnerSubscription.prototype.dispose = function () {
6726
+ if (!this.subject.isDisposed && this.observer !== null) {
6727
+ var idx = this.subject.observers.indexOf(this.observer);
6728
+ this.subject.observers.splice(idx, 1);
6729
+ this.observer = null;
6730
+ }
6731
+ };
6195
6732
 
6196
6733
  /**
6197
6734
  * Represents a value that changes over time.
@@ -6199,15 +6736,14 @@ if (!Array.prototype.forEach) {
6199
6736
  */
6200
6737
  var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
6201
6738
  function subscribe(observer) {
6202
- checkDisposed.call(this);
6739
+ checkDisposed(this);
6203
6740
  if (!this.isStopped) {
6204
6741
  this.observers.push(observer);
6205
6742
  observer.onNext(this.value);
6206
6743
  return new InnerSubscription(this, observer);
6207
6744
  }
6208
- var ex = this.exception;
6209
- if (ex) {
6210
- observer.onError(ex);
6745
+ if (this.hasError) {
6746
+ observer.onError(this.error);
6211
6747
  } else {
6212
6748
  observer.onCompleted();
6213
6749
  }
@@ -6217,7 +6753,6 @@ if (!Array.prototype.forEach) {
6217
6753
  inherits(BehaviorSubject, __super__);
6218
6754
 
6219
6755
  /**
6220
- * @constructor
6221
6756
  * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
6222
6757
  * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
6223
6758
  */
@@ -6227,7 +6762,7 @@ if (!Array.prototype.forEach) {
6227
6762
  this.observers = [],
6228
6763
  this.isDisposed = false,
6229
6764
  this.isStopped = false,
6230
- this.exception = null;
6765
+ this.hasError = false;
6231
6766
  }
6232
6767
 
6233
6768
  addProperties(BehaviorSubject.prototype, Observer, {
@@ -6235,47 +6770,46 @@ if (!Array.prototype.forEach) {
6235
6770
  * Indicates whether the subject has observers subscribed to it.
6236
6771
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
6237
6772
  */
6238
- hasObservers: function () {
6239
- return this.observers.length > 0;
6240
- },
6773
+ hasObservers: function () { return this.observers.length > 0; },
6241
6774
  /**
6242
6775
  * Notifies all subscribed observers about the end of the sequence.
6243
6776
  */
6244
6777
  onCompleted: function () {
6245
- checkDisposed.call(this);
6778
+ checkDisposed(this);
6246
6779
  if (this.isStopped) { return; }
6247
6780
  this.isStopped = true;
6248
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6781
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6249
6782
  os[i].onCompleted();
6250
6783
  }
6251
6784
 
6252
- this.observers = [];
6785
+ this.observers.length = 0;
6253
6786
  },
6254
6787
  /**
6255
6788
  * Notifies all subscribed observers about the exception.
6256
6789
  * @param {Mixed} error The exception to send to all observers.
6257
6790
  */
6258
6791
  onError: function (error) {
6259
- checkDisposed.call(this);
6792
+ checkDisposed(this);
6260
6793
  if (this.isStopped) { return; }
6261
6794
  this.isStopped = true;
6262
- this.exception = error;
6795
+ this.hasError = true;
6796
+ this.error = error;
6263
6797
 
6264
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6798
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6265
6799
  os[i].onError(error);
6266
6800
  }
6267
6801
 
6268
- this.observers = [];
6802
+ this.observers.length = 0;
6269
6803
  },
6270
6804
  /**
6271
6805
  * Notifies all subscribed observers about the arrival of the specified element in the sequence.
6272
6806
  * @param {Mixed} value The value to send to all observers.
6273
6807
  */
6274
6808
  onNext: function (value) {
6275
- checkDisposed.call(this);
6809
+ checkDisposed(this);
6276
6810
  if (this.isStopped) { return; }
6277
6811
  this.value = value;
6278
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
6812
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6279
6813
  os[i].onNext(value);
6280
6814
  }
6281
6815
  },
@@ -6309,7 +6843,7 @@ if (!Array.prototype.forEach) {
6309
6843
  function subscribe(observer) {
6310
6844
  var so = new ScheduledObserver(this.scheduler, observer),
6311
6845
  subscription = createRemovableDisposable(this, so);
6312
- checkDisposed.call(this);
6846
+ checkDisposed(this);
6313
6847
  this._trim(this.scheduler.now());
6314
6848
  this.observers.push(so);
6315
6849
 
@@ -6348,7 +6882,7 @@ if (!Array.prototype.forEach) {
6348
6882
  __super__.call(this, subscribe);
6349
6883
  }
6350
6884
 
6351
- addProperties(ReplaySubject.prototype, Observer, {
6885
+ addProperties(ReplaySubject.prototype, Observer.prototype, {
6352
6886
  /**
6353
6887
  * Indicates whether the subject has observers subscribed to it.
6354
6888
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
@@ -6369,15 +6903,14 @@ if (!Array.prototype.forEach) {
6369
6903
  * @param {Mixed} value The value to send to all observers.
6370
6904
  */
6371
6905
  onNext: function (value) {
6372
- checkDisposed.call(this);
6906
+ checkDisposed(this);
6373
6907
  if (this.isStopped) { return; }
6374
6908
  var now = this.scheduler.now();
6375
6909
  this.q.push({ interval: now, value: value });
6376
6910
  this._trim(now);
6377
6911
 
6378
- var o = this.observers.slice(0);
6379
- for (var i = 0, len = o.length; i < len; i++) {
6380
- var observer = o[i];
6912
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6913
+ var observer = os[i];
6381
6914
  observer.onNext(value);
6382
6915
  observer.ensureActive();
6383
6916
  }
@@ -6387,37 +6920,35 @@ if (!Array.prototype.forEach) {
6387
6920
  * @param {Mixed} error The exception to send to all observers.
6388
6921
  */
6389
6922
  onError: function (error) {
6390
- checkDisposed.call(this);
6923
+ checkDisposed(this);
6391
6924
  if (this.isStopped) { return; }
6392
6925
  this.isStopped = true;
6393
6926
  this.error = error;
6394
6927
  this.hasError = true;
6395
6928
  var now = this.scheduler.now();
6396
6929
  this._trim(now);
6397
- var o = this.observers.slice(0);
6398
- for (var i = 0, len = o.length; i < len; i++) {
6399
- var observer = o[i];
6930
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6931
+ var observer = os[i];
6400
6932
  observer.onError(error);
6401
6933
  observer.ensureActive();
6402
6934
  }
6403
- this.observers = [];
6935
+ this.observers.length = 0;
6404
6936
  },
6405
6937
  /**
6406
6938
  * Notifies all subscribed observers about the end of the sequence.
6407
6939
  */
6408
6940
  onCompleted: function () {
6409
- checkDisposed.call(this);
6941
+ checkDisposed(this);
6410
6942
  if (this.isStopped) { return; }
6411
6943
  this.isStopped = true;
6412
6944
  var now = this.scheduler.now();
6413
6945
  this._trim(now);
6414
- var o = this.observers.slice(0);
6415
- for (var i = 0, len = o.length; i < len; i++) {
6416
- var observer = o[i];
6946
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
6947
+ var observer = os[i];
6417
6948
  observer.onCompleted();
6418
6949
  observer.ensureActive();
6419
6950
  }
6420
- this.observers = [];
6951
+ this.observers.length = 0;
6421
6952
  },
6422
6953
  /**
6423
6954
  * Unsubscribe all observers and release resources.
@@ -6449,7 +6980,7 @@ if (!Array.prototype.forEach) {
6449
6980
  return subscription;
6450
6981
  };
6451
6982
 
6452
- __super__.call(this, subject.subscribe.bind(subject));
6983
+ __super__.call(this, function (o) { return subject.subscribe(o); });
6453
6984
  }
6454
6985
 
6455
6986
  ConnectableObservable.prototype.refCount = function () {
@@ -6536,7 +7067,7 @@ if (!Array.prototype.forEach) {
6536
7067
  // Hack check for valueOf
6537
7068
  var valueOf = obj.valueOf();
6538
7069
  if (typeof valueOf === 'number') { return numberHashFn(valueOf); }
6539
- if (typeof obj === 'string') { return stringHashFn(valueOf); }
7070
+ if (typeof valueOf === 'string') { return stringHashFn(valueOf); }
6540
7071
  }
6541
7072
  if (obj.hashCode) { return obj.hashCode(); }
6542
7073
 
@@ -6952,7 +7483,7 @@ if (!Array.prototype.forEach) {
6952
7483
  */
6953
7484
  observableProto.window = function (windowOpeningsOrClosingSelector, windowClosingSelector) {
6954
7485
  if (arguments.length === 1 && typeof arguments[0] !== 'function') {
6955
- return observableWindowWithBounaries.call(this, windowOpeningsOrClosingSelector);
7486
+ return observableWindowWithBoundaries.call(this, windowOpeningsOrClosingSelector);
6956
7487
  }
6957
7488
  return typeof windowOpeningsOrClosingSelector === 'function' ?
6958
7489
  observableWindowWithClosingSelector.call(this, windowOpeningsOrClosingSelector) :
@@ -6965,7 +7496,7 @@ if (!Array.prototype.forEach) {
6965
7496
  });
6966
7497
  }
6967
7498
 
6968
- function observableWindowWithBounaries(windowBoundaries) {
7499
+ function observableWindowWithBoundaries(windowBoundaries) {
6969
7500
  var source = this;
6970
7501
  return new AnonymousObservable(function (observer) {
6971
7502
  var win = new Subject(),
@@ -7087,10 +7618,9 @@ if (!Array.prototype.forEach) {
7087
7618
  * and the second triggers when the predicate returns false.
7088
7619
  */
7089
7620
  observableProto.partition = function(predicate, thisArg) {
7090
- var published = this.publish().refCount();
7091
7621
  return [
7092
- published.filter(predicate, thisArg),
7093
- published.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
7622
+ this.filter(predicate, thisArg),
7623
+ this.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
7094
7624
  ];
7095
7625
  };
7096
7626
 
@@ -7277,7 +7807,12 @@ if (!Array.prototype.forEach) {
7277
7807
  * @returns {Observable} An observable sequence with an array collecting the last elements of all the input sequences.
7278
7808
  */
7279
7809
  Observable.forkJoin = function () {
7280
- var allSources = argsOrArray(arguments, 0);
7810
+ var allSources = [];
7811
+ if (Array.isArray(arguments[0])) {
7812
+ allSources = arguments[0];
7813
+ } else {
7814
+ for(var i = 0, len = arguments.length; i < len; i++) { allSources.push(arguments[i]); }
7815
+ }
7281
7816
  return new AnonymousObservable(function (subscriber) {
7282
7817
  var count = allSources.length;
7283
7818
  if (count === 0) {
@@ -7338,7 +7873,6 @@ if (!Array.prototype.forEach) {
7338
7873
  */
7339
7874
  observableProto.forkJoin = function (second, resultSelector) {
7340
7875
  var first = this;
7341
-
7342
7876
  return new AnonymousObservable(function (observer) {
7343
7877
  var leftStopped = false, rightStopped = false,
7344
7878
  hasLeft = false, hasRight = false,
@@ -7617,7 +8151,6 @@ if (!Array.prototype.forEach) {
7617
8151
  };
7618
8152
 
7619
8153
  var JoinObserver = (function (__super__) {
7620
-
7621
8154
  inherits(JoinObserver, __super__);
7622
8155
 
7623
8156
  function JoinObserver(source, onError) {
@@ -7635,8 +8168,7 @@ if (!Array.prototype.forEach) {
7635
8168
  JoinObserverPrototype.next = function (notification) {
7636
8169
  if (!this.isDisposed) {
7637
8170
  if (notification.kind === 'E') {
7638
- this.onError(notification.exception);
7639
- return;
8171
+ return this.onError(notification.exception);
7640
8172
  }
7641
8173
  this.queue.push(notification);
7642
8174
  var activePlans = this.activePlans.slice(0);
@@ -7686,7 +8218,7 @@ if (!Array.prototype.forEach) {
7686
8218
  /**
7687
8219
  * Matches when the observable sequence has an available value and projects the value.
7688
8220
  *
7689
- * @param selector Selector that will be invoked for values in the source sequence.
8221
+ * @param {Function} selector Selector that will be invoked for values in the source sequence.
7690
8222
  * @returns {Plan} Plan that produces the projected values, to be fed (with other plans) to the when operator.
7691
8223
  */
7692
8224
  observableProto.thenDo = function (selector) {
@@ -7700,28 +8232,34 @@ if (!Array.prototype.forEach) {
7700
8232
  * @returns {Observable} Observable sequence with the results form matching several patterns.
7701
8233
  */
7702
8234
  Observable.when = function () {
7703
- var plans = argsOrArray(arguments, 0);
7704
- return new AnonymousObservable(function (observer) {
8235
+ var len = arguments.length, plans;
8236
+ if (Array.isArray(arguments[0])) {
8237
+ plans = arguments[0];
8238
+ } else {
8239
+ plans = new Array(len);
8240
+ for(var i = 0; i < len; i++) { plans[i] = arguments[i]; }
8241
+ }
8242
+ return new AnonymousObservable(function (o) {
7705
8243
  var activePlans = [],
7706
8244
  externalSubscriptions = new Map();
7707
8245
  var outObserver = observerCreate(
7708
- observer.onNext.bind(observer),
8246
+ function (x) { o.onNext(x); },
7709
8247
  function (err) {
7710
8248
  externalSubscriptions.forEach(function (v) { v.onError(err); });
7711
- observer.onError(err);
8249
+ o.onError(err);
7712
8250
  },
7713
- observer.onCompleted.bind(observer)
8251
+ function (x) { o.onCompleted(); }
7714
8252
  );
7715
8253
  try {
7716
8254
  for (var i = 0, len = plans.length; i < len; i++) {
7717
8255
  activePlans.push(plans[i].activate(externalSubscriptions, outObserver, function (activePlan) {
7718
8256
  var idx = activePlans.indexOf(activePlan);
7719
8257
  activePlans.splice(idx, 1);
7720
- activePlans.length === 0 && observer.onCompleted();
8258
+ activePlans.length === 0 && o.onCompleted();
7721
8259
  }));
7722
8260
  }
7723
8261
  } catch (e) {
7724
- observableThrow(e).subscribe(observer);
8262
+ observableThrow(e).subscribe(o);
7725
8263
  }
7726
8264
  var group = new CompositeDisposable();
7727
8265
  externalSubscriptions.forEach(function (joinObserver) {
@@ -7744,15 +8282,15 @@ if (!Array.prototype.forEach) {
7744
8282
 
7745
8283
  function observableTimerDateAndPeriod(dueTime, period, scheduler) {
7746
8284
  return new AnonymousObservable(function (observer) {
7747
- var count = 0, d = dueTime, p = normalizeTime(period);
7748
- return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
8285
+ var d = dueTime, p = normalizeTime(period);
8286
+ return scheduler.scheduleRecursiveWithAbsoluteAndState(0, d, function (count, self) {
7749
8287
  if (p > 0) {
7750
8288
  var now = scheduler.now();
7751
8289
  d = d + p;
7752
8290
  d <= now && (d = now + p);
7753
8291
  }
7754
- observer.onNext(count++);
7755
- self(d);
8292
+ observer.onNext(count);
8293
+ self(count + 1, d);
7756
8294
  });
7757
8295
  });
7758
8296
  }
@@ -7957,7 +8495,7 @@ if (!Array.prototype.forEach) {
7957
8495
  * @deprecated use #debounce or #throttleWithTimeout instead.
7958
8496
  */
7959
8497
  observableProto.throttle = function(dueTime, scheduler) {
7960
- deprecate('throttle', 'debounce or throttleWithTimeout');
8498
+ //deprecate('throttle', 'debounce or throttleWithTimeout');
7961
8499
  return this.debounce(dueTime, scheduler);
7962
8500
  };
7963
8501
 
@@ -8461,7 +8999,7 @@ if (!Array.prototype.forEach) {
8461
8999
  /**
8462
9000
  * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
8463
9001
  * @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
8464
- * @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
9002
+ * @param {Function} timeoutDurationSelector Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
8465
9003
  * @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
8466
9004
  * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
8467
9005
  */
@@ -8578,7 +9116,7 @@ if (!Array.prototype.forEach) {
8578
9116
  };
8579
9117
 
8580
9118
  observableProto.throttleWithSelector = function () {
8581
- deprecate('throttleWithSelector', 'debounceWithSelector');
9119
+ //deprecate('throttleWithSelector', 'debounceWithSelector');
8582
9120
  return this.debounceWithSelector.apply(this, arguments);
8583
9121
  };
8584
9122
 
@@ -8599,20 +9137,20 @@ if (!Array.prototype.forEach) {
8599
9137
  observableProto.skipLastWithTime = function (duration, scheduler) {
8600
9138
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8601
9139
  var source = this;
8602
- return new AnonymousObservable(function (observer) {
9140
+ return new AnonymousObservable(function (o) {
8603
9141
  var q = [];
8604
9142
  return source.subscribe(function (x) {
8605
9143
  var now = scheduler.now();
8606
9144
  q.push({ interval: now, value: x });
8607
9145
  while (q.length > 0 && now - q[0].interval >= duration) {
8608
- observer.onNext(q.shift().value);
9146
+ o.onNext(q.shift().value);
8609
9147
  }
8610
- }, observer.onError.bind(observer), function () {
9148
+ }, function (e) { o.onError(e); }, function () {
8611
9149
  var now = scheduler.now();
8612
9150
  while (q.length > 0 && now - q[0].interval >= duration) {
8613
- observer.onNext(q.shift().value);
9151
+ o.onNext(q.shift().value);
8614
9152
  }
8615
- observer.onCompleted();
9153
+ o.onCompleted();
8616
9154
  });
8617
9155
  }, source);
8618
9156
  };
@@ -8630,7 +9168,7 @@ if (!Array.prototype.forEach) {
8630
9168
  observableProto.takeLastWithTime = function (duration, scheduler) {
8631
9169
  var source = this;
8632
9170
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8633
- return new AnonymousObservable(function (observer) {
9171
+ return new AnonymousObservable(function (o) {
8634
9172
  var q = [];
8635
9173
  return source.subscribe(function (x) {
8636
9174
  var now = scheduler.now();
@@ -8638,13 +9176,13 @@ if (!Array.prototype.forEach) {
8638
9176
  while (q.length > 0 && now - q[0].interval >= duration) {
8639
9177
  q.shift();
8640
9178
  }
8641
- }, observer.onError.bind(observer), function () {
9179
+ }, function (e) { o.onError(e); }, function () {
8642
9180
  var now = scheduler.now();
8643
9181
  while (q.length > 0) {
8644
9182
  var next = q.shift();
8645
- if (now - next.interval <= duration) { observer.onNext(next.value); }
9183
+ if (now - next.interval <= duration) { o.onNext(next.value); }
8646
9184
  }
8647
- observer.onCompleted();
9185
+ o.onCompleted();
8648
9186
  });
8649
9187
  }, source);
8650
9188
  };
@@ -8662,7 +9200,7 @@ if (!Array.prototype.forEach) {
8662
9200
  observableProto.takeLastBufferWithTime = function (duration, scheduler) {
8663
9201
  var source = this;
8664
9202
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8665
- return new AnonymousObservable(function (observer) {
9203
+ return new AnonymousObservable(function (o) {
8666
9204
  var q = [];
8667
9205
  return source.subscribe(function (x) {
8668
9206
  var now = scheduler.now();
@@ -8670,14 +9208,14 @@ if (!Array.prototype.forEach) {
8670
9208
  while (q.length > 0 && now - q[0].interval >= duration) {
8671
9209
  q.shift();
8672
9210
  }
8673
- }, observer.onError.bind(observer), function () {
9211
+ }, function (e) { o.onError(e); }, function () {
8674
9212
  var now = scheduler.now(), res = [];
8675
9213
  while (q.length > 0) {
8676
9214
  var next = q.shift();
8677
- if (now - next.interval <= duration) { res.push(next.value); }
9215
+ now - next.interval <= duration && res.push(next.value);
8678
9216
  }
8679
- observer.onNext(res);
8680
- observer.onCompleted();
9217
+ o.onNext(res);
9218
+ o.onCompleted();
8681
9219
  });
8682
9220
  }, source);
8683
9221
  };
@@ -8698,8 +9236,8 @@ if (!Array.prototype.forEach) {
8698
9236
  observableProto.takeWithTime = function (duration, scheduler) {
8699
9237
  var source = this;
8700
9238
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8701
- return new AnonymousObservable(function (observer) {
8702
- return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
9239
+ return new AnonymousObservable(function (o) {
9240
+ return new CompositeDisposable(scheduler.scheduleWithRelative(duration, function () { o.onCompleted(); }), source.subscribe(o));
8703
9241
  }, source);
8704
9242
  };
8705
9243
 
@@ -8746,15 +9284,14 @@ if (!Array.prototype.forEach) {
8746
9284
  var source = this, schedulerMethod = startTime instanceof Date ?
8747
9285
  'scheduleWithAbsolute' :
8748
9286
  'scheduleWithRelative';
8749
- return new AnonymousObservable(function (observer) {
9287
+ return new AnonymousObservable(function (o) {
8750
9288
  var open = false;
8751
9289
 
8752
9290
  return new CompositeDisposable(
8753
9291
  scheduler[schedulerMethod](startTime, function () { open = true; }),
8754
9292
  source.subscribe(
8755
- function (x) { open && observer.onNext(x); },
8756
- observer.onError.bind(observer),
8757
- observer.onCompleted.bind(observer)));
9293
+ function (x) { open && o.onNext(x); },
9294
+ function (e) { o.onError(e); }, function () { o.onCompleted(); }));
8758
9295
  }, source);
8759
9296
  };
8760
9297
 
@@ -8769,10 +9306,10 @@ if (!Array.prototype.forEach) {
8769
9306
  var source = this, schedulerMethod = endTime instanceof Date ?
8770
9307
  'scheduleWithAbsolute' :
8771
9308
  'scheduleWithRelative';
8772
- return new AnonymousObservable(function (observer) {
9309
+ return new AnonymousObservable(function (o) {
8773
9310
  return new CompositeDisposable(
8774
- scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
8775
- source.subscribe(observer));
9311
+ scheduler[schedulerMethod](endTime, function () { o.onCompleted(); }),
9312
+ source.subscribe(o));
8776
9313
  }, source);
8777
9314
  };
8778
9315
 
@@ -8787,18 +9324,16 @@ if (!Array.prototype.forEach) {
8787
9324
  var duration = +windowDuration || 0;
8788
9325
  if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
8789
9326
  var source = this;
8790
- return new AnonymousObservable(function (observer) {
9327
+ return new AnonymousObservable(function (o) {
8791
9328
  var lastOnNext = 0;
8792
9329
  return source.subscribe(
8793
9330
  function (x) {
8794
9331
  var now = scheduler.now();
8795
9332
  if (lastOnNext === 0 || now - lastOnNext >= duration) {
8796
9333
  lastOnNext = now;
8797
- observer.onNext(x);
9334
+ o.onNext(x);
8798
9335
  }
8799
- },
8800
- observer.onError.bind(observer),
8801
- observer.onCompleted.bind(observer)
9336
+ },function (e) { o.onError(e); }, function () { o.onCompleted(); }
8802
9337
  );
8803
9338
  }, source);
8804
9339
  };
@@ -8860,7 +9395,8 @@ if (!Array.prototype.forEach) {
8860
9395
  * @returns {Observable} An exclusive observable with only the results that happen when subscribed.
8861
9396
  */
8862
9397
  observableProto.exclusiveMap = function (selector, thisArg) {
8863
- var sources = this;
9398
+ var sources = this,
9399
+ selectorFunc = bindCallback(selector, thisArg, 3);
8864
9400
  return new AnonymousObservable(function (observer) {
8865
9401
  var index = 0,
8866
9402
  hasCurrent = false,
@@ -8885,7 +9421,7 @@ if (!Array.prototype.forEach) {
8885
9421
  function (x) {
8886
9422
  var result;
8887
9423
  try {
8888
- result = selector.call(thisArg, x, index++, innerSource);
9424
+ result = selectorFunc(x, index++, innerSource);
8889
9425
  } catch (e) {
8890
9426
  observer.onError(e);
8891
9427
  return;
@@ -8893,7 +9429,7 @@ if (!Array.prototype.forEach) {
8893
9429
 
8894
9430
  observer.onNext(result);
8895
9431
  },
8896
- observer.onError.bind(observer),
9432
+ function (e) { observer.onError(e); },
8897
9433
  function () {
8898
9434
  g.remove(innerSubscription);
8899
9435
  hasCurrent = false;
@@ -8904,7 +9440,7 @@ if (!Array.prototype.forEach) {
8904
9440
  }));
8905
9441
  }
8906
9442
  },
8907
- observer.onError.bind(observer),
9443
+ function (e) { observer.onError(e); },
8908
9444
  function () {
8909
9445
  isStopped = true;
8910
9446
  if (g.length === 1 && !hasCurrent) {
@@ -9240,31 +9776,29 @@ if (!Array.prototype.forEach) {
9240
9776
  disposableEmpty;
9241
9777
  }
9242
9778
 
9779
+ function setDisposable(s, state) {
9780
+ var ado = state[0], subscribe = state[1];
9781
+ try {
9782
+ ado.setDisposable(fixSubscriber(subscribe(ado)));
9783
+ } catch (e) {
9784
+ if (!ado.fail(e)) { throw e; }
9785
+ }
9786
+ }
9787
+
9243
9788
  function AnonymousObservable(subscribe, parent) {
9244
9789
  this.source = parent;
9245
- if (!(this instanceof AnonymousObservable)) {
9246
- return new AnonymousObservable(subscribe);
9247
- }
9248
9790
 
9249
9791
  function s(observer) {
9250
- var setDisposable = function () {
9251
- try {
9252
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
9253
- } catch (e) {
9254
- if (!autoDetachObserver.fail(e)) {
9255
- throw e;
9256
- }
9257
- }
9258
- };
9259
9792
 
9260
- var autoDetachObserver = new AutoDetachObserver(observer);
9793
+ var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
9794
+
9261
9795
  if (currentThreadScheduler.scheduleRequired()) {
9262
- currentThreadScheduler.schedule(setDisposable);
9796
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
9263
9797
  } else {
9264
- setDisposable();
9798
+ setDisposable(null, state);
9265
9799
  }
9266
9800
 
9267
- return autoDetachObserver;
9801
+ return ado;
9268
9802
  }
9269
9803
 
9270
9804
  __super__.call(this, s);
@@ -9291,7 +9825,7 @@ if (!Array.prototype.forEach) {
9291
9825
  this.observer.onNext(value);
9292
9826
  noError = true;
9293
9827
  } catch (e) {
9294
- throw e;
9828
+ return thrower(e);
9295
9829
  } finally {
9296
9830
  !noError && this.dispose();
9297
9831
  }
@@ -9301,7 +9835,7 @@ if (!Array.prototype.forEach) {
9301
9835
  try {
9302
9836
  this.observer.onError(err);
9303
9837
  } catch (e) {
9304
- throw e;
9838
+ return thrower(e);
9305
9839
  } finally {
9306
9840
  this.dispose();
9307
9841
  }
@@ -9311,7 +9845,7 @@ if (!Array.prototype.forEach) {
9311
9845
  try {
9312
9846
  this.observer.onCompleted();
9313
9847
  } catch (e) {
9314
- throw e;
9848
+ return thrower(e);
9315
9849
  } finally {
9316
9850
  this.dispose();
9317
9851
  }
@@ -9348,112 +9882,108 @@ if (!Array.prototype.forEach) {
9348
9882
  return GroupedObservable;
9349
9883
  }(Observable));
9350
9884
 
9885
+ /**
9886
+ * Represents an object that is both an observable sequence as well as an observer.
9887
+ * Each notification is broadcasted to all subscribed observers.
9888
+ */
9889
+ var Subject = Rx.Subject = (function (__super__) {
9890
+ function subscribe(observer) {
9891
+ checkDisposed(this);
9892
+ if (!this.isStopped) {
9893
+ this.observers.push(observer);
9894
+ return new InnerSubscription(this, observer);
9895
+ }
9896
+ if (this.hasError) {
9897
+ observer.onError(this.error);
9898
+ return disposableEmpty;
9899
+ }
9900
+ observer.onCompleted();
9901
+ return disposableEmpty;
9902
+ }
9903
+
9904
+ inherits(Subject, __super__);
9905
+
9351
9906
  /**
9352
- * Represents an object that is both an observable sequence as well as an observer.
9353
- * Each notification is broadcasted to all subscribed observers.
9907
+ * Creates a subject.
9354
9908
  */
9355
- var Subject = Rx.Subject = (function (_super) {
9356
- function subscribe(observer) {
9357
- checkDisposed.call(this);
9358
- if (!this.isStopped) {
9359
- this.observers.push(observer);
9360
- return new InnerSubscription(this, observer);
9361
- }
9362
- if (this.exception) {
9363
- observer.onError(this.exception);
9364
- return disposableEmpty;
9365
- }
9366
- observer.onCompleted();
9367
- return disposableEmpty;
9368
- }
9909
+ function Subject() {
9910
+ __super__.call(this, subscribe);
9911
+ this.isDisposed = false,
9912
+ this.isStopped = false,
9913
+ this.observers = [];
9914
+ this.hasError = false;
9915
+ }
9369
9916
 
9370
- inherits(Subject, _super);
9917
+ addProperties(Subject.prototype, Observer.prototype, {
9918
+ /**
9919
+ * Indicates whether the subject has observers subscribed to it.
9920
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
9921
+ */
9922
+ hasObservers: function () { return this.observers.length > 0; },
9923
+ /**
9924
+ * Notifies all subscribed observers about the end of the sequence.
9925
+ */
9926
+ onCompleted: function () {
9927
+ checkDisposed(this);
9928
+ if (!this.isStopped) {
9929
+ this.isStopped = true;
9930
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
9931
+ os[i].onCompleted();
9932
+ }
9371
9933
 
9372
- /**
9373
- * Creates a subject.
9374
- * @constructor
9375
- */
9376
- function Subject() {
9377
- _super.call(this, subscribe);
9378
- this.isDisposed = false,
9379
- this.isStopped = false,
9380
- this.observers = [];
9934
+ this.observers.length = 0;
9381
9935
  }
9936
+ },
9937
+ /**
9938
+ * Notifies all subscribed observers about the exception.
9939
+ * @param {Mixed} error The exception to send to all observers.
9940
+ */
9941
+ onError: function (error) {
9942
+ checkDisposed(this);
9943
+ if (!this.isStopped) {
9944
+ this.isStopped = true;
9945
+ this.error = error;
9946
+ this.hasError = true;
9947
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
9948
+ os[i].onError(error);
9949
+ }
9382
9950
 
9383
- addProperties(Subject.prototype, Observer, {
9384
- /**
9385
- * Indicates whether the subject has observers subscribed to it.
9386
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
9387
- */
9388
- hasObservers: function () {
9389
- return this.observers.length > 0;
9390
- },
9391
- /**
9392
- * Notifies all subscribed observers about the end of the sequence.
9393
- */
9394
- onCompleted: function () {
9395
- checkDisposed.call(this);
9396
- if (!this.isStopped) {
9397
- var os = this.observers.slice(0);
9398
- this.isStopped = true;
9399
- for (var i = 0, len = os.length; i < len; i++) {
9400
- os[i].onCompleted();
9401
- }
9402
-
9403
- this.observers = [];
9404
- }
9405
- },
9406
- /**
9407
- * Notifies all subscribed observers about the exception.
9408
- * @param {Mixed} error The exception to send to all observers.
9409
- */
9410
- onError: function (exception) {
9411
- checkDisposed.call(this);
9412
- if (!this.isStopped) {
9413
- var os = this.observers.slice(0);
9414
- this.isStopped = true;
9415
- this.exception = exception;
9416
- for (var i = 0, len = os.length; i < len; i++) {
9417
- os[i].onError(exception);
9418
- }
9419
-
9420
- this.observers = [];
9421
- }
9422
- },
9423
- /**
9424
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
9425
- * @param {Mixed} value The value to send to all observers.
9426
- */
9427
- onNext: function (value) {
9428
- checkDisposed.call(this);
9429
- if (!this.isStopped) {
9430
- var os = this.observers.slice(0);
9431
- for (var i = 0, len = os.length; i < len; i++) {
9432
- os[i].onNext(value);
9433
- }
9434
- }
9435
- },
9436
- /**
9437
- * Unsubscribe all observers and release resources.
9438
- */
9439
- dispose: function () {
9440
- this.isDisposed = true;
9441
- this.observers = null;
9442
- }
9443
- });
9951
+ this.observers.length = 0;
9952
+ }
9953
+ },
9954
+ /**
9955
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
9956
+ * @param {Mixed} value The value to send to all observers.
9957
+ */
9958
+ onNext: function (value) {
9959
+ checkDisposed(this);
9960
+ if (!this.isStopped) {
9961
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
9962
+ os[i].onNext(value);
9963
+ }
9964
+ }
9965
+ },
9966
+ /**
9967
+ * Unsubscribe all observers and release resources.
9968
+ */
9969
+ dispose: function () {
9970
+ this.isDisposed = true;
9971
+ this.observers = null;
9972
+ }
9973
+ });
9444
9974
 
9445
- /**
9446
- * Creates a subject from the specified observer and observable.
9447
- * @param {Observer} observer The observer used to send messages to the subject.
9448
- * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
9449
- * @returns {Subject} Subject implemented using the given observer and observable.
9450
- */
9451
- Subject.create = function (observer, observable) {
9452
- return new AnonymousSubject(observer, observable);
9453
- };
9975
+ /**
9976
+ * Creates a subject from the specified observer and observable.
9977
+ * @param {Observer} observer The observer used to send messages to the subject.
9978
+ * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
9979
+ * @returns {Subject} Subject implemented using the given observer and observable.
9980
+ */
9981
+ Subject.create = function (observer, observable) {
9982
+ return new AnonymousSubject(observer, observable);
9983
+ };
9454
9984
 
9455
- return Subject;
9456
- }(Observable));
9985
+ return Subject;
9986
+ }(Observable));
9457
9987
 
9458
9988
  /**
9459
9989
  * Represents the result of an asynchronous operation.
@@ -9462,21 +9992,17 @@ if (!Array.prototype.forEach) {
9462
9992
  var AsyncSubject = Rx.AsyncSubject = (function (__super__) {
9463
9993
 
9464
9994
  function subscribe(observer) {
9465
- checkDisposed.call(this);
9995
+ checkDisposed(this);
9466
9996
 
9467
9997
  if (!this.isStopped) {
9468
9998
  this.observers.push(observer);
9469
9999
  return new InnerSubscription(this, observer);
9470
10000
  }
9471
10001
 
9472
- var ex = this.exception,
9473
- hv = this.hasValue,
9474
- v = this.value;
9475
-
9476
- if (ex) {
9477
- observer.onError(ex);
9478
- } else if (hv) {
9479
- observer.onNext(v);
10002
+ if (this.hasError) {
10003
+ observer.onError(this.error);
10004
+ } else if (this.hasValue) {
10005
+ observer.onNext(this.value);
9480
10006
  observer.onCompleted();
9481
10007
  } else {
9482
10008
  observer.onCompleted();
@@ -9496,10 +10022,9 @@ if (!Array.prototype.forEach) {
9496
10022
 
9497
10023
  this.isDisposed = false;
9498
10024
  this.isStopped = false;
9499
- this.value = null;
9500
10025
  this.hasValue = false;
9501
10026
  this.observers = [];
9502
- this.exception = null;
10027
+ this.hasError = false;
9503
10028
  }
9504
10029
 
9505
10030
  addProperties(AsyncSubject.prototype, Observer, {
@@ -9508,34 +10033,32 @@ if (!Array.prototype.forEach) {
9508
10033
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
9509
10034
  */
9510
10035
  hasObservers: function () {
9511
- checkDisposed.call(this);
10036
+ checkDisposed(this);
9512
10037
  return this.observers.length > 0;
9513
10038
  },
9514
10039
  /**
9515
10040
  * Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
9516
10041
  */
9517
10042
  onCompleted: function () {
9518
- var o, i, len;
9519
- checkDisposed.call(this);
10043
+ var i, len;
10044
+ checkDisposed(this);
9520
10045
  if (!this.isStopped) {
9521
10046
  this.isStopped = true;
9522
- var os = this.observers.slice(0),
9523
- v = this.value,
9524
- hv = this.hasValue;
9525
-
9526
- if (hv) {
9527
- for (i = 0, len = os.length; i < len; i++) {
9528
- o = os[i];
9529
- o.onNext(v);
10047
+ var os = cloneArray(this.observers), len = os.length;
10048
+
10049
+ if (this.hasValue) {
10050
+ for (i = 0; i < len; i++) {
10051
+ var o = os[i];
10052
+ o.onNext(this.value);
9530
10053
  o.onCompleted();
9531
10054
  }
9532
10055
  } else {
9533
- for (i = 0, len = os.length; i < len; i++) {
10056
+ for (i = 0; i < len; i++) {
9534
10057
  os[i].onCompleted();
9535
10058
  }
9536
10059
  }
9537
10060
 
9538
- this.observers = [];
10061
+ this.observers.length = 0;
9539
10062
  }
9540
10063
  },
9541
10064
  /**
@@ -9543,17 +10066,17 @@ if (!Array.prototype.forEach) {
9543
10066
  * @param {Mixed} error The Error to send to all observers.
9544
10067
  */
9545
10068
  onError: function (error) {
9546
- checkDisposed.call(this);
10069
+ checkDisposed(this);
9547
10070
  if (!this.isStopped) {
9548
- var os = this.observers.slice(0);
9549
10071
  this.isStopped = true;
9550
- this.exception = error;
10072
+ this.hasError = true;
10073
+ this.error = error;
9551
10074
 
9552
- for (var i = 0, len = os.length; i < len; i++) {
10075
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
9553
10076
  os[i].onError(error);
9554
10077
  }
9555
10078
 
9556
- this.observers = [];
10079
+ this.observers.length = 0;
9557
10080
  }
9558
10081
  },
9559
10082
  /**
@@ -9561,7 +10084,7 @@ if (!Array.prototype.forEach) {
9561
10084
  * @param {Mixed} value The value to store in the subject.
9562
10085
  */
9563
10086
  onNext: function (value) {
9564
- checkDisposed.call(this);
10087
+ checkDisposed(this);
9565
10088
  if (this.isStopped) { return; }
9566
10089
  this.value = value;
9567
10090
  this.hasValue = true;
@@ -9583,18 +10106,22 @@ if (!Array.prototype.forEach) {
9583
10106
  var AnonymousSubject = Rx.AnonymousSubject = (function (__super__) {
9584
10107
  inherits(AnonymousSubject, __super__);
9585
10108
 
10109
+ function subscribe(observer) {
10110
+ return this.observable.subscribe(observer);
10111
+ }
10112
+
9586
10113
  function AnonymousSubject(observer, observable) {
9587
10114
  this.observer = observer;
9588
10115
  this.observable = observable;
9589
- __super__.call(this, this.observable.subscribe.bind(this.observable));
10116
+ __super__.call(this, subscribe);
9590
10117
  }
9591
10118
 
9592
- addProperties(AnonymousSubject.prototype, Observer, {
10119
+ addProperties(AnonymousSubject.prototype, Observer.prototype, {
9593
10120
  onCompleted: function () {
9594
10121
  this.observer.onCompleted();
9595
10122
  },
9596
- onError: function (exception) {
9597
- this.observer.onError(exception);
10123
+ onError: function (error) {
10124
+ this.observer.onError(error);
9598
10125
  },
9599
10126
  onNext: function (value) {
9600
10127
  this.observer.onNext(value);
@@ -9604,23 +10131,46 @@ if (!Array.prototype.forEach) {
9604
10131
  return AnonymousSubject;
9605
10132
  }(Observable));
9606
10133
 
9607
- if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
9608
- root.Rx = Rx;
10134
+ /**
10135
+ * Used to pause and resume streams.
10136
+ */
10137
+ Rx.Pauser = (function (__super__) {
10138
+ inherits(Pauser, __super__);
10139
+
10140
+ function Pauser() {
10141
+ __super__.call(this);
10142
+ }
9609
10143
 
9610
- define(function() {
9611
- return Rx;
9612
- });
9613
- } else if (freeExports && freeModule) {
9614
- // in Node.js or RingoJS
9615
- if (moduleExports) {
9616
- (freeModule.exports = Rx).Rx = Rx;
9617
- } else {
9618
- freeExports.Rx = Rx;
9619
- }
10144
+ /**
10145
+ * Pauses the underlying sequence.
10146
+ */
10147
+ Pauser.prototype.pause = function () { this.onNext(false); };
10148
+
10149
+ /**
10150
+ * Resumes the underlying sequence.
10151
+ */
10152
+ Pauser.prototype.resume = function () { this.onNext(true); };
10153
+
10154
+ return Pauser;
10155
+ }(Subject));
10156
+
10157
+ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
10158
+ root.Rx = Rx;
10159
+
10160
+ define(function() {
10161
+ return Rx;
10162
+ });
10163
+ } else if (freeExports && freeModule) {
10164
+ // in Node.js or RingoJS
10165
+ if (moduleExports) {
10166
+ (freeModule.exports = Rx).Rx = Rx;
9620
10167
  } else {
9621
- // in a browser or Rhino
9622
- root.Rx = Rx;
10168
+ freeExports.Rx = Rx;
9623
10169
  }
10170
+ } else {
10171
+ // in a browser or Rhino
10172
+ root.Rx = Rx;
10173
+ }
9624
10174
 
9625
10175
  // All code before this point will be filtered from stack traces.
9626
10176
  var rEndingLine = captureLine();