rxjs-rails 2.2.27 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -3
- data/lib/rxjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +1545 -1441
- data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
- data/vendor/assets/javascripts/rx.all.js +1545 -1441
- data/vendor/assets/javascripts/rx.all.min.js +3 -3
- data/vendor/assets/javascripts/rx.async.compat.js +149 -152
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +140 -143
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +18 -18
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +490 -339
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.core.compat.js +109 -141
- data/vendor/assets/javascripts/rx.core.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.core.js +109 -141
- data/vendor/assets/javascripts/rx.core.min.js +1 -1
- data/vendor/assets/javascripts/rx.experimental.js +129 -136
- data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
- data/vendor/assets/javascripts/rx.joinpatterns.js +59 -59
- data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
- data/vendor/assets/javascripts/rx.js +490 -339
- data/vendor/assets/javascripts/rx.lite.compat.js +1099 -954
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +1099 -954
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +715 -747
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
- metadata +11 -10
@@ -31,6 +31,8 @@
|
|
31
31
|
|
32
32
|
// Defaults
|
33
33
|
var noop = Rx.helpers.noop = function () { },
|
34
|
+
notDefined = Rx.helpers.notDefined = function (x) { return typeof x === 'undefined'; },
|
35
|
+
isScheduler = Rx.helpers.isScheduler = function (x) { return x instanceof Rx.Scheduler; },
|
34
36
|
identity = Rx.helpers.identity = function (x) { return x; },
|
35
37
|
pluck = Rx.helpers.pluck = function (property) { return function (x) { return x[property]; }; },
|
36
38
|
just = Rx.helpers.just = function (value) { return function () { return value; }; },
|
@@ -50,14 +52,13 @@
|
|
50
52
|
function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
|
51
53
|
|
52
54
|
// Shim in iterator support
|
53
|
-
var $iterator$ = (typeof Symbol === '
|
55
|
+
var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
|
54
56
|
'_es6shim_iterator_';
|
55
|
-
//
|
56
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
|
57
|
-
// So use that name if we detect it.
|
57
|
+
// Bug for mozilla version
|
58
58
|
if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
|
59
59
|
$iterator$ = '@@iterator';
|
60
60
|
}
|
61
|
+
|
61
62
|
var doneEnumerator = { done: true, value: undefined };
|
62
63
|
|
63
64
|
/** `Object#toString` result shortcuts */
|
@@ -1394,140 +1395,111 @@
|
|
1394
1395
|
return CatchScheduler;
|
1395
1396
|
}(Scheduler));
|
1396
1397
|
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
var NotificationPrototype = Notification.prototype;
|
1407
|
-
|
1408
|
-
/**
|
1409
|
-
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1410
|
-
*
|
1411
|
-
* @memberOf Notification
|
1412
|
-
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1413
|
-
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1414
|
-
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1415
|
-
* @returns {Any} Result produced by the observation.
|
1416
|
-
*/
|
1417
|
-
NotificationPrototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1418
|
-
if (arguments.length === 1 && typeof observerOrOnNext === 'object') {
|
1419
|
-
return this._acceptObservable(observerOrOnNext);
|
1420
|
-
}
|
1421
|
-
return this._accept(observerOrOnNext, onError, onCompleted);
|
1422
|
-
};
|
1423
|
-
|
1424
|
-
/**
|
1425
|
-
* Returns an observable sequence with a single notification.
|
1426
|
-
*
|
1427
|
-
* @memberOf Notification
|
1428
|
-
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1429
|
-
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1430
|
-
*/
|
1431
|
-
NotificationPrototype.toObservable = function (scheduler) {
|
1432
|
-
var notification = this;
|
1433
|
-
scheduler || (scheduler = immediateScheduler);
|
1434
|
-
return new AnonymousObservable(function (observer) {
|
1435
|
-
return scheduler.schedule(function () {
|
1436
|
-
notification._acceptObservable(observer);
|
1437
|
-
if (notification.kind === 'N') {
|
1438
|
-
observer.onCompleted();
|
1439
|
-
}
|
1440
|
-
});
|
1441
|
-
});
|
1442
|
-
};
|
1443
|
-
|
1444
|
-
return Notification;
|
1445
|
-
})();
|
1398
|
+
/**
|
1399
|
+
* Represents a notification to an observer.
|
1400
|
+
*/
|
1401
|
+
var Notification = Rx.Notification = (function () {
|
1402
|
+
function Notification(kind, hasValue) {
|
1403
|
+
this.hasValue = hasValue == null ? false : hasValue;
|
1404
|
+
this.kind = kind;
|
1405
|
+
}
|
1446
1406
|
|
1447
1407
|
/**
|
1448
|
-
*
|
1449
|
-
*
|
1450
|
-
* @
|
1408
|
+
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1409
|
+
*
|
1410
|
+
* @memberOf Notification
|
1411
|
+
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1412
|
+
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1413
|
+
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1414
|
+
* @returns {Any} Result produced by the observation.
|
1451
1415
|
*/
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
function _acceptObservable(observer) {
|
1459
|
-
return observer.onNext(this.value);
|
1460
|
-
}
|
1461
|
-
|
1462
|
-
function toString () {
|
1463
|
-
return 'OnNext(' + this.value + ')';
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
return function (value) {
|
1467
|
-
var notification = new Notification('N', true);
|
1468
|
-
notification.value = value;
|
1469
|
-
notification._accept = _accept;
|
1470
|
-
notification._acceptObservable = _acceptObservable;
|
1471
|
-
notification.toString = toString;
|
1472
|
-
return notification;
|
1473
|
-
};
|
1474
|
-
}());
|
1416
|
+
Notification.prototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1417
|
+
return observerOrOnNext && typeof observerOrOnNext === 'object' ?
|
1418
|
+
this._acceptObservable(observerOrOnNext) :
|
1419
|
+
this._accept(observerOrOnNext, onError, onCompleted);
|
1420
|
+
};
|
1475
1421
|
|
1476
1422
|
/**
|
1477
|
-
*
|
1478
|
-
*
|
1479
|
-
* @
|
1423
|
+
* Returns an observable sequence with a single notification.
|
1424
|
+
*
|
1425
|
+
* @memberOf Notifications
|
1426
|
+
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1427
|
+
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1480
1428
|
*/
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
function toString () {
|
1492
|
-
return 'OnError(' + this.exception + ')';
|
1493
|
-
}
|
1429
|
+
Notification.prototype.toObservable = function (scheduler) {
|
1430
|
+
var notification = this;
|
1431
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
1432
|
+
return new AnonymousObservable(function (observer) {
|
1433
|
+
return scheduler.schedule(function () {
|
1434
|
+
notification._acceptObservable(observer);
|
1435
|
+
notification.kind === 'N' && observer.onCompleted();
|
1436
|
+
});
|
1437
|
+
});
|
1438
|
+
};
|
1494
1439
|
|
1495
|
-
|
1496
|
-
|
1497
|
-
notification.exception = exception;
|
1498
|
-
notification._accept = _accept;
|
1499
|
-
notification._acceptObservable = _acceptObservable;
|
1500
|
-
notification.toString = toString;
|
1501
|
-
return notification;
|
1502
|
-
};
|
1503
|
-
}());
|
1440
|
+
return Notification;
|
1441
|
+
})();
|
1504
1442
|
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1443
|
+
/**
|
1444
|
+
* Creates an object that represents an OnNext notification to an observer.
|
1445
|
+
* @param {Any} value The value contained in the notification.
|
1446
|
+
* @returns {Notification} The OnNext notification containing the value.
|
1447
|
+
*/
|
1448
|
+
var notificationCreateOnNext = Notification.createOnNext = (function () {
|
1449
|
+
|
1450
|
+
function _accept (onNext) { return onNext(this.value); }
|
1451
|
+
function _acceptObservable(observer) { return observer.onNext(this.value); }
|
1452
|
+
function toString () { return 'OnNext(' + this.value + ')'; }
|
1453
|
+
|
1454
|
+
return function (value) {
|
1455
|
+
var notification = new Notification('N', true);
|
1456
|
+
notification.value = value;
|
1457
|
+
notification._accept = _accept;
|
1458
|
+
notification._acceptObservable = _acceptObservable;
|
1459
|
+
notification.toString = toString;
|
1460
|
+
return notification;
|
1461
|
+
};
|
1462
|
+
}());
|
1510
1463
|
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1464
|
+
/**
|
1465
|
+
* Creates an object that represents an OnError notification to an observer.
|
1466
|
+
* @param {Any} error The exception contained in the notification.
|
1467
|
+
* @returns {Notification} The OnError notification containing the exception.
|
1468
|
+
*/
|
1469
|
+
var notificationCreateOnError = Notification.createOnError = (function () {
|
1470
|
+
|
1471
|
+
function _accept (onNext, onError) { return onError(this.exception); }
|
1472
|
+
function _acceptObservable(observer) { return observer.onError(this.exception); }
|
1473
|
+
function toString () { return 'OnError(' + this.exception + ')'; }
|
1474
|
+
|
1475
|
+
return function (exception) {
|
1476
|
+
var notification = new Notification('E');
|
1477
|
+
notification.exception = exception;
|
1478
|
+
notification._accept = _accept;
|
1479
|
+
notification._acceptObservable = _acceptObservable;
|
1480
|
+
notification.toString = toString;
|
1481
|
+
return notification;
|
1482
|
+
};
|
1483
|
+
}());
|
1514
1484
|
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1485
|
+
/**
|
1486
|
+
* Creates an object that represents an OnCompleted notification to an observer.
|
1487
|
+
* @returns {Notification} The OnCompleted notification.
|
1488
|
+
*/
|
1489
|
+
var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
|
1518
1490
|
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1491
|
+
function _accept (onNext, onError, onCompleted) { return onCompleted(); }
|
1492
|
+
function _acceptObservable(observer) { return observer.onCompleted(); }
|
1493
|
+
function toString () { return 'OnCompleted()'; }
|
1522
1494
|
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1495
|
+
return function () {
|
1496
|
+
var notification = new Notification('C');
|
1497
|
+
notification._accept = _accept;
|
1498
|
+
notification._acceptObservable = _acceptObservable;
|
1499
|
+
notification.toString = toString;
|
1500
|
+
return notification;
|
1501
|
+
};
|
1502
|
+
}());
|
1531
1503
|
|
1532
1504
|
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1533
1505
|
this._next = next;
|
@@ -2207,129 +2179,204 @@
|
|
2207
2179
|
});
|
2208
2180
|
};
|
2209
2181
|
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2182
|
+
/**
|
2183
|
+
* Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
|
2184
|
+
*
|
2185
|
+
* @example
|
2186
|
+
* var res = Rx.Observable.empty();
|
2187
|
+
* var res = Rx.Observable.empty(Rx.Scheduler.timeout);
|
2188
|
+
* @param {Scheduler} [scheduler] Scheduler to send the termination call on.
|
2189
|
+
* @returns {Observable} An observable sequence with no elements.
|
2190
|
+
*/
|
2191
|
+
var observableEmpty = Observable.empty = function (scheduler) {
|
2192
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2193
|
+
return new AnonymousObservable(function (observer) {
|
2194
|
+
return scheduler.schedule(function () {
|
2195
|
+
observer.onCompleted();
|
2196
|
+
});
|
2197
|
+
});
|
2198
|
+
};
|
2227
2199
|
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2200
|
+
var maxSafeInteger = Math.pow(2, 53) - 1;
|
2201
|
+
|
2202
|
+
function numberIsFinite(value) {
|
2203
|
+
return typeof value === 'number' && root.isFinite(value);
|
2204
|
+
}
|
2205
|
+
|
2206
|
+
function isNan(n) {
|
2207
|
+
return n !== n;
|
2208
|
+
}
|
2209
|
+
|
2210
|
+
function isIterable(o) {
|
2211
|
+
return o[$iterator$] !== undefined;
|
2212
|
+
}
|
2213
|
+
|
2214
|
+
function sign(value) {
|
2215
|
+
var number = +value;
|
2216
|
+
if (number === 0) { return number; }
|
2217
|
+
if (isNaN(number)) { return number; }
|
2218
|
+
return number < 0 ? -1 : 1;
|
2219
|
+
}
|
2220
|
+
|
2221
|
+
function toLength(o) {
|
2222
|
+
var len = +o.length;
|
2223
|
+
if (isNaN(len)) { return 0; }
|
2224
|
+
if (len === 0 || !numberIsFinite(len)) { return len; }
|
2225
|
+
len = sign(len) * Math.floor(Math.abs(len));
|
2226
|
+
if (len <= 0) { return 0; }
|
2227
|
+
if (len > maxSafeInteger) { return maxSafeInteger; }
|
2228
|
+
return len;
|
2229
|
+
}
|
2230
|
+
|
2231
|
+
function isCallable(f) {
|
2232
|
+
return Object.prototype.toString.call(f) === '[object Function]' && typeof f === 'function';
|
2233
|
+
}
|
2234
|
+
|
2235
|
+
/**
|
2236
|
+
* This method creates a new Observable sequence from an array-like or iterable object.
|
2237
|
+
* @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
|
2238
|
+
* @param {Function} [mapFn] Map function to call on every element of the array.
|
2239
|
+
* @param {Any} [thisArg] The context to use calling the mapFn if provided.
|
2240
|
+
* @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
|
2241
|
+
*/
|
2242
|
+
Observable.from = function (iterable, mapFn, thisArg, scheduler) {
|
2243
|
+
if (iterable == null) {
|
2244
|
+
throw new Error('iterable cannot be null.')
|
2245
|
+
}
|
2246
|
+
if (mapFn && !isCallable(mapFn)) {
|
2247
|
+
throw new Error('mapFn when provided must be a function');
|
2248
|
+
}
|
2249
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2250
|
+
return new AnonymousObservable(function (observer) {
|
2251
|
+
var list = Object(iterable),
|
2252
|
+
objIsIterable = isIterable(list),
|
2253
|
+
len = objIsIterable ? 0 : toLength(list),
|
2254
|
+
it = objIsIterable ? list[$iterator$]() : null,
|
2255
|
+
i = 0;
|
2256
|
+
return scheduler.scheduleRecursive(function (self) {
|
2257
|
+
if (i < len || objIsIterable) {
|
2258
|
+
var result;
|
2259
|
+
if (objIsIterable) {
|
2260
|
+
var next = it.next();
|
2261
|
+
if (next.done) {
|
2262
|
+
observer.onCompleted();
|
2263
|
+
return;
|
2264
|
+
}
|
2265
|
+
|
2266
|
+
result = next.value;
|
2267
|
+
} else {
|
2268
|
+
result = list[i];
|
2269
|
+
}
|
2270
|
+
|
2271
|
+
if (mapFn && isCallable(mapFn)) {
|
2272
|
+
try {
|
2273
|
+
result = thisArg ? mapFn.call(thisArg, result, i) : mapFn(result, i);
|
2274
|
+
} catch (e) {
|
2275
|
+
observer.onError(e);
|
2276
|
+
return;
|
2277
|
+
}
|
2278
|
+
}
|
2251
2279
|
|
2280
|
+
observer.onNext(result);
|
2281
|
+
i++;
|
2282
|
+
self();
|
2283
|
+
} else {
|
2284
|
+
observer.onCompleted();
|
2285
|
+
}
|
2286
|
+
});
|
2287
|
+
});
|
2288
|
+
};
|
2252
2289
|
/**
|
2253
|
-
* Converts an
|
2290
|
+
* Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
|
2254
2291
|
*
|
2255
2292
|
* @example
|
2256
|
-
* var res = Rx.Observable.
|
2257
|
-
* var res = Rx.Observable.
|
2293
|
+
* var res = Rx.Observable.fromArray([1,2,3]);
|
2294
|
+
* var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
|
2258
2295
|
* @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
|
2259
|
-
* @returns {Observable} The observable sequence whose elements are pulled from the given
|
2296
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
|
2260
2297
|
*/
|
2261
|
-
Observable.
|
2262
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2298
|
+
var observableFromArray = Observable.fromArray = function (array, scheduler) {
|
2299
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2263
2300
|
return new AnonymousObservable(function (observer) {
|
2264
|
-
var
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2301
|
+
var count = 0, len = array.length;
|
2302
|
+
return scheduler.scheduleRecursive(function (self) {
|
2303
|
+
if (count < len) {
|
2304
|
+
observer.onNext(array[count++]);
|
2305
|
+
self();
|
2306
|
+
} else {
|
2307
|
+
observer.onCompleted();
|
2308
|
+
}
|
2309
|
+
});
|
2310
|
+
});
|
2311
|
+
};
|
2271
2312
|
|
2313
|
+
/**
|
2314
|
+
* Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
|
2315
|
+
*
|
2316
|
+
* @example
|
2317
|
+
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
|
2318
|
+
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
|
2319
|
+
* @param {Mixed} initialState Initial state.
|
2320
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
2321
|
+
* @param {Function} iterate Iteration step function.
|
2322
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
2323
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
|
2324
|
+
* @returns {Observable} The generated sequence.
|
2325
|
+
*/
|
2326
|
+
Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
|
2327
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2328
|
+
return new AnonymousObservable(function (observer) {
|
2329
|
+
var first = true, state = initialState;
|
2272
2330
|
return scheduler.scheduleRecursive(function (self) {
|
2273
|
-
var
|
2331
|
+
var hasResult, result;
|
2274
2332
|
try {
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2333
|
+
if (first) {
|
2334
|
+
first = false;
|
2335
|
+
} else {
|
2336
|
+
state = iterate(state);
|
2337
|
+
}
|
2338
|
+
hasResult = condition(state);
|
2339
|
+
if (hasResult) {
|
2340
|
+
result = resultSelector(state);
|
2341
|
+
}
|
2342
|
+
} catch (exception) {
|
2343
|
+
observer.onError(exception);
|
2278
2344
|
return;
|
2279
2345
|
}
|
2280
|
-
|
2281
|
-
|
2282
|
-
observer.onCompleted();
|
2283
|
-
} else {
|
2284
|
-
observer.onNext(next.value);
|
2346
|
+
if (hasResult) {
|
2347
|
+
observer.onNext(result);
|
2285
2348
|
self();
|
2349
|
+
} else {
|
2350
|
+
observer.onCompleted();
|
2286
2351
|
}
|
2287
2352
|
});
|
2288
2353
|
});
|
2289
2354
|
};
|
2290
2355
|
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
}
|
2316
|
-
hasResult = condition(state);
|
2317
|
-
if (hasResult) {
|
2318
|
-
result = resultSelector(state);
|
2319
|
-
}
|
2320
|
-
} catch (exception) {
|
2321
|
-
observer.onError(exception);
|
2322
|
-
return;
|
2323
|
-
}
|
2324
|
-
if (hasResult) {
|
2325
|
-
observer.onNext(result);
|
2326
|
-
self();
|
2327
|
-
} else {
|
2328
|
-
observer.onCompleted();
|
2329
|
-
}
|
2330
|
-
});
|
2331
|
-
});
|
2332
|
-
};
|
2356
|
+
/**
|
2357
|
+
* This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
|
2358
|
+
* @example
|
2359
|
+
* var res = Rx.Observable.of(1,2,3);
|
2360
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
|
2361
|
+
*/
|
2362
|
+
Observable.of = function () {
|
2363
|
+
var len = arguments.length, args = new Array(len);
|
2364
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
2365
|
+
return observableFromArray(args);
|
2366
|
+
};
|
2367
|
+
|
2368
|
+
/**
|
2369
|
+
* This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
|
2370
|
+
* @example
|
2371
|
+
* var res = Rx.Observable.of(1,2,3);
|
2372
|
+
* @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
|
2373
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
|
2374
|
+
*/
|
2375
|
+
var observableOf = Observable.ofWithScheduler = function (scheduler) {
|
2376
|
+
var len = arguments.length - 1, args = new Array(len);
|
2377
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
|
2378
|
+
return observableFromArray(args, scheduler);
|
2379
|
+
};
|
2333
2380
|
|
2334
2381
|
/**
|
2335
2382
|
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
@@ -2341,115 +2388,112 @@
|
|
2341
2388
|
});
|
2342
2389
|
};
|
2343
2390
|
|
2344
|
-
/**
|
2345
|
-
* Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
|
2346
|
-
*
|
2347
|
-
* @example
|
2348
|
-
* var res = Rx.Observable.range(0, 10);
|
2349
|
-
* var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
|
2350
|
-
* @param {Number} start The value of the first integer in the sequence.
|
2351
|
-
* @param {Number} count The number of sequential integers to generate.
|
2352
|
-
* @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
|
2353
|
-
* @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
|
2354
|
-
*/
|
2355
|
-
Observable.range = function (start, count, scheduler) {
|
2356
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2357
|
-
return new AnonymousObservable(function (observer) {
|
2358
|
-
return scheduler.scheduleRecursiveWithState(0, function (i, self) {
|
2359
|
-
if (i < count) {
|
2360
|
-
observer.onNext(start + i);
|
2361
|
-
self(i + 1);
|
2362
|
-
} else {
|
2363
|
-
observer.onCompleted();
|
2364
|
-
}
|
2365
|
-
});
|
2366
|
-
});
|
2367
|
-
};
|
2368
|
-
|
2369
|
-
/**
|
2370
|
-
* Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
|
2371
|
-
*
|
2372
|
-
* @example
|
2373
|
-
* var res = Rx.Observable.repeat(42);
|
2374
|
-
* var res = Rx.Observable.repeat(42, 4);
|
2375
|
-
* 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
|
2376
|
-
* 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
|
2377
|
-
* @param {Mixed} value Element to repeat.
|
2378
|
-
* @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
|
2379
|
-
* @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
|
2380
|
-
* @returns {Observable} An observable sequence that repeats the given element the specified number of times.
|
2381
|
-
*/
|
2382
|
-
Observable.repeat = function (value, repeatCount, scheduler) {
|
2383
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2384
|
-
if (repeatCount == null) {
|
2385
|
-
repeatCount = -1;
|
2386
|
-
}
|
2387
|
-
return observableReturn(value, scheduler).repeat(repeatCount);
|
2388
|
-
};
|
2389
|
-
|
2390
|
-
/**
|
2391
|
-
* Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
|
2392
|
-
* There is an alias called 'returnValue' for browsers <IE9.
|
2393
|
-
*
|
2394
|
-
* @example
|
2395
|
-
* var res = Rx.Observable.return(42);
|
2396
|
-
* var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
|
2397
|
-
* @param {Mixed} value Single element in the resulting observable sequence.
|
2398
|
-
* @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
|
2399
|
-
* @returns {Observable} An observable sequence containing the single specified element.
|
2400
|
-
*/
|
2401
|
-
var observableReturn = Observable['return'] = Observable.returnValue = function (value, scheduler) {
|
2402
|
-
scheduler || (scheduler = immediateScheduler);
|
2403
|
-
return new AnonymousObservable(function (observer) {
|
2404
|
-
return scheduler.schedule(function () {
|
2405
|
-
observer.onNext(value);
|
2406
|
-
observer.onCompleted();
|
2407
|
-
});
|
2408
|
-
});
|
2409
|
-
};
|
2410
|
-
|
2411
|
-
/**
|
2412
|
-
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2413
|
-
* There is an alias to this method called 'throwException' for browsers <IE9.
|
2414
|
-
*
|
2415
|
-
* @example
|
2416
|
-
* var res = Rx.Observable.throwException(new Error('Error'));
|
2417
|
-
* var res = Rx.Observable.throwException(new Error('Error'), Rx.Scheduler.timeout);
|
2418
|
-
* @param {Mixed} exception An object used for the sequence's termination.
|
2419
|
-
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2420
|
-
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2421
|
-
*/
|
2422
|
-
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2423
|
-
scheduler || (scheduler = immediateScheduler);
|
2424
|
-
return new AnonymousObservable(function (observer) {
|
2425
|
-
return scheduler.schedule(function () {
|
2426
|
-
observer.onError(exception);
|
2427
|
-
});
|
2428
|
-
});
|
2429
|
-
};
|
2430
|
-
|
2431
2391
|
/**
|
2432
|
-
*
|
2392
|
+
* Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
|
2433
2393
|
*
|
2434
2394
|
* @example
|
2435
|
-
* var res = Rx.Observable.
|
2436
|
-
*
|
2437
|
-
* @param {
|
2438
|
-
* @
|
2395
|
+
* var res = Rx.Observable.range(0, 10);
|
2396
|
+
* var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
|
2397
|
+
* @param {Number} start The value of the first integer in the sequence.
|
2398
|
+
* @param {Number} count The number of sequential integers to generate.
|
2399
|
+
* @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
|
2400
|
+
* @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
|
2439
2401
|
*/
|
2440
|
-
Observable.
|
2402
|
+
Observable.range = function (start, count, scheduler) {
|
2403
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2441
2404
|
return new AnonymousObservable(function (observer) {
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2405
|
+
return scheduler.scheduleRecursiveWithState(0, function (i, self) {
|
2406
|
+
if (i < count) {
|
2407
|
+
observer.onNext(start + i);
|
2408
|
+
self(i + 1);
|
2409
|
+
} else {
|
2410
|
+
observer.onCompleted();
|
2447
2411
|
}
|
2448
|
-
|
2449
|
-
|
2450
|
-
|
2451
|
-
|
2452
|
-
|
2412
|
+
});
|
2413
|
+
});
|
2414
|
+
};
|
2415
|
+
|
2416
|
+
/**
|
2417
|
+
* Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
|
2418
|
+
*
|
2419
|
+
* @example
|
2420
|
+
* var res = Rx.Observable.repeat(42);
|
2421
|
+
* var res = Rx.Observable.repeat(42, 4);
|
2422
|
+
* 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
|
2423
|
+
* 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
|
2424
|
+
* @param {Mixed} value Element to repeat.
|
2425
|
+
* @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
|
2426
|
+
* @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
|
2427
|
+
* @returns {Observable} An observable sequence that repeats the given element the specified number of times.
|
2428
|
+
*/
|
2429
|
+
Observable.repeat = function (value, repeatCount, scheduler) {
|
2430
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2431
|
+
return observableReturn(value, scheduler).repeat(repeatCount == null ? -1 : repeatCount);
|
2432
|
+
};
|
2433
|
+
|
2434
|
+
/**
|
2435
|
+
* Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
|
2436
|
+
* There is an alias called 'just', and 'returnValue' for browsers <IE9.
|
2437
|
+
*
|
2438
|
+
* @example
|
2439
|
+
* var res = Rx.Observable.return(42);
|
2440
|
+
* var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
|
2441
|
+
* @param {Mixed} value Single element in the resulting observable sequence.
|
2442
|
+
* @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
|
2443
|
+
* @returns {Observable} An observable sequence containing the single specified element.
|
2444
|
+
*/
|
2445
|
+
var observableReturn = Observable['return'] = Observable.returnValue = Observable.just = function (value, scheduler) {
|
2446
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2447
|
+
return new AnonymousObservable(function (observer) {
|
2448
|
+
return scheduler.schedule(function () {
|
2449
|
+
observer.onNext(value);
|
2450
|
+
observer.onCompleted();
|
2451
|
+
});
|
2452
|
+
});
|
2453
|
+
};
|
2454
|
+
|
2455
|
+
/**
|
2456
|
+
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2457
|
+
* There is an alias to this method called 'throwException' for browsers <IE9.
|
2458
|
+
*
|
2459
|
+
* @example
|
2460
|
+
* var res = Rx.Observable.throw(new Error('Error'));
|
2461
|
+
* var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
|
2462
|
+
* @param {Mixed} exception An object used for the sequence's termination.
|
2463
|
+
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2464
|
+
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2465
|
+
*/
|
2466
|
+
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2467
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2468
|
+
return new AnonymousObservable(function (observer) {
|
2469
|
+
return scheduler.schedule(function () {
|
2470
|
+
observer.onError(exception);
|
2471
|
+
});
|
2472
|
+
});
|
2473
|
+
};
|
2474
|
+
|
2475
|
+
/**
|
2476
|
+
* Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
|
2477
|
+
*
|
2478
|
+
* @example
|
2479
|
+
* var res = Rx.Observable.using(function () { return new AsyncSubject(); }, function (s) { return s; });
|
2480
|
+
* @param {Function} resourceFactory Factory function to obtain a resource object.
|
2481
|
+
* @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
|
2482
|
+
* @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
|
2483
|
+
*/
|
2484
|
+
Observable.using = function (resourceFactory, observableFactory) {
|
2485
|
+
return new AnonymousObservable(function (observer) {
|
2486
|
+
var disposable = disposableEmpty, resource, source;
|
2487
|
+
try {
|
2488
|
+
resource = resourceFactory();
|
2489
|
+
if (resource) {
|
2490
|
+
disposable = resource;
|
2491
|
+
}
|
2492
|
+
source = observableFactory(resource);
|
2493
|
+
} catch (exception) {
|
2494
|
+
return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
|
2495
|
+
}
|
2496
|
+
return new CompositeDisposable(source.subscribe(observer), disposable);
|
2453
2497
|
});
|
2454
2498
|
};
|
2455
2499
|
|
@@ -3331,18 +3375,19 @@
|
|
3331
3375
|
return enumerableRepeat(this, repeatCount).concat();
|
3332
3376
|
};
|
3333
3377
|
|
3334
|
-
|
3335
|
-
|
3336
|
-
|
3337
|
-
|
3338
|
-
|
3339
|
-
|
3340
|
-
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3344
|
-
|
3345
|
-
|
3378
|
+
/**
|
3379
|
+
* Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.
|
3380
|
+
* Note if you encounter an error and want it to retry once, then you must use .retry(2);
|
3381
|
+
*
|
3382
|
+
* @example
|
3383
|
+
* var res = retried = retry.repeat();
|
3384
|
+
* var res = retried = retry.repeat(2);
|
3385
|
+
* @param {Number} [retryCount] Number of times to retry the sequence. If not provided, retry the sequence indefinitely.
|
3386
|
+
* @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
|
3387
|
+
*/
|
3388
|
+
observableProto.retry = function (retryCount) {
|
3389
|
+
return enumerableRepeat(this, retryCount).catchException();
|
3390
|
+
};
|
3346
3391
|
|
3347
3392
|
/**
|
3348
3393
|
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
@@ -3907,7 +3952,7 @@
|
|
3907
3952
|
* @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
|
3908
3953
|
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
3909
3954
|
*/
|
3910
|
-
observableProto.selectSwitch = observableProto.flatMapLatest = function (selector, thisArg) {
|
3955
|
+
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
3911
3956
|
return this.select(selector, thisArg).switchLatest();
|
3912
3957
|
};
|
3913
3958
|
|
@@ -4704,151 +4749,147 @@
|
|
4704
4749
|
return findValue(this, predicate, thisArg, true);
|
4705
4750
|
};
|
4706
4751
|
|
4707
|
-
|
4708
|
-
|
4709
|
-
|
4710
|
-
|
4711
|
-
|
4712
|
-
|
4713
|
-
|
4714
|
-
|
4715
|
-
|
4716
|
-
|
4717
|
-
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
/**
|
4729
|
-
* Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
|
4730
|
-
*
|
4731
|
-
* @example
|
4732
|
-
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
|
4733
|
-
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
4734
|
-
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
4735
|
-
*
|
4736
|
-
* @param {Function} function Function to convert to an asynchronous function.
|
4737
|
-
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
4738
|
-
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4739
|
-
* @returns {Function} Asynchronous function.
|
4740
|
-
*/
|
4741
|
-
var observableToAsync = Observable.toAsync = function (func, scheduler, context) {
|
4742
|
-
scheduler || (scheduler = timeoutScheduler);
|
4743
|
-
return function () {
|
4744
|
-
var args = arguments,
|
4745
|
-
subject = new AsyncSubject();
|
4752
|
+
/**
|
4753
|
+
* Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
|
4754
|
+
*
|
4755
|
+
* @example
|
4756
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); });
|
4757
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
|
4758
|
+
* var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
|
4759
|
+
*
|
4760
|
+
* @param {Function} func Function to run asynchronously.
|
4761
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
4762
|
+
* @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4763
|
+
* @returns {Observable} An observable sequence exposing the function's result value, or an exception.
|
4764
|
+
*
|
4765
|
+
* Remarks
|
4766
|
+
* * The function is called immediately, not during the subscription of the resulting sequence.
|
4767
|
+
* * Multiple subscriptions to the resulting sequence can observe the function's result.
|
4768
|
+
*/
|
4769
|
+
Observable.start = function (func, context, scheduler) {
|
4770
|
+
return observableToAsync(func, context, scheduler)();
|
4771
|
+
};
|
4746
4772
|
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4773
|
+
/**
|
4774
|
+
* Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
|
4775
|
+
*
|
4776
|
+
* @example
|
4777
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
|
4778
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
4779
|
+
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
4780
|
+
*
|
4781
|
+
* @param {Function} function Function to convert to an asynchronous function.
|
4782
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
4783
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4784
|
+
* @returns {Function} Asynchronous function.
|
4785
|
+
*/
|
4786
|
+
var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
4787
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4788
|
+
return function () {
|
4789
|
+
var args = arguments,
|
4790
|
+
subject = new AsyncSubject();
|
4791
|
+
|
4792
|
+
scheduler.schedule(function () {
|
4793
|
+
var result;
|
4794
|
+
try {
|
4795
|
+
result = func.apply(context, args);
|
4796
|
+
} catch (e) {
|
4797
|
+
subject.onError(e);
|
4798
|
+
return;
|
4799
|
+
}
|
4800
|
+
subject.onNext(result);
|
4801
|
+
subject.onCompleted();
|
4802
|
+
});
|
4803
|
+
return subject.asObservable();
|
4760
4804
|
};
|
4805
|
+
};
|
4761
4806
|
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
return function () {
|
4774
|
-
var args = slice.call(arguments, 0);
|
4807
|
+
/**
|
4808
|
+
* Converts a callback function to an observable sequence.
|
4809
|
+
*
|
4810
|
+
* @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
|
4811
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4812
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
4813
|
+
* @returns {Function} A function, when executed with the required parameters minus the callback, produces an Observable sequence with a single value of the arguments to the callback as an array.
|
4814
|
+
*/
|
4815
|
+
Observable.fromCallback = function (func, context, selector) {
|
4816
|
+
return function () {
|
4817
|
+
var args = slice.call(arguments, 0);
|
4775
4818
|
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
}
|
4788
|
-
} else {
|
4789
|
-
if (results.length === 1) {
|
4790
|
-
results = results[0];
|
4791
|
-
}
|
4792
|
-
}
|
4819
|
+
return new AnonymousObservable(function (observer) {
|
4820
|
+
function handler(e) {
|
4821
|
+
var results = e;
|
4822
|
+
|
4823
|
+
if (selector) {
|
4824
|
+
try {
|
4825
|
+
results = selector(arguments);
|
4826
|
+
} catch (err) {
|
4827
|
+
observer.onError(err);
|
4828
|
+
return;
|
4829
|
+
}
|
4793
4830
|
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4831
|
+
observer.onNext(results);
|
4832
|
+
} else {
|
4833
|
+
if (results.length <= 1) {
|
4834
|
+
observer.onNext.apply(observer, results);
|
4835
|
+
} else {
|
4836
|
+
observer.onNext(results);
|
4837
|
+
}
|
4838
|
+
}
|
4839
|
+
|
4840
|
+
observer.onCompleted();
|
4841
|
+
}
|
4797
4842
|
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
});
|
4802
|
-
};
|
4843
|
+
args.push(handler);
|
4844
|
+
func.apply(context, args);
|
4845
|
+
});
|
4803
4846
|
};
|
4847
|
+
};
|
4804
4848
|
|
4805
|
-
|
4806
|
-
|
4807
|
-
|
4808
|
-
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
return function () {
|
4816
|
-
var args = slice.call(arguments, 0);
|
4849
|
+
/**
|
4850
|
+
* Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
|
4851
|
+
* @param {Function} func The function to call
|
4852
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4853
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
|
4854
|
+
* @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
|
4855
|
+
*/
|
4856
|
+
Observable.fromNodeCallback = function (func, context, selector) {
|
4857
|
+
return function () {
|
4858
|
+
var args = slice.call(arguments, 0);
|
4817
4859
|
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4824
|
-
return;
|
4825
|
-
}
|
4860
|
+
return new AnonymousObservable(function (observer) {
|
4861
|
+
function handler(err) {
|
4862
|
+
if (err) {
|
4863
|
+
observer.onError(err);
|
4864
|
+
return;
|
4865
|
+
}
|
4826
4866
|
|
4827
|
-
|
4828
|
-
|
4829
|
-
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4867
|
+
var results = slice.call(arguments, 1);
|
4868
|
+
|
4869
|
+
if (selector) {
|
4870
|
+
try {
|
4871
|
+
results = selector(results);
|
4872
|
+
} catch (e) {
|
4873
|
+
observer.onError(e);
|
4874
|
+
return;
|
4875
|
+
}
|
4876
|
+
observer.onNext(results);
|
4877
|
+
} else {
|
4878
|
+
if (results.length <= 1) {
|
4879
|
+
observer.onNext.apply(observer, results);
|
4880
|
+
} else {
|
4881
|
+
observer.onNext(results);
|
4882
|
+
}
|
4883
|
+
}
|
4841
4884
|
|
4842
|
-
|
4843
|
-
|
4844
|
-
}
|
4885
|
+
observer.onCompleted();
|
4886
|
+
}
|
4845
4887
|
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
});
|
4850
|
-
};
|
4888
|
+
args.push(handler);
|
4889
|
+
func.apply(context, args);
|
4890
|
+
});
|
4851
4891
|
};
|
4892
|
+
};
|
4852
4893
|
|
4853
4894
|
function createListener (element, name, handler) {
|
4854
4895
|
// Node.js specific
|
@@ -5476,24 +5517,24 @@
|
|
5476
5517
|
}, selector);
|
5477
5518
|
};
|
5478
5519
|
|
5479
|
-
|
5480
|
-
|
5481
|
-
|
5482
|
-
|
5483
|
-
|
5484
|
-
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5520
|
+
/**
|
5521
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
|
5522
|
+
* This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
|
5523
|
+
*
|
5524
|
+
* @example
|
5525
|
+
* var res = source.shareReplay(3);
|
5526
|
+
* var res = source.shareReplay(3, 500);
|
5527
|
+
* var res = source.shareReplay(3, 500, scheduler);
|
5528
|
+
*
|
5488
5529
|
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
|
5495
|
-
|
5496
|
-
|
5530
|
+
* @param bufferSize [Optional] Maximum element count of the replay buffer.
|
5531
|
+
* @param window [Optional] Maximum time length of the replay buffer.
|
5532
|
+
* @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
|
5533
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
5534
|
+
*/
|
5535
|
+
observableProto.shareReplay = function (bufferSize, window, scheduler) {
|
5536
|
+
return this.replay(null, bufferSize, window, scheduler).refCount();
|
5537
|
+
};
|
5497
5538
|
|
5498
5539
|
/** @private */
|
5499
5540
|
var InnerSubscription = function (subject, observer) {
|
@@ -6621,6 +6662,7 @@
|
|
6621
6662
|
*/
|
6622
6663
|
Observable['case'] = Observable.switchCase = function (selector, sources, defaultSourceOrScheduler) {
|
6623
6664
|
return observableDefer(function () {
|
6665
|
+
isPromise(defaultSourceOrScheduler) && (defaultSourceOrScheduler = observableFromPromise(defaultSourceOrScheduler));
|
6624
6666
|
defaultSourceOrScheduler || (defaultSourceOrScheduler = observableEmpty());
|
6625
6667
|
|
6626
6668
|
typeof defaultSourceOrScheduler.now === 'function' && (defaultSourceOrScheduler = observableEmpty(defaultSourceOrScheduler));
|
@@ -6632,69 +6674,69 @@
|
|
6632
6674
|
});
|
6633
6675
|
};
|
6634
6676
|
|
6635
|
-
|
6636
|
-
|
6637
|
-
|
6638
|
-
|
6639
|
-
|
6640
|
-
|
6641
|
-
|
6642
|
-
|
6643
|
-
|
6644
|
-
|
6645
|
-
|
6646
|
-
|
6647
|
-
|
6648
|
-
|
6649
|
-
|
6650
|
-
|
6651
|
-
|
6652
|
-
|
6653
|
-
|
6654
|
-
|
6655
|
-
|
6656
|
-
|
6657
|
-
|
6658
|
-
|
6659
|
-
|
6660
|
-
|
6661
|
-
|
6662
|
-
|
6663
|
-
|
6664
|
-
|
6665
|
-
|
6666
|
-
|
6667
|
-
|
6668
|
-
|
6669
|
-
|
6670
|
-
|
6671
|
-
|
6672
|
-
|
6673
|
-
|
6674
|
-
|
6675
|
-
|
6676
|
-
|
6677
|
-
|
6678
|
-
|
6679
|
-
|
6680
|
-
|
6681
|
-
|
6682
|
-
|
6683
|
-
|
6684
|
-
|
6685
|
-
|
6686
|
-
|
6687
|
-
|
6688
|
-
|
6689
|
-
|
6690
|
-
|
6677
|
+
/**
|
6678
|
+
* Expands an observable sequence by recursively invoking selector.
|
6679
|
+
*
|
6680
|
+
* @param {Function} selector Selector function to invoke for each produced element, resulting in another sequence to which the selector will be invoked recursively again.
|
6681
|
+
* @param {Scheduler} [scheduler] Scheduler on which to perform the expansion. If not provided, this defaults to the current thread scheduler.
|
6682
|
+
* @returns {Observable} An observable sequence containing all the elements produced by the recursive expansion.
|
6683
|
+
*/
|
6684
|
+
observableProto.expand = function (selector, scheduler) {
|
6685
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
6686
|
+
var source = this;
|
6687
|
+
return new AnonymousObservable(function (observer) {
|
6688
|
+
var q = [],
|
6689
|
+
m = new SerialDisposable(),
|
6690
|
+
d = new CompositeDisposable(m),
|
6691
|
+
activeCount = 0,
|
6692
|
+
isAcquired = false;
|
6693
|
+
|
6694
|
+
var ensureActive = function () {
|
6695
|
+
var isOwner = false;
|
6696
|
+
if (q.length > 0) {
|
6697
|
+
isOwner = !isAcquired;
|
6698
|
+
isAcquired = true;
|
6699
|
+
}
|
6700
|
+
if (isOwner) {
|
6701
|
+
m.setDisposable(scheduler.scheduleRecursive(function (self) {
|
6702
|
+
var work;
|
6703
|
+
if (q.length > 0) {
|
6704
|
+
work = q.shift();
|
6705
|
+
} else {
|
6706
|
+
isAcquired = false;
|
6707
|
+
return;
|
6708
|
+
}
|
6709
|
+
var m1 = new SingleAssignmentDisposable();
|
6710
|
+
d.add(m1);
|
6711
|
+
m1.setDisposable(work.subscribe(function (x) {
|
6712
|
+
observer.onNext(x);
|
6713
|
+
var result = null;
|
6714
|
+
try {
|
6715
|
+
result = selector(x);
|
6716
|
+
} catch (e) {
|
6717
|
+
observer.onError(e);
|
6718
|
+
}
|
6719
|
+
q.push(result);
|
6720
|
+
activeCount++;
|
6721
|
+
ensureActive();
|
6722
|
+
}, observer.onError.bind(observer), function () {
|
6723
|
+
d.remove(m1);
|
6724
|
+
activeCount--;
|
6725
|
+
if (activeCount === 0) {
|
6726
|
+
observer.onCompleted();
|
6727
|
+
}
|
6728
|
+
}));
|
6729
|
+
self();
|
6730
|
+
}));
|
6731
|
+
}
|
6732
|
+
};
|
6691
6733
|
|
6692
|
-
|
6693
|
-
|
6694
|
-
|
6695
|
-
|
6696
|
-
|
6697
|
-
|
6734
|
+
q.push(source);
|
6735
|
+
activeCount++;
|
6736
|
+
ensureActive();
|
6737
|
+
return d;
|
6738
|
+
});
|
6739
|
+
};
|
6698
6740
|
|
6699
6741
|
/**
|
6700
6742
|
* Runs all observable sequences in parallel and collect their last elements.
|
@@ -6837,82 +6879,73 @@
|
|
6837
6879
|
});
|
6838
6880
|
};
|
6839
6881
|
|
6840
|
-
|
6841
|
-
|
6842
|
-
|
6843
|
-
|
6844
|
-
|
6845
|
-
|
6846
|
-
|
6847
|
-
|
6848
|
-
|
6849
|
-
|
6850
|
-
|
6851
|
-
|
6852
|
-
return source
|
6853
|
-
.select(
|
6854
|
-
function (x) {
|
6855
|
-
var curr = new ChainObservable(x);
|
6856
|
-
if (chain) {
|
6857
|
-
chain.onNext(x);
|
6858
|
-
}
|
6859
|
-
chain = curr;
|
6860
|
-
|
6861
|
-
return curr;
|
6862
|
-
})
|
6863
|
-
.doAction(
|
6864
|
-
noop,
|
6865
|
-
function (e) {
|
6866
|
-
if (chain) {
|
6867
|
-
chain.onError(e);
|
6868
|
-
}
|
6869
|
-
},
|
6870
|
-
function () {
|
6871
|
-
if (chain) {
|
6872
|
-
chain.onCompleted();
|
6873
|
-
}
|
6874
|
-
})
|
6875
|
-
.observeOn(scheduler)
|
6876
|
-
.select(function (x, i, o) { return selector(x, i, o); });
|
6877
|
-
});
|
6878
|
-
};
|
6882
|
+
/**
|
6883
|
+
* Comonadic bind operator.
|
6884
|
+
* @param {Function} selector A transform function to apply to each element.
|
6885
|
+
* @param {Object} scheduler Scheduler used to execute the operation. If not specified, defaults to the ImmediateScheduler.
|
6886
|
+
* @returns {Observable} An observable sequence which results from the comonadic bind operation.
|
6887
|
+
*/
|
6888
|
+
observableProto.manySelect = function (selector, scheduler) {
|
6889
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
6890
|
+
var source = this;
|
6891
|
+
return observableDefer(function () {
|
6892
|
+
var chain;
|
6879
6893
|
|
6880
|
-
|
6894
|
+
return source
|
6895
|
+
.map(function (x) {
|
6896
|
+
var curr = new ChainObservable(x);
|
6881
6897
|
|
6882
|
-
|
6883
|
-
|
6884
|
-
g.add(currentThreadScheduler.schedule(function () {
|
6885
|
-
observer.onNext(self.head);
|
6886
|
-
g.add(self.tail.mergeObservable().subscribe(observer));
|
6887
|
-
}));
|
6898
|
+
chain && chain.onNext(x);
|
6899
|
+
chain = curr;
|
6888
6900
|
|
6889
|
-
|
6890
|
-
}
|
6901
|
+
return curr;
|
6902
|
+
})
|
6903
|
+
.doAction(
|
6904
|
+
noop,
|
6905
|
+
function (e) { chain && chain.onError(e); },
|
6906
|
+
function () { chain && chain.onCompleted(); }
|
6907
|
+
)
|
6908
|
+
.observeOn(scheduler)
|
6909
|
+
.map(selector);
|
6910
|
+
});
|
6911
|
+
};
|
6891
6912
|
|
6892
|
-
|
6913
|
+
var ChainObservable = (function (__super__) {
|
6893
6914
|
|
6894
|
-
|
6895
|
-
|
6896
|
-
|
6897
|
-
|
6898
|
-
|
6915
|
+
function subscribe (observer) {
|
6916
|
+
var self = this, g = new CompositeDisposable();
|
6917
|
+
g.add(currentThreadScheduler.schedule(function () {
|
6918
|
+
observer.onNext(self.head);
|
6919
|
+
g.add(self.tail.mergeObservable().subscribe(observer));
|
6920
|
+
}));
|
6899
6921
|
|
6900
|
-
|
6901
|
-
|
6902
|
-
this.onNext(Observable.empty());
|
6903
|
-
},
|
6904
|
-
onError: function (e) {
|
6905
|
-
this.onNext(Observable.throwException(e));
|
6906
|
-
},
|
6907
|
-
onNext: function (v) {
|
6908
|
-
this.tail.onNext(v);
|
6909
|
-
this.tail.onCompleted();
|
6910
|
-
}
|
6911
|
-
});
|
6922
|
+
return g;
|
6923
|
+
}
|
6912
6924
|
|
6913
|
-
|
6925
|
+
inherits(ChainObservable, __super__);
|
6914
6926
|
|
6915
|
-
|
6927
|
+
function ChainObservable(head) {
|
6928
|
+
__super__.call(this, subscribe);
|
6929
|
+
this.head = head;
|
6930
|
+
this.tail = new AsyncSubject();
|
6931
|
+
}
|
6932
|
+
|
6933
|
+
addProperties(ChainObservable.prototype, Observer, {
|
6934
|
+
onCompleted: function () {
|
6935
|
+
this.onNext(Observable.empty());
|
6936
|
+
},
|
6937
|
+
onError: function (e) {
|
6938
|
+
this.onNext(Observable.throwException(e));
|
6939
|
+
},
|
6940
|
+
onNext: function (v) {
|
6941
|
+
this.tail.onNext(v);
|
6942
|
+
this.tail.onCompleted();
|
6943
|
+
}
|
6944
|
+
});
|
6945
|
+
|
6946
|
+
return ChainObservable;
|
6947
|
+
|
6948
|
+
}(Observable));
|
6916
6949
|
|
6917
6950
|
/** @private */
|
6918
6951
|
var Map = (function () {
|
@@ -7015,51 +7048,51 @@
|
|
7015
7048
|
* @param selector Selector that will be invoked with available values from the source sequences, in the same order of the sequences in the pattern.
|
7016
7049
|
* @return Plan that produces the projected values, to be fed (with other plans) to the when operator.
|
7017
7050
|
*/
|
7018
|
-
Pattern.prototype.
|
7051
|
+
Pattern.prototype.thenDo = function (selector) {
|
7019
7052
|
return new Plan(this, selector);
|
7020
7053
|
};
|
7021
7054
|
|
7022
|
-
|
7023
|
-
|
7024
|
-
|
7055
|
+
function Plan(expression, selector) {
|
7056
|
+
this.expression = expression;
|
7057
|
+
this.selector = selector;
|
7058
|
+
}
|
7059
|
+
|
7060
|
+
Plan.prototype.activate = function (externalSubscriptions, observer, deactivate) {
|
7061
|
+
var self = this;
|
7062
|
+
var joinObservers = [];
|
7063
|
+
for (var i = 0, len = this.expression.patterns.length; i < len; i++) {
|
7064
|
+
joinObservers.push(planCreateObserver(externalSubscriptions, this.expression.patterns[i], observer.onError.bind(observer)));
|
7025
7065
|
}
|
7026
|
-
|
7027
|
-
|
7028
|
-
|
7029
|
-
|
7030
|
-
|
7031
|
-
|
7032
|
-
|
7033
|
-
|
7034
|
-
|
7035
|
-
|
7036
|
-
|
7037
|
-
|
7038
|
-
|
7039
|
-
|
7040
|
-
|
7041
|
-
|
7042
|
-
|
7043
|
-
|
7044
|
-
|
7045
|
-
|
7046
|
-
deactivate(activePlan);
|
7047
|
-
});
|
7048
|
-
for (i = 0, len = joinObservers.length; i < len; i++) {
|
7049
|
-
joinObservers[i].addActivePlan(activePlan);
|
7050
|
-
}
|
7051
|
-
return activePlan;
|
7052
|
-
};
|
7066
|
+
var activePlan = new ActivePlan(joinObservers, function () {
|
7067
|
+
var result;
|
7068
|
+
try {
|
7069
|
+
result = self.selector.apply(self, arguments);
|
7070
|
+
} catch (exception) {
|
7071
|
+
observer.onError(exception);
|
7072
|
+
return;
|
7073
|
+
}
|
7074
|
+
observer.onNext(result);
|
7075
|
+
}, function () {
|
7076
|
+
for (var j = 0, jlen = joinObservers.length; j < jlen; j++) {
|
7077
|
+
joinObservers[j].removeActivePlan(activePlan);
|
7078
|
+
}
|
7079
|
+
deactivate(activePlan);
|
7080
|
+
});
|
7081
|
+
for (i = 0, len = joinObservers.length; i < len; i++) {
|
7082
|
+
joinObservers[i].addActivePlan(activePlan);
|
7083
|
+
}
|
7084
|
+
return activePlan;
|
7085
|
+
};
|
7053
7086
|
|
7054
|
-
|
7055
|
-
|
7056
|
-
|
7057
|
-
|
7058
|
-
|
7059
|
-
|
7060
|
-
}
|
7061
|
-
return entry;
|
7087
|
+
function planCreateObserver(externalSubscriptions, observable, onError) {
|
7088
|
+
var entry = externalSubscriptions.get(observable);
|
7089
|
+
if (!entry) {
|
7090
|
+
var observer = new JoinObserver(observable, onError);
|
7091
|
+
externalSubscriptions.set(observable, observer);
|
7092
|
+
return observer;
|
7062
7093
|
}
|
7094
|
+
return entry;
|
7095
|
+
}
|
7063
7096
|
|
7064
7097
|
// Active Plan
|
7065
7098
|
function ActivePlan(joinObserverArray, onNext, onCompleted) {
|
@@ -7204,25 +7237,25 @@
|
|
7204
7237
|
return JoinObserver;
|
7205
7238
|
} (AbstractObserver));
|
7206
7239
|
|
7207
|
-
|
7208
|
-
|
7209
|
-
|
7210
|
-
|
7211
|
-
|
7212
|
-
|
7213
|
-
|
7214
|
-
|
7215
|
-
|
7240
|
+
/**
|
7241
|
+
* Creates a pattern that matches when both observable sequences have an available value.
|
7242
|
+
*
|
7243
|
+
* @param right Observable sequence to match with the current sequence.
|
7244
|
+
* @return {Pattern} Pattern object that matches when both observable sequences have an available value.
|
7245
|
+
*/
|
7246
|
+
observableProto.and = function (right) {
|
7247
|
+
return new Pattern([this, right]);
|
7248
|
+
};
|
7216
7249
|
|
7217
|
-
|
7218
|
-
|
7219
|
-
|
7220
|
-
|
7221
|
-
|
7222
|
-
|
7223
|
-
|
7224
|
-
|
7225
|
-
|
7250
|
+
/**
|
7251
|
+
* Matches when the observable sequence has an available value and projects the value.
|
7252
|
+
*
|
7253
|
+
* @param selector Selector that will be invoked for values in the source sequence.
|
7254
|
+
* @returns {Plan} Plan that produces the projected values, to be fed (with other plans) to the when operator.
|
7255
|
+
*/
|
7256
|
+
observableProto.thenDo = function (selector) {
|
7257
|
+
return new Pattern([this]).thenDo(selector);
|
7258
|
+
};
|
7226
7259
|
|
7227
7260
|
/**
|
7228
7261
|
* Joins together the results from several patterns.
|
@@ -7280,24 +7313,24 @@
|
|
7280
7313
|
});
|
7281
7314
|
}
|
7282
7315
|
|
7283
|
-
|
7284
|
-
|
7285
|
-
|
7286
|
-
|
7287
|
-
|
7288
|
-
|
7289
|
-
|
7290
|
-
|
7291
|
-
|
7292
|
-
|
7293
|
-
|
7294
|
-
|
7295
|
-
|
7296
|
-
|
7297
|
-
|
7298
|
-
|
7299
|
-
|
7300
|
-
|
7316
|
+
function observableTimerDateAndPeriod(dueTime, period, scheduler) {
|
7317
|
+
var p = normalizeTime(period);
|
7318
|
+
return new AnonymousObservable(function (observer) {
|
7319
|
+
var count = 0, d = dueTime;
|
7320
|
+
return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
|
7321
|
+
var now;
|
7322
|
+
if (p > 0) {
|
7323
|
+
now = scheduler.now();
|
7324
|
+
d = d + p;
|
7325
|
+
if (d <= now) {
|
7326
|
+
d = now + p;
|
7327
|
+
}
|
7328
|
+
}
|
7329
|
+
observer.onNext(count++);
|
7330
|
+
self(d);
|
7331
|
+
});
|
7332
|
+
});
|
7333
|
+
}
|
7301
7334
|
|
7302
7335
|
function observableTimerTimeSpan(dueTime, scheduler) {
|
7303
7336
|
var d = normalizeTime(dueTime);
|
@@ -7309,357 +7342,343 @@
|
|
7309
7342
|
});
|
7310
7343
|
}
|
7311
7344
|
|
7312
|
-
|
7313
|
-
|
7314
|
-
|
7315
|
-
|
7316
|
-
|
7317
|
-
|
7318
|
-
});
|
7319
|
-
});
|
7320
|
-
}
|
7321
|
-
return observableDefer(function () {
|
7322
|
-
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
7345
|
+
function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
7346
|
+
if (dueTime === period) {
|
7347
|
+
return new AnonymousObservable(function (observer) {
|
7348
|
+
return scheduler.schedulePeriodicWithState(0, period, function (count) {
|
7349
|
+
observer.onNext(count);
|
7350
|
+
return count + 1;
|
7323
7351
|
});
|
7352
|
+
});
|
7324
7353
|
}
|
7354
|
+
return observableDefer(function () {
|
7355
|
+
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
7356
|
+
});
|
7357
|
+
}
|
7325
7358
|
|
7326
|
-
|
7327
|
-
|
7328
|
-
|
7329
|
-
|
7330
|
-
|
7331
|
-
|
7332
|
-
|
7333
|
-
|
7334
|
-
|
7335
|
-
|
7336
|
-
|
7337
|
-
|
7338
|
-
|
7339
|
-
|
7340
|
-
};
|
7359
|
+
/**
|
7360
|
+
* Returns an observable sequence that produces a value after each period.
|
7361
|
+
*
|
7362
|
+
* @example
|
7363
|
+
* 1 - res = Rx.Observable.interval(1000);
|
7364
|
+
* 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout);
|
7365
|
+
*
|
7366
|
+
* @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
|
7367
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used.
|
7368
|
+
* @returns {Observable} An observable sequence that produces a value after each period.
|
7369
|
+
*/
|
7370
|
+
var observableinterval = Observable.interval = function (period, scheduler) {
|
7371
|
+
return observableTimerTimeSpanAndPeriod(period, period, isScheduler(scheduler) ? scheduler : timeoutScheduler);
|
7372
|
+
};
|
7341
7373
|
|
7342
|
-
|
7343
|
-
|
7344
|
-
|
7345
|
-
|
7346
|
-
|
7347
|
-
|
7348
|
-
|
7349
|
-
|
7350
|
-
|
7351
|
-
|
7352
|
-
|
7353
|
-
|
7354
|
-
|
7355
|
-
|
7356
|
-
|
7357
|
-
|
7358
|
-
|
7359
|
-
|
7360
|
-
|
7361
|
-
|
7362
|
-
|
7363
|
-
|
7364
|
-
|
7365
|
-
|
7366
|
-
|
7367
|
-
|
7368
|
-
|
7369
|
-
|
7370
|
-
|
7371
|
-
|
7372
|
-
|
7373
|
-
|
7374
|
-
|
7374
|
+
/**
|
7375
|
+
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
7376
|
+
*
|
7377
|
+
* @example
|
7378
|
+
* 1 - res = Rx.Observable.timer(new Date());
|
7379
|
+
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
7380
|
+
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
7381
|
+
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
7382
|
+
*
|
7383
|
+
* 5 - res = Rx.Observable.timer(5000);
|
7384
|
+
* 6 - res = Rx.Observable.timer(5000, 1000);
|
7385
|
+
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
7386
|
+
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
7387
|
+
*
|
7388
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value.
|
7389
|
+
* @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring.
|
7390
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
7391
|
+
* @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
|
7392
|
+
*/
|
7393
|
+
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
7394
|
+
var period;
|
7395
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7396
|
+
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
7397
|
+
period = periodOrScheduler;
|
7398
|
+
} else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
|
7399
|
+
scheduler = periodOrScheduler;
|
7400
|
+
}
|
7401
|
+
if (dueTime instanceof Date && notDefined(period)) {
|
7402
|
+
return observableTimerDate(dueTime.getTime(), scheduler);
|
7403
|
+
}
|
7404
|
+
if (dueTime instanceof Date && period !== undefined) {
|
7405
|
+
period = periodOrScheduler;
|
7406
|
+
return observableTimerDateAndPeriod(dueTime.getTime(), period, scheduler);
|
7407
|
+
}
|
7408
|
+
return notDefined(period) ?
|
7409
|
+
observableTimerTimeSpan(dueTime, scheduler) :
|
7410
|
+
observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
|
7411
|
+
};
|
7412
|
+
|
7413
|
+
function observableDelayTimeSpan(source, dueTime, scheduler) {
|
7414
|
+
return new AnonymousObservable(function (observer) {
|
7415
|
+
var active = false,
|
7416
|
+
cancelable = new SerialDisposable(),
|
7417
|
+
exception = null,
|
7418
|
+
q = [],
|
7419
|
+
running = false,
|
7420
|
+
subscription;
|
7421
|
+
subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
7422
|
+
var d, shouldRun;
|
7423
|
+
if (notification.value.kind === 'E') {
|
7424
|
+
q = [];
|
7425
|
+
q.push(notification);
|
7426
|
+
exception = notification.value.exception;
|
7427
|
+
shouldRun = !running;
|
7428
|
+
} else {
|
7429
|
+
q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
7430
|
+
shouldRun = !active;
|
7431
|
+
active = true;
|
7375
7432
|
}
|
7376
|
-
if (
|
7377
|
-
|
7433
|
+
if (shouldRun) {
|
7434
|
+
if (exception !== null) {
|
7435
|
+
observer.onError(exception);
|
7436
|
+
} else {
|
7437
|
+
d = new SingleAssignmentDisposable();
|
7438
|
+
cancelable.setDisposable(d);
|
7439
|
+
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
7440
|
+
var e, recurseDueTime, result, shouldRecurse;
|
7441
|
+
if (exception !== null) {
|
7442
|
+
return;
|
7443
|
+
}
|
7444
|
+
running = true;
|
7445
|
+
do {
|
7446
|
+
result = null;
|
7447
|
+
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
7448
|
+
result = q.shift().value;
|
7449
|
+
}
|
7450
|
+
if (result !== null) {
|
7451
|
+
result.accept(observer);
|
7452
|
+
}
|
7453
|
+
} while (result !== null);
|
7454
|
+
shouldRecurse = false;
|
7455
|
+
recurseDueTime = 0;
|
7456
|
+
if (q.length > 0) {
|
7457
|
+
shouldRecurse = true;
|
7458
|
+
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
7459
|
+
} else {
|
7460
|
+
active = false;
|
7461
|
+
}
|
7462
|
+
e = exception;
|
7463
|
+
running = false;
|
7464
|
+
if (e !== null) {
|
7465
|
+
observer.onError(e);
|
7466
|
+
} else if (shouldRecurse) {
|
7467
|
+
self(recurseDueTime);
|
7468
|
+
}
|
7469
|
+
}));
|
7470
|
+
}
|
7378
7471
|
}
|
7379
|
-
|
7380
|
-
|
7381
|
-
|
7382
|
-
|
7383
|
-
var source = this;
|
7384
|
-
return new AnonymousObservable(function (observer) {
|
7385
|
-
var active = false,
|
7386
|
-
cancelable = new SerialDisposable(),
|
7387
|
-
exception = null,
|
7388
|
-
q = [],
|
7389
|
-
running = false,
|
7390
|
-
subscription;
|
7391
|
-
subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
7392
|
-
var d, shouldRun;
|
7393
|
-
if (notification.value.kind === 'E') {
|
7394
|
-
q = [];
|
7395
|
-
q.push(notification);
|
7396
|
-
exception = notification.value.exception;
|
7397
|
-
shouldRun = !running;
|
7398
|
-
} else {
|
7399
|
-
q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
7400
|
-
shouldRun = !active;
|
7401
|
-
active = true;
|
7402
|
-
}
|
7403
|
-
if (shouldRun) {
|
7404
|
-
if (exception !== null) {
|
7405
|
-
observer.onError(exception);
|
7406
|
-
} else {
|
7407
|
-
d = new SingleAssignmentDisposable();
|
7408
|
-
cancelable.setDisposable(d);
|
7409
|
-
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
7410
|
-
var e, recurseDueTime, result, shouldRecurse;
|
7411
|
-
if (exception !== null) {
|
7412
|
-
return;
|
7413
|
-
}
|
7414
|
-
running = true;
|
7415
|
-
do {
|
7416
|
-
result = null;
|
7417
|
-
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
7418
|
-
result = q.shift().value;
|
7419
|
-
}
|
7420
|
-
if (result !== null) {
|
7421
|
-
result.accept(observer);
|
7422
|
-
}
|
7423
|
-
} while (result !== null);
|
7424
|
-
shouldRecurse = false;
|
7425
|
-
recurseDueTime = 0;
|
7426
|
-
if (q.length > 0) {
|
7427
|
-
shouldRecurse = true;
|
7428
|
-
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
7429
|
-
} else {
|
7430
|
-
active = false;
|
7431
|
-
}
|
7432
|
-
e = exception;
|
7433
|
-
running = false;
|
7434
|
-
if (e !== null) {
|
7435
|
-
observer.onError(e);
|
7436
|
-
} else if (shouldRecurse) {
|
7437
|
-
self(recurseDueTime);
|
7438
|
-
}
|
7439
|
-
}));
|
7440
|
-
}
|
7441
|
-
}
|
7442
|
-
});
|
7443
|
-
return new CompositeDisposable(subscription, cancelable);
|
7444
|
-
});
|
7445
|
-
}
|
7472
|
+
});
|
7473
|
+
return new CompositeDisposable(subscription, cancelable);
|
7474
|
+
});
|
7475
|
+
}
|
7446
7476
|
|
7447
|
-
|
7448
|
-
|
7449
|
-
|
7450
|
-
|
7451
|
-
|
7452
|
-
});
|
7453
|
-
}
|
7477
|
+
function observableDelayDate(source, dueTime, scheduler) {
|
7478
|
+
return observableDefer(function () {
|
7479
|
+
return observableDelayTimeSpan(source, dueTime - scheduler.now(), scheduler);
|
7480
|
+
});
|
7481
|
+
}
|
7454
7482
|
|
7455
|
-
|
7456
|
-
|
7457
|
-
|
7458
|
-
|
7459
|
-
|
7460
|
-
|
7461
|
-
|
7462
|
-
|
7463
|
-
|
7464
|
-
|
7465
|
-
|
7466
|
-
|
7467
|
-
|
7468
|
-
|
7469
|
-
|
7470
|
-
|
7471
|
-
|
7472
|
-
|
7473
|
-
|
7474
|
-
|
7483
|
+
/**
|
7484
|
+
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
7485
|
+
*
|
7486
|
+
* @example
|
7487
|
+
* 1 - res = Rx.Observable.delay(new Date());
|
7488
|
+
* 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout);
|
7489
|
+
*
|
7490
|
+
* 3 - res = Rx.Observable.delay(5000);
|
7491
|
+
* 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
7492
|
+
* @memberOf Observable#
|
7493
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence.
|
7494
|
+
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
7495
|
+
* @returns {Observable} Time-shifted sequence.
|
7496
|
+
*/
|
7497
|
+
observableProto.delay = function (dueTime, scheduler) {
|
7498
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7499
|
+
return dueTime instanceof Date ?
|
7500
|
+
observableDelayDate(this, dueTime.getTime(), scheduler) :
|
7501
|
+
observableDelayTimeSpan(this, dueTime, scheduler);
|
7502
|
+
};
|
7475
7503
|
|
7476
|
-
|
7477
|
-
|
7478
|
-
|
7479
|
-
|
7480
|
-
|
7481
|
-
|
7482
|
-
|
7483
|
-
|
7484
|
-
|
7485
|
-
|
7486
|
-
|
7487
|
-
|
7488
|
-
|
7489
|
-
|
7490
|
-
|
7491
|
-
};
|
7504
|
+
/**
|
7505
|
+
* Ignores values from an observable sequence which are followed by another value before dueTime.
|
7506
|
+
*
|
7507
|
+
* @example
|
7508
|
+
* 1 - res = source.throttle(5000); // 5 seconds
|
7509
|
+
* 2 - res = source.throttle(5000, scheduler);
|
7510
|
+
*
|
7511
|
+
* @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
|
7512
|
+
* @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
|
7513
|
+
* @returns {Observable} The throttled sequence.
|
7514
|
+
*/
|
7515
|
+
observableProto.throttle = function (dueTime, scheduler) {
|
7516
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7517
|
+
return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
|
7518
|
+
};
|
7492
7519
|
|
7493
|
-
|
7494
|
-
|
7495
|
-
|
7496
|
-
|
7497
|
-
|
7498
|
-
|
7499
|
-
|
7500
|
-
|
7501
|
-
|
7502
|
-
|
7503
|
-
|
7504
|
-
|
7505
|
-
|
7506
|
-
|
7507
|
-
|
7508
|
-
|
7520
|
+
/**
|
7521
|
+
* Projects each element of an observable sequence into zero or more windows which are produced based on timing information.
|
7522
|
+
*
|
7523
|
+
* @example
|
7524
|
+
* 1 - res = xs.windowWithTime(1000, scheduler); // non-overlapping segments of 1 second
|
7525
|
+
* 2 - res = xs.windowWithTime(1000, 500 , scheduler); // segments of 1 second with time shift 0.5 seconds
|
7526
|
+
*
|
7527
|
+
* @param {Number} timeSpan Length of each window (specified as an integer denoting milliseconds).
|
7528
|
+
* @param {Mixed} [timeShiftOrScheduler] Interval between creation of consecutive windows (specified as an integer denoting milliseconds), or an optional scheduler parameter. If not specified, the time shift corresponds to the timeSpan parameter, resulting in non-overlapping adjacent windows.
|
7529
|
+
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
7530
|
+
* @returns {Observable} An observable sequence of windows.
|
7531
|
+
*/
|
7532
|
+
observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
7533
|
+
var source = this, timeShift;
|
7534
|
+
|
7535
|
+
notDefined(timeShiftOrScheduler) && (timeShift = timeSpan);
|
7536
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7537
|
+
if (typeof timeShiftOrScheduler === 'number') {
|
7538
|
+
timeShift = timeShiftOrScheduler;
|
7539
|
+
} else if (typeof timeShiftOrScheduler === 'object') {
|
7540
|
+
timeShift = timeSpan;
|
7541
|
+
scheduler = timeShiftOrScheduler;
|
7542
|
+
}
|
7543
|
+
return new AnonymousObservable(function (observer) {
|
7544
|
+
var groupDisposable,
|
7545
|
+
nextShift = timeShift,
|
7546
|
+
nextSpan = timeSpan,
|
7547
|
+
q = [],
|
7548
|
+
refCountDisposable,
|
7549
|
+
timerD = new SerialDisposable(),
|
7550
|
+
totalTime = 0;
|
7551
|
+
groupDisposable = new CompositeDisposable(timerD),
|
7552
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7553
|
+
|
7554
|
+
|
7555
|
+
q.push(new Subject());
|
7556
|
+
observer.onNext(addRef(q[0], refCountDisposable));
|
7557
|
+
createTimer();
|
7558
|
+
groupDisposable.add(source.subscribe(function (x) {
|
7559
|
+
var i, len;
|
7560
|
+
for (i = 0, len = q.length; i < len; i++) {
|
7561
|
+
q[i].onNext(x);
|
7509
7562
|
}
|
7510
|
-
|
7511
|
-
|
7563
|
+
}, function (e) {
|
7564
|
+
var i, len;
|
7565
|
+
for (i = 0, len = q.length; i < len; i++) {
|
7566
|
+
q[i].onError(e);
|
7512
7567
|
}
|
7513
|
-
|
7514
|
-
|
7515
|
-
|
7516
|
-
|
7517
|
-
|
7568
|
+
observer.onError(e);
|
7569
|
+
}, function () {
|
7570
|
+
var i, len;
|
7571
|
+
for (i = 0, len = q.length; i < len; i++) {
|
7572
|
+
q[i].onCompleted();
|
7518
7573
|
}
|
7519
|
-
|
7520
|
-
|
7521
|
-
nextShift = timeShift,
|
7522
|
-
nextSpan = timeSpan,
|
7523
|
-
q = [],
|
7524
|
-
refCountDisposable,
|
7525
|
-
timerD = new SerialDisposable(),
|
7526
|
-
totalTime = 0;
|
7527
|
-
groupDisposable = new CompositeDisposable(timerD),
|
7528
|
-
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7574
|
+
observer.onCompleted();
|
7575
|
+
}));
|
7529
7576
|
|
7530
|
-
|
7531
|
-
var m = new SingleAssignmentDisposable(),
|
7532
|
-
isSpan = false,
|
7533
|
-
isShift = false;
|
7534
|
-
timerD.setDisposable(m);
|
7535
|
-
if (nextSpan === nextShift) {
|
7536
|
-
isSpan = true;
|
7537
|
-
isShift = true;
|
7538
|
-
} else if (nextSpan < nextShift) {
|
7539
|
-
isSpan = true;
|
7540
|
-
} else {
|
7541
|
-
isShift = true;
|
7542
|
-
}
|
7543
|
-
var newTotalTime = isSpan ? nextSpan : nextShift,
|
7544
|
-
ts = newTotalTime - totalTime;
|
7545
|
-
totalTime = newTotalTime;
|
7546
|
-
if (isSpan) {
|
7547
|
-
nextSpan += timeShift;
|
7548
|
-
}
|
7549
|
-
if (isShift) {
|
7550
|
-
nextShift += timeShift;
|
7551
|
-
}
|
7552
|
-
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
7553
|
-
var s;
|
7554
|
-
if (isShift) {
|
7555
|
-
s = new Subject();
|
7556
|
-
q.push(s);
|
7557
|
-
observer.onNext(addRef(s, refCountDisposable));
|
7558
|
-
}
|
7559
|
-
if (isSpan) {
|
7560
|
-
s = q.shift();
|
7561
|
-
s.onCompleted();
|
7562
|
-
}
|
7563
|
-
createTimer();
|
7564
|
-
}));
|
7565
|
-
};
|
7566
|
-
q.push(new Subject());
|
7567
|
-
observer.onNext(addRef(q[0], refCountDisposable));
|
7568
|
-
createTimer();
|
7569
|
-
groupDisposable.add(source.subscribe(function (x) {
|
7570
|
-
var i, s;
|
7571
|
-
for (i = 0; i < q.length; i++) {
|
7572
|
-
s = q[i];
|
7573
|
-
s.onNext(x);
|
7574
|
-
}
|
7575
|
-
}, function (e) {
|
7576
|
-
var i, s;
|
7577
|
-
for (i = 0; i < q.length; i++) {
|
7578
|
-
s = q[i];
|
7579
|
-
s.onError(e);
|
7580
|
-
}
|
7581
|
-
observer.onError(e);
|
7582
|
-
}, function () {
|
7583
|
-
var i, s;
|
7584
|
-
for (i = 0; i < q.length; i++) {
|
7585
|
-
s = q[i];
|
7586
|
-
s.onCompleted();
|
7587
|
-
}
|
7588
|
-
observer.onCompleted();
|
7589
|
-
}));
|
7590
|
-
return refCountDisposable;
|
7591
|
-
});
|
7592
|
-
};
|
7577
|
+
return refCountDisposable;
|
7593
7578
|
|
7594
|
-
|
7595
|
-
|
7596
|
-
|
7597
|
-
|
7598
|
-
|
7599
|
-
|
7600
|
-
|
7601
|
-
|
7602
|
-
|
7603
|
-
|
7604
|
-
|
7605
|
-
|
7606
|
-
|
7607
|
-
var
|
7608
|
-
|
7609
|
-
|
7610
|
-
|
7611
|
-
|
7612
|
-
|
7613
|
-
|
7614
|
-
|
7615
|
-
|
7616
|
-
windowId = 0;
|
7617
|
-
groupDisposable = new CompositeDisposable(timerD);
|
7618
|
-
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7619
|
-
createTimer = function (id) {
|
7620
|
-
var m = new SingleAssignmentDisposable();
|
7621
|
-
timerD.setDisposable(m);
|
7622
|
-
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
7623
|
-
var newId;
|
7624
|
-
if (id !== windowId) {
|
7625
|
-
return;
|
7626
|
-
}
|
7627
|
-
n = 0;
|
7628
|
-
newId = ++windowId;
|
7629
|
-
s.onCompleted();
|
7630
|
-
s = new Subject();
|
7631
|
-
observer.onNext(addRef(s, refCountDisposable));
|
7632
|
-
createTimer(newId);
|
7633
|
-
}));
|
7634
|
-
};
|
7579
|
+
function createTimer () {
|
7580
|
+
var m = new SingleAssignmentDisposable(), isSpan = false, isShift = false;
|
7581
|
+
timerD.setDisposable(m);
|
7582
|
+
|
7583
|
+
if (nextSpan === nextShift) {
|
7584
|
+
isSpan = true;
|
7585
|
+
isShift = true;
|
7586
|
+
} else if (nextSpan < nextShift) {
|
7587
|
+
isSpan = true;
|
7588
|
+
} else {
|
7589
|
+
isShift = true;
|
7590
|
+
}
|
7591
|
+
|
7592
|
+
var newTotalTime = isSpan ? nextSpan : nextShift,
|
7593
|
+
ts = newTotalTime - totalTime;
|
7594
|
+
totalTime = newTotalTime;
|
7595
|
+
isSpan && (nextSpan += timeShift);
|
7596
|
+
isShift && (nextShift += timeShift);
|
7597
|
+
|
7598
|
+
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
7599
|
+
var s;
|
7600
|
+
if (isShift) {
|
7635
7601
|
s = new Subject();
|
7602
|
+
q.push(s);
|
7636
7603
|
observer.onNext(addRef(s, refCountDisposable));
|
7637
|
-
|
7638
|
-
|
7639
|
-
|
7640
|
-
|
7641
|
-
|
7642
|
-
|
7643
|
-
|
7644
|
-
|
7645
|
-
|
7646
|
-
|
7647
|
-
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7651
|
-
|
7652
|
-
|
7653
|
-
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7657
|
-
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7604
|
+
}
|
7605
|
+
if (isSpan) {
|
7606
|
+
s = q.shift();
|
7607
|
+
s.onCompleted();
|
7608
|
+
}
|
7609
|
+
createTimer();
|
7610
|
+
}));
|
7611
|
+
}
|
7612
|
+
});
|
7613
|
+
};
|
7614
|
+
|
7615
|
+
/**
|
7616
|
+
* Projects each element of an observable sequence into a window that is completed when either it's full or a given amount of time has elapsed.
|
7617
|
+
* @example
|
7618
|
+
* 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
|
7619
|
+
* 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
|
7620
|
+
*
|
7621
|
+
* @memberOf Observable#
|
7622
|
+
* @param {Number} timeSpan Maximum time length of a window.
|
7623
|
+
* @param {Number} count Maximum element count of a window.
|
7624
|
+
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
7625
|
+
* @returns {Observable} An observable sequence of windows.
|
7626
|
+
*/
|
7627
|
+
observableProto.windowWithTimeOrCount = function (timeSpan, count, scheduler) {
|
7628
|
+
var source = this;
|
7629
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7630
|
+
return new AnonymousObservable(function (observer) {
|
7631
|
+
var createTimer,
|
7632
|
+
groupDisposable,
|
7633
|
+
n = 0,
|
7634
|
+
refCountDisposable,
|
7635
|
+
s = new Subject()
|
7636
|
+
timerD = new SerialDisposable(),
|
7637
|
+
windowId = 0;
|
7638
|
+
groupDisposable = new CompositeDisposable(timerD);
|
7639
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7640
|
+
|
7641
|
+
observer.onNext(addRef(s, refCountDisposable));
|
7642
|
+
createTimer(0);
|
7643
|
+
groupDisposable.add(source.subscribe(function (x) {
|
7644
|
+
var newId = 0, newWindow = false;
|
7645
|
+
s.onNext(x);
|
7646
|
+
n++;
|
7647
|
+
if (n === count) {
|
7648
|
+
newWindow = true;
|
7649
|
+
n = 0;
|
7650
|
+
newId = ++windowId;
|
7651
|
+
s.onCompleted();
|
7652
|
+
s = new Subject();
|
7653
|
+
observer.onNext(addRef(s, refCountDisposable));
|
7654
|
+
}
|
7655
|
+
newWindow && createTimer(newId);
|
7656
|
+
}, function (e) {
|
7657
|
+
s.onError(e);
|
7658
|
+
observer.onError(e);
|
7659
|
+
}, function () {
|
7660
|
+
s.onCompleted();
|
7661
|
+
observer.onCompleted();
|
7662
|
+
}));
|
7663
|
+
|
7664
|
+
return refCountDisposable;
|
7665
|
+
|
7666
|
+
function createTimer(id) {
|
7667
|
+
var m = new SingleAssignmentDisposable();
|
7668
|
+
timerD.setDisposable(m);
|
7669
|
+
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
7670
|
+
var newId;
|
7671
|
+
if (id !== windowId) { return; }
|
7672
|
+
n = 0;
|
7673
|
+
newId = ++windowId;
|
7674
|
+
s.onCompleted();
|
7675
|
+
s = new Subject();
|
7676
|
+
observer.onNext(addRef(s, refCountDisposable));
|
7677
|
+
createTimer(newId);
|
7678
|
+
}));
|
7679
|
+
}
|
7680
|
+
});
|
7681
|
+
};
|
7663
7682
|
|
7664
7683
|
/**
|
7665
7684
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
|
@@ -7695,98 +7714,89 @@
|
|
7695
7714
|
});
|
7696
7715
|
};
|
7697
7716
|
|
7698
|
-
|
7699
|
-
|
7700
|
-
|
7701
|
-
|
7702
|
-
|
7703
|
-
|
7704
|
-
|
7705
|
-
|
7706
|
-
|
7707
|
-
|
7708
|
-
|
7709
|
-
|
7710
|
-
|
7711
|
-
|
7712
|
-
|
7713
|
-
|
7714
|
-
|
7715
|
-
|
7716
|
-
|
7717
|
-
|
7718
|
-
|
7719
|
-
|
7720
|
-
});
|
7721
|
-
});
|
7722
|
-
};
|
7717
|
+
/**
|
7718
|
+
* Records the time interval between consecutive values in an observable sequence.
|
7719
|
+
*
|
7720
|
+
* @example
|
7721
|
+
* 1 - res = source.timeInterval();
|
7722
|
+
* 2 - res = source.timeInterval(Rx.Scheduler.timeout);
|
7723
|
+
*
|
7724
|
+
* @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
|
7725
|
+
* @returns {Observable} An observable sequence with time interval information on values.
|
7726
|
+
*/
|
7727
|
+
observableProto.timeInterval = function (scheduler) {
|
7728
|
+
var source = this;
|
7729
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7730
|
+
return observableDefer(function () {
|
7731
|
+
var last = scheduler.now();
|
7732
|
+
return source.map(function (x) {
|
7733
|
+
var now = scheduler.now(), span = now - last;
|
7734
|
+
last = now;
|
7735
|
+
return { value: x, interval: span };
|
7736
|
+
});
|
7737
|
+
});
|
7738
|
+
};
|
7723
7739
|
|
7724
|
-
|
7725
|
-
|
7726
|
-
|
7727
|
-
|
7728
|
-
|
7729
|
-
|
7730
|
-
|
7731
|
-
|
7732
|
-
|
7733
|
-
|
7734
|
-
|
7735
|
-
|
7736
|
-
|
7737
|
-
|
7738
|
-
|
7739
|
-
|
7740
|
-
};
|
7741
|
-
});
|
7742
|
-
};
|
7740
|
+
/**
|
7741
|
+
* Records the timestamp for each value in an observable sequence.
|
7742
|
+
*
|
7743
|
+
* @example
|
7744
|
+
* 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
|
7745
|
+
* 2 - res = source.timestamp(Rx.Scheduler.timeout);
|
7746
|
+
*
|
7747
|
+
* @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
|
7748
|
+
* @returns {Observable} An observable sequence with timestamp information on values.
|
7749
|
+
*/
|
7750
|
+
observableProto.timestamp = function (scheduler) {
|
7751
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7752
|
+
return this.map(function (x) {
|
7753
|
+
return { value: x, timestamp: scheduler.now() };
|
7754
|
+
});
|
7755
|
+
};
|
7743
7756
|
|
7744
|
-
|
7745
|
-
|
7746
|
-
|
7747
|
-
|
7757
|
+
function sampleObservable(source, sampler) {
|
7758
|
+
|
7759
|
+
return new AnonymousObservable(function (observer) {
|
7760
|
+
var atEnd, value, hasValue;
|
7748
7761
|
|
7749
|
-
|
7750
|
-
|
7751
|
-
|
7752
|
-
|
7753
|
-
|
7754
|
-
|
7755
|
-
|
7756
|
-
}
|
7757
|
-
}
|
7762
|
+
function sampleSubscribe() {
|
7763
|
+
if (hasValue) {
|
7764
|
+
hasValue = false;
|
7765
|
+
observer.onNext(value);
|
7766
|
+
}
|
7767
|
+
atEnd && observer.onCompleted();
|
7768
|
+
}
|
7758
7769
|
|
7759
|
-
|
7760
|
-
|
7761
|
-
|
7762
|
-
|
7763
|
-
|
7764
|
-
|
7765
|
-
|
7766
|
-
|
7767
|
-
|
7768
|
-
|
7769
|
-
|
7770
|
+
return new CompositeDisposable(
|
7771
|
+
source.subscribe(function (newValue) {
|
7772
|
+
hasValue = true;
|
7773
|
+
value = newValue;
|
7774
|
+
}, observer.onError.bind(observer), function () {
|
7775
|
+
atEnd = true;
|
7776
|
+
}),
|
7777
|
+
sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
|
7778
|
+
);
|
7779
|
+
});
|
7780
|
+
}
|
7770
7781
|
|
7771
|
-
|
7772
|
-
|
7773
|
-
|
7774
|
-
|
7775
|
-
|
7776
|
-
|
7777
|
-
|
7778
|
-
|
7779
|
-
|
7780
|
-
|
7781
|
-
|
7782
|
-
|
7783
|
-
|
7784
|
-
|
7785
|
-
|
7786
|
-
|
7787
|
-
|
7788
|
-
|
7789
|
-
};
|
7782
|
+
/**
|
7783
|
+
* Samples the observable sequence at each interval.
|
7784
|
+
*
|
7785
|
+
* @example
|
7786
|
+
* 1 - res = source.sample(sampleObservable); // Sampler tick sequence
|
7787
|
+
* 2 - res = source.sample(5000); // 5 seconds
|
7788
|
+
* 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds
|
7789
|
+
*
|
7790
|
+
* @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable.
|
7791
|
+
* @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
|
7792
|
+
* @returns {Observable} Sampled observable sequence.
|
7793
|
+
*/
|
7794
|
+
observableProto.sample = function (intervalOrSampler, scheduler) {
|
7795
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7796
|
+
return typeof intervalOrSampler === 'number' ?
|
7797
|
+
sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
|
7798
|
+
sampleObservable(this, intervalOrSampler);
|
7799
|
+
};
|
7790
7800
|
|
7791
7801
|
/**
|
7792
7802
|
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
@@ -7806,7 +7816,7 @@
|
|
7806
7816
|
*/
|
7807
7817
|
observableProto.timeout = function (dueTime, other, scheduler) {
|
7808
7818
|
other || (other = observableThrow(new Error('Timeout')));
|
7809
|
-
scheduler || (scheduler = timeoutScheduler);
|
7819
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7810
7820
|
|
7811
7821
|
var source = this, schedulerMethod = dueTime instanceof Date ?
|
7812
7822
|
'scheduleWithAbsolute' :
|
@@ -7854,131 +7864,128 @@
|
|
7854
7864
|
});
|
7855
7865
|
};
|
7856
7866
|
|
7857
|
-
|
7858
|
-
|
7859
|
-
|
7860
|
-
|
7861
|
-
|
7862
|
-
|
7863
|
-
|
7864
|
-
|
7865
|
-
|
7866
|
-
|
7867
|
-
|
7868
|
-
|
7869
|
-
|
7870
|
-
|
7871
|
-
|
7872
|
-
|
7873
|
-
|
7874
|
-
|
7875
|
-
|
7876
|
-
|
7877
|
-
|
7878
|
-
|
7879
|
-
|
7880
|
-
|
7881
|
-
|
7882
|
-
|
7883
|
-
|
7884
|
-
|
7885
|
-
|
7886
|
-
|
7887
|
-
|
7888
|
-
|
7889
|
-
|
7890
|
-
|
7891
|
-
|
7892
|
-
|
7893
|
-
|
7894
|
-
|
7895
|
-
|
7896
|
-
|
7897
|
-
|
7898
|
-
|
7899
|
-
|
7900
|
-
|
7901
|
-
|
7902
|
-
|
7903
|
-
|
7904
|
-
|
7905
|
-
|
7906
|
-
|
7907
|
-
|
7908
|
-
|
7909
|
-
|
7910
|
-
};
|
7867
|
+
/**
|
7868
|
+
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
7869
|
+
*
|
7870
|
+
* @example
|
7871
|
+
* res = source.generateWithAbsoluteTime(0,
|
7872
|
+
* function (x) { return return true; },
|
7873
|
+
* function (x) { return x + 1; },
|
7874
|
+
* function (x) { return x; },
|
7875
|
+
* function (x) { return new Date(); }
|
7876
|
+
* });
|
7877
|
+
*
|
7878
|
+
* @param {Mixed} initialState Initial state.
|
7879
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
7880
|
+
* @param {Function} iterate Iteration step function.
|
7881
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
7882
|
+
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning Date values.
|
7883
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
7884
|
+
* @returns {Observable} The generated sequence.
|
7885
|
+
*/
|
7886
|
+
Observable.generateWithAbsoluteTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
7887
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7888
|
+
return new AnonymousObservable(function (observer) {
|
7889
|
+
var first = true,
|
7890
|
+
hasResult = false,
|
7891
|
+
result,
|
7892
|
+
state = initialState,
|
7893
|
+
time;
|
7894
|
+
return scheduler.scheduleRecursiveWithAbsolute(scheduler.now(), function (self) {
|
7895
|
+
hasResult && observer.onNext(result);
|
7896
|
+
|
7897
|
+
try {
|
7898
|
+
if (first) {
|
7899
|
+
first = false;
|
7900
|
+
} else {
|
7901
|
+
state = iterate(state);
|
7902
|
+
}
|
7903
|
+
hasResult = condition(state);
|
7904
|
+
if (hasResult) {
|
7905
|
+
result = resultSelector(state);
|
7906
|
+
time = timeSelector(state);
|
7907
|
+
}
|
7908
|
+
} catch (e) {
|
7909
|
+
observer.onError(e);
|
7910
|
+
return;
|
7911
|
+
}
|
7912
|
+
if (hasResult) {
|
7913
|
+
self(time);
|
7914
|
+
} else {
|
7915
|
+
observer.onCompleted();
|
7916
|
+
}
|
7917
|
+
});
|
7918
|
+
});
|
7919
|
+
};
|
7911
7920
|
|
7912
|
-
|
7913
|
-
|
7914
|
-
|
7915
|
-
|
7916
|
-
|
7917
|
-
|
7918
|
-
|
7919
|
-
|
7920
|
-
|
7921
|
-
|
7922
|
-
|
7923
|
-
|
7924
|
-
|
7925
|
-
|
7926
|
-
|
7927
|
-
|
7928
|
-
|
7929
|
-
|
7930
|
-
|
7931
|
-
|
7932
|
-
|
7933
|
-
|
7934
|
-
|
7935
|
-
|
7936
|
-
|
7937
|
-
|
7938
|
-
|
7939
|
-
|
7940
|
-
|
7941
|
-
|
7942
|
-
|
7943
|
-
|
7944
|
-
|
7945
|
-
|
7946
|
-
|
7947
|
-
|
7948
|
-
|
7949
|
-
|
7950
|
-
|
7951
|
-
|
7952
|
-
|
7953
|
-
|
7954
|
-
|
7955
|
-
|
7956
|
-
|
7957
|
-
|
7958
|
-
|
7959
|
-
|
7960
|
-
|
7961
|
-
|
7962
|
-
|
7963
|
-
|
7964
|
-
|
7965
|
-
};
|
7921
|
+
/**
|
7922
|
+
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
7923
|
+
*
|
7924
|
+
* @example
|
7925
|
+
* res = source.generateWithRelativeTime(0,
|
7926
|
+
* function (x) { return return true; },
|
7927
|
+
* function (x) { return x + 1; },
|
7928
|
+
* function (x) { return x; },
|
7929
|
+
* function (x) { return 500; }
|
7930
|
+
* );
|
7931
|
+
*
|
7932
|
+
* @param {Mixed} initialState Initial state.
|
7933
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
7934
|
+
* @param {Function} iterate Iteration step function.
|
7935
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
7936
|
+
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning integer values denoting milliseconds.
|
7937
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
7938
|
+
* @returns {Observable} The generated sequence.
|
7939
|
+
*/
|
7940
|
+
Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
7941
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7942
|
+
return new AnonymousObservable(function (observer) {
|
7943
|
+
var first = true,
|
7944
|
+
hasResult = false,
|
7945
|
+
result,
|
7946
|
+
state = initialState,
|
7947
|
+
time;
|
7948
|
+
return scheduler.scheduleRecursiveWithRelative(0, function (self) {
|
7949
|
+
hasResult && observer.onNext(result);
|
7950
|
+
|
7951
|
+
try {
|
7952
|
+
if (first) {
|
7953
|
+
first = false;
|
7954
|
+
} else {
|
7955
|
+
state = iterate(state);
|
7956
|
+
}
|
7957
|
+
hasResult = condition(state);
|
7958
|
+
if (hasResult) {
|
7959
|
+
result = resultSelector(state);
|
7960
|
+
time = timeSelector(state);
|
7961
|
+
}
|
7962
|
+
} catch (e) {
|
7963
|
+
observer.onError(e);
|
7964
|
+
return;
|
7965
|
+
}
|
7966
|
+
if (hasResult) {
|
7967
|
+
self(time);
|
7968
|
+
} else {
|
7969
|
+
observer.onCompleted();
|
7970
|
+
}
|
7971
|
+
});
|
7972
|
+
});
|
7973
|
+
};
|
7966
7974
|
|
7967
|
-
|
7968
|
-
|
7969
|
-
|
7970
|
-
|
7971
|
-
|
7972
|
-
|
7973
|
-
|
7974
|
-
|
7975
|
-
|
7976
|
-
|
7977
|
-
|
7978
|
-
|
7979
|
-
|
7980
|
-
|
7981
|
-
};
|
7975
|
+
/**
|
7976
|
+
* Time shifts the observable sequence by delaying the subscription.
|
7977
|
+
*
|
7978
|
+
* @example
|
7979
|
+
* 1 - res = source.delaySubscription(5000); // 5s
|
7980
|
+
* 2 - res = source.delaySubscription(5000, Rx.Scheduler.timeout); // 5 seconds
|
7981
|
+
*
|
7982
|
+
* @param {Number} dueTime Absolute or relative time to perform the subscription at.
|
7983
|
+
* @param {Scheduler} [scheduler] Scheduler to run the subscription delay timer on. If not specified, the timeout scheduler is used.
|
7984
|
+
* @returns {Observable} Time-shifted sequence.
|
7985
|
+
*/
|
7986
|
+
observableProto.delaySubscription = function (dueTime, scheduler) {
|
7987
|
+
return this.delayWithSelector(observableTimer(dueTime, isScheduler(scheduler) ? scheduler : timeoutScheduler), observableEmpty);
|
7988
|
+
};
|
7982
7989
|
|
7983
7990
|
/**
|
7984
7991
|
* Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
|
@@ -8124,96 +8131,96 @@
|
|
8124
8131
|
});
|
8125
8132
|
};
|
8126
8133
|
|
8127
|
-
|
8128
|
-
|
8129
|
-
|
8130
|
-
|
8131
|
-
|
8132
|
-
|
8133
|
-
|
8134
|
-
|
8135
|
-
|
8136
|
-
|
8137
|
-
|
8138
|
-
|
8139
|
-
|
8140
|
-
|
8141
|
-
|
8142
|
-
|
8143
|
-
|
8144
|
-
|
8145
|
-
|
8146
|
-
|
8147
|
-
|
8148
|
-
|
8149
|
-
|
8150
|
-
|
8151
|
-
|
8152
|
-
|
8153
|
-
|
8154
|
-
|
8155
|
-
|
8156
|
-
|
8157
|
-
|
8158
|
-
|
8159
|
-
|
8160
|
-
|
8161
|
-
|
8162
|
-
|
8163
|
-
|
8164
|
-
|
8165
|
-
|
8166
|
-
|
8167
|
-
|
8168
|
-
|
8169
|
-
|
8170
|
-
|
8171
|
-
|
8172
|
-
|
8173
|
-
|
8174
|
-
|
8175
|
-
|
8176
|
-
|
8177
|
-
|
8178
|
-
|
8179
|
-
|
8180
|
-
|
8181
|
-
|
8134
|
+
/**
|
8135
|
+
* Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
|
8136
|
+
*
|
8137
|
+
* @example
|
8138
|
+
* 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
|
8139
|
+
*
|
8140
|
+
* @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
|
8141
|
+
* @returns {Observable} The throttled sequence.
|
8142
|
+
*/
|
8143
|
+
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
8144
|
+
var source = this;
|
8145
|
+
return new AnonymousObservable(function (observer) {
|
8146
|
+
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
|
8147
|
+
var throttle;
|
8148
|
+
try {
|
8149
|
+
throttle = throttleDurationSelector(x);
|
8150
|
+
} catch (e) {
|
8151
|
+
observer.onError(e);
|
8152
|
+
return;
|
8153
|
+
}
|
8154
|
+
hasValue = true;
|
8155
|
+
value = x;
|
8156
|
+
id++;
|
8157
|
+
var currentid = id, d = new SingleAssignmentDisposable();
|
8158
|
+
cancelable.setDisposable(d);
|
8159
|
+
d.setDisposable(throttle.subscribe(function () {
|
8160
|
+
if (hasValue && id === currentid) {
|
8161
|
+
observer.onNext(value);
|
8162
|
+
}
|
8163
|
+
hasValue = false;
|
8164
|
+
d.dispose();
|
8165
|
+
}, observer.onError.bind(observer), function () {
|
8166
|
+
if (hasValue && id === currentid) {
|
8167
|
+
observer.onNext(value);
|
8168
|
+
}
|
8169
|
+
hasValue = false;
|
8170
|
+
d.dispose();
|
8171
|
+
}));
|
8172
|
+
}, function (e) {
|
8173
|
+
cancelable.dispose();
|
8174
|
+
observer.onError(e);
|
8175
|
+
hasValue = false;
|
8176
|
+
id++;
|
8177
|
+
}, function () {
|
8178
|
+
cancelable.dispose();
|
8179
|
+
if (hasValue) {
|
8180
|
+
observer.onNext(value);
|
8181
|
+
}
|
8182
|
+
observer.onCompleted();
|
8183
|
+
hasValue = false;
|
8184
|
+
id++;
|
8185
|
+
});
|
8186
|
+
return new CompositeDisposable(subscription, cancelable);
|
8187
|
+
});
|
8188
|
+
};
|
8182
8189
|
|
8183
|
-
|
8184
|
-
|
8185
|
-
|
8186
|
-
|
8187
|
-
|
8188
|
-
|
8189
|
-
|
8190
|
-
|
8191
|
-
|
8192
|
-
|
8193
|
-
|
8194
|
-
|
8195
|
-
|
8196
|
-
|
8197
|
-
|
8198
|
-
|
8199
|
-
|
8200
|
-
|
8201
|
-
|
8202
|
-
|
8203
|
-
|
8204
|
-
|
8205
|
-
|
8206
|
-
|
8207
|
-
|
8208
|
-
|
8209
|
-
|
8210
|
-
|
8211
|
-
|
8212
|
-
|
8213
|
-
|
8214
|
-
|
8215
|
-
|
8216
|
-
|
8190
|
+
/**
|
8191
|
+
* Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
8192
|
+
*
|
8193
|
+
* 1 - res = source.skipLastWithTime(5000);
|
8194
|
+
* 2 - res = source.skipLastWithTime(5000, scheduler);
|
8195
|
+
*
|
8196
|
+
* @description
|
8197
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8198
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
8199
|
+
* result sequence. This causes elements to be delayed with duration.
|
8200
|
+
* @param {Number} duration Duration for skipping elements from the end of the sequence.
|
8201
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout
|
8202
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the end of the source sequence.
|
8203
|
+
*/
|
8204
|
+
observableProto.skipLastWithTime = function (duration, scheduler) {
|
8205
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8206
|
+
var source = this;
|
8207
|
+
return new AnonymousObservable(function (observer) {
|
8208
|
+
var q = [];
|
8209
|
+
return source.subscribe(function (x) {
|
8210
|
+
var now = scheduler.now();
|
8211
|
+
q.push({ interval: now, value: x });
|
8212
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
8213
|
+
observer.onNext(q.shift().value);
|
8214
|
+
}
|
8215
|
+
}, observer.onError.bind(observer), function () {
|
8216
|
+
var now = scheduler.now();
|
8217
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
8218
|
+
observer.onNext(q.shift().value);
|
8219
|
+
}
|
8220
|
+
observer.onCompleted();
|
8221
|
+
});
|
8222
|
+
});
|
8223
|
+
};
|
8217
8224
|
|
8218
8225
|
/**
|
8219
8226
|
* Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
|
@@ -8233,102 +8240,93 @@
|
|
8233
8240
|
return this.takeLastBufferWithTime(duration, timerScheduler).selectMany(function (xs) { return observableFromArray(xs, loopScheduler); });
|
8234
8241
|
};
|
8235
8242
|
|
8236
|
-
|
8237
|
-
|
8238
|
-
|
8239
|
-
|
8240
|
-
|
8241
|
-
|
8242
|
-
|
8243
|
-
|
8244
|
-
|
8245
|
-
|
8246
|
-
|
8247
|
-
|
8248
|
-
|
8249
|
-
|
8250
|
-
|
8251
|
-
|
8252
|
-
|
8253
|
-
|
8254
|
-
|
8255
|
-
return source.subscribe(function (x) {
|
8256
|
-
var now = scheduler.now();
|
8257
|
-
q.push({ interval: now, value: x });
|
8258
|
-
while (q.length > 0 && now - q[0].interval >= duration) {
|
8259
|
-
q.shift();
|
8260
|
-
}
|
8261
|
-
}, observer.onError.bind(observer), function () {
|
8262
|
-
var now = scheduler.now(), res = [];
|
8263
|
-
while (q.length > 0) {
|
8264
|
-
var next = q.shift();
|
8265
|
-
if (now - next.interval <= duration) {
|
8266
|
-
res.push(next.value);
|
8267
|
-
}
|
8268
|
-
}
|
8269
|
-
|
8270
|
-
observer.onNext(res);
|
8271
|
-
observer.onCompleted();
|
8272
|
-
});
|
8273
|
-
});
|
8274
|
-
};
|
8243
|
+
/**
|
8244
|
+
* Returns an array with the elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
8245
|
+
*
|
8246
|
+
* @example
|
8247
|
+
* 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
|
8248
|
+
* @description
|
8249
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8250
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
8251
|
+
* result sequence. This causes elements to be delayed with duration.
|
8252
|
+
* @param {Number} duration Duration for taking elements from the end of the sequence.
|
8253
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8254
|
+
* @returns {Observable} An observable sequence containing a single array with the elements taken during the specified duration from the end of the source sequence.
|
8255
|
+
*/
|
8256
|
+
observableProto.takeLastBufferWithTime = function (duration, scheduler) {
|
8257
|
+
var source = this;
|
8258
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8259
|
+
return new AnonymousObservable(function (observer) {
|
8260
|
+
var q = [];
|
8275
8261
|
|
8276
|
-
|
8277
|
-
|
8278
|
-
|
8279
|
-
|
8280
|
-
|
8281
|
-
|
8282
|
-
|
8283
|
-
|
8284
|
-
|
8285
|
-
|
8286
|
-
|
8287
|
-
|
8288
|
-
|
8289
|
-
|
8290
|
-
var source = this;
|
8291
|
-
scheduler || (scheduler = timeoutScheduler);
|
8292
|
-
return new AnonymousObservable(function (observer) {
|
8293
|
-
var t = scheduler.scheduleWithRelative(duration, function () {
|
8294
|
-
observer.onCompleted();
|
8295
|
-
});
|
8262
|
+
return source.subscribe(function (x) {
|
8263
|
+
var now = scheduler.now();
|
8264
|
+
q.push({ interval: now, value: x });
|
8265
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
8266
|
+
q.shift();
|
8267
|
+
}
|
8268
|
+
}, observer.onError.bind(observer), function () {
|
8269
|
+
var now = scheduler.now(), res = [];
|
8270
|
+
while (q.length > 0) {
|
8271
|
+
var next = q.shift();
|
8272
|
+
if (now - next.interval <= duration) {
|
8273
|
+
res.push(next.value);
|
8274
|
+
}
|
8275
|
+
}
|
8296
8276
|
|
8297
|
-
|
8298
|
-
|
8299
|
-
|
8277
|
+
observer.onNext(res);
|
8278
|
+
observer.onCompleted();
|
8279
|
+
});
|
8280
|
+
});
|
8281
|
+
};
|
8300
8282
|
|
8301
|
-
|
8302
|
-
|
8303
|
-
|
8304
|
-
|
8305
|
-
|
8306
|
-
|
8307
|
-
|
8308
|
-
|
8309
|
-
|
8310
|
-
|
8311
|
-
|
8312
|
-
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8318
|
-
|
8319
|
-
|
8320
|
-
|
8321
|
-
var open = false,
|
8322
|
-
t = scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
8323
|
-
d = source.subscribe(function (x) {
|
8324
|
-
if (open) {
|
8325
|
-
observer.onNext(x);
|
8326
|
-
}
|
8327
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
8283
|
+
/**
|
8284
|
+
* Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
8285
|
+
*
|
8286
|
+
* @example
|
8287
|
+
* 1 - res = source.takeWithTime(5000, [optional scheduler]);
|
8288
|
+
* @description
|
8289
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8290
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
8291
|
+
* result sequence. This causes elements to be delayed with duration.
|
8292
|
+
* @param {Number} duration Duration for taking elements from the start of the sequence.
|
8293
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8294
|
+
* @returns {Observable} An observable sequence with the elements taken during the specified duration from the start of the source sequence.
|
8295
|
+
*/
|
8296
|
+
observableProto.takeWithTime = function (duration, scheduler) {
|
8297
|
+
var source = this;
|
8298
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8299
|
+
return new AnonymousObservable(function (observer) {
|
8300
|
+
return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
|
8301
|
+
});
|
8302
|
+
};
|
8328
8303
|
|
8329
|
-
|
8330
|
-
|
8331
|
-
|
8304
|
+
/**
|
8305
|
+
* Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
8306
|
+
*
|
8307
|
+
* @example
|
8308
|
+
* 1 - res = source.skipWithTime(5000, [optional scheduler]);
|
8309
|
+
*
|
8310
|
+
* @description
|
8311
|
+
* Specifying a zero value for duration doesn't guarantee no elements will be dropped from the start of the source sequence.
|
8312
|
+
* This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded
|
8313
|
+
* may not execute immediately, despite the zero due time.
|
8314
|
+
*
|
8315
|
+
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the duration.
|
8316
|
+
* @param {Number} duration Duration for skipping elements from the start of the sequence.
|
8317
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8318
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the start of the source sequence.
|
8319
|
+
*/
|
8320
|
+
observableProto.skipWithTime = function (duration, scheduler) {
|
8321
|
+
var source = this;
|
8322
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8323
|
+
return new AnonymousObservable(function (observer) {
|
8324
|
+
var open = false;
|
8325
|
+
return new CompositeDisposable(
|
8326
|
+
scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
8327
|
+
source.subscribe(function (x) { open && observer.onNext(x); }, observer.onError.bind(observer), observer.onCompleted.bind(observer)));
|
8328
|
+
});
|
8329
|
+
};
|
8332
8330
|
|
8333
8331
|
/**
|
8334
8332
|
* Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
|
@@ -8342,7 +8340,7 @@
|
|
8342
8340
|
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
8343
8341
|
*/
|
8344
8342
|
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
8345
|
-
scheduler || (scheduler = timeoutScheduler);
|
8343
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8346
8344
|
var source = this, schedulerMethod = startTime instanceof Date ?
|
8347
8345
|
'scheduleWithAbsolute' :
|
8348
8346
|
'scheduleWithRelative';
|
@@ -8369,7 +8367,7 @@
|
|
8369
8367
|
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
8370
8368
|
*/
|
8371
8369
|
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
8372
|
-
scheduler || (scheduler = timeoutScheduler);
|
8370
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8373
8371
|
var source = this, schedulerMethod = endTime instanceof Date ?
|
8374
8372
|
'scheduleWithAbsolute' :
|
8375
8373
|
'scheduleWithRelative';
|
@@ -8380,6 +8378,116 @@
|
|
8380
8378
|
});
|
8381
8379
|
};
|
8382
8380
|
|
8381
|
+
/*
|
8382
|
+
* Performs a exclusive waiting for the first to finish before subscribing to another observable.
|
8383
|
+
* Observables that come in between subscriptions will be dropped on the floor.
|
8384
|
+
* @returns {Observable} A exclusive observable with only the results that happen when subscribed.
|
8385
|
+
*/
|
8386
|
+
observableProto.exclusive = function () {
|
8387
|
+
var sources = this;
|
8388
|
+
return new AnonymousObservable(function (observer) {
|
8389
|
+
var hasCurrent = false,
|
8390
|
+
isStopped = false,
|
8391
|
+
m = new SingleAssignmentDisposable(),
|
8392
|
+
g = new CompositeDisposable();
|
8393
|
+
|
8394
|
+
g.add(m);
|
8395
|
+
|
8396
|
+
m.setDisposable(sources.subscribe(
|
8397
|
+
function (innerSource) {
|
8398
|
+
if (!hasCurrent) {
|
8399
|
+
hasCurrent = true;
|
8400
|
+
|
8401
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
8402
|
+
|
8403
|
+
var innerSubscription = new SingleAssignmentDisposable();
|
8404
|
+
g.add(innerSubscription);
|
8405
|
+
|
8406
|
+
innerSubscription.setDisposable(innerSource.subscribe(
|
8407
|
+
observer.onNext.bind(observer),
|
8408
|
+
observer.onError.bind(observer),
|
8409
|
+
function () {
|
8410
|
+
g.remove(innerSubscription);
|
8411
|
+
hasCurrent = false;
|
8412
|
+
if (isStopped && g.length === 1) {
|
8413
|
+
observer.onCompleted();
|
8414
|
+
}
|
8415
|
+
}));
|
8416
|
+
}
|
8417
|
+
},
|
8418
|
+
observer.onError.bind(observer),
|
8419
|
+
function () {
|
8420
|
+
isStopped = true;
|
8421
|
+
if (!hasCurrent && g.length === 1) {
|
8422
|
+
observer.onCompleted();
|
8423
|
+
}
|
8424
|
+
}));
|
8425
|
+
|
8426
|
+
return g;
|
8427
|
+
});
|
8428
|
+
};
|
8429
|
+
/*
|
8430
|
+
* Performs a exclusive map waiting for the first to finish before subscribing to another observable.
|
8431
|
+
* Observables that come in between subscriptions will be dropped on the floor.
|
8432
|
+
* @param {Function} selector Selector to invoke for every item in the current subscription.
|
8433
|
+
* @param {Any} [thisArg] An optional context to invoke with the selector parameter.
|
8434
|
+
* @returns {Observable} An exclusive observable with only the results that happen when subscribed.
|
8435
|
+
*/
|
8436
|
+
observableProto.exclusiveMap = function (selector, thisArg) {
|
8437
|
+
var sources = this;
|
8438
|
+
return new AnonymousObservable(function (observer) {
|
8439
|
+
var index = 0,
|
8440
|
+
hasCurrent = false,
|
8441
|
+
isStopped = true,
|
8442
|
+
m = new SingleAssignmentDisposable(),
|
8443
|
+
g = new CompositeDisposable();
|
8444
|
+
|
8445
|
+
g.add(m);
|
8446
|
+
|
8447
|
+
m.setDisposable(sources.subscribe(
|
8448
|
+
function (innerSource) {
|
8449
|
+
|
8450
|
+
if (!hasCurrent) {
|
8451
|
+
hasCurrent = true;
|
8452
|
+
|
8453
|
+
innerSubscription = new SingleAssignmentDisposable();
|
8454
|
+
g.add(innerSubscription);
|
8455
|
+
|
8456
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
8457
|
+
|
8458
|
+
innerSubscription.setDisposable(innerSource.subscribe(
|
8459
|
+
function (x) {
|
8460
|
+
var result;
|
8461
|
+
try {
|
8462
|
+
result = selector.call(thisArg, x, index++, innerSource);
|
8463
|
+
} catch (e) {
|
8464
|
+
observer.onError(e);
|
8465
|
+
return;
|
8466
|
+
}
|
8467
|
+
|
8468
|
+
observer.onNext(result);
|
8469
|
+
},
|
8470
|
+
observer.onError.bind(observer),
|
8471
|
+
function () {
|
8472
|
+
g.remove(innerSubscription);
|
8473
|
+
hasCurrent = false;
|
8474
|
+
|
8475
|
+
if (isStopped && g.length === 1) {
|
8476
|
+
observer.onCompleted();
|
8477
|
+
}
|
8478
|
+
}));
|
8479
|
+
}
|
8480
|
+
},
|
8481
|
+
observer.onError.bind(observer),
|
8482
|
+
function () {
|
8483
|
+
isStopped = true;
|
8484
|
+
if (g.length === 1 && !hasCurrent) {
|
8485
|
+
observer.onCompleted();
|
8486
|
+
}
|
8487
|
+
}));
|
8488
|
+
return g;
|
8489
|
+
});
|
8490
|
+
};
|
8383
8491
|
/** Provides a set of extension methods for virtual time scheduling. */
|
8384
8492
|
Rx.VirtualTimeScheduler = (function (_super) {
|
8385
8493
|
|
@@ -8689,25 +8797,21 @@
|
|
8689
8797
|
}
|
8690
8798
|
|
8691
8799
|
function s(observer) {
|
8692
|
-
var
|
8693
|
-
if (currentThreadScheduler.scheduleRequired()) {
|
8694
|
-
currentThreadScheduler.schedule(function () {
|
8695
|
-
try {
|
8696
|
-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
8697
|
-
} catch (e) {
|
8698
|
-
if (!autoDetachObserver.fail(e)) {
|
8699
|
-
throw e;
|
8700
|
-
}
|
8701
|
-
}
|
8702
|
-
});
|
8703
|
-
} else {
|
8800
|
+
var setDisposable = function () {
|
8704
8801
|
try {
|
8705
8802
|
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
8706
8803
|
} catch (e) {
|
8707
8804
|
if (!autoDetachObserver.fail(e)) {
|
8708
8805
|
throw e;
|
8709
|
-
}
|
8806
|
+
}
|
8710
8807
|
}
|
8808
|
+
};
|
8809
|
+
|
8810
|
+
var autoDetachObserver = new AutoDetachObserver(observer);
|
8811
|
+
if (currentThreadScheduler.scheduleRequired()) {
|
8812
|
+
currentThreadScheduler.schedule(setDisposable);
|
8813
|
+
} else {
|
8814
|
+
setDisposable();
|
8711
8815
|
}
|
8712
8816
|
|
8713
8817
|
return autoDetachObserver;
|