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
 
@@ -1032,25 +1032,25 @@
1032
1032
 
1033
1033
  var normalizeTime = Scheduler.normalize;
1034
1034
 
1035
- /**
1036
- * Gets a scheduler that schedules work immediately on the current thread.
1037
- */
1038
- var immediateScheduler = Scheduler.immediate = (function () {
1035
+ /**
1036
+ * Gets a scheduler that schedules work immediately on the current thread.
1037
+ */
1038
+ var immediateScheduler = Scheduler.immediate = (function () {
1039
1039
 
1040
- function scheduleNow(state, action) { return action(this, state); }
1040
+ function scheduleNow(state, action) { return action(this, state); }
1041
1041
 
1042
- function scheduleRelative(state, dueTime, action) {
1043
- var dt = normalizeTime(dt);
1044
- while (dt - this.now() > 0) { }
1045
- return action(this, state);
1046
- }
1042
+ function scheduleRelative(state, dueTime, action) {
1043
+ var dt = normalizeTime(dt);
1044
+ while (dt - this.now() > 0) { }
1045
+ return action(this, state);
1046
+ }
1047
1047
 
1048
- function scheduleAbsolute(state, dueTime, action) {
1049
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1050
- }
1048
+ function scheduleAbsolute(state, dueTime, action) {
1049
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1050
+ }
1051
1051
 
1052
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1053
- }());
1052
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1053
+ }());
1054
1054
 
1055
1055
  /**
1056
1056
  * Gets a scheduler that schedules work as soon as possible on the current thread.
@@ -1143,143 +1143,143 @@
1143
1143
  return SchedulePeriodicRecursive;
1144
1144
  }());
1145
1145
 
1146
-
1147
- var scheduleMethod, clearMethod = noop;
1148
- (function () {
1149
-
1150
- var reNative = RegExp('^' +
1151
- String(toString)
1152
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1153
- .replace(/toString| for [^\]]+/g, '.*?') + '$'
1154
- );
1155
-
1156
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1157
- !reNative.test(setImmediate) && setImmediate,
1158
- clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1159
- !reNative.test(clearImmediate) && clearImmediate;
1160
-
1161
- function postMessageSupported () {
1162
- // Ensure not in a worker
1163
- if (!root.postMessage || root.importScripts) { return false; }
1164
- var isAsync = false,
1165
- oldHandler = root.onmessage;
1166
- // Test for async
1167
- root.onmessage = function () { isAsync = true; };
1168
- root.postMessage('','*');
1169
- root.onmessage = oldHandler;
1170
-
1171
- return isAsync;
1172
- }
1146
+
1147
+ var scheduleMethod, clearMethod = noop;
1148
+ (function () {
1173
1149
 
1174
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1175
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1176
- scheduleMethod = process.nextTick;
1177
- } else if (typeof setImmediate === 'function') {
1178
- scheduleMethod = setImmediate;
1179
- clearMethod = clearImmediate;
1180
- } else if (postMessageSupported()) {
1181
- var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1182
- tasks = {},
1183
- taskId = 0;
1184
-
1185
- function onGlobalPostMessage(event) {
1186
- // Only if we're a match to avoid any other global events
1187
- if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1188
- var handleId = event.data.substring(MSG_PREFIX.length),
1189
- action = tasks[handleId];
1190
- action();
1191
- delete tasks[handleId];
1192
- }
1193
- }
1150
+ var reNative = RegExp('^' +
1151
+ String(toString)
1152
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1153
+ .replace(/toString| for [^\]]+/g, '.*?') + '$'
1154
+ );
1155
+
1156
+ var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
1157
+ !reNative.test(setImmediate) && setImmediate,
1158
+ clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1159
+ !reNative.test(clearImmediate) && clearImmediate;
1160
+
1161
+ function postMessageSupported () {
1162
+ // Ensure not in a worker
1163
+ if (!root.postMessage || root.importScripts) { return false; }
1164
+ var isAsync = false,
1165
+ oldHandler = root.onmessage;
1166
+ // Test for async
1167
+ root.onmessage = function () { isAsync = true; };
1168
+ root.postMessage('','*');
1169
+ root.onmessage = oldHandler;
1170
+
1171
+ return isAsync;
1172
+ }
1194
1173
 
1195
- if (root.addEventListener) {
1196
- root.addEventListener('message', onGlobalPostMessage, false);
1197
- } else {
1198
- root.attachEvent('onmessage', onGlobalPostMessage, false);
1174
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1175
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1176
+ scheduleMethod = process.nextTick;
1177
+ } else if (typeof setImmediate === 'function') {
1178
+ scheduleMethod = setImmediate;
1179
+ clearMethod = clearImmediate;
1180
+ } else if (postMessageSupported()) {
1181
+ var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1182
+ tasks = {},
1183
+ taskId = 0;
1184
+
1185
+ function onGlobalPostMessage(event) {
1186
+ // Only if we're a match to avoid any other global events
1187
+ if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1188
+ var handleId = event.data.substring(MSG_PREFIX.length),
1189
+ action = tasks[handleId];
1190
+ action();
1191
+ delete tasks[handleId];
1199
1192
  }
1193
+ }
1200
1194
 
1201
- scheduleMethod = function (action) {
1202
- var currentId = taskId++;
1203
- tasks[currentId] = action;
1204
- root.postMessage(MSG_PREFIX + currentId, '*');
1205
- };
1206
- } else if (!!root.MessageChannel) {
1207
- var channel = new root.MessageChannel(),
1208
- channelTasks = {},
1209
- channelTaskId = 0;
1210
-
1211
- channel.port1.onmessage = function (event) {
1212
- var id = event.data,
1213
- action = channelTasks[id];
1214
- action();
1215
- delete channelTasks[id];
1216
- };
1195
+ if (root.addEventListener) {
1196
+ root.addEventListener('message', onGlobalPostMessage, false);
1197
+ } else {
1198
+ root.attachEvent('onmessage', onGlobalPostMessage, false);
1199
+ }
1217
1200
 
1218
- scheduleMethod = function (action) {
1219
- var id = channelTaskId++;
1220
- channelTasks[id] = action;
1221
- channel.port2.postMessage(id);
1222
- };
1223
- } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1224
-
1225
- scheduleMethod = function (action) {
1226
- var scriptElement = root.document.createElement('script');
1227
- scriptElement.onreadystatechange = function () {
1228
- action();
1229
- scriptElement.onreadystatechange = null;
1230
- scriptElement.parentNode.removeChild(scriptElement);
1231
- scriptElement = null;
1232
- };
1233
- root.document.documentElement.appendChild(scriptElement);
1234
- };
1235
-
1236
- } else {
1237
- scheduleMethod = function (action) { return setTimeout(action, 0); };
1238
- clearMethod = clearTimeout;
1239
- }
1240
- }());
1201
+ scheduleMethod = function (action) {
1202
+ var currentId = taskId++;
1203
+ tasks[currentId] = action;
1204
+ root.postMessage(MSG_PREFIX + currentId, '*');
1205
+ };
1206
+ } else if (!!root.MessageChannel) {
1207
+ var channel = new root.MessageChannel(),
1208
+ channelTasks = {},
1209
+ channelTaskId = 0;
1210
+
1211
+ channel.port1.onmessage = function (event) {
1212
+ var id = event.data,
1213
+ action = channelTasks[id];
1214
+ action();
1215
+ delete channelTasks[id];
1216
+ };
1217
+
1218
+ scheduleMethod = function (action) {
1219
+ var id = channelTaskId++;
1220
+ channelTasks[id] = action;
1221
+ channel.port2.postMessage(id);
1222
+ };
1223
+ } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
1224
+
1225
+ scheduleMethod = function (action) {
1226
+ var scriptElement = root.document.createElement('script');
1227
+ scriptElement.onreadystatechange = function () {
1228
+ action();
1229
+ scriptElement.onreadystatechange = null;
1230
+ scriptElement.parentNode.removeChild(scriptElement);
1231
+ scriptElement = null;
1232
+ };
1233
+ root.document.documentElement.appendChild(scriptElement);
1234
+ };
1241
1235
 
1242
- /**
1243
- * Gets a scheduler that schedules work via a timed callback based upon platform.
1244
- */
1245
- var timeoutScheduler = Scheduler.timeout = (function () {
1236
+ } else {
1237
+ scheduleMethod = function (action) { return setTimeout(action, 0); };
1238
+ clearMethod = clearTimeout;
1239
+ }
1240
+ }());
1246
1241
 
1247
- function scheduleNow(state, action) {
1248
- var scheduler = this,
1249
- disposable = new SingleAssignmentDisposable();
1250
- var id = scheduleMethod(function () {
1251
- if (!disposable.isDisposed) {
1252
- disposable.setDisposable(action(scheduler, state));
1253
- }
1254
- });
1255
- return new CompositeDisposable(disposable, disposableCreate(function () {
1256
- clearMethod(id);
1257
- }));
1258
- }
1242
+ /**
1243
+ * Gets a scheduler that schedules work via a timed callback based upon platform.
1244
+ */
1245
+ var timeoutScheduler = Scheduler.timeout = (function () {
1246
+
1247
+ function scheduleNow(state, action) {
1248
+ var scheduler = this,
1249
+ disposable = new SingleAssignmentDisposable();
1250
+ var id = scheduleMethod(function () {
1251
+ if (!disposable.isDisposed) {
1252
+ disposable.setDisposable(action(scheduler, state));
1253
+ }
1254
+ });
1255
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1256
+ clearMethod(id);
1257
+ }));
1258
+ }
1259
1259
 
1260
- function scheduleRelative(state, dueTime, action) {
1261
- var scheduler = this,
1262
- dt = Scheduler.normalize(dueTime);
1263
- if (dt === 0) {
1264
- return scheduler.scheduleWithState(state, action);
1265
- }
1266
- var disposable = new SingleAssignmentDisposable();
1267
- var id = setTimeout(function () {
1268
- if (!disposable.isDisposed) {
1269
- disposable.setDisposable(action(scheduler, state));
1270
- }
1271
- }, dt);
1272
- return new CompositeDisposable(disposable, disposableCreate(function () {
1273
- clearTimeout(id);
1274
- }));
1260
+ function scheduleRelative(state, dueTime, action) {
1261
+ var scheduler = this,
1262
+ dt = Scheduler.normalize(dueTime);
1263
+ if (dt === 0) {
1264
+ return scheduler.scheduleWithState(state, action);
1275
1265
  }
1266
+ var disposable = new SingleAssignmentDisposable();
1267
+ var id = setTimeout(function () {
1268
+ if (!disposable.isDisposed) {
1269
+ disposable.setDisposable(action(scheduler, state));
1270
+ }
1271
+ }, dt);
1272
+ return new CompositeDisposable(disposable, disposableCreate(function () {
1273
+ clearTimeout(id);
1274
+ }));
1275
+ }
1276
1276
 
1277
- function scheduleAbsolute(state, dueTime, action) {
1278
- return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1279
- }
1277
+ function scheduleAbsolute(state, dueTime, action) {
1278
+ return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
1279
+ }
1280
1280
 
1281
- return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1282
- })();
1281
+ return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1282
+ })();
1283
1283
 
1284
1284
  /**
1285
1285
  * Represents a notification to an observer.
@@ -1903,28 +1903,26 @@
1903
1903
  return new AnonymousObservable(subscribe);
1904
1904
  };
1905
1905
 
1906
- /**
1907
- * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
1908
- *
1909
- * @example
1910
- * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
1911
- * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence.
1912
- * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
1913
- */
1914
- var observableDefer = Observable.defer = function (observableFactory) {
1915
- return new AnonymousObservable(function (observer) {
1916
- var result;
1917
- try {
1918
- result = observableFactory();
1919
- } catch (e) {
1920
- return observableThrow(e).subscribe(observer);
1921
- }
1922
-
1923
- // Check if promise
1924
- isPromise(result) && (result = observableFromPromise(result));
1925
- return result.subscribe(observer);
1926
- });
1927
- };
1906
+ /**
1907
+ * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
1908
+ *
1909
+ * @example
1910
+ * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); });
1911
+ * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence or Promise.
1912
+ * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function.
1913
+ */
1914
+ var observableDefer = Observable.defer = function (observableFactory) {
1915
+ return new AnonymousObservable(function (observer) {
1916
+ var result;
1917
+ try {
1918
+ result = observableFactory();
1919
+ } catch (e) {
1920
+ return observableThrow(e).subscribe(observer);
1921
+ }
1922
+ isPromise(result) && (result = observableFromPromise(result));
1923
+ return result.subscribe(observer);
1924
+ });
1925
+ };
1928
1926
 
1929
1927
  /**
1930
1928
  * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
@@ -2147,40 +2145,42 @@
2147
2145
  });
2148
2146
  };
2149
2147
 
2150
- function observableCatchHandler(source, handler) {
2151
- return new AnonymousObservable(function (observer) {
2152
- var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2153
- subscription.setDisposable(d1);
2154
- d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2155
- var d, result;
2156
- try {
2157
- result = handler(exception);
2158
- } catch (ex) {
2159
- observer.onError(ex);
2160
- return;
2161
- }
2162
- d = new SingleAssignmentDisposable();
2163
- subscription.setDisposable(d);
2164
- d.setDisposable(result.subscribe(observer));
2165
- }, observer.onCompleted.bind(observer)));
2166
- return subscription;
2167
- });
2168
- }
2169
-
2170
- /**
2171
- * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2172
- * @example
2173
- * 1 - xs.catchException(ys)
2174
- * 2 - xs.catchException(function (ex) { return ys(ex); })
2175
- * @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.
2176
- * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2177
- */
2178
- observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2179
- if (typeof handlerOrSecond === 'function') {
2180
- return observableCatchHandler(this, handlerOrSecond);
2148
+ function observableCatchHandler(source, handler) {
2149
+ return new AnonymousObservable(function (observer) {
2150
+ var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
2151
+ subscription.setDisposable(d1);
2152
+ d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
2153
+ var d, result;
2154
+ try {
2155
+ result = handler(exception);
2156
+ } catch (ex) {
2157
+ observer.onError(ex);
2158
+ return;
2181
2159
  }
2182
- return observableCatch([this, handlerOrSecond]);
2183
- };
2160
+ isPromise(result) && (result = observableFromPromise(result));
2161
+
2162
+ d = new SingleAssignmentDisposable();
2163
+ subscription.setDisposable(d);
2164
+ d.setDisposable(result.subscribe(observer));
2165
+ }, observer.onCompleted.bind(observer)));
2166
+
2167
+ return subscription;
2168
+ });
2169
+ }
2170
+
2171
+ /**
2172
+ * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2173
+ * @example
2174
+ * 1 - xs.catchException(ys)
2175
+ * 2 - xs.catchException(function (ex) { return ys(ex); })
2176
+ * @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.
2177
+ * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2178
+ */
2179
+ observableProto['catch'] = observableProto.catchException = function (handlerOrSecond) {
2180
+ return typeof handlerOrSecond === 'function' ?
2181
+ observableCatchHandler(this, handlerOrSecond) :
2182
+ observableCatch([this, handlerOrSecond]);
2183
+ };
2184
2184
 
2185
2185
  /**
2186
2186
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
@@ -2195,87 +2195,89 @@
2195
2195
  return enumerableFor(items).catchException();
2196
2196
  };
2197
2197
 
2198
- /**
2199
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2200
- * This can be in the form of an argument list of observables or an array.
2201
- *
2202
- * @example
2203
- * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2204
- * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2205
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2206
- */
2207
- observableProto.combineLatest = function () {
2208
- var args = slice.call(arguments);
2209
- if (Array.isArray(args[0])) {
2210
- args[0].unshift(this);
2211
- } else {
2212
- args.unshift(this);
2213
- }
2214
- return combineLatest.apply(this, args);
2215
- };
2198
+ /**
2199
+ * 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.
2200
+ * This can be in the form of an argument list of observables or an array.
2201
+ *
2202
+ * @example
2203
+ * 1 - obs = observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2204
+ * 2 - obs = observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2205
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2206
+ */
2207
+ observableProto.combineLatest = function () {
2208
+ var args = slice.call(arguments);
2209
+ if (Array.isArray(args[0])) {
2210
+ args[0].unshift(this);
2211
+ } else {
2212
+ args.unshift(this);
2213
+ }
2214
+ return combineLatest.apply(this, args);
2215
+ };
2216
2216
 
2217
- /**
2218
- * Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
2219
- *
2220
- * @example
2221
- * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2222
- * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2223
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2224
- */
2225
- var combineLatest = Observable.combineLatest = function () {
2226
- var args = slice.call(arguments), resultSelector = args.pop();
2227
-
2228
- if (Array.isArray(args[0])) {
2229
- args = args[0];
2230
- }
2217
+ /**
2218
+ * 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.
2219
+ *
2220
+ * @example
2221
+ * 1 - obs = Rx.Observable.combineLatest(obs1, obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
2222
+ * 2 - obs = Rx.Observable.combineLatest([obs1, obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
2223
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2224
+ */
2225
+ var combineLatest = Observable.combineLatest = function () {
2226
+ var args = slice.call(arguments), resultSelector = args.pop();
2227
+
2228
+ if (Array.isArray(args[0])) {
2229
+ args = args[0];
2230
+ }
2231
2231
 
2232
- return new AnonymousObservable(function (observer) {
2233
- var falseFactory = function () { return false; },
2234
- n = args.length,
2235
- hasValue = arrayInitialize(n, falseFactory),
2236
- hasValueAll = false,
2237
- isDone = arrayInitialize(n, falseFactory),
2238
- values = new Array(n);
2232
+ return new AnonymousObservable(function (observer) {
2233
+ var falseFactory = function () { return false; },
2234
+ n = args.length,
2235
+ hasValue = arrayInitialize(n, falseFactory),
2236
+ hasValueAll = false,
2237
+ isDone = arrayInitialize(n, falseFactory),
2238
+ values = new Array(n);
2239
2239
 
2240
- function next(i) {
2241
- var res;
2242
- hasValue[i] = true;
2243
- if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2244
- try {
2245
- res = resultSelector.apply(null, values);
2246
- } catch (ex) {
2247
- observer.onError(ex);
2248
- return;
2249
- }
2250
- observer.onNext(res);
2251
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2252
- observer.onCompleted();
2253
- }
2254
- }
2240
+ function next(i) {
2241
+ var res;
2242
+ hasValue[i] = true;
2243
+ if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
2244
+ try {
2245
+ res = resultSelector.apply(null, values);
2246
+ } catch (ex) {
2247
+ observer.onError(ex);
2248
+ return;
2249
+ }
2250
+ observer.onNext(res);
2251
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2252
+ observer.onCompleted();
2253
+ }
2254
+ }
2255
2255
 
2256
- function done (i) {
2257
- isDone[i] = true;
2258
- if (isDone.every(identity)) {
2259
- observer.onCompleted();
2260
- }
2261
- }
2256
+ function done (i) {
2257
+ isDone[i] = true;
2258
+ if (isDone.every(identity)) {
2259
+ observer.onCompleted();
2260
+ }
2261
+ }
2262
2262
 
2263
- var subscriptions = new Array(n);
2264
- for (var idx = 0; idx < n; idx++) {
2265
- (function (i) {
2266
- subscriptions[i] = new SingleAssignmentDisposable();
2267
- subscriptions[i].setDisposable(args[i].subscribe(function (x) {
2268
- values[i] = x;
2269
- next(i);
2270
- }, observer.onError.bind(observer), function () {
2271
- done(i);
2272
- }));
2273
- }(idx));
2274
- }
2263
+ var subscriptions = new Array(n);
2264
+ for (var idx = 0; idx < n; idx++) {
2265
+ (function (i) {
2266
+ var source = args[i], sad = new SingleAssignmentDisposable();
2267
+ isPromise(source) && (source = observableFromPromise(source));
2268
+ sad.setDisposable(source.subscribe(function (x) {
2269
+ values[i] = x;
2270
+ next(i);
2271
+ }, observer.onError.bind(observer), function () {
2272
+ done(i);
2273
+ }));
2274
+ subscriptions[i] = sad;
2275
+ }(idx));
2276
+ }
2275
2277
 
2276
- return new CompositeDisposable(subscriptions);
2277
- });
2278
- };
2278
+ return new CompositeDisposable(subscriptions);
2279
+ });
2280
+ };
2279
2281
 
2280
2282
  /**
2281
2283
  * Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate.
@@ -2528,86 +2530,88 @@
2528
2530
  });
2529
2531
  };
2530
2532
 
2531
- function zipArray(second, resultSelector) {
2532
- var first = this;
2533
- return new AnonymousObservable(function (observer) {
2534
- var index = 0, len = second.length;
2535
- return first.subscribe(function (left) {
2536
- if (index < len) {
2537
- var right = second[index++], result;
2538
- try {
2539
- result = resultSelector(left, right);
2540
- } catch (e) {
2541
- observer.onError(e);
2542
- return;
2543
- }
2544
- observer.onNext(result);
2545
- } else {
2546
- observer.onCompleted();
2547
- }
2548
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2549
- });
2550
- }
2533
+ function zipArray(second, resultSelector) {
2534
+ var first = this;
2535
+ return new AnonymousObservable(function (observer) {
2536
+ var index = 0, len = second.length;
2537
+ return first.subscribe(function (left) {
2538
+ if (index < len) {
2539
+ var right = second[index++], result;
2540
+ try {
2541
+ result = resultSelector(left, right);
2542
+ } catch (e) {
2543
+ observer.onError(e);
2544
+ return;
2545
+ }
2546
+ observer.onNext(result);
2547
+ } else {
2548
+ observer.onCompleted();
2549
+ }
2550
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
2551
+ });
2552
+ }
2551
2553
 
2552
- /**
2553
- * 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.
2554
- * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
2555
- *
2556
- * @example
2557
- * 1 - res = obs1.zip(obs2, fn);
2558
- * 1 - res = x1.zip([1,2,3], fn);
2559
- * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2560
- */
2561
- observableProto.zip = function () {
2562
- if (Array.isArray(arguments[0])) {
2563
- return zipArray.apply(this, arguments);
2554
+ /**
2555
+ * 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.
2556
+ * The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the sources.
2557
+ *
2558
+ * @example
2559
+ * 1 - res = obs1.zip(obs2, fn);
2560
+ * 1 - res = x1.zip([1,2,3], fn);
2561
+ * @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
2562
+ */
2563
+ observableProto.zip = function () {
2564
+ if (Array.isArray(arguments[0])) {
2565
+ return zipArray.apply(this, arguments);
2566
+ }
2567
+ var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
2568
+ sources.unshift(parent);
2569
+ return new AnonymousObservable(function (observer) {
2570
+ var n = sources.length,
2571
+ queues = arrayInitialize(n, function () { return []; }),
2572
+ isDone = arrayInitialize(n, function () { return false; });
2573
+
2574
+ function next(i) {
2575
+ var res, queuedValues;
2576
+ if (queues.every(function (x) { return x.length > 0; })) {
2577
+ try {
2578
+ queuedValues = queues.map(function (x) { return x.shift(); });
2579
+ res = resultSelector.apply(parent, queuedValues);
2580
+ } catch (ex) {
2581
+ observer.onError(ex);
2582
+ return;
2583
+ }
2584
+ observer.onNext(res);
2585
+ } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2586
+ observer.onCompleted();
2564
2587
  }
2565
- var parent = this, sources = slice.call(arguments), resultSelector = sources.pop();
2566
- sources.unshift(parent);
2567
- return new AnonymousObservable(function (observer) {
2568
- var n = sources.length,
2569
- queues = arrayInitialize(n, function () { return []; }),
2570
- isDone = arrayInitialize(n, function () { return false; });
2571
-
2572
- var next = function (i) {
2573
- var res, queuedValues;
2574
- if (queues.every(function (x) { return x.length > 0; })) {
2575
- try {
2576
- queuedValues = queues.map(function (x) { return x.shift(); });
2577
- res = resultSelector.apply(parent, queuedValues);
2578
- } catch (ex) {
2579
- observer.onError(ex);
2580
- return;
2581
- }
2582
- observer.onNext(res);
2583
- } else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
2584
- observer.onCompleted();
2585
- }
2586
- };
2588
+ };
2587
2589
 
2588
- function done(i) {
2589
- isDone[i] = true;
2590
- if (isDone.every(function (x) { return x; })) {
2591
- observer.onCompleted();
2592
- }
2593
- }
2590
+ function done(i) {
2591
+ isDone[i] = true;
2592
+ if (isDone.every(function (x) { return x; })) {
2593
+ observer.onCompleted();
2594
+ }
2595
+ }
2594
2596
 
2595
- var subscriptions = new Array(n);
2596
- for (var idx = 0; idx < n; idx++) {
2597
- (function (i) {
2598
- subscriptions[i] = new SingleAssignmentDisposable();
2599
- subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
2600
- queues[i].push(x);
2601
- next(i);
2602
- }, observer.onError.bind(observer), function () {
2603
- done(i);
2604
- }));
2605
- })(idx);
2606
- }
2597
+ var subscriptions = new Array(n);
2598
+ for (var idx = 0; idx < n; idx++) {
2599
+ (function (i) {
2600
+ var source = sources[i], sad = new SingleAssignmentDisposable();
2601
+ isPromise(source) && (source = observableFromPromise(source));
2602
+ sad.setDisposable(source.subscribe(function (x) {
2603
+ queues[i].push(x);
2604
+ next(i);
2605
+ }, observer.onError.bind(observer), function () {
2606
+ done(i);
2607
+ }));
2608
+ subscriptions[i] = sad;
2609
+ })(idx);
2610
+ }
2607
2611
 
2608
- return new CompositeDisposable(subscriptions);
2609
- });
2610
- };
2612
+ return new CompositeDisposable(subscriptions);
2613
+ });
2614
+ };
2611
2615
  /**
2612
2616
  * 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.
2613
2617
  * @param arguments Observable sources.
@@ -3389,7 +3393,7 @@
3389
3393
  selector);
3390
3394
  }
3391
3395
  if (jq) {
3392
- var $elem = jq(elem);
3396
+ var $elem = jq(element);
3393
3397
  return fromEventPattern(
3394
3398
  function (h) { $elem.on(eventName, h); },
3395
3399
  function (h) { $elem.off(eventName, h); },