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 */
|
@@ -1283,140 +1284,111 @@
|
|
1283
1284
|
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1284
1285
|
})();
|
1285
1286
|
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
var NotificationPrototype = Notification.prototype;
|
1296
|
-
|
1297
|
-
/**
|
1298
|
-
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1299
|
-
*
|
1300
|
-
* @memberOf Notification
|
1301
|
-
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1302
|
-
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1303
|
-
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1304
|
-
* @returns {Any} Result produced by the observation.
|
1305
|
-
*/
|
1306
|
-
NotificationPrototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1307
|
-
if (arguments.length === 1 && typeof observerOrOnNext === 'object') {
|
1308
|
-
return this._acceptObservable(observerOrOnNext);
|
1309
|
-
}
|
1310
|
-
return this._accept(observerOrOnNext, onError, onCompleted);
|
1311
|
-
};
|
1312
|
-
|
1313
|
-
/**
|
1314
|
-
* Returns an observable sequence with a single notification.
|
1315
|
-
*
|
1316
|
-
* @memberOf Notification
|
1317
|
-
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1318
|
-
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1319
|
-
*/
|
1320
|
-
NotificationPrototype.toObservable = function (scheduler) {
|
1321
|
-
var notification = this;
|
1322
|
-
scheduler || (scheduler = immediateScheduler);
|
1323
|
-
return new AnonymousObservable(function (observer) {
|
1324
|
-
return scheduler.schedule(function () {
|
1325
|
-
notification._acceptObservable(observer);
|
1326
|
-
if (notification.kind === 'N') {
|
1327
|
-
observer.onCompleted();
|
1328
|
-
}
|
1329
|
-
});
|
1330
|
-
});
|
1331
|
-
};
|
1332
|
-
|
1333
|
-
return Notification;
|
1334
|
-
})();
|
1287
|
+
/**
|
1288
|
+
* Represents a notification to an observer.
|
1289
|
+
*/
|
1290
|
+
var Notification = Rx.Notification = (function () {
|
1291
|
+
function Notification(kind, hasValue) {
|
1292
|
+
this.hasValue = hasValue == null ? false : hasValue;
|
1293
|
+
this.kind = kind;
|
1294
|
+
}
|
1335
1295
|
|
1336
1296
|
/**
|
1337
|
-
*
|
1338
|
-
*
|
1339
|
-
* @
|
1297
|
+
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1298
|
+
*
|
1299
|
+
* @memberOf Notification
|
1300
|
+
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1301
|
+
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1302
|
+
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1303
|
+
* @returns {Any} Result produced by the observation.
|
1340
1304
|
*/
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
function _acceptObservable(observer) {
|
1348
|
-
return observer.onNext(this.value);
|
1349
|
-
}
|
1350
|
-
|
1351
|
-
function toString () {
|
1352
|
-
return 'OnNext(' + this.value + ')';
|
1353
|
-
}
|
1354
|
-
|
1355
|
-
return function (value) {
|
1356
|
-
var notification = new Notification('N', true);
|
1357
|
-
notification.value = value;
|
1358
|
-
notification._accept = _accept;
|
1359
|
-
notification._acceptObservable = _acceptObservable;
|
1360
|
-
notification.toString = toString;
|
1361
|
-
return notification;
|
1362
|
-
};
|
1363
|
-
}());
|
1305
|
+
Notification.prototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1306
|
+
return observerOrOnNext && typeof observerOrOnNext === 'object' ?
|
1307
|
+
this._acceptObservable(observerOrOnNext) :
|
1308
|
+
this._accept(observerOrOnNext, onError, onCompleted);
|
1309
|
+
};
|
1364
1310
|
|
1365
1311
|
/**
|
1366
|
-
*
|
1367
|
-
*
|
1368
|
-
* @
|
1312
|
+
* Returns an observable sequence with a single notification.
|
1313
|
+
*
|
1314
|
+
* @memberOf Notifications
|
1315
|
+
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1316
|
+
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1369
1317
|
*/
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
function toString () {
|
1381
|
-
return 'OnError(' + this.exception + ')';
|
1382
|
-
}
|
1318
|
+
Notification.prototype.toObservable = function (scheduler) {
|
1319
|
+
var notification = this;
|
1320
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
1321
|
+
return new AnonymousObservable(function (observer) {
|
1322
|
+
return scheduler.schedule(function () {
|
1323
|
+
notification._acceptObservable(observer);
|
1324
|
+
notification.kind === 'N' && observer.onCompleted();
|
1325
|
+
});
|
1326
|
+
});
|
1327
|
+
};
|
1383
1328
|
|
1384
|
-
|
1385
|
-
|
1386
|
-
notification.exception = exception;
|
1387
|
-
notification._accept = _accept;
|
1388
|
-
notification._acceptObservable = _acceptObservable;
|
1389
|
-
notification.toString = toString;
|
1390
|
-
return notification;
|
1391
|
-
};
|
1392
|
-
}());
|
1329
|
+
return Notification;
|
1330
|
+
})();
|
1393
1331
|
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1332
|
+
/**
|
1333
|
+
* Creates an object that represents an OnNext notification to an observer.
|
1334
|
+
* @param {Any} value The value contained in the notification.
|
1335
|
+
* @returns {Notification} The OnNext notification containing the value.
|
1336
|
+
*/
|
1337
|
+
var notificationCreateOnNext = Notification.createOnNext = (function () {
|
1338
|
+
|
1339
|
+
function _accept (onNext) { return onNext(this.value); }
|
1340
|
+
function _acceptObservable(observer) { return observer.onNext(this.value); }
|
1341
|
+
function toString () { return 'OnNext(' + this.value + ')'; }
|
1342
|
+
|
1343
|
+
return function (value) {
|
1344
|
+
var notification = new Notification('N', true);
|
1345
|
+
notification.value = value;
|
1346
|
+
notification._accept = _accept;
|
1347
|
+
notification._acceptObservable = _acceptObservable;
|
1348
|
+
notification.toString = toString;
|
1349
|
+
return notification;
|
1350
|
+
};
|
1351
|
+
}());
|
1399
1352
|
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1353
|
+
/**
|
1354
|
+
* Creates an object that represents an OnError notification to an observer.
|
1355
|
+
* @param {Any} error The exception contained in the notification.
|
1356
|
+
* @returns {Notification} The OnError notification containing the exception.
|
1357
|
+
*/
|
1358
|
+
var notificationCreateOnError = Notification.createOnError = (function () {
|
1359
|
+
|
1360
|
+
function _accept (onNext, onError) { return onError(this.exception); }
|
1361
|
+
function _acceptObservable(observer) { return observer.onError(this.exception); }
|
1362
|
+
function toString () { return 'OnError(' + this.exception + ')'; }
|
1363
|
+
|
1364
|
+
return function (exception) {
|
1365
|
+
var notification = new Notification('E');
|
1366
|
+
notification.exception = exception;
|
1367
|
+
notification._accept = _accept;
|
1368
|
+
notification._acceptObservable = _acceptObservable;
|
1369
|
+
notification.toString = toString;
|
1370
|
+
return notification;
|
1371
|
+
};
|
1372
|
+
}());
|
1403
1373
|
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1374
|
+
/**
|
1375
|
+
* Creates an object that represents an OnCompleted notification to an observer.
|
1376
|
+
* @returns {Notification} The OnCompleted notification.
|
1377
|
+
*/
|
1378
|
+
var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
|
1407
1379
|
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1380
|
+
function _accept (onNext, onError, onCompleted) { return onCompleted(); }
|
1381
|
+
function _acceptObservable(observer) { return observer.onCompleted(); }
|
1382
|
+
function toString () { return 'OnCompleted()'; }
|
1411
1383
|
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1384
|
+
return function () {
|
1385
|
+
var notification = new Notification('C');
|
1386
|
+
notification._accept = _accept;
|
1387
|
+
notification._acceptObservable = _acceptObservable;
|
1388
|
+
notification.toString = toString;
|
1389
|
+
return notification;
|
1390
|
+
};
|
1391
|
+
}());
|
1420
1392
|
|
1421
1393
|
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1422
1394
|
this._next = next;
|
@@ -1903,130 +1875,180 @@
|
|
1903
1875
|
});
|
1904
1876
|
};
|
1905
1877
|
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1878
|
+
/**
|
1879
|
+
* Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
|
1880
|
+
*
|
1881
|
+
* @example
|
1882
|
+
* var res = Rx.Observable.empty();
|
1883
|
+
* var res = Rx.Observable.empty(Rx.Scheduler.timeout);
|
1884
|
+
* @param {Scheduler} [scheduler] Scheduler to send the termination call on.
|
1885
|
+
* @returns {Observable} An observable sequence with no elements.
|
1886
|
+
*/
|
1887
|
+
var observableEmpty = Observable.empty = function (scheduler) {
|
1888
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
1889
|
+
return new AnonymousObservable(function (observer) {
|
1890
|
+
return scheduler.schedule(function () {
|
1891
|
+
observer.onCompleted();
|
1892
|
+
});
|
1893
|
+
});
|
1894
|
+
};
|
1923
1895
|
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1896
|
+
var maxSafeInteger = Math.pow(2, 53) - 1;
|
1897
|
+
|
1898
|
+
function numberIsFinite(value) {
|
1899
|
+
return typeof value === 'number' && root.isFinite(value);
|
1900
|
+
}
|
1901
|
+
|
1902
|
+
function isNan(n) {
|
1903
|
+
return n !== n;
|
1904
|
+
}
|
1905
|
+
|
1906
|
+
function isIterable(o) {
|
1907
|
+
return o[$iterator$] !== undefined;
|
1908
|
+
}
|
1909
|
+
|
1910
|
+
function sign(value) {
|
1911
|
+
var number = +value;
|
1912
|
+
if (number === 0) { return number; }
|
1913
|
+
if (isNaN(number)) { return number; }
|
1914
|
+
return number < 0 ? -1 : 1;
|
1915
|
+
}
|
1916
|
+
|
1917
|
+
function toLength(o) {
|
1918
|
+
var len = +o.length;
|
1919
|
+
if (isNaN(len)) { return 0; }
|
1920
|
+
if (len === 0 || !numberIsFinite(len)) { return len; }
|
1921
|
+
len = sign(len) * Math.floor(Math.abs(len));
|
1922
|
+
if (len <= 0) { return 0; }
|
1923
|
+
if (len > maxSafeInteger) { return maxSafeInteger; }
|
1924
|
+
return len;
|
1925
|
+
}
|
1926
|
+
|
1927
|
+
function isCallable(f) {
|
1928
|
+
return Object.prototype.toString.call(f) === '[object Function]' && typeof f === 'function';
|
1929
|
+
}
|
1930
|
+
|
1931
|
+
/**
|
1932
|
+
* This method creates a new Observable sequence from an array-like or iterable object.
|
1933
|
+
* @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
|
1934
|
+
* @param {Function} [mapFn] Map function to call on every element of the array.
|
1935
|
+
* @param {Any} [thisArg] The context to use calling the mapFn if provided.
|
1936
|
+
* @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
|
1937
|
+
*/
|
1938
|
+
Observable.from = function (iterable, mapFn, thisArg, scheduler) {
|
1939
|
+
if (iterable == null) {
|
1940
|
+
throw new Error('iterable cannot be null.')
|
1941
|
+
}
|
1942
|
+
if (mapFn && !isCallable(mapFn)) {
|
1943
|
+
throw new Error('mapFn when provided must be a function');
|
1944
|
+
}
|
1945
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
1946
|
+
return new AnonymousObservable(function (observer) {
|
1947
|
+
var list = Object(iterable),
|
1948
|
+
objIsIterable = isIterable(list),
|
1949
|
+
len = objIsIterable ? 0 : toLength(list),
|
1950
|
+
it = objIsIterable ? list[$iterator$]() : null,
|
1951
|
+
i = 0;
|
1952
|
+
return scheduler.scheduleRecursive(function (self) {
|
1953
|
+
if (i < len || objIsIterable) {
|
1954
|
+
var result;
|
1955
|
+
if (objIsIterable) {
|
1956
|
+
var next = it.next();
|
1957
|
+
if (next.done) {
|
1958
|
+
observer.onCompleted();
|
1959
|
+
return;
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
result = next.value;
|
1963
|
+
} else {
|
1964
|
+
result = list[i];
|
1965
|
+
}
|
1966
|
+
|
1967
|
+
if (mapFn && isCallable(mapFn)) {
|
1968
|
+
try {
|
1969
|
+
result = thisArg ? mapFn.call(thisArg, result, i) : mapFn(result, i);
|
1970
|
+
} catch (e) {
|
1971
|
+
observer.onError(e);
|
1972
|
+
return;
|
1973
|
+
}
|
1974
|
+
}
|
1947
1975
|
|
1976
|
+
observer.onNext(result);
|
1977
|
+
i++;
|
1978
|
+
self();
|
1979
|
+
} else {
|
1980
|
+
observer.onCompleted();
|
1981
|
+
}
|
1982
|
+
});
|
1983
|
+
});
|
1984
|
+
};
|
1948
1985
|
/**
|
1949
|
-
* Converts an
|
1986
|
+
* Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
|
1950
1987
|
*
|
1951
1988
|
* @example
|
1952
|
-
* var res = Rx.Observable.
|
1953
|
-
* var res = Rx.Observable.
|
1989
|
+
* var res = Rx.Observable.fromArray([1,2,3]);
|
1990
|
+
* var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
|
1954
1991
|
* @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
|
1955
|
-
* @returns {Observable} The observable sequence whose elements are pulled from the given
|
1992
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
|
1956
1993
|
*/
|
1957
|
-
Observable.
|
1958
|
-
scheduler || (scheduler = currentThreadScheduler);
|
1994
|
+
var observableFromArray = Observable.fromArray = function (array, scheduler) {
|
1995
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
1959
1996
|
return new AnonymousObservable(function (observer) {
|
1960
|
-
var
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1997
|
+
var count = 0, len = array.length;
|
1998
|
+
return scheduler.scheduleRecursive(function (self) {
|
1999
|
+
if (count < len) {
|
2000
|
+
observer.onNext(array[count++]);
|
2001
|
+
self();
|
2002
|
+
} else {
|
2003
|
+
observer.onCompleted();
|
2004
|
+
}
|
2005
|
+
});
|
2006
|
+
});
|
2007
|
+
};
|
1967
2008
|
|
2009
|
+
/**
|
2010
|
+
* Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
|
2011
|
+
*
|
2012
|
+
* @example
|
2013
|
+
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
|
2014
|
+
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
|
2015
|
+
* @param {Mixed} initialState Initial state.
|
2016
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
2017
|
+
* @param {Function} iterate Iteration step function.
|
2018
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
2019
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
|
2020
|
+
* @returns {Observable} The generated sequence.
|
2021
|
+
*/
|
2022
|
+
Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
|
2023
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2024
|
+
return new AnonymousObservable(function (observer) {
|
2025
|
+
var first = true, state = initialState;
|
1968
2026
|
return scheduler.scheduleRecursive(function (self) {
|
1969
|
-
var
|
2027
|
+
var hasResult, result;
|
1970
2028
|
try {
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
2029
|
+
if (first) {
|
2030
|
+
first = false;
|
2031
|
+
} else {
|
2032
|
+
state = iterate(state);
|
2033
|
+
}
|
2034
|
+
hasResult = condition(state);
|
2035
|
+
if (hasResult) {
|
2036
|
+
result = resultSelector(state);
|
2037
|
+
}
|
2038
|
+
} catch (exception) {
|
2039
|
+
observer.onError(exception);
|
1974
2040
|
return;
|
1975
2041
|
}
|
1976
|
-
|
1977
|
-
|
1978
|
-
observer.onCompleted();
|
1979
|
-
} else {
|
1980
|
-
observer.onNext(next.value);
|
2042
|
+
if (hasResult) {
|
2043
|
+
observer.onNext(result);
|
1981
2044
|
self();
|
2045
|
+
} else {
|
2046
|
+
observer.onCompleted();
|
1982
2047
|
}
|
1983
2048
|
});
|
1984
2049
|
});
|
1985
2050
|
};
|
1986
2051
|
|
1987
|
-
/**
|
1988
|
-
* Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
|
1989
|
-
*
|
1990
|
-
* @example
|
1991
|
-
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; });
|
1992
|
-
* var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout);
|
1993
|
-
* @param {Mixed} initialState Initial state.
|
1994
|
-
* @param {Function} condition Condition to terminate generation (upon returning false).
|
1995
|
-
* @param {Function} iterate Iteration step function.
|
1996
|
-
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
1997
|
-
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.
|
1998
|
-
* @returns {Observable} The generated sequence.
|
1999
|
-
*/
|
2000
|
-
Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
|
2001
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2002
|
-
return new AnonymousObservable(function (observer) {
|
2003
|
-
var first = true, state = initialState;
|
2004
|
-
return scheduler.scheduleRecursive(function (self) {
|
2005
|
-
var hasResult, result;
|
2006
|
-
try {
|
2007
|
-
if (first) {
|
2008
|
-
first = false;
|
2009
|
-
} else {
|
2010
|
-
state = iterate(state);
|
2011
|
-
}
|
2012
|
-
hasResult = condition(state);
|
2013
|
-
if (hasResult) {
|
2014
|
-
result = resultSelector(state);
|
2015
|
-
}
|
2016
|
-
} catch (exception) {
|
2017
|
-
observer.onError(exception);
|
2018
|
-
return;
|
2019
|
-
}
|
2020
|
-
if (hasResult) {
|
2021
|
-
observer.onNext(result);
|
2022
|
-
self();
|
2023
|
-
} else {
|
2024
|
-
observer.onCompleted();
|
2025
|
-
}
|
2026
|
-
});
|
2027
|
-
});
|
2028
|
-
};
|
2029
|
-
|
2030
2052
|
/**
|
2031
2053
|
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2032
2054
|
* @returns {Observable} An observable sequence whose observers will never get called.
|
@@ -2037,118 +2059,140 @@
|
|
2037
2059
|
});
|
2038
2060
|
};
|
2039
2061
|
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
Observable.range = function (start, count, scheduler) {
|
2052
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2053
|
-
return new AnonymousObservable(function (observer) {
|
2054
|
-
return scheduler.scheduleRecursiveWithState(0, function (i, self) {
|
2055
|
-
if (i < count) {
|
2056
|
-
observer.onNext(start + i);
|
2057
|
-
self(i + 1);
|
2058
|
-
} else {
|
2059
|
-
observer.onCompleted();
|
2060
|
-
}
|
2061
|
-
});
|
2062
|
-
});
|
2063
|
-
};
|
2064
|
-
|
2065
|
-
/**
|
2066
|
-
* Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
|
2067
|
-
*
|
2068
|
-
* @example
|
2069
|
-
* var res = Rx.Observable.repeat(42);
|
2070
|
-
* var res = Rx.Observable.repeat(42, 4);
|
2071
|
-
* 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
|
2072
|
-
* 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
|
2073
|
-
* @param {Mixed} value Element to repeat.
|
2074
|
-
* @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
|
2075
|
-
* @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
|
2076
|
-
* @returns {Observable} An observable sequence that repeats the given element the specified number of times.
|
2077
|
-
*/
|
2078
|
-
Observable.repeat = function (value, repeatCount, scheduler) {
|
2079
|
-
scheduler || (scheduler = currentThreadScheduler);
|
2080
|
-
if (repeatCount == null) {
|
2081
|
-
repeatCount = -1;
|
2082
|
-
}
|
2083
|
-
return observableReturn(value, scheduler).repeat(repeatCount);
|
2084
|
-
};
|
2085
|
-
|
2086
|
-
/**
|
2087
|
-
* Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
|
2088
|
-
* There is an alias called 'returnValue' for browsers <IE9.
|
2089
|
-
*
|
2090
|
-
* @example
|
2091
|
-
* var res = Rx.Observable.return(42);
|
2092
|
-
* var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
|
2093
|
-
* @param {Mixed} value Single element in the resulting observable sequence.
|
2094
|
-
* @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
|
2095
|
-
* @returns {Observable} An observable sequence containing the single specified element.
|
2096
|
-
*/
|
2097
|
-
var observableReturn = Observable['return'] = Observable.returnValue = function (value, scheduler) {
|
2098
|
-
scheduler || (scheduler = immediateScheduler);
|
2099
|
-
return new AnonymousObservable(function (observer) {
|
2100
|
-
return scheduler.schedule(function () {
|
2101
|
-
observer.onNext(value);
|
2102
|
-
observer.onCompleted();
|
2103
|
-
});
|
2104
|
-
});
|
2105
|
-
};
|
2062
|
+
/**
|
2063
|
+
* This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
|
2064
|
+
* @example
|
2065
|
+
* var res = Rx.Observable.of(1,2,3);
|
2066
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
|
2067
|
+
*/
|
2068
|
+
Observable.of = function () {
|
2069
|
+
var len = arguments.length, args = new Array(len);
|
2070
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
2071
|
+
return observableFromArray(args);
|
2072
|
+
};
|
2106
2073
|
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
scheduler || (scheduler = immediateScheduler);
|
2120
|
-
return new AnonymousObservable(function (observer) {
|
2121
|
-
return scheduler.schedule(function () {
|
2122
|
-
observer.onError(exception);
|
2123
|
-
});
|
2124
|
-
});
|
2125
|
-
};
|
2074
|
+
/**
|
2075
|
+
* This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
|
2076
|
+
* @example
|
2077
|
+
* var res = Rx.Observable.of(1,2,3);
|
2078
|
+
* @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
|
2079
|
+
* @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
|
2080
|
+
*/
|
2081
|
+
var observableOf = Observable.ofWithScheduler = function (scheduler) {
|
2082
|
+
var len = arguments.length - 1, args = new Array(len);
|
2083
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
|
2084
|
+
return observableFromArray(args, scheduler);
|
2085
|
+
};
|
2126
2086
|
|
2127
|
-
|
2087
|
+
/**
|
2088
|
+
* Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
|
2089
|
+
*
|
2090
|
+
* @example
|
2091
|
+
* var res = Rx.Observable.range(0, 10);
|
2092
|
+
* var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout);
|
2093
|
+
* @param {Number} start The value of the first integer in the sequence.
|
2094
|
+
* @param {Number} count The number of sequential integers to generate.
|
2095
|
+
* @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread.
|
2096
|
+
* @returns {Observable} An observable sequence that contains a range of sequential integral numbers.
|
2097
|
+
*/
|
2098
|
+
Observable.range = function (start, count, scheduler) {
|
2099
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2128
2100
|
return new AnonymousObservable(function (observer) {
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
} catch (ex) {
|
2136
|
-
observer.onError(ex);
|
2137
|
-
return;
|
2101
|
+
return scheduler.scheduleRecursiveWithState(0, function (i, self) {
|
2102
|
+
if (i < count) {
|
2103
|
+
observer.onNext(start + i);
|
2104
|
+
self(i + 1);
|
2105
|
+
} else {
|
2106
|
+
observer.onCompleted();
|
2138
2107
|
}
|
2139
|
-
|
2140
|
-
|
2141
|
-
d = new SingleAssignmentDisposable();
|
2142
|
-
subscription.setDisposable(d);
|
2143
|
-
d.setDisposable(result.subscribe(observer));
|
2144
|
-
}, observer.onCompleted.bind(observer)));
|
2145
|
-
|
2146
|
-
return subscription;
|
2108
|
+
});
|
2147
2109
|
});
|
2148
|
-
}
|
2110
|
+
};
|
2149
2111
|
|
2150
2112
|
/**
|
2151
|
-
*
|
2113
|
+
* Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
|
2114
|
+
*
|
2115
|
+
* @example
|
2116
|
+
* var res = Rx.Observable.repeat(42);
|
2117
|
+
* var res = Rx.Observable.repeat(42, 4);
|
2118
|
+
* 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout);
|
2119
|
+
* 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout);
|
2120
|
+
* @param {Mixed} value Element to repeat.
|
2121
|
+
* @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
|
2122
|
+
* @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
|
2123
|
+
* @returns {Observable} An observable sequence that repeats the given element the specified number of times.
|
2124
|
+
*/
|
2125
|
+
Observable.repeat = function (value, repeatCount, scheduler) {
|
2126
|
+
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2127
|
+
return observableReturn(value, scheduler).repeat(repeatCount == null ? -1 : repeatCount);
|
2128
|
+
};
|
2129
|
+
|
2130
|
+
/**
|
2131
|
+
* Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages.
|
2132
|
+
* There is an alias called 'just', and 'returnValue' for browsers <IE9.
|
2133
|
+
*
|
2134
|
+
* @example
|
2135
|
+
* var res = Rx.Observable.return(42);
|
2136
|
+
* var res = Rx.Observable.return(42, Rx.Scheduler.timeout);
|
2137
|
+
* @param {Mixed} value Single element in the resulting observable sequence.
|
2138
|
+
* @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
|
2139
|
+
* @returns {Observable} An observable sequence containing the single specified element.
|
2140
|
+
*/
|
2141
|
+
var observableReturn = Observable['return'] = Observable.returnValue = Observable.just = function (value, scheduler) {
|
2142
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2143
|
+
return new AnonymousObservable(function (observer) {
|
2144
|
+
return scheduler.schedule(function () {
|
2145
|
+
observer.onNext(value);
|
2146
|
+
observer.onCompleted();
|
2147
|
+
});
|
2148
|
+
});
|
2149
|
+
};
|
2150
|
+
|
2151
|
+
/**
|
2152
|
+
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2153
|
+
* There is an alias to this method called 'throwException' for browsers <IE9.
|
2154
|
+
*
|
2155
|
+
* @example
|
2156
|
+
* var res = Rx.Observable.throw(new Error('Error'));
|
2157
|
+
* var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
|
2158
|
+
* @param {Mixed} exception An object used for the sequence's termination.
|
2159
|
+
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2160
|
+
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2161
|
+
*/
|
2162
|
+
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2163
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2164
|
+
return new AnonymousObservable(function (observer) {
|
2165
|
+
return scheduler.schedule(function () {
|
2166
|
+
observer.onError(exception);
|
2167
|
+
});
|
2168
|
+
});
|
2169
|
+
};
|
2170
|
+
|
2171
|
+
function observableCatchHandler(source, handler) {
|
2172
|
+
return new AnonymousObservable(function (observer) {
|
2173
|
+
var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
|
2174
|
+
subscription.setDisposable(d1);
|
2175
|
+
d1.setDisposable(source.subscribe(observer.onNext.bind(observer), function (exception) {
|
2176
|
+
var d, result;
|
2177
|
+
try {
|
2178
|
+
result = handler(exception);
|
2179
|
+
} catch (ex) {
|
2180
|
+
observer.onError(ex);
|
2181
|
+
return;
|
2182
|
+
}
|
2183
|
+
isPromise(result) && (result = observableFromPromise(result));
|
2184
|
+
|
2185
|
+
d = new SingleAssignmentDisposable();
|
2186
|
+
subscription.setDisposable(d);
|
2187
|
+
d.setDisposable(result.subscribe(observer));
|
2188
|
+
}, observer.onCompleted.bind(observer)));
|
2189
|
+
|
2190
|
+
return subscription;
|
2191
|
+
});
|
2192
|
+
}
|
2193
|
+
|
2194
|
+
/**
|
2195
|
+
* Continues an observable sequence that is terminated by an exception with the next observable sequence.
|
2152
2196
|
* @example
|
2153
2197
|
* 1 - xs.catchException(ys)
|
2154
2198
|
* 2 - xs.catchException(function (ex) { return ys(ex); })
|
@@ -2851,18 +2895,19 @@
|
|
2851
2895
|
return enumerableRepeat(this, repeatCount).concat();
|
2852
2896
|
};
|
2853
2897
|
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
|
2898
|
+
/**
|
2899
|
+
* 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.
|
2900
|
+
* Note if you encounter an error and want it to retry once, then you must use .retry(2);
|
2901
|
+
*
|
2902
|
+
* @example
|
2903
|
+
* var res = retried = retry.repeat();
|
2904
|
+
* var res = retried = retry.repeat(2);
|
2905
|
+
* @param {Number} [retryCount] Number of times to retry the sequence. If not provided, retry the sequence indefinitely.
|
2906
|
+
* @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
|
2907
|
+
*/
|
2908
|
+
observableProto.retry = function (retryCount) {
|
2909
|
+
return enumerableRepeat(this, retryCount).catchException();
|
2910
|
+
};
|
2866
2911
|
|
2867
2912
|
/**
|
2868
2913
|
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
@@ -3171,7 +3216,7 @@
|
|
3171
3216
|
* @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
|
3172
3217
|
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
3173
3218
|
*/
|
3174
|
-
observableProto.selectSwitch = observableProto.flatMapLatest = function (selector, thisArg) {
|
3219
|
+
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
3175
3220
|
return this.select(selector, thisArg).switchLatest();
|
3176
3221
|
};
|
3177
3222
|
|
@@ -3320,96 +3365,92 @@
|
|
3320
3365
|
});
|
3321
3366
|
};
|
3322
3367
|
|
3323
|
-
|
3324
|
-
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
|
3330
|
-
|
3331
|
-
|
3332
|
-
|
3333
|
-
|
3334
|
-
return function () {
|
3335
|
-
var args = slice.call(arguments, 0);
|
3368
|
+
/**
|
3369
|
+
* Converts a callback function to an observable sequence.
|
3370
|
+
*
|
3371
|
+
* @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
|
3372
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
3373
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
3374
|
+
* @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.
|
3375
|
+
*/
|
3376
|
+
Observable.fromCallback = function (func, context, selector) {
|
3377
|
+
return function () {
|
3378
|
+
var args = slice.call(arguments, 0);
|
3336
3379
|
|
3337
|
-
|
3338
|
-
|
3339
|
-
|
3340
|
-
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3344
|
-
|
3345
|
-
|
3346
|
-
|
3347
|
-
|
3348
|
-
}
|
3349
|
-
} else {
|
3350
|
-
if (results.length === 1) {
|
3351
|
-
results = results[0];
|
3352
|
-
}
|
3353
|
-
}
|
3380
|
+
return new AnonymousObservable(function (observer) {
|
3381
|
+
function handler(e) {
|
3382
|
+
var results = e;
|
3383
|
+
|
3384
|
+
if (selector) {
|
3385
|
+
try {
|
3386
|
+
results = selector(arguments);
|
3387
|
+
} catch (err) {
|
3388
|
+
observer.onError(err);
|
3389
|
+
return;
|
3390
|
+
}
|
3354
3391
|
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3392
|
+
observer.onNext(results);
|
3393
|
+
} else {
|
3394
|
+
if (results.length <= 1) {
|
3395
|
+
observer.onNext.apply(observer, results);
|
3396
|
+
} else {
|
3397
|
+
observer.onNext(results);
|
3398
|
+
}
|
3399
|
+
}
|
3400
|
+
|
3401
|
+
observer.onCompleted();
|
3402
|
+
}
|
3358
3403
|
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
});
|
3363
|
-
};
|
3404
|
+
args.push(handler);
|
3405
|
+
func.apply(context, args);
|
3406
|
+
});
|
3364
3407
|
};
|
3408
|
+
};
|
3365
3409
|
|
3366
|
-
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
return function () {
|
3377
|
-
var args = slice.call(arguments, 0);
|
3410
|
+
/**
|
3411
|
+
* Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
|
3412
|
+
* @param {Function} func The function to call
|
3413
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
3414
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
|
3415
|
+
* @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
|
3416
|
+
*/
|
3417
|
+
Observable.fromNodeCallback = function (func, context, selector) {
|
3418
|
+
return function () {
|
3419
|
+
var args = slice.call(arguments, 0);
|
3378
3420
|
|
3379
|
-
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
return;
|
3386
|
-
}
|
3421
|
+
return new AnonymousObservable(function (observer) {
|
3422
|
+
function handler(err) {
|
3423
|
+
if (err) {
|
3424
|
+
observer.onError(err);
|
3425
|
+
return;
|
3426
|
+
}
|
3387
3427
|
|
3388
|
-
|
3389
|
-
|
3390
|
-
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3394
|
-
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3428
|
+
var results = slice.call(arguments, 1);
|
3429
|
+
|
3430
|
+
if (selector) {
|
3431
|
+
try {
|
3432
|
+
results = selector(results);
|
3433
|
+
} catch (e) {
|
3434
|
+
observer.onError(e);
|
3435
|
+
return;
|
3436
|
+
}
|
3437
|
+
observer.onNext(results);
|
3438
|
+
} else {
|
3439
|
+
if (results.length <= 1) {
|
3440
|
+
observer.onNext.apply(observer, results);
|
3441
|
+
} else {
|
3442
|
+
observer.onNext(results);
|
3443
|
+
}
|
3444
|
+
}
|
3402
3445
|
|
3403
|
-
|
3404
|
-
|
3405
|
-
}
|
3446
|
+
observer.onCompleted();
|
3447
|
+
}
|
3406
3448
|
|
3407
|
-
|
3408
|
-
|
3409
|
-
|
3410
|
-
});
|
3411
|
-
};
|
3449
|
+
args.push(handler);
|
3450
|
+
func.apply(context, args);
|
3451
|
+
});
|
3412
3452
|
};
|
3453
|
+
};
|
3413
3454
|
|
3414
3455
|
function createListener (element, name, handler) {
|
3415
3456
|
// Node.js specific
|
@@ -3736,24 +3777,24 @@
|
|
3736
3777
|
}, selector);
|
3737
3778
|
};
|
3738
3779
|
|
3739
|
-
|
3740
|
-
|
3741
|
-
|
3742
|
-
|
3743
|
-
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3747
|
-
|
3780
|
+
/**
|
3781
|
+
* 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.
|
3782
|
+
* 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.
|
3783
|
+
*
|
3784
|
+
* @example
|
3785
|
+
* var res = source.shareReplay(3);
|
3786
|
+
* var res = source.shareReplay(3, 500);
|
3787
|
+
* var res = source.shareReplay(3, 500, scheduler);
|
3788
|
+
*
|
3748
3789
|
|
3749
|
-
|
3750
|
-
|
3751
|
-
|
3752
|
-
|
3753
|
-
|
3754
|
-
|
3755
|
-
|
3756
|
-
|
3790
|
+
* @param bufferSize [Optional] Maximum element count of the replay buffer.
|
3791
|
+
* @param window [Optional] Maximum time length of the replay buffer.
|
3792
|
+
* @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
|
3793
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
3794
|
+
*/
|
3795
|
+
observableProto.shareReplay = function (bufferSize, window, scheduler) {
|
3796
|
+
return this.replay(null, bufferSize, window, scheduler).refCount();
|
3797
|
+
};
|
3757
3798
|
|
3758
3799
|
/** @private */
|
3759
3800
|
var ConnectableObservable = Rx.ConnectableObservable = (function (_super) {
|
@@ -3831,259 +3872,268 @@
|
|
3831
3872
|
});
|
3832
3873
|
}
|
3833
3874
|
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
3837
|
-
|
3838
|
-
|
3839
|
-
|
3840
|
-
});
|
3841
|
-
});
|
3842
|
-
}
|
3843
|
-
return observableDefer(function () {
|
3844
|
-
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
3875
|
+
function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
3876
|
+
if (dueTime === period) {
|
3877
|
+
return new AnonymousObservable(function (observer) {
|
3878
|
+
return scheduler.schedulePeriodicWithState(0, period, function (count) {
|
3879
|
+
observer.onNext(count);
|
3880
|
+
return count + 1;
|
3845
3881
|
});
|
3882
|
+
});
|
3846
3883
|
}
|
3884
|
+
return observableDefer(function () {
|
3885
|
+
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
3886
|
+
});
|
3887
|
+
}
|
3847
3888
|
|
3848
|
-
|
3849
|
-
|
3850
|
-
|
3851
|
-
|
3852
|
-
|
3853
|
-
|
3854
|
-
|
3855
|
-
|
3856
|
-
|
3857
|
-
|
3858
|
-
|
3859
|
-
|
3860
|
-
scheduler || (scheduler = timeoutScheduler);
|
3861
|
-
return observableTimerTimeSpanAndPeriod(period, period, scheduler);
|
3862
|
-
};
|
3863
|
-
|
3864
|
-
/**
|
3865
|
-
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
3866
|
-
*
|
3867
|
-
* @example
|
3868
|
-
* var res = Rx.Observable.timer(5000);
|
3869
|
-
* var res = Rx.Observable.timer(5000, 1000);
|
3870
|
-
* var res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
3871
|
-
* var res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
3872
|
-
*
|
3873
|
-
* @param {Number} dueTime Relative time (specified as an integer denoting milliseconds) at which to produce the first value.
|
3874
|
-
* @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.
|
3875
|
-
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
3876
|
-
* @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
|
3877
|
-
*/
|
3878
|
-
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
3879
|
-
var period;
|
3880
|
-
scheduler || (scheduler = timeoutScheduler);
|
3881
|
-
if (typeof periodOrScheduler === 'number') {
|
3882
|
-
period = periodOrScheduler;
|
3883
|
-
} else if (typeof periodOrScheduler === 'object' && 'now' in periodOrScheduler) {
|
3884
|
-
scheduler = periodOrScheduler;
|
3889
|
+
function observableTimerDateAndPeriod(dueTime, period, scheduler) {
|
3890
|
+
var p = normalizeTime(period);
|
3891
|
+
return new AnonymousObservable(function (observer) {
|
3892
|
+
var count = 0, d = dueTime;
|
3893
|
+
return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
|
3894
|
+
var now;
|
3895
|
+
if (p > 0) {
|
3896
|
+
now = scheduler.now();
|
3897
|
+
d = d + p;
|
3898
|
+
if (d <= now) {
|
3899
|
+
d = now + p;
|
3900
|
+
}
|
3885
3901
|
}
|
3886
|
-
|
3887
|
-
|
3888
|
-
|
3889
|
-
};
|
3890
|
-
|
3891
|
-
/**
|
3892
|
-
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
3893
|
-
*
|
3894
|
-
* @example
|
3895
|
-
* var res = Rx.Observable.delay(5000);
|
3896
|
-
* var res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
3897
|
-
* @memberOf Observable#
|
3898
|
-
* @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.
|
3899
|
-
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
3900
|
-
* @returns {Observable} Time-shifted sequence.
|
3901
|
-
*/
|
3902
|
-
observableProto.delay = function (dueTime, scheduler) {
|
3903
|
-
scheduler || (scheduler = timeoutScheduler);
|
3904
|
-
var source = this;
|
3905
|
-
return new AnonymousObservable(function (observer) {
|
3906
|
-
var active = false,
|
3907
|
-
cancelable = new SerialDisposable(),
|
3908
|
-
exception = null,
|
3909
|
-
q = [],
|
3910
|
-
running = false,
|
3911
|
-
subscription;
|
3912
|
-
subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
3913
|
-
var d, shouldRun;
|
3914
|
-
if (notification.value.kind === 'E') {
|
3915
|
-
q = [];
|
3916
|
-
q.push(notification);
|
3917
|
-
exception = notification.value.exception;
|
3918
|
-
shouldRun = !running;
|
3919
|
-
} else {
|
3920
|
-
q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
3921
|
-
shouldRun = !active;
|
3922
|
-
active = true;
|
3923
|
-
}
|
3924
|
-
if (shouldRun) {
|
3925
|
-
if (exception !== null) {
|
3926
|
-
observer.onError(exception);
|
3927
|
-
} else {
|
3928
|
-
d = new SingleAssignmentDisposable();
|
3929
|
-
cancelable.setDisposable(d);
|
3930
|
-
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
3931
|
-
var e, recurseDueTime, result, shouldRecurse;
|
3932
|
-
if (exception !== null) {
|
3933
|
-
return;
|
3934
|
-
}
|
3935
|
-
running = true;
|
3936
|
-
do {
|
3937
|
-
result = null;
|
3938
|
-
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
3939
|
-
result = q.shift().value;
|
3940
|
-
}
|
3941
|
-
if (result !== null) {
|
3942
|
-
result.accept(observer);
|
3943
|
-
}
|
3944
|
-
} while (result !== null);
|
3945
|
-
shouldRecurse = false;
|
3946
|
-
recurseDueTime = 0;
|
3947
|
-
if (q.length > 0) {
|
3948
|
-
shouldRecurse = true;
|
3949
|
-
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
3950
|
-
} else {
|
3951
|
-
active = false;
|
3952
|
-
}
|
3953
|
-
e = exception;
|
3954
|
-
running = false;
|
3955
|
-
if (e !== null) {
|
3956
|
-
observer.onError(e);
|
3957
|
-
} else if (shouldRecurse) {
|
3958
|
-
self(recurseDueTime);
|
3959
|
-
}
|
3960
|
-
}));
|
3961
|
-
}
|
3962
|
-
}
|
3963
|
-
});
|
3964
|
-
return new CompositeDisposable(subscription, cancelable);
|
3965
|
-
});
|
3966
|
-
};
|
3967
|
-
|
3968
|
-
/**
|
3969
|
-
* Ignores values from an observable sequence which are followed by another value before dueTime.
|
3970
|
-
*
|
3971
|
-
* @example
|
3972
|
-
* 1 - res = source.throttle(5000); // 5 seconds
|
3973
|
-
* 2 - res = source.throttle(5000, scheduler);
|
3974
|
-
*
|
3975
|
-
* @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
|
3976
|
-
* @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
|
3977
|
-
* @returns {Observable} The throttled sequence.
|
3978
|
-
*/
|
3979
|
-
observableProto.throttle = function (dueTime, scheduler) {
|
3980
|
-
scheduler || (scheduler = timeoutScheduler);
|
3981
|
-
var source = this;
|
3982
|
-
return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
|
3983
|
-
};
|
3984
|
-
|
3985
|
-
/**
|
3986
|
-
* Records the time interval between consecutive values in an observable sequence.
|
3987
|
-
*
|
3988
|
-
* @example
|
3989
|
-
* 1 - res = source.timeInterval();
|
3990
|
-
* 2 - res = source.timeInterval(Rx.Scheduler.timeout);
|
3991
|
-
*
|
3992
|
-
* @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
|
3993
|
-
* @returns {Observable} An observable sequence with time interval information on values.
|
3994
|
-
*/
|
3995
|
-
observableProto.timeInterval = function (scheduler) {
|
3996
|
-
var source = this;
|
3997
|
-
scheduler || (scheduler = timeoutScheduler);
|
3998
|
-
return observableDefer(function () {
|
3999
|
-
var last = scheduler.now();
|
4000
|
-
return source.select(function (x) {
|
4001
|
-
var now = scheduler.now(), span = now - last;
|
4002
|
-
last = now;
|
4003
|
-
return {
|
4004
|
-
value: x,
|
4005
|
-
interval: span
|
4006
|
-
};
|
4007
|
-
});
|
4008
|
-
});
|
4009
|
-
};
|
4010
|
-
|
4011
|
-
/**
|
4012
|
-
* Records the timestamp for each value in an observable sequence.
|
4013
|
-
*
|
4014
|
-
* @example
|
4015
|
-
* 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
|
4016
|
-
* 2 - res = source.timestamp(Rx.Scheduler.timeout);
|
4017
|
-
*
|
4018
|
-
* @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
|
4019
|
-
* @returns {Observable} An observable sequence with timestamp information on values.
|
4020
|
-
*/
|
4021
|
-
observableProto.timestamp = function (scheduler) {
|
4022
|
-
scheduler || (scheduler = timeoutScheduler);
|
4023
|
-
return this.select(function (x) {
|
4024
|
-
return {
|
4025
|
-
value: x,
|
4026
|
-
timestamp: scheduler.now()
|
4027
|
-
};
|
4028
|
-
});
|
4029
|
-
};
|
4030
|
-
|
4031
|
-
function sampleObservable(source, sampler) {
|
4032
|
-
|
4033
|
-
return new AnonymousObservable(function (observer) {
|
4034
|
-
var atEnd, value, hasValue;
|
3902
|
+
observer.onNext(count++);
|
3903
|
+
self(d);
|
3904
|
+
});
|
3905
|
+
});
|
3906
|
+
}
|
4035
3907
|
|
4036
|
-
|
4037
|
-
|
4038
|
-
|
4039
|
-
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4043
|
-
|
4044
|
-
|
3908
|
+
/**
|
3909
|
+
* Returns an observable sequence that produces a value after each period.
|
3910
|
+
*
|
3911
|
+
* @example
|
3912
|
+
* 1 - res = Rx.Observable.interval(1000);
|
3913
|
+
* 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout);
|
3914
|
+
*
|
3915
|
+
* @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
|
3916
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used.
|
3917
|
+
* @returns {Observable} An observable sequence that produces a value after each period.
|
3918
|
+
*/
|
3919
|
+
var observableinterval = Observable.interval = function (period, scheduler) {
|
3920
|
+
return observableTimerTimeSpanAndPeriod(period, period, isScheduler(scheduler) ? scheduler : timeoutScheduler);
|
3921
|
+
};
|
4045
3922
|
|
4046
|
-
|
4047
|
-
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
|
4055
|
-
|
3923
|
+
/**
|
3924
|
+
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
3925
|
+
*
|
3926
|
+
* @example
|
3927
|
+
* var res = Rx.Observable.timer(5000);
|
3928
|
+
* var res = Rx.Observable.timer(5000, 1000);
|
3929
|
+
* var res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
3930
|
+
* var res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
3931
|
+
*
|
3932
|
+
* @param {Number} dueTime Relative time (specified as an integer denoting milliseconds) at which to produce the first value.
|
3933
|
+
* @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.
|
3934
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
3935
|
+
* @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
|
3936
|
+
*/
|
3937
|
+
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
3938
|
+
var period;
|
3939
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
3940
|
+
if (typeof periodOrScheduler === 'number') {
|
3941
|
+
period = periodOrScheduler;
|
3942
|
+
} else if (typeof periodOrScheduler === 'object' && typeof periodOrScheduler.now === 'function') {
|
3943
|
+
scheduler = periodOrScheduler;
|
4056
3944
|
}
|
4057
|
-
|
4058
|
-
|
4059
|
-
|
4060
|
-
|
4061
|
-
* @example
|
4062
|
-
* 1 - res = source.sample(sampleObservable); // Sampler tick sequence
|
4063
|
-
* 2 - res = source.sample(5000); // 5 seconds
|
4064
|
-
* 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds
|
4065
|
-
*
|
4066
|
-
* @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable.
|
4067
|
-
* @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
|
4068
|
-
* @returns {Observable} Sampled observable sequence.
|
4069
|
-
*/
|
4070
|
-
observableProto.sample = function (intervalOrSampler, scheduler) {
|
4071
|
-
scheduler || (scheduler = timeoutScheduler);
|
4072
|
-
if (typeof intervalOrSampler === 'number') {
|
4073
|
-
return sampleObservable(this, observableinterval(intervalOrSampler, scheduler));
|
4074
|
-
}
|
4075
|
-
return sampleObservable(this, intervalOrSampler);
|
4076
|
-
};
|
3945
|
+
return notDefined(period) ?
|
3946
|
+
observableTimerTimeSpan(dueTime, scheduler) :
|
3947
|
+
observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
|
3948
|
+
};
|
4077
3949
|
|
4078
3950
|
/**
|
4079
|
-
*
|
3951
|
+
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
4080
3952
|
*
|
4081
3953
|
* @example
|
4082
|
-
*
|
4083
|
-
*
|
4084
|
-
*
|
4085
|
-
*
|
4086
|
-
*
|
3954
|
+
* var res = Rx.Observable.delay(5000);
|
3955
|
+
* var res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
3956
|
+
* @memberOf Observable#
|
3957
|
+
* @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.
|
3958
|
+
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
3959
|
+
* @returns {Observable} Time-shifted sequence.
|
3960
|
+
*/
|
3961
|
+
observableProto.delay = function (dueTime, scheduler) {
|
3962
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
3963
|
+
var source = this;
|
3964
|
+
return new AnonymousObservable(function (observer) {
|
3965
|
+
var active = false,
|
3966
|
+
cancelable = new SerialDisposable(),
|
3967
|
+
exception = null,
|
3968
|
+
q = [],
|
3969
|
+
running = false,
|
3970
|
+
subscription;
|
3971
|
+
subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
3972
|
+
var d, shouldRun;
|
3973
|
+
if (notification.value.kind === 'E') {
|
3974
|
+
q = [];
|
3975
|
+
q.push(notification);
|
3976
|
+
exception = notification.value.exception;
|
3977
|
+
shouldRun = !running;
|
3978
|
+
} else {
|
3979
|
+
q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
3980
|
+
shouldRun = !active;
|
3981
|
+
active = true;
|
3982
|
+
}
|
3983
|
+
if (shouldRun) {
|
3984
|
+
if (exception !== null) {
|
3985
|
+
observer.onError(exception);
|
3986
|
+
} else {
|
3987
|
+
d = new SingleAssignmentDisposable();
|
3988
|
+
cancelable.setDisposable(d);
|
3989
|
+
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
3990
|
+
var e, recurseDueTime, result, shouldRecurse;
|
3991
|
+
|
3992
|
+
if (exception !== null) { return; }
|
3993
|
+
|
3994
|
+
running = true;
|
3995
|
+
do {
|
3996
|
+
result = null;
|
3997
|
+
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
3998
|
+
result = q.shift().value;
|
3999
|
+
}
|
4000
|
+
if (result !== null) {
|
4001
|
+
result.accept(observer);
|
4002
|
+
}
|
4003
|
+
} while (result !== null);
|
4004
|
+
|
4005
|
+
shouldRecurse = false;
|
4006
|
+
recurseDueTime = 0;
|
4007
|
+
if (q.length > 0) {
|
4008
|
+
shouldRecurse = true;
|
4009
|
+
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
4010
|
+
} else {
|
4011
|
+
active = false;
|
4012
|
+
}
|
4013
|
+
e = exception;
|
4014
|
+
running = false;
|
4015
|
+
if (e !== null) {
|
4016
|
+
observer.onError(e);
|
4017
|
+
} else if (shouldRecurse) {
|
4018
|
+
self(recurseDueTime);
|
4019
|
+
}
|
4020
|
+
}));
|
4021
|
+
}
|
4022
|
+
}
|
4023
|
+
});
|
4024
|
+
return new CompositeDisposable(subscription, cancelable);
|
4025
|
+
});
|
4026
|
+
};
|
4027
|
+
|
4028
|
+
/**
|
4029
|
+
* Ignores values from an observable sequence which are followed by another value before dueTime.
|
4030
|
+
*
|
4031
|
+
* @example
|
4032
|
+
* 1 - res = source.throttle(5000); // 5 seconds
|
4033
|
+
* 2 - res = source.throttle(5000, scheduler);
|
4034
|
+
*
|
4035
|
+
* @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
|
4036
|
+
* @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
|
4037
|
+
* @returns {Observable} The throttled sequence.
|
4038
|
+
*/
|
4039
|
+
observableProto.throttle = function (dueTime, scheduler) {
|
4040
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4041
|
+
return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
|
4042
|
+
};
|
4043
|
+
|
4044
|
+
/**
|
4045
|
+
* Records the time interval between consecutive values in an observable sequence.
|
4046
|
+
*
|
4047
|
+
* @example
|
4048
|
+
* 1 - res = source.timeInterval();
|
4049
|
+
* 2 - res = source.timeInterval(Rx.Scheduler.timeout);
|
4050
|
+
*
|
4051
|
+
* @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
|
4052
|
+
* @returns {Observable} An observable sequence with time interval information on values.
|
4053
|
+
*/
|
4054
|
+
observableProto.timeInterval = function (scheduler) {
|
4055
|
+
var source = this;
|
4056
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4057
|
+
return observableDefer(function () {
|
4058
|
+
var last = scheduler.now();
|
4059
|
+
return source.map(function (x) {
|
4060
|
+
var now = scheduler.now(), span = now - last;
|
4061
|
+
last = now;
|
4062
|
+
return { value: x, interval: span };
|
4063
|
+
});
|
4064
|
+
});
|
4065
|
+
};
|
4066
|
+
|
4067
|
+
/**
|
4068
|
+
* Records the timestamp for each value in an observable sequence.
|
4069
|
+
*
|
4070
|
+
* @example
|
4071
|
+
* 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
|
4072
|
+
* 2 - res = source.timestamp(Rx.Scheduler.timeout);
|
4073
|
+
*
|
4074
|
+
* @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
|
4075
|
+
* @returns {Observable} An observable sequence with timestamp information on values.
|
4076
|
+
*/
|
4077
|
+
observableProto.timestamp = function (scheduler) {
|
4078
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4079
|
+
return this.map(function (x) {
|
4080
|
+
return { value: x, timestamp: scheduler.now() };
|
4081
|
+
});
|
4082
|
+
};
|
4083
|
+
|
4084
|
+
function sampleObservable(source, sampler) {
|
4085
|
+
|
4086
|
+
return new AnonymousObservable(function (observer) {
|
4087
|
+
var atEnd, value, hasValue;
|
4088
|
+
|
4089
|
+
function sampleSubscribe() {
|
4090
|
+
if (hasValue) {
|
4091
|
+
hasValue = false;
|
4092
|
+
observer.onNext(value);
|
4093
|
+
}
|
4094
|
+
atEnd && observer.onCompleted();
|
4095
|
+
}
|
4096
|
+
|
4097
|
+
return new CompositeDisposable(
|
4098
|
+
source.subscribe(function (newValue) {
|
4099
|
+
hasValue = true;
|
4100
|
+
value = newValue;
|
4101
|
+
}, observer.onError.bind(observer), function () {
|
4102
|
+
atEnd = true;
|
4103
|
+
}),
|
4104
|
+
sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
|
4105
|
+
);
|
4106
|
+
});
|
4107
|
+
}
|
4108
|
+
|
4109
|
+
/**
|
4110
|
+
* Samples the observable sequence at each interval.
|
4111
|
+
*
|
4112
|
+
* @example
|
4113
|
+
* 1 - res = source.sample(sampleObservable); // Sampler tick sequence
|
4114
|
+
* 2 - res = source.sample(5000); // 5 seconds
|
4115
|
+
* 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds
|
4116
|
+
*
|
4117
|
+
* @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable.
|
4118
|
+
* @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
|
4119
|
+
* @returns {Observable} Sampled observable sequence.
|
4120
|
+
*/
|
4121
|
+
observableProto.sample = function (intervalOrSampler, scheduler) {
|
4122
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4123
|
+
return typeof intervalOrSampler === 'number' ?
|
4124
|
+
sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
|
4125
|
+
sampleObservable(this, intervalOrSampler);
|
4126
|
+
};
|
4127
|
+
|
4128
|
+
/**
|
4129
|
+
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
4130
|
+
*
|
4131
|
+
* @example
|
4132
|
+
* 1 - res = source.timeout(new Date()); // As a date
|
4133
|
+
* 2 - res = source.timeout(5000); // 5 seconds
|
4134
|
+
* 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
|
4135
|
+
* 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
|
4136
|
+
* 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
|
4087
4137
|
* 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
|
4088
4138
|
*
|
4089
4139
|
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
|
@@ -4093,7 +4143,7 @@
|
|
4093
4143
|
*/
|
4094
4144
|
observableProto.timeout = function (dueTime, other, scheduler) {
|
4095
4145
|
other || (other = observableThrow(new Error('Timeout')));
|
4096
|
-
scheduler || (scheduler = timeoutScheduler);
|
4146
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4097
4147
|
|
4098
4148
|
var source = this, schedulerMethod = dueTime instanceof Date ?
|
4099
4149
|
'scheduleWithAbsolute' :
|
@@ -4141,76 +4191,74 @@
|
|
4141
4191
|
});
|
4142
4192
|
};
|
4143
4193
|
|
4144
|
-
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
4173
|
-
observer.onNext(result);
|
4174
|
-
}
|
4175
|
-
try {
|
4176
|
-
if (first) {
|
4177
|
-
first = false;
|
4178
|
-
} else {
|
4179
|
-
state = iterate(state);
|
4180
|
-
}
|
4181
|
-
hasResult = condition(state);
|
4182
|
-
if (hasResult) {
|
4183
|
-
result = resultSelector(state);
|
4184
|
-
time = timeSelector(state);
|
4185
|
-
}
|
4186
|
-
} catch (e) {
|
4187
|
-
observer.onError(e);
|
4188
|
-
return;
|
4189
|
-
}
|
4190
|
-
if (hasResult) {
|
4191
|
-
self(time);
|
4192
|
-
} else {
|
4193
|
-
observer.onCompleted();
|
4194
|
-
}
|
4195
|
-
});
|
4196
|
-
});
|
4197
|
-
};
|
4194
|
+
/**
|
4195
|
+
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
4196
|
+
*
|
4197
|
+
* @example
|
4198
|
+
* res = source.generateWithRelativeTime(0,
|
4199
|
+
* function (x) { return return true; },
|
4200
|
+
* function (x) { return x + 1; },
|
4201
|
+
* function (x) { return x; },
|
4202
|
+
* function (x) { return 500; }
|
4203
|
+
* );
|
4204
|
+
*
|
4205
|
+
* @param {Mixed} initialState Initial state.
|
4206
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
4207
|
+
* @param {Function} iterate Iteration step function.
|
4208
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
4209
|
+
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning integer values denoting milliseconds.
|
4210
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
4211
|
+
* @returns {Observable} The generated sequence.
|
4212
|
+
*/
|
4213
|
+
Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
4214
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4215
|
+
return new AnonymousObservable(function (observer) {
|
4216
|
+
var first = true,
|
4217
|
+
hasResult = false,
|
4218
|
+
result,
|
4219
|
+
state = initialState,
|
4220
|
+
time;
|
4221
|
+
return scheduler.scheduleRecursiveWithRelative(0, function (self) {
|
4222
|
+
hasResult && observer.onNext(result);
|
4198
4223
|
|
4199
|
-
|
4200
|
-
|
4201
|
-
|
4202
|
-
|
4203
|
-
|
4204
|
-
|
4205
|
-
|
4206
|
-
|
4207
|
-
|
4208
|
-
|
4209
|
-
|
4210
|
-
|
4211
|
-
|
4212
|
-
|
4213
|
-
|
4224
|
+
try {
|
4225
|
+
if (first) {
|
4226
|
+
first = false;
|
4227
|
+
} else {
|
4228
|
+
state = iterate(state);
|
4229
|
+
}
|
4230
|
+
hasResult = condition(state);
|
4231
|
+
if (hasResult) {
|
4232
|
+
result = resultSelector(state);
|
4233
|
+
time = timeSelector(state);
|
4234
|
+
}
|
4235
|
+
} catch (e) {
|
4236
|
+
observer.onError(e);
|
4237
|
+
return;
|
4238
|
+
}
|
4239
|
+
if (hasResult) {
|
4240
|
+
self(time);
|
4241
|
+
} else {
|
4242
|
+
observer.onCompleted();
|
4243
|
+
}
|
4244
|
+
});
|
4245
|
+
});
|
4246
|
+
};
|
4247
|
+
|
4248
|
+
/**
|
4249
|
+
* Time shifts the observable sequence by delaying the subscription.
|
4250
|
+
*
|
4251
|
+
* @example
|
4252
|
+
* 1 - res = source.delaySubscription(5000); // 5s
|
4253
|
+
* 2 - res = source.delaySubscription(5000, Rx.Scheduler.timeout); // 5 seconds
|
4254
|
+
*
|
4255
|
+
* @param {Number} dueTime Absolute or relative time to perform the subscription at.
|
4256
|
+
* @param {Scheduler} [scheduler] Scheduler to run the subscription delay timer on. If not specified, the timeout scheduler is used.
|
4257
|
+
* @returns {Observable} Time-shifted sequence.
|
4258
|
+
*/
|
4259
|
+
observableProto.delaySubscription = function (dueTime, scheduler) {
|
4260
|
+
return this.delayWithSelector(observableTimer(dueTime, isScheduler(scheduler) ? scheduler : timeoutScheduler), observableEmpty);
|
4261
|
+
};
|
4214
4262
|
|
4215
4263
|
/**
|
4216
4264
|
* Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
|
@@ -4356,96 +4404,96 @@
|
|
4356
4404
|
});
|
4357
4405
|
};
|
4358
4406
|
|
4359
|
-
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
|
4364
|
-
|
4365
|
-
|
4366
|
-
|
4367
|
-
|
4368
|
-
|
4369
|
-
|
4370
|
-
|
4371
|
-
|
4372
|
-
|
4373
|
-
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
|
4389
|
-
|
4390
|
-
|
4391
|
-
|
4392
|
-
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4396
|
-
|
4397
|
-
|
4398
|
-
|
4399
|
-
|
4400
|
-
|
4401
|
-
|
4402
|
-
|
4403
|
-
|
4404
|
-
|
4405
|
-
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4407
|
+
/**
|
4408
|
+
* Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
|
4409
|
+
*
|
4410
|
+
* @example
|
4411
|
+
* 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
|
4412
|
+
*
|
4413
|
+
* @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
|
4414
|
+
* @returns {Observable} The throttled sequence.
|
4415
|
+
*/
|
4416
|
+
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
4417
|
+
var source = this;
|
4418
|
+
return new AnonymousObservable(function (observer) {
|
4419
|
+
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
|
4420
|
+
var throttle;
|
4421
|
+
try {
|
4422
|
+
throttle = throttleDurationSelector(x);
|
4423
|
+
} catch (e) {
|
4424
|
+
observer.onError(e);
|
4425
|
+
return;
|
4426
|
+
}
|
4427
|
+
hasValue = true;
|
4428
|
+
value = x;
|
4429
|
+
id++;
|
4430
|
+
var currentid = id, d = new SingleAssignmentDisposable();
|
4431
|
+
cancelable.setDisposable(d);
|
4432
|
+
d.setDisposable(throttle.subscribe(function () {
|
4433
|
+
if (hasValue && id === currentid) {
|
4434
|
+
observer.onNext(value);
|
4435
|
+
}
|
4436
|
+
hasValue = false;
|
4437
|
+
d.dispose();
|
4438
|
+
}, observer.onError.bind(observer), function () {
|
4439
|
+
if (hasValue && id === currentid) {
|
4440
|
+
observer.onNext(value);
|
4441
|
+
}
|
4442
|
+
hasValue = false;
|
4443
|
+
d.dispose();
|
4444
|
+
}));
|
4445
|
+
}, function (e) {
|
4446
|
+
cancelable.dispose();
|
4447
|
+
observer.onError(e);
|
4448
|
+
hasValue = false;
|
4449
|
+
id++;
|
4450
|
+
}, function () {
|
4451
|
+
cancelable.dispose();
|
4452
|
+
if (hasValue) {
|
4453
|
+
observer.onNext(value);
|
4454
|
+
}
|
4455
|
+
observer.onCompleted();
|
4456
|
+
hasValue = false;
|
4457
|
+
id++;
|
4458
|
+
});
|
4459
|
+
return new CompositeDisposable(subscription, cancelable);
|
4460
|
+
});
|
4461
|
+
};
|
4414
4462
|
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4439
|
-
|
4440
|
-
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4444
|
-
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4448
|
-
|
4463
|
+
/**
|
4464
|
+
* Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
4465
|
+
*
|
4466
|
+
* 1 - res = source.skipLastWithTime(5000);
|
4467
|
+
* 2 - res = source.skipLastWithTime(5000, scheduler);
|
4468
|
+
*
|
4469
|
+
* @description
|
4470
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4471
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
4472
|
+
* result sequence. This causes elements to be delayed with duration.
|
4473
|
+
* @param {Number} duration Duration for skipping elements from the end of the sequence.
|
4474
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout
|
4475
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the end of the source sequence.
|
4476
|
+
*/
|
4477
|
+
observableProto.skipLastWithTime = function (duration, scheduler) {
|
4478
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4479
|
+
var source = this;
|
4480
|
+
return new AnonymousObservable(function (observer) {
|
4481
|
+
var q = [];
|
4482
|
+
return source.subscribe(function (x) {
|
4483
|
+
var now = scheduler.now();
|
4484
|
+
q.push({ interval: now, value: x });
|
4485
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
4486
|
+
observer.onNext(q.shift().value);
|
4487
|
+
}
|
4488
|
+
}, observer.onError.bind(observer), function () {
|
4489
|
+
var now = scheduler.now();
|
4490
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
4491
|
+
observer.onNext(q.shift().value);
|
4492
|
+
}
|
4493
|
+
observer.onCompleted();
|
4494
|
+
});
|
4495
|
+
});
|
4496
|
+
};
|
4449
4497
|
|
4450
4498
|
/**
|
4451
4499
|
* 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.
|
@@ -4465,102 +4513,93 @@
|
|
4465
4513
|
return this.takeLastBufferWithTime(duration, timerScheduler).selectMany(function (xs) { return observableFromArray(xs, loopScheduler); });
|
4466
4514
|
};
|
4467
4515
|
|
4468
|
-
|
4469
|
-
|
4470
|
-
|
4471
|
-
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
return source.subscribe(function (x) {
|
4488
|
-
var now = scheduler.now();
|
4489
|
-
q.push({ interval: now, value: x });
|
4490
|
-
while (q.length > 0 && now - q[0].interval >= duration) {
|
4491
|
-
q.shift();
|
4492
|
-
}
|
4493
|
-
}, observer.onError.bind(observer), function () {
|
4494
|
-
var now = scheduler.now(), res = [];
|
4495
|
-
while (q.length > 0) {
|
4496
|
-
var next = q.shift();
|
4497
|
-
if (now - next.interval <= duration) {
|
4498
|
-
res.push(next.value);
|
4499
|
-
}
|
4500
|
-
}
|
4501
|
-
|
4502
|
-
observer.onNext(res);
|
4503
|
-
observer.onCompleted();
|
4504
|
-
});
|
4505
|
-
});
|
4506
|
-
};
|
4516
|
+
/**
|
4517
|
+
* 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.
|
4518
|
+
*
|
4519
|
+
* @example
|
4520
|
+
* 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
|
4521
|
+
* @description
|
4522
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4523
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
4524
|
+
* result sequence. This causes elements to be delayed with duration.
|
4525
|
+
* @param {Number} duration Duration for taking elements from the end of the sequence.
|
4526
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4527
|
+
* @returns {Observable} An observable sequence containing a single array with the elements taken during the specified duration from the end of the source sequence.
|
4528
|
+
*/
|
4529
|
+
observableProto.takeLastBufferWithTime = function (duration, scheduler) {
|
4530
|
+
var source = this;
|
4531
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4532
|
+
return new AnonymousObservable(function (observer) {
|
4533
|
+
var q = [];
|
4507
4534
|
|
4508
|
-
|
4509
|
-
|
4510
|
-
|
4511
|
-
|
4512
|
-
|
4513
|
-
|
4514
|
-
|
4515
|
-
|
4516
|
-
|
4517
|
-
|
4518
|
-
|
4519
|
-
|
4520
|
-
|
4521
|
-
|
4522
|
-
var source = this;
|
4523
|
-
scheduler || (scheduler = timeoutScheduler);
|
4524
|
-
return new AnonymousObservable(function (observer) {
|
4525
|
-
var t = scheduler.scheduleWithRelative(duration, function () {
|
4526
|
-
observer.onCompleted();
|
4527
|
-
});
|
4535
|
+
return source.subscribe(function (x) {
|
4536
|
+
var now = scheduler.now();
|
4537
|
+
q.push({ interval: now, value: x });
|
4538
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
4539
|
+
q.shift();
|
4540
|
+
}
|
4541
|
+
}, observer.onError.bind(observer), function () {
|
4542
|
+
var now = scheduler.now(), res = [];
|
4543
|
+
while (q.length > 0) {
|
4544
|
+
var next = q.shift();
|
4545
|
+
if (now - next.interval <= duration) {
|
4546
|
+
res.push(next.value);
|
4547
|
+
}
|
4548
|
+
}
|
4528
4549
|
|
4529
|
-
|
4530
|
-
|
4531
|
-
|
4550
|
+
observer.onNext(res);
|
4551
|
+
observer.onCompleted();
|
4552
|
+
});
|
4553
|
+
});
|
4554
|
+
};
|
4532
4555
|
|
4533
|
-
|
4534
|
-
|
4535
|
-
|
4536
|
-
|
4537
|
-
|
4538
|
-
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4546
|
-
|
4547
|
-
|
4548
|
-
|
4549
|
-
|
4550
|
-
|
4551
|
-
|
4552
|
-
|
4553
|
-
var open = false,
|
4554
|
-
t = scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
4555
|
-
d = source.subscribe(function (x) {
|
4556
|
-
if (open) {
|
4557
|
-
observer.onNext(x);
|
4558
|
-
}
|
4559
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4556
|
+
/**
|
4557
|
+
* Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
4558
|
+
*
|
4559
|
+
* @example
|
4560
|
+
* 1 - res = source.takeWithTime(5000, [optional scheduler]);
|
4561
|
+
* @description
|
4562
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4563
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
4564
|
+
* result sequence. This causes elements to be delayed with duration.
|
4565
|
+
* @param {Number} duration Duration for taking elements from the start of the sequence.
|
4566
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4567
|
+
* @returns {Observable} An observable sequence with the elements taken during the specified duration from the start of the source sequence.
|
4568
|
+
*/
|
4569
|
+
observableProto.takeWithTime = function (duration, scheduler) {
|
4570
|
+
var source = this;
|
4571
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4572
|
+
return new AnonymousObservable(function (observer) {
|
4573
|
+
return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
|
4574
|
+
});
|
4575
|
+
};
|
4560
4576
|
|
4561
|
-
|
4562
|
-
|
4563
|
-
|
4577
|
+
/**
|
4578
|
+
* Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
4579
|
+
*
|
4580
|
+
* @example
|
4581
|
+
* 1 - res = source.skipWithTime(5000, [optional scheduler]);
|
4582
|
+
*
|
4583
|
+
* @description
|
4584
|
+
* Specifying a zero value for duration doesn't guarantee no elements will be dropped from the start of the source sequence.
|
4585
|
+
* 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
|
4586
|
+
* may not execute immediately, despite the zero due time.
|
4587
|
+
*
|
4588
|
+
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the duration.
|
4589
|
+
* @param {Number} duration Duration for skipping elements from the start of the sequence.
|
4590
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
4591
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the start of the source sequence.
|
4592
|
+
*/
|
4593
|
+
observableProto.skipWithTime = function (duration, scheduler) {
|
4594
|
+
var source = this;
|
4595
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4596
|
+
return new AnonymousObservable(function (observer) {
|
4597
|
+
var open = false;
|
4598
|
+
return new CompositeDisposable(
|
4599
|
+
scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
4600
|
+
source.subscribe(function (x) { open && observer.onNext(x); }, observer.onError.bind(observer), observer.onCompleted.bind(observer)));
|
4601
|
+
});
|
4602
|
+
};
|
4564
4603
|
|
4565
4604
|
/**
|
4566
4605
|
* Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
|
@@ -4574,7 +4613,7 @@
|
|
4574
4613
|
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
4575
4614
|
*/
|
4576
4615
|
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
4577
|
-
scheduler || (scheduler = timeoutScheduler);
|
4616
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4578
4617
|
var source = this, schedulerMethod = startTime instanceof Date ?
|
4579
4618
|
'scheduleWithAbsolute' :
|
4580
4619
|
'scheduleWithRelative';
|
@@ -4601,7 +4640,7 @@
|
|
4601
4640
|
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
4602
4641
|
*/
|
4603
4642
|
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
4604
|
-
scheduler || (scheduler = timeoutScheduler);
|
4643
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4605
4644
|
var source = this, schedulerMethod = endTime instanceof Date ?
|
4606
4645
|
'scheduleWithAbsolute' :
|
4607
4646
|
'scheduleWithRelative';
|
@@ -5012,6 +5051,116 @@
|
|
5012
5051
|
];
|
5013
5052
|
};
|
5014
5053
|
|
5054
|
+
/*
|
5055
|
+
* Performs a exclusive waiting for the first to finish before subscribing to another observable.
|
5056
|
+
* Observables that come in between subscriptions will be dropped on the floor.
|
5057
|
+
* @returns {Observable} A exclusive observable with only the results that happen when subscribed.
|
5058
|
+
*/
|
5059
|
+
observableProto.exclusive = function () {
|
5060
|
+
var sources = this;
|
5061
|
+
return new AnonymousObservable(function (observer) {
|
5062
|
+
var hasCurrent = false,
|
5063
|
+
isStopped = false,
|
5064
|
+
m = new SingleAssignmentDisposable(),
|
5065
|
+
g = new CompositeDisposable();
|
5066
|
+
|
5067
|
+
g.add(m);
|
5068
|
+
|
5069
|
+
m.setDisposable(sources.subscribe(
|
5070
|
+
function (innerSource) {
|
5071
|
+
if (!hasCurrent) {
|
5072
|
+
hasCurrent = true;
|
5073
|
+
|
5074
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
5075
|
+
|
5076
|
+
var innerSubscription = new SingleAssignmentDisposable();
|
5077
|
+
g.add(innerSubscription);
|
5078
|
+
|
5079
|
+
innerSubscription.setDisposable(innerSource.subscribe(
|
5080
|
+
observer.onNext.bind(observer),
|
5081
|
+
observer.onError.bind(observer),
|
5082
|
+
function () {
|
5083
|
+
g.remove(innerSubscription);
|
5084
|
+
hasCurrent = false;
|
5085
|
+
if (isStopped && g.length === 1) {
|
5086
|
+
observer.onCompleted();
|
5087
|
+
}
|
5088
|
+
}));
|
5089
|
+
}
|
5090
|
+
},
|
5091
|
+
observer.onError.bind(observer),
|
5092
|
+
function () {
|
5093
|
+
isStopped = true;
|
5094
|
+
if (!hasCurrent && g.length === 1) {
|
5095
|
+
observer.onCompleted();
|
5096
|
+
}
|
5097
|
+
}));
|
5098
|
+
|
5099
|
+
return g;
|
5100
|
+
});
|
5101
|
+
};
|
5102
|
+
/*
|
5103
|
+
* Performs a exclusive map waiting for the first to finish before subscribing to another observable.
|
5104
|
+
* Observables that come in between subscriptions will be dropped on the floor.
|
5105
|
+
* @param {Function} selector Selector to invoke for every item in the current subscription.
|
5106
|
+
* @param {Any} [thisArg] An optional context to invoke with the selector parameter.
|
5107
|
+
* @returns {Observable} An exclusive observable with only the results that happen when subscribed.
|
5108
|
+
*/
|
5109
|
+
observableProto.exclusiveMap = function (selector, thisArg) {
|
5110
|
+
var sources = this;
|
5111
|
+
return new AnonymousObservable(function (observer) {
|
5112
|
+
var index = 0,
|
5113
|
+
hasCurrent = false,
|
5114
|
+
isStopped = true,
|
5115
|
+
m = new SingleAssignmentDisposable(),
|
5116
|
+
g = new CompositeDisposable();
|
5117
|
+
|
5118
|
+
g.add(m);
|
5119
|
+
|
5120
|
+
m.setDisposable(sources.subscribe(
|
5121
|
+
function (innerSource) {
|
5122
|
+
|
5123
|
+
if (!hasCurrent) {
|
5124
|
+
hasCurrent = true;
|
5125
|
+
|
5126
|
+
innerSubscription = new SingleAssignmentDisposable();
|
5127
|
+
g.add(innerSubscription);
|
5128
|
+
|
5129
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
5130
|
+
|
5131
|
+
innerSubscription.setDisposable(innerSource.subscribe(
|
5132
|
+
function (x) {
|
5133
|
+
var result;
|
5134
|
+
try {
|
5135
|
+
result = selector.call(thisArg, x, index++, innerSource);
|
5136
|
+
} catch (e) {
|
5137
|
+
observer.onError(e);
|
5138
|
+
return;
|
5139
|
+
}
|
5140
|
+
|
5141
|
+
observer.onNext(result);
|
5142
|
+
},
|
5143
|
+
observer.onError.bind(observer),
|
5144
|
+
function () {
|
5145
|
+
g.remove(innerSubscription);
|
5146
|
+
hasCurrent = false;
|
5147
|
+
|
5148
|
+
if (isStopped && g.length === 1) {
|
5149
|
+
observer.onCompleted();
|
5150
|
+
}
|
5151
|
+
}));
|
5152
|
+
}
|
5153
|
+
},
|
5154
|
+
observer.onError.bind(observer),
|
5155
|
+
function () {
|
5156
|
+
isStopped = true;
|
5157
|
+
if (g.length === 1 && !hasCurrent) {
|
5158
|
+
observer.onCompleted();
|
5159
|
+
}
|
5160
|
+
}));
|
5161
|
+
return g;
|
5162
|
+
});
|
5163
|
+
};
|
5015
5164
|
var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
|
5016
5165
|
inherits(AnonymousObservable, __super__);
|
5017
5166
|
|
@@ -5032,25 +5181,21 @@
|
|
5032
5181
|
}
|
5033
5182
|
|
5034
5183
|
function s(observer) {
|
5035
|
-
var
|
5036
|
-
if (currentThreadScheduler.scheduleRequired()) {
|
5037
|
-
currentThreadScheduler.schedule(function () {
|
5038
|
-
try {
|
5039
|
-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
5040
|
-
} catch (e) {
|
5041
|
-
if (!autoDetachObserver.fail(e)) {
|
5042
|
-
throw e;
|
5043
|
-
}
|
5044
|
-
}
|
5045
|
-
});
|
5046
|
-
} else {
|
5184
|
+
var setDisposable = function () {
|
5047
5185
|
try {
|
5048
5186
|
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
5049
5187
|
} catch (e) {
|
5050
5188
|
if (!autoDetachObserver.fail(e)) {
|
5051
5189
|
throw e;
|
5052
|
-
}
|
5190
|
+
}
|
5053
5191
|
}
|
5192
|
+
};
|
5193
|
+
|
5194
|
+
var autoDetachObserver = new AutoDetachObserver(observer);
|
5195
|
+
if (currentThreadScheduler.scheduleRequired()) {
|
5196
|
+
currentThreadScheduler.schedule(setDisposable);
|
5197
|
+
} else {
|
5198
|
+
setDisposable();
|
5054
5199
|
}
|
5055
5200
|
|
5056
5201
|
return autoDetachObserver;
|