rxjs-rails 2.3.14 → 2.3.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +325 -370
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1115 -930
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +4 -3
  7. data/vendor/assets/javascripts/rx.all.js +1113 -928
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +16 -20
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +14 -18
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.js +26 -10
  14. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.binding.js +2 -14
  16. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.coincidence.js +13 -13
  18. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  19. data/vendor/assets/javascripts/rx.compat.js +586 -378
  20. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  21. data/vendor/assets/javascripts/rx.experimental.js +37 -29
  22. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  23. data/vendor/assets/javascripts/rx.js +586 -378
  24. data/vendor/assets/javascripts/rx.lite.compat.js +632 -394
  25. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  26. data/vendor/assets/javascripts/rx.lite.extras.js +29 -25
  27. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  28. data/vendor/assets/javascripts/rx.lite.js +630 -392
  29. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  30. data/vendor/assets/javascripts/rx.min.js +2 -2
  31. data/vendor/assets/javascripts/rx.sorting.js +72 -0
  32. data/vendor/assets/javascripts/rx.sorting.min.js +3 -0
  33. data/vendor/assets/javascripts/rx.testing.js +116 -83
  34. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  35. data/vendor/assets/javascripts/rx.time.js +127 -101
  36. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  37. metadata +4 -2
@@ -24,7 +24,7 @@
24
24
  var Rx = {
25
25
  internals: {},
26
26
  config: {
27
- Promise: root.Promise // Detect if promise exists
27
+ Promise: root.Promise,
28
28
  },
29
29
  helpers: { }
30
30
  };
@@ -66,6 +66,104 @@
66
66
  var objectDisposed = 'Object has been disposed';
67
67
  function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
68
68
 
69
+ Rx.config.longStackSupport = false;
70
+ var hasStacks = false;
71
+ try {
72
+ throw new Error();
73
+ } catch (e) {
74
+ hasStacks = !!e.stack;
75
+ }
76
+
77
+ // All code after this point will be filtered from stack traces reported by RxJS
78
+ var rStartingLine = captureLine(), rFileName;
79
+
80
+ var STACK_JUMP_SEPARATOR = "From previous event:";
81
+
82
+ function makeStackTraceLong(error, observable) {
83
+ // If possible, transform the error stack trace by removing Node and RxJS
84
+ // cruft, then concatenating with the stack trace of `observable`.
85
+ if (hasStacks &&
86
+ observable.stack &&
87
+ typeof error === "object" &&
88
+ error !== null &&
89
+ error.stack &&
90
+ error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
91
+ ) {
92
+ var stacks = [];
93
+ for (var o = observable; !!o; o = o.source) {
94
+ if (o.stack) {
95
+ stacks.unshift(o.stack);
96
+ }
97
+ }
98
+ stacks.unshift(error.stack);
99
+
100
+ var concatedStacks = stacks.join("\n" + STACK_JUMP_SEPARATOR + "\n");
101
+ error.stack = filterStackString(concatedStacks);
102
+ }
103
+ }
104
+
105
+ function filterStackString(stackString) {
106
+ var lines = stackString.split("\n"),
107
+ desiredLines = [];
108
+ for (var i = 0, len = lines.length; i < len; i++) {
109
+ var line = lines[i];
110
+
111
+ if (!isInternalFrame(line) && !isNodeFrame(line) && line) {
112
+ desiredLines.push(line);
113
+ }
114
+ }
115
+ return desiredLines.join("\n");
116
+ }
117
+
118
+ function isInternalFrame(stackLine) {
119
+ var fileNameAndLineNumber = getFileNameAndLineNumber(stackLine);
120
+ if (!fileNameAndLineNumber) {
121
+ return false;
122
+ }
123
+ var fileName = fileNameAndLineNumber[0], lineNumber = fileNameAndLineNumber[1];
124
+
125
+ console.log(rFileName, rStartingLine, rEndingLine);
126
+
127
+ return fileName === rFileName &&
128
+ lineNumber >= rStartingLine &&
129
+ lineNumber <= rEndingLine;
130
+ }
131
+
132
+ function isNodeFrame(stackLine) {
133
+ return stackLine.indexOf("(module.js:") !== -1 ||
134
+ stackLine.indexOf("(node.js:") !== -1;
135
+ }
136
+
137
+ function captureLine() {
138
+ if (!hasStacks) { return; }
139
+
140
+ try {
141
+ throw new Error();
142
+ } catch (e) {
143
+ var lines = e.stack.split("\n");
144
+ var firstLine = lines[0].indexOf("@") > 0 ? lines[1] : lines[2];
145
+ var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
146
+ if (!fileNameAndLineNumber) { return; }
147
+
148
+ rFileName = fileNameAndLineNumber[0];
149
+ return fileNameAndLineNumber[1];
150
+ }
151
+ }
152
+
153
+ function getFileNameAndLineNumber(stackLine) {
154
+ // Named functions: "at functionName (filename:lineNumber:columnNumber)"
155
+ var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
156
+ if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
157
+
158
+ // Anonymous functions: "at filename:lineNumber:columnNumber"
159
+ var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
160
+ if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
161
+
162
+ // Firefox style: "function@filename:lineNumber or @filename:lineNumber"
163
+ var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
164
+ if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
165
+ }
166
+
69
167
  // Shim in iterator support
70
168
  var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
71
169
  '_es6shim_iterator_';
@@ -76,7 +174,21 @@
76
174
 
77
175
  var doneEnumerator = Rx.doneEnumerator = { done: true, value: undefined };
78
176
 
79
- Rx.iterator = $iterator$;
177
+ var isIterable = Rx.helpers.isIterable = function (o) {
178
+ return o[$iterator$] !== undefined;
179
+ }
180
+
181
+ var isArrayLike = Rx.helpers.isArrayLike = function (o) {
182
+ return o && o.length !== undefined;
183
+ }
184
+
185
+ Rx.helpers.iterator = $iterator$;
186
+
187
+ var deprecate = Rx.helpers.deprecate = function (name, alternative) {
188
+ /*if (typeof console !== "undefined" && typeof console.warn === "function") {
189
+ console.warn(name + ' is deprecated, use ' + alternative + ' instead.', new Error('').stack);
190
+ }*/
191
+ }
80
192
 
81
193
  /** `Object#toString` result shortcuts */
82
194
  var argsClass = '[object Arguments]',
@@ -93,15 +205,16 @@
93
205
  var toString = Object.prototype.toString,
94
206
  hasOwnProperty = Object.prototype.hasOwnProperty,
95
207
  supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
96
- suportNodeClass,
208
+ supportNodeClass,
97
209
  errorProto = Error.prototype,
98
210
  objectProto = Object.prototype,
211
+ stringProto = String.prototype,
99
212
  propertyIsEnumerable = objectProto.propertyIsEnumerable;
100
213
 
101
214
  try {
102
- suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
103
- } catch(e) {
104
- suportNodeClass = true;
215
+ supportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
216
+ } catch (e) {
217
+ supportNodeClass = true;
105
218
  }
106
219
 
107
220
  var shadowedProps = [
@@ -206,7 +319,7 @@
206
319
  return typeof value.toString != 'function' && typeof (value + '') == 'string';
207
320
  }
208
321
 
209
- function isArguments(value) {
322
+ var isArguments = function(value) {
210
323
  return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
211
324
  }
212
325
 
@@ -262,10 +375,10 @@
262
375
 
263
376
  case numberClass:
264
377
  // treat `NaN` vs. `NaN` as equal
265
- return (a != +a)
266
- ? b != +b
378
+ return (a != +a) ?
379
+ b != +b :
267
380
  // but treat `-0` vs. `+0` as not equal
268
- : (a == 0 ? (1 / a == 1 / b) : a == +b);
381
+ (a == 0 ? (1 / a == 1 / b) : a == +b);
269
382
 
270
383
  case regexpClass:
271
384
  case stringClass:
@@ -1024,15 +1137,13 @@
1024
1137
  return SchedulePeriodicRecursive;
1025
1138
  }());
1026
1139
 
1027
- /**
1028
- * Gets a scheduler that schedules work immediately on the current thread.
1029
- */
1140
+ /** Gets a scheduler that schedules work immediately on the current thread. */
1030
1141
  var immediateScheduler = Scheduler.immediate = (function () {
1031
1142
 
1032
1143
  function scheduleNow(state, action) { return action(this, state); }
1033
1144
 
1034
1145
  function scheduleRelative(state, dueTime, action) {
1035
- var dt = normalizeTime(dt);
1146
+ var dt = normalizeTime(dueTime);
1036
1147
  while (dt - this.now() > 0) { }
1037
1148
  return action(this, state);
1038
1149
  }
@@ -1146,24 +1257,24 @@
1146
1257
  oldHandler = root.onmessage;
1147
1258
  // Test for async
1148
1259
  root.onmessage = function () { isAsync = true; };
1149
- root.postMessage('','*');
1260
+ root.postMessage('', '*');
1150
1261
  root.onmessage = oldHandler;
1151
1262
 
1152
1263
  return isAsync;
1153
1264
  }
1154
1265
 
1155
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1156
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1157
- scheduleMethod = process.nextTick;
1158
- } else if (typeof setImmediate === 'function') {
1266
+ // Use in order, setImmediate, nextTick, postMessage, MessageChannel, script readystatechanged, setTimeout
1267
+ if (typeof setImmediate === 'function') {
1159
1268
  scheduleMethod = setImmediate;
1160
1269
  clearMethod = clearImmediate;
1270
+ } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1271
+ scheduleMethod = process.nextTick;
1161
1272
  } else if (postMessageSupported()) {
1162
1273
  var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1163
1274
  tasks = {},
1164
1275
  taskId = 0;
1165
1276
 
1166
- function onGlobalPostMessage(event) {
1277
+ var onGlobalPostMessage = function (event) {
1167
1278
  // Only if we're a match to avoid any other global events
1168
1279
  if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1169
1280
  var handleId = event.data.substring(MSG_PREFIX.length),
@@ -1464,8 +1575,8 @@
1464
1575
  var e;
1465
1576
  try {
1466
1577
  e = sources[$iterator$]();
1467
- } catch(err) {
1468
- observer.onError();
1578
+ } catch (err) {
1579
+ observer.onError(err);
1469
1580
  return;
1470
1581
  }
1471
1582
 
@@ -1506,14 +1617,14 @@
1506
1617
  });
1507
1618
  };
1508
1619
 
1509
- Enumerable.prototype.catchException = function () {
1620
+ Enumerable.prototype.catchError = function () {
1510
1621
  var sources = this;
1511
1622
  return new AnonymousObservable(function (observer) {
1512
1623
  var e;
1513
1624
  try {
1514
1625
  e = sources[$iterator$]();
1515
- } catch(err) {
1516
- observer.onError();
1626
+ } catch (err) {
1627
+ observer.onError(err);
1517
1628
  return;
1518
1629
  }
1519
1630
 
@@ -1651,7 +1762,7 @@
1651
1762
  * @param {Scheduler} scheduler Scheduler to schedule observer messages on.
1652
1763
  * @returns {Observer} Observer whose messages are scheduled on the given scheduler.
1653
1764
  */
1654
- Observer.notifyOn = function (scheduler) {
1765
+ Observer.prototype.notifyOn = function (scheduler) {
1655
1766
  return new ObserveOnObserver(scheduler, this);
1656
1767
  };
1657
1768
 
@@ -1832,23 +1943,17 @@
1832
1943
 
1833
1944
  ScheduledObserver.prototype.next = function (value) {
1834
1945
  var self = this;
1835
- this.queue.push(function () {
1836
- self.observer.onNext(value);
1837
- });
1946
+ this.queue.push(function () { self.observer.onNext(value); });
1838
1947
  };
1839
1948
 
1840
- ScheduledObserver.prototype.error = function (err) {
1949
+ ScheduledObserver.prototype.error = function (e) {
1841
1950
  var self = this;
1842
- this.queue.push(function () {
1843
- self.observer.onError(err);
1844
- });
1951
+ this.queue.push(function () { self.observer.onError(e); });
1845
1952
  };
1846
1953
 
1847
1954
  ScheduledObserver.prototype.completed = function () {
1848
1955
  var self = this;
1849
- this.queue.push(function () {
1850
- self.observer.onCompleted();
1851
- });
1956
+ this.queue.push(function () { self.observer.onCompleted(); });
1852
1957
  };
1853
1958
 
1854
1959
  ScheduledObserver.prototype.ensureActive = function () {
@@ -1889,8 +1994,9 @@
1889
1994
  var ObserveOnObserver = (function (__super__) {
1890
1995
  inherits(ObserveOnObserver, __super__);
1891
1996
 
1892
- function ObserveOnObserver() {
1893
- __super__.apply(this, arguments);
1997
+ function ObserveOnObserver(scheduler, observer, cancel) {
1998
+ __super__.call(this, scheduler, observer);
1999
+ this._cancel = cancel;
1894
2000
  }
1895
2001
 
1896
2002
  ObserveOnObserver.prototype.next = function (value) {
@@ -1908,6 +2014,12 @@
1908
2014
  this.ensureActive();
1909
2015
  };
1910
2016
 
2017
+ ObserveOnObserver.prototype.dispose = function () {
2018
+ __super__.prototype.dispose.call(this);
2019
+ this._cancel && this._cancel.dispose();
2020
+ this._cancel = null;
2021
+ };
2022
+
1911
2023
  return ObserveOnObserver;
1912
2024
  })(ScheduledObserver);
1913
2025
 
@@ -1919,6 +2031,24 @@
1919
2031
  var Observable = Rx.Observable = (function () {
1920
2032
 
1921
2033
  function Observable(subscribe) {
2034
+ if (Rx.config.longStackSupport && hasStacks) {
2035
+ try {
2036
+ throw new Error();
2037
+ } catch (e) {
2038
+ this.stack = e.stack.substring(e.stack.indexOf("\n") + 1);
2039
+ }
2040
+
2041
+ var self = this;
2042
+ this._subscribe = function (observer) {
2043
+ observer.onError = function (err) {
2044
+ makeStackTraceLong(self, err);
2045
+ observer.onError(err);
2046
+ };
2047
+
2048
+ subscribe(observer);
2049
+ };
2050
+ }
2051
+
1922
2052
  this._subscribe = subscribe;
1923
2053
  }
1924
2054
 
@@ -1983,7 +2113,7 @@
1983
2113
  var source = this;
1984
2114
  return new AnonymousObservable(function (observer) {
1985
2115
  return source.subscribe(new ObserveOnObserver(scheduler, observer));
1986
- });
2116
+ }, source);
1987
2117
  };
1988
2118
 
1989
2119
  /**
@@ -2005,7 +2135,7 @@
2005
2135
  d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2006
2136
  }));
2007
2137
  return d;
2008
- });
2138
+ }, source);
2009
2139
  };
2010
2140
 
2011
2141
  /**
@@ -2019,10 +2149,8 @@
2019
2149
 
2020
2150
  promise.then(
2021
2151
  function (value) {
2022
- if (!subject.isDisposed) {
2023
- subject.onNext(value);
2024
- subject.onCompleted();
2025
- }
2152
+ subject.onNext(value);
2153
+ subject.onCompleted();
2026
2154
  },
2027
2155
  subject.onError.bind(subject));
2028
2156
 
@@ -2058,36 +2186,34 @@
2058
2186
  };
2059
2187
 
2060
2188
  /**
2061
- * Creates a list from an observable sequence.
2062
- * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
2189
+ * Creates an array from an observable sequence.
2190
+ * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2063
2191
  */
2064
2192
  observableProto.toArray = function () {
2065
- var self = this;
2193
+ var source = this;
2066
2194
  return new AnonymousObservable(function(observer) {
2067
2195
  var arr = [];
2068
- return self.subscribe(
2196
+ return source.subscribe(
2069
2197
  arr.push.bind(arr),
2070
2198
  observer.onError.bind(observer),
2071
2199
  function () {
2072
2200
  observer.onNext(arr);
2073
2201
  observer.onCompleted();
2074
2202
  });
2075
- });
2203
+ }, source);
2076
2204
  };
2077
2205
 
2078
2206
  /**
2079
2207
  * Creates an observable sequence from a specified subscribe method implementation.
2080
- *
2081
2208
  * @example
2082
2209
  * var res = Rx.Observable.create(function (observer) { return function () { } );
2083
2210
  * var res = Rx.Observable.create(function (observer) { return Rx.Disposable.empty; } );
2084
2211
  * var res = Rx.Observable.create(function (observer) { } );
2085
- *
2086
2212
  * @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable.
2087
2213
  * @returns {Observable} The observable sequence with the specified implementation for the Subscribe method.
2088
2214
  */
2089
- Observable.create = Observable.createWithDisposable = function (subscribe) {
2090
- return new AnonymousObservable(subscribe);
2215
+ Observable.create = Observable.createWithDisposable = function (subscribe, parent) {
2216
+ return new AnonymousObservable(subscribe, parent);
2091
2217
  };
2092
2218
 
2093
2219
  /**
@@ -2131,6 +2257,60 @@
2131
2257
 
2132
2258
  var maxSafeInteger = Math.pow(2, 53) - 1;
2133
2259
 
2260
+ function StringIterable(str) {
2261
+ this._s = s;
2262
+ }
2263
+
2264
+ StringIterable.prototype[$iterator$] = function () {
2265
+ return new StringIterator(this._s);
2266
+ };
2267
+
2268
+ function StringIterator(str) {
2269
+ this._s = s;
2270
+ this._l = s.length;
2271
+ this._i = 0;
2272
+ }
2273
+
2274
+ StringIterator.prototype[$iterator$] = function () {
2275
+ return this;
2276
+ };
2277
+
2278
+ StringIterator.prototype.next = function () {
2279
+ if (this._i < this._l) {
2280
+ var val = this._s.charAt(this._i++);
2281
+ return { done: false, value: val };
2282
+ } else {
2283
+ return doneEnumerator;
2284
+ }
2285
+ };
2286
+
2287
+ function ArrayIterable(a) {
2288
+ this._a = a;
2289
+ }
2290
+
2291
+ ArrayIterable.prototype[$iterator$] = function () {
2292
+ return new ArrayIterator(this._a);
2293
+ };
2294
+
2295
+ function ArrayIterator(a) {
2296
+ this._a = a;
2297
+ this._l = toLength(a);
2298
+ this._i = 0;
2299
+ }
2300
+
2301
+ ArrayIterator.prototype[$iterator$] = function () {
2302
+ return this;
2303
+ };
2304
+
2305
+ ArrayIterator.prototype.next = function () {
2306
+ if (this._i < this._l) {
2307
+ var val = this._a[this._i++];
2308
+ return { done: false, value: val };
2309
+ } else {
2310
+ return doneEnumerator;
2311
+ }
2312
+ };
2313
+
2134
2314
  function numberIsFinite(value) {
2135
2315
  return typeof value === 'number' && root.isFinite(value);
2136
2316
  }
@@ -2139,8 +2319,18 @@
2139
2319
  return n !== n;
2140
2320
  }
2141
2321
 
2142
- function isIterable(o) {
2143
- return o[$iterator$] !== undefined;
2322
+ function getIterable(o) {
2323
+ var i = o[$iterator$], it;
2324
+ if (!i && typeof o === 'string') {
2325
+ it = new StringIterable(o);
2326
+ return it[$iterator$]();
2327
+ }
2328
+ if (!i && o.length !== undefined) {
2329
+ it = new ArrayIterable(o);
2330
+ return it[$iterator$]();
2331
+ }
2332
+ if (!i) { throw new TypeError('Object is not iterable'); }
2333
+ return o[$iterator$]();
2144
2334
  }
2145
2335
 
2146
2336
  function sign(value) {
@@ -2160,10 +2350,6 @@
2160
2350
  return len;
2161
2351
  }
2162
2352
 
2163
- function isCallable(f) {
2164
- return Object.prototype.toString.call(f) === '[object Function]' && typeof f === 'function';
2165
- }
2166
-
2167
2353
  /**
2168
2354
  * This method creates a new Observable sequence from an array-like or iterable object.
2169
2355
  * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
@@ -2175,66 +2361,52 @@
2175
2361
  if (iterable == null) {
2176
2362
  throw new Error('iterable cannot be null.')
2177
2363
  }
2178
- if (mapFn && !isCallable(mapFn)) {
2364
+ if (mapFn && !isFunction(mapFn)) {
2179
2365
  throw new Error('mapFn when provided must be a function');
2180
2366
  }
2181
2367
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2368
+ var list = Object(iterable), it = getIterable(list);
2182
2369
  return new AnonymousObservable(function (observer) {
2183
- var list = Object(iterable),
2184
- objIsIterable = isIterable(list),
2185
- len = objIsIterable ? 0 : toLength(list),
2186
- it = objIsIterable ? list[$iterator$]() : null,
2187
- i = 0;
2370
+ var i = 0;
2188
2371
  return scheduler.scheduleRecursive(function (self) {
2189
- if (i < len || objIsIterable) {
2190
- var result;
2191
- if (objIsIterable) {
2192
- var next;
2193
- try {
2194
- next = it.next();
2195
- } catch (e) {
2196
- observer.onError(e);
2197
- return;
2198
- }
2199
- if (next.done) {
2200
- observer.onCompleted();
2201
- return;
2202
- }
2372
+ var next;
2373
+ try {
2374
+ next = it.next();
2375
+ } catch (e) {
2376
+ observer.onError(e);
2377
+ return;
2378
+ }
2379
+ if (next.done) {
2380
+ observer.onCompleted();
2381
+ return;
2382
+ }
2203
2383
 
2204
- result = next.value;
2205
- } else {
2206
- result = !!list.charAt ? list.charAt(i) : list[i];
2207
- }
2384
+ var result = next.value;
2208
2385
 
2209
- if (mapFn && isCallable(mapFn)) {
2210
- try {
2211
- result = thisArg ? mapFn.call(thisArg, result, i) : mapFn(result, i);
2212
- } catch (e) {
2213
- observer.onError(e);
2214
- return;
2215
- }
2386
+ if (mapFn && isFunction(mapFn)) {
2387
+ try {
2388
+ result = mapFn.call(thisArg, result, i);
2389
+ } catch (e) {
2390
+ observer.onError(e);
2391
+ return;
2216
2392
  }
2217
-
2218
- observer.onNext(result);
2219
- i++;
2220
- self();
2221
- } else {
2222
- observer.onCompleted();
2223
2393
  }
2394
+
2395
+ observer.onNext(result);
2396
+ i++;
2397
+ self();
2224
2398
  });
2225
2399
  });
2226
2400
  };
2227
2401
 
2228
2402
  /**
2229
2403
  * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2230
- *
2231
- * @example
2232
- * var res = Rx.Observable.fromArray([1,2,3]);
2233
- * var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
2404
+ * @deprecated use Observable.from or Observable.of
2234
2405
  * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2235
2406
  * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2236
2407
  */
2237
2408
  var observableFromArray = Observable.fromArray = function (array, scheduler) {
2409
+ deprecate('fromArray', 'from');
2238
2410
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2239
2411
  return new AnonymousObservable(function (observer) {
2240
2412
  var count = 0, len = array.length;
@@ -2292,29 +2464,36 @@
2292
2464
  });
2293
2465
  };
2294
2466
 
2467
+ function observableOf (scheduler, array) {
2468
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2469
+ return new AnonymousObservable(function (observer) {
2470
+ var count = 0, len = array.length;
2471
+ return scheduler.scheduleRecursive(function (self) {
2472
+ if (count < len) {
2473
+ observer.onNext(array[count++]);
2474
+ self();
2475
+ } else {
2476
+ observer.onCompleted();
2477
+ }
2478
+ });
2479
+ });
2480
+ }
2481
+
2295
2482
  /**
2296
2483
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2297
- * @example
2298
- * var res = Rx.Observable.of(1,2,3);
2299
2484
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2300
2485
  */
2301
2486
  Observable.of = function () {
2302
- var len = arguments.length, args = new Array(len);
2303
- for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2304
- return observableFromArray(args);
2487
+ return observableOf(null, arguments);
2305
2488
  };
2306
2489
 
2307
2490
  /**
2308
2491
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2309
- * @example
2310
- * var res = Rx.Observable.of(1,2,3);
2311
2492
  * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2312
2493
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2313
2494
  */
2314
- var observableOf = Observable.ofWithScheduler = function (scheduler) {
2315
- var len = arguments.length - 1, args = new Array(len);
2316
- for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
2317
- return observableFromArray(args, scheduler);
2495
+ Observable.ofWithScheduler = function (scheduler) {
2496
+ return observableOf(scheduler, slice.call(arguments, 1));
2318
2497
  };
2319
2498
 
2320
2499
  /**
@@ -2381,7 +2560,7 @@
2381
2560
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2382
2561
  * @returns {Observable} An observable sequence containing the single specified element.
2383
2562
  */
2384
- var observableReturn = Observable['return'] = Observable.returnValue = Observable.just = function (value, scheduler) {
2563
+ var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
2385
2564
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2386
2565
  return new AnonymousObservable(function (observer) {
2387
2566
  return scheduler.schedule(function () {
@@ -2391,6 +2570,12 @@
2391
2570
  });
2392
2571
  };
2393
2572
 
2573
+ /** @deprecated use return or just */
2574
+ Observable.returnValue = function () {
2575
+ deprecate('returnValue', 'return or just');
2576
+ return observableReturn.apply(null, arguments);
2577
+ };
2578
+
2394
2579
  /**
2395
2580
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2396
2581
  * There is an alias to this method called 'throwError' for browsers <IE9.
@@ -2533,7 +2718,7 @@
2533
2718
  }, observer.onCompleted.bind(observer)));
2534
2719
 
2535
2720
  return subscription;
2536
- });
2721
+ }, source);
2537
2722
  }
2538
2723
 
2539
2724
  /**
@@ -2544,19 +2729,35 @@
2544
2729
  * @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.
2545
2730
  * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2546
2731
  */
2547
- observableProto['catch'] = observableProto.catchError = observableProto.catchException = function (handlerOrSecond) {
2732
+ observableProto['catch'] = observableProto.catchError = function (handlerOrSecond) {
2548
2733
  return typeof handlerOrSecond === 'function' ?
2549
2734
  observableCatchHandler(this, handlerOrSecond) :
2550
2735
  observableCatch([this, handlerOrSecond]);
2551
2736
  };
2552
2737
 
2738
+ /**
2739
+ * @deprecated use #catch or #catchError instead.
2740
+ */
2741
+ observableProto.catchException = function (handlerOrSecond) {
2742
+ deprecate('catchException', 'catch or catchError');
2743
+ return this.catchError(handlerOrSecond);
2744
+ };
2745
+
2553
2746
  /**
2554
2747
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2555
2748
  * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
2556
2749
  * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
2557
2750
  */
2558
- var observableCatch = Observable.catchException = Observable.catchError = Observable['catch'] = function () {
2559
- return enumerableOf(argsOrArray(arguments, 0)).catchException();
2751
+ var observableCatch = Observable.catchError = Observable['catch'] = function () {
2752
+ return enumerableOf(argsOrArray(arguments, 0)).catchError();
2753
+ };
2754
+
2755
+ /**
2756
+ * @deprecated use #catch or #catchError instead.
2757
+ */
2758
+ Observable.catchException = function () {
2759
+ deprecate('catchException', 'catch or catchError');
2760
+ return observableCatch.apply(null, arguments);
2560
2761
  };
2561
2762
 
2562
2763
  /**
@@ -2640,7 +2841,7 @@
2640
2841
  }
2641
2842
 
2642
2843
  return new CompositeDisposable(subscriptions);
2643
- });
2844
+ }, this);
2644
2845
  };
2645
2846
 
2646
2847
  /**
@@ -2666,13 +2867,19 @@
2666
2867
  return enumerableOf(argsOrArray(arguments, 0)).concat();
2667
2868
  };
2668
2869
 
2669
- /**
2670
- * Concatenates an observable sequence of observable sequences.
2671
- * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
2672
- */
2673
- observableProto.concatObservable = observableProto.concatAll =function () {
2674
- return this.merge(1);
2675
- };
2870
+ /**
2871
+ * Concatenates an observable sequence of observable sequences.
2872
+ * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
2873
+ */
2874
+ observableProto.concatAll = function () {
2875
+ return this.merge(1);
2876
+ };
2877
+
2878
+ /** @deprecated Use `concatAll` instead. */
2879
+ observableProto.concatObservable = function () {
2880
+ deprecate('concatObservable', 'concatAll');
2881
+ return this.merge(1);
2882
+ };
2676
2883
 
2677
2884
  /**
2678
2885
  * Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences.
@@ -2719,43 +2926,37 @@
2719
2926
  activeCount === 0 && observer.onCompleted();
2720
2927
  }));
2721
2928
  return group;
2722
- });
2929
+ }, sources);
2723
2930
  };
2724
2931
 
2725
- /**
2726
- * Merges all the observable sequences into a single observable sequence.
2727
- * The scheduler is optional and if not specified, the immediate scheduler is used.
2728
- *
2729
- * @example
2730
- * 1 - merged = Rx.Observable.merge(xs, ys, zs);
2731
- * 2 - merged = Rx.Observable.merge([xs, ys, zs]);
2732
- * 3 - merged = Rx.Observable.merge(scheduler, xs, ys, zs);
2733
- * 4 - merged = Rx.Observable.merge(scheduler, [xs, ys, zs]);
2734
- * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
2735
- */
2736
- var observableMerge = Observable.merge = function () {
2737
- var scheduler, sources;
2738
- if (!arguments[0]) {
2739
- scheduler = immediateScheduler;
2740
- sources = slice.call(arguments, 1);
2741
- } else if (arguments[0].now) {
2742
- scheduler = arguments[0];
2743
- sources = slice.call(arguments, 1);
2744
- } else {
2745
- scheduler = immediateScheduler;
2746
- sources = slice.call(arguments, 0);
2747
- }
2748
- if (Array.isArray(sources[0])) {
2749
- sources = sources[0];
2750
- }
2751
- return observableFromArray(sources, scheduler).mergeObservable();
2752
- };
2932
+ /**
2933
+ * Merges all the observable sequences into a single observable sequence.
2934
+ * The scheduler is optional and if not specified, the immediate scheduler is used.
2935
+ * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
2936
+ */
2937
+ var observableMerge = Observable.merge = function () {
2938
+ var scheduler, sources;
2939
+ if (!arguments[0]) {
2940
+ scheduler = immediateScheduler;
2941
+ sources = slice.call(arguments, 1);
2942
+ } else if (isScheduler(arguments[0])) {
2943
+ scheduler = arguments[0];
2944
+ sources = slice.call(arguments, 1);
2945
+ } else {
2946
+ scheduler = immediateScheduler;
2947
+ sources = slice.call(arguments, 0);
2948
+ }
2949
+ if (Array.isArray(sources[0])) {
2950
+ sources = sources[0];
2951
+ }
2952
+ return observableOf(scheduler, sources).mergeAll();
2953
+ };
2753
2954
 
2754
2955
  /**
2755
2956
  * Merges an observable sequence of observable sequences into an observable sequence.
2756
2957
  * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2757
2958
  */
2758
- observableProto.mergeObservable = observableProto.mergeAll = function () {
2959
+ observableProto.mergeAll = function () {
2759
2960
  var sources = this;
2760
2961
  return new AnonymousObservable(function (observer) {
2761
2962
  var group = new CompositeDisposable(),
@@ -2779,7 +2980,15 @@
2779
2980
  group.length === 1 && observer.onCompleted();
2780
2981
  }));
2781
2982
  return group;
2782
- });
2983
+ }, sources);
2984
+ };
2985
+
2986
+ /**
2987
+ * @deprecated use #mergeAll instead.
2988
+ */
2989
+ observableProto.mergeObservable = function () {
2990
+ deprecate('mergeObservable', 'mergeAll');
2991
+ return this.mergeAll.apply(this, arguments);
2783
2992
  };
2784
2993
 
2785
2994
  /**
@@ -2847,7 +3056,7 @@
2847
3056
  }));
2848
3057
 
2849
3058
  return disposables;
2850
- });
3059
+ }, source);
2851
3060
  };
2852
3061
 
2853
3062
  /**
@@ -2886,7 +3095,7 @@
2886
3095
  !hasLatest && observer.onCompleted();
2887
3096
  });
2888
3097
  return new CompositeDisposable(subscription, innerSubscription);
2889
- });
3098
+ }, sources);
2890
3099
  };
2891
3100
 
2892
3101
  /**
@@ -2902,7 +3111,7 @@
2902
3111
  source.subscribe(observer),
2903
3112
  other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
2904
3113
  );
2905
- });
3114
+ }, source);
2906
3115
  };
2907
3116
 
2908
3117
  function zipArray(second, resultSelector) {
@@ -2923,7 +3132,7 @@
2923
3132
  observer.onCompleted();
2924
3133
  }
2925
3134
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2926
- });
3135
+ }, first);
2927
3136
  }
2928
3137
 
2929
3138
  /**
@@ -2985,7 +3194,7 @@
2985
3194
  }
2986
3195
 
2987
3196
  return new CompositeDisposable(subscriptions);
2988
- });
3197
+ }, parent);
2989
3198
  };
2990
3199
 
2991
3200
  /**
@@ -3055,7 +3264,7 @@
3055
3264
  * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3056
3265
  */
3057
3266
  observableProto.asObservable = function () {
3058
- return new AnonymousObservable(this.subscribe.bind(this));
3267
+ return new AnonymousObservable(this.subscribe.bind(this), this);
3059
3268
  };
3060
3269
 
3061
3270
  /**
@@ -3079,60 +3288,58 @@
3079
3288
  });
3080
3289
  };
3081
3290
 
3082
- /**
3083
- * Dematerializes the explicit notification values of an observable sequence as implicit notifications.
3084
- * @returns {Observable} An observable sequence exhibiting the behavior corresponding to the source sequence's notification values.
3085
- */
3086
- observableProto.dematerialize = function () {
3087
- var source = this;
3088
- return new AnonymousObservable(function (observer) {
3089
- return source.subscribe(function (x) {
3090
- return x.accept(observer);
3091
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3092
- });
3093
- };
3291
+ /**
3292
+ * Dematerializes the explicit notification values of an observable sequence as implicit notifications.
3293
+ * @returns {Observable} An observable sequence exhibiting the behavior corresponding to the source sequence's notification values.
3294
+ */
3295
+ observableProto.dematerialize = function () {
3296
+ var source = this;
3297
+ return new AnonymousObservable(function (observer) {
3298
+ return source.subscribe(function (x) { return x.accept(observer); }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3299
+ }, this);
3300
+ };
3094
3301
 
3095
- /**
3096
- * Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
3097
- *
3098
- * var obs = observable.distinctUntilChanged();
3099
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; });
3100
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; }, function (x, y) { return x === y; });
3101
- *
3102
- * @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
3103
- * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
3104
- * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
3105
- */
3106
- observableProto.distinctUntilChanged = function (keySelector, comparer) {
3107
- var source = this;
3108
- keySelector || (keySelector = identity);
3109
- comparer || (comparer = defaultComparer);
3110
- return new AnonymousObservable(function (observer) {
3111
- var hasCurrentKey = false, currentKey;
3112
- return source.subscribe(function (value) {
3113
- var comparerEquals = false, key;
3114
- try {
3115
- key = keySelector(value);
3116
- } catch (exception) {
3117
- observer.onError(exception);
3118
- return;
3119
- }
3120
- if (hasCurrentKey) {
3121
- try {
3122
- comparerEquals = comparer(currentKey, key);
3123
- } catch (exception) {
3124
- observer.onError(exception);
3125
- return;
3126
- }
3127
- }
3128
- if (!hasCurrentKey || !comparerEquals) {
3129
- hasCurrentKey = true;
3130
- currentKey = key;
3131
- observer.onNext(value);
3132
- }
3133
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3134
- });
3135
- };
3302
+ /**
3303
+ * Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
3304
+ *
3305
+ * var obs = observable.distinctUntilChanged();
3306
+ * var obs = observable.distinctUntilChanged(function (x) { return x.id; });
3307
+ * var obs = observable.distinctUntilChanged(function (x) { return x.id; }, function (x, y) { return x === y; });
3308
+ *
3309
+ * @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
3310
+ * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
3311
+ * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
3312
+ */
3313
+ observableProto.distinctUntilChanged = function (keySelector, comparer) {
3314
+ var source = this;
3315
+ keySelector || (keySelector = identity);
3316
+ comparer || (comparer = defaultComparer);
3317
+ return new AnonymousObservable(function (observer) {
3318
+ var hasCurrentKey = false, currentKey;
3319
+ return source.subscribe(function (value) {
3320
+ var comparerEquals = false, key;
3321
+ try {
3322
+ key = keySelector(value);
3323
+ } catch (e) {
3324
+ observer.onError(e);
3325
+ return;
3326
+ }
3327
+ if (hasCurrentKey) {
3328
+ try {
3329
+ comparerEquals = comparer(currentKey, key);
3330
+ } catch (e) {
3331
+ observer.onError(e);
3332
+ return;
3333
+ }
3334
+ }
3335
+ if (!hasCurrentKey || !comparerEquals) {
3336
+ hasCurrentKey = true;
3337
+ currentKey = key;
3338
+ observer.onNext(value);
3339
+ }
3340
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3341
+ }, this);
3342
+ };
3136
3343
 
3137
3344
  /**
3138
3345
  * Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
@@ -3142,7 +3349,7 @@
3142
3349
  * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
3143
3350
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3144
3351
  */
3145
- observableProto['do'] = observableProto.doAction = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3352
+ observableProto['do'] = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3146
3353
  var source = this, onNextFunc;
3147
3354
  if (typeof observerOrOnNext === 'function') {
3148
3355
  onNextFunc = observerOrOnNext;
@@ -3178,7 +3385,13 @@
3178
3385
  }
3179
3386
  observer.onCompleted();
3180
3387
  });
3181
- });
3388
+ }, this);
3389
+ };
3390
+
3391
+ /** @deprecated use #do or #tap instead. */
3392
+ observableProto.doAction = function () {
3393
+ deprecate('doAction', 'do or tap');
3394
+ return this.tap.apply(this, arguments);
3182
3395
  };
3183
3396
 
3184
3397
  /**
@@ -3216,13 +3429,10 @@
3216
3429
 
3217
3430
  /**
3218
3431
  * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
3219
- *
3220
- * @example
3221
- * var res = observable.finallyAction(function () { console.log('sequence ended'; });
3222
3432
  * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
3223
3433
  * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
3224
3434
  */
3225
- observableProto['finally'] = observableProto.finallyAction = function (action) {
3435
+ observableProto['finally'] = observableProto.ensure = function (action) {
3226
3436
  var source = this;
3227
3437
  return new AnonymousObservable(function (observer) {
3228
3438
  var subscription;
@@ -3241,7 +3451,15 @@
3241
3451
  action();
3242
3452
  }
3243
3453
  });
3244
- });
3454
+ }, this);
3455
+ };
3456
+
3457
+ /**
3458
+ * @deprecated use #finally or #ensure instead.
3459
+ */
3460
+ observableProto.finallyAction = function (action) {
3461
+ deprecate('finallyAction', 'finally or ensure');
3462
+ return this.ensure(action);
3245
3463
  };
3246
3464
 
3247
3465
  /**
@@ -3252,7 +3470,7 @@
3252
3470
  var source = this;
3253
3471
  return new AnonymousObservable(function (observer) {
3254
3472
  return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3255
- });
3473
+ }, source);
3256
3474
  };
3257
3475
 
3258
3476
  /**
@@ -3271,21 +3489,17 @@
3271
3489
  observer.onNext(notificationCreateOnCompleted());
3272
3490
  observer.onCompleted();
3273
3491
  });
3274
- });
3492
+ }, source);
3275
3493
  };
3276
3494
 
3277
- /**
3278
- * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
3279
- *
3280
- * @example
3281
- * var res = repeated = source.repeat();
3282
- * var res = repeated = source.repeat(42);
3283
- * @param {Number} [repeatCount] Number of times to repeat the sequence. If not provided, repeats the sequence indefinitely.
3284
- * @returns {Observable} The observable sequence producing the elements of the given sequence repeatedly.
3285
- */
3286
- observableProto.repeat = function (repeatCount) {
3287
- return enumerableRepeat(this, repeatCount).concat();
3288
- };
3495
+ /**
3496
+ * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
3497
+ * @param {Number} [repeatCount] Number of times to repeat the sequence. If not provided, repeats the sequence indefinitely.
3498
+ * @returns {Observable} The observable sequence producing the elements of the given sequence repeatedly.
3499
+ */
3500
+ observableProto.repeat = function (repeatCount) {
3501
+ return enumerableRepeat(this, repeatCount).concat();
3502
+ };
3289
3503
 
3290
3504
  /**
3291
3505
  * Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.
@@ -3298,7 +3512,7 @@
3298
3512
  * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3299
3513
  */
3300
3514
  observableProto.retry = function (retryCount) {
3301
- return enumerableRepeat(this, retryCount).catchException();
3515
+ return enumerableRepeat(this, retryCount).catchError();
3302
3516
  };
3303
3517
 
3304
3518
  /**
@@ -3345,7 +3559,7 @@
3345
3559
  observer.onCompleted();
3346
3560
  }
3347
3561
  );
3348
- });
3562
+ }, source);
3349
3563
  };
3350
3564
 
3351
3565
  /**
@@ -3364,7 +3578,7 @@
3364
3578
  q.push(x);
3365
3579
  q.length > count && observer.onNext(q.shift());
3366
3580
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3367
- });
3581
+ }, source);
3368
3582
  };
3369
3583
 
3370
3584
  /**
@@ -3403,10 +3617,10 @@
3403
3617
  q.push(x);
3404
3618
  q.length > count && q.shift();
3405
3619
  }, observer.onError.bind(observer), function () {
3406
- while(q.length > 0) { observer.onNext(q.shift()); }
3620
+ while (q.length > 0) { observer.onNext(q.shift()); }
3407
3621
  observer.onCompleted();
3408
3622
  });
3409
- });
3623
+ }, source);
3410
3624
  };
3411
3625
 
3412
3626
  /**
@@ -3429,7 +3643,7 @@
3429
3643
  observer.onNext(q);
3430
3644
  observer.onCompleted();
3431
3645
  });
3432
- });
3646
+ }, source);
3433
3647
  };
3434
3648
 
3435
3649
  /**
@@ -3469,27 +3683,27 @@
3469
3683
  function (x) {
3470
3684
  for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
3471
3685
  var c = n - count + 1;
3472
- c >=0 && c % skip === 0 && q.shift().onCompleted();
3686
+ c >= 0 && c % skip === 0 && q.shift().onCompleted();
3473
3687
  ++n % skip === 0 && createWindow();
3474
- },
3688
+ },
3475
3689
  function (e) {
3476
3690
  while (q.length > 0) { q.shift().onError(e); }
3477
3691
  observer.onError(e);
3478
- },
3692
+ },
3479
3693
  function () {
3480
3694
  while (q.length > 0) { q.shift().onCompleted(); }
3481
3695
  observer.onCompleted();
3482
3696
  }
3483
3697
  ));
3484
3698
  return refCountDisposable;
3485
- });
3699
+ }, source);
3486
3700
  };
3487
3701
 
3488
3702
  function concatMap(source, selector, thisArg) {
3489
3703
  return source.map(function (x, i) {
3490
3704
  var result = selector.call(thisArg, x, i, source);
3491
3705
  isPromise(result) && (result = observableFromPromise(result));
3492
- (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3706
+ (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3493
3707
  return result;
3494
3708
  }).concatAll();
3495
3709
  }
@@ -3514,18 +3728,18 @@
3514
3728
  * @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.
3515
3729
  */
3516
3730
  observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3517
- if (typeof selector === 'function' && typeof resultSelector === 'function') {
3731
+ if (isFunction(selector) && isFunction(resultSelector)) {
3518
3732
  return this.concatMap(function (x, i) {
3519
3733
  var selectorResult = selector(x, i);
3520
3734
  isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3521
- (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3735
+ (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3522
3736
 
3523
3737
  return selectorResult.map(function (y, i2) {
3524
3738
  return resultSelector(x, y, i, i2);
3525
3739
  });
3526
3740
  });
3527
3741
  }
3528
- return typeof selector === 'function' ?
3742
+ return isFunction(selector) ?
3529
3743
  concatMap(this, selector, thisArg) :
3530
3744
  concatMap(this, function () { return selector; });
3531
3745
  };
@@ -3579,7 +3793,7 @@
3579
3793
  observer.onNext(result);
3580
3794
  observer.onCompleted();
3581
3795
  });
3582
- }).concatAll();
3796
+ }, this).concatAll();
3583
3797
  };
3584
3798
 
3585
3799
  /**
@@ -3593,22 +3807,18 @@
3593
3807
  * @returns {Observable} An observable sequence that contains the specified default value if the source is empty; otherwise, the elements of the source itself.
3594
3808
  */
3595
3809
  observableProto.defaultIfEmpty = function (defaultValue) {
3596
- var source = this;
3597
- if (defaultValue === undefined) {
3598
- defaultValue = null;
3599
- }
3600
- return new AnonymousObservable(function (observer) {
3601
- var found = false;
3602
- return source.subscribe(function (x) {
3603
- found = true;
3604
- observer.onNext(x);
3605
- }, observer.onError.bind(observer), function () {
3606
- if (!found) {
3607
- observer.onNext(defaultValue);
3608
- }
3609
- observer.onCompleted();
3610
- });
3810
+ var source = this;
3811
+ defaultValue === undefined && (defaultValue = null);
3812
+ return new AnonymousObservable(function (observer) {
3813
+ var found = false;
3814
+ return source.subscribe(function (x) {
3815
+ found = true;
3816
+ observer.onNext(x);
3817
+ }, observer.onError.bind(observer), function () {
3818
+ !found && observer.onNext(defaultValue);
3819
+ observer.onCompleted();
3611
3820
  });
3821
+ }, this);
3612
3822
  };
3613
3823
 
3614
3824
  // Swap out for Array.findIndex
@@ -3661,7 +3871,7 @@
3661
3871
  },
3662
3872
  observer.onError.bind(observer),
3663
3873
  observer.onCompleted.bind(observer));
3664
- });
3874
+ }, this);
3665
3875
  };
3666
3876
 
3667
3877
  /**
@@ -3775,30 +3985,31 @@
3775
3985
  }));
3776
3986
 
3777
3987
  return refCountDisposable;
3778
- });
3988
+ }, source);
3779
3989
  };
3780
3990
 
3781
3991
  /**
3782
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
3992
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
3783
3993
  * @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.
3784
3994
  * @param {Any} [thisArg] Object to use as this when executing callback.
3785
3995
  * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
3786
3996
  */
3787
3997
  observableProto.select = observableProto.map = function (selector, thisArg) {
3788
- var parent = this;
3998
+ var selectorFn = isFunction(selector) ? selector : function () { return selector; },
3999
+ source = this;
3789
4000
  return new AnonymousObservable(function (observer) {
3790
4001
  var count = 0;
3791
- return parent.subscribe(function (value) {
4002
+ return source.subscribe(function (value) {
3792
4003
  var result;
3793
4004
  try {
3794
- result = selector.call(thisArg, value, count++, parent);
4005
+ result = selectorFn.call(thisArg, value, count++, source);
3795
4006
  } catch (e) {
3796
4007
  observer.onError(e);
3797
4008
  return;
3798
4009
  }
3799
4010
  observer.onNext(result);
3800
4011
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3801
- });
4012
+ }, source);
3802
4013
  };
3803
4014
 
3804
4015
  /**
@@ -3814,9 +4025,9 @@
3814
4025
  return source.map(function (x, i) {
3815
4026
  var result = selector.call(thisArg, x, i, source);
3816
4027
  isPromise(result) && (result = observableFromPromise(result));
3817
- (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
4028
+ (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3818
4029
  return result;
3819
- }).mergeObservable();
4030
+ }).mergeAll();
3820
4031
  }
3821
4032
 
3822
4033
  /**
@@ -3839,18 +4050,18 @@
3839
4050
  * @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.
3840
4051
  */
3841
4052
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3842
- if (typeof selector === 'function' && typeof resultSelector === 'function') {
4053
+ if (isFunction(selector) && isFunction(resultSelector)) {
3843
4054
  return this.flatMap(function (x, i) {
3844
4055
  var selectorResult = selector(x, i);
3845
4056
  isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3846
- (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
4057
+ (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3847
4058
 
3848
4059
  return selectorResult.map(function (y, i2) {
3849
4060
  return resultSelector(x, y, i, i2);
3850
4061
  });
3851
4062
  }, thisArg);
3852
4063
  }
3853
- return typeof selector === 'function' ?
4064
+ return isFunction(selector) ?
3854
4065
  flatMap(this, selector, thisArg) :
3855
4066
  flatMap(this, function () { return selector; });
3856
4067
  };
@@ -3904,7 +4115,7 @@
3904
4115
  observer.onNext(result);
3905
4116
  observer.onCompleted();
3906
4117
  });
3907
- }).mergeAll();
4118
+ }, source).mergeAll();
3908
4119
  };
3909
4120
 
3910
4121
  /**
@@ -3925,18 +4136,18 @@
3925
4136
  * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3926
4137
  */
3927
4138
  observableProto.skip = function (count) {
3928
- if (count < 0) { throw new Error(argumentOutOfRange); }
3929
- var source = this;
3930
- return new AnonymousObservable(function (observer) {
3931
- var remaining = count;
3932
- return source.subscribe(function (x) {
3933
- if (remaining <= 0) {
3934
- observer.onNext(x);
3935
- } else {
3936
- remaining--;
3937
- }
3938
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3939
- });
4139
+ if (count < 0) { throw new Error(argumentOutOfRange); }
4140
+ var source = this;
4141
+ return new AnonymousObservable(function (observer) {
4142
+ var remaining = count;
4143
+ return source.subscribe(function (x) {
4144
+ if (remaining <= 0) {
4145
+ observer.onNext(x);
4146
+ } else {
4147
+ remaining--;
4148
+ }
4149
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4150
+ }, source);
3940
4151
  };
3941
4152
 
3942
4153
  /**
@@ -3964,7 +4175,7 @@
3964
4175
  }
3965
4176
  running && observer.onNext(x);
3966
4177
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3967
- });
4178
+ }, source);
3968
4179
  };
3969
4180
 
3970
4181
  /**
@@ -3977,18 +4188,18 @@
3977
4188
  * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3978
4189
  */
3979
4190
  observableProto.take = function (count, scheduler) {
3980
- if (count < 0) { throw new RangeError(argumentOutOfRange); }
3981
- if (count === 0) { return observableEmpty(scheduler); }
3982
- var observable = this;
3983
- return new AnonymousObservable(function (observer) {
3984
- var remaining = count;
3985
- return observable.subscribe(function (x) {
3986
- if (remaining-- > 0) {
3987
- observer.onNext(x);
3988
- remaining === 0 && observer.onCompleted();
3989
- }
3990
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3991
- });
4191
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
4192
+ if (count === 0) { return observableEmpty(scheduler); }
4193
+ var source = this;
4194
+ return new AnonymousObservable(function (observer) {
4195
+ var remaining = count;
4196
+ return source.subscribe(function (x) {
4197
+ if (remaining-- > 0) {
4198
+ observer.onNext(x);
4199
+ remaining === 0 && observer.onCompleted();
4200
+ }
4201
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4202
+ }, source);
3992
4203
  };
3993
4204
 
3994
4205
  /**
@@ -3999,13 +4210,13 @@
3999
4210
  * @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
4000
4211
  */
4001
4212
  observableProto.takeWhile = function (predicate, thisArg) {
4002
- var observable = this;
4213
+ var source = this;
4003
4214
  return new AnonymousObservable(function (observer) {
4004
4215
  var i = 0, running = true;
4005
- return observable.subscribe(function (x) {
4216
+ return source.subscribe(function (x) {
4006
4217
  if (running) {
4007
4218
  try {
4008
- running = predicate.call(thisArg, x, i++, observable);
4219
+ running = predicate.call(thisArg, x, i++, source);
4009
4220
  } catch (e) {
4010
4221
  observer.onError(e);
4011
4222
  return;
@@ -4017,7 +4228,7 @@
4017
4228
  }
4018
4229
  }
4019
4230
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4020
- });
4231
+ }, source);
4021
4232
  };
4022
4233
 
4023
4234
  /**
@@ -4031,20 +4242,20 @@
4031
4242
  * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4032
4243
  */
4033
4244
  observableProto.where = observableProto.filter = function (predicate, thisArg) {
4034
- var parent = this;
4035
- return new AnonymousObservable(function (observer) {
4036
- var count = 0;
4037
- return parent.subscribe(function (value) {
4038
- var shouldRun;
4039
- try {
4040
- shouldRun = predicate.call(thisArg, value, count++, parent);
4041
- } catch (e) {
4042
- observer.onError(e);
4043
- return;
4044
- }
4045
- shouldRun && observer.onNext(value);
4046
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4047
- });
4245
+ var source = this;
4246
+ return new AnonymousObservable(function (observer) {
4247
+ var count = 0;
4248
+ return source.subscribe(function (value) {
4249
+ var shouldRun;
4250
+ try {
4251
+ shouldRun = predicate.call(thisArg, value, count++, parent);
4252
+ } catch (e) {
4253
+ observer.onError(e);
4254
+ return;
4255
+ }
4256
+ shouldRun && observer.onNext(value);
4257
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4258
+ }, source);
4048
4259
  };
4049
4260
 
4050
4261
  observableProto.finalValue = function () {
@@ -4062,7 +4273,7 @@
4062
4273
  observer.onCompleted();
4063
4274
  }
4064
4275
  });
4065
- });
4276
+ }, source);
4066
4277
  };
4067
4278
 
4068
4279
  function extremaBy(source, keySelector, comparer) {
@@ -4097,24 +4308,24 @@
4097
4308
  observer.onNext(list);
4098
4309
  observer.onCompleted();
4099
4310
  });
4100
- });
4311
+ }, source);
4101
4312
  }
4102
4313
 
4103
- function firstOnly(x) {
4104
- if (x.length === 0) {
4105
- throw new Error(sequenceContainsNoElements);
4106
- }
4107
- return x[0];
4108
- }
4314
+ function firstOnly(x) {
4315
+ if (x.length === 0) { throw new Error(sequenceContainsNoElements); }
4316
+ return x[0];
4317
+ }
4109
4318
 
4110
4319
  /**
4111
4320
  * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4112
4321
  * For aggregation behavior with incremental intermediate results, see Observable.scan.
4322
+ * @deprecated Use #reduce instead
4113
4323
  * @param {Mixed} [seed] The initial accumulator value.
4114
4324
  * @param {Function} accumulator An accumulator function to be invoked on each element.
4115
4325
  * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4116
4326
  */
4117
4327
  observableProto.aggregate = function () {
4328
+ deprecate('aggregate', 'reduce');
4118
4329
  var seed, hasSeed, accumulator;
4119
4330
  if (arguments.length === 2) {
4120
4331
  seed = arguments[0];
@@ -4142,28 +4353,31 @@
4142
4353
  return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4143
4354
  };
4144
4355
 
4145
- /**
4146
- * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
4147
- * @example
4148
- * var result = source.any();
4149
- * var result = source.any(function (x) { return x > 3; });
4150
- * @param {Function} [predicate] A function to test each element for a condition.
4151
- * @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
4152
- */
4153
- observableProto.some = observableProto.any = function (predicate, thisArg) {
4154
- var source = this;
4155
- return predicate ?
4156
- source.where(predicate, thisArg).any() :
4157
- new AnonymousObservable(function (observer) {
4158
- return source.subscribe(function () {
4159
- observer.onNext(true);
4160
- observer.onCompleted();
4161
- }, observer.onError.bind(observer), function () {
4162
- observer.onNext(false);
4163
- observer.onCompleted();
4164
- });
4165
- });
4166
- };
4356
+ /**
4357
+ * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
4358
+ * @param {Function} [predicate] A function to test each element for a condition.
4359
+ * @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
4360
+ */
4361
+ observableProto.some = function (predicate, thisArg) {
4362
+ var source = this;
4363
+ return predicate ?
4364
+ source.filter(predicate, thisArg).some() :
4365
+ new AnonymousObservable(function (observer) {
4366
+ return source.subscribe(function () {
4367
+ observer.onNext(true);
4368
+ observer.onCompleted();
4369
+ }, observer.onError.bind(observer), function () {
4370
+ observer.onNext(false);
4371
+ observer.onCompleted();
4372
+ });
4373
+ }, source);
4374
+ };
4375
+
4376
+ /** @deprecated use #some instead */
4377
+ observableProto.any = function () {
4378
+ deprecate('any', 'some');
4379
+ return this.some.apply(this, arguments);
4380
+ };
4167
4381
 
4168
4382
  /**
4169
4383
  * Determines whether an observable sequence is empty.
@@ -4173,22 +4387,21 @@
4173
4387
  return this.any().map(not);
4174
4388
  };
4175
4389
 
4176
- /**
4177
- * Determines whether all elements of an observable sequence satisfy a condition.
4178
- *
4179
- * 1 - res = source.all(function (value) { return value.length > 3; });
4180
- * @memberOf Observable#
4181
- * @param {Function} [predicate] A function to test each element for a condition.
4182
- * @param {Any} [thisArg] Object to use as this when executing callback.
4183
- * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
4184
- */
4185
- observableProto.every = observableProto.all = function (predicate, thisArg) {
4186
- return this.where(function (v) {
4187
- return !predicate(v);
4188
- }, thisArg).any().select(function (b) {
4189
- return !b;
4190
- });
4191
- };
4390
+ /**
4391
+ * Determines whether all elements of an observable sequence satisfy a condition.
4392
+ * @param {Function} [predicate] A function to test each element for a condition.
4393
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4394
+ * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
4395
+ */
4396
+ observableProto.every = function (predicate, thisArg) {
4397
+ return this.filter(function (v) { return !predicate(v); }, thisArg).some().map(not);
4398
+ };
4399
+
4400
+ /** @deprecated use #every instead */
4401
+ observableProto.all = function () {
4402
+ deprecate('all', 'every');
4403
+ return this.every.apply(this, arguments);
4404
+ };
4192
4405
 
4193
4406
  /**
4194
4407
  * Determines whether an observable sequence contains a specified element with an optional equality comparer.
@@ -4221,7 +4434,7 @@
4221
4434
  observer.onNext(false);
4222
4435
  observer.onCompleted();
4223
4436
  });
4224
- });
4437
+ }, this);
4225
4438
  };
4226
4439
 
4227
4440
  /**
@@ -4270,13 +4483,11 @@
4270
4483
  observer.onNext(-1);
4271
4484
  observer.onCompleted();
4272
4485
  });
4273
- });
4486
+ }, source);
4274
4487
  };
4488
+
4275
4489
  /**
4276
4490
  * Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
4277
- * @example
4278
- * var res = source.sum();
4279
- * var res = source.sum(function (x) { return x.value; });
4280
4491
  * @param {Function} [selector] A transform function to apply to each element.
4281
4492
  * @param {Any} [thisArg] Object to use as this when executing callback.
4282
4493
  * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
@@ -4284,68 +4495,62 @@
4284
4495
  observableProto.sum = function (keySelector, thisArg) {
4285
4496
  return keySelector && isFunction(keySelector) ?
4286
4497
  this.map(keySelector, thisArg).sum() :
4287
- this.aggregate(0, function (prev, curr) {
4498
+ this.reduce(function (prev, curr) {
4288
4499
  return prev + curr;
4289
- });
4500
+ }, 0);
4290
4501
  };
4291
4502
 
4292
- /**
4293
- * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4294
- * @example
4295
- * var res = source.minBy(function (x) { return x.value; });
4296
- * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
4297
- * @param {Function} keySelector Key selector function.
4298
- * @param {Function} [comparer] Comparer used to compare key values.
4299
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
4300
- */
4301
- observableProto.minBy = function (keySelector, comparer) {
4302
- comparer || (comparer = defaultSubComparer);
4303
- return extremaBy(this, keySelector, function (x, y) {
4304
- return comparer(x, y) * -1;
4305
- });
4306
- };
4503
+ /**
4504
+ * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4505
+ * @example
4506
+ * var res = source.minBy(function (x) { return x.value; });
4507
+ * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
4508
+ * @param {Function} keySelector Key selector function.
4509
+ * @param {Function} [comparer] Comparer used to compare key values.
4510
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
4511
+ */
4512
+ observableProto.minBy = function (keySelector, comparer) {
4513
+ comparer || (comparer = defaultSubComparer);
4514
+ return extremaBy(this, keySelector, function (x, y) { return comparer(x, y) * -1; });
4515
+ };
4307
4516
 
4308
- /**
4309
- * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
4310
- * @example
4311
- * var res = source.min();
4312
- * var res = source.min(function (x, y) { return x.value - y.value; });
4313
- * @param {Function} [comparer] Comparer used to compare elements.
4314
- * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
4315
- */
4316
- observableProto.min = function (comparer) {
4317
- return this.minBy(identity, comparer).select(function (x) {
4318
- return firstOnly(x);
4319
- });
4320
- };
4517
+ /**
4518
+ * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
4519
+ * @example
4520
+ * var res = source.min();
4521
+ * var res = source.min(function (x, y) { return x.value - y.value; });
4522
+ * @param {Function} [comparer] Comparer used to compare elements.
4523
+ * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
4524
+ */
4525
+ observableProto.min = function (comparer) {
4526
+ return this.minBy(identity, comparer).map(function (x) { return firstOnly(x); });
4527
+ };
4321
4528
 
4322
- /**
4323
- * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
4324
- * @example
4325
- * var res = source.maxBy(function (x) { return x.value; });
4326
- * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
4327
- * @param {Function} keySelector Key selector function.
4328
- * @param {Function} [comparer] Comparer used to compare key values.
4329
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
4330
- */
4331
- observableProto.maxBy = function (keySelector, comparer) {
4332
- comparer || (comparer = defaultSubComparer);
4333
- return extremaBy(this, keySelector, comparer);
4334
- };
4529
+ /**
4530
+ * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
4531
+ * @example
4532
+ * var res = source.maxBy(function (x) { return x.value; });
4533
+ * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
4534
+ * @param {Function} keySelector Key selector function.
4535
+ * @param {Function} [comparer] Comparer used to compare key values.
4536
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
4537
+ */
4538
+ observableProto.maxBy = function (keySelector, comparer) {
4539
+ comparer || (comparer = defaultSubComparer);
4540
+ return extremaBy(this, keySelector, comparer);
4541
+ };
4335
4542
 
4336
- /**
4337
- * Returns the maximum value in an observable sequence according to the specified comparer.
4338
- * @example
4339
- * var res = source.max();
4340
- * var res = source.max(function (x, y) { return x.value - y.value; });
4341
- * @param {Function} [comparer] Comparer used to compare elements.
4342
- * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
4343
- */
4344
- observableProto.max = function (comparer) {
4345
- return this.maxBy(identity, comparer).select(function (x) {
4346
- return firstOnly(x);
4347
- });
4348
- };
4543
+ /**
4544
+ * Returns the maximum value in an observable sequence according to the specified comparer.
4545
+ * @example
4546
+ * var res = source.max();
4547
+ * var res = source.max(function (x, y) { return x.value - y.value; });
4548
+ * @param {Function} [comparer] Comparer used to compare elements.
4549
+ * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
4550
+ */
4551
+ observableProto.max = function (comparer) {
4552
+ return this.maxBy(identity, comparer).map(function (x) { return firstOnly(x); });
4553
+ };
4349
4554
 
4350
4555
  /**
4351
4556
  * Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
@@ -4369,28 +4574,6 @@
4369
4574
  });
4370
4575
  };
4371
4576
 
4372
- function sequenceEqualArray(first, second, comparer) {
4373
- return new AnonymousObservable(function (observer) {
4374
- var count = 0, len = second.length;
4375
- return first.subscribe(function (value) {
4376
- var equal = false;
4377
- try {
4378
- count < len && (equal = comparer(value, second[count++]));
4379
- } catch (e) {
4380
- observer.onError(e);
4381
- return;
4382
- }
4383
- if (!equal) {
4384
- observer.onNext(false);
4385
- observer.onCompleted();
4386
- }
4387
- }, observer.onError.bind(observer), function () {
4388
- observer.onNext(count === len);
4389
- observer.onCompleted();
4390
- });
4391
- });
4392
- }
4393
-
4394
4577
  /**
4395
4578
  * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
4396
4579
  *
@@ -4406,9 +4589,6 @@
4406
4589
  observableProto.sequenceEqual = function (second, comparer) {
4407
4590
  var first = this;
4408
4591
  comparer || (comparer = defaultComparer);
4409
- if (Array.isArray(second)) {
4410
- return sequenceEqualArray(first, second, comparer);
4411
- }
4412
4592
  return new AnonymousObservable(function (observer) {
4413
4593
  var donel = false, doner = false, ql = [], qr = [];
4414
4594
  var subscription1 = first.subscribe(function (x) {
@@ -4444,6 +4624,7 @@
4444
4624
  }
4445
4625
  });
4446
4626
 
4627
+ (isArrayLike(second) || isIterable(second)) && (second = observableFrom(second));
4447
4628
  isPromise(second) && (second = observableFromPromise(second));
4448
4629
  var subscription2 = second.subscribe(function (x) {
4449
4630
  var equal;
@@ -4478,55 +4659,52 @@
4478
4659
  }
4479
4660
  });
4480
4661
  return new CompositeDisposable(subscription1, subscription2);
4481
- });
4662
+ }, first);
4482
4663
  };
4483
4664
 
4484
- function elementAtOrDefault(source, index, hasDefault, defaultValue) {
4485
- if (index < 0) {
4486
- throw new Error(argumentOutOfRange);
4665
+ function elementAtOrDefault(source, index, hasDefault, defaultValue) {
4666
+ if (index < 0) { throw new Error(argumentOutOfRange); }
4667
+ return new AnonymousObservable(function (observer) {
4668
+ var i = index;
4669
+ return source.subscribe(function (x) {
4670
+ if (i-- === 0) {
4671
+ observer.onNext(x);
4672
+ observer.onCompleted();
4487
4673
  }
4488
- return new AnonymousObservable(function (observer) {
4489
- var i = index;
4490
- return source.subscribe(function (x) {
4491
- if (i === 0) {
4492
- observer.onNext(x);
4493
- observer.onCompleted();
4494
- }
4495
- i--;
4496
- }, observer.onError.bind(observer), function () {
4497
- if (!hasDefault) {
4498
- observer.onError(new Error(argumentOutOfRange));
4499
- } else {
4500
- observer.onNext(defaultValue);
4501
- observer.onCompleted();
4502
- }
4503
- });
4504
- });
4505
- }
4674
+ }, observer.onError.bind(observer), function () {
4675
+ if (!hasDefault) {
4676
+ observer.onError(new Error(argumentOutOfRange));
4677
+ } else {
4678
+ observer.onNext(defaultValue);
4679
+ observer.onCompleted();
4680
+ }
4681
+ });
4682
+ }, source);
4683
+ }
4506
4684
 
4507
- /**
4508
- * Returns the element at a specified index in a sequence.
4509
- * @example
4510
- * var res = source.elementAt(5);
4511
- * @param {Number} index The zero-based index of the element to retrieve.
4512
- * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
4513
- */
4514
- observableProto.elementAt = function (index) {
4515
- return elementAtOrDefault(this, index, false);
4516
- };
4685
+ /**
4686
+ * Returns the element at a specified index in a sequence.
4687
+ * @example
4688
+ * var res = source.elementAt(5);
4689
+ * @param {Number} index The zero-based index of the element to retrieve.
4690
+ * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
4691
+ */
4692
+ observableProto.elementAt = function (index) {
4693
+ return elementAtOrDefault(this, index, false);
4694
+ };
4517
4695
 
4518
- /**
4519
- * Returns the element at a specified index in a sequence or a default value if the index is out of range.
4520
- * @example
4521
- * var res = source.elementAtOrDefault(5);
4522
- * var res = source.elementAtOrDefault(5, 0);
4523
- * @param {Number} index The zero-based index of the element to retrieve.
4524
- * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4525
- * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.
4526
- */
4527
- observableProto.elementAtOrDefault = function (index, defaultValue) {
4528
- return elementAtOrDefault(this, index, true, defaultValue);
4529
- };
4696
+ /**
4697
+ * Returns the element at a specified index in a sequence or a default value if the index is out of range.
4698
+ * @example
4699
+ * var res = source.elementAtOrDefault(5);
4700
+ * var res = source.elementAtOrDefault(5, 0);
4701
+ * @param {Number} index The zero-based index of the element to retrieve.
4702
+ * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4703
+ * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.
4704
+ */
4705
+ observableProto.elementAtOrDefault = function (index, defaultValue) {
4706
+ return elementAtOrDefault(this, index, true, defaultValue);
4707
+ };
4530
4708
 
4531
4709
  function singleOrDefaultAsync(source, hasDefault, defaultValue) {
4532
4710
  return new AnonymousObservable(function (observer) {
@@ -4546,14 +4724,11 @@
4546
4724
  observer.onCompleted();
4547
4725
  }
4548
4726
  });
4549
- });
4727
+ }, source);
4550
4728
  }
4551
4729
 
4552
4730
  /**
4553
4731
  * Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
4554
- * @example
4555
- * var res = res = source.single();
4556
- * var res = res = source.single(function (x) { return x === 42; });
4557
4732
  * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4558
4733
  * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4559
4734
  * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
@@ -4583,211 +4758,198 @@
4583
4758
  singleOrDefaultAsync(this, true, defaultValue);
4584
4759
  };
4585
4760
 
4586
- function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4587
- return new AnonymousObservable(function (observer) {
4588
- return source.subscribe(function (x) {
4589
- observer.onNext(x);
4590
- observer.onCompleted();
4591
- }, observer.onError.bind(observer), function () {
4592
- if (!hasDefault) {
4593
- observer.onError(new Error(sequenceContainsNoElements));
4594
- } else {
4595
- observer.onNext(defaultValue);
4596
- observer.onCompleted();
4597
- }
4598
- });
4599
- });
4600
- }
4761
+ function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4762
+ return new AnonymousObservable(function (observer) {
4763
+ return source.subscribe(function (x) {
4764
+ observer.onNext(x);
4765
+ observer.onCompleted();
4766
+ }, observer.onError.bind(observer), function () {
4767
+ if (!hasDefault) {
4768
+ observer.onError(new Error(sequenceContainsNoElements));
4769
+ } else {
4770
+ observer.onNext(defaultValue);
4771
+ observer.onCompleted();
4772
+ }
4773
+ });
4774
+ }, source);
4775
+ }
4601
4776
 
4602
- /**
4603
- * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
4604
- * @example
4605
- * var res = res = source.first();
4606
- * var res = res = source.first(function (x) { return x > 3; });
4607
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4608
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4609
- * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
4610
- */
4611
- observableProto.first = function (predicate, thisArg) {
4612
- return predicate ?
4613
- this.where(predicate, thisArg).first() :
4614
- firstOrDefaultAsync(this, false);
4615
- };
4777
+ /**
4778
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
4779
+ * @example
4780
+ * var res = res = source.first();
4781
+ * var res = res = source.first(function (x) { return x > 3; });
4782
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4783
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4784
+ * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
4785
+ */
4786
+ observableProto.first = function (predicate, thisArg) {
4787
+ return predicate ?
4788
+ this.where(predicate, thisArg).first() :
4789
+ firstOrDefaultAsync(this, false);
4790
+ };
4616
4791
 
4617
- /**
4618
- * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4619
- * @example
4620
- * var res = res = source.firstOrDefault();
4621
- * var res = res = source.firstOrDefault(function (x) { return x > 3; });
4622
- * var res = source.firstOrDefault(function (x) { return x > 3; }, 0);
4623
- * var res = source.firstOrDefault(null, 0);
4624
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4625
- * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4626
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4627
- * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4628
- */
4629
- observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
4630
- return predicate ?
4631
- this.where(predicate).firstOrDefault(null, defaultValue) :
4632
- firstOrDefaultAsync(this, true, defaultValue);
4633
- };
4792
+ /**
4793
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4794
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4795
+ * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4796
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4797
+ * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4798
+ */
4799
+ observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
4800
+ return predicate ?
4801
+ this.where(predicate).firstOrDefault(null, defaultValue) :
4802
+ firstOrDefaultAsync(this, true, defaultValue);
4803
+ };
4634
4804
 
4635
- function lastOrDefaultAsync(source, hasDefault, defaultValue) {
4636
- return new AnonymousObservable(function (observer) {
4637
- var value = defaultValue, seenValue = false;
4638
- return source.subscribe(function (x) {
4639
- value = x;
4640
- seenValue = true;
4641
- }, observer.onError.bind(observer), function () {
4642
- if (!seenValue && !hasDefault) {
4643
- observer.onError(new Error(sequenceContainsNoElements));
4644
- } else {
4645
- observer.onNext(value);
4646
- observer.onCompleted();
4647
- }
4648
- });
4649
- });
4650
- }
4805
+ function lastOrDefaultAsync(source, hasDefault, defaultValue) {
4806
+ return new AnonymousObservable(function (observer) {
4807
+ var value = defaultValue, seenValue = false;
4808
+ return source.subscribe(function (x) {
4809
+ value = x;
4810
+ seenValue = true;
4811
+ }, observer.onError.bind(observer), function () {
4812
+ if (!seenValue && !hasDefault) {
4813
+ observer.onError(new Error(sequenceContainsNoElements));
4814
+ } else {
4815
+ observer.onNext(value);
4816
+ observer.onCompleted();
4817
+ }
4818
+ });
4819
+ }, source);
4820
+ }
4651
4821
 
4652
- /**
4653
- * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
4654
- * @example
4655
- * var res = source.last();
4656
- * var res = source.last(function (x) { return x > 3; });
4657
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4658
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4659
- * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
4660
- */
4661
- observableProto.last = function (predicate, thisArg) {
4662
- return predicate ?
4663
- this.where(predicate, thisArg).last() :
4664
- lastOrDefaultAsync(this, false);
4665
- };
4822
+ /**
4823
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
4824
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4825
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4826
+ * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
4827
+ */
4828
+ observableProto.last = function (predicate, thisArg) {
4829
+ return predicate ?
4830
+ this.where(predicate, thisArg).last() :
4831
+ lastOrDefaultAsync(this, false);
4832
+ };
4666
4833
 
4667
- /**
4668
- * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4669
- * @example
4670
- * var res = source.lastOrDefault();
4671
- * var res = source.lastOrDefault(function (x) { return x > 3; });
4672
- * var res = source.lastOrDefault(function (x) { return x > 3; }, 0);
4673
- * var res = source.lastOrDefault(null, 0);
4674
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4675
- * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4676
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4677
- * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4678
- */
4679
- observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
4680
- return predicate ?
4681
- this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
4682
- lastOrDefaultAsync(this, true, defaultValue);
4683
- };
4834
+ /**
4835
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4836
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4837
+ * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4838
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4839
+ * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4840
+ */
4841
+ observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
4842
+ return predicate ?
4843
+ this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
4844
+ lastOrDefaultAsync(this, true, defaultValue);
4845
+ };
4684
4846
 
4685
- function findValue (source, predicate, thisArg, yieldIndex) {
4686
- return new AnonymousObservable(function (observer) {
4687
- var i = 0;
4688
- return source.subscribe(function (x) {
4689
- var shouldRun;
4690
- try {
4691
- shouldRun = predicate.call(thisArg, x, i, source);
4692
- } catch(e) {
4693
- observer.onError(e);
4694
- return;
4695
- }
4696
- if (shouldRun) {
4697
- observer.onNext(yieldIndex ? i : x);
4698
- observer.onCompleted();
4699
- } else {
4700
- i++;
4701
- }
4702
- }, observer.onError.bind(observer), function () {
4703
- observer.onNext(yieldIndex ? -1 : undefined);
4704
- observer.onCompleted();
4705
- });
4706
- });
4707
- }
4847
+ function findValue (source, predicate, thisArg, yieldIndex) {
4848
+ return new AnonymousObservable(function (observer) {
4849
+ var i = 0;
4850
+ return source.subscribe(function (x) {
4851
+ var shouldRun;
4852
+ try {
4853
+ shouldRun = predicate.call(thisArg, x, i, source);
4854
+ } catch (e) {
4855
+ observer.onError(e);
4856
+ return;
4857
+ }
4858
+ if (shouldRun) {
4859
+ observer.onNext(yieldIndex ? i : x);
4860
+ observer.onCompleted();
4861
+ } else {
4862
+ i++;
4863
+ }
4864
+ }, observer.onError.bind(observer), function () {
4865
+ observer.onNext(yieldIndex ? -1 : undefined);
4866
+ observer.onCompleted();
4867
+ });
4868
+ }, source);
4869
+ }
4708
4870
 
4709
- /**
4710
- * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
4711
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4712
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4713
- * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
4714
- */
4715
- observableProto.find = function (predicate, thisArg) {
4716
- return findValue(this, predicate, thisArg, false);
4717
- };
4871
+ /**
4872
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
4873
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4874
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4875
+ * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
4876
+ */
4877
+ observableProto.find = function (predicate, thisArg) {
4878
+ return findValue(this, predicate, thisArg, false);
4879
+ };
4880
+
4881
+ /**
4882
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns
4883
+ * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
4884
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4885
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4886
+ * @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
4887
+ */
4888
+ observableProto.findIndex = function (predicate, thisArg) {
4889
+ return findValue(this, predicate, thisArg, true);
4890
+ };
4891
+
4892
+
4893
+ /**
4894
+ * Converts the observable sequence to a Set if it exists.
4895
+ * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
4896
+ */
4897
+ observableProto.toSet = function () {
4898
+ if (typeof root.Set === 'undefined') { throw new TypeError(); }
4899
+ var source = this;
4900
+ return new AnonymousObservable(function (observer) {
4901
+ var s = new root.Set();
4902
+ return source.subscribe(
4903
+ s.add.bind(s),
4904
+ observer.onError.bind(observer),
4905
+ function () {
4906
+ observer.onNext(s);
4907
+ observer.onCompleted();
4908
+ });
4909
+ }, source);
4910
+ };
4718
4911
 
4719
- /**
4720
- * Searches for an element that matches the conditions defined by the specified predicate, and returns
4721
- * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
4722
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4723
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4724
- * @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
4725
- */
4726
- observableProto.findIndex = function (predicate, thisArg) {
4727
- return findValue(this, predicate, thisArg, true);
4728
- };
4729
4912
 
4730
- if (!!root.Set) {
4731
- /**
4732
- * Converts the observable sequence to a Set if it exists.
4733
- * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
4734
- */
4735
- observableProto.toSet = function () {
4736
- var source = this;
4737
- return new AnonymousObservable(function (observer) {
4738
- var s = new root.Set();
4739
- return source.subscribe(
4740
- s.add.bind(s),
4741
- observer.onError.bind(observer),
4742
- function () {
4743
- observer.onNext(s);
4744
- observer.onCompleted();
4745
- });
4746
- });
4747
- };
4748
- }
4913
+ /**
4914
+ * Converts the observable sequence to a Map if it exists.
4915
+ * @param {Function} keySelector A function which produces the key for the Map.
4916
+ * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
4917
+ * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
4918
+ */
4919
+ observableProto.toMap = function (keySelector, elementSelector) {
4920
+ if (typeof root.Map === 'undefined') { throw new TypeError(); }
4921
+ var source = this;
4922
+ return new AnonymousObservable(function (observer) {
4923
+ var m = new root.Map();
4924
+ return source.subscribe(
4925
+ function (x) {
4926
+ var key;
4927
+ try {
4928
+ key = keySelector(x);
4929
+ } catch (e) {
4930
+ observer.onError(e);
4931
+ return;
4932
+ }
4749
4933
 
4750
- if (!!root.Map) {
4751
- /**
4752
- * Converts the observable sequence to a Map if it exists.
4753
- * @param {Function} keySelector A function which produces the key for the Map.
4754
- * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
4755
- * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
4756
- */
4757
- observableProto.toMap = function (keySelector, elementSelector) {
4758
- var source = this;
4759
- return new AnonymousObservable(function (observer) {
4760
- var m = new root.Map();
4761
- return source.subscribe(
4762
- function (x) {
4763
- var key;
4934
+ var element = x;
4935
+ if (elementSelector) {
4764
4936
  try {
4765
- key = keySelector(x);
4937
+ element = elementSelector(x);
4766
4938
  } catch (e) {
4767
4939
  observer.onError(e);
4768
4940
  return;
4769
4941
  }
4942
+ }
4770
4943
 
4771
- var element = x;
4772
- if (elementSelector) {
4773
- try {
4774
- element = elementSelector(x);
4775
- } catch (e) {
4776
- observer.onError(e);
4777
- return;
4778
- }
4779
- }
4780
-
4781
- m.set(key, element);
4782
- },
4783
- observer.onError.bind(observer),
4784
- function () {
4785
- observer.onNext(m);
4786
- observer.onCompleted();
4787
- });
4788
- });
4789
- };
4790
- }
4944
+ m.set(key, element);
4945
+ },
4946
+ observer.onError.bind(observer),
4947
+ function () {
4948
+ observer.onNext(m);
4949
+ observer.onCompleted();
4950
+ });
4951
+ }, source);
4952
+ };
4791
4953
 
4792
4954
  var fnString = 'function',
4793
4955
  throwString = 'throw';
@@ -4832,7 +4994,7 @@
4832
4994
  return --pending || done(null, results);
4833
4995
  }
4834
4996
 
4835
- fn.call(ctx, function(err, res){
4997
+ fn.call(ctx, function(err, res) {
4836
4998
  if (finished) { return; }
4837
4999
 
4838
5000
  if (err) {
@@ -4867,7 +5029,7 @@
4867
5029
  }
4868
5030
 
4869
5031
  function promiseToThunk(promise) {
4870
- return function(fn){
5032
+ return function(fn) {
4871
5033
  promise.then(function(res) {
4872
5034
  fn(null, res);
4873
5035
  }, fn);
@@ -4923,7 +5085,9 @@
4923
5085
  var ret;
4924
5086
 
4925
5087
  // multiple args
4926
- if (arguments.length > 2) res = slice.call(arguments, 1);
5088
+ if (arguments.length > 2) {
5089
+ res = slice.call(arguments, 1);
5090
+ }
4927
5091
 
4928
5092
  if (err) {
4929
5093
  try {
@@ -4950,7 +5114,7 @@
4950
5114
  if (typeof ret.value === fnString) {
4951
5115
  var called = false;
4952
5116
  try {
4953
- ret.value.call(ctx, function(){
5117
+ ret.value.call(ctx, function() {
4954
5118
  if (called) {
4955
5119
  return;
4956
5120
  }
@@ -4983,13 +5147,13 @@
4983
5147
  * @returns {Function} A function, when executed will continue the state machine.
4984
5148
  */
4985
5149
  Rx.denodify = function (fn) {
4986
- return function (){
5150
+ return function () {
4987
5151
  var args = slice.call(arguments),
4988
5152
  results,
4989
5153
  called,
4990
5154
  callback;
4991
5155
 
4992
- args.push(function(){
5156
+ args.push(function() {
4993
5157
  results = arguments;
4994
5158
 
4995
5159
  if (callback && !called) {
@@ -5000,7 +5164,7 @@
5000
5164
 
5001
5165
  fn.apply(this, args);
5002
5166
 
5003
- return function (fn){
5167
+ return function (fn) {
5004
5168
  callback = fn;
5005
5169
 
5006
5170
  if (results && !called) {
@@ -5013,7 +5177,7 @@
5013
5177
 
5014
5178
  function error(err) {
5015
5179
  if (!err) { return; }
5016
- timeoutScheduler.schedule(function(){
5180
+ timeoutScheduler.schedule(function() {
5017
5181
  throw err;
5018
5182
  });
5019
5183
  }
@@ -5041,12 +5205,6 @@
5041
5205
 
5042
5206
  /**
5043
5207
  * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
5044
- *
5045
- * @example
5046
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
5047
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
5048
- * var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
5049
- *
5050
5208
  * @param {Function} function Function to convert to an asynchronous function.
5051
5209
  * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5052
5210
  * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
@@ -5086,12 +5244,12 @@
5086
5244
  var args = slice.call(arguments, 0);
5087
5245
 
5088
5246
  return new AnonymousObservable(function (observer) {
5089
- function handler(e) {
5090
- var results = e;
5247
+ function handler() {
5248
+ var results = arguments;
5091
5249
 
5092
5250
  if (selector) {
5093
5251
  try {
5094
- results = selector(arguments);
5252
+ results = selector(results);
5095
5253
  } catch (err) {
5096
5254
  observer.onError(err);
5097
5255
  return;
@@ -5372,17 +5530,22 @@
5372
5530
 
5373
5531
  function combineLatestSource(source, subject, resultSelector) {
5374
5532
  return new AnonymousObservable(function (observer) {
5375
- var n = 2,
5376
- hasValue = [false, false],
5533
+ var hasValue = [false, false],
5377
5534
  hasValueAll = false,
5378
5535
  isDone = false,
5379
- values = new Array(n);
5536
+ values = new Array(2),
5537
+ err;
5380
5538
 
5381
5539
  function next(x, i) {
5382
5540
  values[i] = x
5383
5541
  var res;
5384
5542
  hasValue[i] = true;
5385
5543
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
5544
+ if (err) {
5545
+ observer.onError(err);
5546
+ return;
5547
+ }
5548
+
5386
5549
  try {
5387
5550
  res = resultSelector.apply(null, values);
5388
5551
  } catch (ex) {
@@ -5390,7 +5553,8 @@
5390
5553
  return;
5391
5554
  }
5392
5555
  observer.onNext(res);
5393
- } else if (isDone) {
5556
+ }
5557
+ if (isDone && values[1]) {
5394
5558
  observer.onCompleted();
5395
5559
  }
5396
5560
  }
@@ -5400,23 +5564,33 @@
5400
5564
  function (x) {
5401
5565
  next(x, 0);
5402
5566
  },
5403
- observer.onError.bind(observer),
5567
+ function (e) {
5568
+ if (values[1]) {
5569
+ observer.onError(e);
5570
+ } else {
5571
+ err = e;
5572
+ }
5573
+ },
5404
5574
  function () {
5405
5575
  isDone = true;
5406
- observer.onCompleted();
5576
+ values[1] && observer.onCompleted();
5407
5577
  }),
5408
5578
  subject.subscribe(
5409
5579
  function (x) {
5410
5580
  next(x, 1);
5411
5581
  },
5412
- observer.onError.bind(observer))
5582
+ observer.onError.bind(observer),
5583
+ function () {
5584
+ isDone = true;
5585
+ next(true, 1);
5586
+ })
5413
5587
  );
5414
5588
  });
5415
5589
  }
5416
5590
 
5417
- var PausableBufferedObservable = (function (_super) {
5591
+ var PausableBufferedObservable = (function (__super__) {
5418
5592
 
5419
- inherits(PausableBufferedObservable, _super);
5593
+ inherits(PausableBufferedObservable, __super__);
5420
5594
 
5421
5595
  function subscribe(observer) {
5422
5596
  var q = [], previousShouldFire;
@@ -5476,7 +5650,7 @@
5476
5650
  this.pauser = this.controller;
5477
5651
  }
5478
5652
 
5479
- _super.call(this, subscribe);
5653
+ __super__.call(this, subscribe);
5480
5654
  }
5481
5655
 
5482
5656
  PausableBufferedObservable.prototype.pause = function () {
@@ -5690,7 +5864,7 @@
5690
5864
  new AnonymousObservable(function (observer) {
5691
5865
  var connectable = source.multicast(subjectOrSubjectSelector());
5692
5866
  return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
5693
- }) :
5867
+ }, source) :
5694
5868
  new ConnectableObservable(source, subjectOrSubjectSelector);
5695
5869
  };
5696
5870
 
@@ -5714,10 +5888,6 @@
5714
5888
  /**
5715
5889
  * Returns an observable sequence that shares a single subscription to the underlying sequence.
5716
5890
  * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5717
- *
5718
- * @example
5719
- * var res = source.share();
5720
- *
5721
5891
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5722
5892
  */
5723
5893
  observableProto.share = function () {
@@ -5764,10 +5934,6 @@
5764
5934
  /**
5765
5935
  * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
5766
5936
  * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5767
- *
5768
- * @example
5769
- * var res = source.shareValue(42);
5770
- *
5771
5937
  * @param {Mixed} initialValue Initial value received by observers upon subscription.
5772
5938
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5773
5939
  */
@@ -5954,21 +6120,17 @@
5954
6120
  this._trim(this.scheduler.now());
5955
6121
  this.observers.push(so);
5956
6122
 
5957
- var n = this.q.length;
5958
-
5959
6123
  for (var i = 0, len = this.q.length; i < len; i++) {
5960
6124
  so.onNext(this.q[i].value);
5961
6125
  }
5962
6126
 
5963
6127
  if (this.hasError) {
5964
- n++;
5965
6128
  so.onError(this.error);
5966
6129
  } else if (this.isStopped) {
5967
- n++;
5968
6130
  so.onCompleted();
5969
6131
  }
5970
6132
 
5971
- so.ensureActive(n);
6133
+ so.ensureActive();
5972
6134
  return subscription;
5973
6135
  }
5974
6136
 
@@ -6120,7 +6282,7 @@
6120
6282
  duplicatekey = "duplicate key";
6121
6283
 
6122
6284
  function isPrime(candidate) {
6123
- if (candidate & 1 === 0) { return candidate === 2; }
6285
+ if ((candidate & 1) === 0) { return candidate === 2; }
6124
6286
  var num1 = Math.sqrt(candidate),
6125
6287
  num2 = 3;
6126
6288
  while (num2 <= num1) {
@@ -6149,7 +6311,7 @@
6149
6311
  if (!str.length) { return hash; }
6150
6312
  for (var i = 0, len = str.length; i < len; i++) {
6151
6313
  var character = str.charCodeAt(i);
6152
- hash = ((hash<<5)-hash)+character;
6314
+ hash = ((hash << 5) - hash) + character;
6153
6315
  hash = hash & hash;
6154
6316
  }
6155
6317
  return hash;
@@ -6183,10 +6345,10 @@
6183
6345
  if (typeof valueOf === 'number') { return numberHashFn(valueOf); }
6184
6346
  if (typeof obj === 'string') { return stringHashFn(valueOf); }
6185
6347
  }
6186
- if (obj.getHashCode) { return obj.getHashCode(); }
6348
+ if (obj.hashCode) { return obj.hashCode(); }
6187
6349
 
6188
6350
  var id = 17 * uniqueIdCounter++;
6189
- obj.getHashCode = function () { return id; };
6351
+ obj.hashCode = function () { return id; };
6190
6352
  return id;
6191
6353
  };
6192
6354
  }());
@@ -6219,7 +6381,7 @@
6219
6381
  };
6220
6382
 
6221
6383
  dictionaryProto.add = function (key, value) {
6222
- return this._insert(key, value, true);
6384
+ this._insert(key, value, true);
6223
6385
  };
6224
6386
 
6225
6387
  dictionaryProto._insert = function (key, value, add) {
@@ -6447,7 +6609,7 @@
6447
6609
  var result;
6448
6610
  try {
6449
6611
  result = resultSelector(v, value);
6450
- } catch(exn) {
6612
+ } catch (exn) {
6451
6613
  observer.onError(exn);
6452
6614
  return;
6453
6615
  }
@@ -6462,7 +6624,7 @@
6462
6624
  })
6463
6625
  );
6464
6626
  return group;
6465
- });
6627
+ }, left);
6466
6628
  };
6467
6629
 
6468
6630
  /**
@@ -6574,7 +6736,7 @@
6574
6736
  );
6575
6737
 
6576
6738
  return r;
6577
- });
6739
+ }, left);
6578
6740
  };
6579
6741
 
6580
6742
  /**
@@ -6644,7 +6806,7 @@
6644
6806
  }));
6645
6807
 
6646
6808
  return r;
6647
- });
6809
+ }, source);
6648
6810
  }
6649
6811
 
6650
6812
  function observableWindowWithClosingSelector(windowClosingSelector) {
@@ -6664,7 +6826,7 @@
6664
6826
  win.onCompleted();
6665
6827
  observer.onCompleted();
6666
6828
  }));
6667
-
6829
+
6668
6830
  function createWindowClose () {
6669
6831
  var windowClose;
6670
6832
  try {
@@ -6691,7 +6853,7 @@
6691
6853
 
6692
6854
  createWindowClose();
6693
6855
  return r;
6694
- });
6856
+ }, source);
6695
6857
  }
6696
6858
 
6697
6859
  /**
@@ -6715,7 +6877,7 @@
6715
6877
  },
6716
6878
  observer.onError.bind(observer),
6717
6879
  observer.onCompleted.bind(observer));
6718
- });
6880
+ }, source);
6719
6881
  };
6720
6882
 
6721
6883
  /**
@@ -6749,16 +6911,16 @@
6749
6911
  });
6750
6912
  }
6751
6913
 
6752
- /**
6753
- * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
6754
- * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
6755
- *
6756
- * @param {Function} selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
6757
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
6758
- */
6759
- observableProto.letBind = observableProto['let'] = function (func) {
6760
- return func(this);
6761
- };
6914
+ /**
6915
+ * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
6916
+ * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
6917
+ *
6918
+ * @param {Function} selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
6919
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
6920
+ */
6921
+ observableProto.letBind = observableProto['let'] = function (func) {
6922
+ return func(this);
6923
+ };
6762
6924
 
6763
6925
  /**
6764
6926
  * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
@@ -6809,16 +6971,16 @@
6809
6971
  return enumerableWhile(condition, source).concat();
6810
6972
  };
6811
6973
 
6812
- /**
6813
- * Repeats source as long as condition holds emulating a do while loop.
6814
- *
6815
- * @param {Function} condition The condition which determines if the source will be repeated.
6816
- * @param {Observable} source The observable sequence that will be run if the condition function returns true.
6817
- * @returns {Observable} An observable sequence which is repeated as long as the condition holds.
6818
- */
6819
- observableProto.doWhile = function (condition) {
6820
- return observableConcat([this, observableWhileDo(condition, this)]);
6821
- };
6974
+ /**
6975
+ * Repeats source as long as condition holds emulating a do while loop.
6976
+ *
6977
+ * @param {Function} condition The condition which determines if the source will be repeated.
6978
+ * @param {Observable} source The observable sequence that will be run if the condition function returns true.
6979
+ * @returns {Observable} An observable sequence which is repeated as long as the condition holds.
6980
+ */
6981
+ observableProto.doWhile = function (condition) {
6982
+ return observableConcat([this, observableWhileDo(condition, this)]);
6983
+ };
6822
6984
 
6823
6985
  /**
6824
6986
  * Uses selector to determine which source in sources to use.
@@ -6869,8 +7031,8 @@
6869
7031
  var ensureActive = function () {
6870
7032
  var isOwner = false;
6871
7033
  if (q.length > 0) {
6872
- isOwner = !isAcquired;
6873
- isAcquired = true;
7034
+ isOwner = !isAcquired;
7035
+ isAcquired = true;
6874
7036
  }
6875
7037
  if (isOwner) {
6876
7038
  m.setDisposable(scheduler.scheduleRecursive(function (self) {
@@ -6910,7 +7072,7 @@
6910
7072
  activeCount++;
6911
7073
  ensureActive();
6912
7074
  return d;
6913
- });
7075
+ }, this);
6914
7076
  };
6915
7077
 
6916
7078
  /**
@@ -7051,7 +7213,7 @@
7051
7213
  );
7052
7214
 
7053
7215
  return new CompositeDisposable(leftSubscription, rightSubscription);
7054
- });
7216
+ }, first);
7055
7217
  };
7056
7218
 
7057
7219
  /**
@@ -7082,7 +7244,7 @@
7082
7244
  )
7083
7245
  .observeOn(scheduler)
7084
7246
  .map(selector);
7085
- });
7247
+ }, source);
7086
7248
  };
7087
7249
 
7088
7250
  var ChainObservable = (function (__super__) {
@@ -7091,7 +7253,7 @@
7091
7253
  var self = this, g = new CompositeDisposable();
7092
7254
  g.add(currentThreadScheduler.schedule(function () {
7093
7255
  observer.onNext(self.head);
7094
- g.add(self.tail.mergeObservable().subscribe(observer));
7256
+ g.add(self.tail.mergeAll().subscribe(observer));
7095
7257
  }));
7096
7258
 
7097
7259
  return g;
@@ -7527,7 +7689,7 @@
7527
7689
  }
7528
7690
  });
7529
7691
  return new CompositeDisposable(subscription, cancelable);
7530
- });
7692
+ }, source);
7531
7693
  }
7532
7694
 
7533
7695
  function observableDelayDate(source, dueTime, scheduler) {
@@ -7559,16 +7721,11 @@
7559
7721
 
7560
7722
  /**
7561
7723
  * Ignores values from an observable sequence which are followed by another value before dueTime.
7562
- *
7563
- * @example
7564
- * 1 - res = source.throttle(5000); // 5 seconds
7565
- * 2 - res = source.throttle(5000, scheduler);
7566
- *
7567
- * @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
7568
- * @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
7569
- * @returns {Observable} The throttled sequence.
7724
+ * @param {Number} dueTime Duration of the debounce period for each value (specified as an integer denoting milliseconds).
7725
+ * @param {Scheduler} [scheduler] Scheduler to run the debounce timers on. If not specified, the timeout scheduler is used.
7726
+ * @returns {Observable} The debounced sequence.
7570
7727
  */
7571
- observableProto.throttle = function (dueTime, scheduler) {
7728
+ observableProto.debounce = observableProto.throttleWithTimeout = function (dueTime, scheduler) {
7572
7729
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7573
7730
  var source = this;
7574
7731
  return new AnonymousObservable(function (observer) {
@@ -7600,7 +7757,15 @@
7600
7757
  id++;
7601
7758
  });
7602
7759
  return new CompositeDisposable(subscription, cancelable);
7603
- });
7760
+ }, this);
7761
+ };
7762
+
7763
+ /**
7764
+ * @deprecated use #debounce or #throttleWithTimeout instead.
7765
+ */
7766
+ observableProto.throttle = function(dueTime, scheduler) {
7767
+ deprecate('throttle', 'debounce or throttleWithTimeout');
7768
+ return this.debounce(dueTime, scheduler);
7604
7769
  };
7605
7770
 
7606
7771
  /**
@@ -7669,18 +7834,18 @@
7669
7834
  groupDisposable.add(source.subscribe(
7670
7835
  function (x) {
7671
7836
  for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
7672
- },
7837
+ },
7673
7838
  function (e) {
7674
7839
  for (var i = 0, len = q.length; i < len; i++) { q[i].onError(e); }
7675
7840
  observer.onError(e);
7676
- },
7841
+ },
7677
7842
  function () {
7678
7843
  for (var i = 0, len = q.length; i < len; i++) { q[i].onCompleted(); }
7679
7844
  observer.onCompleted();
7680
7845
  }
7681
7846
  ));
7682
7847
  return refCountDisposable;
7683
- });
7848
+ }, source);
7684
7849
  };
7685
7850
 
7686
7851
  /**
@@ -7714,7 +7879,7 @@
7714
7879
  createTimer(newId);
7715
7880
  }));
7716
7881
  }
7717
-
7882
+
7718
7883
  observer.onNext(addRef(s, refCountDisposable));
7719
7884
  createTimer(0);
7720
7885
 
@@ -7731,7 +7896,7 @@
7731
7896
  observer.onNext(addRef(s, refCountDisposable));
7732
7897
  }
7733
7898
  newWindow && createTimer(newId);
7734
- },
7899
+ },
7735
7900
  function (e) {
7736
7901
  s.onError(e);
7737
7902
  observer.onError(e);
@@ -7741,7 +7906,7 @@
7741
7906
  }
7742
7907
  ));
7743
7908
  return refCountDisposable;
7744
- });
7909
+ }, source);
7745
7910
  };
7746
7911
 
7747
7912
  /**
@@ -7819,7 +7984,6 @@
7819
7984
  };
7820
7985
 
7821
7986
  function sampleObservable(source, sampler) {
7822
-
7823
7987
  return new AnonymousObservable(function (observer) {
7824
7988
  var atEnd, value, hasValue;
7825
7989
 
@@ -7840,7 +8004,7 @@
7840
8004
  }),
7841
8005
  sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
7842
8006
  );
7843
- });
8007
+ }, source);
7844
8008
  }
7845
8009
 
7846
8010
  /**
@@ -7855,7 +8019,7 @@
7855
8019
  * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
7856
8020
  * @returns {Observable} Sampled observable sequence.
7857
8021
  */
7858
- observableProto.sample = function (intervalOrSampler, scheduler) {
8022
+ observableProto.sample = observableProto.throttleLatest = function (intervalOrSampler, scheduler) {
7859
8023
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7860
8024
  return typeof intervalOrSampler === 'number' ?
7861
8025
  sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
@@ -7916,7 +8080,7 @@
7916
8080
  }
7917
8081
  }));
7918
8082
  return new CompositeDisposable(subscription, timer);
7919
- });
8083
+ }, source);
7920
8084
  };
7921
8085
 
7922
8086
  /**
@@ -8042,68 +8206,64 @@
8042
8206
  return this.delayWithSelector(observableTimer(dueTime, isScheduler(scheduler) ? scheduler : timeoutScheduler), observableEmpty);
8043
8207
  };
8044
8208
 
8045
- /**
8046
- * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
8047
- *
8048
- * @example
8049
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only
8050
- * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector
8051
- *
8052
- * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source.
8053
- * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element.
8054
- * @returns {Observable} Time-shifted sequence.
8055
- */
8056
- observableProto.delayWithSelector = function (subscriptionDelay, delayDurationSelector) {
8057
- var source = this, subDelay, selector;
8058
- if (typeof subscriptionDelay === 'function') {
8059
- selector = subscriptionDelay;
8060
- } else {
8061
- subDelay = subscriptionDelay;
8062
- selector = delayDurationSelector;
8063
- }
8064
- return new AnonymousObservable(function (observer) {
8065
- var delays = new CompositeDisposable(), atEnd = false, done = function () {
8066
- if (atEnd && delays.length === 0) {
8067
- observer.onCompleted();
8068
- }
8069
- }, subscription = new SerialDisposable(), start = function () {
8070
- subscription.setDisposable(source.subscribe(function (x) {
8071
- var delay;
8072
- try {
8073
- delay = selector(x);
8074
- } catch (error) {
8075
- observer.onError(error);
8076
- return;
8077
- }
8078
- var d = new SingleAssignmentDisposable();
8079
- delays.add(d);
8080
- d.setDisposable(delay.subscribe(function () {
8081
- observer.onNext(x);
8082
- delays.remove(d);
8083
- done();
8084
- }, observer.onError.bind(observer), function () {
8085
- observer.onNext(x);
8086
- delays.remove(d);
8087
- done();
8088
- }));
8089
- }, observer.onError.bind(observer), function () {
8090
- atEnd = true;
8091
- subscription.dispose();
8092
- done();
8093
- }));
8094
- };
8209
+ /**
8210
+ * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
8211
+ *
8212
+ * @example
8213
+ * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only
8214
+ * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector
8215
+ *
8216
+ * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source.
8217
+ * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element.
8218
+ * @returns {Observable} Time-shifted sequence.
8219
+ */
8220
+ observableProto.delayWithSelector = function (subscriptionDelay, delayDurationSelector) {
8221
+ var source = this, subDelay, selector;
8222
+ if (typeof subscriptionDelay === 'function') {
8223
+ selector = subscriptionDelay;
8224
+ } else {
8225
+ subDelay = subscriptionDelay;
8226
+ selector = delayDurationSelector;
8227
+ }
8228
+ return new AnonymousObservable(function (observer) {
8229
+ var delays = new CompositeDisposable(), atEnd = false, done = function () {
8230
+ if (atEnd && delays.length === 0) { observer.onCompleted(); }
8231
+ }, subscription = new SerialDisposable(), start = function () {
8232
+ subscription.setDisposable(source.subscribe(function (x) {
8233
+ var delay;
8234
+ try {
8235
+ delay = selector(x);
8236
+ } catch (error) {
8237
+ observer.onError(error);
8238
+ return;
8239
+ }
8240
+ var d = new SingleAssignmentDisposable();
8241
+ delays.add(d);
8242
+ d.setDisposable(delay.subscribe(function () {
8243
+ observer.onNext(x);
8244
+ delays.remove(d);
8245
+ done();
8246
+ }, observer.onError.bind(observer), function () {
8247
+ observer.onNext(x);
8248
+ delays.remove(d);
8249
+ done();
8250
+ }));
8251
+ }, observer.onError.bind(observer), function () {
8252
+ atEnd = true;
8253
+ subscription.dispose();
8254
+ done();
8255
+ }));
8256
+ };
8095
8257
 
8096
- if (!subDelay) {
8097
- start();
8098
- } else {
8099
- subscription.setDisposable(subDelay.subscribe(function () {
8100
- start();
8101
- }, observer.onError.bind(observer), function () { start(); }));
8102
- }
8258
+ if (!subDelay) {
8259
+ start();
8260
+ } else {
8261
+ subscription.setDisposable(subDelay.subscribe(start, observer.onError.bind(observer), start));
8262
+ }
8103
8263
 
8104
- return new CompositeDisposable(subscription, delays);
8105
- });
8106
- };
8264
+ return new CompositeDisposable(subscription, delays);
8265
+ }, this);
8266
+ };
8107
8267
 
8108
8268
  /**
8109
8269
  * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
@@ -8171,26 +8331,22 @@
8171
8331
  observerWins() && observer.onCompleted();
8172
8332
  }));
8173
8333
  return new CompositeDisposable(subscription, timer);
8174
- });
8334
+ }, source);
8175
8335
  };
8176
8336
 
8177
8337
  /**
8178
- * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
8179
- *
8180
- * @example
8181
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
8182
- *
8183
- * @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
8184
- * @returns {Observable} The throttled sequence.
8338
+ * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
8339
+ * @param {Function} durationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
8340
+ * @returns {Observable} The debounced sequence.
8185
8341
  */
8186
- observableProto.throttleWithSelector = function (throttleDurationSelector) {
8342
+ observableProto.debounceWithSelector = function (durationSelector) {
8187
8343
  var source = this;
8188
8344
  return new AnonymousObservable(function (observer) {
8189
8345
  var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
8190
8346
  var subscription = source.subscribe(function (x) {
8191
8347
  var throttle;
8192
8348
  try {
8193
- throttle = throttleDurationSelector(x);
8349
+ throttle = durationSelector(x);
8194
8350
  } catch (e) {
8195
8351
  observer.onError(e);
8196
8352
  return;
@@ -8225,7 +8381,12 @@
8225
8381
  id++;
8226
8382
  });
8227
8383
  return new CompositeDisposable(subscription, cancelable);
8228
- });
8384
+ }, source);
8385
+ };
8386
+
8387
+ observableProto.throttleWithSelector = function () {
8388
+ deprecate('throttleWithSelector', 'debounceWithSelector');
8389
+ return this.debounceWithSelector.apply(this, arguments);
8229
8390
  };
8230
8391
 
8231
8392
  /**
@@ -8260,7 +8421,7 @@
8260
8421
  }
8261
8422
  observer.onCompleted();
8262
8423
  });
8263
- });
8424
+ }, source);
8264
8425
  };
8265
8426
 
8266
8427
  /**
@@ -8292,7 +8453,7 @@
8292
8453
  }
8293
8454
  observer.onCompleted();
8294
8455
  });
8295
- });
8456
+ }, source);
8296
8457
  };
8297
8458
 
8298
8459
  /**
@@ -8325,7 +8486,7 @@
8325
8486
  observer.onNext(res);
8326
8487
  observer.onCompleted();
8327
8488
  });
8328
- });
8489
+ }, source);
8329
8490
  };
8330
8491
 
8331
8492
  /**
@@ -8346,7 +8507,7 @@
8346
8507
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8347
8508
  return new AnonymousObservable(function (observer) {
8348
8509
  return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
8349
- });
8510
+ }, source);
8350
8511
  };
8351
8512
 
8352
8513
  /**
@@ -8373,7 +8534,7 @@
8373
8534
  return new CompositeDisposable(
8374
8535
  scheduler.scheduleWithRelative(duration, function () { open = true; }),
8375
8536
  source.subscribe(function (x) { open && observer.onNext(x); }, observer.onError.bind(observer), observer.onCompleted.bind(observer)));
8376
- });
8537
+ }, source);
8377
8538
  };
8378
8539
 
8379
8540
  /**
@@ -8401,7 +8562,7 @@
8401
8562
  function (x) { open && observer.onNext(x); },
8402
8563
  observer.onError.bind(observer),
8403
8564
  observer.onCompleted.bind(observer)));
8404
- });
8565
+ }, source);
8405
8566
  };
8406
8567
 
8407
8568
  /**
@@ -8419,11 +8580,38 @@
8419
8580
  return new CompositeDisposable(
8420
8581
  scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
8421
8582
  source.subscribe(observer));
8422
- });
8583
+ }, source);
8584
+ };
8585
+
8586
+ /**
8587
+ * Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
8588
+ * @param {Number} windowDuration time to wait before emitting another item after emitting the last item
8589
+ * @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.
8590
+ * @returns {Observable} An Observable that performs the throttle operation.
8591
+ */
8592
+ observableProto.throttleFirst = function (windowDuration, scheduler) {
8593
+ isScheduler(scheduler) || (scheduler = timeoutScheduler);
8594
+ var duration = +windowDuration || 0;
8595
+ if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
8596
+ var source = this;
8597
+ return new AnonymousObservable(function (observer) {
8598
+ var lastOnNext = 0;
8599
+ return source.subscribe(
8600
+ function (x) {
8601
+ var now = scheduler.now();
8602
+ if (lastOnNext === 0 || now - lastOnNext >= duration) {
8603
+ lastOnNext = now;
8604
+ observer.onNext(x);
8605
+ }
8606
+ },
8607
+ observer.onError.bind(observer),
8608
+ observer.onCompleted.bind(observer)
8609
+ );
8610
+ }, source);
8423
8611
  };
8424
8612
 
8425
8613
  /**
8426
- * Executes a transducer to transform the observable sequence
8614
+ * Executes a transducer to transform the observable sequence
8427
8615
  * @param {Transducer} transducer A transducer to execute
8428
8616
  * @returns {Observable} An Observable sequence containing the results from the transducer.
8429
8617
  */
@@ -8447,17 +8635,17 @@
8447
8635
  return new AnonymousObservable(function(observer) {
8448
8636
  var xform = transducer(transformForObserver(observer));
8449
8637
  return source.subscribe(
8450
- function(v) {
8638
+ function(v) {
8451
8639
  try {
8452
8640
  xform.step(observer, v);
8453
8641
  } catch (e) {
8454
8642
  observer.onError(e);
8455
8643
  }
8456
- },
8457
- observer.onError.bind(observer),
8644
+ },
8645
+ observer.onError.bind(observer),
8458
8646
  function() { xform.result(observer); }
8459
8647
  );
8460
- });
8648
+ }, source);
8461
8649
  };
8462
8650
 
8463
8651
  /*
@@ -8506,7 +8694,7 @@
8506
8694
  }));
8507
8695
 
8508
8696
  return g;
8509
- });
8697
+ }, this);
8510
8698
  };
8511
8699
 
8512
8700
  /*
@@ -8569,7 +8757,7 @@
8569
8757
  }
8570
8758
  }));
8571
8759
  return g;
8572
- });
8760
+ }, this);
8573
8761
  };
8574
8762
 
8575
8763
  /** Provides a set of extension methods for virtual time scheduling. */
@@ -8859,7 +9047,8 @@
8859
9047
  disposableEmpty;
8860
9048
  }
8861
9049
 
8862
- function AnonymousObservable(subscribe) {
9050
+ function AnonymousObservable(subscribe, parent) {
9051
+ this.source = parent;
8863
9052
  if (!(this instanceof AnonymousObservable)) {
8864
9053
  return new AnonymousObservable(subscribe);
8865
9054
  }
@@ -8892,66 +9081,59 @@
8892
9081
 
8893
9082
  }(Observable));
8894
9083
 
8895
- /** @private */
8896
- var AutoDetachObserver = (function (_super) {
8897
- inherits(AutoDetachObserver, _super);
9084
+ var AutoDetachObserver = (function (__super__) {
9085
+ inherits(AutoDetachObserver, __super__);
8898
9086
 
8899
- function AutoDetachObserver(observer) {
8900
- _super.call(this);
8901
- this.observer = observer;
8902
- this.m = new SingleAssignmentDisposable();
8903
- }
9087
+ function AutoDetachObserver(observer) {
9088
+ __super__.call(this);
9089
+ this.observer = observer;
9090
+ this.m = new SingleAssignmentDisposable();
9091
+ }
8904
9092
 
8905
- var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
9093
+ var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
8906
9094
 
8907
- AutoDetachObserverPrototype.next = function (value) {
8908
- var noError = false;
8909
- try {
8910
- this.observer.onNext(value);
8911
- noError = true;
8912
- } catch (e) {
8913
- throw e;
8914
- } finally {
8915
- if (!noError) {
8916
- this.dispose();
8917
- }
8918
- }
8919
- };
9095
+ AutoDetachObserverPrototype.next = function (value) {
9096
+ var noError = false;
9097
+ try {
9098
+ this.observer.onNext(value);
9099
+ noError = true;
9100
+ } catch (e) {
9101
+ throw e;
9102
+ } finally {
9103
+ !noError && this.dispose();
9104
+ }
9105
+ };
8920
9106
 
8921
- AutoDetachObserverPrototype.error = function (exn) {
8922
- try {
8923
- this.observer.onError(exn);
8924
- } catch (e) {
8925
- throw e;
8926
- } finally {
8927
- this.dispose();
8928
- }
8929
- };
9107
+ AutoDetachObserverPrototype.error = function (err) {
9108
+ try {
9109
+ this.observer.onError(err);
9110
+ } catch (e) {
9111
+ throw e;
9112
+ } finally {
9113
+ this.dispose();
9114
+ }
9115
+ };
8930
9116
 
8931
- AutoDetachObserverPrototype.completed = function () {
8932
- try {
8933
- this.observer.onCompleted();
8934
- } catch (e) {
8935
- throw e;
8936
- } finally {
8937
- this.dispose();
8938
- }
8939
- };
9117
+ AutoDetachObserverPrototype.completed = function () {
9118
+ try {
9119
+ this.observer.onCompleted();
9120
+ } catch (e) {
9121
+ throw e;
9122
+ } finally {
9123
+ this.dispose();
9124
+ }
9125
+ };
8940
9126
 
8941
- AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
8942
- AutoDetachObserverPrototype.getDisposable = function (value) { return this.m.getDisposable(); };
8943
- /* @private */
8944
- AutoDetachObserverPrototype.disposable = function (value) {
8945
- return arguments.length ? this.getDisposable() : setDisposable(value);
8946
- };
9127
+ AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
9128
+ AutoDetachObserverPrototype.getDisposable = function () { return this.m.getDisposable(); };
8947
9129
 
8948
- AutoDetachObserverPrototype.dispose = function () {
8949
- _super.prototype.dispose.call(this);
8950
- this.m.dispose();
8951
- };
9130
+ AutoDetachObserverPrototype.dispose = function () {
9131
+ __super__.prototype.dispose.call(this);
9132
+ this.m.dispose();
9133
+ };
8952
9134
 
8953
- return AutoDetachObserver;
8954
- }(AbstractObserver));
9135
+ return AutoDetachObserver;
9136
+ }(AbstractObserver));
8955
9137
 
8956
9138
  var GroupedObservable = (function (__super__) {
8957
9139
  inherits(GroupedObservable, __super__);
@@ -9247,4 +9429,7 @@
9247
9429
  root.Rx = Rx;
9248
9430
  }
9249
9431
 
9432
+ // All code before this point will be filtered from stack traces.
9433
+ var rEndingLine = captureLine();
9434
+
9250
9435
  }.call(this));