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;
@@ -2302,29 +2474,36 @@
2302
2474
  });
2303
2475
  };
2304
2476
 
2477
+ function observableOf (scheduler, array) {
2478
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2479
+ return new AnonymousObservable(function (observer) {
2480
+ var count = 0, len = array.length;
2481
+ return scheduler.scheduleRecursive(function (self) {
2482
+ if (count < len) {
2483
+ observer.onNext(array[count++]);
2484
+ self();
2485
+ } else {
2486
+ observer.onCompleted();
2487
+ }
2488
+ });
2489
+ });
2490
+ }
2491
+
2305
2492
  /**
2306
2493
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2307
- * @example
2308
- * var res = Rx.Observable.of(1,2,3);
2309
2494
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2310
2495
  */
2311
2496
  Observable.of = function () {
2312
- var len = arguments.length, args = new Array(len);
2313
- for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2314
- return observableFromArray(args);
2497
+ return observableOf(null, arguments);
2315
2498
  };
2316
2499
 
2317
2500
  /**
2318
2501
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2319
- * @example
2320
- * var res = Rx.Observable.of(1,2,3);
2321
2502
  * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2322
2503
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2323
2504
  */
2324
- var observableOf = Observable.ofWithScheduler = function (scheduler) {
2325
- var len = arguments.length - 1, args = new Array(len);
2326
- for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
2327
- return observableFromArray(args, scheduler);
2505
+ Observable.ofWithScheduler = function (scheduler) {
2506
+ return observableOf(scheduler, slice.call(arguments, 1));
2328
2507
  };
2329
2508
 
2330
2509
  /**
@@ -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,30 +3871,31 @@
3661
3871
  },
3662
3872
  observer.onError.bind(observer),
3663
3873
  observer.onCompleted.bind(observer));
3664
- });
3874
+ }, this);
3665
3875
  };
3666
3876
 
3667
3877
  /**
3668
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
3878
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
3669
3879
  * @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.
3670
3880
  * @param {Any} [thisArg] Object to use as this when executing callback.
3671
3881
  * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
3672
3882
  */
3673
3883
  observableProto.select = observableProto.map = function (selector, thisArg) {
3674
- var parent = this;
3884
+ var selectorFn = isFunction(selector) ? selector : function () { return selector; },
3885
+ source = this;
3675
3886
  return new AnonymousObservable(function (observer) {
3676
3887
  var count = 0;
3677
- return parent.subscribe(function (value) {
3888
+ return source.subscribe(function (value) {
3678
3889
  var result;
3679
3890
  try {
3680
- result = selector.call(thisArg, value, count++, parent);
3891
+ result = selectorFn.call(thisArg, value, count++, source);
3681
3892
  } catch (e) {
3682
3893
  observer.onError(e);
3683
3894
  return;
3684
3895
  }
3685
3896
  observer.onNext(result);
3686
3897
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3687
- });
3898
+ }, source);
3688
3899
  };
3689
3900
 
3690
3901
  /**
@@ -3745,16 +3956,16 @@
3745
3956
  observer.onNext(result);
3746
3957
  observer.onCompleted();
3747
3958
  });
3748
- }).mergeAll();
3959
+ }, source).mergeAll();
3749
3960
  };
3750
3961
 
3751
3962
  function flatMap(source, selector, thisArg) {
3752
3963
  return source.map(function (x, i) {
3753
3964
  var result = selector.call(thisArg, x, i, source);
3754
3965
  isPromise(result) && (result = observableFromPromise(result));
3755
- (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3966
+ (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3756
3967
  return result;
3757
- }).mergeObservable();
3968
+ }).mergeAll();
3758
3969
  }
3759
3970
 
3760
3971
  /**
@@ -3777,18 +3988,18 @@
3777
3988
  * @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.
3778
3989
  */
3779
3990
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3780
- if (typeof selector === 'function' && typeof resultSelector === 'function') {
3991
+ if (isFunction(selector) && isFunction(resultSelector)) {
3781
3992
  return this.flatMap(function (x, i) {
3782
3993
  var selectorResult = selector(x, i);
3783
3994
  isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3784
- (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3995
+ (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3785
3996
 
3786
3997
  return selectorResult.map(function (y, i2) {
3787
3998
  return resultSelector(x, y, i, i2);
3788
3999
  });
3789
4000
  }, thisArg);
3790
4001
  }
3791
- return typeof selector === 'function' ?
4002
+ return isFunction(selector) ?
3792
4003
  flatMap(this, selector, thisArg) :
3793
4004
  flatMap(this, function () { return selector; });
3794
4005
  };
@@ -3811,18 +4022,18 @@
3811
4022
  * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
3812
4023
  */
3813
4024
  observableProto.skip = function (count) {
3814
- if (count < 0) { throw new Error(argumentOutOfRange); }
3815
- var source = this;
3816
- return new AnonymousObservable(function (observer) {
3817
- var remaining = count;
3818
- return source.subscribe(function (x) {
3819
- if (remaining <= 0) {
3820
- observer.onNext(x);
3821
- } else {
3822
- remaining--;
3823
- }
3824
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3825
- });
4025
+ if (count < 0) { throw new Error(argumentOutOfRange); }
4026
+ var source = this;
4027
+ return new AnonymousObservable(function (observer) {
4028
+ var remaining = count;
4029
+ return source.subscribe(function (x) {
4030
+ if (remaining <= 0) {
4031
+ observer.onNext(x);
4032
+ } else {
4033
+ remaining--;
4034
+ }
4035
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4036
+ }, source);
3826
4037
  };
3827
4038
 
3828
4039
  /**
@@ -3850,7 +4061,7 @@
3850
4061
  }
3851
4062
  running && observer.onNext(x);
3852
4063
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3853
- });
4064
+ }, source);
3854
4065
  };
3855
4066
 
3856
4067
  /**
@@ -3863,18 +4074,18 @@
3863
4074
  * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
3864
4075
  */
3865
4076
  observableProto.take = function (count, scheduler) {
3866
- if (count < 0) { throw new RangeError(argumentOutOfRange); }
3867
- if (count === 0) { return observableEmpty(scheduler); }
3868
- var observable = this;
3869
- return new AnonymousObservable(function (observer) {
3870
- var remaining = count;
3871
- return observable.subscribe(function (x) {
3872
- if (remaining-- > 0) {
3873
- observer.onNext(x);
3874
- remaining === 0 && observer.onCompleted();
3875
- }
3876
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3877
- });
4077
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
4078
+ if (count === 0) { return observableEmpty(scheduler); }
4079
+ var source = this;
4080
+ return new AnonymousObservable(function (observer) {
4081
+ var remaining = count;
4082
+ return source.subscribe(function (x) {
4083
+ if (remaining-- > 0) {
4084
+ observer.onNext(x);
4085
+ remaining === 0 && observer.onCompleted();
4086
+ }
4087
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4088
+ }, source);
3878
4089
  };
3879
4090
 
3880
4091
  /**
@@ -3885,13 +4096,13 @@
3885
4096
  * @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.
3886
4097
  */
3887
4098
  observableProto.takeWhile = function (predicate, thisArg) {
3888
- var observable = this;
4099
+ var source = this;
3889
4100
  return new AnonymousObservable(function (observer) {
3890
4101
  var i = 0, running = true;
3891
- return observable.subscribe(function (x) {
4102
+ return source.subscribe(function (x) {
3892
4103
  if (running) {
3893
4104
  try {
3894
- running = predicate.call(thisArg, x, i++, observable);
4105
+ running = predicate.call(thisArg, x, i++, source);
3895
4106
  } catch (e) {
3896
4107
  observer.onError(e);
3897
4108
  return;
@@ -3903,7 +4114,7 @@
3903
4114
  }
3904
4115
  }
3905
4116
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3906
- });
4117
+ }, source);
3907
4118
  };
3908
4119
 
3909
4120
  /**
@@ -3917,24 +4128,24 @@
3917
4128
  * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
3918
4129
  */
3919
4130
  observableProto.where = observableProto.filter = function (predicate, thisArg) {
3920
- var parent = this;
3921
- return new AnonymousObservable(function (observer) {
3922
- var count = 0;
3923
- return parent.subscribe(function (value) {
3924
- var shouldRun;
3925
- try {
3926
- shouldRun = predicate.call(thisArg, value, count++, parent);
3927
- } catch (e) {
3928
- observer.onError(e);
3929
- return;
3930
- }
3931
- shouldRun && observer.onNext(value);
3932
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3933
- });
4131
+ var source = this;
4132
+ return new AnonymousObservable(function (observer) {
4133
+ var count = 0;
4134
+ return source.subscribe(function (value) {
4135
+ var shouldRun;
4136
+ try {
4137
+ shouldRun = predicate.call(thisArg, value, count++, parent);
4138
+ } catch (e) {
4139
+ observer.onError(e);
4140
+ return;
4141
+ }
4142
+ shouldRun && observer.onNext(value);
4143
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4144
+ }, source);
3934
4145
  };
3935
4146
 
3936
4147
  /**
3937
- * Executes a transducer to transform the observable sequence
4148
+ * Executes a transducer to transform the observable sequence
3938
4149
  * @param {Transducer} transducer A transducer to execute
3939
4150
  * @returns {Observable} An Observable sequence containing the results from the transducer.
3940
4151
  */
@@ -3958,17 +4169,17 @@
3958
4169
  return new AnonymousObservable(function(observer) {
3959
4170
  var xform = transducer(transformForObserver(observer));
3960
4171
  return source.subscribe(
3961
- function(v) {
4172
+ function(v) {
3962
4173
  try {
3963
4174
  xform.step(observer, v);
3964
4175
  } catch (e) {
3965
4176
  observer.onError(e);
3966
4177
  }
3967
- },
3968
- observer.onError.bind(observer),
4178
+ },
4179
+ observer.onError.bind(observer),
3969
4180
  function() { xform.result(observer); }
3970
4181
  );
3971
- });
4182
+ }, source);
3972
4183
  };
3973
4184
 
3974
4185
  var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
@@ -3983,7 +4194,8 @@
3983
4194
  disposableEmpty;
3984
4195
  }
3985
4196
 
3986
- function AnonymousObservable(subscribe) {
4197
+ function AnonymousObservable(subscribe, parent) {
4198
+ this.source = parent;
3987
4199
  if (!(this instanceof AnonymousObservable)) {
3988
4200
  return new AnonymousObservable(subscribe);
3989
4201
  }
@@ -4016,66 +4228,59 @@
4016
4228
 
4017
4229
  }(Observable));
4018
4230
 
4019
- /** @private */
4020
- var AutoDetachObserver = (function (_super) {
4021
- inherits(AutoDetachObserver, _super);
4231
+ var AutoDetachObserver = (function (__super__) {
4232
+ inherits(AutoDetachObserver, __super__);
4022
4233
 
4023
- function AutoDetachObserver(observer) {
4024
- _super.call(this);
4025
- this.observer = observer;
4026
- this.m = new SingleAssignmentDisposable();
4027
- }
4234
+ function AutoDetachObserver(observer) {
4235
+ __super__.call(this);
4236
+ this.observer = observer;
4237
+ this.m = new SingleAssignmentDisposable();
4238
+ }
4028
4239
 
4029
- var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
4240
+ var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
4030
4241
 
4031
- AutoDetachObserverPrototype.next = function (value) {
4032
- var noError = false;
4033
- try {
4034
- this.observer.onNext(value);
4035
- noError = true;
4036
- } catch (e) {
4037
- throw e;
4038
- } finally {
4039
- if (!noError) {
4040
- this.dispose();
4041
- }
4042
- }
4043
- };
4242
+ AutoDetachObserverPrototype.next = function (value) {
4243
+ var noError = false;
4244
+ try {
4245
+ this.observer.onNext(value);
4246
+ noError = true;
4247
+ } catch (e) {
4248
+ throw e;
4249
+ } finally {
4250
+ !noError && this.dispose();
4251
+ }
4252
+ };
4044
4253
 
4045
- AutoDetachObserverPrototype.error = function (exn) {
4046
- try {
4047
- this.observer.onError(exn);
4048
- } catch (e) {
4049
- throw e;
4050
- } finally {
4051
- this.dispose();
4052
- }
4053
- };
4254
+ AutoDetachObserverPrototype.error = function (err) {
4255
+ try {
4256
+ this.observer.onError(err);
4257
+ } catch (e) {
4258
+ throw e;
4259
+ } finally {
4260
+ this.dispose();
4261
+ }
4262
+ };
4054
4263
 
4055
- AutoDetachObserverPrototype.completed = function () {
4056
- try {
4057
- this.observer.onCompleted();
4058
- } catch (e) {
4059
- throw e;
4060
- } finally {
4061
- this.dispose();
4062
- }
4063
- };
4264
+ AutoDetachObserverPrototype.completed = function () {
4265
+ try {
4266
+ this.observer.onCompleted();
4267
+ } catch (e) {
4268
+ throw e;
4269
+ } finally {
4270
+ this.dispose();
4271
+ }
4272
+ };
4064
4273
 
4065
- AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
4066
- AutoDetachObserverPrototype.getDisposable = function (value) { return this.m.getDisposable(); };
4067
- /* @private */
4068
- AutoDetachObserverPrototype.disposable = function (value) {
4069
- return arguments.length ? this.getDisposable() : setDisposable(value);
4070
- };
4274
+ AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
4275
+ AutoDetachObserverPrototype.getDisposable = function () { return this.m.getDisposable(); };
4071
4276
 
4072
- AutoDetachObserverPrototype.dispose = function () {
4073
- _super.prototype.dispose.call(this);
4074
- this.m.dispose();
4075
- };
4277
+ AutoDetachObserverPrototype.dispose = function () {
4278
+ __super__.prototype.dispose.call(this);
4279
+ this.m.dispose();
4280
+ };
4076
4281
 
4077
- return AutoDetachObserver;
4078
- }(AbstractObserver));
4282
+ return AutoDetachObserver;
4283
+ }(AbstractObserver));
4079
4284
 
4080
4285
  /** @private */
4081
4286
  var InnerSubscription = function (subject, observer) {
@@ -4369,4 +4574,7 @@
4369
4574
  root.Rx = Rx;
4370
4575
  }
4371
4576
 
4577
+ // All code before this point will be filtered from stack traces.
4578
+ var rEndingLine = captureLine();
4579
+
4372
4580
  }.call(this));