rxjs-rails 2.2.19 → 2.2.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -1150,25 +1150,25 @@
1150
1150
 
1151
1151
  var normalizeTime = Scheduler.normalize;
1152
1152
 
1153
- /**
1154
- * Gets a scheduler that schedules work immediately on the current thread.
1155
- */
1156
- var immediateScheduler = Scheduler.immediate = (function () {
1153
+ /**
1154
+ * Gets a scheduler that schedules work immediately on the current thread.
1155
+ */
1156
+ var immediateScheduler = Scheduler.immediate = (function () {
1157
1157
 
1158
- function scheduleNow(state, action) { return action(this, state); }
1158
+ function scheduleNow(state, action) { return action(this, state); }
1159
1159
 
1160
- function scheduleRelative(state, dueTime, action) {
1161
- var dt = normalizeTime(dt);
1162
- while (dt - this.now() > 0) { }
1163
- return action(this, state);
1164
- }
1160
+ function scheduleRelative(state, dueTime, action) {
1161
+ var dt = normalizeTime(dt);
1162
+ while (dt - this.now() > 0) { }
1163
+ return action(this, state);
1164
+ }
1165
1165
 
1166
- function scheduleAbsolute(state, dueTime, action) {
1167
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1168
- }
1166
+ function scheduleAbsolute(state, dueTime, action) {
1167
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1168
+ }
1169
1169
 
1170
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1171
- }());
1170
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1171
+ }());
1172
1172
 
1173
1173
  /**
1174
1174
  * Gets a scheduler that schedules work as soon as possible on the current thread.
@@ -1261,143 +1261,143 @@
1261
1261
  return SchedulePeriodicRecursive;
1262
1262
  }());
1263
1263
 
1264
-
1265
- var scheduleMethod, clearMethod = noop;
1266
- (function () {
1267
-
1268
- var reNative = RegExp('^' +
1269
- String(toString)
1270
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1271
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1272
- );
1273
-
1274
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1275
- !reNative.test(setImmediate) && setImmediate,
1276
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1277
- !reNative.test(clearImmediate) && clearImmediate;
1278
-
1279
- function postMessageSupported () {
1280
- // Ensure not in a worker
1281
- if (!root.postMessage || root.importScripts) { return false; }
1282
- var isAsync = false,
1283
- oldHandler = root.onmessage;
1284
- // Test for async
1285
- root.onmessage = function () { isAsync = true; };
1286
- root.postMessage('','*');
1287
- root.onmessage = oldHandler;
1288
-
1289
- return isAsync;
1290
- }
1264
+
1265
+ var scheduleMethod, clearMethod = noop;
1266
+ (function () {
1291
1267
 
1292
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1293
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1294
- scheduleMethod = process.nextTick;
1295
- } else if (typeof setImmediate === 'function') {
1296
- scheduleMethod = setImmediate;
1297
- clearMethod = clearImmediate;
1298
- } else if (postMessageSupported()) {
1299
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1300
- tasks = {},
1301
- taskId = 0;
1302
-
1303
- function onGlobalPostMessage(event) {
1304
- // Only if we're a match to avoid any other global events
1305
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1306
- var handleId = event.data.substring(MSG_PREFIX.length),
1307
- action = tasks[handleId];
1308
- action();
1309
- delete tasks[handleId];
1310
- }
1311
- }
1268
+ var reNative = RegExp('^' +
1269
+ String(toString)
1270
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1271
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1272
+ );
1273
+
1274
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1275
+ !reNative.test(setImmediate) && setImmediate,
1276
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1277
+ !reNative.test(clearImmediate) && clearImmediate;
1278
+
1279
+ function postMessageSupported () {
1280
+ // Ensure not in a worker
1281
+ if (!root.postMessage || root.importScripts) { return false; }
1282
+ var isAsync = false,
1283
+ oldHandler = root.onmessage;
1284
+ // Test for async
1285
+ root.onmessage = function () { isAsync = true; };
1286
+ root.postMessage('','*');
1287
+ root.onmessage = oldHandler;
1288
+
1289
+ return isAsync;
1290
+ }
1312
1291
 
1313
- if (root.addEventListener) {
1314
- root.addEventListener('message', onGlobalPostMessage, false);
1315
- } else {
1316
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1292
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1293
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1294
+ scheduleMethod = process.nextTick;
1295
+ } else if (typeof setImmediate === 'function') {
1296
+ scheduleMethod = setImmediate;
1297
+ clearMethod = clearImmediate;
1298
+ } else if (postMessageSupported()) {
1299
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1300
+ tasks = {},
1301
+ taskId = 0;
1302
+
1303
+ function onGlobalPostMessage(event) {
1304
+ // Only if we're a match to avoid any other global events
1305
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1306
+ var handleId = event.data.substring(MSG_PREFIX.length),
1307
+ action = tasks[handleId];
1308
+ action();
1309
+ delete tasks[handleId];
1317
1310
  }
1311
+ }
1318
1312
 
1319
- scheduleMethod = function (action) {
1320
- var currentId = taskId++;
1321
- tasks[currentId] = action;
1322
- root.postMessage(MSG_PREFIX + currentId, '*');
1323
- };
1324
- } else if (!!root.MessageChannel) {
1325
- var channel = new root.MessageChannel(),
1326
- channelTasks = {},
1327
- channelTaskId = 0;
1328
-
1329
- channel.port1.onmessage = function (event) {
1330
- var id = event.data,
1331
- action = channelTasks[id];
1332
- action();
1333
- delete channelTasks[id];
1334
- };
1313
+ if (root.addEventListener) {
1314
+ root.addEventListener('message', onGlobalPostMessage, false);
1315
+ } else {
1316
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1317
+ }
1335
1318
 
1336
- scheduleMethod = function (action) {
1337
- var id = channelTaskId++;
1338
- channelTasks[id] = action;
1339
- channel.port2.postMessage(id);
1340
- };
1341
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1342
-
1343
- scheduleMethod = function (action) {
1344
- var scriptElement = root.document.createElement('script');
1345
- scriptElement.onreadystatechange = function () {
1346
- action();
1347
- scriptElement.onreadystatechange = null;
1348
- scriptElement.parentNode.removeChild(scriptElement);
1349
- scriptElement = null;
1350
- };
1351
- root.document.documentElement.appendChild(scriptElement);
1352
- };
1353
-
1354
- } else {
1355
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1356
- clearMethod = clearTimeout;
1357
- }
1358
- }());
1319
+ scheduleMethod = function (action) {
1320
+ var currentId = taskId++;
1321
+ tasks[currentId] = action;
1322
+ root.postMessage(MSG_PREFIX + currentId, '*');
1323
+ };
1324
+ } else if (!!root.MessageChannel) {
1325
+ var channel = new root.MessageChannel(),
1326
+ channelTasks = {},
1327
+ channelTaskId = 0;
1328
+
1329
+ channel.port1.onmessage = function (event) {
1330
+ var id = event.data,
1331
+ action = channelTasks[id];
1332
+ action();
1333
+ delete channelTasks[id];
1334
+ };
1335
+
1336
+ scheduleMethod = function (action) {
1337
+ var id = channelTaskId++;
1338
+ channelTasks[id] = action;
1339
+ channel.port2.postMessage(id);
1340
+ };
1341
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1342
+
1343
+ scheduleMethod = function (action) {
1344
+ var scriptElement = root.document.createElement('script');
1345
+ scriptElement.onreadystatechange = function () {
1346
+ action();
1347
+ scriptElement.onreadystatechange = null;
1348
+ scriptElement.parentNode.removeChild(scriptElement);
1349
+ scriptElement = null;
1350
+ };
1351
+ root.document.documentElement.appendChild(scriptElement);
1352
+ };
1359
1353
 
1360
- /**
1361
- * Gets a scheduler that schedules work via a timed callback based upon platform.
1362
- */
1363
- var timeoutScheduler = Scheduler.timeout = (function () {
1354
+ } else {
1355
+ scheduleMethod = function (action) { return setTimeout(action, 0); };
1356
+ clearMethod = clearTimeout;
1357
+ }
1358
+ }());
1364
1359
 
1365
- function scheduleNow(state, action) {
1366
- var scheduler = this,
1367
- disposable = new SingleAssignmentDisposable();
1368
- var id = scheduleMethod(function () {
1369
- if (!disposable.isDisposed) {
1370
- disposable.setDisposable(action(scheduler, state));
1371
- }
1372
- });
1373
- return new CompositeDisposable(disposable, disposableCreate(function () {
1374
- clearMethod(id);
1375
- }));
1376
- }
1360
+ /**
1361
+ * Gets a scheduler that schedules work via a timed callback based upon platform.
1362
+ */
1363
+ var timeoutScheduler = Scheduler.timeout = (function () {
1364
+
1365
+ function scheduleNow(state, action) {
1366
+ var scheduler = this,
1367
+ disposable = new SingleAssignmentDisposable();
1368
+ var id = scheduleMethod(function () {
1369
+ if (!disposable.isDisposed) {
1370
+ disposable.setDisposable(action(scheduler, state));
1371
+ }
1372
+ });
1373
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1374
+ clearMethod(id);
1375
+ }));
1376
+ }
1377
1377
 
1378
- function scheduleRelative(state, dueTime, action) {
1379
- var scheduler = this,
1380
- dt = Scheduler.normalize(dueTime);
1381
- if (dt === 0) {
1382
- return scheduler.scheduleWithState(state, action);
1383
- }
1384
- var disposable = new SingleAssignmentDisposable();
1385
- var id = setTimeout(function () {
1386
- if (!disposable.isDisposed) {
1387
- disposable.setDisposable(action(scheduler, state));
1388
- }
1389
- }, dt);
1390
- return new CompositeDisposable(disposable, disposableCreate(function () {
1391
- clearTimeout(id);
1392
- }));
1378
+ function scheduleRelative(state, dueTime, action) {
1379
+ var scheduler = this,
1380
+ dt = Scheduler.normalize(dueTime);
1381
+ if (dt === 0) {
1382
+ return scheduler.scheduleWithState(state, action);
1393
1383
  }
1384
+ var disposable = new SingleAssignmentDisposable();
1385
+ var id = setTimeout(function () {
1386
+ if (!disposable.isDisposed) {
1387
+ disposable.setDisposable(action(scheduler, state));
1388
+ }
1389
+ }, dt);
1390
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1391
+ clearTimeout(id);
1392
+ }));
1393
+ }
1394
1394
 
1395
- function scheduleAbsolute(state, dueTime, action) {
1396
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1397
- }
1395
+ function scheduleAbsolute(state, dueTime, action) {
1396
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1397
+ }
1398
1398
 
1399
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1400
- })();
1399
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1400
+ })();
1401
1401
 
1402
1402
  /**
1403
1403
  * Represents a notification to an observer.
@@ -2021,28 +2021,26 @@
2021
2021
  return new AnonymousObservable(subscribe);
2022
2022
  };
2023
2023
 
2024
- /**
2025
- * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
2026
- *
2027
- * @example
2028
- * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
2029
- * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence.
2030
- * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
2031
- */
2032
- var observableDefer = Observable.defer = function (observableFactory) {
2033
- return new AnonymousObservable(function (observer) {
2034
- var result;
2035
- try {
2036
- result = observableFactory();
2037
- } catch (e) {
2038
- return observableThrow(e).subscribe(observer);
2039
- }
2040
-
2041
- // Check if promise
2042
- isPromise(result) && (result = observableFromPromise(result));
2043
- return result.subscribe(observer);
2044
- });
2045
- };
2024
+ /**
2025
+ * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
2026
+ *
2027
+ * @example
2028
+ * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
2029
+ * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence or Promise.
2030
+ * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
2031
+ */
2032
+ var observableDefer = Observable.defer = function (observableFactory) {
2033
+ return new AnonymousObservable(function (observer) {
2034
+ var result;
2035
+ try {
2036
+ result = observableFactory();
2037
+ } catch (e) {
2038
+ return observableThrow(e).subscribe(observer);
2039
+ }
2040
+ isPromise(result) && (result = observableFromPromise(result));
2041
+ return result.subscribe(observer);
2042
+ });
2043
+ };
2046
2044
 
2047
2045
  /**
2048
2046
  * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
@@ -2265,40 +2263,42 @@
2265
2263
  });
2266
2264
  };
2267
2265
 
2268
- function observableCatchHandler(source, handler) {
2269
- return new AnonymousObservable(function (observer) {
2270
- var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2271
- subscription.setDisposable(d1);
2272
- d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2273
- var d, result;
2274
- try {
2275
- result = handler(exception);
2276
- } catch (ex) {
2277
- observer.onError(ex);
2278
- return;
2279
- }
2280
- d = new SingleAssignmentDisposable();
2281
- subscription.setDisposable(d);
2282
- d.setDisposable(result.subscribe(observer));
2283
- }, observer.onCompleted.bind(observer)));
2284
- return subscription;
2285
- });
2286
- }
2287
-
2288
- /**
2289
- * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2290
- * @example
2291
- * 1 - xs.catchException(ys)
2292
- * 2 - xs.catchException(function (ex) { return ys(ex); })
2293
- * @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.
2294
- * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2295
- */
2296
- observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2297
- if (typeof handlerOrSecond === 'function') {
2298
- return observableCatchHandler(this, handlerOrSecond);
2266
+ function observableCatchHandler(source, handler) {
2267
+ return new AnonymousObservable(function (observer) {
2268
+ var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2269
+ subscription.setDisposable(d1);
2270
+ d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2271
+ var d, result;
2272
+ try {
2273
+ result = handler(exception);
2274
+ } catch (ex) {
2275
+ observer.onError(ex);
2276
+ return;
2299
2277
  }
2300
- return observableCatch([this, handlerOrSecond]);
2301
- };
2278
+ isPromise(result) && (result = observableFromPromise(result));
2279
+
2280
+ d = new SingleAssignmentDisposable();
2281
+ subscription.setDisposable(d);
2282
+ d.setDisposable(result.subscribe(observer));
2283
+ }, observer.onCompleted.bind(observer)));
2284
+
2285
+ return subscription;
2286
+ });
2287
+ }
2288
+
2289
+ /**
2290
+ * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2291
+ * @example
2292
+ * 1 - xs.catchException(ys)
2293
+ * 2 - xs.catchException(function (ex) { return ys(ex); })
2294
+ * @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.
2295
+ * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2296
+ */
2297
+ observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2298
+ return typeof handlerOrSecond === 'function' ?
2299
+ observableCatchHandler(this, handlerOrSecond) :
2300
+ observableCatch([this, handlerOrSecond]);
2301
+ };
2302
2302
 
2303
2303
  /**
2304
2304
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
@@ -2313,87 +2313,89 @@
2313
2313
  return enumerableFor(items).catchException();
2314
2314
  };
2315
2315
 
2316
- /**
2317
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2318
- * This can be in the form of an argument list of observables or an array.
2319
- *
2320
- * @example
2321
- * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2322
- * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2323
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2324
- */
2325
- observableProto.combineLatest = function () {
2326
- var args = slice.call(arguments);
2327
- if (Array.isArray(args[0])) {
2328
- args[0].unshift(this);
2329
- } else {
2330
- args.unshift(this);
2331
- }
2332
- return combineLatest.apply(this, args);
2333
- };
2316
+ /**
2317
+ * 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.
2318
+ * This can be in the form of an argument list of observables or an array.
2319
+ *
2320
+ * @example
2321
+ * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2322
+ * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2323
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2324
+ */
2325
+ observableProto.combineLatest = function () {
2326
+ var args = slice.call(arguments);
2327
+ if (Array.isArray(args[0])) {
2328
+ args[0].unshift(this);
2329
+ } else {
2330
+ args.unshift(this);
2331
+ }
2332
+ return combineLatest.apply(this, args);
2333
+ };
2334
2334
 
2335
- /**
2336
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2337
- *
2338
- * @example
2339
- * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2340
- * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2341
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2342
- */
2343
- var combineLatest = Observable.combineLatest = function () {
2344
- var args = slice.call(arguments), resultSelector = args.pop();
2345
-
2346
- if (Array.isArray(args[0])) {
2347
- args = args[0];
2348
- }
2335
+ /**
2336
+ * 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.
2337
+ *
2338
+ * @example
2339
+ * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2340
+ * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2341
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2342
+ */
2343
+ var combineLatest = Observable.combineLatest = function () {
2344
+ var args = slice.call(arguments), resultSelector = args.pop();
2345
+
2346
+ if (Array.isArray(args[0])) {
2347
+ args = args[0];
2348
+ }
2349
2349
 
2350
- return new AnonymousObservable(function (observer) {
2351
- var falseFactory = function () { return false; },
2352
- n = args.length,
2353
- hasValue = arrayInitialize(n, falseFactory),
2354
- hasValueAll = false,
2355
- isDone = arrayInitialize(n, falseFactory),
2356
- values = new Array(n);
2350
+ return new AnonymousObservable(function (observer) {
2351
+ var falseFactory = function () { return false; },
2352
+ n = args.length,
2353
+ hasValue = arrayInitialize(n, falseFactory),
2354
+ hasValueAll = false,
2355
+ isDone = arrayInitialize(n, falseFactory),
2356
+ values = new Array(n);
2357
2357
 
2358
- function next(i) {
2359
- var res;
2360
- hasValue[i] = true;
2361
- if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2362
- try {
2363
- res = resultSelector.apply(null, values);
2364
- } catch (ex) {
2365
- observer.onError(ex);
2366
- return;
2367
- }
2368
- observer.onNext(res);
2369
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2370
- observer.onCompleted();
2371
- }
2372
- }
2358
+ function next(i) {
2359
+ var res;
2360
+ hasValue[i] = true;
2361
+ if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2362
+ try {
2363
+ res = resultSelector.apply(null, values);
2364
+ } catch (ex) {
2365
+ observer.onError(ex);
2366
+ return;
2367
+ }
2368
+ observer.onNext(res);
2369
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2370
+ observer.onCompleted();
2371
+ }
2372
+ }
2373
2373
 
2374
- function done (i) {
2375
- isDone[i] = true;
2376
- if (isDone.every(identity)) {
2377
- observer.onCompleted();
2378
- }
2379
- }
2374
+ function done (i) {
2375
+ isDone[i] = true;
2376
+ if (isDone.every(identity)) {
2377
+ observer.onCompleted();
2378
+ }
2379
+ }
2380
2380
 
2381
- var subscriptions = new Array(n);
2382
- for (var idx = 0; idx < n; idx++) {
2383
- (function (i) {
2384
- subscriptions[i] = new SingleAssignmentDisposable();
2385
- subscriptions[i].setDisposable(args[i].subscribe(function (x) {
2386
- values[i] = x;
2387
- next(i);
2388
- }, observer.onError.bind(observer), function () {
2389
- done(i);
2390
- }));
2391
- }(idx));
2392
- }
2381
+ var subscriptions = new Array(n);
2382
+ for (var idx = 0; idx < n; idx++) {
2383
+ (function (i) {
2384
+ var source = args[i], sad = new SingleAssignmentDisposable();
2385
+ isPromise(source) && (source = observableFromPromise(source));
2386
+ sad.setDisposable(source.subscribe(function (x) {
2387
+ values[i] = x;
2388
+ next(i);
2389
+ }, observer.onError.bind(observer), function () {
2390
+ done(i);
2391
+ }));
2392
+ subscriptions[i] = sad;
2393
+ }(idx));
2394
+ }
2393
2395
 
2394
- return new CompositeDisposable(subscriptions);
2395
- });
2396
- };
2396
+ return new CompositeDisposable(subscriptions);
2397
+ });
2398
+ };
2397
2399
 
2398
2400
  /**
2399
2401
  * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
@@ -2646,86 +2648,88 @@
2646
2648
  });
2647
2649
  };
2648
2650
 
2649
- function zipArray(second, resultSelector) {
2650
- var first = this;
2651
- return new AnonymousObservable(function (observer) {
2652
- var index = 0, len = second.length;
2653
- return first.subscribe(function (left) {
2654
- if (index < len) {
2655
- var right = second[index++], result;
2656
- try {
2657
- result = resultSelector(left, right);
2658
- } catch (e) {
2659
- observer.onError(e);
2660
- return;
2661
- }
2662
- observer.onNext(result);
2663
- } else {
2664
- observer.onCompleted();
2665
- }
2666
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2667
- });
2668
- }
2651
+ function zipArray(second, resultSelector) {
2652
+ var first = this;
2653
+ return new AnonymousObservable(function (observer) {
2654
+ var index = 0, len = second.length;
2655
+ return first.subscribe(function (left) {
2656
+ if (index < len) {
2657
+ var right = second[index++], result;
2658
+ try {
2659
+ result = resultSelector(left, right);
2660
+ } catch (e) {
2661
+ observer.onError(e);
2662
+ return;
2663
+ }
2664
+ observer.onNext(result);
2665
+ } else {
2666
+ observer.onCompleted();
2667
+ }
2668
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2669
+ });
2670
+ }
2669
2671
 
2670
- /**
2671
- * 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.
2672
- * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
2673
- *
2674
- * @example
2675
- * 1 - res = obs1.zip(obs2, fn);
2676
- * 1 - res = x1.zip([1,2,3], fn);
2677
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2678
- */
2679
- observableProto.zip = function () {
2680
- if (Array.isArray(arguments[0])) {
2681
- return zipArray.apply(this, arguments);
2672
+ /**
2673
+ * 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.
2674
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
2675
+ *
2676
+ * @example
2677
+ * 1 - res = obs1.zip(obs2, fn);
2678
+ * 1 - res = x1.zip([1,2,3], fn);
2679
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2680
+ */
2681
+ observableProto.zip = function () {
2682
+ if (Array.isArray(arguments[0])) {
2683
+ return zipArray.apply(this, arguments);
2684
+ }
2685
+ var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
2686
+ sources.unshift(parent);
2687
+ return new AnonymousObservable(function (observer) {
2688
+ var n = sources.length,
2689
+ queues = arrayInitialize(n, function () { return []; }),
2690
+ isDone = arrayInitialize(n, function () { return false; });
2691
+
2692
+ function next(i) {
2693
+ var res, queuedValues;
2694
+ if (queues.every(function (x) { return x.length > 0; })) {
2695
+ try {
2696
+ queuedValues = queues.map(function (x) { return x.shift(); });
2697
+ res = resultSelector.apply(parent, queuedValues);
2698
+ } catch (ex) {
2699
+ observer.onError(ex);
2700
+ return;
2701
+ }
2702
+ observer.onNext(res);
2703
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2704
+ observer.onCompleted();
2682
2705
  }
2683
- var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
2684
- sources.unshift(parent);
2685
- return new AnonymousObservable(function (observer) {
2686
- var n = sources.length,
2687
- queues = arrayInitialize(n, function () { return []; }),
2688
- isDone = arrayInitialize(n, function () { return false; });
2689
-
2690
- var next = function (i) {
2691
- var res, queuedValues;
2692
- if (queues.every(function (x) { return x.length > 0; })) {
2693
- try {
2694
- queuedValues = queues.map(function (x) { return x.shift(); });
2695
- res = resultSelector.apply(parent, queuedValues);
2696
- } catch (ex) {
2697
- observer.onError(ex);
2698
- return;
2699
- }
2700
- observer.onNext(res);
2701
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2702
- observer.onCompleted();
2703
- }
2704
- };
2706
+ };
2705
2707
 
2706
- function done(i) {
2707
- isDone[i] = true;
2708
- if (isDone.every(function (x) { return x; })) {
2709
- observer.onCompleted();
2710
- }
2711
- }
2708
+ function done(i) {
2709
+ isDone[i] = true;
2710
+ if (isDone.every(function (x) { return x; })) {
2711
+ observer.onCompleted();
2712
+ }
2713
+ }
2712
2714
 
2713
- var subscriptions = new Array(n);
2714
- for (var idx = 0; idx < n; idx++) {
2715
- (function (i) {
2716
- subscriptions[i] = new SingleAssignmentDisposable();
2717
- subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
2718
- queues[i].push(x);
2719
- next(i);
2720
- }, observer.onError.bind(observer), function () {
2721
- done(i);
2722
- }));
2723
- })(idx);
2724
- }
2715
+ var subscriptions = new Array(n);
2716
+ for (var idx = 0; idx < n; idx++) {
2717
+ (function (i) {
2718
+ var source = sources[i], sad = new SingleAssignmentDisposable();
2719
+ isPromise(source) && (source = observableFromPromise(source));
2720
+ sad.setDisposable(source.subscribe(function (x) {
2721
+ queues[i].push(x);
2722
+ next(i);
2723
+ }, observer.onError.bind(observer), function () {
2724
+ done(i);
2725
+ }));
2726
+ subscriptions[i] = sad;
2727
+ })(idx);
2728
+ }
2725
2729
 
2726
- return new CompositeDisposable(subscriptions);
2727
- });
2728
- };
2730
+ return new CompositeDisposable(subscriptions);
2731
+ });
2732
+ };
2729
2733
  /**
2730
2734
  * 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.
2731
2735
  * @param arguments Observable sources.
@@ -3575,7 +3579,7 @@
3575
3579
  selector);
3576
3580
  }
3577
3581
  if (jq) {
3578
- var $elem = jq(elem);
3582
+ var $elem = jq(element);
3579
3583
  return fromEventPattern(
3580
3584
  function (h) { $elem.on(eventName, h); },
3581
3585
  function (h) { $elem.off(eventName, h); },