rxjs-rails 2.5.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +367 -284
  4. data/vendor/assets/javascripts/rx.aggregates.map +1 -1
  5. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  6. data/vendor/assets/javascripts/rx.all.compat.js +2405 -2438
  7. data/vendor/assets/javascripts/rx.all.compat.map +1 -1
  8. data/vendor/assets/javascripts/rx.all.compat.min.js +4 -4
  9. data/vendor/assets/javascripts/rx.all.js +2380 -2395
  10. data/vendor/assets/javascripts/rx.all.map +1 -1
  11. data/vendor/assets/javascripts/rx.all.min.js +4 -4
  12. data/vendor/assets/javascripts/rx.async.compat.js +311 -333
  13. data/vendor/assets/javascripts/rx.async.compat.map +1 -1
  14. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.async.js +280 -327
  16. data/vendor/assets/javascripts/rx.async.map +1 -1
  17. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  18. data/vendor/assets/javascripts/rx.backpressure.js +208 -176
  19. data/vendor/assets/javascripts/rx.backpressure.map +1 -1
  20. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  21. data/vendor/assets/javascripts/rx.binding.js +44 -27
  22. data/vendor/assets/javascripts/rx.binding.map +1 -1
  23. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  24. data/vendor/assets/javascripts/rx.coincidence.js +220 -453
  25. data/vendor/assets/javascripts/rx.coincidence.map +1 -1
  26. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  27. data/vendor/assets/javascripts/rx.compat.js +1366 -1173
  28. data/vendor/assets/javascripts/rx.compat.map +1 -1
  29. data/vendor/assets/javascripts/rx.compat.min.js +3 -2
  30. data/vendor/assets/javascripts/rx.core.binding.js +823 -0
  31. data/vendor/assets/javascripts/rx.core.binding.map +1 -0
  32. data/vendor/assets/javascripts/rx.core.binding.min.js +3 -0
  33. data/vendor/assets/javascripts/rx.core.js +1281 -0
  34. data/vendor/assets/javascripts/rx.core.map +1 -0
  35. data/vendor/assets/javascripts/rx.core.min.js +3 -0
  36. data/vendor/assets/javascripts/rx.core.testing.js +1242 -0
  37. data/vendor/assets/javascripts/rx.core.testing.map +1 -0
  38. data/vendor/assets/javascripts/rx.core.testing.min.js +3 -0
  39. data/vendor/assets/javascripts/rx.experimental.js +85 -123
  40. data/vendor/assets/javascripts/rx.experimental.map +1 -1
  41. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  42. data/vendor/assets/javascripts/rx.joinpatterns.js +48 -37
  43. data/vendor/assets/javascripts/rx.joinpatterns.map +1 -1
  44. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  45. data/vendor/assets/javascripts/rx.js +1367 -1174
  46. data/vendor/assets/javascripts/rx.lite.compat.js +1621 -1403
  47. data/vendor/assets/javascripts/rx.lite.compat.map +1 -1
  48. data/vendor/assets/javascripts/rx.lite.compat.min.js +3 -3
  49. data/vendor/assets/javascripts/rx.lite.extras.compat.js +119 -89
  50. data/vendor/assets/javascripts/rx.lite.extras.compat.map +1 -1
  51. data/vendor/assets/javascripts/rx.lite.extras.compat.min.js +1 -1
  52. data/vendor/assets/javascripts/rx.lite.extras.js +119 -89
  53. data/vendor/assets/javascripts/rx.lite.extras.map +1 -1
  54. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  55. data/vendor/assets/javascripts/rx.lite.js +1583 -1390
  56. data/vendor/assets/javascripts/rx.lite.map +1 -1
  57. data/vendor/assets/javascripts/rx.lite.min.js +3 -3
  58. data/vendor/assets/javascripts/rx.map +1 -1
  59. data/vendor/assets/javascripts/rx.min.js +3 -2
  60. data/vendor/assets/javascripts/rx.sorting.js +23 -27
  61. data/vendor/assets/javascripts/rx.sorting.map +1 -1
  62. data/vendor/assets/javascripts/rx.sorting.min.js +1 -1
  63. data/vendor/assets/javascripts/rx.testing.js +11 -15
  64. data/vendor/assets/javascripts/rx.testing.map +1 -1
  65. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  66. data/vendor/assets/javascripts/rx.time.js +117 -133
  67. data/vendor/assets/javascripts/rx.time.map +1 -1
  68. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  69. data/vendor/assets/javascripts/rx.virtualtime.js +120 -39
  70. data/vendor/assets/javascripts/rx.virtualtime.map +1 -1
  71. data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
  72. metadata +12 -3
@@ -3,46 +3,37 @@
3
3
  ;(function (undefined) {
4
4
 
5
5
  var objectTypes = {
6
- 'boolean': false,
7
6
  'function': true,
8
- 'object': true,
9
- 'number': false,
10
- 'string': false,
11
- 'undefined': false
7
+ 'object': true
12
8
  };
13
9
 
14
- var root = (objectTypes[typeof window] && window) || this,
10
+ var
15
11
  freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports,
12
+ freeSelf = objectTypes[typeof self] && self.Object && self,
13
+ freeWindow = objectTypes[typeof window] && window && window.Object && window,
16
14
  freeModule = objectTypes[typeof module] && module && !module.nodeType && module,
17
15
  moduleExports = freeModule && freeModule.exports === freeExports && freeExports,
18
- freeGlobal = objectTypes[typeof global] && global;
16
+ freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
19
17
 
20
- if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
21
- root = freeGlobal;
22
- }
18
+ var root = root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
23
19
 
24
20
  var Rx = {
25
- internals: {},
26
- config: {
27
- Promise: root.Promise
28
- },
29
- helpers: { }
21
+ internals: {},
22
+ config: {
23
+ Promise: root.Promise
24
+ },
25
+ helpers: { }
30
26
  };
31
27
 
32
28
  // Defaults
33
29
  var noop = Rx.helpers.noop = function () { },
34
- notDefined = Rx.helpers.notDefined = function (x) { return typeof x === 'undefined'; },
35
30
  identity = Rx.helpers.identity = function (x) { return x; },
36
- pluck = Rx.helpers.pluck = function (property) { return function (x) { return x[property]; }; },
37
- just = Rx.helpers.just = function (value) { return function () { return value; }; },
38
31
  defaultNow = Rx.helpers.defaultNow = Date.now,
39
32
  defaultComparer = Rx.helpers.defaultComparer = function (x, y) { return isEqual(x, y); },
40
33
  defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
41
34
  defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
42
35
  defaultError = Rx.helpers.defaultError = function (err) { throw err; },
43
- isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'; },
44
- asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
45
- not = Rx.helpers.not = function (a) { return !a; },
36
+ isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.subscribe !== 'function' && typeof p.then === 'function'; },
46
37
  isFunction = Rx.helpers.isFunction = (function () {
47
38
 
48
39
  var isFn = function (value) {
@@ -61,45 +52,59 @@
61
52
 
62
53
  function cloneArray(arr) { for(var a = [], i = 0, len = arr.length; i < len; i++) { a.push(arr[i]); } return a;}
63
54
 
64
- Rx.config.longStackSupport = false;
65
- var hasStacks = false;
66
- try {
67
- throw new Error();
68
- } catch (e) {
69
- hasStacks = !!e.stack;
55
+ var errorObj = {e: {}};
56
+ var tryCatchTarget;
57
+ function tryCatcher() {
58
+ try {
59
+ return tryCatchTarget.apply(this, arguments);
60
+ } catch (e) {
61
+ errorObj.e = e;
62
+ return errorObj;
63
+ }
64
+ }
65
+ function tryCatch(fn) {
66
+ if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
67
+ tryCatchTarget = fn;
68
+ return tryCatcher;
69
+ }
70
+ function thrower(e) {
71
+ throw e;
70
72
  }
71
73
 
74
+ Rx.config.longStackSupport = false;
75
+ var hasStacks = false, stacks = tryCatch(function () { throw new Error(); })();
76
+ hasStacks = !!stacks.e && !!stacks.e.stack;
77
+
72
78
  // All code after this point will be filtered from stack traces reported by RxJS
73
79
  var rStartingLine = captureLine(), rFileName;
74
80
 
75
- var STACK_JUMP_SEPARATOR = "From previous event:";
81
+ var STACK_JUMP_SEPARATOR = 'From previous event:';
76
82
 
77
83
  function makeStackTraceLong(error, observable) {
78
- // If possible, transform the error stack trace by removing Node and RxJS
79
- // cruft, then concatenating with the stack trace of `observable`.
80
- if (hasStacks &&
81
- observable.stack &&
82
- typeof error === "object" &&
83
- error !== null &&
84
- error.stack &&
85
- error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
86
- ) {
87
- var stacks = [];
88
- for (var o = observable; !!o; o = o.source) {
89
- if (o.stack) {
90
- stacks.unshift(o.stack);
91
- }
84
+ // If possible, transform the error stack trace by removing Node and RxJS
85
+ // cruft, then concatenating with the stack trace of `observable`.
86
+ if (hasStacks &&
87
+ observable.stack &&
88
+ typeof error === 'object' &&
89
+ error !== null &&
90
+ error.stack &&
91
+ error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
92
+ ) {
93
+ var stacks = [];
94
+ for (var o = observable; !!o; o = o.source) {
95
+ if (o.stack) {
96
+ stacks.unshift(o.stack);
92
97
  }
93
- stacks.unshift(error.stack);
98
+ }
99
+ stacks.unshift(error.stack);
94
100
 
95
- var concatedStacks = stacks.join("\n" + STACK_JUMP_SEPARATOR + "\n");
96
- error.stack = filterStackString(concatedStacks);
101
+ var concatedStacks = stacks.join('\n' + STACK_JUMP_SEPARATOR + '\n');
102
+ error.stack = filterStackString(concatedStacks);
97
103
  }
98
104
  }
99
105
 
100
106
  function filterStackString(stackString) {
101
- var lines = stackString.split("\n"),
102
- desiredLines = [];
107
+ var lines = stackString.split('\n'), desiredLines = [];
103
108
  for (var i = 0, len = lines.length; i < len; i++) {
104
109
  var line = lines[i];
105
110
 
@@ -107,7 +112,7 @@
107
112
  desiredLines.push(line);
108
113
  }
109
114
  }
110
- return desiredLines.join("\n");
115
+ return desiredLines.join('\n');
111
116
  }
112
117
 
113
118
  function isInternalFrame(stackLine) {
@@ -123,8 +128,8 @@
123
128
  }
124
129
 
125
130
  function isNodeFrame(stackLine) {
126
- return stackLine.indexOf("(module.js:") !== -1 ||
127
- stackLine.indexOf("(node.js:") !== -1;
131
+ return stackLine.indexOf('(module.js:') !== -1 ||
132
+ stackLine.indexOf('(node.js:') !== -1;
128
133
  }
129
134
 
130
135
  function captureLine() {
@@ -133,8 +138,8 @@
133
138
  try {
134
139
  throw new Error();
135
140
  } catch (e) {
136
- var lines = e.stack.split("\n");
137
- var firstLine = lines[0].indexOf("@") > 0 ? lines[1] : lines[2];
141
+ var lines = e.stack.split('\n');
142
+ var firstLine = lines[0].indexOf('@') > 0 ? lines[1] : lines[2];
138
143
  var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
139
144
  if (!fileNameAndLineNumber) { return; }
140
145
 
@@ -144,45 +149,50 @@
144
149
  }
145
150
 
146
151
  function getFileNameAndLineNumber(stackLine) {
147
- // Named functions: "at functionName (filename:lineNumber:columnNumber)"
152
+ // Named functions: 'at functionName (filename:lineNumber:columnNumber)'
148
153
  var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
149
154
  if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
150
155
 
151
- // Anonymous functions: "at filename:lineNumber:columnNumber"
156
+ // Anonymous functions: 'at filename:lineNumber:columnNumber'
152
157
  var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
153
158
  if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
154
159
 
155
- // Firefox style: "function@filename:lineNumber or @filename:lineNumber"
160
+ // Firefox style: 'function@filename:lineNumber or @filename:lineNumber'
156
161
  var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
157
162
  if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
158
163
  }
159
164
 
160
165
  var EmptyError = Rx.EmptyError = function() {
161
166
  this.message = 'Sequence contains no elements.';
167
+ this.name = 'EmptyError';
162
168
  Error.call(this);
163
169
  };
164
170
  EmptyError.prototype = Error.prototype;
165
171
 
166
172
  var ObjectDisposedError = Rx.ObjectDisposedError = function() {
167
173
  this.message = 'Object has been disposed';
174
+ this.name = 'ObjectDisposedError';
168
175
  Error.call(this);
169
176
  };
170
177
  ObjectDisposedError.prototype = Error.prototype;
171
178
 
172
179
  var ArgumentOutOfRangeError = Rx.ArgumentOutOfRangeError = function () {
173
180
  this.message = 'Argument out of range';
181
+ this.name = 'ArgumentOutOfRangeError';
174
182
  Error.call(this);
175
183
  };
176
184
  ArgumentOutOfRangeError.prototype = Error.prototype;
177
185
 
178
186
  var NotSupportedError = Rx.NotSupportedError = function (message) {
179
187
  this.message = message || 'This operation is not supported';
188
+ this.name = 'NotSupportedError';
180
189
  Error.call(this);
181
190
  };
182
191
  NotSupportedError.prototype = Error.prototype;
183
192
 
184
193
  var NotImplementedError = Rx.NotImplementedError = function (message) {
185
194
  this.message = message || 'This operation is not implemented';
195
+ this.name = 'NotImplementedError';
186
196
  Error.call(this);
187
197
  };
188
198
  NotImplementedError.prototype = Error.prototype;
@@ -529,7 +539,7 @@
529
539
  var hasProp = {}.hasOwnProperty,
530
540
  slice = Array.prototype.slice;
531
541
 
532
- var inherits = this.inherits = Rx.internals.inherits = function (child, parent) {
542
+ var inherits = Rx.internals.inherits = function (child, parent) {
533
543
  function __() { this.constructor = child; }
534
544
  __.prototype = parent.prototype;
535
545
  child.prototype = new __();
@@ -560,111 +570,6 @@
560
570
  return a;
561
571
  }
562
572
 
563
- var errorObj = {e: {}};
564
- var tryCatchTarget;
565
- function tryCatcher() {
566
- try {
567
- return tryCatchTarget.apply(this, arguments);
568
- } catch (e) {
569
- errorObj.e = e;
570
- return errorObj;
571
- }
572
- }
573
- function tryCatch(fn) {
574
- if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
575
- tryCatchTarget = fn;
576
- return tryCatcher;
577
- }
578
- function thrower(e) {
579
- throw e;
580
- }
581
-
582
- // Collections
583
- function IndexedItem(id, value) {
584
- this.id = id;
585
- this.value = value;
586
- }
587
-
588
- IndexedItem.prototype.compareTo = function (other) {
589
- var c = this.value.compareTo(other.value);
590
- c === 0 && (c = this.id - other.id);
591
- return c;
592
- };
593
-
594
- // Priority Queue for Scheduling
595
- var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
596
- this.items = new Array(capacity);
597
- this.length = 0;
598
- };
599
-
600
- var priorityProto = PriorityQueue.prototype;
601
- priorityProto.isHigherPriority = function (left, right) {
602
- return this.items[left].compareTo(this.items[right]) < 0;
603
- };
604
-
605
- priorityProto.percolate = function (index) {
606
- if (index >= this.length || index < 0) { return; }
607
- var parent = index - 1 >> 1;
608
- if (parent < 0 || parent === index) { return; }
609
- if (this.isHigherPriority(index, parent)) {
610
- var temp = this.items[index];
611
- this.items[index] = this.items[parent];
612
- this.items[parent] = temp;
613
- this.percolate(parent);
614
- }
615
- };
616
-
617
- priorityProto.heapify = function (index) {
618
- +index || (index = 0);
619
- if (index >= this.length || index < 0) { return; }
620
- var left = 2 * index + 1,
621
- right = 2 * index + 2,
622
- first = index;
623
- if (left < this.length && this.isHigherPriority(left, first)) {
624
- first = left;
625
- }
626
- if (right < this.length && this.isHigherPriority(right, first)) {
627
- first = right;
628
- }
629
- if (first !== index) {
630
- var temp = this.items[index];
631
- this.items[index] = this.items[first];
632
- this.items[first] = temp;
633
- this.heapify(first);
634
- }
635
- };
636
-
637
- priorityProto.peek = function () { return this.items[0].value; };
638
-
639
- priorityProto.removeAt = function (index) {
640
- this.items[index] = this.items[--this.length];
641
- this.items[this.length] = undefined;
642
- this.heapify();
643
- };
644
-
645
- priorityProto.dequeue = function () {
646
- var result = this.peek();
647
- this.removeAt(0);
648
- return result;
649
- };
650
-
651
- priorityProto.enqueue = function (item) {
652
- var index = this.length++;
653
- this.items[index] = new IndexedItem(PriorityQueue.count++, item);
654
- this.percolate(index);
655
- };
656
-
657
- priorityProto.remove = function (item) {
658
- for (var i = 0; i < this.length; i++) {
659
- if (this.items[i].value === item) {
660
- this.removeAt(i);
661
- return true;
662
- }
663
- }
664
- return false;
665
- };
666
- PriorityQueue.count = 0;
667
-
668
573
  /**
669
574
  * Represents a group of disposable resources that are disposed together.
670
575
  * @constructor
@@ -1034,52 +939,62 @@
1034
939
 
1035
940
  function invokeRecImmediate(scheduler, pair) {
1036
941
  var state = pair[0], action = pair[1], group = new CompositeDisposable();
942
+ action(state, innerAction);
943
+ return group;
1037
944
 
1038
- function recursiveAction(state1) {
1039
- action(state1, function (state2) {
1040
- var isAdded = false, isDone = false,
1041
- d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
1042
- if (isAdded) {
1043
- group.remove(d);
1044
- } else {
1045
- isDone = true;
1046
- }
1047
- recursiveAction(state3);
1048
- return disposableEmpty;
1049
- });
1050
- if (!isDone) {
1051
- group.add(d);
1052
- isAdded = true;
945
+ function innerAction(state2) {
946
+ var isAdded = false, isDone = false;
947
+
948
+ var d = scheduler.scheduleWithState(state2, scheduleWork);
949
+ if (!isDone) {
950
+ group.add(d);
951
+ isAdded = true;
952
+ }
953
+
954
+ function scheduleWork(_, state3) {
955
+ if (isAdded) {
956
+ group.remove(d);
957
+ } else {
958
+ isDone = true;
1053
959
  }
1054
- });
960
+ action(state3, innerAction);
961
+ return disposableEmpty;
962
+ }
1055
963
  }
1056
-
1057
- recursiveAction(state);
1058
- return group;
1059
964
  }
1060
965
 
1061
966
  function invokeRecDate(scheduler, pair, method) {
1062
967
  var state = pair[0], action = pair[1], group = new CompositeDisposable();
1063
- function recursiveAction(state1) {
1064
- action(state1, function (state2, dueTime1) {
1065
- var isAdded = false, isDone = false,
1066
- d = scheduler[method](state2, dueTime1, function (scheduler1, state3) {
1067
- if (isAdded) {
1068
- group.remove(d);
1069
- } else {
1070
- isDone = true;
1071
- }
1072
- recursiveAction(state3);
1073
- return disposableEmpty;
1074
- });
1075
- if (!isDone) {
1076
- group.add(d);
1077
- isAdded = true;
1078
- }
1079
- });
1080
- };
1081
- recursiveAction(state);
968
+ action(state, innerAction);
1082
969
  return group;
970
+
971
+ function innerAction(state2, dueTime1) {
972
+ var isAdded = false, isDone = false;
973
+
974
+ var d = scheduler[method](state2, dueTime1, scheduleWork);
975
+ if (!isDone) {
976
+ group.add(d);
977
+ isAdded = true;
978
+ }
979
+
980
+ function scheduleWork(_, state3) {
981
+ if (isAdded) {
982
+ group.remove(d);
983
+ } else {
984
+ isDone = true;
985
+ }
986
+ action(state3, innerAction);
987
+ return disposableEmpty;
988
+ }
989
+ }
990
+ }
991
+
992
+ function invokeRecDateRelative(s, p) {
993
+ return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
994
+ }
995
+
996
+ function invokeRecDateAbsolute(s, p) {
997
+ return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
1083
998
  }
1084
999
 
1085
1000
  function scheduleInnerRecursive(action, self) {
@@ -1092,8 +1007,7 @@
1092
1007
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1093
1008
  */
1094
1009
  schedulerProto.scheduleRecursive = function (action) {
1095
- return this.scheduleRecursiveWithState(action, function (_action, self) {
1096
- _action(function () { self(_action); }); });
1010
+ return this.scheduleRecursiveWithState(action, scheduleInnerRecursive);
1097
1011
  };
1098
1012
 
1099
1013
  /**
@@ -1124,9 +1038,7 @@
1124
1038
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1125
1039
  */
1126
1040
  schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
1127
- return this._scheduleRelative([state, action], dueTime, function (s, p) {
1128
- return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
1129
- });
1041
+ return this._scheduleRelative([state, action], dueTime, invokeRecDateRelative);
1130
1042
  };
1131
1043
 
1132
1044
  /**
@@ -1147,9 +1059,7 @@
1147
1059
  * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
1148
1060
  */
1149
1061
  schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
1150
- return this._scheduleAbsolute([state, action], dueTime, function (s, p) {
1151
- return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
1152
- });
1062
+ return this._scheduleAbsolute([state, action], dueTime, invokeRecDateAbsolute);
1153
1063
  };
1154
1064
  }(Scheduler.prototype));
1155
1065
 
@@ -1235,7 +1145,7 @@
1235
1145
 
1236
1146
  function runTrampoline () {
1237
1147
  while (queue.length > 0) {
1238
- var item = queue.dequeue();
1148
+ var item = queue.shift();
1239
1149
  !item.isCancelled() && item.invoke();
1240
1150
  }
1241
1151
  }
@@ -1244,14 +1154,13 @@
1244
1154
  var si = new ScheduledItem(this, state, action, this.now());
1245
1155
 
1246
1156
  if (!queue) {
1247
- queue = new PriorityQueue(4);
1248
- queue.enqueue(si);
1157
+ queue = [si];
1249
1158
 
1250
1159
  var result = tryCatch(runTrampoline)();
1251
1160
  queue = null;
1252
1161
  if (result === errorObj) { return thrower(result.e); }
1253
1162
  } else {
1254
- queue.enqueue(si);
1163
+ queue.push(si);
1255
1164
  }
1256
1165
  return si.disposable;
1257
1166
  }
@@ -1610,188 +1519,6 @@
1610
1519
  };
1611
1520
  }());
1612
1521
 
1613
- var Enumerator = Rx.internals.Enumerator = function (next) {
1614
- this._next = next;
1615
- };
1616
-
1617
- Enumerator.prototype.next = function () {
1618
- return this._next();
1619
- };
1620
-
1621
- Enumerator.prototype[$iterator$] = function () { return this; }
1622
-
1623
- var Enumerable = Rx.internals.Enumerable = function (iterator) {
1624
- this._iterator = iterator;
1625
- };
1626
-
1627
- Enumerable.prototype[$iterator$] = function () {
1628
- return this._iterator();
1629
- };
1630
-
1631
- Enumerable.prototype.concat = function () {
1632
- var sources = this;
1633
- return new AnonymousObservable(function (o) {
1634
- var e = sources[$iterator$]();
1635
-
1636
- var isDisposed, subscription = new SerialDisposable();
1637
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1638
- if (isDisposed) { return; }
1639
- try {
1640
- var currentItem = e.next();
1641
- } catch (ex) {
1642
- return o.onError(ex);
1643
- }
1644
-
1645
- if (currentItem.done) {
1646
- return o.onCompleted();
1647
- }
1648
-
1649
- // Check if promise
1650
- var currentValue = currentItem.value;
1651
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1652
-
1653
- var d = new SingleAssignmentDisposable();
1654
- subscription.setDisposable(d);
1655
- d.setDisposable(currentValue.subscribe(
1656
- function(x) { o.onNext(x); },
1657
- function(err) { o.onError(err); },
1658
- self)
1659
- );
1660
- });
1661
-
1662
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1663
- isDisposed = true;
1664
- }));
1665
- });
1666
- };
1667
-
1668
- Enumerable.prototype.catchError = function () {
1669
- var sources = this;
1670
- return new AnonymousObservable(function (o) {
1671
- var e = sources[$iterator$]();
1672
-
1673
- var isDisposed, subscription = new SerialDisposable();
1674
- var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
1675
- if (isDisposed) { return; }
1676
-
1677
- try {
1678
- var currentItem = e.next();
1679
- } catch (ex) {
1680
- return observer.onError(ex);
1681
- }
1682
-
1683
- if (currentItem.done) {
1684
- if (lastException !== null) {
1685
- o.onError(lastException);
1686
- } else {
1687
- o.onCompleted();
1688
- }
1689
- return;
1690
- }
1691
-
1692
- // Check if promise
1693
- var currentValue = currentItem.value;
1694
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1695
-
1696
- var d = new SingleAssignmentDisposable();
1697
- subscription.setDisposable(d);
1698
- d.setDisposable(currentValue.subscribe(
1699
- function(x) { o.onNext(x); },
1700
- self,
1701
- function() { o.onCompleted(); }));
1702
- });
1703
- return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
1704
- isDisposed = true;
1705
- }));
1706
- });
1707
- };
1708
-
1709
-
1710
- Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
1711
- var sources = this;
1712
- return new AnonymousObservable(function (o) {
1713
- var exceptions = new Subject(),
1714
- notifier = new Subject(),
1715
- handled = notificationHandler(exceptions),
1716
- notificationDisposable = handled.subscribe(notifier);
1717
-
1718
- var e = sources[$iterator$]();
1719
-
1720
- var isDisposed,
1721
- lastException,
1722
- subscription = new SerialDisposable();
1723
- var cancelable = immediateScheduler.scheduleRecursive(function (self) {
1724
- if (isDisposed) { return; }
1725
-
1726
- try {
1727
- var currentItem = e.next();
1728
- } catch (ex) {
1729
- return o.onError(ex);
1730
- }
1731
-
1732
- if (currentItem.done) {
1733
- if (lastException) {
1734
- o.onError(lastException);
1735
- } else {
1736
- o.onCompleted();
1737
- }
1738
- return;
1739
- }
1740
-
1741
- // Check if promise
1742
- var currentValue = currentItem.value;
1743
- isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
1744
-
1745
- var outer = new SingleAssignmentDisposable();
1746
- var inner = new SingleAssignmentDisposable();
1747
- subscription.setDisposable(new CompositeDisposable(inner, outer));
1748
- outer.setDisposable(currentValue.subscribe(
1749
- function(x) { o.onNext(x); },
1750
- function (exn) {
1751
- inner.setDisposable(notifier.subscribe(self, function(ex) {
1752
- o.onError(ex);
1753
- }, function() {
1754
- o.onCompleted();
1755
- }));
1756
-
1757
- exceptions.onNext(exn);
1758
- },
1759
- function() { o.onCompleted(); }));
1760
- });
1761
-
1762
- return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
1763
- isDisposed = true;
1764
- }));
1765
- });
1766
- };
1767
-
1768
- var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
1769
- if (repeatCount == null) { repeatCount = -1; }
1770
- return new Enumerable(function () {
1771
- var left = repeatCount;
1772
- return new Enumerator(function () {
1773
- if (left === 0) { return doneEnumerator; }
1774
- if (left > 0) { left--; }
1775
- return { done: false, value: value };
1776
- });
1777
- });
1778
- };
1779
-
1780
- var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
1781
- if (selector) {
1782
- var selectorFn = bindCallback(selector, thisArg, 3);
1783
- }
1784
- return new Enumerable(function () {
1785
- var index = -1;
1786
- return new Enumerator(
1787
- function () {
1788
- return ++index < source.length ?
1789
- { done: false, value: !selector ? source[index] : selectorFn(source[index], index, source) } :
1790
- doneEnumerator;
1791
- });
1792
- });
1793
- };
1794
-
1795
1522
  /**
1796
1523
  * Supports push-style iteration over an observable sequence.
1797
1524
  */
@@ -1811,7 +1538,11 @@
1811
1538
  * @returns An observer that hides the identity of the specified observer.
1812
1539
  */
1813
1540
  Observer.prototype.asObserver = function () {
1814
- return new AnonymousObserver(this.onNext.bind(this), this.onError.bind(this), this.onCompleted.bind(this));
1541
+ var self = this;
1542
+ return new AnonymousObserver(
1543
+ function (x) { self.onNext(x); },
1544
+ function (err) { self.onError(err); },
1545
+ function () { self.onCompleted(); });
1815
1546
  };
1816
1547
 
1817
1548
  /**
@@ -1844,12 +1575,13 @@
1844
1575
  * @returns The observer object that invokes the specified handler using a notification corresponding to each message it receives.
1845
1576
  */
1846
1577
  Observer.fromNotifier = function (handler, thisArg) {
1578
+ var cb = bindCallback(handler, thisArg, 1);
1847
1579
  return new AnonymousObserver(function (x) {
1848
- return handler.call(thisArg, notificationCreateOnNext(x));
1580
+ return cb(notificationCreateOnNext(x));
1849
1581
  }, function (e) {
1850
- return handler.call(thisArg, notificationCreateOnError(e));
1582
+ return cb(notificationCreateOnError(e));
1851
1583
  }, function () {
1852
- return handler.call(thisArg, notificationCreateOnCompleted());
1584
+ return cb(notificationCreateOnCompleted());
1853
1585
  });
1854
1586
  };
1855
1587
 
@@ -1878,7 +1610,6 @@
1878
1610
  */
1879
1611
  function AbstractObserver() {
1880
1612
  this.isStopped = false;
1881
- __super__.call(this);
1882
1613
  }
1883
1614
 
1884
1615
  // Must be implemented by other observers
@@ -1891,7 +1622,7 @@
1891
1622
  * @param {Any} value Next element in the sequence.
1892
1623
  */
1893
1624
  AbstractObserver.prototype.onNext = function (value) {
1894
- if (!this.isStopped) { this.next(value); }
1625
+ !this.isStopped && this.next(value);
1895
1626
  };
1896
1627
 
1897
1628
  /**
@@ -1918,9 +1649,7 @@
1918
1649
  /**
1919
1650
  * Disposes the observer, causing it to transition to the stopped state.
1920
1651
  */
1921
- AbstractObserver.prototype.dispose = function () {
1922
- this.isStopped = true;
1923
- };
1652
+ AbstractObserver.prototype.dispose = function () { this.isStopped = true; };
1924
1653
 
1925
1654
  AbstractObserver.prototype.fail = function (e) {
1926
1655
  if (!this.isStopped) {
@@ -2050,13 +1779,13 @@
2050
1779
  };
2051
1780
 
2052
1781
  ScheduledObserver.prototype.ensureActive = function () {
2053
- var isOwner = false, parent = this;
1782
+ var isOwner = false;
2054
1783
  if (!this.hasFaulted && this.queue.length > 0) {
2055
1784
  isOwner = !this.isAcquired;
2056
1785
  this.isAcquired = true;
2057
1786
  }
2058
1787
  if (isOwner) {
2059
- this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
1788
+ this.disposable.setDisposable(this.scheduler.scheduleRecursiveWithState(this, function (parent, self) {
2060
1789
  var work;
2061
1790
  if (parent.queue.length > 0) {
2062
1791
  work = parent.queue.shift();
@@ -2064,14 +1793,13 @@
2064
1793
  parent.isAcquired = false;
2065
1794
  return;
2066
1795
  }
2067
- try {
2068
- work();
2069
- } catch (ex) {
1796
+ var res = tryCatch(work)();
1797
+ if (res === errorObj) {
2070
1798
  parent.queue = [];
2071
1799
  parent.hasFaulted = true;
2072
- throw ex;
1800
+ return thrower(res.e);
2073
1801
  }
2074
- self();
1802
+ self(parent);
2075
1803
  }));
2076
1804
  }
2077
1805
  };
@@ -2123,25 +1851,23 @@
2123
1851
  */
2124
1852
  var Observable = Rx.Observable = (function () {
2125
1853
 
2126
- function Observable(subscribe) {
2127
- if (Rx.config.longStackSupport && hasStacks) {
2128
- try {
2129
- throw new Error();
2130
- } catch (e) {
2131
- this.stack = e.stack.substring(e.stack.indexOf("\n") + 1);
2132
- }
2133
-
2134
- var self = this;
2135
- this._subscribe = function (observer) {
2136
- var oldOnError = observer.onError.bind(observer);
1854
+ function makeSubscribe(self, subscribe) {
1855
+ return function (o) {
1856
+ var oldOnError = o.onError;
1857
+ o.onError = function (e) {
1858
+ makeStackTraceLong(e, self);
1859
+ oldOnError.call(o, e);
1860
+ };
2137
1861
 
2138
- observer.onError = function (err) {
2139
- makeStackTraceLong(err, self);
2140
- oldOnError(err);
2141
- };
1862
+ return subscribe.call(self, o);
1863
+ };
1864
+ }
2142
1865
 
2143
- return subscribe.call(self, observer);
2144
- };
1866
+ function Observable(subscribe) {
1867
+ if (Rx.config.longStackSupport && hasStacks) {
1868
+ var e = tryCatch(thrower)(new Error()).e;
1869
+ this.stack = e.stack.substring(e.stack.indexOf('\n') + 1);
1870
+ this._subscribe = makeSubscribe(this, subscribe);
2145
1871
  } else {
2146
1872
  this._subscribe = subscribe;
2147
1873
  }
@@ -2150,16 +1876,25 @@
2150
1876
  observableProto = Observable.prototype;
2151
1877
 
2152
1878
  /**
2153
- * Subscribes an observer to the observable sequence.
2154
- * @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
1879
+ * Determines whether the given object is an Observable
1880
+ * @param {Any} An object to determine whether it is an Observable
1881
+ * @returns {Boolean} true if an Observable, else false.
1882
+ */
1883
+ Observable.isObservable = function (o) {
1884
+ return o && isFunction(o.subscribe);
1885
+ }
1886
+
1887
+ /**
1888
+ * Subscribes an o to the observable sequence.
1889
+ * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
2155
1890
  * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
2156
1891
  * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
2157
1892
  * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
2158
1893
  */
2159
- observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
2160
- return this._subscribe(typeof observerOrOnNext === 'object' ?
2161
- observerOrOnNext :
2162
- observerCreate(observerOrOnNext, onError, onCompleted));
1894
+ observableProto.subscribe = observableProto.forEach = function (oOrOnNext, onError, onCompleted) {
1895
+ return this._subscribe(typeof oOrOnNext === 'object' ?
1896
+ oOrOnNext :
1897
+ observerCreate(oOrOnNext, onError, onCompleted));
2163
1898
  };
2164
1899
 
2165
1900
  /**
@@ -2233,6 +1968,294 @@
2233
1968
  return ObservableBase;
2234
1969
  }(Observable));
2235
1970
 
1971
+ var FlatMapObservable = (function(__super__){
1972
+
1973
+ inherits(FlatMapObservable, __super__);
1974
+
1975
+ function FlatMapObservable(source, selector, resultSelector, thisArg) {
1976
+ this.resultSelector = Rx.helpers.isFunction(resultSelector) ?
1977
+ resultSelector : null;
1978
+
1979
+ this.selector = Rx.internals.bindCallback(Rx.helpers.isFunction(selector) ? selector : function() { return selector; }, thisArg, 3);
1980
+ this.source = source;
1981
+
1982
+ __super__.call(this);
1983
+
1984
+ }
1985
+
1986
+ FlatMapObservable.prototype.subscribeCore = function(o) {
1987
+ return this.source.subscribe(new InnerObserver(o, this.selector, this.resultSelector, this));
1988
+ };
1989
+
1990
+ function InnerObserver(observer, selector, resultSelector, source) {
1991
+ this.i = 0;
1992
+ this.selector = selector;
1993
+ this.resultSelector = resultSelector;
1994
+ this.source = source;
1995
+ this.isStopped = false;
1996
+ this.o = observer;
1997
+ }
1998
+
1999
+ InnerObserver.prototype._wrapResult = function(result, x, i) {
2000
+ return this.resultSelector ?
2001
+ result.map(function(y, i2) { return this.resultSelector(x, y, i, i2); }, this) :
2002
+ result;
2003
+ };
2004
+
2005
+ InnerObserver.prototype.onNext = function(x) {
2006
+
2007
+ if (this.isStopped) return;
2008
+
2009
+ var i = this.i++;
2010
+ var result = tryCatch(this.selector)(x, i, this.source);
2011
+
2012
+ if (result === errorObj) {
2013
+ return this.o.onError(result.e);
2014
+ }
2015
+
2016
+ Rx.helpers.isPromise(result) && (result = Rx.Observable.fromPromise(result));
2017
+ (Rx.helpers.isArrayLike(result) || Rx.helpers.isIterable(result)) && (result = Rx.Observable.from(result));
2018
+
2019
+ this.o.onNext(this._wrapResult(result, x, i));
2020
+
2021
+ };
2022
+
2023
+ InnerObserver.prototype.onError = function(e) {
2024
+ if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
2025
+ };
2026
+
2027
+ InnerObserver.prototype.onCompleted = function() {
2028
+ if (!this.isStopped) {this.isStopped = true; this.o.onCompleted(); }
2029
+ };
2030
+
2031
+ return FlatMapObservable;
2032
+
2033
+ }(ObservableBase));
2034
+
2035
+ var Enumerable = Rx.internals.Enumerable = function () { };
2036
+
2037
+ var ConcatEnumerableObservable = (function(__super__) {
2038
+ inherits(ConcatEnumerableObservable, __super__);
2039
+ function ConcatEnumerableObservable(sources) {
2040
+ this.sources = sources;
2041
+ __super__.call(this);
2042
+ }
2043
+
2044
+ ConcatEnumerableObservable.prototype.subscribeCore = function (o) {
2045
+ var isDisposed, subscription = new SerialDisposable();
2046
+ var cancelable = immediateScheduler.scheduleRecursiveWithState(this.sources[$iterator$](), function (e, self) {
2047
+ if (isDisposed) { return; }
2048
+ var currentItem = tryCatch(e.next).call(e);
2049
+ if (currentItem === errorObj) { return o.onError(currentItem.e); }
2050
+
2051
+ if (currentItem.done) {
2052
+ return o.onCompleted();
2053
+ }
2054
+
2055
+ // Check if promise
2056
+ var currentValue = currentItem.value;
2057
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
2058
+
2059
+ var d = new SingleAssignmentDisposable();
2060
+ subscription.setDisposable(d);
2061
+ d.setDisposable(currentValue.subscribe(new InnerObserver(o, self, e)));
2062
+ });
2063
+
2064
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
2065
+ isDisposed = true;
2066
+ }));
2067
+ };
2068
+
2069
+ function InnerObserver(o, s, e) {
2070
+ this.o = o;
2071
+ this.s = s;
2072
+ this.e = e;
2073
+ this.isStopped = false;
2074
+ }
2075
+ InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
2076
+ InnerObserver.prototype.onError = function (err) {
2077
+ if (!this.isStopped) {
2078
+ this.isStopped = true;
2079
+ this.o.onError(err);
2080
+ }
2081
+ };
2082
+ InnerObserver.prototype.onCompleted = function () {
2083
+ if (!this.isStopped) {
2084
+ this.isStopped = true;
2085
+ this.s(this.e);
2086
+ }
2087
+ };
2088
+ InnerObserver.prototype.dispose = function () { this.isStopped = true; };
2089
+ InnerObserver.prototype.fail = function (err) {
2090
+ if (!this.isStopped) {
2091
+ this.isStopped = true;
2092
+ this.o.onError(err);
2093
+ return true;
2094
+ }
2095
+ return false;
2096
+ };
2097
+
2098
+ return ConcatEnumerableObservable;
2099
+ }(ObservableBase));
2100
+
2101
+ Enumerable.prototype.concat = function () {
2102
+ return new ConcatEnumerableObservable(this);
2103
+ };
2104
+
2105
+ var CatchErrorObservable = (function(__super__) {
2106
+ inherits(CatchErrorObservable, __super__);
2107
+ function CatchErrorObservable(sources) {
2108
+ this.sources = sources;
2109
+ __super__.call(this);
2110
+ }
2111
+
2112
+ CatchErrorObservable.prototype.subscribeCore = function (o) {
2113
+ var e = this.sources[$iterator$]();
2114
+
2115
+ var isDisposed, subscription = new SerialDisposable();
2116
+ var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
2117
+ if (isDisposed) { return; }
2118
+ var currentItem = tryCatch(e.next).call(e);
2119
+ if (currentItem === errorObj) { return o.onError(currentItem.e); }
2120
+
2121
+ if (currentItem.done) {
2122
+ return lastException !== null ? o.onError(lastException) : o.onCompleted();
2123
+ }
2124
+
2125
+ // Check if promise
2126
+ var currentValue = currentItem.value;
2127
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
2128
+
2129
+ var d = new SingleAssignmentDisposable();
2130
+ subscription.setDisposable(d);
2131
+ d.setDisposable(currentValue.subscribe(
2132
+ function(x) { o.onNext(x); },
2133
+ self,
2134
+ function() { o.onCompleted(); }));
2135
+ });
2136
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
2137
+ isDisposed = true;
2138
+ }));
2139
+ };
2140
+
2141
+ return CatchErrorObservable;
2142
+ }(ObservableBase));
2143
+
2144
+ Enumerable.prototype.catchError = function () {
2145
+ return new CatchErrorObservable(this);
2146
+ };
2147
+
2148
+ Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
2149
+ var sources = this;
2150
+ return new AnonymousObservable(function (o) {
2151
+ var exceptions = new Subject(),
2152
+ notifier = new Subject(),
2153
+ handled = notificationHandler(exceptions),
2154
+ notificationDisposable = handled.subscribe(notifier);
2155
+
2156
+ var e = sources[$iterator$]();
2157
+
2158
+ var isDisposed,
2159
+ lastException,
2160
+ subscription = new SerialDisposable();
2161
+ var cancelable = immediateScheduler.scheduleRecursive(function (self) {
2162
+ if (isDisposed) { return; }
2163
+ var currentItem = tryCatch(e.next).call(e);
2164
+ if (currentItem === errorObj) { return o.onError(currentItem.e); }
2165
+
2166
+ if (currentItem.done) {
2167
+ if (lastException) {
2168
+ o.onError(lastException);
2169
+ } else {
2170
+ o.onCompleted();
2171
+ }
2172
+ return;
2173
+ }
2174
+
2175
+ // Check if promise
2176
+ var currentValue = currentItem.value;
2177
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
2178
+
2179
+ var outer = new SingleAssignmentDisposable();
2180
+ var inner = new SingleAssignmentDisposable();
2181
+ subscription.setDisposable(new CompositeDisposable(inner, outer));
2182
+ outer.setDisposable(currentValue.subscribe(
2183
+ function(x) { o.onNext(x); },
2184
+ function (exn) {
2185
+ inner.setDisposable(notifier.subscribe(self, function(ex) {
2186
+ o.onError(ex);
2187
+ }, function() {
2188
+ o.onCompleted();
2189
+ }));
2190
+
2191
+ exceptions.onNext(exn);
2192
+ },
2193
+ function() { o.onCompleted(); }));
2194
+ });
2195
+
2196
+ return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
2197
+ isDisposed = true;
2198
+ }));
2199
+ });
2200
+ };
2201
+
2202
+ var RepeatEnumerable = (function (__super__) {
2203
+ inherits(RepeatEnumerable, __super__);
2204
+
2205
+ function RepeatEnumerable(v, c) {
2206
+ this.v = v;
2207
+ this.c = c == null ? -1 : c;
2208
+ }
2209
+ RepeatEnumerable.prototype[$iterator$] = function () {
2210
+ return new RepeatEnumerator(this);
2211
+ };
2212
+
2213
+ function RepeatEnumerator(p) {
2214
+ this.v = p.v;
2215
+ this.l = p.c;
2216
+ }
2217
+ RepeatEnumerator.prototype.next = function () {
2218
+ if (this.l === 0) { return doneEnumerator; }
2219
+ if (this.l > 0) { this.l--; }
2220
+ return { done: false, value: this.v };
2221
+ };
2222
+
2223
+ return RepeatEnumerable;
2224
+ }(Enumerable));
2225
+
2226
+ var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
2227
+ return new RepeatEnumerable(value, repeatCount);
2228
+ };
2229
+
2230
+ var OfEnumerable = (function(__super__) {
2231
+ inherits(OfEnumerable, __super__);
2232
+ function OfEnumerable(s, fn, thisArg) {
2233
+ this.s = s;
2234
+ this.fn = fn ? bindCallback(fn, thisArg, 3) : null;
2235
+ }
2236
+ OfEnumerable.prototype[$iterator$] = function () {
2237
+ return new OfEnumerator(this);
2238
+ };
2239
+
2240
+ function OfEnumerator(p) {
2241
+ this.i = -1;
2242
+ this.s = p.s;
2243
+ this.l = this.s.length;
2244
+ this.fn = p.fn;
2245
+ }
2246
+ OfEnumerator.prototype.next = function () {
2247
+ return ++this.i < this.l ?
2248
+ { done: false, value: !this.fn ? this.s[this.i] : this.fn(this.s[this.i], this.i, this.s) } :
2249
+ doneEnumerator;
2250
+ };
2251
+
2252
+ return OfEnumerable;
2253
+ }(Enumerable));
2254
+
2255
+ var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
2256
+ return new OfEnumerable(source, selector, thisArg);
2257
+ };
2258
+
2236
2259
  /**
2237
2260
  * Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
2238
2261
  *
@@ -2271,26 +2294,32 @@
2271
2294
  }, source);
2272
2295
  };
2273
2296
 
2274
- /**
2275
- * Converts a Promise to an Observable sequence
2276
- * @param {Promise} An ES6 Compliant promise.
2277
- * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
2278
- */
2279
- var observableFromPromise = Observable.fromPromise = function (promise) {
2280
- return observableDefer(function () {
2281
- var subject = new Rx.AsyncSubject();
2297
+ var FromPromiseObservable = (function(__super__) {
2298
+ inherits(FromPromiseObservable, __super__);
2299
+ function FromPromiseObservable(p) {
2300
+ this.p = p;
2301
+ __super__.call(this);
2302
+ }
2282
2303
 
2283
- promise.then(
2284
- function (value) {
2285
- subject.onNext(value);
2286
- subject.onCompleted();
2287
- },
2288
- subject.onError.bind(subject));
2304
+ FromPromiseObservable.prototype.subscribeCore = function(o) {
2305
+ this.p.then(function (data) {
2306
+ o.onNext(data);
2307
+ o.onCompleted();
2308
+ }, function (err) { o.onError(err); });
2309
+ return disposableEmpty;
2310
+ };
2289
2311
 
2290
- return subject;
2291
- });
2292
- };
2312
+ return FromPromiseObservable;
2313
+ }(ObservableBase));
2293
2314
 
2315
+ /**
2316
+ * Converts a Promise to an Observable sequence
2317
+ * @param {Promise} An ES6 Compliant promise.
2318
+ * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
2319
+ */
2320
+ var observableFromPromise = Observable.fromPromise = function (promise) {
2321
+ return new FromPromiseObservable(promise);
2322
+ };
2294
2323
  /*
2295
2324
  * Converts an existing observable sequence to an ES6 Compatible Promise
2296
2325
  * @example
@@ -2325,42 +2354,42 @@
2325
2354
  __super__.call(this);
2326
2355
  }
2327
2356
 
2328
- ToArrayObservable.prototype.subscribeCore = function(observer) {
2329
- return this.source.subscribe(new ToArrayObserver(observer));
2357
+ ToArrayObservable.prototype.subscribeCore = function(o) {
2358
+ return this.source.subscribe(new InnerObserver(o));
2330
2359
  };
2331
2360
 
2332
- return ToArrayObservable;
2333
- }(ObservableBase));
2334
-
2335
- function ToArrayObserver(observer) {
2336
- this.observer = observer;
2337
- this.a = [];
2338
- this.isStopped = false;
2339
- }
2340
- ToArrayObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
2341
- ToArrayObserver.prototype.onError = function (e) {
2342
- if (!this.isStopped) {
2343
- this.isStopped = true;
2344
- this.observer.onError(e);
2345
- }
2346
- };
2347
- ToArrayObserver.prototype.onCompleted = function () {
2348
- if (!this.isStopped) {
2349
- this.isStopped = true;
2350
- this.observer.onNext(this.a);
2351
- this.observer.onCompleted();
2352
- }
2353
- };
2354
- ToArrayObserver.prototype.dispose = function () { this.isStopped = true; }
2355
- ToArrayObserver.prototype.fail = function (e) {
2356
- if (!this.isStopped) {
2357
- this.isStopped = true;
2358
- this.observer.onError(e);
2359
- return true;
2361
+ function InnerObserver(o) {
2362
+ this.o = o;
2363
+ this.a = [];
2364
+ this.isStopped = false;
2360
2365
  }
2366
+ InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
2367
+ InnerObserver.prototype.onError = function (e) {
2368
+ if (!this.isStopped) {
2369
+ this.isStopped = true;
2370
+ this.o.onError(e);
2371
+ }
2372
+ };
2373
+ InnerObserver.prototype.onCompleted = function () {
2374
+ if (!this.isStopped) {
2375
+ this.isStopped = true;
2376
+ this.o.onNext(this.a);
2377
+ this.o.onCompleted();
2378
+ }
2379
+ };
2380
+ InnerObserver.prototype.dispose = function () { this.isStopped = true; }
2381
+ InnerObserver.prototype.fail = function (e) {
2382
+ if (!this.isStopped) {
2383
+ this.isStopped = true;
2384
+ this.o.onError(e);
2385
+ return true;
2386
+ }
2387
+
2388
+ return false;
2389
+ };
2361
2390
 
2362
- return false;
2363
- };
2391
+ return ToArrayObservable;
2392
+ }(ObservableBase));
2364
2393
 
2365
2394
  /**
2366
2395
  * Creates an array from an observable sequence.
@@ -2379,7 +2408,7 @@
2379
2408
  * @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable.
2380
2409
  * @returns {Observable} The observable sequence with the specified implementation for the Subscribe method.
2381
2410
  */
2382
- Observable.create = Observable.createWithDisposable = function (subscribe, parent) {
2411
+ Observable.create = function (subscribe, parent) {
2383
2412
  return new AnonymousObservable(subscribe, parent);
2384
2413
  };
2385
2414
 
@@ -2412,26 +2441,29 @@
2412
2441
  }
2413
2442
 
2414
2443
  EmptyObservable.prototype.subscribeCore = function (observer) {
2415
- var sink = new EmptySink(observer, this);
2444
+ var sink = new EmptySink(observer, this.scheduler);
2416
2445
  return sink.run();
2417
2446
  };
2418
2447
 
2419
- function EmptySink(observer, parent) {
2448
+ function EmptySink(observer, scheduler) {
2420
2449
  this.observer = observer;
2421
- this.parent = parent;
2450
+ this.scheduler = scheduler;
2422
2451
  }
2423
2452
 
2424
2453
  function scheduleItem(s, state) {
2425
2454
  state.onCompleted();
2455
+ return disposableEmpty;
2426
2456
  }
2427
2457
 
2428
2458
  EmptySink.prototype.run = function () {
2429
- return this.parent.scheduler.scheduleWithState(this.observer, scheduleItem);
2459
+ return this.scheduler.scheduleWithState(this.observer, scheduleItem);
2430
2460
  };
2431
2461
 
2432
2462
  return EmptyObservable;
2433
2463
  }(ObservableBase));
2434
2464
 
2465
+ var EMPTY_OBSERVABLE = new EmptyObservable(immediateScheduler);
2466
+
2435
2467
  /**
2436
2468
  * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
2437
2469
  *
@@ -2443,7 +2475,7 @@
2443
2475
  */
2444
2476
  var observableEmpty = Observable.empty = function (scheduler) {
2445
2477
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2446
- return new EmptyObservable(scheduler);
2478
+ return scheduler === immediateScheduler ? EMPTY_OBSERVABLE : new EmptyObservable(scheduler);
2447
2479
  };
2448
2480
 
2449
2481
  var FromObservable = (function(__super__) {
@@ -2455,8 +2487,8 @@
2455
2487
  __super__.call(this);
2456
2488
  }
2457
2489
 
2458
- FromObservable.prototype.subscribeCore = function (observer) {
2459
- var sink = new FromSink(observer, this);
2490
+ FromObservable.prototype.subscribeCore = function (o) {
2491
+ var sink = new FromSink(o, this);
2460
2492
  return sink.run();
2461
2493
  };
2462
2494
 
@@ -2464,38 +2496,30 @@
2464
2496
  }(ObservableBase));
2465
2497
 
2466
2498
  var FromSink = (function () {
2467
- function FromSink(observer, parent) {
2468
- this.observer = observer;
2499
+ function FromSink(o, parent) {
2500
+ this.o = o;
2469
2501
  this.parent = parent;
2470
2502
  }
2471
2503
 
2472
2504
  FromSink.prototype.run = function () {
2473
2505
  var list = Object(this.parent.iterable),
2474
2506
  it = getIterable(list),
2475
- observer = this.observer,
2507
+ o = this.o,
2476
2508
  mapper = this.parent.mapper;
2477
2509
 
2478
2510
  function loopRecursive(i, recurse) {
2479
- try {
2480
- var next = it.next();
2481
- } catch (e) {
2482
- return observer.onError(e);
2483
- }
2484
- if (next.done) {
2485
- return observer.onCompleted();
2486
- }
2511
+ var next = tryCatch(it.next).call(it);
2512
+ if (next === errorObj) { return o.onError(next.e); }
2513
+ if (next.done) { return o.onCompleted(); }
2487
2514
 
2488
2515
  var result = next.value;
2489
2516
 
2490
- if (mapper) {
2491
- try {
2492
- result = mapper(result, i);
2493
- } catch (e) {
2494
- return observer.onError(e);
2495
- }
2517
+ if (isFunction(mapper)) {
2518
+ result = tryCatch(mapper)(result, i);
2519
+ if (result === errorObj) { return o.onError(result.e); }
2496
2520
  }
2497
2521
 
2498
- observer.onNext(result);
2522
+ o.onNext(result);
2499
2523
  recurse(i + 1);
2500
2524
  }
2501
2525
 
@@ -2507,7 +2531,7 @@
2507
2531
 
2508
2532
  var maxSafeInteger = Math.pow(2, 53) - 1;
2509
2533
 
2510
- function StringIterable(str) {
2534
+ function StringIterable(s) {
2511
2535
  this._s = s;
2512
2536
  }
2513
2537
 
@@ -2515,7 +2539,7 @@
2515
2539
  return new StringIterator(this._s);
2516
2540
  };
2517
2541
 
2518
- function StringIterator(str) {
2542
+ function StringIterator(s) {
2519
2543
  this._s = s;
2520
2544
  this._l = s.length;
2521
2545
  this._i = 0;
@@ -2710,12 +2734,14 @@
2710
2734
  return NeverObservable;
2711
2735
  }(ObservableBase));
2712
2736
 
2737
+ var NEVER_OBSERVABLE = new NeverObservable();
2738
+
2713
2739
  /**
2714
2740
  * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
2715
2741
  * @returns {Observable} An observable sequence whose observers will never get called.
2716
2742
  */
2717
2743
  var observableNever = Observable.never = function () {
2718
- return new NeverObservable();
2744
+ return NEVER_OBSERVABLE;
2719
2745
  };
2720
2746
 
2721
2747
  function observableOf (scheduler, array) {
@@ -2796,7 +2822,7 @@
2796
2822
  inherits(RangeObservable, __super__);
2797
2823
  function RangeObservable(start, count, scheduler) {
2798
2824
  this.start = start;
2799
- this.count = count;
2825
+ this.rangeCount = count;
2800
2826
  this.scheduler = scheduler;
2801
2827
  __super__.call(this);
2802
2828
  }
@@ -2816,7 +2842,7 @@
2816
2842
  }
2817
2843
 
2818
2844
  RangeSink.prototype.run = function () {
2819
- var start = this.parent.start, count = this.parent.count, observer = this.observer;
2845
+ var start = this.parent.start, count = this.parent.rangeCount, observer = this.observer;
2820
2846
  function loopRecursive(i, recurse) {
2821
2847
  if (i < count) {
2822
2848
  observer.onNext(start + i);
@@ -2901,23 +2927,28 @@
2901
2927
  }
2902
2928
 
2903
2929
  JustObservable.prototype.subscribeCore = function (observer) {
2904
- var sink = new JustSink(observer, this);
2930
+ var sink = new JustSink(observer, this.value, this.scheduler);
2905
2931
  return sink.run();
2906
2932
  };
2907
2933
 
2908
- function JustSink(observer, parent) {
2934
+ function JustSink(observer, value, scheduler) {
2909
2935
  this.observer = observer;
2910
- this.parent = parent;
2936
+ this.value = value;
2937
+ this.scheduler = scheduler;
2911
2938
  }
2912
2939
 
2913
2940
  function scheduleItem(s, state) {
2914
2941
  var value = state[0], observer = state[1];
2915
2942
  observer.onNext(value);
2916
2943
  observer.onCompleted();
2944
+ return disposableEmpty;
2917
2945
  }
2918
2946
 
2919
2947
  JustSink.prototype.run = function () {
2920
- return this.parent.scheduler.scheduleWithState([this.parent.value, this.observer], scheduleItem);
2948
+ var state = [this.value, this.observer];
2949
+ return this.scheduler === immediateScheduler ?
2950
+ scheduleItem(null, state) :
2951
+ this.scheduler.scheduleWithState(state, scheduleItem);
2921
2952
  };
2922
2953
 
2923
2954
  return JustObservable;
@@ -2930,7 +2961,7 @@
2930
2961
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2931
2962
  * @returns {Observable} An observable sequence containing the single specified element.
2932
2963
  */
2933
- var observableReturn = Observable['return'] = Observable.just = Observable.returnValue = function (value, scheduler) {
2964
+ var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
2934
2965
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2935
2966
  return new JustObservable(value, scheduler);
2936
2967
  };
@@ -2943,23 +2974,23 @@
2943
2974
  __super__.call(this);
2944
2975
  }
2945
2976
 
2946
- ThrowObservable.prototype.subscribeCore = function (observer) {
2947
- var sink = new ThrowSink(observer, this);
2977
+ ThrowObservable.prototype.subscribeCore = function (o) {
2978
+ var sink = new ThrowSink(o, this);
2948
2979
  return sink.run();
2949
2980
  };
2950
2981
 
2951
- function ThrowSink(observer, parent) {
2952
- this.observer = observer;
2953
- this.parent = parent;
2982
+ function ThrowSink(o, p) {
2983
+ this.o = o;
2984
+ this.p = p;
2954
2985
  }
2955
2986
 
2956
2987
  function scheduleItem(s, state) {
2957
- var error = state[0], observer = state[1];
2958
- observer.onError(error);
2988
+ var e = state[0], o = state[1];
2989
+ o.onError(e);
2959
2990
  }
2960
2991
 
2961
2992
  ThrowSink.prototype.run = function () {
2962
- return this.parent.scheduler.scheduleWithState([this.parent.error, this.observer], scheduleItem);
2993
+ return this.p.scheduler.scheduleWithState([this.p.error, this.o], scheduleItem);
2963
2994
  };
2964
2995
 
2965
2996
  return ThrowObservable;
@@ -2972,7 +3003,7 @@
2972
3003
  * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
2973
3004
  * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
2974
3005
  */
2975
- var observableThrow = Observable['throw'] = Observable.throwError = Observable.throwException = function (error, scheduler) {
3006
+ var observableThrow = Observable['throw'] = function (error, scheduler) {
2976
3007
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2977
3008
  return new ThrowObservable(error, scheduler);
2978
3009
  };
@@ -2984,16 +3015,18 @@
2984
3015
  * @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
2985
3016
  */
2986
3017
  Observable.using = function (resourceFactory, observableFactory) {
2987
- return new AnonymousObservable(function (observer) {
2988
- var disposable = disposableEmpty, resource, source;
2989
- try {
2990
- resource = resourceFactory();
2991
- resource && (disposable = resource);
2992
- source = observableFactory(resource);
2993
- } catch (exception) {
2994
- return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
3018
+ return new AnonymousObservable(function (o) {
3019
+ var disposable = disposableEmpty;
3020
+ var resource = tryCatch(resourceFactory)();
3021
+ if (resource === errorObj) {
3022
+ return new CompositeDisposable(observableThrow(resource.e).subscribe(o), disposable);
2995
3023
  }
2996
- return new CompositeDisposable(source.subscribe(observer), disposable);
3024
+ resource && (disposable = resource);
3025
+ var source = tryCatch(observableFactory)(resource);
3026
+ if (source === errorObj) {
3027
+ return new CompositeDisposable(observableThrow(source.e).subscribe(o), disposable);
3028
+ }
3029
+ return new CompositeDisposable(source.subscribe(o), disposable);
2997
3030
  });
2998
3031
  };
2999
3032
 
@@ -3026,101 +3059,103 @@
3026
3059
  }
3027
3060
  }
3028
3061
 
3029
- leftSubscription.setDisposable(leftSource.subscribe(function (left) {
3030
- choiceL();
3031
- if (choice === leftChoice) {
3032
- observer.onNext(left);
3033
- }
3034
- }, function (err) {
3035
- choiceL();
3036
- if (choice === leftChoice) {
3037
- observer.onError(err);
3038
- }
3039
- }, function () {
3040
- choiceL();
3041
- if (choice === leftChoice) {
3042
- observer.onCompleted();
3043
- }
3044
- }));
3045
-
3046
- rightSubscription.setDisposable(rightSource.subscribe(function (right) {
3047
- choiceR();
3048
- if (choice === rightChoice) {
3049
- observer.onNext(right);
3050
- }
3051
- }, function (err) {
3052
- choiceR();
3053
- if (choice === rightChoice) {
3054
- observer.onError(err);
3062
+ var leftSubscribe = observerCreate(
3063
+ function (left) {
3064
+ choiceL();
3065
+ choice === leftChoice && observer.onNext(left);
3066
+ },
3067
+ function (e) {
3068
+ choiceL();
3069
+ choice === leftChoice && observer.onError(e);
3070
+ },
3071
+ function () {
3072
+ choiceL();
3073
+ choice === leftChoice && observer.onCompleted();
3055
3074
  }
3056
- }, function () {
3057
- choiceR();
3058
- if (choice === rightChoice) {
3059
- observer.onCompleted();
3075
+ );
3076
+ var rightSubscribe = observerCreate(
3077
+ function (right) {
3078
+ choiceR();
3079
+ choice === rightChoice && observer.onNext(right);
3080
+ },
3081
+ function (e) {
3082
+ choiceR();
3083
+ choice === rightChoice && observer.onError(e);
3084
+ },
3085
+ function () {
3086
+ choiceR();
3087
+ choice === rightChoice && observer.onCompleted();
3060
3088
  }
3061
- }));
3089
+ );
3090
+
3091
+ leftSubscription.setDisposable(leftSource.subscribe(leftSubscribe));
3092
+ rightSubscription.setDisposable(rightSource.subscribe(rightSubscribe));
3062
3093
 
3063
3094
  return new CompositeDisposable(leftSubscription, rightSubscription);
3064
3095
  });
3065
3096
  };
3066
3097
 
3098
+ function amb(p, c) { return p.amb(c); }
3099
+
3067
3100
  /**
3068
3101
  * Propagates the observable sequence or Promise that reacts first.
3069
- *
3070
- * @example
3071
- * var = Rx.Observable.amb(xs, ys, zs);
3072
3102
  * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
3073
3103
  */
3074
3104
  Observable.amb = function () {
3075
- var acc = observableNever(), items = [];
3105
+ var acc = observableNever(), items;
3076
3106
  if (Array.isArray(arguments[0])) {
3077
3107
  items = arguments[0];
3078
3108
  } else {
3079
- for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
3080
- }
3081
-
3082
- function func(previous, current) {
3083
- return previous.amb(current);
3109
+ var len = arguments.length;
3110
+ items = new Array(items);
3111
+ for(var i = 0; i < len; i++) { items[i] = arguments[i]; }
3084
3112
  }
3085
3113
  for (var i = 0, len = items.length; i < len; i++) {
3086
- acc = func(acc, items[i]);
3114
+ acc = amb(acc, items[i]);
3087
3115
  }
3088
3116
  return acc;
3089
3117
  };
3090
3118
 
3119
+ var CatchObserver = (function(__super__) {
3120
+ inherits(CatchObserver, __super__);
3121
+ function CatchObserver(o, s, fn) {
3122
+ this._o = o;
3123
+ this._s = s;
3124
+ this._fn = fn;
3125
+ __super__.call(this);
3126
+ }
3127
+
3128
+ CatchObserver.prototype.next = function (x) { this._o.onNext(x); };
3129
+ CatchObserver.prototype.completed = function () { return this._o.onCompleted(); };
3130
+ CatchObserver.prototype.error = function (e) {
3131
+ var result = tryCatch(this._fn)(e);
3132
+ if (result === errorObj) { return this._o.onError(result.e); }
3133
+ isPromise(result) && (result = observableFromPromise(result));
3134
+
3135
+ var d = new SingleAssignmentDisposable();
3136
+ this._s.setDisposable(d);
3137
+ d.setDisposable(result.subscribe(this._o));
3138
+ };
3139
+
3140
+ return CatchObserver;
3141
+ }(AbstractObserver));
3142
+
3091
3143
  function observableCatchHandler(source, handler) {
3092
3144
  return new AnonymousObservable(function (o) {
3093
3145
  var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
3094
3146
  subscription.setDisposable(d1);
3095
- d1.setDisposable(source.subscribe(function (x) { o.onNext(x); }, function (e) {
3096
- try {
3097
- var result = handler(e);
3098
- } catch (ex) {
3099
- return o.onError(ex);
3100
- }
3101
- isPromise(result) && (result = observableFromPromise(result));
3102
-
3103
- var d = new SingleAssignmentDisposable();
3104
- subscription.setDisposable(d);
3105
- d.setDisposable(result.subscribe(o));
3106
- }, function (x) { o.onCompleted(x); }));
3107
-
3147
+ d1.setDisposable(source.subscribe(new CatchObserver(o, subscription, handler)));
3108
3148
  return subscription;
3109
3149
  }, source);
3110
3150
  }
3111
3151
 
3112
3152
  /**
3113
3153
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
3114
- * @example
3115
- * 1 - xs.catchException(ys)
3116
- * 2 - xs.catchException(function (ex) { return ys(ex); })
3117
3154
  * @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.
3118
3155
  * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
3119
3156
  */
3120
- observableProto['catch'] = observableProto.catchError = observableProto.catchException = function (handlerOrSecond) {
3121
- return typeof handlerOrSecond === 'function' ?
3122
- observableCatchHandler(this, handlerOrSecond) :
3123
- observableCatch([this, handlerOrSecond]);
3157
+ observableProto['catch'] = function (handlerOrSecond) {
3158
+ return isFunction(handlerOrSecond) ? observableCatchHandler(this, handlerOrSecond) : observableCatch([this, handlerOrSecond]);
3124
3159
  };
3125
3160
 
3126
3161
  /**
@@ -3128,12 +3163,14 @@
3128
3163
  * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
3129
3164
  * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
3130
3165
  */
3131
- var observableCatch = Observable.catchError = Observable['catch'] = Observable.catchException = function () {
3132
- var items = [];
3166
+ var observableCatch = Observable['catch'] = function () {
3167
+ var items;
3133
3168
  if (Array.isArray(arguments[0])) {
3134
3169
  items = arguments[0];
3135
3170
  } else {
3136
- for(var i = 0, len = arguments.length; i < len; i++) { items.push(arguments[i]); }
3171
+ var len = arguments.length;
3172
+ items = new Array(len);
3173
+ for(var i = 0; i < len; i++) { items[i] = arguments[i]; }
3137
3174
  }
3138
3175
  return enumerableOf(items).catchError();
3139
3176
  };
@@ -3158,6 +3195,13 @@
3158
3195
  return combineLatest.apply(this, args);
3159
3196
  };
3160
3197
 
3198
+ function falseFactory() { return false; }
3199
+ function argumentsToArray() {
3200
+ var len = arguments.length, args = new Array(len);
3201
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3202
+ return args;
3203
+ }
3204
+
3161
3205
  /**
3162
3206
  * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences or Promises produces an element.
3163
3207
  *
@@ -3169,12 +3213,11 @@
3169
3213
  var combineLatest = Observable.combineLatest = function () {
3170
3214
  var len = arguments.length, args = new Array(len);
3171
3215
  for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3172
- var resultSelector = args.pop();
3216
+ var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
3173
3217
  Array.isArray(args[0]) && (args = args[0]);
3174
3218
 
3175
3219
  return new AnonymousObservable(function (o) {
3176
3220
  var n = args.length,
3177
- falseFactory = function () { return false; },
3178
3221
  hasValue = arrayInitialize(n, falseFactory),
3179
3222
  hasValueAll = false,
3180
3223
  isDone = arrayInitialize(n, falseFactory),
@@ -3229,6 +3272,52 @@
3229
3272
  return observableConcat.apply(null, args);
3230
3273
  };
3231
3274
 
3275
+ var ConcatObservable = (function(__super__) {
3276
+ inherits(ConcatObservable, __super__);
3277
+ function ConcatObservable(sources) {
3278
+ this.sources = sources;
3279
+ __super__.call(this);
3280
+ }
3281
+
3282
+ ConcatObservable.prototype.subscribeCore = function(o) {
3283
+ var sink = new ConcatSink(this.sources, o);
3284
+ return sink.run();
3285
+ };
3286
+
3287
+ function ConcatSink(sources, o) {
3288
+ this.sources = sources;
3289
+ this.o = o;
3290
+ }
3291
+ ConcatSink.prototype.run = function () {
3292
+ var isDisposed, subscription = new SerialDisposable(), sources = this.sources, length = sources.length, o = this.o;
3293
+ var cancelable = immediateScheduler.scheduleRecursiveWithState(0, function (i, self) {
3294
+ if (isDisposed) { return; }
3295
+ if (i === length) {
3296
+ return o.onCompleted();
3297
+ }
3298
+
3299
+ // Check if promise
3300
+ var currentValue = sources[i];
3301
+ isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
3302
+
3303
+ var d = new SingleAssignmentDisposable();
3304
+ subscription.setDisposable(d);
3305
+ d.setDisposable(currentValue.subscribe(
3306
+ function (x) { o.onNext(x); },
3307
+ function (e) { o.onError(e); },
3308
+ function () { self(i + 1); }
3309
+ ));
3310
+ });
3311
+
3312
+ return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
3313
+ isDisposed = true;
3314
+ }));
3315
+ };
3316
+
3317
+
3318
+ return ConcatObservable;
3319
+ }(ObservableBase));
3320
+
3232
3321
  /**
3233
3322
  * Concatenates all the observable sequences.
3234
3323
  * @param {Array | Arguments} args Arguments or an array to concat to the observable sequence.
@@ -3242,14 +3331,14 @@
3242
3331
  args = new Array(arguments.length);
3243
3332
  for(var i = 0, len = arguments.length; i < len; i++) { args[i] = arguments[i]; }
3244
3333
  }
3245
- return enumerableOf(args).concat();
3334
+ return new ConcatObservable(args);
3246
3335
  };
3247
3336
 
3248
3337
  /**
3249
3338
  * Concatenates an observable sequence of observable sequences.
3250
3339
  * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
3251
3340
  */
3252
- observableProto.concatAll = observableProto.concatObservable = function () {
3341
+ observableProto.concatAll = function () {
3253
3342
  return this.merge(1);
3254
3343
  };
3255
3344
 
@@ -3499,11 +3588,6 @@
3499
3588
  return g;
3500
3589
  };
3501
3590
 
3502
- return MergeAllObservable;
3503
- }(ObservableBase));
3504
-
3505
- var MergeAllObserver = (function() {
3506
-
3507
3591
  function MergeAllObserver(o, g) {
3508
3592
  this.o = o;
3509
3593
  this.g = g;
@@ -3517,7 +3601,7 @@
3517
3601
 
3518
3602
  isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3519
3603
 
3520
- sad.setDisposable(innerSource.subscribe(new InnerObserver(this, this.g, sad)));
3604
+ sad.setDisposable(innerSource.subscribe(new InnerObserver(this, sad)));
3521
3605
  };
3522
3606
  MergeAllObserver.prototype.onError = function (e) {
3523
3607
  if(!this.isStopped) {
@@ -3543,9 +3627,8 @@
3543
3627
  return false;
3544
3628
  };
3545
3629
 
3546
- function InnerObserver(parent, g, sad) {
3630
+ function InnerObserver(parent, sad) {
3547
3631
  this.parent = parent;
3548
- this.g = g;
3549
3632
  this.sad = sad;
3550
3633
  this.isStopped = false;
3551
3634
  }
@@ -3575,15 +3658,14 @@
3575
3658
  return false;
3576
3659
  };
3577
3660
 
3578
- return MergeAllObserver;
3579
-
3580
- }());
3661
+ return MergeAllObservable;
3662
+ }(ObservableBase));
3581
3663
 
3582
3664
  /**
3583
3665
  * Merges an observable sequence of observable sequences into an observable sequence.
3584
3666
  * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
3585
3667
  */
3586
- observableProto.mergeAll = observableProto.mergeObservable = function () {
3668
+ observableProto.mergeAll = function () {
3587
3669
  return new MergeAllObservable(this);
3588
3670
  };
3589
3671
 
@@ -3660,87 +3742,171 @@
3660
3742
  }, source);
3661
3743
  };
3662
3744
 
3745
+ var SwitchObservable = (function(__super__) {
3746
+ inherits(SwitchObservable, __super__);
3747
+ function SwitchObservable(source) {
3748
+ this.source = source;
3749
+ __super__.call(this);
3750
+ }
3751
+
3752
+ SwitchObservable.prototype.subscribeCore = function (o) {
3753
+ var inner = new SerialDisposable(), s = this.source.subscribe(new SwitchObserver(o, inner));
3754
+ return new CompositeDisposable(s, inner);
3755
+ };
3756
+
3757
+ function SwitchObserver(o, inner) {
3758
+ this.o = o;
3759
+ this.inner = inner;
3760
+ this.stopped = false;
3761
+ this.latest = 0;
3762
+ this.hasLatest = false;
3763
+ this.isStopped = false;
3764
+ }
3765
+ SwitchObserver.prototype.onNext = function (innerSource) {
3766
+ if (this.isStopped) { return; }
3767
+ var d = new SingleAssignmentDisposable(), id = ++this.latest;
3768
+ this.hasLatest = true;
3769
+ this.inner.setDisposable(d);
3770
+ isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3771
+ d.setDisposable(innerSource.subscribe(new InnerObserver(this, id)));
3772
+ };
3773
+ SwitchObserver.prototype.onError = function (e) {
3774
+ if (!this.isStopped) {
3775
+ this.isStopped = true;
3776
+ this.o.onError(e);
3777
+ }
3778
+ };
3779
+ SwitchObserver.prototype.onCompleted = function () {
3780
+ if (!this.isStopped) {
3781
+ this.isStopped = true;
3782
+ this.stopped = true;
3783
+ !this.hasLatest && this.o.onCompleted();
3784
+ }
3785
+ };
3786
+ SwitchObserver.prototype.dispose = function () { this.isStopped = true; };
3787
+ SwitchObserver.prototype.fail = function (e) {
3788
+ if(!this.isStopped) {
3789
+ this.isStopped = true;
3790
+ this.o.onError(e);
3791
+ return true;
3792
+ }
3793
+ return false;
3794
+ };
3795
+
3796
+ function InnerObserver(parent, id) {
3797
+ this.parent = parent;
3798
+ this.id = id;
3799
+ this.isStopped = false;
3800
+ }
3801
+ InnerObserver.prototype.onNext = function (x) {
3802
+ if (this.isStopped) { return; }
3803
+ this.parent.latest === this.id && this.parent.o.onNext(x);
3804
+ };
3805
+ InnerObserver.prototype.onError = function (e) {
3806
+ if (!this.isStopped) {
3807
+ this.isStopped = true;
3808
+ this.parent.latest === this.id && this.parent.o.onError(e);
3809
+ }
3810
+ };
3811
+ InnerObserver.prototype.onCompleted = function () {
3812
+ if (!this.isStopped) {
3813
+ this.isStopped = true;
3814
+ if (this.parent.latest === this.id) {
3815
+ this.parent.hasLatest = false;
3816
+ this.parent.isStopped && this.parent.o.onCompleted();
3817
+ }
3818
+ }
3819
+ };
3820
+ InnerObserver.prototype.dispose = function () { this.isStopped = true; }
3821
+ InnerObserver.prototype.fail = function (e) {
3822
+ if(!this.isStopped) {
3823
+ this.isStopped = true;
3824
+ this.parent.o.onError(e);
3825
+ return true;
3826
+ }
3827
+ return false;
3828
+ };
3829
+
3830
+ return SwitchObservable;
3831
+ }(ObservableBase));
3832
+
3663
3833
  /**
3664
- * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3665
- * @returns {Observable} The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3666
- */
3834
+ * Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
3835
+ * @returns {Observable} The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
3836
+ */
3667
3837
  observableProto['switch'] = observableProto.switchLatest = function () {
3668
- var sources = this;
3669
- return new AnonymousObservable(function (observer) {
3670
- var hasLatest = false,
3671
- innerSubscription = new SerialDisposable(),
3672
- isStopped = false,
3673
- latest = 0,
3674
- subscription = sources.subscribe(
3675
- function (innerSource) {
3676
- var d = new SingleAssignmentDisposable(), id = ++latest;
3677
- hasLatest = true;
3678
- innerSubscription.setDisposable(d);
3679
-
3680
- // Check if Promise or Observable
3681
- isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
3682
-
3683
- d.setDisposable(innerSource.subscribe(
3684
- function (x) { latest === id && observer.onNext(x); },
3685
- function (e) { latest === id && observer.onError(e); },
3686
- function () {
3687
- if (latest === id) {
3688
- hasLatest = false;
3689
- isStopped && observer.onCompleted();
3690
- }
3691
- }));
3692
- },
3693
- function (e) { observer.onError(e); },
3694
- function () {
3695
- isStopped = true;
3696
- !hasLatest && observer.onCompleted();
3697
- });
3698
- return new CompositeDisposable(subscription, innerSubscription);
3699
- }, sources);
3838
+ return new SwitchObservable(this);
3700
3839
  };
3701
3840
 
3841
+ var TakeUntilObservable = (function(__super__) {
3842
+ inherits(TakeUntilObservable, __super__);
3843
+
3844
+ function TakeUntilObservable(source, other) {
3845
+ this.source = source;
3846
+ this.other = isPromise(other) ? observableFromPromise(other) : other;
3847
+ __super__.call(this);
3848
+ }
3849
+
3850
+ TakeUntilObservable.prototype.subscribeCore = function(o) {
3851
+ return new CompositeDisposable(
3852
+ this.source.subscribe(o),
3853
+ this.other.subscribe(new InnerObserver(o))
3854
+ );
3855
+ };
3856
+
3857
+ function InnerObserver(o) {
3858
+ this.o = o;
3859
+ this.isStopped = false;
3860
+ }
3861
+ InnerObserver.prototype.onNext = function (x) {
3862
+ if (this.isStopped) { return; }
3863
+ this.o.onCompleted();
3864
+ };
3865
+ InnerObserver.prototype.onError = function (err) {
3866
+ if (!this.isStopped) {
3867
+ this.isStopped = true;
3868
+ this.o.onError(err);
3869
+ }
3870
+ };
3871
+ InnerObserver.prototype.onCompleted = function () {
3872
+ !this.isStopped && (this.isStopped = true);
3873
+ };
3874
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
3875
+ InnerObserver.prototype.fail = function (e) {
3876
+ if (!this.isStopped) {
3877
+ this.isStopped = true;
3878
+ this.o.onError(e);
3879
+ return true;
3880
+ }
3881
+ return false;
3882
+ };
3883
+
3884
+ return TakeUntilObservable;
3885
+ }(ObservableBase));
3886
+
3702
3887
  /**
3703
3888
  * Returns the values from the source observable sequence until the other observable sequence produces a value.
3704
3889
  * @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence.
3705
3890
  * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
3706
3891
  */
3707
3892
  observableProto.takeUntil = function (other) {
3708
- var source = this;
3709
- return new AnonymousObservable(function (o) {
3710
- isPromise(other) && (other = observableFromPromise(other));
3711
- return new CompositeDisposable(
3712
- source.subscribe(o),
3713
- other.subscribe(function () { o.onCompleted(); }, function (e) { o.onError(e); }, noop)
3714
- );
3715
- }, source);
3893
+ return new TakeUntilObservable(this, other);
3716
3894
  };
3717
3895
 
3896
+ function falseFactory() { return false; }
3897
+
3718
3898
  /**
3719
3899
  * Merges the specified observable sequences into one observable sequence by using the selector function only when the (first) source observable sequence produces an element.
3720
- *
3721
- * @example
3722
- * 1 - obs = obs1.withLatestFrom(obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
3723
- * 2 - obs = obs1.withLatestFrom([obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
3724
3900
  * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3725
3901
  */
3726
3902
  observableProto.withLatestFrom = function () {
3727
3903
  var len = arguments.length, args = new Array(len)
3728
3904
  for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3729
3905
  var resultSelector = args.pop(), source = this;
3730
-
3731
- if (typeof source === 'undefined') {
3732
- throw new Error('Source observable not found for withLatestFrom().');
3733
- }
3734
- if (typeof resultSelector !== 'function') {
3735
- throw new Error('withLatestFrom() expects a resultSelector function.');
3736
- }
3737
- if (Array.isArray(args[0])) {
3738
- args = args[0];
3739
- }
3906
+ Array.isArray(args[0]) && (args = args[0]);
3740
3907
 
3741
3908
  return new AnonymousObservable(function (observer) {
3742
- var falseFactory = function () { return false; },
3743
- n = args.length,
3909
+ var n = args.length,
3744
3910
  hasValue = arrayInitialize(n, falseFactory),
3745
3911
  hasValueAll = false,
3746
3912
  values = new Array(n);
@@ -3754,24 +3920,19 @@
3754
3920
  values[i] = x;
3755
3921
  hasValue[i] = true;
3756
3922
  hasValueAll = hasValue.every(identity);
3757
- }, observer.onError.bind(observer), function () {}));
3923
+ }, function (e) { observer.onError(e); }, noop));
3758
3924
  subscriptions[i] = sad;
3759
3925
  }(idx));
3760
3926
  }
3761
3927
 
3762
3928
  var sad = new SingleAssignmentDisposable();
3763
3929
  sad.setDisposable(source.subscribe(function (x) {
3764
- var res;
3765
3930
  var allValues = [x].concat(values);
3766
- if (!hasValueAll) return;
3767
- try {
3768
- res = resultSelector.apply(null, allValues);
3769
- } catch (ex) {
3770
- observer.onError(ex);
3771
- return;
3772
- }
3931
+ if (!hasValueAll) { return; }
3932
+ var res = tryCatch(resultSelector).apply(null, allValues);
3933
+ if (res === errorObj) { return observer.onError(res.e); }
3773
3934
  observer.onNext(res);
3774
- }, observer.onError.bind(observer), function () {
3935
+ }, function (e) { observer.onError(e); }, function () {
3775
3936
  observer.onCompleted();
3776
3937
  }));
3777
3938
  subscriptions[n] = sad;
@@ -3780,83 +3941,54 @@
3780
3941
  }, this);
3781
3942
  };
3782
3943
 
3783
- function zipArray(second, resultSelector) {
3784
- var first = this;
3785
- return new AnonymousObservable(function (observer) {
3786
- var index = 0, len = second.length;
3787
- return first.subscribe(function (left) {
3788
- if (index < len) {
3789
- var right = second[index++], result;
3790
- try {
3791
- result = resultSelector(left, right);
3792
- } catch (e) {
3793
- return observer.onError(e);
3794
- }
3795
- observer.onNext(result);
3796
- } else {
3797
- observer.onCompleted();
3798
- }
3799
- }, function (e) { observer.onError(e); }, function () { observer.onCompleted(); });
3800
- }, first);
3801
- }
3802
-
3803
3944
  function falseFactory() { return false; }
3804
3945
  function emptyArrayFactory() { return []; }
3946
+ function argumentsToArray() {
3947
+ var len = arguments.length, args = new Array(len);
3948
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3949
+ return args;
3950
+ }
3805
3951
 
3806
3952
  /**
3807
3953
  * 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.
3808
3954
  * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
3809
- *
3810
- * @example
3811
- * 1 - res = obs1.zip(obs2, fn);
3812
- * 1 - res = x1.zip([1,2,3], fn);
3813
3955
  * @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
3814
3956
  */
3815
3957
  observableProto.zip = function () {
3816
- if (Array.isArray(arguments[0])) { return zipArray.apply(this, arguments); }
3958
+ if (arguments.length === 0) { throw new Error('invalid arguments'); }
3959
+
3817
3960
  var len = arguments.length, args = new Array(len);
3818
3961
  for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
3962
+ var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
3963
+ Array.isArray(args[0]) && (args = args[0]);
3819
3964
 
3820
- var parent = this, resultSelector = args.pop();
3965
+ var parent = this;
3821
3966
  args.unshift(parent);
3822
- return new AnonymousObservable(function (observer) {
3967
+ return new AnonymousObservable(function (o) {
3823
3968
  var n = args.length,
3824
3969
  queues = arrayInitialize(n, emptyArrayFactory),
3825
3970
  isDone = arrayInitialize(n, falseFactory);
3826
3971
 
3827
- function next(i) {
3828
- var res, queuedValues;
3829
- if (queues.every(function (x) { return x.length > 0; })) {
3830
- try {
3831
- queuedValues = queues.map(function (x) { return x.shift(); });
3832
- res = resultSelector.apply(parent, queuedValues);
3833
- } catch (ex) {
3834
- observer.onError(ex);
3835
- return;
3836
- }
3837
- observer.onNext(res);
3838
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
3839
- observer.onCompleted();
3840
- }
3841
- };
3842
-
3843
- function done(i) {
3844
- isDone[i] = true;
3845
- if (isDone.every(function (x) { return x; })) {
3846
- observer.onCompleted();
3847
- }
3848
- }
3849
-
3850
3972
  var subscriptions = new Array(n);
3851
3973
  for (var idx = 0; idx < n; idx++) {
3852
3974
  (function (i) {
3853
3975
  var source = args[i], sad = new SingleAssignmentDisposable();
3976
+
3854
3977
  isPromise(source) && (source = observableFromPromise(source));
3978
+
3855
3979
  sad.setDisposable(source.subscribe(function (x) {
3856
3980
  queues[i].push(x);
3857
- next(i);
3858
- }, function (e) { observer.onError(e); }, function () {
3859
- done(i);
3981
+ if (queues.every(function (x) { return x.length > 0; })) {
3982
+ var queuedValues = queues.map(function (x) { return x.shift(); }),
3983
+ res = tryCatch(resultSelector).apply(parent, queuedValues);
3984
+ if (res === errorObj) { return o.onError(res.e); }
3985
+ o.onNext(res);
3986
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
3987
+ o.onCompleted();
3988
+ }
3989
+ }, function (e) { o.onError(e); }, function () {
3990
+ isDone[i] = true;
3991
+ isDone.every(identity) && o.onCompleted();
3860
3992
  }));
3861
3993
  subscriptions[i] = sad;
3862
3994
  })(idx);
@@ -3879,88 +4011,88 @@
3879
4011
  return first.zip.apply(first, args);
3880
4012
  };
3881
4013
 
3882
- /**
3883
- * Merges the specified observable sequences into one observable sequence by emitting a list with the elements of the observable sequences at corresponding indexes.
3884
- * @param arguments Observable sources.
3885
- * @returns {Observable} An observable sequence containing lists of elements at corresponding indexes.
3886
- */
3887
- Observable.zipArray = function () {
3888
- var sources;
3889
- if (Array.isArray(arguments[0])) {
3890
- sources = arguments[0];
3891
- } else {
3892
- var len = arguments.length;
3893
- sources = new Array(len);
3894
- for(var i = 0; i < len; i++) { sources[i] = arguments[i]; }
4014
+ function falseFactory() { return false; }
4015
+ function emptyArrayFactory() { return []; }
4016
+ function argumentsToArray() {
4017
+ var len = arguments.length, args = new Array(len);
4018
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
4019
+ return args;
4020
+ }
4021
+
4022
+ /**
4023
+ * 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.
4024
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
4025
+ * @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
4026
+ */
4027
+ observableProto.zipIterable = function () {
4028
+ if (arguments.length === 0) { throw new Error('invalid arguments'); }
4029
+
4030
+ var len = arguments.length, args = new Array(len);
4031
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
4032
+ var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
4033
+
4034
+ var parent = this;
4035
+ args.unshift(parent);
4036
+ return new AnonymousObservable(function (o) {
4037
+ var n = args.length,
4038
+ queues = arrayInitialize(n, emptyArrayFactory),
4039
+ isDone = arrayInitialize(n, falseFactory);
4040
+
4041
+ var subscriptions = new Array(n);
4042
+ for (var idx = 0; idx < n; idx++) {
4043
+ (function (i) {
4044
+ var source = args[i], sad = new SingleAssignmentDisposable();
4045
+
4046
+ (isArrayLike(source) || isIterable(source)) && (source = observableFrom(source));
4047
+
4048
+ sad.setDisposable(source.subscribe(function (x) {
4049
+ queues[i].push(x);
4050
+ if (queues.every(function (x) { return x.length > 0; })) {
4051
+ var queuedValues = queues.map(function (x) { return x.shift(); }),
4052
+ res = tryCatch(resultSelector).apply(parent, queuedValues);
4053
+ if (res === errorObj) { return o.onError(res.e); }
4054
+ o.onNext(res);
4055
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
4056
+ o.onCompleted();
4057
+ }
4058
+ }, function (e) { o.onError(e); }, function () {
4059
+ isDone[i] = true;
4060
+ isDone.every(identity) && o.onCompleted();
4061
+ }));
4062
+ subscriptions[i] = sad;
4063
+ })(idx);
3895
4064
  }
3896
- return new AnonymousObservable(function (observer) {
3897
- var n = sources.length,
3898
- queues = arrayInitialize(n, function () { return []; }),
3899
- isDone = arrayInitialize(n, function () { return false; });
3900
4065
 
3901
- function next(i) {
3902
- if (queues.every(function (x) { return x.length > 0; })) {
3903
- var res = queues.map(function (x) { return x.shift(); });
3904
- observer.onNext(res);
3905
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
3906
- observer.onCompleted();
3907
- return;
3908
- }
3909
- };
4066
+ return new CompositeDisposable(subscriptions);
4067
+ }, parent);
4068
+ };
3910
4069
 
3911
- function done(i) {
3912
- isDone[i] = true;
3913
- if (isDone.every(identity)) {
3914
- observer.onCompleted();
3915
- return;
3916
- }
3917
- }
3918
-
3919
- var subscriptions = new Array(n);
3920
- for (var idx = 0; idx < n; idx++) {
3921
- (function (i) {
3922
- subscriptions[i] = new SingleAssignmentDisposable();
3923
- subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
3924
- queues[i].push(x);
3925
- next(i);
3926
- }, function (e) { observer.onError(e); }, function () {
3927
- done(i);
3928
- }));
3929
- })(idx);
3930
- }
3931
-
3932
- return new CompositeDisposable(subscriptions);
3933
- });
3934
- };
4070
+ function asObservable(source) {
4071
+ return function subscribe(o) { return source.subscribe(o); };
4072
+ }
3935
4073
 
3936
4074
  /**
3937
4075
  * Hides the identity of an observable sequence.
3938
4076
  * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3939
4077
  */
3940
4078
  observableProto.asObservable = function () {
3941
- var source = this;
3942
- return new AnonymousObservable(function (o) { return source.subscribe(o); }, this);
4079
+ return new AnonymousObservable(asObservable(this), this);
3943
4080
  };
3944
4081
 
4082
+ function toArray(x) { return x.toArray(); }
4083
+ function notEmpty(x) { return x.length > 0; }
4084
+
3945
4085
  /**
3946
4086
  * Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
3947
- *
3948
- * @example
3949
- * var res = xs.bufferWithCount(10);
3950
- * var res = xs.bufferWithCount(10, 1);
3951
4087
  * @param {Number} count Length of each buffer.
3952
4088
  * @param {Number} [skip] Number of elements to skip between creation of consecutive buffers. If not provided, defaults to the count.
3953
4089
  * @returns {Observable} An observable sequence of buffers.
3954
4090
  */
3955
4091
  observableProto.bufferWithCount = function (count, skip) {
3956
- if (typeof skip !== 'number') {
3957
- skip = count;
3958
- }
3959
- return this.windowWithCount(count, skip).selectMany(function (x) {
3960
- return x.toArray();
3961
- }).where(function (x) {
3962
- return x.length > 0;
3963
- });
4092
+ typeof skip !== 'number' && (skip = count);
4093
+ return this.windowWithCount(count, skip)
4094
+ .flatMap(toArray)
4095
+ .filter(notEmpty);
3964
4096
  };
3965
4097
 
3966
4098
  /**
@@ -3974,118 +4106,167 @@
3974
4106
  }, this);
3975
4107
  };
3976
4108
 
4109
+ var DistinctUntilChangedObservable = (function(__super__) {
4110
+ inherits(DistinctUntilChangedObservable, __super__);
4111
+ function DistinctUntilChangedObservable(source, keyFn, comparer) {
4112
+ this.source = source;
4113
+ this.keyFn = keyFn;
4114
+ this.comparer = comparer;
4115
+ __super__.call(this);
4116
+ }
4117
+
4118
+ DistinctUntilChangedObservable.prototype.subscribeCore = function (o) {
4119
+ return this.source.subscribe(new DistinctUntilChangedObserver(o, this.keyFn, this.comparer));
4120
+ };
4121
+
4122
+ return DistinctUntilChangedObservable;
4123
+ }(ObservableBase));
4124
+
4125
+ var DistinctUntilChangedObserver = (function(__super__) {
4126
+ inherits(DistinctUntilChangedObserver, __super__);
4127
+ function DistinctUntilChangedObserver(o, keyFn, comparer) {
4128
+ this.o = o;
4129
+ this.keyFn = keyFn;
4130
+ this.comparer = comparer;
4131
+ this.hasCurrentKey = false;
4132
+ this.currentKey = null;
4133
+ __super__.call(this);
4134
+ }
4135
+
4136
+ DistinctUntilChangedObserver.prototype.next = function (x) {
4137
+ var key = x, comparerEquals;
4138
+ if (isFunction(this.keyFn)) {
4139
+ key = tryCatch(this.keyFn)(x);
4140
+ if (key === errorObj) { return this.o.onError(key.e); }
4141
+ }
4142
+ if (this.hasCurrentKey) {
4143
+ comparerEquals = tryCatch(this.comparer)(this.currentKey, key);
4144
+ if (comparerEquals === errorObj) { return this.o.onError(comparerEquals.e); }
4145
+ }
4146
+ if (!this.hasCurrentKey || !comparerEquals) {
4147
+ this.hasCurrentKey = true;
4148
+ this.currentKey = key;
4149
+ this.o.onNext(x);
4150
+ }
4151
+ };
4152
+ DistinctUntilChangedObserver.prototype.error = function(e) {
4153
+ this.o.onError(e);
4154
+ };
4155
+ DistinctUntilChangedObserver.prototype.completed = function () {
4156
+ this.o.onCompleted();
4157
+ };
4158
+
4159
+ return DistinctUntilChangedObserver;
4160
+ }(AbstractObserver));
4161
+
3977
4162
  /**
3978
- * Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
3979
- *
3980
- * var obs = observable.distinctUntilChanged();
3981
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; });
3982
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; }, function (x, y) { return x === y; });
3983
- *
3984
- * @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
3985
- * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
3986
- * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
3987
- */
3988
- observableProto.distinctUntilChanged = function (keySelector, comparer) {
3989
- var source = this;
4163
+ * Returns an observable sequence that contains only distinct contiguous elements according to the keyFn and the comparer.
4164
+ * @param {Function} [keyFn] A function to compute the comparison key for each element. If not provided, it projects the value.
4165
+ * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
4166
+ * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
4167
+ */
4168
+ observableProto.distinctUntilChanged = function (keyFn, comparer) {
3990
4169
  comparer || (comparer = defaultComparer);
3991
- return new AnonymousObservable(function (o) {
3992
- var hasCurrentKey = false, currentKey;
3993
- return source.subscribe(function (value) {
3994
- var key = value;
3995
- if (keySelector) {
3996
- try {
3997
- key = keySelector(value);
3998
- } catch (e) {
3999
- o.onError(e);
4000
- return;
4001
- }
4002
- }
4003
- if (hasCurrentKey) {
4004
- try {
4005
- var comparerEquals = comparer(currentKey, key);
4006
- } catch (e) {
4007
- o.onError(e);
4008
- return;
4009
- }
4010
- }
4011
- if (!hasCurrentKey || !comparerEquals) {
4012
- hasCurrentKey = true;
4013
- currentKey = key;
4014
- o.onNext(value);
4015
- }
4016
- }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4017
- }, this);
4170
+ return new DistinctUntilChangedObservable(this, keyFn, comparer);
4018
4171
  };
4019
4172
 
4173
+ var TapObservable = (function(__super__) {
4174
+ inherits(TapObservable,__super__);
4175
+ function TapObservable(source, observerOrOnNext, onError, onCompleted) {
4176
+ this.source = source;
4177
+ this._oN = observerOrOnNext;
4178
+ this._oE = onError;
4179
+ this._oC = onCompleted;
4180
+ __super__.call(this);
4181
+ }
4182
+
4183
+ TapObservable.prototype.subscribeCore = function(o) {
4184
+ return this.source.subscribe(new InnerObserver(o, this));
4185
+ };
4186
+
4187
+ function InnerObserver(o, p) {
4188
+ this.o = o;
4189
+ this.t = !p._oN || isFunction(p._oN) ?
4190
+ observerCreate(p._oN || noop, p._oE || noop, p._oC || noop) :
4191
+ p._oN;
4192
+ this.isStopped = false;
4193
+ }
4194
+ InnerObserver.prototype.onNext = function(x) {
4195
+ if (this.isStopped) { return; }
4196
+ var res = tryCatch(this.t.onNext).call(this.t, x);
4197
+ if (res === errorObj) { this.o.onError(res.e); }
4198
+ this.o.onNext(x);
4199
+ };
4200
+ InnerObserver.prototype.onError = function(err) {
4201
+ if (!this.isStopped) {
4202
+ this.isStopped = true;
4203
+ var res = tryCatch(this.t.onError).call(this.t, err);
4204
+ if (res === errorObj) { return this.o.onError(res.e); }
4205
+ this.o.onError(err);
4206
+ }
4207
+ };
4208
+ InnerObserver.prototype.onCompleted = function() {
4209
+ if (!this.isStopped) {
4210
+ this.isStopped = true;
4211
+ var res = tryCatch(this.t.onCompleted).call(this.t);
4212
+ if (res === errorObj) { return this.o.onError(res.e); }
4213
+ this.o.onCompleted();
4214
+ }
4215
+ };
4216
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4217
+ InnerObserver.prototype.fail = function (e) {
4218
+ if (!this.isStopped) {
4219
+ this.isStopped = true;
4220
+ this.o.onError(e);
4221
+ return true;
4222
+ }
4223
+ return false;
4224
+ };
4225
+
4226
+ return TapObservable;
4227
+ }(ObservableBase));
4228
+
4020
4229
  /**
4021
- * Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
4022
- * 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.
4023
- * @param {Function | Observer} observerOrOnNext Action to invoke for each element in the observable sequence or an observer.
4024
- * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
4025
- * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
4026
- * @returns {Observable} The source sequence with the side-effecting behavior applied.
4027
- */
4230
+ * Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
4231
+ * 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.
4232
+ * @param {Function | Observer} observerOrOnNext Action to invoke for each element in the observable sequence or an o.
4233
+ * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
4234
+ * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
4235
+ * @returns {Observable} The source sequence with the side-effecting behavior applied.
4236
+ */
4028
4237
  observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
4029
- var source = this;
4030
- return new AnonymousObservable(function (observer) {
4031
- var tapObserver = !observerOrOnNext || isFunction(observerOrOnNext) ?
4032
- observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
4033
- observerOrOnNext;
4034
-
4035
- return source.subscribe(function (x) {
4036
- try {
4037
- tapObserver.onNext(x);
4038
- } catch (e) {
4039
- observer.onError(e);
4040
- }
4041
- observer.onNext(x);
4042
- }, function (err) {
4043
- try {
4044
- tapObserver.onError(err);
4045
- } catch (e) {
4046
- observer.onError(e);
4047
- }
4048
- observer.onError(err);
4049
- }, function () {
4050
- try {
4051
- tapObserver.onCompleted();
4052
- } catch (e) {
4053
- observer.onError(e);
4054
- }
4055
- observer.onCompleted();
4056
- });
4057
- }, this);
4238
+ return new TapObservable(this, observerOrOnNext, onError, onCompleted);
4058
4239
  };
4059
4240
 
4060
4241
  /**
4061
- * Invokes an action for each element in the observable sequence.
4062
- * 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.
4063
- * @param {Function} onNext Action to invoke for each element in the observable sequence.
4064
- * @param {Any} [thisArg] Object to use as this when executing callback.
4065
- * @returns {Observable} The source sequence with the side-effecting behavior applied.
4066
- */
4242
+ * Invokes an action for each element in the observable sequence.
4243
+ * 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.
4244
+ * @param {Function} onNext Action to invoke for each element in the observable sequence.
4245
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4246
+ * @returns {Observable} The source sequence with the side-effecting behavior applied.
4247
+ */
4067
4248
  observableProto.doOnNext = observableProto.tapOnNext = function (onNext, thisArg) {
4068
4249
  return this.tap(typeof thisArg !== 'undefined' ? function (x) { onNext.call(thisArg, x); } : onNext);
4069
4250
  };
4070
4251
 
4071
4252
  /**
4072
- * Invokes an action upon exceptional termination of the observable sequence.
4073
- * 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.
4074
- * @param {Function} onError Action to invoke upon exceptional termination of the observable sequence.
4075
- * @param {Any} [thisArg] Object to use as this when executing callback.
4076
- * @returns {Observable} The source sequence with the side-effecting behavior applied.
4077
- */
4253
+ * Invokes an action upon exceptional termination of the observable sequence.
4254
+ * 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.
4255
+ * @param {Function} onError Action to invoke upon exceptional termination of the observable sequence.
4256
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4257
+ * @returns {Observable} The source sequence with the side-effecting behavior applied.
4258
+ */
4078
4259
  observableProto.doOnError = observableProto.tapOnError = function (onError, thisArg) {
4079
4260
  return this.tap(noop, typeof thisArg !== 'undefined' ? function (e) { onError.call(thisArg, e); } : onError);
4080
4261
  };
4081
4262
 
4082
4263
  /**
4083
- * Invokes an action upon graceful termination of the observable sequence.
4084
- * 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.
4085
- * @param {Function} onCompleted Action to invoke upon graceful termination of the observable sequence.
4086
- * @param {Any} [thisArg] Object to use as this when executing callback.
4087
- * @returns {Observable} The source sequence with the side-effecting behavior applied.
4088
- */
4264
+ * Invokes an action upon graceful termination of the observable sequence.
4265
+ * 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.
4266
+ * @param {Function} onCompleted Action to invoke upon graceful termination of the observable sequence.
4267
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4268
+ * @returns {Observable} The source sequence with the side-effecting behavior applied.
4269
+ */
4089
4270
  observableProto.doOnCompleted = observableProto.tapOnCompleted = function (onCompleted, thisArg) {
4090
4271
  return this.tap(noop, null, typeof thisArg !== 'undefined' ? function () { onCompleted.call(thisArg); } : onCompleted);
4091
4272
  };
@@ -4095,45 +4276,71 @@
4095
4276
  * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
4096
4277
  * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
4097
4278
  */
4098
- observableProto['finally'] = observableProto.ensure = function (action) {
4279
+ observableProto['finally'] = function (action) {
4099
4280
  var source = this;
4100
4281
  return new AnonymousObservable(function (observer) {
4101
- var subscription;
4102
- try {
4103
- subscription = source.subscribe(observer);
4104
- } catch (e) {
4282
+ var subscription = tryCatch(source.subscribe).call(source, observer);
4283
+ if (subscription === errorObj) {
4105
4284
  action();
4106
- throw e;
4285
+ return thrower(subscription.e);
4107
4286
  }
4108
4287
  return disposableCreate(function () {
4109
- try {
4110
- subscription.dispose();
4111
- } catch (e) {
4112
- throw e;
4113
- } finally {
4114
- action();
4115
- }
4288
+ var r = tryCatch(subscription.dispose).call(subscription);
4289
+ action();
4290
+ r === errorObj && thrower(r.e);
4116
4291
  });
4117
4292
  }, this);
4118
4293
  };
4119
4294
 
4120
- /**
4121
- * @deprecated use #finally or #ensure instead.
4122
- */
4123
- observableProto.finallyAction = function (action) {
4124
- //deprecate('finallyAction', 'finally or ensure');
4125
- return this.ensure(action);
4126
- };
4295
+ var IgnoreElementsObservable = (function(__super__) {
4296
+ inherits(IgnoreElementsObservable, __super__);
4297
+
4298
+ function IgnoreElementsObservable(source) {
4299
+ this.source = source;
4300
+ __super__.call(this);
4301
+ }
4302
+
4303
+ IgnoreElementsObservable.prototype.subscribeCore = function (o) {
4304
+ return this.source.subscribe(new InnerObserver(o));
4305
+ };
4306
+
4307
+ function InnerObserver(o) {
4308
+ this.o = o;
4309
+ this.isStopped = false;
4310
+ }
4311
+ InnerObserver.prototype.onNext = noop;
4312
+ InnerObserver.prototype.onError = function (err) {
4313
+ if(!this.isStopped) {
4314
+ this.isStopped = true;
4315
+ this.o.onError(err);
4316
+ }
4317
+ };
4318
+ InnerObserver.prototype.onCompleted = function () {
4319
+ if(!this.isStopped) {
4320
+ this.isStopped = true;
4321
+ this.o.onCompleted();
4322
+ }
4323
+ };
4324
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4325
+ InnerObserver.prototype.fail = function (e) {
4326
+ if (!this.isStopped) {
4327
+ this.isStopped = true;
4328
+ this.observer.onError(e);
4329
+ return true;
4330
+ }
4331
+
4332
+ return false;
4333
+ };
4334
+
4335
+ return IgnoreElementsObservable;
4336
+ }(ObservableBase));
4127
4337
 
4128
4338
  /**
4129
4339
  * Ignores all elements in an observable sequence leaving only the termination messages.
4130
4340
  * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
4131
4341
  */
4132
4342
  observableProto.ignoreElements = function () {
4133
- var source = this;
4134
- return new AnonymousObservable(function (o) {
4135
- return source.subscribe(noop, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4136
- }, source);
4343
+ return new IgnoreElementsObservable(this);
4137
4344
  };
4138
4345
 
4139
4346
  /**
@@ -4191,51 +4398,84 @@
4191
4398
  observableProto.retryWhen = function (notifier) {
4192
4399
  return enumerableRepeat(this).catchErrorWhen(notifier);
4193
4400
  };
4401
+ var ScanObservable = (function(__super__) {
4402
+ inherits(ScanObservable, __super__);
4403
+ function ScanObservable(source, accumulator, hasSeed, seed) {
4404
+ this.source = source;
4405
+ this.accumulator = accumulator;
4406
+ this.hasSeed = hasSeed;
4407
+ this.seed = seed;
4408
+ __super__.call(this);
4409
+ }
4410
+
4411
+ ScanObservable.prototype.subscribeCore = function(o) {
4412
+ return this.source.subscribe(new InnerObserver(o,this));
4413
+ };
4414
+
4415
+ return ScanObservable;
4416
+ }(ObservableBase));
4417
+
4418
+ function InnerObserver(o, parent) {
4419
+ this.o = o;
4420
+ this.accumulator = parent.accumulator;
4421
+ this.hasSeed = parent.hasSeed;
4422
+ this.seed = parent.seed;
4423
+ this.hasAccumulation = false;
4424
+ this.accumulation = null;
4425
+ this.hasValue = false;
4426
+ this.isStopped = false;
4427
+ }
4428
+ InnerObserver.prototype = {
4429
+ onNext: function (x) {
4430
+ if (this.isStopped) { return; }
4431
+ !this.hasValue && (this.hasValue = true);
4432
+ if (this.hasAccumulation) {
4433
+ this.accumulation = tryCatch(this.accumulator)(this.accumulation, x);
4434
+ } else {
4435
+ this.accumulation = this.hasSeed ? tryCatch(this.accumulator)(this.seed, x) : x;
4436
+ this.hasAccumulation = true;
4437
+ }
4438
+ if (this.accumulation === errorObj) { return this.o.onError(this.accumulation.e); }
4439
+ this.o.onNext(this.accumulation);
4440
+ },
4441
+ onError: function (e) {
4442
+ if (!this.isStopped) {
4443
+ this.isStopped = true;
4444
+ this.o.onError(e);
4445
+ }
4446
+ },
4447
+ onCompleted: function () {
4448
+ if (!this.isStopped) {
4449
+ this.isStopped = true;
4450
+ !this.hasValue && this.hasSeed && this.o.onNext(this.seed);
4451
+ this.o.onCompleted();
4452
+ }
4453
+ },
4454
+ dispose: function() { this.isStopped = true; },
4455
+ fail: function (e) {
4456
+ if (!this.isStopped) {
4457
+ this.isStopped = true;
4458
+ this.o.onError(e);
4459
+ return true;
4460
+ }
4461
+ return false;
4462
+ }
4463
+ };
4464
+
4194
4465
  /**
4195
- * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
4196
- * For aggregation behavior with no intermediate results, see Observable.aggregate.
4197
- * @example
4198
- * var res = source.scan(function (acc, x) { return acc + x; });
4199
- * var res = source.scan(0, function (acc, x) { return acc + x; });
4200
- * @param {Mixed} [seed] The initial accumulator value.
4201
- * @param {Function} accumulator An accumulator function to be invoked on each element.
4202
- * @returns {Observable} An observable sequence containing the accumulated values.
4203
- */
4466
+ * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
4467
+ * For aggregation behavior with no intermediate results, see Observable.aggregate.
4468
+ * @param {Mixed} [seed] The initial accumulator value.
4469
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
4470
+ * @returns {Observable} An observable sequence containing the accumulated values.
4471
+ */
4204
4472
  observableProto.scan = function () {
4205
- var hasSeed = false, seed, accumulator, source = this;
4473
+ var hasSeed = false, seed, accumulator = arguments[0];
4206
4474
  if (arguments.length === 2) {
4207
4475
  hasSeed = true;
4208
- seed = arguments[0];
4209
- accumulator = arguments[1];
4210
- } else {
4211
- accumulator = arguments[0];
4476
+ seed = arguments[1];
4212
4477
  }
4213
- return new AnonymousObservable(function (o) {
4214
- var hasAccumulation, accumulation, hasValue;
4215
- return source.subscribe (
4216
- function (x) {
4217
- !hasValue && (hasValue = true);
4218
- try {
4219
- if (hasAccumulation) {
4220
- accumulation = accumulator(accumulation, x);
4221
- } else {
4222
- accumulation = hasSeed ? accumulator(seed, x) : x;
4223
- hasAccumulation = true;
4224
- }
4225
- } catch (e) {
4226
- o.onError(e);
4227
- return;
4228
- }
4229
-
4230
- o.onNext(accumulation);
4231
- },
4232
- function (e) { o.onError(e); },
4233
- function () {
4234
- !hasValue && hasSeed && o.onNext(seed);
4235
- o.onCompleted();
4236
- }
4237
- );
4238
- }, source);
4478
+ return new ScanObservable(this, accumulator, hasSeed, seed);
4239
4479
  };
4240
4480
 
4241
4481
  /**
@@ -4377,52 +4617,9 @@
4377
4617
  }, source);
4378
4618
  };
4379
4619
 
4380
- function concatMap(source, selector, thisArg) {
4381
- var selectorFunc = bindCallback(selector, thisArg, 3);
4382
- return source.map(function (x, i) {
4383
- var result = selectorFunc(x, i, source);
4384
- isPromise(result) && (result = observableFromPromise(result));
4385
- (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
4386
- return result;
4387
- }).concatAll();
4388
- }
4389
-
4390
- /**
4391
- * One of the Following:
4392
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
4393
- *
4394
- * @example
4395
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
4396
- * Or:
4397
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
4398
- *
4399
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
4400
- * Or:
4401
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
4402
- *
4403
- * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
4404
- * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the
4405
- * source sequence onto which could be either an observable or Promise.
4406
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
4407
- * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
4408
- */
4409
- observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
4410
- if (isFunction(selector) && isFunction(resultSelector)) {
4411
- return this.concatMap(function (x, i) {
4412
- var selectorResult = selector(x, i);
4413
- isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
4414
- (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
4415
-
4416
- return selectorResult.map(function (y, i2) {
4417
- return resultSelector(x, y, i, i2);
4418
- });
4419
- });
4420
- }
4421
- return isFunction(selector) ?
4422
- concatMap(this, selector, thisArg) :
4423
- concatMap(this, function () { return selector; });
4424
- };
4425
-
4620
+ observableProto.flatMapConcat = observableProto.concatMap = function(selector, resultSelector, thisArg) {
4621
+ return new FlatMapObservable(this, selector, resultSelector, thisArg).merge(1);
4622
+ };
4426
4623
  /**
4427
4624
  * Projects each notification of an observable sequence to an observable sequence and concats the resulting observable sequences into one observable sequence.
4428
4625
  * @param {Function} onNext A transform function to apply to each element; the second parameter of the function represents the index of the source element.
@@ -4565,51 +4762,52 @@
4565
4762
  __super__.call(this);
4566
4763
  }
4567
4764
 
4765
+ function innerMap(selector, self) {
4766
+ return function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); }
4767
+ }
4768
+
4568
4769
  MapObservable.prototype.internalMap = function (selector, thisArg) {
4569
- var self = this;
4570
- return new MapObservable(this.source, function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); }, thisArg)
4770
+ return new MapObservable(this.source, innerMap(selector, this), thisArg);
4571
4771
  };
4572
4772
 
4573
- MapObservable.prototype.subscribeCore = function (observer) {
4574
- return this.source.subscribe(new MapObserver(observer, this.selector, this));
4773
+ MapObservable.prototype.subscribeCore = function (o) {
4774
+ return this.source.subscribe(new InnerObserver(o, this.selector, this));
4575
4775
  };
4576
4776
 
4577
- return MapObservable;
4777
+ function InnerObserver(o, selector, source) {
4778
+ this.o = o;
4779
+ this.selector = selector;
4780
+ this.source = source;
4781
+ this.i = 0;
4782
+ this.isStopped = false;
4783
+ }
4578
4784
 
4579
- }(ObservableBase));
4785
+ InnerObserver.prototype.onNext = function(x) {
4786
+ if (this.isStopped) { return; }
4787
+ var result = tryCatch(this.selector)(x, this.i++, this.source);
4788
+ if (result === errorObj) { return this.o.onError(result.e); }
4789
+ this.o.onNext(result);
4790
+ };
4791
+ InnerObserver.prototype.onError = function (e) {
4792
+ if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
4793
+ };
4794
+ InnerObserver.prototype.onCompleted = function () {
4795
+ if(!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
4796
+ };
4797
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4798
+ InnerObserver.prototype.fail = function (e) {
4799
+ if (!this.isStopped) {
4800
+ this.isStopped = true;
4801
+ this.o.onError(e);
4802
+ return true;
4803
+ }
4580
4804
 
4581
- function MapObserver(observer, selector, source) {
4582
- this.observer = observer;
4583
- this.selector = selector;
4584
- this.source = source;
4585
- this.i = 0;
4586
- this.isStopped = false;
4587
- }
4805
+ return false;
4806
+ };
4588
4807
 
4589
- MapObserver.prototype.onNext = function(x) {
4590
- if (this.isStopped) { return; }
4591
- var result = tryCatch(this.selector).call(this, x, this.i++, this.source);
4592
- if (result === errorObj) {
4593
- return this.observer.onError(result.e);
4594
- }
4595
- this.observer.onNext(result);
4596
- };
4597
- MapObserver.prototype.onError = function (e) {
4598
- if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4599
- };
4600
- MapObserver.prototype.onCompleted = function () {
4601
- if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4602
- };
4603
- MapObserver.prototype.dispose = function() { this.isStopped = true; };
4604
- MapObserver.prototype.fail = function (e) {
4605
- if (!this.isStopped) {
4606
- this.isStopped = true;
4607
- this.observer.onError(e);
4608
- return true;
4609
- }
4808
+ return MapObservable;
4610
4809
 
4611
- return false;
4612
- };
4810
+ }(ObservableBase));
4613
4811
 
4614
4812
  /**
4615
4813
  * Projects each element of an observable sequence into a new form by incorporating the element's index.
@@ -4624,16 +4822,8 @@
4624
4822
  new MapObservable(this, selectorFn, thisArg);
4625
4823
  };
4626
4824
 
4627
- /**
4628
- * Retrieves the value of a specified nested property from all elements in
4629
- * the Observable sequence.
4630
- * @param {Arguments} arguments The nested properties to pluck.
4631
- * @returns {Observable} Returns a new Observable sequence of property values.
4632
- */
4633
- observableProto.pluck = function () {
4634
- var args = arguments, len = arguments.length;
4635
- if (len === 0) { throw new Error('List of properties cannot be empty.'); }
4636
- return this.map(function (x) {
4825
+ function plucker(args, len) {
4826
+ return function mapper(x) {
4637
4827
  var currentProp = x;
4638
4828
  for (var i = 0; i < len; i++) {
4639
4829
  var p = currentProp[args[i]];
@@ -4644,7 +4834,20 @@
4644
4834
  }
4645
4835
  }
4646
4836
  return currentProp;
4647
- });
4837
+ }
4838
+ }
4839
+
4840
+ /**
4841
+ * Retrieves the value of a specified nested property from all elements in
4842
+ * the Observable sequence.
4843
+ * @param {Arguments} arguments The nested properties to pluck.
4844
+ * @returns {Observable} Returns a new Observable sequence of property values.
4845
+ */
4846
+ observableProto.pluck = function () {
4847
+ var len = arguments.length, args = new Array(len);
4848
+ if (len === 0) { throw new Error('List of properties cannot be empty.'); }
4849
+ for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
4850
+ return this.map(plucker(args, len));
4648
4851
  };
4649
4852
 
4650
4853
  /**
@@ -4699,64 +4902,65 @@
4699
4902
  }, source).mergeAll();
4700
4903
  };
4701
4904
 
4702
- function flatMap(source, selector, thisArg) {
4703
- var selectorFunc = bindCallback(selector, thisArg, 3);
4704
- return source.map(function (x, i) {
4705
- var result = selectorFunc(x, i, source);
4706
- isPromise(result) && (result = observableFromPromise(result));
4707
- (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
4708
- return result;
4709
- }).mergeAll();
4710
- }
4905
+ observableProto.flatMap = observableProto.selectMany = function(selector, resultSelector, thisArg) {
4906
+ return new FlatMapObservable(this, selector, resultSelector, thisArg).mergeAll();
4907
+ };
4711
4908
 
4712
- /**
4713
- * One of the Following:
4714
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
4715
- *
4716
- * @example
4717
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
4718
- * Or:
4719
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
4720
- *
4721
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
4722
- * Or:
4723
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
4724
- *
4725
- * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
4726
- * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto which could be either an observable or Promise.
4727
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
4728
- * @param {Any} [thisArg] Object to use as this when executing callback.
4729
- * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
4730
- */
4731
- observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
4732
- if (isFunction(selector) && isFunction(resultSelector)) {
4733
- return this.flatMap(function (x, i) {
4734
- var selectorResult = selector(x, i);
4735
- isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
4736
- (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
4737
-
4738
- return selectorResult.map(function (y, i2) {
4739
- return resultSelector(x, y, i, i2);
4740
- });
4741
- }, thisArg);
4742
- }
4743
- return isFunction(selector) ?
4744
- flatMap(this, selector, thisArg) :
4745
- flatMap(this, function () { return selector; });
4746
- };
4747
4909
 
4748
- /**
4749
- * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
4750
- * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
4751
- * @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.
4752
- * @param {Any} [thisArg] Object to use as this when executing callback.
4753
- * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
4754
- * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
4755
- */
4756
- observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
4757
- return this.select(selector, thisArg).switchLatest();
4758
- };
4910
+ //
4911
+ //Rx.Observable.prototype.flatMapWithMaxConcurrent = function(limit, selector, resultSelector, thisArg) {
4912
+ // return new FlatMapObservable(this, selector, resultSelector, thisArg).merge(limit);
4913
+ //};
4914
+ //
4759
4915
 
4916
+ Rx.Observable.prototype.flatMapLatest = function(selector, resultSelector, thisArg) {
4917
+ return new FlatMapObservable(this, selector, resultSelector, thisArg).switchLatest();
4918
+ };
4919
+ var SkipObservable = (function(__super__) {
4920
+ inherits(SkipObservable, __super__);
4921
+ function SkipObservable(source, count) {
4922
+ this.source = source;
4923
+ this.skipCount = count;
4924
+ __super__.call(this);
4925
+ }
4926
+
4927
+ SkipObservable.prototype.subscribeCore = function (o) {
4928
+ return this.source.subscribe(new InnerObserver(o, this.skipCount));
4929
+ };
4930
+
4931
+ function InnerObserver(o, c) {
4932
+ this.c = c;
4933
+ this.r = c;
4934
+ this.o = o;
4935
+ this.isStopped = false;
4936
+ }
4937
+ InnerObserver.prototype.onNext = function (x) {
4938
+ if (this.isStopped) { return; }
4939
+ if (this.r <= 0) {
4940
+ this.o.onNext(x);
4941
+ } else {
4942
+ this.r--;
4943
+ }
4944
+ };
4945
+ InnerObserver.prototype.onError = function(e) {
4946
+ if (!this.isStopped) { this.isStopped = true; this.o.onError(e); }
4947
+ };
4948
+ InnerObserver.prototype.onCompleted = function() {
4949
+ if (!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
4950
+ };
4951
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4952
+ InnerObserver.prototype.fail = function(e) {
4953
+ if (!this.isStopped) {
4954
+ this.isStopped = true;
4955
+ this.o.onError(e);
4956
+ return true;
4957
+ }
4958
+ return false;
4959
+ };
4960
+
4961
+ return SkipObservable;
4962
+ }(ObservableBase));
4963
+
4760
4964
  /**
4761
4965
  * Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
4762
4966
  * @param {Number} count The number of elements to skip before returning the remaining elements.
@@ -4764,19 +4968,8 @@
4764
4968
  */
4765
4969
  observableProto.skip = function (count) {
4766
4970
  if (count < 0) { throw new ArgumentOutOfRangeError(); }
4767
- var source = this;
4768
- return new AnonymousObservable(function (o) {
4769
- var remaining = count;
4770
- return source.subscribe(function (x) {
4771
- if (remaining <= 0) {
4772
- o.onNext(x);
4773
- } else {
4774
- remaining--;
4775
- }
4776
- }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4777
- }, source);
4971
+ return new SkipObservable(this, count);
4778
4972
  };
4779
-
4780
4973
  /**
4781
4974
  * Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
4782
4975
  * The element's index is used in the logic of the predicate function.
@@ -4824,7 +5017,7 @@
4824
5017
  return source.subscribe(function (x) {
4825
5018
  if (remaining-- > 0) {
4826
5019
  o.onNext(x);
4827
- remaining === 0 && o.onCompleted();
5020
+ remaining <= 0 && o.onCompleted();
4828
5021
  }
4829
5022
  }, function (e) { o.onError(e); }, function () { o.onCompleted(); });
4830
5023
  }, source);
@@ -4869,51 +5062,54 @@
4869
5062
  __super__.call(this);
4870
5063
  }
4871
5064
 
4872
- FilterObservable.prototype.subscribeCore = function (observer) {
4873
- return this.source.subscribe(new FilterObserver(observer, this.predicate, this));
5065
+ FilterObservable.prototype.subscribeCore = function (o) {
5066
+ return this.source.subscribe(new InnerObserver(o, this.predicate, this));
4874
5067
  };
5068
+
5069
+ function innerPredicate(predicate, self) {
5070
+ return function(x, i, o) { return self.predicate(x, i, o) && predicate.call(this, x, i, o); }
5071
+ }
4875
5072
 
4876
5073
  FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
4877
- var self = this;
4878
- return new FilterObservable(this.source, function(x, i, o) { return self.predicate(x, i, o) && predicate.call(this, x, i, o); }, thisArg);
5074
+ return new FilterObservable(this.source, innerPredicate(predicate, this), thisArg);
5075
+ };
5076
+
5077
+ function InnerObserver(o, predicate, source) {
5078
+ this.o = o;
5079
+ this.predicate = predicate;
5080
+ this.source = source;
5081
+ this.i = 0;
5082
+ this.isStopped = false;
5083
+ }
5084
+
5085
+ InnerObserver.prototype.onNext = function(x) {
5086
+ if (this.isStopped) { return; }
5087
+ var shouldYield = tryCatch(this.predicate)(x, this.i++, this.source);
5088
+ if (shouldYield === errorObj) {
5089
+ return this.o.onError(shouldYield.e);
5090
+ }
5091
+ shouldYield && this.o.onNext(x);
5092
+ };
5093
+ InnerObserver.prototype.onError = function (e) {
5094
+ if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
5095
+ };
5096
+ InnerObserver.prototype.onCompleted = function () {
5097
+ if(!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
5098
+ };
5099
+ InnerObserver.prototype.dispose = function() { this.isStopped = true; };
5100
+ InnerObserver.prototype.fail = function (e) {
5101
+ if (!this.isStopped) {
5102
+ this.isStopped = true;
5103
+ this.o.onError(e);
5104
+ return true;
5105
+ }
5106
+ return false;
4879
5107
  };
4880
5108
 
4881
5109
  return FilterObservable;
4882
5110
 
4883
5111
  }(ObservableBase));
4884
5112
 
4885
- function FilterObserver(observer, predicate, source) {
4886
- this.observer = observer;
4887
- this.predicate = predicate;
4888
- this.source = source;
4889
- this.i = 0;
4890
- this.isStopped = false;
4891
- }
4892
-
4893
- FilterObserver.prototype.onNext = function(x) {
4894
- if (this.isStopped) { return; }
4895
- var shouldYield = tryCatch(this.predicate).call(this, x, this.i++, this.source);
4896
- if (shouldYield === errorObj) {
4897
- return this.observer.onError(shouldYield.e);
4898
- }
4899
- shouldYield && this.observer.onNext(x);
4900
- };
4901
- FilterObserver.prototype.onError = function (e) {
4902
- if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
4903
- };
4904
- FilterObserver.prototype.onCompleted = function () {
4905
- if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
4906
- };
4907
- FilterObserver.prototype.dispose = function() { this.isStopped = true; };
4908
- FilterObserver.prototype.fail = function (e) {
4909
- if (!this.isStopped) {
4910
- this.isStopped = true;
4911
- this.observer.onError(e);
4912
- return true;
4913
- }
4914
- return false;
4915
- };
4916
-
4917
5113
  /**
4918
5114
  * Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
4919
5115
  * @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.
@@ -4951,11 +5147,8 @@
4951
5147
  var xform = transducer(transformForObserver(o));
4952
5148
  return source.subscribe(
4953
5149
  function(v) {
4954
- try {
4955
- xform['@@transducer/step'](o, v);
4956
- } catch (e) {
4957
- o.onError(e);
4958
- }
5150
+ var res = tryCatch(xform['@@transducer/step']).call(xform, o, v);
5151
+ if (res === errorObj) { o.onError(res.e); }
4959
5152
  },
4960
5153
  function (e) { o.onError(e); },
4961
5154
  function() { xform['@@transducer/result'](o); }
@@ -4973,8 +5166,8 @@
4973
5166
  }
4974
5167
 
4975
5168
  function setDisposable(s, state) {
4976
- var ado = state[0], subscribe = state[1];
4977
- var sub = tryCatch(subscribe)(ado);
5169
+ var ado = state[0], self = state[1];
5170
+ var sub = tryCatch(self.__subscribe).call(self, ado);
4978
5171
 
4979
5172
  if (sub === errorObj) {
4980
5173
  if(!ado.fail(errorObj.e)) { return thrower(errorObj.e); }
@@ -4982,21 +5175,21 @@
4982
5175
  ado.setDisposable(fixSubscriber(sub));
4983
5176
  }
4984
5177
 
4985
- function AnonymousObservable(subscribe, parent) {
4986
- this.source = parent;
4987
-
4988
- function s(observer) {
4989
- var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
5178
+ function innerSubscribe(observer) {
5179
+ var ado = new AutoDetachObserver(observer), state = [ado, this];
4990
5180
 
4991
- if (currentThreadScheduler.scheduleRequired()) {
4992
- currentThreadScheduler.scheduleWithState(state, setDisposable);
4993
- } else {
4994
- setDisposable(null, state);
4995
- }
4996
- return ado;
5181
+ if (currentThreadScheduler.scheduleRequired()) {
5182
+ currentThreadScheduler.scheduleWithState(state, setDisposable);
5183
+ } else {
5184
+ setDisposable(null, state);
4997
5185
  }
5186
+ return ado;
5187
+ }
4998
5188
 
4999
- __super__.call(this, s);
5189
+ function AnonymousObservable(subscribe, parent) {
5190
+ this.source = parent;
5191
+ this.__subscribe = subscribe;
5192
+ __super__.call(this, innerSubscribe);
5000
5193
  }
5001
5194
 
5002
5195
  return AnonymousObservable;