rxjs-rails 2.2.19 → 2.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,7 @@
37
37
  defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
38
38
  defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
39
39
  defaultError = Rx.helpers.defaultError = function (err) { throw err; },
40
- isPromise = Rx.helpers.isPromise = function (p) { return typeof p.then === 'function' && p.then !== Rx.Observable.prototype.then; },
40
+ isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function' && p.then !== Rx.Observable.prototype.then; },
41
41
  asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
42
42
  not = Rx.helpers.not = function (a) { return !a; };
43
43
 
@@ -1090,25 +1090,25 @@
1090
1090
  return SchedulePeriodicRecursive;
1091
1091
  }());
1092
1092
 
1093
- /**
1094
- * Gets a scheduler that schedules work immediately on the current thread.
1095
- */
1096
- var immediateScheduler = Scheduler.immediate = (function () {
1093
+ /**
1094
+ * Gets a scheduler that schedules work immediately on the current thread.
1095
+ */
1096
+ var immediateScheduler = Scheduler.immediate = (function () {
1097
1097
 
1098
- function scheduleNow(state, action) { return action(this, state); }
1098
+ function scheduleNow(state, action) { return action(this, state); }
1099
1099
 
1100
- function scheduleRelative(state, dueTime, action) {
1101
- var dt = normalizeTime(dt);
1102
- while (dt - this.now() > 0) { }
1103
- return action(this, state);
1104
- }
1100
+ function scheduleRelative(state, dueTime, action) {
1101
+ var dt = normalizeTime(dt);
1102
+ while (dt - this.now() > 0) { }
1103
+ return action(this, state);
1104
+ }
1105
1105
 
1106
- function scheduleAbsolute(state, dueTime, action) {
1107
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1108
- }
1106
+ function scheduleAbsolute(state, dueTime, action) {
1107
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1108
+ }
1109
1109
 
1110
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1111
- }());
1110
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1111
+ }());
1112
1112
 
1113
1113
  /**
1114
1114
  * Gets a scheduler that schedules work as soon as possible on the current thread.
@@ -1172,143 +1172,143 @@
1172
1172
  return currentScheduler;
1173
1173
  }());
1174
1174
 
1175
-
1176
- var scheduleMethod, clearMethod = noop;
1177
- (function () {
1178
-
1179
- var reNative = RegExp('^' +
1180
- String(toString)
1181
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1182
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1183
- );
1184
-
1185
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1186
- !reNative.test(setImmediate) && setImmediate,
1187
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1188
- !reNative.test(clearImmediate) && clearImmediate;
1189
-
1190
- function postMessageSupported () {
1191
- // Ensure not in a worker
1192
- if (!root.postMessage || root.importScripts) { return false; }
1193
- var isAsync = false,
1194
- oldHandler = root.onmessage;
1195
- // Test for async
1196
- root.onmessage = function () { isAsync = true; };
1197
- root.postMessage('','*');
1198
- root.onmessage = oldHandler;
1199
-
1200
- return isAsync;
1201
- }
1175
+
1176
+ var scheduleMethod, clearMethod = noop;
1177
+ (function () {
1202
1178
 
1203
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1204
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1205
- scheduleMethod = process.nextTick;
1206
- } else if (typeof setImmediate === 'function') {
1207
- scheduleMethod = setImmediate;
1208
- clearMethod = clearImmediate;
1209
- } else if (postMessageSupported()) {
1210
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1211
- tasks = {},
1212
- taskId = 0;
1213
-
1214
- function onGlobalPostMessage(event) {
1215
- // Only if we're a match to avoid any other global events
1216
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1217
- var handleId = event.data.substring(MSG_PREFIX.length),
1218
- action = tasks[handleId];
1219
- action();
1220
- delete tasks[handleId];
1221
- }
1222
- }
1179
+ var reNative = RegExp('^' +
1180
+ String(toString)
1181
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1182
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1183
+ );
1184
+
1185
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1186
+ !reNative.test(setImmediate) && setImmediate,
1187
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1188
+ !reNative.test(clearImmediate) && clearImmediate;
1189
+
1190
+ function postMessageSupported () {
1191
+ // Ensure not in a worker
1192
+ if (!root.postMessage || root.importScripts) { return false; }
1193
+ var isAsync = false,
1194
+ oldHandler = root.onmessage;
1195
+ // Test for async
1196
+ root.onmessage = function () { isAsync = true; };
1197
+ root.postMessage('','*');
1198
+ root.onmessage = oldHandler;
1199
+
1200
+ return isAsync;
1201
+ }
1223
1202
 
1224
- if (root.addEventListener) {
1225
- root.addEventListener('message', onGlobalPostMessage, false);
1226
- } else {
1227
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1203
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1204
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1205
+ scheduleMethod = process.nextTick;
1206
+ } else if (typeof setImmediate === 'function') {
1207
+ scheduleMethod = setImmediate;
1208
+ clearMethod = clearImmediate;
1209
+ } else if (postMessageSupported()) {
1210
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1211
+ tasks = {},
1212
+ taskId = 0;
1213
+
1214
+ function onGlobalPostMessage(event) {
1215
+ // Only if we're a match to avoid any other global events
1216
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1217
+ var handleId = event.data.substring(MSG_PREFIX.length),
1218
+ action = tasks[handleId];
1219
+ action();
1220
+ delete tasks[handleId];
1228
1221
  }
1222
+ }
1229
1223
 
1230
- scheduleMethod = function (action) {
1231
- var currentId = taskId++;
1232
- tasks[currentId] = action;
1233
- root.postMessage(MSG_PREFIX + currentId, '*');
1234
- };
1235
- } else if (!!root.MessageChannel) {
1236
- var channel = new root.MessageChannel(),
1237
- channelTasks = {},
1238
- channelTaskId = 0;
1239
-
1240
- channel.port1.onmessage = function (event) {
1241
- var id = event.data,
1242
- action = channelTasks[id];
1243
- action();
1244
- delete channelTasks[id];
1245
- };
1224
+ if (root.addEventListener) {
1225
+ root.addEventListener('message', onGlobalPostMessage, false);
1226
+ } else {
1227
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1228
+ }
1246
1229
 
1247
- scheduleMethod = function (action) {
1248
- var id = channelTaskId++;
1249
- channelTasks[id] = action;
1250
- channel.port2.postMessage(id);
1251
- };
1252
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1253
-
1254
- scheduleMethod = function (action) {
1255
- var scriptElement = root.document.createElement('script');
1256
- scriptElement.onreadystatechange = function () {
1257
- action();
1258
- scriptElement.onreadystatechange = null;
1259
- scriptElement.parentNode.removeChild(scriptElement);
1260
- scriptElement = null;
1261
- };
1262
- root.document.documentElement.appendChild(scriptElement);
1263
- };
1264
-
1265
- } else {
1266
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1267
- clearMethod = clearTimeout;
1268
- }
1269
- }());
1230
+ scheduleMethod = function (action) {
1231
+ var currentId = taskId++;
1232
+ tasks[currentId] = action;
1233
+ root.postMessage(MSG_PREFIX + currentId, '*');
1234
+ };
1235
+ } else if (!!root.MessageChannel) {
1236
+ var channel = new root.MessageChannel(),
1237
+ channelTasks = {},
1238
+ channelTaskId = 0;
1239
+
1240
+ channel.port1.onmessage = function (event) {
1241
+ var id = event.data,
1242
+ action = channelTasks[id];
1243
+ action();
1244
+ delete channelTasks[id];
1245
+ };
1246
+
1247
+ scheduleMethod = function (action) {
1248
+ var id = channelTaskId++;
1249
+ channelTasks[id] = action;
1250
+ channel.port2.postMessage(id);
1251
+ };
1252
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1253
+
1254
+ scheduleMethod = function (action) {
1255
+ var scriptElement = root.document.createElement('script');
1256
+ scriptElement.onreadystatechange = function () {
1257
+ action();
1258
+ scriptElement.onreadystatechange = null;
1259
+ scriptElement.parentNode.removeChild(scriptElement);
1260
+ scriptElement = null;
1261
+ };
1262
+ root.document.documentElement.appendChild(scriptElement);
1263
+ };
1270
1264
 
1271
- /**
1272
- * Gets a scheduler that schedules work via a timed callback based upon platform.
1273
- */
1274
- var timeoutScheduler = Scheduler.timeout = (function () {
1265
+ } else {
1266
+ scheduleMethod = function (action) { return setTimeout(action, 0); };
1267
+ clearMethod = clearTimeout;
1268
+ }
1269
+ }());
1275
1270
 
1276
- function scheduleNow(state, action) {
1277
- var scheduler = this,
1278
- disposable = new SingleAssignmentDisposable();
1279
- var id = scheduleMethod(function () {
1280
- if (!disposable.isDisposed) {
1281
- disposable.setDisposable(action(scheduler, state));
1282
- }
1283
- });
1284
- return new CompositeDisposable(disposable, disposableCreate(function () {
1285
- clearMethod(id);
1286
- }));
1287
- }
1271
+ /**
1272
+ * Gets a scheduler that schedules work via a timed callback based upon platform.
1273
+ */
1274
+ var timeoutScheduler = Scheduler.timeout = (function () {
1275
+
1276
+ function scheduleNow(state, action) {
1277
+ var scheduler = this,
1278
+ disposable = new SingleAssignmentDisposable();
1279
+ var id = scheduleMethod(function () {
1280
+ if (!disposable.isDisposed) {
1281
+ disposable.setDisposable(action(scheduler, state));
1282
+ }
1283
+ });
1284
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1285
+ clearMethod(id);
1286
+ }));
1287
+ }
1288
1288
 
1289
- function scheduleRelative(state, dueTime, action) {
1290
- var scheduler = this,
1291
- dt = Scheduler.normalize(dueTime);
1292
- if (dt === 0) {
1293
- return scheduler.scheduleWithState(state, action);
1294
- }
1295
- var disposable = new SingleAssignmentDisposable();
1296
- var id = setTimeout(function () {
1297
- if (!disposable.isDisposed) {
1298
- disposable.setDisposable(action(scheduler, state));
1299
- }
1300
- }, dt);
1301
- return new CompositeDisposable(disposable, disposableCreate(function () {
1302
- clearTimeout(id);
1303
- }));
1289
+ function scheduleRelative(state, dueTime, action) {
1290
+ var scheduler = this,
1291
+ dt = Scheduler.normalize(dueTime);
1292
+ if (dt === 0) {
1293
+ return scheduler.scheduleWithState(state, action);
1304
1294
  }
1295
+ var disposable = new SingleAssignmentDisposable();
1296
+ var id = setTimeout(function () {
1297
+ if (!disposable.isDisposed) {
1298
+ disposable.setDisposable(action(scheduler, state));
1299
+ }
1300
+ }, dt);
1301
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1302
+ clearTimeout(id);
1303
+ }));
1304
+ }
1305
1305
 
1306
- function scheduleAbsolute(state, dueTime, action) {
1307
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1308
- }
1306
+ function scheduleAbsolute(state, dueTime, action) {
1307
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1308
+ }
1309
1309
 
1310
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1311
- })();
1310
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1311
+ })();
1312
1312
 
1313
1313
  /** @private */
1314
1314
  var CatchScheduler = (function (_super) {
@@ -2207,28 +2207,26 @@
2207
2207
  return new AnonymousObservable(subscribe);
2208
2208
  };
2209
2209
 
2210
- /**
2211
- * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
2212
- *
2213
- * @example
2214
- * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
2215
- * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence.
2216
- * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
2217
- */
2218
- var observableDefer = Observable.defer = function (observableFactory) {
2219
- return new AnonymousObservable(function (observer) {
2220
- var result;
2221
- try {
2222
- result = observableFactory();
2223
- } catch (e) {
2224
- return observableThrow(e).subscribe(observer);
2225
- }
2226
-
2227
- // Check if promise
2228
- isPromise(result) && (result = observableFromPromise(result));
2229
- return result.subscribe(observer);
2230
- });
2231
- };
2210
+ /**
2211
+ * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
2212
+ *
2213
+ * @example
2214
+ * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
2215
+ * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence or Promise.
2216
+ * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
2217
+ */
2218
+ var observableDefer = Observable.defer = function (observableFactory) {
2219
+ return new AnonymousObservable(function (observer) {
2220
+ var result;
2221
+ try {
2222
+ result = observableFactory();
2223
+ } catch (e) {
2224
+ return observableThrow(e).subscribe(observer);
2225
+ }
2226
+ isPromise(result) && (result = observableFromPromise(result));
2227
+ return result.subscribe(observer);
2228
+ });
2229
+ };
2232
2230
 
2233
2231
  /**
2234
2232
  * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
@@ -2476,125 +2474,128 @@
2476
2474
  });
2477
2475
  };
2478
2476
 
2479
- /**
2480
- * Propagates the observable sequence that reacts first.
2481
- * @param {Observable} rightSource Second observable sequence.
2482
- * @returns {Observable} {Observable} An observable sequence that surfaces either of the given sequences, whichever reacted first.
2483
- */
2484
- observableProto.amb = function (rightSource) {
2485
- var leftSource = this;
2486
- return new AnonymousObservable(function (observer) {
2487
-
2488
- var choice,
2489
- leftChoice = 'L', rightChoice = 'R',
2490
- leftSubscription = new SingleAssignmentDisposable(),
2491
- rightSubscription = new SingleAssignmentDisposable();
2492
-
2493
- function choiceL() {
2494
- if (!choice) {
2495
- choice = leftChoice;
2496
- rightSubscription.dispose();
2497
- }
2498
- }
2477
+ /**
2478
+ * Propagates the observable sequence or Promise that reacts first.
2479
+ * @param {Observable} rightSource Second observable sequence or Promise.
2480
+ * @returns {Observable} {Observable} An observable sequence that surfaces either of the given sequences, whichever reacted first.
2481
+ */
2482
+ observableProto.amb = function (rightSource) {
2483
+ var leftSource = this;
2484
+ return new AnonymousObservable(function (observer) {
2485
+ var choice,
2486
+ leftChoice = 'L', rightChoice = 'R',
2487
+ leftSubscription = new SingleAssignmentDisposable(),
2488
+ rightSubscription = new SingleAssignmentDisposable();
2499
2489
 
2500
- function choiceR() {
2501
- if (!choice) {
2502
- choice = rightChoice;
2503
- leftSubscription.dispose();
2504
- }
2505
- }
2490
+ isPromise(rightSource) && (rightSource = observableFromPromise(rightSource));
2506
2491
 
2507
- leftSubscription.setDisposable(leftSource.subscribe(function (left) {
2508
- choiceL();
2509
- if (choice === leftChoice) {
2510
- observer.onNext(left);
2511
- }
2512
- }, function (err) {
2513
- choiceL();
2514
- if (choice === leftChoice) {
2515
- observer.onError(err);
2516
- }
2517
- }, function () {
2518
- choiceL();
2519
- if (choice === leftChoice) {
2520
- observer.onCompleted();
2521
- }
2522
- }));
2492
+ function choiceL() {
2493
+ if (!choice) {
2494
+ choice = leftChoice;
2495
+ rightSubscription.dispose();
2496
+ }
2497
+ }
2523
2498
 
2524
- rightSubscription.setDisposable(rightSource.subscribe(function (right) {
2525
- choiceR();
2526
- if (choice === rightChoice) {
2527
- observer.onNext(right);
2528
- }
2529
- }, function (err) {
2530
- choiceR();
2531
- if (choice === rightChoice) {
2532
- observer.onError(err);
2533
- }
2534
- }, function () {
2535
- choiceR();
2536
- if (choice === rightChoice) {
2537
- observer.onCompleted();
2538
- }
2539
- }));
2499
+ function choiceR() {
2500
+ if (!choice) {
2501
+ choice = rightChoice;
2502
+ leftSubscription.dispose();
2503
+ }
2504
+ }
2540
2505
 
2541
- return new CompositeDisposable(leftSubscription, rightSubscription);
2542
- });
2543
- };
2506
+ leftSubscription.setDisposable(leftSource.subscribe(function (left) {
2507
+ choiceL();
2508
+ if (choice === leftChoice) {
2509
+ observer.onNext(left);
2510
+ }
2511
+ }, function (err) {
2512
+ choiceL();
2513
+ if (choice === leftChoice) {
2514
+ observer.onError(err);
2515
+ }
2516
+ }, function () {
2517
+ choiceL();
2518
+ if (choice === leftChoice) {
2519
+ observer.onCompleted();
2520
+ }
2521
+ }));
2544
2522
 
2545
- /**
2546
- * Propagates the observable sequence that reacts first.
2547
- *
2548
- * @example
2549
- * var = Rx.Observable.amb(xs, ys, zs);
2550
- * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
2551
- */
2552
- Observable.amb = function () {
2553
- var acc = observableNever(),
2554
- items = argsOrArray(arguments, 0);
2555
- function func(previous, current) {
2556
- return previous.amb(current);
2523
+ rightSubscription.setDisposable(rightSource.subscribe(function (right) {
2524
+ choiceR();
2525
+ if (choice === rightChoice) {
2526
+ observer.onNext(right);
2527
+ }
2528
+ }, function (err) {
2529
+ choiceR();
2530
+ if (choice === rightChoice) {
2531
+ observer.onError(err);
2557
2532
  }
2558
- for (var i = 0, len = items.length; i < len; i++) {
2559
- acc = func(acc, items[i]);
2533
+ }, function () {
2534
+ choiceR();
2535
+ if (choice === rightChoice) {
2536
+ observer.onCompleted();
2560
2537
  }
2561
- return acc;
2562
- };
2538
+ }));
2563
2539
 
2564
- function observableCatchHandler(source, handler) {
2565
- return new AnonymousObservable(function (observer) {
2566
- var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2567
- subscription.setDisposable(d1);
2568
- d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2569
- var d, result;
2570
- try {
2571
- result = handler(exception);
2572
- } catch (ex) {
2573
- observer.onError(ex);
2574
- return;
2575
- }
2576
- d = new SingleAssignmentDisposable();
2577
- subscription.setDisposable(d);
2578
- d.setDisposable(result.subscribe(observer));
2579
- }, observer.onCompleted.bind(observer)));
2580
- return subscription;
2581
- });
2540
+ return new CompositeDisposable(leftSubscription, rightSubscription);
2541
+ });
2542
+ };
2543
+
2544
+ /**
2545
+ * Propagates the observable sequence or Promise that reacts first.
2546
+ *
2547
+ * @example
2548
+ * var = Rx.Observable.amb(xs, ys, zs);
2549
+ * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first.
2550
+ */
2551
+ Observable.amb = function () {
2552
+ var acc = observableNever(),
2553
+ items = argsOrArray(arguments, 0);
2554
+ function func(previous, current) {
2555
+ return previous.amb(current);
2582
2556
  }
2557
+ for (var i = 0, len = items.length; i < len; i++) {
2558
+ acc = func(acc, items[i]);
2559
+ }
2560
+ return acc;
2561
+ };
2583
2562
 
2584
- /**
2585
- * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2586
- * @example
2587
- * 1 - xs.catchException(ys)
2588
- * 2 - xs.catchException(function (ex) { return ys(ex); })
2589
- * @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.
2590
- * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2591
- */
2592
- observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2593
- if (typeof handlerOrSecond === 'function') {
2594
- return observableCatchHandler(this, handlerOrSecond);
2563
+ function observableCatchHandler(source, handler) {
2564
+ return new AnonymousObservable(function (observer) {
2565
+ var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2566
+ subscription.setDisposable(d1);
2567
+ d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2568
+ var d, result;
2569
+ try {
2570
+ result = handler(exception);
2571
+ } catch (ex) {
2572
+ observer.onError(ex);
2573
+ return;
2595
2574
  }
2596
- return observableCatch([this, handlerOrSecond]);
2597
- };
2575
+ isPromise(result) && (result = observableFromPromise(result));
2576
+
2577
+ d = new SingleAssignmentDisposable();
2578
+ subscription.setDisposable(d);
2579
+ d.setDisposable(result.subscribe(observer));
2580
+ }, observer.onCompleted.bind(observer)));
2581
+
2582
+ return subscription;
2583
+ });
2584
+ }
2585
+
2586
+ /**
2587
+ * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2588
+ * @example
2589
+ * 1 - xs.catchException(ys)
2590
+ * 2 - xs.catchException(function (ex) { return ys(ex); })
2591
+ * @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.
2592
+ * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2593
+ */
2594
+ observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2595
+ return typeof handlerOrSecond === 'function' ?
2596
+ observableCatchHandler(this, handlerOrSecond) :
2597
+ observableCatch([this, handlerOrSecond]);
2598
+ };
2598
2599
 
2599
2600
  /**
2600
2601
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
@@ -2609,87 +2610,89 @@
2609
2610
  return enumerableFor(items).catchException();
2610
2611
  };
2611
2612
 
2612
- /**
2613
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2614
- * This can be in the form of an argument list of observables or an array.
2615
- *
2616
- * @example
2617
- * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2618
- * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2619
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2620
- */
2621
- observableProto.combineLatest = function () {
2622
- var args = slice.call(arguments);
2623
- if (Array.isArray(args[0])) {
2624
- args[0].unshift(this);
2625
- } else {
2626
- args.unshift(this);
2627
- }
2628
- return combineLatest.apply(this, args);
2629
- };
2630
-
2631
- /**
2632
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2633
- *
2634
- * @example
2635
- * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2636
- * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2637
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2638
- */
2639
- var combineLatest = Observable.combineLatest = function () {
2640
- var args = slice.call(arguments), resultSelector = args.pop();
2641
-
2642
- if (Array.isArray(args[0])) {
2643
- args = args[0];
2644
- }
2613
+ /**
2614
+ * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences or Promises produces an element.
2615
+ * This can be in the form of an argument list of observables or an array.
2616
+ *
2617
+ * @example
2618
+ * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2619
+ * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2620
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2621
+ */
2622
+ observableProto.combineLatest = function () {
2623
+ var args = slice.call(arguments);
2624
+ if (Array.isArray(args[0])) {
2625
+ args[0].unshift(this);
2626
+ } else {
2627
+ args.unshift(this);
2628
+ }
2629
+ return combineLatest.apply(this, args);
2630
+ };
2645
2631
 
2646
- return new AnonymousObservable(function (observer) {
2647
- var falseFactory = function () { return false; },
2648
- n = args.length,
2649
- hasValue = arrayInitialize(n, falseFactory),
2650
- hasValueAll = false,
2651
- isDone = arrayInitialize(n, falseFactory),
2652
- values = new Array(n);
2632
+ /**
2633
+ * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences or Promises produces an element.
2634
+ *
2635
+ * @example
2636
+ * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2637
+ * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2638
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2639
+ */
2640
+ var combineLatest = Observable.combineLatest = function () {
2641
+ var args = slice.call(arguments), resultSelector = args.pop();
2642
+
2643
+ if (Array.isArray(args[0])) {
2644
+ args = args[0];
2645
+ }
2653
2646
 
2654
- function next(i) {
2655
- var res;
2656
- hasValue[i] = true;
2657
- if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2658
- try {
2659
- res = resultSelector.apply(null, values);
2660
- } catch (ex) {
2661
- observer.onError(ex);
2662
- return;
2663
- }
2664
- observer.onNext(res);
2665
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2666
- observer.onCompleted();
2667
- }
2668
- }
2647
+ return new AnonymousObservable(function (observer) {
2648
+ var falseFactory = function () { return false; },
2649
+ n = args.length,
2650
+ hasValue = arrayInitialize(n, falseFactory),
2651
+ hasValueAll = false,
2652
+ isDone = arrayInitialize(n, falseFactory),
2653
+ values = new Array(n);
2654
+
2655
+ function next(i) {
2656
+ var res;
2657
+ hasValue[i] = true;
2658
+ if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2659
+ try {
2660
+ res = resultSelector.apply(null, values);
2661
+ } catch (ex) {
2662
+ observer.onError(ex);
2663
+ return;
2664
+ }
2665
+ observer.onNext(res);
2666
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2667
+ observer.onCompleted();
2668
+ }
2669
+ }
2669
2670
 
2670
- function done (i) {
2671
- isDone[i] = true;
2672
- if (isDone.every(identity)) {
2673
- observer.onCompleted();
2674
- }
2675
- }
2671
+ function done (i) {
2672
+ isDone[i] = true;
2673
+ if (isDone.every(identity)) {
2674
+ observer.onCompleted();
2675
+ }
2676
+ }
2676
2677
 
2677
- var subscriptions = new Array(n);
2678
- for (var idx = 0; idx < n; idx++) {
2679
- (function (i) {
2680
- subscriptions[i] = new SingleAssignmentDisposable();
2681
- subscriptions[i].setDisposable(args[i].subscribe(function (x) {
2682
- values[i] = x;
2683
- next(i);
2684
- }, observer.onError.bind(observer), function () {
2685
- done(i);
2686
- }));
2687
- }(idx));
2688
- }
2678
+ var subscriptions = new Array(n);
2679
+ for (var idx = 0; idx < n; idx++) {
2680
+ (function (i) {
2681
+ var source = args[i], sad = new SingleAssignmentDisposable();
2682
+ isPromise(source) && (source = observableFromPromise(source));
2683
+ sad.setDisposable(source.subscribe(function (x) {
2684
+ values[i] = x;
2685
+ next(i);
2686
+ }, observer.onError.bind(observer), function () {
2687
+ done(i);
2688
+ }));
2689
+ subscriptions[i] = sad;
2690
+ }(idx));
2691
+ }
2689
2692
 
2690
- return new CompositeDisposable(subscriptions);
2691
- });
2692
- };
2693
+ return new CompositeDisposable(subscriptions);
2694
+ });
2695
+ };
2693
2696
 
2694
2697
  /**
2695
2698
  * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
@@ -2848,48 +2851,49 @@
2848
2851
  });
2849
2852
  };
2850
2853
 
2851
- /**
2852
- * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
2853
- * @param {Observable} second Second observable sequence used to produce results after the first sequence terminates.
2854
- * @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
2855
- */
2856
- observableProto.onErrorResumeNext = function (second) {
2857
- if (!second) {
2858
- throw new Error('Second observable is required');
2859
- }
2860
- return onErrorResumeNext([this, second]);
2861
- };
2854
+ /**
2855
+ * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
2856
+ * @param {Observable} second Second observable sequence used to produce results after the first sequence terminates.
2857
+ * @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
2858
+ */
2859
+ observableProto.onErrorResumeNext = function (second) {
2860
+ if (!second) {
2861
+ throw new Error('Second observable is required');
2862
+ }
2863
+ return onErrorResumeNext([this, second]);
2864
+ };
2862
2865
 
2863
- /**
2864
- * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
2865
- *
2866
- * @example
2867
- * 1 - res = Rx.Observable.onErrorResumeNext(xs, ys, zs);
2868
- * 1 - res = Rx.Observable.onErrorResumeNext([xs, ys, zs]);
2869
- * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
2870
- */
2871
- var onErrorResumeNext = Observable.onErrorResumeNext = function () {
2872
- var sources = argsOrArray(arguments, 0);
2873
- return new AnonymousObservable(function (observer) {
2874
- var pos = 0, subscription = new SerialDisposable(),
2875
- cancelable = immediateScheduler.scheduleRecursive(function (self) {
2876
- var current, d;
2877
- if (pos < sources.length) {
2878
- current = sources[pos++];
2879
- d = new SingleAssignmentDisposable();
2880
- subscription.setDisposable(d);
2881
- d.setDisposable(current.subscribe(observer.onNext.bind(observer), function () {
2882
- self();
2883
- }, function () {
2884
- self();
2885
- }));
2886
- } else {
2887
- observer.onCompleted();
2888
- }
2889
- });
2890
- return new CompositeDisposable(subscription, cancelable);
2891
- });
2892
- };
2866
+ /**
2867
+ * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
2868
+ *
2869
+ * @example
2870
+ * 1 - res = Rx.Observable.onErrorResumeNext(xs, ys, zs);
2871
+ * 1 - res = Rx.Observable.onErrorResumeNext([xs, ys, zs]);
2872
+ * @returns {Observable} An observable sequence that concatenates the source sequences, even if a sequence terminates exceptionally.
2873
+ */
2874
+ var onErrorResumeNext = Observable.onErrorResumeNext = function () {
2875
+ var sources = argsOrArray(arguments, 0);
2876
+ return new AnonymousObservable(function (observer) {
2877
+ var pos = 0, subscription = new SerialDisposable(),
2878
+ cancelable = immediateScheduler.scheduleRecursive(function (self) {
2879
+ var current, d;
2880
+ if (pos < sources.length) {
2881
+ current = sources[pos++];
2882
+ isPromise(current) && (current = observableFromPromise(current));
2883
+ d = new SingleAssignmentDisposable();
2884
+ subscription.setDisposable(d);
2885
+ d.setDisposable(current.subscribe(observer.onNext.bind(observer), function () {
2886
+ self();
2887
+ }, function () {
2888
+ self();
2889
+ }));
2890
+ } else {
2891
+ observer.onCompleted();
2892
+ }
2893
+ });
2894
+ return new CompositeDisposable(subscription, cancelable);
2895
+ });
2896
+ };
2893
2897
 
2894
2898
  /**
2895
2899
  * Returns the values from the source observable sequence only after the other observable sequence produces a value.
@@ -2985,86 +2989,88 @@
2985
2989
  });
2986
2990
  };
2987
2991
 
2988
- function zipArray(second, resultSelector) {
2989
- var first = this;
2990
- return new AnonymousObservable(function (observer) {
2991
- var index = 0, len = second.length;
2992
- return first.subscribe(function (left) {
2993
- if (index < len) {
2994
- var right = second[index++], result;
2995
- try {
2996
- result = resultSelector(left, right);
2997
- } catch (e) {
2998
- observer.onError(e);
2999
- return;
3000
- }
3001
- observer.onNext(result);
3002
- } else {
3003
- observer.onCompleted();
3004
- }
3005
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3006
- });
3007
- }
2992
+ function zipArray(second, resultSelector) {
2993
+ var first = this;
2994
+ return new AnonymousObservable(function (observer) {
2995
+ var index = 0, len = second.length;
2996
+ return first.subscribe(function (left) {
2997
+ if (index < len) {
2998
+ var right = second[index++], result;
2999
+ try {
3000
+ result = resultSelector(left, right);
3001
+ } catch (e) {
3002
+ observer.onError(e);
3003
+ return;
3004
+ }
3005
+ observer.onNext(result);
3006
+ } else {
3007
+ observer.onCompleted();
3008
+ }
3009
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3010
+ });
3011
+ }
3008
3012
 
3009
- /**
3010
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences or an array have produced an element at a corresponding index.
3011
- * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
3012
- *
3013
- * @example
3014
- * 1 - res = obs1.zip(obs2, fn);
3015
- * 1 - res = x1.zip([1,2,3], fn);
3016
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3017
- */
3018
- observableProto.zip = function () {
3019
- if (Array.isArray(arguments[0])) {
3020
- return zipArray.apply(this, arguments);
3013
+ /**
3014
+ * Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences or an array have produced an element at a corresponding index.
3015
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
3016
+ *
3017
+ * @example
3018
+ * 1 - res = obs1.zip(obs2, fn);
3019
+ * 1 - res = x1.zip([1,2,3], fn);
3020
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
3021
+ */
3022
+ observableProto.zip = function () {
3023
+ if (Array.isArray(arguments[0])) {
3024
+ return zipArray.apply(this, arguments);
3025
+ }
3026
+ var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
3027
+ sources.unshift(parent);
3028
+ return new AnonymousObservable(function (observer) {
3029
+ var n = sources.length,
3030
+ queues = arrayInitialize(n, function () { return []; }),
3031
+ isDone = arrayInitialize(n, function () { return false; });
3032
+
3033
+ function next(i) {
3034
+ var res, queuedValues;
3035
+ if (queues.every(function (x) { return x.length > 0; })) {
3036
+ try {
3037
+ queuedValues = queues.map(function (x) { return x.shift(); });
3038
+ res = resultSelector.apply(parent, queuedValues);
3039
+ } catch (ex) {
3040
+ observer.onError(ex);
3041
+ return;
3042
+ }
3043
+ observer.onNext(res);
3044
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
3045
+ observer.onCompleted();
3021
3046
  }
3022
- var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
3023
- sources.unshift(parent);
3024
- return new AnonymousObservable(function (observer) {
3025
- var n = sources.length,
3026
- queues = arrayInitialize(n, function () { return []; }),
3027
- isDone = arrayInitialize(n, function () { return false; });
3028
-
3029
- var next = function (i) {
3030
- var res, queuedValues;
3031
- if (queues.every(function (x) { return x.length > 0; })) {
3032
- try {
3033
- queuedValues = queues.map(function (x) { return x.shift(); });
3034
- res = resultSelector.apply(parent, queuedValues);
3035
- } catch (ex) {
3036
- observer.onError(ex);
3037
- return;
3038
- }
3039
- observer.onNext(res);
3040
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
3041
- observer.onCompleted();
3042
- }
3043
- };
3047
+ };
3044
3048
 
3045
- function done(i) {
3046
- isDone[i] = true;
3047
- if (isDone.every(function (x) { return x; })) {
3048
- observer.onCompleted();
3049
- }
3050
- }
3049
+ function done(i) {
3050
+ isDone[i] = true;
3051
+ if (isDone.every(function (x) { return x; })) {
3052
+ observer.onCompleted();
3053
+ }
3054
+ }
3051
3055
 
3052
- var subscriptions = new Array(n);
3053
- for (var idx = 0; idx < n; idx++) {
3054
- (function (i) {
3055
- subscriptions[i] = new SingleAssignmentDisposable();
3056
- subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
3057
- queues[i].push(x);
3058
- next(i);
3059
- }, observer.onError.bind(observer), function () {
3060
- done(i);
3061
- }));
3062
- })(idx);
3063
- }
3056
+ var subscriptions = new Array(n);
3057
+ for (var idx = 0; idx < n; idx++) {
3058
+ (function (i) {
3059
+ var source = sources[i], sad = new SingleAssignmentDisposable();
3060
+ isPromise(source) && (source = observableFromPromise(source));
3061
+ sad.setDisposable(source.subscribe(function (x) {
3062
+ queues[i].push(x);
3063
+ next(i);
3064
+ }, observer.onError.bind(observer), function () {
3065
+ done(i);
3066
+ }));
3067
+ subscriptions[i] = sad;
3068
+ })(idx);
3069
+ }
3064
3070
 
3065
- return new CompositeDisposable(subscriptions);
3066
- });
3067
- };
3071
+ return new CompositeDisposable(subscriptions);
3072
+ });
3073
+ };
3068
3074
  /**
3069
3075
  * Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences have produced an element at a corresponding index.
3070
3076
  * @param arguments Observable sources.