rxjs-rails 2.3.22 → 2.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 h(function(d){function e(a,b){k[b]=a;var e;if(g[b]=!0,h||(h=g.every(r))){if(f)return void d.onError(f);try{e=c.apply(null,k)}catch(j){return void d.onError(j)}d.onNext(e)}i&&k[1]&&d.onCompleted()}var f,g=[!1,!1],h=!1,i=!1,k=new Array(2);return new j(a.subscribe(function(a){e(a,0)},function(a){k[1]?d.onError(a):f=a},function(){i=!0,k[1]&&d.onCompleted()}),b.subscribe(function(a){e(a,1)},d.onError.bind(d),function(){i=!0,e(!0,1)}))},a)}var f=c.Observable,g=f.prototype,h=c.AnonymousObservable,i=c.internals.AbstractObserver,j=c.CompositeDisposable,k=c.Subject,l=c.Observer,m=c.Disposable.empty,n=c.Disposable.create,o=c.internals.inherits,p=c.internals.addProperties,q=c.Scheduler.timeout,r=(c.Scheduler.currentThread,c.helpers.identity),s=function(a){function b(a){var b=this.source.publish(),c=b.subscribe(a),d=m,e=this.pauser.distinctUntilChanged().subscribe(function(a){a?d=b.connect():(d.dispose(),d=m)});return new j(c,d,e)}function c(c,d){this.source=c,this.controller=new k,this.pauser=d&&d.subscribe?this.controller.merge(d):this.controller,a.call(this,b,c)}return o(c,a),c.prototype.pause=function(){this.controller.onNext(!1)},c.prototype.resume=function(){this.controller.onNext(!0)},c}(f);g.pausable=function(a){return new s(this,a)};var t=function(a){function b(a){var b,c=[],f=e(this.source,this.pauser.distinctUntilChanged().startWith(!1),function(a,b){return{data:a,shouldFire:b}}).subscribe(function(e){if(b!==d&&e.shouldFire!=b){if(b=e.shouldFire,e.shouldFire)for(;c.length>0;)a.onNext(c.shift())}else b=e.shouldFire,e.shouldFire?a.onNext(e.data):c.push(e.data)},function(b){for(;c.length>0;)a.onNext(c.shift());a.onError(b)},function(){for(;c.length>0;)a.onNext(c.shift());a.onCompleted()});return f}function c(c,d){this.source=c,this.controller=new k,this.pauser=d&&d.subscribe?this.controller.merge(d):this.controller,a.call(this,b,c)}return o(c,a),c.prototype.pause=function(){this.controller.onNext(!1)},c.prototype.resume=function(){this.controller.onNext(!0)},c}(f);g.pausableBuffered=function(a){return new t(this,a)};var u=function(a){function b(a){return this.source.subscribe(a)}function c(c,d){a.call(this,b,c),this.subject=new v(d),this.source=c.multicast(this.subject).refCount()}return o(c,a),c.prototype.request=function(a){return null==a&&(a=-1),this.subject.request(a)},c}(f),v=function(a){function b(a){return this.subject.subscribe(a)}function c(c){null==c&&(c=!0),a.call(this,b),this.subject=new k,this.enableQueue=c,this.queue=c?[]:null,this.requestedCount=0,this.requestedDisposable=m,this.error=null,this.hasFailed=!1,this.hasCompleted=!1,this.controlledDisposable=m}return o(c,a),p(c.prototype,l,{onCompleted:function(){this.hasCompleted=!0,(!this.enableQueue||0===this.queue.length)&&this.subject.onCompleted()},onError:function(a){this.hasFailed=!0,this.error=a,(!this.enableQueue||0===this.queue.length)&&this.subject.onError(a)},onNext:function(a){var b=!1;0===this.requestedCount?this.enableQueue&&this.queue.push(a):(-1!==this.requestedCount&&0===this.requestedCount--&&this.disposeCurrentRequest(),b=!0),b&&this.subject.onNext(a)},_processRequest:function(a){if(this.enableQueue){for(;this.queue.length>=a&&a>0;)this.subject.onNext(this.queue.shift()),a--;return 0!==this.queue.length?{numberOfItems:a,returnValue:!0}:{numberOfItems:a,returnValue:!1}}return this.hasFailed?(this.subject.onError(this.error),this.controlledDisposable.dispose(),this.controlledDisposable=m):this.hasCompleted&&(this.subject.onCompleted(),this.controlledDisposable.dispose(),this.controlledDisposable=m),{numberOfItems:a,returnValue:!1}},request:function(a){this.disposeCurrentRequest();var b=this,c=this._processRequest(a),a=c.numberOfItems;return c.returnValue?m:(this.requestedCount=a,this.requestedDisposable=n(function(){b.requestedCount=0}),this.requestedDisposable)},disposeCurrentRequest:function(){this.requestedDisposable.dispose(),this.requestedDisposable=m}}),c}(f);g.controlled=function(a){return null==a&&(a=!0),new u(this,a)};var w=function(a){function b(a){this.subscription=this.source.subscribe(new d(a,this,this.subscription));var b=this;return q.schedule(function(){b.source.request(1)}),this.subscription}function c(c){a.call(this,b,c),this.source=c}o(c,a);var d=function(a){function b(b,c,d){a.call(this),this.observer=b,this.observable=c,this.cancel=d}o(b,a);var c=b.prototype;return c.completed=function(){this.observer.onCompleted(),this.dispose()},c.error=function(a){this.observer.onError(a),this.dispose()},c.next=function(a){this.observer.onNext(a);var b=this;q.schedule(function(){b.observable.source.request(1)})},c.dispose=function(){this.observer=null,this.cancel&&(this.cancel.dispose(),this.cancel=null),a.prototype.dispose.call(this)},b}(i);return c}(f);u.prototype.stopAndWait=function(){return new w(this)};var x=function(a){function b(a){this.subscription=this.source.subscribe(new d(a,this,this.subscription));var b=this;return q.schedule(function(){b.source.request(b.windowSize)}),this.subscription}function c(c,d){a.call(this,b,c),this.source=c,this.windowSize=d}o(c,a);var d=function(a){function b(a,b,c){this.observer=a,this.observable=b,this.cancel=c,this.received=0}o(b,a);var c=b.prototype;return c.completed=function(){this.observer.onCompleted(),this.dispose()},c.error=function(a){this.observer.onError(a),this.dispose()},c.next=function(a){if(this.observer.onNext(a),this.received=++this.received%this.observable.windowSize,0===this.received){var b=this;q.schedule(function(){b.observable.source.request(b.observable.windowSize)})}},c.dispose=function(){this.observer=null,this.cancel&&(this.cancel.dispose(),this.cancel=null),a.prototype.dispose.call(this)},b}(i);return c}(f);return u.prototype.windowed=function(a){return new x(this,a)},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 h(function(d){function e(a,b){k[b]=a;var e;if(g[b]=!0,h||(h=g.every(r))){if(f)return void d.onError(f);try{e=c.apply(null,k)}catch(j){return void d.onError(j)}d.onNext(e)}i&&k[1]&&d.onCompleted()}var f,g=[!1,!1],h=!1,i=!1,k=new Array(2);return new j(a.subscribe(function(a){e(a,0)},function(a){k[1]?d.onError(a):f=a},function(){i=!0,k[1]&&d.onCompleted()}),b.subscribe(function(a){e(a,1)},function(a){d.onError(a)},function(){i=!0,e(!0,1)}))},a)}var f=c.Observable,g=f.prototype,h=c.AnonymousObservable,i=c.internals.AbstractObserver,j=c.CompositeDisposable,k=c.Subject,l=c.Observer,m=c.Disposable.empty,n=c.Disposable.create,o=c.internals.inherits,p=c.internals.addProperties,q=c.Scheduler.timeout,r=(c.Scheduler.currentThread,c.helpers.identity);c.Pauser=function(a){function b(){a.call(this)}return o(b,a),b.prototype.pause=function(){this.onNext(!1)},b.prototype.resume=function(){this.onNext(!0)},b}(k);var s=function(a){function b(a){var b=this.source.publish(),c=b.subscribe(a),d=m,e=this.pauser.distinctUntilChanged().subscribe(function(a){a?d=b.connect():(d.dispose(),d=m)});return new j(c,d,e)}function c(c,d){this.source=c,this.controller=new k,this.pauser=d&&d.subscribe?this.controller.merge(d):this.controller,a.call(this,b,c)}return o(c,a),c.prototype.pause=function(){this.controller.onNext(!1)},c.prototype.resume=function(){this.controller.onNext(!0)},c}(f);g.pausable=function(a){return new s(this,a)};var t=function(a){function b(a){var b,c=[],f=e(this.source,this.pauser.distinctUntilChanged().startWith(!1),function(a,b){return{data:a,shouldFire:b}}).subscribe(function(e){if(b!==d&&e.shouldFire!=b){if(b=e.shouldFire,e.shouldFire)for(;c.length>0;)a.onNext(c.shift())}else b=e.shouldFire,e.shouldFire?a.onNext(e.data):c.push(e.data)},function(b){for(;c.length>0;)a.onNext(c.shift());a.onError(b)},function(){for(;c.length>0;)a.onNext(c.shift());a.onCompleted()});return f}function c(c,d){this.source=c,this.controller=new k,this.pauser=d&&d.subscribe?this.controller.merge(d):this.controller,a.call(this,b,c)}return o(c,a),c.prototype.pause=function(){this.controller.onNext(!1)},c.prototype.resume=function(){this.controller.onNext(!0)},c}(f);g.pausableBuffered=function(a){return new t(this,a)};var u=function(a){function b(a){return this.source.subscribe(a)}function c(c,d){a.call(this,b,c),this.subject=new v(d),this.source=c.multicast(this.subject).refCount()}return o(c,a),c.prototype.request=function(a){return null==a&&(a=-1),this.subject.request(a)},c}(f),v=function(a){function b(a){return this.subject.subscribe(a)}function c(c){null==c&&(c=!0),a.call(this,b),this.subject=new k,this.enableQueue=c,this.queue=c?[]:null,this.requestedCount=0,this.requestedDisposable=m,this.error=null,this.hasFailed=!1,this.hasCompleted=!1,this.controlledDisposable=m}return o(c,a),p(c.prototype,l,{onCompleted:function(){this.hasCompleted=!0,(!this.enableQueue||0===this.queue.length)&&this.subject.onCompleted()},onError:function(a){this.hasFailed=!0,this.error=a,(!this.enableQueue||0===this.queue.length)&&this.subject.onError(a)},onNext:function(a){var b=!1;0===this.requestedCount?this.enableQueue&&this.queue.push(a):(-1!==this.requestedCount&&0===this.requestedCount--&&this.disposeCurrentRequest(),b=!0),b&&this.subject.onNext(a)},_processRequest:function(a){if(this.enableQueue){for(;this.queue.length>=a&&a>0;)this.subject.onNext(this.queue.shift()),a--;return 0!==this.queue.length?{numberOfItems:a,returnValue:!0}:{numberOfItems:a,returnValue:!1}}return this.hasFailed?(this.subject.onError(this.error),this.controlledDisposable.dispose(),this.controlledDisposable=m):this.hasCompleted&&(this.subject.onCompleted(),this.controlledDisposable.dispose(),this.controlledDisposable=m),{numberOfItems:a,returnValue:!1}},request:function(a){this.disposeCurrentRequest();var b=this,c=this._processRequest(a),a=c.numberOfItems;return c.returnValue?m:(this.requestedCount=a,this.requestedDisposable=n(function(){b.requestedCount=0}),this.requestedDisposable)},disposeCurrentRequest:function(){this.requestedDisposable.dispose(),this.requestedDisposable=m}}),c}(f);g.controlled=function(a){return null==a&&(a=!0),new u(this,a)};var w=function(a){function b(a){this.subscription=this.source.subscribe(new d(a,this,this.subscription));var b=this;return q.schedule(function(){b.source.request(1)}),this.subscription}function c(c){a.call(this,b,c),this.source=c}o(c,a);var d=function(a){function b(b,c,d){a.call(this),this.observer=b,this.observable=c,this.cancel=d}o(b,a);var c=b.prototype;return c.completed=function(){this.observer.onCompleted(),this.dispose()},c.error=function(a){this.observer.onError(a),this.dispose()},c.next=function(a){this.observer.onNext(a);var b=this;q.schedule(function(){b.observable.source.request(1)})},c.dispose=function(){this.observer=null,this.cancel&&(this.cancel.dispose(),this.cancel=null),a.prototype.dispose.call(this)},b}(i);return c}(f);u.prototype.stopAndWait=function(){return new w(this)};var x=function(a){function b(a){this.subscription=this.source.subscribe(new d(a,this,this.subscription));var b=this;return q.schedule(function(){b.source.request(b.windowSize)}),this.subscription}function c(c,d){a.call(this,b,c),this.source=c,this.windowSize=d}o(c,a);var d=function(a){function b(a,b,c){this.observer=a,this.observable=b,this.cancel=c,this.received=0}o(b,a);var c=b.prototype;return c.completed=function(){this.observer.onCompleted(),this.dispose()},c.error=function(a){this.observer.onError(a),this.dispose()},c.next=function(a){if(this.observer.onNext(a),this.received=++this.received%this.observable.windowSize,0===this.received){var b=this;q.schedule(function(){b.observable.source.request(b.observable.windowSize)})}},c.dispose=function(){this.observer=null,this.cancel&&(this.cancel.dispose(),this.cancel=null),a.prototype.dispose.call(this)},b}(i);return c}(f);return u.prototype.windowed=function(a){return new x(this,a)},c});
3
3
  //# sourceMappingURL=rx.backpressure.map
@@ -49,9 +49,8 @@
49
49
 
50
50
  // Utilities
51
51
  var objectDisposed = 'Object has been disposed';
52
- function checkDisposed() {
53
- if (this.isDisposed) { throw new Error(objectDisposed); }
54
- }
52
+ function checkDisposed(self) { if (self.isDisposed) { throw new Error(objectDisposed); } }
53
+ function cloneArray(arr) { for(var a = [], i = 0, len = arr.length; i < len; i++) { a.push(arr[i]); } return a;}
55
54
 
56
55
  /**
57
56
  * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
@@ -194,23 +193,18 @@
194
193
  return this.replay(null, bufferSize, window, scheduler).refCount();
195
194
  };
196
195
 
197
- /** @private */
198
- var InnerSubscription = function (subject, observer) {
199
- this.subject = subject;
200
- this.observer = observer;
201
- };
196
+ var InnerSubscription = function (subject, observer) {
197
+ this.subject = subject;
198
+ this.observer = observer;
199
+ };
202
200
 
203
- /**
204
- * @private
205
- * @memberOf InnerSubscription
206
- */
207
- InnerSubscription.prototype.dispose = function () {
208
- if (!this.subject.isDisposed && this.observer !== null) {
209
- var idx = this.subject.observers.indexOf(this.observer);
210
- this.subject.observers.splice(idx, 1);
211
- this.observer = null;
212
- }
213
- };
201
+ InnerSubscription.prototype.dispose = function () {
202
+ if (!this.subject.isDisposed && this.observer !== null) {
203
+ var idx = this.subject.observers.indexOf(this.observer);
204
+ this.subject.observers.splice(idx, 1);
205
+ this.observer = null;
206
+ }
207
+ };
214
208
 
215
209
  /**
216
210
  * Represents a value that changes over time.
@@ -218,15 +212,14 @@
218
212
  */
219
213
  var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
220
214
  function subscribe(observer) {
221
- checkDisposed.call(this);
215
+ checkDisposed(this);
222
216
  if (!this.isStopped) {
223
217
  this.observers.push(observer);
224
218
  observer.onNext(this.value);
225
219
  return new InnerSubscription(this, observer);
226
220
  }
227
- var ex = this.exception;
228
- if (ex) {
229
- observer.onError(ex);
221
+ if (this.hasError) {
222
+ observer.onError(this.error);
230
223
  } else {
231
224
  observer.onCompleted();
232
225
  }
@@ -236,7 +229,6 @@
236
229
  inherits(BehaviorSubject, __super__);
237
230
 
238
231
  /**
239
- * @constructor
240
232
  * Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
241
233
  * @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
242
234
  */
@@ -246,7 +238,7 @@
246
238
  this.observers = [],
247
239
  this.isDisposed = false,
248
240
  this.isStopped = false,
249
- this.exception = null;
241
+ this.hasError = false;
250
242
  }
251
243
 
252
244
  addProperties(BehaviorSubject.prototype, Observer, {
@@ -254,47 +246,46 @@
254
246
  * Indicates whether the subject has observers subscribed to it.
255
247
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
256
248
  */
257
- hasObservers: function () {
258
- return this.observers.length > 0;
259
- },
249
+ hasObservers: function () { return this.observers.length > 0; },
260
250
  /**
261
251
  * Notifies all subscribed observers about the end of the sequence.
262
252
  */
263
253
  onCompleted: function () {
264
- checkDisposed.call(this);
254
+ checkDisposed(this);
265
255
  if (this.isStopped) { return; }
266
256
  this.isStopped = true;
267
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
257
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
268
258
  os[i].onCompleted();
269
259
  }
270
260
 
271
- this.observers = [];
261
+ this.observers.length = 0;
272
262
  },
273
263
  /**
274
264
  * Notifies all subscribed observers about the exception.
275
265
  * @param {Mixed} error The exception to send to all observers.
276
266
  */
277
267
  onError: function (error) {
278
- checkDisposed.call(this);
268
+ checkDisposed(this);
279
269
  if (this.isStopped) { return; }
280
270
  this.isStopped = true;
281
- this.exception = error;
271
+ this.hasError = true;
272
+ this.error = error;
282
273
 
283
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
274
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
284
275
  os[i].onError(error);
285
276
  }
286
277
 
287
- this.observers = [];
278
+ this.observers.length = 0;
288
279
  },
289
280
  /**
290
281
  * Notifies all subscribed observers about the arrival of the specified element in the sequence.
291
282
  * @param {Mixed} value The value to send to all observers.
292
283
  */
293
284
  onNext: function (value) {
294
- checkDisposed.call(this);
285
+ checkDisposed(this);
295
286
  if (this.isStopped) { return; }
296
287
  this.value = value;
297
- for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
288
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
298
289
  os[i].onNext(value);
299
290
  }
300
291
  },
@@ -328,7 +319,7 @@
328
319
  function subscribe(observer) {
329
320
  var so = new ScheduledObserver(this.scheduler, observer),
330
321
  subscription = createRemovableDisposable(this, so);
331
- checkDisposed.call(this);
322
+ checkDisposed(this);
332
323
  this._trim(this.scheduler.now());
333
324
  this.observers.push(so);
334
325
 
@@ -367,7 +358,7 @@
367
358
  __super__.call(this, subscribe);
368
359
  }
369
360
 
370
- addProperties(ReplaySubject.prototype, Observer, {
361
+ addProperties(ReplaySubject.prototype, Observer.prototype, {
371
362
  /**
372
363
  * Indicates whether the subject has observers subscribed to it.
373
364
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
@@ -388,15 +379,14 @@
388
379
  * @param {Mixed} value The value to send to all observers.
389
380
  */
390
381
  onNext: function (value) {
391
- checkDisposed.call(this);
382
+ checkDisposed(this);
392
383
  if (this.isStopped) { return; }
393
384
  var now = this.scheduler.now();
394
385
  this.q.push({ interval: now, value: value });
395
386
  this._trim(now);
396
387
 
397
- var o = this.observers.slice(0);
398
- for (var i = 0, len = o.length; i < len; i++) {
399
- var observer = o[i];
388
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
389
+ var observer = os[i];
400
390
  observer.onNext(value);
401
391
  observer.ensureActive();
402
392
  }
@@ -406,37 +396,35 @@
406
396
  * @param {Mixed} error The exception to send to all observers.
407
397
  */
408
398
  onError: function (error) {
409
- checkDisposed.call(this);
399
+ checkDisposed(this);
410
400
  if (this.isStopped) { return; }
411
401
  this.isStopped = true;
412
402
  this.error = error;
413
403
  this.hasError = true;
414
404
  var now = this.scheduler.now();
415
405
  this._trim(now);
416
- var o = this.observers.slice(0);
417
- for (var i = 0, len = o.length; i < len; i++) {
418
- var observer = o[i];
406
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
407
+ var observer = os[i];
419
408
  observer.onError(error);
420
409
  observer.ensureActive();
421
410
  }
422
- this.observers = [];
411
+ this.observers.length = 0;
423
412
  },
424
413
  /**
425
414
  * Notifies all subscribed observers about the end of the sequence.
426
415
  */
427
416
  onCompleted: function () {
428
- checkDisposed.call(this);
417
+ checkDisposed(this);
429
418
  if (this.isStopped) { return; }
430
419
  this.isStopped = true;
431
420
  var now = this.scheduler.now();
432
421
  this._trim(now);
433
- var o = this.observers.slice(0);
434
- for (var i = 0, len = o.length; i < len; i++) {
435
- var observer = o[i];
422
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
423
+ var observer = os[i];
436
424
  observer.onCompleted();
437
425
  observer.ensureActive();
438
426
  }
439
- this.observers = [];
427
+ this.observers.length = 0;
440
428
  },
441
429
  /**
442
430
  * Unsubscribe all observers and release resources.
@@ -468,7 +456,7 @@
468
456
  return subscription;
469
457
  };
470
458
 
471
- __super__.call(this, subject.subscribe.bind(subject));
459
+ __super__.call(this, function (o) { return subject.subscribe(o); });
472
460
  }
473
461
 
474
462
  ConnectableObservable.prototype.refCount = function () {
@@ -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){function d(){if(this.isDisposed)throw new Error(s)}var e=c.Observable,f=e.prototype,g=c.AnonymousObservable,h=c.Subject,i=c.AsyncSubject,j=c.Observer,k=c.internals.ScheduledObserver,l=c.Disposable.create,m=c.Disposable.empty,n=c.CompositeDisposable,o=c.Scheduler.currentThread,p=c.helpers.isFunction,q=c.internals.inherits,r=c.internals.addProperties,s="Object has been disposed";f.multicast=function(a,b){var c=this;return"function"==typeof a?new g(function(d){var e=c.multicast(a());return new n(b(e).subscribe(d),e.connect())},c):new w(c,a)},f.publish=function(a){return a&&p(a)?this.multicast(function(){return new h},a):this.multicast(new h)},f.share=function(){return this.publish().refCount()},f.publishLast=function(a){return a&&p(a)?this.multicast(function(){return new i},a):this.multicast(new i)},f.publishValue=function(a,b){return 2===arguments.length?this.multicast(function(){return new u(b)},a):this.multicast(new u(a))},f.shareValue=function(a){return this.publishValue(a).refCount()},f.replay=function(a,b,c,d){return a&&p(a)?this.multicast(function(){return new v(b,c,d)},a):this.multicast(new v(b,c,d))},f.shareReplay=function(a,b,c){return this.replay(null,a,b,c).refCount()};var t=function(a,b){this.subject=a,this.observer=b};t.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var a=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(a,1),this.observer=null}};var u=c.BehaviorSubject=function(a){function b(a){if(d.call(this),!this.isStopped)return this.observers.push(a),a.onNext(this.value),new t(this,a);var b=this.exception;return b?a.onError(b):a.onCompleted(),m}function c(c){a.call(this,b),this.value=c,this.observers=[],this.isDisposed=!1,this.isStopped=!1,this.exception=null}return q(c,a),r(c.prototype,j,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(d.call(this),!this.isStopped){this.isStopped=!0;for(var a=0,b=this.observers.slice(0),c=b.length;c>a;a++)b[a].onCompleted();this.observers=[]}},onError:function(a){if(d.call(this),!this.isStopped){this.isStopped=!0,this.exception=a;for(var b=0,c=this.observers.slice(0),e=c.length;e>b;b++)c[b].onError(a);this.observers=[]}},onNext:function(a){if(d.call(this),!this.isStopped){this.value=a;for(var b=0,c=this.observers.slice(0),e=c.length;e>b;b++)c[b].onNext(a)}},dispose:function(){this.isDisposed=!0,this.observers=null,this.value=null,this.exception=null}}),c}(e),v=c.ReplaySubject=function(a){function b(a,b){return l(function(){b.dispose(),!a.isDisposed&&a.observers.splice(a.observers.indexOf(b),1)})}function c(a){var c=new k(this.scheduler,a),e=b(this,c);d.call(this),this._trim(this.scheduler.now()),this.observers.push(c);for(var f=0,g=this.q.length;g>f;f++)c.onNext(this.q[f].value);return this.hasError?c.onError(this.error):this.isStopped&&c.onCompleted(),c.ensureActive(),e}function e(b,d,e){this.bufferSize=null==b?Number.MAX_VALUE:b,this.windowSize=null==d?Number.MAX_VALUE:d,this.scheduler=e||o,this.q=[],this.observers=[],this.isStopped=!1,this.isDisposed=!1,this.hasError=!1,this.error=null,a.call(this,c)}return q(e,a),r(e.prototype,j,{hasObservers:function(){return this.observers.length>0},_trim:function(a){for(;this.q.length>this.bufferSize;)this.q.shift();for(;this.q.length>0&&a-this.q[0].interval>this.windowSize;)this.q.shift()},onNext:function(a){if(d.call(this),!this.isStopped){var b=this.scheduler.now();this.q.push({interval:b,value:a}),this._trim(b);for(var c=this.observers.slice(0),e=0,f=c.length;f>e;e++){var g=c[e];g.onNext(a),g.ensureActive()}}},onError:function(a){if(d.call(this),!this.isStopped){this.isStopped=!0,this.error=a,this.hasError=!0;var b=this.scheduler.now();this._trim(b);for(var c=this.observers.slice(0),e=0,f=c.length;f>e;e++){var g=c[e];g.onError(a),g.ensureActive()}this.observers=[]}},onCompleted:function(){if(d.call(this),!this.isStopped){this.isStopped=!0;var a=this.scheduler.now();this._trim(a);for(var b=this.observers.slice(0),c=0,e=b.length;e>c;c++){var f=b[c];f.onCompleted(),f.ensureActive()}this.observers=[]}},dispose:function(){this.isDisposed=!0,this.observers=null}}),e}(e),w=c.ConnectableObservable=function(a){function b(b,c){var d,e=!1,f=b.asObservable();this.connect=function(){return e||(e=!0,d=new n(f.subscribe(c),l(function(){e=!1}))),d},a.call(this,c.subscribe.bind(c))}return q(b,a),b.prototype.refCount=function(){var a,b=0,c=this;return new g(function(d){var e=1===++b,f=c.subscribe(d);return e&&(a=c.connect()),function(){f.dispose(),0===--b&&a.dispose()}})},b}(e);return 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){function d(a){if(a.isDisposed)throw new Error(t)}function e(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(a[c]);return b}var f=c.Observable,g=f.prototype,h=c.AnonymousObservable,i=c.Subject,j=c.AsyncSubject,k=c.Observer,l=c.internals.ScheduledObserver,m=c.Disposable.create,n=c.Disposable.empty,o=c.CompositeDisposable,p=c.Scheduler.currentThread,q=c.helpers.isFunction,r=c.internals.inherits,s=c.internals.addProperties,t="Object has been disposed";g.multicast=function(a,b){var c=this;return"function"==typeof a?new h(function(d){var e=c.multicast(a());return new o(b(e).subscribe(d),e.connect())},c):new x(c,a)},g.publish=function(a){return a&&q(a)?this.multicast(function(){return new i},a):this.multicast(new i)},g.share=function(){return this.publish().refCount()},g.publishLast=function(a){return a&&q(a)?this.multicast(function(){return new j},a):this.multicast(new j)},g.publishValue=function(a,b){return 2===arguments.length?this.multicast(function(){return new v(b)},a):this.multicast(new v(a))},g.shareValue=function(a){return this.publishValue(a).refCount()},g.replay=function(a,b,c,d){return a&&q(a)?this.multicast(function(){return new w(b,c,d)},a):this.multicast(new w(b,c,d))},g.shareReplay=function(a,b,c){return this.replay(null,a,b,c).refCount()};var u=function(a,b){this.subject=a,this.observer=b};u.prototype.dispose=function(){if(!this.subject.isDisposed&&null!==this.observer){var a=this.subject.observers.indexOf(this.observer);this.subject.observers.splice(a,1),this.observer=null}};var v=c.BehaviorSubject=function(a){function b(a){return d(this),this.isStopped?(this.hasError?a.onError(this.error):a.onCompleted(),n):(this.observers.push(a),a.onNext(this.value),new u(this,a))}function c(c){a.call(this,b),this.value=c,this.observers=[],this.isDisposed=!1,this.isStopped=!1,this.hasError=!1}return r(c,a),s(c.prototype,k,{hasObservers:function(){return this.observers.length>0},onCompleted:function(){if(d(this),!this.isStopped){this.isStopped=!0;for(var a=0,b=e(this.observers),c=b.length;c>a;a++)b[a].onCompleted();this.observers.length=0}},onError:function(a){if(d(this),!this.isStopped){this.isStopped=!0,this.hasError=!0,this.error=a;for(var b=0,c=e(this.observers),f=c.length;f>b;b++)c[b].onError(a);this.observers.length=0}},onNext:function(a){if(d(this),!this.isStopped){this.value=a;for(var b=0,c=e(this.observers),f=c.length;f>b;b++)c[b].onNext(a)}},dispose:function(){this.isDisposed=!0,this.observers=null,this.value=null,this.exception=null}}),c}(f),w=c.ReplaySubject=function(a){function b(a,b){return m(function(){b.dispose(),!a.isDisposed&&a.observers.splice(a.observers.indexOf(b),1)})}function c(a){var c=new l(this.scheduler,a),e=b(this,c);d(this),this._trim(this.scheduler.now()),this.observers.push(c);for(var f=0,g=this.q.length;g>f;f++)c.onNext(this.q[f].value);return this.hasError?c.onError(this.error):this.isStopped&&c.onCompleted(),c.ensureActive(),e}function f(b,d,e){this.bufferSize=null==b?Number.MAX_VALUE:b,this.windowSize=null==d?Number.MAX_VALUE:d,this.scheduler=e||p,this.q=[],this.observers=[],this.isStopped=!1,this.isDisposed=!1,this.hasError=!1,this.error=null,a.call(this,c)}return r(f,a),s(f.prototype,k.prototype,{hasObservers:function(){return this.observers.length>0},_trim:function(a){for(;this.q.length>this.bufferSize;)this.q.shift();for(;this.q.length>0&&a-this.q[0].interval>this.windowSize;)this.q.shift()},onNext:function(a){if(d(this),!this.isStopped){var b=this.scheduler.now();this.q.push({interval:b,value:a}),this._trim(b);for(var c=0,f=e(this.observers),g=f.length;g>c;c++){var h=f[c];h.onNext(a),h.ensureActive()}}},onError:function(a){if(d(this),!this.isStopped){this.isStopped=!0,this.error=a,this.hasError=!0;var b=this.scheduler.now();this._trim(b);for(var c=0,f=e(this.observers),g=f.length;g>c;c++){var h=f[c];h.onError(a),h.ensureActive()}this.observers.length=0}},onCompleted:function(){if(d(this),!this.isStopped){this.isStopped=!0;var a=this.scheduler.now();this._trim(a);for(var b=0,c=e(this.observers),f=c.length;f>b;b++){var g=c[b];g.onCompleted(),g.ensureActive()}this.observers.length=0}},dispose:function(){this.isDisposed=!0,this.observers=null}}),f}(f),x=c.ConnectableObservable=function(a){function b(b,c){var d,e=!1,f=b.asObservable();this.connect=function(){return e||(e=!0,d=new o(f.subscribe(c),m(function(){e=!1}))),d},a.call(this,function(a){return c.subscribe(a)})}return r(b,a),b.prototype.refCount=function(){var a,b=0,c=this;return new h(function(d){var e=1===++b,f=c.subscribe(d);return e&&(a=c.connect()),function(){f.dispose(),0===--b&&a.dispose()}})},b}(f);return c});
3
3
  //# sourceMappingURL=rx.binding.map
@@ -45,6 +45,7 @@
45
45
  observerCreate = Rx.Observer.create,
46
46
  addRef = Rx.internals.addRef,
47
47
  defaultComparer = Rx.internals.isEqual,
48
+ inherits = Rx.internals.inherits,
48
49
  noop = Rx.helpers.noop,
49
50
  identity = Rx.helpers.identity,
50
51
  isPromise = Rx.helpers.isPromise,
@@ -118,7 +119,7 @@
118
119
  // Hack check for valueOf
119
120
  var valueOf = obj.valueOf();
120
121
  if (typeof valueOf === 'number') { return numberHashFn(valueOf); }
121
- if (typeof obj === 'string') { return stringHashFn(valueOf); }
122
+ if (typeof valueOf === 'string') { return stringHashFn(valueOf); }
122
123
  }
123
124
  if (obj.hashCode) { return obj.hashCode(); }
124
125
 
@@ -534,7 +535,7 @@
534
535
  */
535
536
  observableProto.window = function (windowOpeningsOrClosingSelector, windowClosingSelector) {
536
537
  if (arguments.length === 1 && typeof arguments[0] !== 'function') {
537
- return observableWindowWithBounaries.call(this, windowOpeningsOrClosingSelector);
538
+ return observableWindowWithBoundaries.call(this, windowOpeningsOrClosingSelector);
538
539
  }
539
540
  return typeof windowOpeningsOrClosingSelector === 'function' ?
540
541
  observableWindowWithClosingSelector.call(this, windowOpeningsOrClosingSelector) :
@@ -547,7 +548,7 @@
547
548
  });
548
549
  }
549
550
 
550
- function observableWindowWithBounaries(windowBoundaries) {
551
+ function observableWindowWithBoundaries(windowBoundaries) {
551
552
  var source = this;
552
553
  return new AnonymousObservable(function (observer) {
553
554
  var win = new Subject(),
@@ -669,10 +670,9 @@
669
670
  * and the second triggers when the predicate returns false.
670
671
  */
671
672
  observableProto.partition = function(predicate, thisArg) {
672
- var published = this.publish().refCount();
673
673
  return [
674
- published.filter(predicate, thisArg),
675
- published.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
674
+ this.filter(predicate, thisArg),
675
+ this.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
676
676
  ];
677
677
  };
678
678
 
@@ -1,3 +1,3 @@
1
1
  /* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
2
- (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return a.groupJoin(this,b,o,function(a,b){return b})}function f(a){var b=this;return new q(function(c){var d=new m,e=new i,f=new j(e);return c.onNext(r(d,f)),e.add(b.subscribe(function(a){d.onNext(a)},function(a){d.onError(a),c.onError(a)},function(){d.onCompleted(),c.onCompleted()})),v(a)&&(a=w(a)),e.add(a.subscribe(function(){d.onCompleted(),d=new m,c.onNext(r(d,f))},function(a){d.onError(a),c.onError(a)},function(){d.onCompleted(),c.onCompleted()})),f},b)}function g(a){var b=this;return new q(function(c){function d(){var b;try{b=a()}catch(f){return void c.onError(f)}v(b)&&(b=w(b));var i=new k;e.setDisposable(i),i.setDisposable(b.take(1).subscribe(t,function(a){h.onError(a),c.onError(a)},function(){h.onCompleted(),h=new m,c.onNext(r(h,g)),d()}))}var e=new l,f=new i(e),g=new j(f),h=new m;return c.onNext(r(h,g)),f.add(b.subscribe(function(a){h.onNext(a)},function(a){h.onError(a),c.onError(a)},function(){h.onCompleted(),c.onCompleted()})),d(),g},b)}var h=c.Observable,i=c.CompositeDisposable,j=c.RefCountDisposable,k=c.SingleAssignmentDisposable,l=c.SerialDisposable,m=c.Subject,n=h.prototype,o=h.empty,p=h.never,q=c.AnonymousObservable,r=(c.Observer.create,c.internals.addRef),s=c.internals.isEqual,t=c.helpers.noop,u=c.helpers.identity,v=c.helpers.isPromise,w=h.fromPromise,x=function(){function a(a){if(0===(1&a))return 2===a;for(var b=Math.sqrt(a),c=3;b>=c;){if(a%c===0)return!1;c+=2}return!0}function b(b){var c,d,e;for(c=0;c<h.length;++c)if(d=h[c],d>=b)return d;for(e=1|b;e<h[h.length-1];){if(a(e))return e;e+=2}return b}function c(a){var b=757602046;if(!a.length)return b;for(var c=0,d=a.length;d>c;c++){var e=a.charCodeAt(c);b=(b<<5)-b+e,b&=b}return b}function e(a){var b=668265261;return a=61^a^a>>>16,a+=a<<3,a^=a>>>4,a*=b,a^=a>>>15}function f(){return{key:null,value:null,next:0,hashCode:0}}function g(a,b){if(0>a)throw new Error("out of range");a>0&&this._initialize(a),this.comparer=b||s,this.freeCount=0,this.size=0,this.freeList=-1}var h=[1,3,7,13,31,61,127,251,509,1021,2039,4093,8191,16381,32749,65521,131071,262139,524287,1048573,2097143,4194301,8388593,16777213,33554393,67108859,134217689,268435399,536870909,1073741789,2147483647],i="no such key",j="duplicate key",k=function(){var a=0;return function(b){if(null==b)throw new Error(i);if("string"==typeof b)return c(b);if("number"==typeof b)return e(b);if("boolean"==typeof b)return b===!0?1:0;if(b instanceof Date)return e(b.valueOf());if(b instanceof RegExp)return c(b.toString());if("function"==typeof b.valueOf){var d=b.valueOf();if("number"==typeof d)return e(d);if("string"==typeof b)return c(d)}if(b.hashCode)return b.hashCode();var f=17*a++;return b.hashCode=function(){return f},f}}(),l=g.prototype;return l._initialize=function(a){var c,d=b(a);for(this.buckets=new Array(d),this.entries=new Array(d),c=0;d>c;c++)this.buckets[c]=-1,this.entries[c]=f();this.freeList=-1},l.add=function(a,b){this._insert(a,b,!0)},l._insert=function(a,b,c){this.buckets||this._initialize(0);for(var d,e=2147483647&k(a),f=e%this.buckets.length,g=this.buckets[f];g>=0;g=this.entries[g].next)if(this.entries[g].hashCode===e&&this.comparer(this.entries[g].key,a)){if(c)throw new Error(j);return void(this.entries[g].value=b)}this.freeCount>0?(d=this.freeList,this.freeList=this.entries[d].next,--this.freeCount):(this.size===this.entries.length&&(this._resize(),f=e%this.buckets.length),d=this.size,++this.size),this.entries[d].hashCode=e,this.entries[d].next=this.buckets[f],this.entries[d].key=a,this.entries[d].value=b,this.buckets[f]=d},l._resize=function(){var a=b(2*this.size),c=new Array(a);for(e=0;e<c.length;++e)c[e]=-1;var d=new Array(a);for(e=0;e<this.size;++e)d[e]=this.entries[e];for(var e=this.size;a>e;++e)d[e]=f();for(var g=0;g<this.size;++g){var h=d[g].hashCode%a;d[g].next=c[h],c[h]=g}this.buckets=c,this.entries=d},l.remove=function(a){if(this.buckets)for(var b=2147483647&k(a),c=b%this.buckets.length,d=-1,e=this.buckets[c];e>=0;e=this.entries[e].next){if(this.entries[e].hashCode===b&&this.comparer(this.entries[e].key,a))return 0>d?this.buckets[c]=this.entries[e].next:this.entries[d].next=this.entries[e].next,this.entries[e].hashCode=-1,this.entries[e].next=this.freeList,this.entries[e].key=null,this.entries[e].value=null,this.freeList=e,++this.freeCount,!0;d=e}return!1},l.clear=function(){var a,b;if(!(this.size<=0)){for(a=0,b=this.buckets.length;b>a;++a)this.buckets[a]=-1;for(a=0;a<this.size;++a)this.entries[a]=f();this.freeList=-1,this.size=0}},l._findEntry=function(a){if(this.buckets)for(var b=2147483647&k(a),c=this.buckets[b%this.buckets.length];c>=0;c=this.entries[c].next)if(this.entries[c].hashCode===b&&this.comparer(this.entries[c].key,a))return c;return-1},l.count=function(){return this.size-this.freeCount},l.tryGetValue=function(a){var b=this._findEntry(a);return b>=0?this.entries[b].value:d},l.getValues=function(){var a=0,b=[];if(this.entries)for(var c=0;c<this.size;c++)this.entries[c].hashCode>=0&&(b[a++]=this.entries[c].value);return b},l.get=function(a){var b=this._findEntry(a);if(b>=0)return this.entries[b].value;throw new Error(i)},l.set=function(a,b){this._insert(a,b,!1)},l.containskey=function(a){return this._findEntry(a)>=0},g}();n.join=function(a,b,c,d){var e=this;return new q(function(f){var g=new i,h=!1,j=!1,l=0,m=0,n=new x,o=new x;return g.add(e.subscribe(function(a){var c=l++,e=new k;n.add(c,a),g.add(e);var i,j=function(){n.remove(c)&&0===n.count()&&h&&f.onCompleted(),g.remove(e)};try{i=b(a)}catch(m){return void f.onError(m)}e.setDisposable(i.take(1).subscribe(t,f.onError.bind(f),j)),o.getValues().forEach(function(b){var c;try{c=d(a,b)}catch(e){return void f.onError(e)}f.onNext(c)})},f.onError.bind(f),function(){h=!0,(j||0===n.count())&&f.onCompleted()})),g.add(a.subscribe(function(a){var b=m++,e=new k;o.add(b,a),g.add(e);var h,i=function(){o.remove(b)&&0===o.count()&&j&&f.onCompleted(),g.remove(e)};try{h=c(a)}catch(l){return void f.onError(l)}e.setDisposable(h.take(1).subscribe(t,f.onError.bind(f),i)),n.getValues().forEach(function(b){var c;try{c=d(b,a)}catch(e){return void f.onError(e)}f.onNext(c)})},f.onError.bind(f),function(){j=!0,(h||0===o.count())&&f.onCompleted()})),g},e)},n.groupJoin=function(a,b,c,d){var e=this;return new q(function(f){function g(a){return function(b){b.onError(a)}}var h=new i,l=new j(h),n=new x,o=new x,p=0,q=0;return h.add(e.subscribe(function(a){var c=new m,e=p++;n.add(e,c);var i;try{i=d(a,r(c,l))}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}f.onNext(i),o.getValues().forEach(function(a){c.onNext(a)});var q=new k;h.add(q);var s,u=function(){n.remove(e)&&c.onCompleted(),h.remove(q)};try{s=b(a)}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}q.setDisposable(s.take(1).subscribe(t,function(a){n.getValues().forEach(g(a)),f.onError(a)},u))},function(a){n.getValues().forEach(g(a)),f.onError(a)},f.onCompleted.bind(f))),h.add(a.subscribe(function(a){var b=q++;o.add(b,a);var d=new k;h.add(d);var e,i=function(){o.remove(b),h.remove(d)};try{e=c(a)}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}d.setDisposable(e.take(1).subscribe(t,function(a){n.getValues().forEach(g(a)),f.onError(a)},i)),n.getValues().forEach(function(b){b.onNext(a)})},function(a){n.getValues().forEach(g(a)),f.onError(a)})),l},e)},n.buffer=function(){return this.window.apply(this,arguments).selectMany(function(a){return a.toArray()})},n.window=function(a,b){return 1===arguments.length&&"function"!=typeof arguments[0]?f.call(this,a):"function"==typeof a?g.call(this,a):e.call(this,a,b)},n.pairwise=function(){var a=this;return new q(function(b){var c,d=!1;return a.subscribe(function(a){d?b.onNext([c,a]):d=!0,c=a},b.onError.bind(b),b.onCompleted.bind(b))},a)},n.partition=function(a,b){var c=this.publish().refCount();return[c.filter(a,b),c.filter(function(c,d,e){return!a.call(b,c,d,e)})]},n.groupBy=function(a,b,c){return this.groupByUntil(a,b,p,c)},n.groupByUntil=function(a,b,c,d){var e=this;return b||(b=u),d||(d=s),new q(function(f){function g(a){return function(b){b.onError(a)}}var h=new x(0,d),l=new i,n=new j(l);return l.add(e.subscribe(function(d){var e;try{e=a(d)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}var j=!1,o=h.tryGetValue(e);if(o||(o=new m,h.set(e,o),j=!0),j){var p=new y(e,o,n),q=new y(e,o);try{duration=c(q)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}f.onNext(p);var r=new k;l.add(r);var s=function(){h.remove(e)&&o.onCompleted(),l.remove(r)};r.setDisposable(duration.take(1).subscribe(t,function(a){h.getValues().forEach(g(a)),f.onError(a)},s))}var u;try{u=b(d)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}o.onNext(u)},function(a){h.getValues().forEach(g(a)),f.onError(a)},function(){h.getValues().forEach(function(a){a.onCompleted()}),f.onCompleted()})),n},e)};var y=function(a){function b(a){return this.underlyingObservable.subscribe(a)}function c(c,d,e){a.call(this,b),this.key=c,this.underlyingObservable=e?new q(function(a){return new i(e.getDisposable(),d.subscribe(a))}):d}return inherits(c,a),c}(h);return c});
2
+ (function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(a,b){return a.groupJoin(this,b,o,function(a,b){return b})}function f(a){var b=this;return new q(function(c){var d=new m,e=new i,f=new j(e);return c.onNext(r(d,f)),e.add(b.subscribe(function(a){d.onNext(a)},function(a){d.onError(a),c.onError(a)},function(){d.onCompleted(),c.onCompleted()})),w(a)&&(a=x(a)),e.add(a.subscribe(function(){d.onCompleted(),d=new m,c.onNext(r(d,f))},function(a){d.onError(a),c.onError(a)},function(){d.onCompleted(),c.onCompleted()})),f},b)}function g(a){var b=this;return new q(function(c){function d(){var b;try{b=a()}catch(f){return void c.onError(f)}w(b)&&(b=x(b));var i=new k;e.setDisposable(i),i.setDisposable(b.take(1).subscribe(u,function(a){h.onError(a),c.onError(a)},function(){h.onCompleted(),h=new m,c.onNext(r(h,g)),d()}))}var e=new l,f=new i(e),g=new j(f),h=new m;return c.onNext(r(h,g)),f.add(b.subscribe(function(a){h.onNext(a)},function(a){h.onError(a),c.onError(a)},function(){h.onCompleted(),c.onCompleted()})),d(),g},b)}var h=c.Observable,i=c.CompositeDisposable,j=c.RefCountDisposable,k=c.SingleAssignmentDisposable,l=c.SerialDisposable,m=c.Subject,n=h.prototype,o=h.empty,p=h.never,q=c.AnonymousObservable,r=(c.Observer.create,c.internals.addRef),s=c.internals.isEqual,t=c.internals.inherits,u=c.helpers.noop,v=c.helpers.identity,w=c.helpers.isPromise,x=h.fromPromise,y=function(){function a(a){if(0===(1&a))return 2===a;for(var b=Math.sqrt(a),c=3;b>=c;){if(a%c===0)return!1;c+=2}return!0}function b(b){var c,d,e;for(c=0;c<h.length;++c)if(d=h[c],d>=b)return d;for(e=1|b;e<h[h.length-1];){if(a(e))return e;e+=2}return b}function c(a){var b=757602046;if(!a.length)return b;for(var c=0,d=a.length;d>c;c++){var e=a.charCodeAt(c);b=(b<<5)-b+e,b&=b}return b}function e(a){var b=668265261;return a=61^a^a>>>16,a+=a<<3,a^=a>>>4,a*=b,a^=a>>>15}function f(){return{key:null,value:null,next:0,hashCode:0}}function g(a,b){if(0>a)throw new Error("out of range");a>0&&this._initialize(a),this.comparer=b||s,this.freeCount=0,this.size=0,this.freeList=-1}var h=[1,3,7,13,31,61,127,251,509,1021,2039,4093,8191,16381,32749,65521,131071,262139,524287,1048573,2097143,4194301,8388593,16777213,33554393,67108859,134217689,268435399,536870909,1073741789,2147483647],i="no such key",j="duplicate key",k=function(){var a=0;return function(b){if(null==b)throw new Error(i);if("string"==typeof b)return c(b);if("number"==typeof b)return e(b);if("boolean"==typeof b)return b===!0?1:0;if(b instanceof Date)return e(b.valueOf());if(b instanceof RegExp)return c(b.toString());if("function"==typeof b.valueOf){var d=b.valueOf();if("number"==typeof d)return e(d);if("string"==typeof d)return c(d)}if(b.hashCode)return b.hashCode();var f=17*a++;return b.hashCode=function(){return f},f}}(),l=g.prototype;return l._initialize=function(a){var c,d=b(a);for(this.buckets=new Array(d),this.entries=new Array(d),c=0;d>c;c++)this.buckets[c]=-1,this.entries[c]=f();this.freeList=-1},l.add=function(a,b){this._insert(a,b,!0)},l._insert=function(a,b,c){this.buckets||this._initialize(0);for(var d,e=2147483647&k(a),f=e%this.buckets.length,g=this.buckets[f];g>=0;g=this.entries[g].next)if(this.entries[g].hashCode===e&&this.comparer(this.entries[g].key,a)){if(c)throw new Error(j);return void(this.entries[g].value=b)}this.freeCount>0?(d=this.freeList,this.freeList=this.entries[d].next,--this.freeCount):(this.size===this.entries.length&&(this._resize(),f=e%this.buckets.length),d=this.size,++this.size),this.entries[d].hashCode=e,this.entries[d].next=this.buckets[f],this.entries[d].key=a,this.entries[d].value=b,this.buckets[f]=d},l._resize=function(){var a=b(2*this.size),c=new Array(a);for(e=0;e<c.length;++e)c[e]=-1;var d=new Array(a);for(e=0;e<this.size;++e)d[e]=this.entries[e];for(var e=this.size;a>e;++e)d[e]=f();for(var g=0;g<this.size;++g){var h=d[g].hashCode%a;d[g].next=c[h],c[h]=g}this.buckets=c,this.entries=d},l.remove=function(a){if(this.buckets)for(var b=2147483647&k(a),c=b%this.buckets.length,d=-1,e=this.buckets[c];e>=0;e=this.entries[e].next){if(this.entries[e].hashCode===b&&this.comparer(this.entries[e].key,a))return 0>d?this.buckets[c]=this.entries[e].next:this.entries[d].next=this.entries[e].next,this.entries[e].hashCode=-1,this.entries[e].next=this.freeList,this.entries[e].key=null,this.entries[e].value=null,this.freeList=e,++this.freeCount,!0;d=e}return!1},l.clear=function(){var a,b;if(!(this.size<=0)){for(a=0,b=this.buckets.length;b>a;++a)this.buckets[a]=-1;for(a=0;a<this.size;++a)this.entries[a]=f();this.freeList=-1,this.size=0}},l._findEntry=function(a){if(this.buckets)for(var b=2147483647&k(a),c=this.buckets[b%this.buckets.length];c>=0;c=this.entries[c].next)if(this.entries[c].hashCode===b&&this.comparer(this.entries[c].key,a))return c;return-1},l.count=function(){return this.size-this.freeCount},l.tryGetValue=function(a){var b=this._findEntry(a);return b>=0?this.entries[b].value:d},l.getValues=function(){var a=0,b=[];if(this.entries)for(var c=0;c<this.size;c++)this.entries[c].hashCode>=0&&(b[a++]=this.entries[c].value);return b},l.get=function(a){var b=this._findEntry(a);if(b>=0)return this.entries[b].value;throw new Error(i)},l.set=function(a,b){this._insert(a,b,!1)},l.containskey=function(a){return this._findEntry(a)>=0},g}();n.join=function(a,b,c,d){var e=this;return new q(function(f){var g=new i,h=!1,j=!1,l=0,m=0,n=new y,o=new y;return g.add(e.subscribe(function(a){var c=l++,e=new k;n.add(c,a),g.add(e);var i,j=function(){n.remove(c)&&0===n.count()&&h&&f.onCompleted(),g.remove(e)};try{i=b(a)}catch(m){return void f.onError(m)}e.setDisposable(i.take(1).subscribe(u,f.onError.bind(f),j)),o.getValues().forEach(function(b){var c;try{c=d(a,b)}catch(e){return void f.onError(e)}f.onNext(c)})},f.onError.bind(f),function(){h=!0,(j||0===n.count())&&f.onCompleted()})),g.add(a.subscribe(function(a){var b=m++,e=new k;o.add(b,a),g.add(e);var h,i=function(){o.remove(b)&&0===o.count()&&j&&f.onCompleted(),g.remove(e)};try{h=c(a)}catch(l){return void f.onError(l)}e.setDisposable(h.take(1).subscribe(u,f.onError.bind(f),i)),n.getValues().forEach(function(b){var c;try{c=d(b,a)}catch(e){return void f.onError(e)}f.onNext(c)})},f.onError.bind(f),function(){j=!0,(h||0===o.count())&&f.onCompleted()})),g},e)},n.groupJoin=function(a,b,c,d){var e=this;return new q(function(f){function g(a){return function(b){b.onError(a)}}var h=new i,l=new j(h),n=new y,o=new y,p=0,q=0;return h.add(e.subscribe(function(a){var c=new m,e=p++;n.add(e,c);var i;try{i=d(a,r(c,l))}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}f.onNext(i),o.getValues().forEach(function(a){c.onNext(a)});var q=new k;h.add(q);var s,t=function(){n.remove(e)&&c.onCompleted(),h.remove(q)};try{s=b(a)}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}q.setDisposable(s.take(1).subscribe(u,function(a){n.getValues().forEach(g(a)),f.onError(a)},t))},function(a){n.getValues().forEach(g(a)),f.onError(a)},f.onCompleted.bind(f))),h.add(a.subscribe(function(a){var b=q++;o.add(b,a);var d=new k;h.add(d);var e,i=function(){o.remove(b),h.remove(d)};try{e=c(a)}catch(j){return n.getValues().forEach(g(j)),void f.onError(j)}d.setDisposable(e.take(1).subscribe(u,function(a){n.getValues().forEach(g(a)),f.onError(a)},i)),n.getValues().forEach(function(b){b.onNext(a)})},function(a){n.getValues().forEach(g(a)),f.onError(a)})),l},e)},n.buffer=function(){return this.window.apply(this,arguments).selectMany(function(a){return a.toArray()})},n.window=function(a,b){return 1===arguments.length&&"function"!=typeof arguments[0]?f.call(this,a):"function"==typeof a?g.call(this,a):e.call(this,a,b)},n.pairwise=function(){var a=this;return new q(function(b){var c,d=!1;return a.subscribe(function(a){d?b.onNext([c,a]):d=!0,c=a},b.onError.bind(b),b.onCompleted.bind(b))},a)},n.partition=function(a,b){return[this.filter(a,b),this.filter(function(c,d,e){return!a.call(b,c,d,e)})]},n.groupBy=function(a,b,c){return this.groupByUntil(a,b,p,c)},n.groupByUntil=function(a,b,c,d){var e=this;return b||(b=v),d||(d=s),new q(function(f){function g(a){return function(b){b.onError(a)}}var h=new y(0,d),l=new i,n=new j(l);return l.add(e.subscribe(function(d){var e;try{e=a(d)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}var j=!1,o=h.tryGetValue(e);if(o||(o=new m,h.set(e,o),j=!0),j){var p=new z(e,o,n),q=new z(e,o);try{duration=c(q)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}f.onNext(p);var r=new k;l.add(r);var s=function(){h.remove(e)&&o.onCompleted(),l.remove(r)};r.setDisposable(duration.take(1).subscribe(u,function(a){h.getValues().forEach(g(a)),f.onError(a)},s))}var t;try{t=b(d)}catch(i){return h.getValues().forEach(g(i)),void f.onError(i)}o.onNext(t)},function(a){h.getValues().forEach(g(a)),f.onError(a)},function(){h.getValues().forEach(function(a){a.onCompleted()}),f.onCompleted()})),n},e)};var z=function(a){function b(a){return this.underlyingObservable.subscribe(a)}function c(c,d,e){a.call(this,b),this.key=c,this.underlyingObservable=e?new q(function(a){return new i(e.getDisposable(),d.subscribe(a))}):d}return t(c,a),c}(h);return c});
3
3
  //# sourceMappingURL=rx.coincidence.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
 
904
- /**
905
- * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
906
- */
907
- var RefCountDisposable = Rx.RefCountDisposable = (function () {
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
+ }
908
979
 
909
- function InnerDisposable(disposable) {
910
- this.disposable = disposable;
911
- this.disposable.count++;
912
- this.isInnerDisposed = false;
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();
913
987
  }
988
+ }
989
+ };
914
990
 
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
- };
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
+ }
927
1002
 
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;
1003
+ /**
1004
+ * Disposes the underlying disposable only when all dependent disposables have been disposed
1005
+ */
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();
938
1012
  }
1013
+ }
1014
+ };
939
1015
 
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,33 +2584,87 @@ 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 () {
2424
- return new StringIterator(this._s);
2425
- };
2601
+ return FromObservable;
2602
+ }(ObservableBase));
2426
2603
 
2427
- function StringIterator(str) {
2428
- this._s = s;
2429
- this._l = s.length;
2430
- this._i = 0;
2431
- }
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 () {
2653
+ return new StringIterator(this._s);
2654
+ };
2655
+
2656
+ function StringIterator(str) {
2657
+ this._s = s;
2658
+ this._l = s.length;
2659
+ this._i = 0;
2660
+ }
2432
2661
 
2433
2662
  StringIterator.prototype[$iterator$] = function () {
2434
2663
  return this;
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
  /**
@@ -2634,55 +2848,45 @@ if (!Array.prototype.forEach) {
2634
2848
  };
2635
2849
 
2636
2850
  function observableOf (scheduler, array) {
2637
- isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2638
- return new AnonymousObservable(function (observer) {
2639
- var count = 0, len = array.length;
2640
- return scheduler.scheduleRecursive(function (self) {
2641
- if (count < len) {
2642
- observer.onNext(array[count++]);
2643
- self();
2644
- } else {
2645
- observer.onCompleted();
2646
- }
2647
- });
2648
- });
2851
+ return new FromArrayObservable(array, scheduler);
2649
2852
  }
2650
2853
 
2651
2854
  /**
2652
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2653
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2654
- */
2855
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2856
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2857
+ */
2655
2858
  Observable.of = function () {
2656
- return observableOf(null, arguments);
2859
+ var len = arguments.length, args = new Array(len);
2860
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2861
+ return new FromArrayObservable(args);
2657
2862
  };
2658
2863
 
2659
2864
  /**
2660
- * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2661
- * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2662
- * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2663
- */
2865
+ * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2866
+ * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2867
+ * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2868
+ */
2664
2869
  Observable.ofWithScheduler = function (scheduler) {
2665
- return observableOf(scheduler, slice.call(arguments, 1));
2870
+ var len = arguments.length, args = new Array(len - 1);
2871
+ for(var i = 1; i < len; i++) { args[i - 1] = arguments[i]; }
2872
+ return new FromArrayObservable(args, scheduler);
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();
2951
-
2952
- if (Array.isArray(args[0])) {
2953
- args = args[0];
2954
- }
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]);
2955
3207
 
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,53 +4342,112 @@ 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
 
4355
+ var MapObservable = (function (__super__) {
4356
+ inherits(MapObservable, __super__);
4357
+
4358
+ function MapObservable(source, selector, thisArg) {
4359
+ this.source = source;
4360
+ this.selector = bindCallback(selector, thisArg, 3);
4361
+ __super__.call(this);
4362
+ }
4363
+
4364
+ MapObservable.prototype.internalMap = function (selector, thisArg) {
4365
+ var self = this;
4366
+ return new MapObservable(this.source, function (x, i, o) { return selector(self.selector(x, i, o), i, o); }, thisArg)
4367
+ };
4368
+
4369
+ MapObservable.prototype.subscribeCore = function (observer) {
4370
+ return this.source.subscribe(new MapObserver(observer, this.selector, this));
4371
+ };
4372
+
4373
+ return MapObservable;
4374
+
4375
+ }(ObservableBase));
4376
+
4377
+ function MapObserver(observer, selector, source) {
4378
+ this.observer = observer;
4379
+ this.selector = selector;
4380
+ this.source = source;
4381
+ this.i = 0;
4382
+ this.isStopped = false;
4383
+ }
4384
+
4385
+ MapObserver.prototype.onNext = function(x) {
4386
+ if (this.isStopped) { return; }
4387
+ try {
4388
+ var result = this.selector(x, this.i++, this.source);
4389
+ } catch (e) {
4390
+ return this.observer.onError(e);
4391
+ }
4392
+ this.observer.onNext(result);
4393
+ };
4394
+ MapObserver.prototype.onError = function (e) {
4395
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4396
+ };
4397
+ MapObserver.prototype.onCompleted = function () {
4398
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4399
+ };
4400
+ MapObserver.prototype.dispose = function() { this.isStopped = true; };
4401
+ MapObserver.prototype.fail = function (e) {
4402
+ if (!this.isStopped) {
4403
+ this.isStopped = true;
4404
+ this.observer.onError(e);
4405
+ return true;
4406
+ }
4407
+
4408
+ return false;
4409
+ };
4410
+
4036
4411
  /**
4037
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
4038
- * @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.
4039
- * @param {Any} [thisArg] Object to use as this when executing callback.
4040
- * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
4041
- */
4042
- observableProto.select = observableProto.map = function (selector, thisArg) {
4043
- var selectorFn = isFunction(selector) ? selector : function () { return selector; },
4044
- source = this;
4045
- return new AnonymousObservable(function (observer) {
4046
- var count = 0;
4047
- return source.subscribe(function (value) {
4048
- var result;
4049
- try {
4050
- result = selectorFn.call(thisArg, value, count++, source);
4051
- } catch (e) {
4052
- observer.onError(e);
4053
- return;
4054
- }
4055
- observer.onNext(result);
4056
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4057
- }, source);
4412
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
4413
+ * @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.
4414
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4415
+ * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
4416
+ */
4417
+ observableProto.map = observableProto.select = function (selector, thisArg) {
4418
+ var selectorFn = typeof selector === 'function' ? selector : function () { return selector; };
4419
+ return this instanceof MapObservable ?
4420
+ this.internalMap(selectorFn, thisArg) :
4421
+ new MapObservable(this, selectorFn, thisArg);
4058
4422
  };
4059
4423
 
4060
4424
  /**
4061
- * Retrieves the value of a specified property from all elements in the Observable sequence.
4062
- * @param {String} prop The property to pluck.
4425
+ * Retrieves the value of a specified nested property from all elements in
4426
+ * the Observable sequence.
4427
+ * @param {Arguments} arguments The nested properties to pluck.
4063
4428
  * @returns {Observable} Returns a new Observable sequence of property values.
4064
4429
  */
4065
- observableProto.pluck = function (prop) {
4066
- return this.map(function (x) { return x[prop]; });
4430
+ observableProto.pluck = function () {
4431
+ var args = arguments, len = arguments.length;
4432
+ if (len === 0) { throw new Error('List of properties cannot be empty.'); }
4433
+ return this.map(function (x) {
4434
+ var currentProp = x;
4435
+ for (var i = 0; i < len; i++) {
4436
+ var p = currentProp[args[i]];
4437
+ if (typeof p !== 'undefined') {
4438
+ currentProp = p;
4439
+ } else {
4440
+ return undefined;
4441
+ }
4442
+ }
4443
+ return currentProp;
4444
+ });
4067
4445
  };
4068
4446
 
4069
4447
  function flatMap(source, selector, thisArg) {
4448
+ var selectorFunc = bindCallback(selector, thisArg, 3);
4070
4449
  return source.map(function (x, i) {
4071
- var result = selector.call(thisArg, x, i, source);
4450
+ var result = selectorFunc(x, i, source);
4072
4451
  isPromise(result) && (result = observableFromPromise(result));
4073
4452
  (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
4074
4453
  return result;
@@ -4183,15 +4562,15 @@ if (!Array.prototype.forEach) {
4183
4562
  observableProto.skip = function (count) {
4184
4563
  if (count < 0) { throw new Error(argumentOutOfRange); }
4185
4564
  var source = this;
4186
- return new AnonymousObservable(function (observer) {
4565
+ return new AnonymousObservable(function (o) {
4187
4566
  var remaining = count;
4188
4567
  return source.subscribe(function (x) {
4189
4568
  if (remaining <= 0) {
4190
- observer.onNext(x);
4569
+ o.onNext(x);
4191
4570
  } else {
4192
4571
  remaining--;
4193
4572
  }
4194
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4573
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4195
4574
  }, source);
4196
4575
  };
4197
4576
 
@@ -4206,20 +4585,21 @@ if (!Array.prototype.forEach) {
4206
4585
  * @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.
4207
4586
  */
4208
4587
  observableProto.skipWhile = function (predicate, thisArg) {
4209
- var source = this;
4210
- return new AnonymousObservable(function (observer) {
4588
+ var source = this,
4589
+ callback = bindCallback(predicate, thisArg, 3);
4590
+ return new AnonymousObservable(function (o) {
4211
4591
  var i = 0, running = false;
4212
4592
  return source.subscribe(function (x) {
4213
4593
  if (!running) {
4214
4594
  try {
4215
- running = !predicate.call(thisArg, x, i++, source);
4595
+ running = !callback(x, i++, source);
4216
4596
  } catch (e) {
4217
- observer.onError(e);
4597
+ o.onError(e);
4218
4598
  return;
4219
4599
  }
4220
4600
  }
4221
- running && observer.onNext(x);
4222
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4601
+ running && o.onNext(x);
4602
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4223
4603
  }, source);
4224
4604
  };
4225
4605
 
@@ -4236,14 +4616,14 @@ if (!Array.prototype.forEach) {
4236
4616
  if (count < 0) { throw new RangeError(argumentOutOfRange); }
4237
4617
  if (count === 0) { return observableEmpty(scheduler); }
4238
4618
  var source = this;
4239
- return new AnonymousObservable(function (observer) {
4619
+ return new AnonymousObservable(function (o) {
4240
4620
  var remaining = count;
4241
4621
  return source.subscribe(function (x) {
4242
4622
  if (remaining-- > 0) {
4243
- observer.onNext(x);
4244
- remaining === 0 && observer.onCompleted();
4623
+ o.onNext(x);
4624
+ remaining === 0 && o.onCompleted();
4245
4625
  }
4246
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4626
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4247
4627
  }, source);
4248
4628
  };
4249
4629
 
@@ -4255,52 +4635,92 @@ if (!Array.prototype.forEach) {
4255
4635
  * @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.
4256
4636
  */
4257
4637
  observableProto.takeWhile = function (predicate, thisArg) {
4258
- var source = this;
4259
- return new AnonymousObservable(function (observer) {
4638
+ var source = this,
4639
+ callback = bindCallback(predicate, thisArg, 3);
4640
+ return new AnonymousObservable(function (o) {
4260
4641
  var i = 0, running = true;
4261
4642
  return source.subscribe(function (x) {
4262
4643
  if (running) {
4263
4644
  try {
4264
- running = predicate.call(thisArg, x, i++, source);
4645
+ running = callback(x, i++, source);
4265
4646
  } catch (e) {
4266
- observer.onError(e);
4647
+ o.onError(e);
4267
4648
  return;
4268
4649
  }
4269
4650
  if (running) {
4270
- observer.onNext(x);
4651
+ o.onNext(x);
4271
4652
  } else {
4272
- observer.onCompleted();
4653
+ o.onCompleted();
4273
4654
  }
4274
4655
  }
4275
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4656
+ }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4276
4657
  }, source);
4277
4658
  };
4278
4659
 
4660
+ var FilterObservable = (function (__super__) {
4661
+ inherits(FilterObservable, __super__);
4662
+
4663
+ function FilterObservable(source, predicate, thisArg) {
4664
+ this.source = source;
4665
+ this.predicate = bindCallback(predicate, thisArg, 3);
4666
+ __super__.call(this);
4667
+ }
4668
+
4669
+ FilterObservable.prototype.subscribeCore = function (observer) {
4670
+ return this.source.subscribe(new FilterObserver(observer, this.predicate, this));
4671
+ };
4672
+
4673
+ FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
4674
+ var self = this;
4675
+ return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate(x, i, o); }, thisArg);
4676
+ };
4677
+
4678
+ return FilterObservable;
4679
+
4680
+ }(ObservableBase));
4681
+
4682
+ function FilterObserver(observer, predicate, source) {
4683
+ this.observer = observer;
4684
+ this.predicate = predicate;
4685
+ this.source = source;
4686
+ this.i = 0;
4687
+ this.isStopped = false;
4688
+ }
4689
+
4690
+ FilterObserver.prototype.onNext = function(x) {
4691
+ if (this.isStopped) { return; }
4692
+ try {
4693
+ var shouldYield = this.predicate(x, this.i++, this.source);
4694
+ } catch (e) {
4695
+ return this.observer.onError(e);
4696
+ }
4697
+ shouldYield && this.observer.onNext(x);
4698
+ };
4699
+ FilterObserver.prototype.onError = function (e) {
4700
+ if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4701
+ };
4702
+ FilterObserver.prototype.onCompleted = function () {
4703
+ if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4704
+ };
4705
+ FilterObserver.prototype.dispose = function() { this.isStopped = true; };
4706
+ FilterObserver.prototype.fail = function (e) {
4707
+ if (!this.isStopped) {
4708
+ this.isStopped = true;
4709
+ this.observer.onError(e);
4710
+ return true;
4711
+ }
4712
+ return false;
4713
+ };
4714
+
4279
4715
  /**
4280
- * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4281
- *
4282
- * @example
4283
- * var res = source.where(function (value) { return value < 10; });
4284
- * var res = source.where(function (value, index) { return value < 10 || index < 10; });
4285
- * @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.
4286
- * @param {Any} [thisArg] Object to use as this when executing callback.
4287
- * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4288
- */
4289
- observableProto.where = observableProto.filter = function (predicate, thisArg) {
4290
- var source = this;
4291
- return new AnonymousObservable(function (observer) {
4292
- var count = 0;
4293
- return source.subscribe(function (value) {
4294
- var shouldRun;
4295
- try {
4296
- shouldRun = predicate.call(thisArg, value, count++, source);
4297
- } catch (e) {
4298
- observer.onError(e);
4299
- return;
4300
- }
4301
- shouldRun && observer.onNext(value);
4302
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4303
- }, source);
4716
+ * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4717
+ * @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.
4718
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4719
+ * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4720
+ */
4721
+ observableProto.filter = observableProto.where = function (predicate, thisArg) {
4722
+ return this instanceof FilterObservable ? this.internalFilter(predicate, thisArg) :
4723
+ new FilterObservable(this, predicate, thisArg);
4304
4724
  };
4305
4725
 
4306
4726
  /**
@@ -4353,31 +4773,29 @@ if (!Array.prototype.forEach) {
4353
4773
  disposableEmpty;
4354
4774
  }
4355
4775
 
4776
+ function setDisposable(s, state) {
4777
+ var ado = state[0], subscribe = state[1];
4778
+ try {
4779
+ ado.setDisposable(fixSubscriber(subscribe(ado)));
4780
+ } catch (e) {
4781
+ if (!ado.fail(e)) { throw e; }
4782
+ }
4783
+ }
4784
+
4356
4785
  function AnonymousObservable(subscribe, parent) {
4357
4786
  this.source = parent;
4358
- if (!(this instanceof AnonymousObservable)) {
4359
- return new AnonymousObservable(subscribe);
4360
- }
4361
4787
 
4362
4788
  function s(observer) {
4363
- var setDisposable = function () {
4364
- try {
4365
- autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4366
- } catch (e) {
4367
- if (!autoDetachObserver.fail(e)) {
4368
- throw e;
4369
- }
4370
- }
4371
- };
4372
4789
 
4373
- var autoDetachObserver = new AutoDetachObserver(observer);
4790
+ var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
4791
+
4374
4792
  if (currentThreadScheduler.scheduleRequired()) {
4375
- currentThreadScheduler.schedule(setDisposable);
4793
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
4376
4794
  } else {
4377
- setDisposable();
4795
+ setDisposable(null, state);
4378
4796
  }
4379
4797
 
4380
- return autoDetachObserver;
4798
+ return ado;
4381
4799
  }
4382
4800
 
4383
4801
  __super__.call(this, s);
@@ -4404,7 +4822,7 @@ if (!Array.prototype.forEach) {
4404
4822
  this.observer.onNext(value);
4405
4823
  noError = true;
4406
4824
  } catch (e) {
4407
- throw e;
4825
+ return thrower(e);
4408
4826
  } finally {
4409
4827
  !noError && this.dispose();
4410
4828
  }
@@ -4414,7 +4832,7 @@ if (!Array.prototype.forEach) {
4414
4832
  try {
4415
4833
  this.observer.onError(err);
4416
4834
  } catch (e) {
4417
- throw e;
4835
+ return thrower(e);
4418
4836
  } finally {
4419
4837
  this.dispose();
4420
4838
  }
@@ -4424,7 +4842,7 @@ if (!Array.prototype.forEach) {
4424
4842
  try {
4425
4843
  this.observer.onCompleted();
4426
4844
  } catch (e) {
4427
- throw e;
4845
+ return thrower(e);
4428
4846
  } finally {
4429
4847
  this.dispose();
4430
4848
  }
@@ -4441,130 +4859,121 @@ if (!Array.prototype.forEach) {
4441
4859
  return AutoDetachObserver;
4442
4860
  }(AbstractObserver));
4443
4861
 
4444
- /** @private */
4445
- var InnerSubscription = function (subject, observer) {
4446
- this.subject = subject;
4447
- this.observer = observer;
4448
- };
4862
+ var InnerSubscription = function (subject, observer) {
4863
+ this.subject = subject;
4864
+ this.observer = observer;
4865
+ };
4449
4866
 
4450
- /**
4451
- * @private
4452
- * @memberOf InnerSubscription
4453
- */
4454
- InnerSubscription.prototype.dispose = function () {
4455
- if (!this.subject.isDisposed && this.observer !== null) {
4456
- var idx = this.subject.observers.indexOf(this.observer);
4457
- this.subject.observers.splice(idx, 1);
4458
- this.observer = null;
4459
- }
4460
- };
4867
+ InnerSubscription.prototype.dispose = function () {
4868
+ if (!this.subject.isDisposed && this.observer !== null) {
4869
+ var idx = this.subject.observers.indexOf(this.observer);
4870
+ this.subject.observers.splice(idx, 1);
4871
+ this.observer = null;
4872
+ }
4873
+ };
4874
+
4875
+ /**
4876
+ * Represents an object that is both an observable sequence as well as an observer.
4877
+ * Each notification is broadcasted to all subscribed observers.
4878
+ */
4879
+ var Subject = Rx.Subject = (function (__super__) {
4880
+ function subscribe(observer) {
4881
+ checkDisposed(this);
4882
+ if (!this.isStopped) {
4883
+ this.observers.push(observer);
4884
+ return new InnerSubscription(this, observer);
4885
+ }
4886
+ if (this.hasError) {
4887
+ observer.onError(this.error);
4888
+ return disposableEmpty;
4889
+ }
4890
+ observer.onCompleted();
4891
+ return disposableEmpty;
4892
+ }
4893
+
4894
+ inherits(Subject, __super__);
4461
4895
 
4462
4896
  /**
4463
- * Represents an object that is both an observable sequence as well as an observer.
4464
- * Each notification is broadcasted to all subscribed observers.
4897
+ * Creates a subject.
4465
4898
  */
4466
- var Subject = Rx.Subject = (function (_super) {
4467
- function subscribe(observer) {
4468
- checkDisposed.call(this);
4469
- if (!this.isStopped) {
4470
- this.observers.push(observer);
4471
- return new InnerSubscription(this, observer);
4472
- }
4473
- if (this.exception) {
4474
- observer.onError(this.exception);
4475
- return disposableEmpty;
4476
- }
4477
- observer.onCompleted();
4478
- return disposableEmpty;
4479
- }
4899
+ function Subject() {
4900
+ __super__.call(this, subscribe);
4901
+ this.isDisposed = false,
4902
+ this.isStopped = false,
4903
+ this.observers = [];
4904
+ this.hasError = false;
4905
+ }
4906
+
4907
+ addProperties(Subject.prototype, Observer.prototype, {
4908
+ /**
4909
+ * Indicates whether the subject has observers subscribed to it.
4910
+ * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4911
+ */
4912
+ hasObservers: function () { return this.observers.length > 0; },
4913
+ /**
4914
+ * Notifies all subscribed observers about the end of the sequence.
4915
+ */
4916
+ onCompleted: function () {
4917
+ checkDisposed(this);
4918
+ if (!this.isStopped) {
4919
+ this.isStopped = true;
4920
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4921
+ os[i].onCompleted();
4922
+ }
4480
4923
 
4481
- inherits(Subject, _super);
4482
-
4483
- /**
4484
- * Creates a subject.
4485
- * @constructor
4486
- */
4487
- function Subject() {
4488
- _super.call(this, subscribe);
4489
- this.isDisposed = false,
4490
- this.isStopped = false,
4491
- this.observers = [];
4924
+ this.observers.length = 0;
4492
4925
  }
4926
+ },
4927
+ /**
4928
+ * Notifies all subscribed observers about the exception.
4929
+ * @param {Mixed} error The exception to send to all observers.
4930
+ */
4931
+ onError: function (error) {
4932
+ checkDisposed(this);
4933
+ if (!this.isStopped) {
4934
+ this.isStopped = true;
4935
+ this.error = error;
4936
+ this.hasError = true;
4937
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4938
+ os[i].onError(error);
4939
+ }
4493
4940
 
4494
- addProperties(Subject.prototype, Observer, {
4495
- /**
4496
- * Indicates whether the subject has observers subscribed to it.
4497
- * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4498
- */
4499
- hasObservers: function () {
4500
- return this.observers.length > 0;
4501
- },
4502
- /**
4503
- * Notifies all subscribed observers about the end of the sequence.
4504
- */
4505
- onCompleted: function () {
4506
- checkDisposed.call(this);
4507
- if (!this.isStopped) {
4508
- var os = this.observers.slice(0);
4509
- this.isStopped = true;
4510
- for (var i = 0, len = os.length; i < len; i++) {
4511
- os[i].onCompleted();
4512
- }
4513
-
4514
- this.observers = [];
4515
- }
4516
- },
4517
- /**
4518
- * Notifies all subscribed observers about the exception.
4519
- * @param {Mixed} error The exception to send to all observers.
4520
- */
4521
- onError: function (exception) {
4522
- checkDisposed.call(this);
4523
- if (!this.isStopped) {
4524
- var os = this.observers.slice(0);
4525
- this.isStopped = true;
4526
- this.exception = exception;
4527
- for (var i = 0, len = os.length; i < len; i++) {
4528
- os[i].onError(exception);
4529
- }
4530
-
4531
- this.observers = [];
4532
- }
4533
- },
4534
- /**
4535
- * Notifies all subscribed observers about the arrival of the specified element in the sequence.
4536
- * @param {Mixed} value The value to send to all observers.
4537
- */
4538
- onNext: function (value) {
4539
- checkDisposed.call(this);
4540
- if (!this.isStopped) {
4541
- var os = this.observers.slice(0);
4542
- for (var i = 0, len = os.length; i < len; i++) {
4543
- os[i].onNext(value);
4544
- }
4545
- }
4546
- },
4547
- /**
4548
- * Unsubscribe all observers and release resources.
4549
- */
4550
- dispose: function () {
4551
- this.isDisposed = true;
4552
- this.observers = null;
4553
- }
4554
- });
4941
+ this.observers.length = 0;
4942
+ }
4943
+ },
4944
+ /**
4945
+ * Notifies all subscribed observers about the arrival of the specified element in the sequence.
4946
+ * @param {Mixed} value The value to send to all observers.
4947
+ */
4948
+ onNext: function (value) {
4949
+ checkDisposed(this);
4950
+ if (!this.isStopped) {
4951
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4952
+ os[i].onNext(value);
4953
+ }
4954
+ }
4955
+ },
4956
+ /**
4957
+ * Unsubscribe all observers and release resources.
4958
+ */
4959
+ dispose: function () {
4960
+ this.isDisposed = true;
4961
+ this.observers = null;
4962
+ }
4963
+ });
4555
4964
 
4556
- /**
4557
- * Creates a subject from the specified observer and observable.
4558
- * @param {Observer} observer The observer used to send messages to the subject.
4559
- * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
4560
- * @returns {Subject} Subject implemented using the given observer and observable.
4561
- */
4562
- Subject.create = function (observer, observable) {
4563
- return new AnonymousSubject(observer, observable);
4564
- };
4965
+ /**
4966
+ * Creates a subject from the specified observer and observable.
4967
+ * @param {Observer} observer The observer used to send messages to the subject.
4968
+ * @param {Observable} observable The observable used to subscribe to messages sent from the subject.
4969
+ * @returns {Subject} Subject implemented using the given observer and observable.
4970
+ */
4971
+ Subject.create = function (observer, observable) {
4972
+ return new AnonymousSubject(observer, observable);
4973
+ };
4565
4974
 
4566
- return Subject;
4567
- }(Observable));
4975
+ return Subject;
4976
+ }(Observable));
4568
4977
 
4569
4978
  /**
4570
4979
  * Represents the result of an asynchronous operation.
@@ -4573,21 +4982,17 @@ if (!Array.prototype.forEach) {
4573
4982
  var AsyncSubject = Rx.AsyncSubject = (function (__super__) {
4574
4983
 
4575
4984
  function subscribe(observer) {
4576
- checkDisposed.call(this);
4985
+ checkDisposed(this);
4577
4986
 
4578
4987
  if (!this.isStopped) {
4579
4988
  this.observers.push(observer);
4580
4989
  return new InnerSubscription(this, observer);
4581
4990
  }
4582
4991
 
4583
- var ex = this.exception,
4584
- hv = this.hasValue,
4585
- v = this.value;
4586
-
4587
- if (ex) {
4588
- observer.onError(ex);
4589
- } else if (hv) {
4590
- observer.onNext(v);
4992
+ if (this.hasError) {
4993
+ observer.onError(this.error);
4994
+ } else if (this.hasValue) {
4995
+ observer.onNext(this.value);
4591
4996
  observer.onCompleted();
4592
4997
  } else {
4593
4998
  observer.onCompleted();
@@ -4607,10 +5012,9 @@ if (!Array.prototype.forEach) {
4607
5012
 
4608
5013
  this.isDisposed = false;
4609
5014
  this.isStopped = false;
4610
- this.value = null;
4611
5015
  this.hasValue = false;
4612
5016
  this.observers = [];
4613
- this.exception = null;
5017
+ this.hasError = false;
4614
5018
  }
4615
5019
 
4616
5020
  addProperties(AsyncSubject.prototype, Observer, {
@@ -4619,34 +5023,32 @@ if (!Array.prototype.forEach) {
4619
5023
  * @returns {Boolean} Indicates whether the subject has observers subscribed to it.
4620
5024
  */
4621
5025
  hasObservers: function () {
4622
- checkDisposed.call(this);
5026
+ checkDisposed(this);
4623
5027
  return this.observers.length > 0;
4624
5028
  },
4625
5029
  /**
4626
5030
  * Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
4627
5031
  */
4628
5032
  onCompleted: function () {
4629
- var o, i, len;
4630
- checkDisposed.call(this);
5033
+ var i, len;
5034
+ checkDisposed(this);
4631
5035
  if (!this.isStopped) {
4632
5036
  this.isStopped = true;
4633
- var os = this.observers.slice(0),
4634
- v = this.value,
4635
- hv = this.hasValue;
4636
-
4637
- if (hv) {
4638
- for (i = 0, len = os.length; i < len; i++) {
4639
- o = os[i];
4640
- o.onNext(v);
5037
+ var os = cloneArray(this.observers), len = os.length;
5038
+
5039
+ if (this.hasValue) {
5040
+ for (i = 0; i < len; i++) {
5041
+ var o = os[i];
5042
+ o.onNext(this.value);
4641
5043
  o.onCompleted();
4642
5044
  }
4643
5045
  } else {
4644
- for (i = 0, len = os.length; i < len; i++) {
5046
+ for (i = 0; i < len; i++) {
4645
5047
  os[i].onCompleted();
4646
5048
  }
4647
5049
  }
4648
5050
 
4649
- this.observers = [];
5051
+ this.observers.length = 0;
4650
5052
  }
4651
5053
  },
4652
5054
  /**
@@ -4654,17 +5056,17 @@ if (!Array.prototype.forEach) {
4654
5056
  * @param {Mixed} error The Error to send to all observers.
4655
5057
  */
4656
5058
  onError: function (error) {
4657
- checkDisposed.call(this);
5059
+ checkDisposed(this);
4658
5060
  if (!this.isStopped) {
4659
- var os = this.observers.slice(0);
4660
5061
  this.isStopped = true;
4661
- this.exception = error;
5062
+ this.hasError = true;
5063
+ this.error = error;
4662
5064
 
4663
- for (var i = 0, len = os.length; i < len; i++) {
5065
+ for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
4664
5066
  os[i].onError(error);
4665
5067
  }
4666
5068
 
4667
- this.observers = [];
5069
+ this.observers.length = 0;
4668
5070
  }
4669
5071
  },
4670
5072
  /**
@@ -4672,7 +5074,7 @@ if (!Array.prototype.forEach) {
4672
5074
  * @param {Mixed} value The value to store in the subject.
4673
5075
  */
4674
5076
  onNext: function (value) {
4675
- checkDisposed.call(this);
5077
+ checkDisposed(this);
4676
5078
  if (this.isStopped) { return; }
4677
5079
  this.value = value;
4678
5080
  this.hasValue = true;
@@ -4694,18 +5096,22 @@ if (!Array.prototype.forEach) {
4694
5096
  var AnonymousSubject = Rx.AnonymousSubject = (function (__super__) {
4695
5097
  inherits(AnonymousSubject, __super__);
4696
5098
 
5099
+ function subscribe(observer) {
5100
+ return this.observable.subscribe(observer);
5101
+ }
5102
+
4697
5103
  function AnonymousSubject(observer, observable) {
4698
5104
  this.observer = observer;
4699
5105
  this.observable = observable;
4700
- __super__.call(this, this.observable.subscribe.bind(this.observable));
5106
+ __super__.call(this, subscribe);
4701
5107
  }
4702
5108
 
4703
- addProperties(AnonymousSubject.prototype, Observer, {
5109
+ addProperties(AnonymousSubject.prototype, Observer.prototype, {
4704
5110
  onCompleted: function () {
4705
5111
  this.observer.onCompleted();
4706
5112
  },
4707
- onError: function (exception) {
4708
- this.observer.onError(exception);
5113
+ onError: function (error) {
5114
+ this.observer.onError(error);
4709
5115
  },
4710
5116
  onNext: function (value) {
4711
5117
  this.observer.onNext(value);
@@ -4715,23 +5121,23 @@ if (!Array.prototype.forEach) {
4715
5121
  return AnonymousSubject;
4716
5122
  }(Observable));
4717
5123
 
4718
- if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
4719
- root.Rx = Rx;
5124
+ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
5125
+ root.Rx = Rx;
4720
5126
 
4721
- define(function() {
4722
- return Rx;
4723
- });
4724
- } else if (freeExports && freeModule) {
4725
- // in Node.js or RingoJS
4726
- if (moduleExports) {
4727
- (freeModule.exports = Rx).Rx = Rx;
4728
- } else {
4729
- freeExports.Rx = Rx;
4730
- }
5127
+ define(function() {
5128
+ return Rx;
5129
+ });
5130
+ } else if (freeExports && freeModule) {
5131
+ // in Node.js or RingoJS
5132
+ if (moduleExports) {
5133
+ (freeModule.exports = Rx).Rx = Rx;
4731
5134
  } else {
4732
- // in a browser or Rhino
4733
- root.Rx = Rx;
5135
+ freeExports.Rx = Rx;
4734
5136
  }
5137
+ } else {
5138
+ // in a browser or Rhino
5139
+ root.Rx = Rx;
5140
+ }
4735
5141
 
4736
5142
  // All code before this point will be filtered from stack traces.
4737
5143
  var rEndingLine = captureLine();