rxjs-rails 2.3.9 → 2.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rxjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rx.aggregates.js +174 -204
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +1626 -1528
- data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
- data/vendor/assets/javascripts/rx.all.js +1624 -1526
- data/vendor/assets/javascripts/rx.all.min.js +3 -3
- data/vendor/assets/javascripts/rx.async.compat.js +241 -0
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +241 -0
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.js +3 -3
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +350 -378
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.js +16 -21
- data/vendor/assets/javascripts/rx.compat.js +633 -683
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.js +633 -683
- data/vendor/assets/javascripts/rx.lite.compat.js +941 -1137
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.js +58 -74
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +941 -1137
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.time.js +182 -212
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- metadata +10 -10
@@ -43,7 +43,22 @@
|
|
43
43
|
defaultError = Rx.helpers.defaultError = function (err) { throw err; },
|
44
44
|
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'; },
|
45
45
|
asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
|
46
|
-
not = Rx.helpers.not = function (a) { return !a; }
|
46
|
+
not = Rx.helpers.not = function (a) { return !a; },
|
47
|
+
isFunction = Rx.helpers.isFunction = (function () {
|
48
|
+
|
49
|
+
var isFn = function (value) {
|
50
|
+
return typeof value == 'function' || false;
|
51
|
+
}
|
52
|
+
|
53
|
+
// fallback for older versions of Chrome and Safari
|
54
|
+
if (isFn(/x/)) {
|
55
|
+
isFn = function(value) {
|
56
|
+
return typeof value == 'function' && toString.call(value) == '[object Function]';
|
57
|
+
};
|
58
|
+
}
|
59
|
+
|
60
|
+
return isFn;
|
61
|
+
}());
|
47
62
|
|
48
63
|
// Errors
|
49
64
|
var sequenceContainsNoElements = 'Sequence contains no elements.';
|
@@ -198,18 +213,7 @@
|
|
198
213
|
isArguments = function(value) {
|
199
214
|
return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
|
200
215
|
};
|
201
|
-
}
|
202
|
-
|
203
|
-
function isFunction(value) {
|
204
|
-
return typeof value == 'function' || false;
|
205
|
-
}
|
206
|
-
|
207
|
-
// fallback for older versions of Chrome and Safari
|
208
|
-
if (isFunction(/x/)) {
|
209
|
-
isFunction = function(value) {
|
210
|
-
return typeof value == 'function' && toString.call(value) == funcClass;
|
211
|
-
};
|
212
|
-
}
|
216
|
+
}
|
213
217
|
|
214
218
|
var isEqual = Rx.internals.isEqual = function (x, y) {
|
215
219
|
return deepEquals(x, y, [], []);
|
@@ -395,101 +399,91 @@
|
|
395
399
|
return a;
|
396
400
|
}
|
397
401
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
402
|
+
// Collections
|
403
|
+
function IndexedItem(id, value) {
|
404
|
+
this.id = id;
|
405
|
+
this.value = value;
|
406
|
+
}
|
403
407
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
return c;
|
410
|
-
};
|
408
|
+
IndexedItem.prototype.compareTo = function (other) {
|
409
|
+
var c = this.value.compareTo(other.value);
|
410
|
+
c === 0 && (c = this.id - other.id);
|
411
|
+
return c;
|
412
|
+
};
|
411
413
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
414
|
+
// Priority Queue for Scheduling
|
415
|
+
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
416
|
+
this.items = new Array(capacity);
|
417
|
+
this.length = 0;
|
418
|
+
};
|
417
419
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
420
|
+
var priorityProto = PriorityQueue.prototype;
|
421
|
+
priorityProto.isHigherPriority = function (left, right) {
|
422
|
+
return this.items[left].compareTo(this.items[right]) < 0;
|
423
|
+
};
|
422
424
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
this.items[parent] = temp;
|
435
|
-
this.percolate(parent);
|
436
|
-
}
|
437
|
-
};
|
425
|
+
priorityProto.percolate = function (index) {
|
426
|
+
if (index >= this.length || index < 0) { return; }
|
427
|
+
var parent = index - 1 >> 1;
|
428
|
+
if (parent < 0 || parent === index) { return; }
|
429
|
+
if (this.isHigherPriority(index, parent)) {
|
430
|
+
var temp = this.items[index];
|
431
|
+
this.items[index] = this.items[parent];
|
432
|
+
this.items[parent] = temp;
|
433
|
+
this.percolate(parent);
|
434
|
+
}
|
435
|
+
};
|
438
436
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
}
|
461
|
-
};
|
462
|
-
|
463
|
-
priorityProto.peek = function () { return this.items[0].value; };
|
437
|
+
priorityProto.heapify = function (index) {
|
438
|
+
+index || (index = 0);
|
439
|
+
if (index >= this.length || index < 0) { return; }
|
440
|
+
var left = 2 * index + 1,
|
441
|
+
right = 2 * index + 2,
|
442
|
+
first = index;
|
443
|
+
if (left < this.length && this.isHigherPriority(left, first)) {
|
444
|
+
first = left;
|
445
|
+
}
|
446
|
+
if (right < this.length && this.isHigherPriority(right, first)) {
|
447
|
+
first = right;
|
448
|
+
}
|
449
|
+
if (first !== index) {
|
450
|
+
var temp = this.items[index];
|
451
|
+
this.items[index] = this.items[first];
|
452
|
+
this.items[first] = temp;
|
453
|
+
this.heapify(first);
|
454
|
+
}
|
455
|
+
};
|
456
|
+
|
457
|
+
priorityProto.peek = function () { return this.items[0].value; };
|
464
458
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
459
|
+
priorityProto.removeAt = function (index) {
|
460
|
+
this.items[index] = this.items[--this.length];
|
461
|
+
delete this.items[this.length];
|
462
|
+
this.heapify();
|
463
|
+
};
|
470
464
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
465
|
+
priorityProto.dequeue = function () {
|
466
|
+
var result = this.peek();
|
467
|
+
this.removeAt(0);
|
468
|
+
return result;
|
469
|
+
};
|
476
470
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
471
|
+
priorityProto.enqueue = function (item) {
|
472
|
+
var index = this.length++;
|
473
|
+
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
474
|
+
this.percolate(index);
|
475
|
+
};
|
482
476
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
477
|
+
priorityProto.remove = function (item) {
|
478
|
+
for (var i = 0; i < this.length; i++) {
|
479
|
+
if (this.items[i].value === item) {
|
480
|
+
this.removeAt(i);
|
481
|
+
return true;
|
482
|
+
}
|
483
|
+
}
|
484
|
+
return false;
|
485
|
+
};
|
486
|
+
PriorityQueue.count = 0;
|
493
487
|
/**
|
494
488
|
* Represents a group of disposable resources that are disposed together.
|
495
489
|
* @constructor
|
@@ -558,39 +552,38 @@
|
|
558
552
|
return this.disposables.slice(0);
|
559
553
|
};
|
560
554
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
555
|
+
/**
|
556
|
+
* Provides a set of static methods for creating Disposables.
|
557
|
+
*
|
558
|
+
* @constructor
|
559
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
560
|
+
*/
|
561
|
+
var Disposable = Rx.Disposable = function (action) {
|
562
|
+
this.isDisposed = false;
|
563
|
+
this.action = action || noop;
|
564
|
+
};
|
571
565
|
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
566
|
+
/** Performs the task of cleaning up resources. */
|
567
|
+
Disposable.prototype.dispose = function () {
|
568
|
+
if (!this.isDisposed) {
|
569
|
+
this.action();
|
570
|
+
this.isDisposed = true;
|
571
|
+
}
|
572
|
+
};
|
579
573
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
574
|
+
/**
|
575
|
+
* Creates a disposable object that invokes the specified action when disposed.
|
576
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
577
|
+
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
578
|
+
*/
|
579
|
+
var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
|
586
580
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
581
|
+
/**
|
582
|
+
* Gets the disposable that does nothing when disposed.
|
583
|
+
*/
|
584
|
+
var disposableEmpty = Disposable.empty = { dispose: noop };
|
591
585
|
|
592
|
-
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable =
|
593
|
-
SerialDisposable = Rx.SerialDisposable = (function () {
|
586
|
+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function () {
|
594
587
|
function BooleanDisposable () {
|
595
588
|
this.isDisposed = false;
|
596
589
|
this.current = null;
|
@@ -635,6 +628,7 @@
|
|
635
628
|
|
636
629
|
return BooleanDisposable;
|
637
630
|
}());
|
631
|
+
var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
|
638
632
|
/**
|
639
633
|
* Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
|
640
634
|
*/
|
@@ -1003,6 +997,7 @@
|
|
1003
997
|
}(Scheduler.prototype));
|
1004
998
|
|
1005
999
|
(function (schedulerProto) {
|
1000
|
+
|
1006
1001
|
/**
|
1007
1002
|
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
1008
1003
|
* @param {Number} period Period for running the work periodically.
|
@@ -1020,17 +1015,19 @@
|
|
1020
1015
|
* @param {Function} action Action to be executed, potentially updating the state.
|
1021
1016
|
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1022
1017
|
*/
|
1023
|
-
Scheduler.prototype.schedulePeriodicWithState = function
|
1018
|
+
Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
|
1019
|
+
if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
|
1024
1020
|
var s = state;
|
1025
|
-
|
1026
|
-
var id = setInterval(function () {
|
1021
|
+
|
1022
|
+
var id = root.setInterval(function () {
|
1027
1023
|
s = action(s);
|
1028
1024
|
}, period);
|
1029
1025
|
|
1030
1026
|
return disposableCreate(function () {
|
1031
|
-
clearInterval(id);
|
1027
|
+
root.clearInterval(id);
|
1032
1028
|
});
|
1033
1029
|
};
|
1030
|
+
|
1034
1031
|
}(Scheduler.prototype));
|
1035
1032
|
|
1036
1033
|
(function (schedulerProto) {
|
@@ -1152,100 +1149,121 @@
|
|
1152
1149
|
return currentScheduler;
|
1153
1150
|
}());
|
1154
1151
|
|
1155
|
-
|
1156
1152
|
var scheduleMethod, clearMethod = noop;
|
1157
|
-
(function () {
|
1153
|
+
var localTimer = (function () {
|
1154
|
+
var localSetTimeout, localClearTimeout = noop;
|
1155
|
+
if ('WScript' in this) {
|
1156
|
+
localSetTimeout = function (fn, time) {
|
1157
|
+
WScript.Sleep(time);
|
1158
|
+
fn();
|
1159
|
+
};
|
1160
|
+
} else if (!!root.setTimeout) {
|
1161
|
+
localSetTimeout = root.setTimeout;
|
1162
|
+
localClearTimeout = root.clearTimeout;
|
1163
|
+
} else {
|
1164
|
+
throw new Error('No concurrency detected!');
|
1165
|
+
}
|
1158
1166
|
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1167
|
+
return {
|
1168
|
+
setTimeout: localSetTimeout,
|
1169
|
+
clearTimeout: localClearTimeout
|
1170
|
+
};
|
1171
|
+
}());
|
1172
|
+
var localSetTimeout = localTimer.setTimeout,
|
1173
|
+
localClearTimeout = localTimer.clearTimeout;
|
1174
|
+
|
1175
|
+
(function () {
|
1176
|
+
|
1177
|
+
var reNative = RegExp('^' +
|
1178
|
+
String(toString)
|
1179
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1180
|
+
.replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1181
|
+
);
|
1182
|
+
|
1183
|
+
var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1184
|
+
!reNative.test(setImmediate) && setImmediate,
|
1185
|
+
clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
|
1186
|
+
!reNative.test(clearImmediate) && clearImmediate;
|
1187
|
+
|
1188
|
+
function postMessageSupported () {
|
1189
|
+
// Ensure not in a worker
|
1190
|
+
if (!root.postMessage || root.importScripts) { return false; }
|
1191
|
+
var isAsync = false,
|
1192
|
+
oldHandler = root.onmessage;
|
1193
|
+
// Test for async
|
1194
|
+
root.onmessage = function () { isAsync = true; };
|
1195
|
+
root.postMessage('','*');
|
1196
|
+
root.onmessage = oldHandler;
|
1197
|
+
|
1198
|
+
return isAsync;
|
1199
|
+
}
|
1164
1200
|
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1201
|
+
// Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
|
1202
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1203
|
+
scheduleMethod = process.nextTick;
|
1204
|
+
} else if (typeof setImmediate === 'function') {
|
1205
|
+
scheduleMethod = setImmediate;
|
1206
|
+
clearMethod = clearImmediate;
|
1207
|
+
} else if (postMessageSupported()) {
|
1208
|
+
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1209
|
+
tasks = {},
|
1210
|
+
taskId = 0;
|
1211
|
+
|
1212
|
+
function onGlobalPostMessage(event) {
|
1213
|
+
// Only if we're a match to avoid any other global events
|
1214
|
+
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1215
|
+
var handleId = event.data.substring(MSG_PREFIX.length),
|
1216
|
+
action = tasks[handleId];
|
1217
|
+
action();
|
1218
|
+
delete tasks[handleId];
|
1219
|
+
}
|
1181
1220
|
}
|
1182
1221
|
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
clearMethod = clearImmediate;
|
1189
|
-
} else if (postMessageSupported()) {
|
1190
|
-
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1191
|
-
tasks = {},
|
1192
|
-
taskId = 0;
|
1193
|
-
|
1194
|
-
function onGlobalPostMessage(event) {
|
1195
|
-
// Only if we're a match to avoid any other global events
|
1196
|
-
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1197
|
-
var handleId = event.data.substring(MSG_PREFIX.length),
|
1198
|
-
action = tasks[handleId];
|
1199
|
-
action();
|
1200
|
-
delete tasks[handleId];
|
1201
|
-
}
|
1202
|
-
}
|
1203
|
-
|
1204
|
-
if (root.addEventListener) {
|
1205
|
-
root.addEventListener('message', onGlobalPostMessage, false);
|
1206
|
-
} else {
|
1207
|
-
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1208
|
-
}
|
1222
|
+
if (root.addEventListener) {
|
1223
|
+
root.addEventListener('message', onGlobalPostMessage, false);
|
1224
|
+
} else {
|
1225
|
+
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1226
|
+
}
|
1209
1227
|
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1228
|
+
scheduleMethod = function (action) {
|
1229
|
+
var currentId = taskId++;
|
1230
|
+
tasks[currentId] = action;
|
1231
|
+
root.postMessage(MSG_PREFIX + currentId, '*');
|
1232
|
+
};
|
1233
|
+
} else if (!!root.MessageChannel) {
|
1234
|
+
var channel = new root.MessageChannel(),
|
1235
|
+
channelTasks = {},
|
1236
|
+
channelTaskId = 0;
|
1237
|
+
|
1238
|
+
channel.port1.onmessage = function (event) {
|
1239
|
+
var id = event.data,
|
1240
|
+
action = channelTasks[id];
|
1241
|
+
action();
|
1242
|
+
delete channelTasks[id];
|
1243
|
+
};
|
1226
1244
|
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
};
|
1242
|
-
root.document.documentElement.appendChild(scriptElement);
|
1245
|
+
scheduleMethod = function (action) {
|
1246
|
+
var id = channelTaskId++;
|
1247
|
+
channelTasks[id] = action;
|
1248
|
+
channel.port2.postMessage(id);
|
1249
|
+
};
|
1250
|
+
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1251
|
+
|
1252
|
+
scheduleMethod = function (action) {
|
1253
|
+
var scriptElement = root.document.createElement('script');
|
1254
|
+
scriptElement.onreadystatechange = function () {
|
1255
|
+
action();
|
1256
|
+
scriptElement.onreadystatechange = null;
|
1257
|
+
scriptElement.parentNode.removeChild(scriptElement);
|
1258
|
+
scriptElement = null;
|
1243
1259
|
};
|
1260
|
+
root.document.documentElement.appendChild(scriptElement);
|
1261
|
+
};
|
1244
1262
|
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1263
|
+
} else {
|
1264
|
+
scheduleMethod = function (action) { return localSetTimeout(action, 0); };
|
1265
|
+
clearMethod = localClearTimeout;
|
1266
|
+
}
|
1249
1267
|
}());
|
1250
1268
|
|
1251
1269
|
/**
|
@@ -1254,33 +1272,33 @@
|
|
1254
1272
|
var timeoutScheduler = Scheduler.timeout = (function () {
|
1255
1273
|
|
1256
1274
|
function scheduleNow(state, action) {
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1275
|
+
var scheduler = this,
|
1276
|
+
disposable = new SingleAssignmentDisposable();
|
1277
|
+
var id = scheduleMethod(function () {
|
1278
|
+
if (!disposable.isDisposed) {
|
1279
|
+
disposable.setDisposable(action(scheduler, state));
|
1280
|
+
}
|
1281
|
+
});
|
1282
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1283
|
+
clearMethod(id);
|
1284
|
+
}));
|
1267
1285
|
}
|
1268
1286
|
|
1269
1287
|
function scheduleRelative(state, dueTime, action) {
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1288
|
+
var scheduler = this,
|
1289
|
+
dt = Scheduler.normalize(dueTime);
|
1290
|
+
if (dt === 0) {
|
1291
|
+
return scheduler.scheduleWithState(state, action);
|
1292
|
+
}
|
1293
|
+
var disposable = new SingleAssignmentDisposable();
|
1294
|
+
var id = localSetTimeout(function () {
|
1295
|
+
if (!disposable.isDisposed) {
|
1296
|
+
disposable.setDisposable(action(scheduler, state));
|
1297
|
+
}
|
1298
|
+
}, dt);
|
1299
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1300
|
+
localClearTimeout(id);
|
1301
|
+
}));
|
1284
1302
|
}
|
1285
1303
|
|
1286
1304
|
function scheduleAbsolute(state, dueTime, action) {
|
@@ -1872,11 +1890,11 @@
|
|
1872
1890
|
return CheckedObserver;
|
1873
1891
|
}(Observer));
|
1874
1892
|
|
1875
|
-
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (
|
1876
|
-
inherits(ScheduledObserver,
|
1893
|
+
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
|
1894
|
+
inherits(ScheduledObserver, __super__);
|
1877
1895
|
|
1878
1896
|
function ScheduledObserver(scheduler, observer) {
|
1879
|
-
|
1897
|
+
__super__.call(this);
|
1880
1898
|
this.scheduler = scheduler;
|
1881
1899
|
this.observer = observer;
|
1882
1900
|
this.isAcquired = false;
|
@@ -1892,10 +1910,10 @@
|
|
1892
1910
|
});
|
1893
1911
|
};
|
1894
1912
|
|
1895
|
-
ScheduledObserver.prototype.error = function (
|
1913
|
+
ScheduledObserver.prototype.error = function (err) {
|
1896
1914
|
var self = this;
|
1897
1915
|
this.queue.push(function () {
|
1898
|
-
self.observer.onError(
|
1916
|
+
self.observer.onError(err);
|
1899
1917
|
});
|
1900
1918
|
};
|
1901
1919
|
|
@@ -1934,42 +1952,37 @@
|
|
1934
1952
|
};
|
1935
1953
|
|
1936
1954
|
ScheduledObserver.prototype.dispose = function () {
|
1937
|
-
|
1955
|
+
__super__.prototype.dispose.call(this);
|
1938
1956
|
this.disposable.dispose();
|
1939
1957
|
};
|
1940
1958
|
|
1941
1959
|
return ScheduledObserver;
|
1942
1960
|
}(AbstractObserver));
|
1943
1961
|
|
1944
|
-
|
1945
|
-
|
1946
|
-
inherits(ObserveOnObserver, _super);
|
1962
|
+
var ObserveOnObserver = (function (__super__) {
|
1963
|
+
inherits(ObserveOnObserver, __super__);
|
1947
1964
|
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
}
|
1965
|
+
function ObserveOnObserver() {
|
1966
|
+
__super__.apply(this, arguments);
|
1967
|
+
}
|
1952
1968
|
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
};
|
1969
|
+
ObserveOnObserver.prototype.next = function (value) {
|
1970
|
+
__super__.prototype.next.call(this, value);
|
1971
|
+
this.ensureActive();
|
1972
|
+
};
|
1958
1973
|
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
};
|
1974
|
+
ObserveOnObserver.prototype.error = function (e) {
|
1975
|
+
__super__.prototype.error.call(this, e);
|
1976
|
+
this.ensureActive();
|
1977
|
+
};
|
1964
1978
|
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
};
|
1979
|
+
ObserveOnObserver.prototype.completed = function () {
|
1980
|
+
__super__.prototype.completed.call(this);
|
1981
|
+
this.ensureActive();
|
1982
|
+
};
|
1970
1983
|
|
1971
|
-
|
1972
|
-
|
1984
|
+
return ObserveOnObserver;
|
1985
|
+
})(ScheduledObserver);
|
1973
1986
|
|
1974
1987
|
var observableProto;
|
1975
1988
|
|
@@ -2009,43 +2022,43 @@
|
|
2009
2022
|
return Observable;
|
2010
2023
|
})();
|
2011
2024
|
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2025
|
+
/**
|
2026
|
+
* Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
|
2027
|
+
*
|
2028
|
+
* This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
|
2029
|
+
* that require to be run on a scheduler, use subscribeOn.
|
2030
|
+
*
|
2031
|
+
* @param {Scheduler} scheduler Scheduler to notify observers on.
|
2032
|
+
* @returns {Observable} The source sequence whose observations happen on the specified scheduler.
|
2033
|
+
*/
|
2034
|
+
observableProto.observeOn = function (scheduler) {
|
2035
|
+
var source = this;
|
2036
|
+
return new AnonymousObservable(function (observer) {
|
2037
|
+
return source.subscribe(new ObserveOnObserver(scheduler, observer));
|
2038
|
+
});
|
2039
|
+
};
|
2027
2040
|
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2041
|
+
/**
|
2042
|
+
* Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
|
2043
|
+
* see the remarks section for more information on the distinction between subscribeOn and observeOn.
|
2031
2044
|
|
2032
|
-
|
2033
|
-
|
2045
|
+
* This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
|
2046
|
+
* callbacks on a scheduler, use observeOn.
|
2034
2047
|
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2048
|
+
* @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
|
2049
|
+
* @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
|
2050
|
+
*/
|
2051
|
+
observableProto.subscribeOn = function (scheduler) {
|
2052
|
+
var source = this;
|
2053
|
+
return new AnonymousObservable(function (observer) {
|
2054
|
+
var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
|
2055
|
+
d.setDisposable(m);
|
2056
|
+
m.setDisposable(scheduler.schedule(function () {
|
2057
|
+
d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
|
2058
|
+
}));
|
2059
|
+
return d;
|
2060
|
+
});
|
2061
|
+
};
|
2049
2062
|
|
2050
2063
|
/**
|
2051
2064
|
* Converts a Promise to an Observable sequence
|
@@ -2068,38 +2081,32 @@
|
|
2068
2081
|
return subject;
|
2069
2082
|
});
|
2070
2083
|
};
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
if (hasValue) {
|
2098
|
-
resolve(value);
|
2099
|
-
}
|
2100
|
-
});
|
2101
|
-
});
|
2102
|
-
};
|
2084
|
+
/*
|
2085
|
+
* Converts an existing observable sequence to an ES6 Compatible Promise
|
2086
|
+
* @example
|
2087
|
+
* var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
|
2088
|
+
*
|
2089
|
+
* // With config
|
2090
|
+
* Rx.config.Promise = RSVP.Promise;
|
2091
|
+
* var promise = Rx.Observable.return(42).toPromise();
|
2092
|
+
* @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
|
2093
|
+
* @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
|
2094
|
+
*/
|
2095
|
+
observableProto.toPromise = function (promiseCtor) {
|
2096
|
+
promiseCtor || (promiseCtor = Rx.config.Promise);
|
2097
|
+
if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
|
2098
|
+
var source = this;
|
2099
|
+
return new promiseCtor(function (resolve, reject) {
|
2100
|
+
// No cancellation can be done
|
2101
|
+
var value, hasValue = false;
|
2102
|
+
source.subscribe(function (v) {
|
2103
|
+
value = v;
|
2104
|
+
hasValue = true;
|
2105
|
+
}, reject, function () {
|
2106
|
+
hasValue && resolve(value);
|
2107
|
+
});
|
2108
|
+
});
|
2109
|
+
};
|
2103
2110
|
/**
|
2104
2111
|
* Creates a list from an observable sequence.
|
2105
2112
|
* @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
|
@@ -2353,15 +2360,15 @@
|
|
2353
2360
|
return observableFromArray(args, scheduler);
|
2354
2361
|
};
|
2355
2362
|
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2363
|
+
/**
|
2364
|
+
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2365
|
+
* @returns {Observable} An observable sequence whose observers will never get called.
|
2366
|
+
*/
|
2367
|
+
var observableNever = Observable.never = function () {
|
2368
|
+
return new AnonymousObservable(function () {
|
2369
|
+
return disposableEmpty;
|
2370
|
+
});
|
2371
|
+
};
|
2365
2372
|
|
2366
2373
|
/**
|
2367
2374
|
* Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
|
@@ -2429,16 +2436,12 @@
|
|
2429
2436
|
|
2430
2437
|
/**
|
2431
2438
|
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2432
|
-
* There is an alias to this method called '
|
2433
|
-
*
|
2434
|
-
* @example
|
2435
|
-
* var res = Rx.Observable.throw(new Error('Error'));
|
2436
|
-
* var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
|
2439
|
+
* There is an alias to this method called 'throwError' for browsers <IE9.
|
2437
2440
|
* @param {Mixed} exception An object used for the sequence's termination.
|
2438
2441
|
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2439
2442
|
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2440
2443
|
*/
|
2441
|
-
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2444
|
+
var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
|
2442
2445
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2443
2446
|
return new AnonymousObservable(function (observer) {
|
2444
2447
|
return scheduler.schedule(function () {
|
@@ -2448,10 +2451,7 @@
|
|
2448
2451
|
};
|
2449
2452
|
|
2450
2453
|
/**
|
2451
|
-
*
|
2452
|
-
*
|
2453
|
-
* @example
|
2454
|
-
* var res = Rx.Observable.using(function () { return new AsyncSubject(); }, function (s) { return s; });
|
2454
|
+
* Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
|
2455
2455
|
* @param {Function} resourceFactory Factory function to obtain a resource object.
|
2456
2456
|
* @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
|
2457
2457
|
* @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
|
@@ -2461,9 +2461,7 @@
|
|
2461
2461
|
var disposable = disposableEmpty, resource, source;
|
2462
2462
|
try {
|
2463
2463
|
resource = resourceFactory();
|
2464
|
-
|
2465
|
-
disposable = resource;
|
2466
|
-
}
|
2464
|
+
resource && (disposable = resource);
|
2467
2465
|
source = observableFactory(resource);
|
2468
2466
|
} catch (exception) {
|
2469
2467
|
return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
|
@@ -2820,20 +2818,16 @@
|
|
2820
2818
|
var innerSubscription = new SingleAssignmentDisposable();
|
2821
2819
|
group.add(innerSubscription);
|
2822
2820
|
|
2823
|
-
// Check
|
2824
|
-
|
2825
|
-
innerSource = observableFromPromise(innerSource);
|
2826
|
-
}
|
2821
|
+
// Check for promises support
|
2822
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
2827
2823
|
|
2828
|
-
innerSubscription.setDisposable(innerSource.subscribe(function (
|
2829
|
-
|
2830
|
-
|
2831
|
-
group.remove(innerSubscription);
|
2832
|
-
if (isStopped && group.length === 1) { observer.onCompleted(); }
|
2824
|
+
innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
|
2825
|
+
group.remove(innerSubscription);
|
2826
|
+
isStopped && group.length === 1 && observer.onCompleted();
|
2833
2827
|
}));
|
2834
2828
|
}, observer.onError.bind(observer), function () {
|
2835
2829
|
isStopped = true;
|
2836
|
-
|
2830
|
+
group.length === 1 && observer.onCompleted();
|
2837
2831
|
}));
|
2838
2832
|
return group;
|
2839
2833
|
});
|
@@ -2845,9 +2839,7 @@
|
|
2845
2839
|
* @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
|
2846
2840
|
*/
|
2847
2841
|
observableProto.onErrorResumeNext = function (second) {
|
2848
|
-
if (!second) {
|
2849
|
-
throw new Error('Second observable is required');
|
2850
|
-
}
|
2842
|
+
if (!second) { throw new Error('Second observable is required'); }
|
2851
2843
|
return onErrorResumeNext([this, second]);
|
2852
2844
|
};
|
2853
2845
|
|
@@ -2870,11 +2862,7 @@
|
|
2870
2862
|
isPromise(current) && (current = observableFromPromise(current));
|
2871
2863
|
d = new SingleAssignmentDisposable();
|
2872
2864
|
subscription.setDisposable(d);
|
2873
|
-
d.setDisposable(current.subscribe(observer.onNext.bind(observer),
|
2874
|
-
self();
|
2875
|
-
}, function () {
|
2876
|
-
self();
|
2877
|
-
}));
|
2865
|
+
d.setDisposable(current.subscribe(observer.onNext.bind(observer), self, self));
|
2878
2866
|
} else {
|
2879
2867
|
observer.onCompleted();
|
2880
2868
|
}
|
@@ -2913,52 +2901,44 @@
|
|
2913
2901
|
});
|
2914
2902
|
};
|
2915
2903
|
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2930
|
-
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
}
|
2904
|
+
/**
|
2905
|
+
* Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
2906
|
+
* @returns {Observable} The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
2907
|
+
*/
|
2908
|
+
observableProto['switch'] = observableProto.switchLatest = function () {
|
2909
|
+
var sources = this;
|
2910
|
+
return new AnonymousObservable(function (observer) {
|
2911
|
+
var hasLatest = false,
|
2912
|
+
innerSubscription = new SerialDisposable(),
|
2913
|
+
isStopped = false,
|
2914
|
+
latest = 0,
|
2915
|
+
subscription = sources.subscribe(
|
2916
|
+
function (innerSource) {
|
2917
|
+
var d = new SingleAssignmentDisposable(), id = ++latest;
|
2918
|
+
hasLatest = true;
|
2919
|
+
innerSubscription.setDisposable(d);
|
2920
|
+
|
2921
|
+
// Check if Promise or Observable
|
2922
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
2936
2923
|
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
if (!hasLatest) {
|
2956
|
-
observer.onCompleted();
|
2957
|
-
}
|
2958
|
-
});
|
2959
|
-
return new CompositeDisposable(subscription, innerSubscription);
|
2960
|
-
});
|
2961
|
-
};
|
2924
|
+
d.setDisposable(innerSource.subscribe(
|
2925
|
+
function (x) { latest === id && observer.onNext(x); },
|
2926
|
+
function (e) { latest === id && observer.onError(e); },
|
2927
|
+
function () {
|
2928
|
+
if (latest === id) {
|
2929
|
+
hasLatest = false;
|
2930
|
+
isStopped && observer.onCompleted();
|
2931
|
+
}
|
2932
|
+
}));
|
2933
|
+
},
|
2934
|
+
observer.onError.bind(observer),
|
2935
|
+
function () {
|
2936
|
+
isStopped = true;
|
2937
|
+
!hasLatest && observer.onCompleted();
|
2938
|
+
});
|
2939
|
+
return new CompositeDisposable(subscription, innerSubscription);
|
2940
|
+
});
|
2941
|
+
};
|
2962
2942
|
|
2963
2943
|
/**
|
2964
2944
|
* Returns the values from the source observable sequence until the other observable sequence produces a value.
|
@@ -3123,16 +3103,13 @@
|
|
3123
3103
|
});
|
3124
3104
|
};
|
3125
3105
|
|
3126
|
-
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
return source.subscribe(observer);
|
3134
|
-
});
|
3135
|
-
};
|
3106
|
+
/**
|
3107
|
+
* Hides the identity of an observable sequence.
|
3108
|
+
* @returns {Observable} An observable sequence that hides the identity of the source sequence.
|
3109
|
+
*/
|
3110
|
+
observableProto.asObservable = function () {
|
3111
|
+
return new AnonymousObservable(this.subscribe.bind(this));
|
3112
|
+
};
|
3136
3113
|
|
3137
3114
|
/**
|
3138
3115
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
|
@@ -3297,35 +3274,35 @@
|
|
3297
3274
|
});
|
3298
3275
|
};
|
3299
3276
|
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3305
|
-
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
|
3277
|
+
/**
|
3278
|
+
* Ignores all elements in an observable sequence leaving only the termination messages.
|
3279
|
+
* @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
|
3280
|
+
*/
|
3281
|
+
observableProto.ignoreElements = function () {
|
3282
|
+
var source = this;
|
3283
|
+
return new AnonymousObservable(function (observer) {
|
3284
|
+
return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3285
|
+
});
|
3286
|
+
};
|
3310
3287
|
|
3311
|
-
|
3312
|
-
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
|
3319
|
-
|
3320
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3288
|
+
/**
|
3289
|
+
* Materializes the implicit notifications of an observable sequence as explicit notification values.
|
3290
|
+
* @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
|
3291
|
+
*/
|
3292
|
+
observableProto.materialize = function () {
|
3293
|
+
var source = this;
|
3294
|
+
return new AnonymousObservable(function (observer) {
|
3295
|
+
return source.subscribe(function (value) {
|
3296
|
+
observer.onNext(notificationCreateOnNext(value));
|
3297
|
+
}, function (e) {
|
3298
|
+
observer.onNext(notificationCreateOnError(e));
|
3299
|
+
observer.onCompleted();
|
3300
|
+
}, function () {
|
3301
|
+
observer.onNext(notificationCreateOnCompleted());
|
3302
|
+
observer.onCompleted();
|
3303
|
+
});
|
3304
|
+
});
|
3305
|
+
};
|
3329
3306
|
|
3330
3307
|
/**
|
3331
3308
|
* Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
|
@@ -3354,106 +3331,94 @@
|
|
3354
3331
|
return enumerableRepeat(this, retryCount).catchException();
|
3355
3332
|
};
|
3356
3333
|
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3334
|
+
/**
|
3335
|
+
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
3336
|
+
* For aggregation behavior with no intermediate results, see Observable.aggregate.
|
3337
|
+
* @example
|
3338
|
+
* var res = source.scan(function (acc, x) { return acc + x; });
|
3339
|
+
* var res = source.scan(0, function (acc, x) { return acc + x; });
|
3340
|
+
* @param {Mixed} [seed] The initial accumulator value.
|
3341
|
+
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
3342
|
+
* @returns {Observable} An observable sequence containing the accumulated values.
|
3343
|
+
*/
|
3344
|
+
observableProto.scan = function () {
|
3345
|
+
var hasSeed = false, seed, accumulator, source = this;
|
3346
|
+
if (arguments.length === 2) {
|
3347
|
+
hasSeed = true;
|
3348
|
+
seed = arguments[0];
|
3349
|
+
accumulator = arguments[1];
|
3350
|
+
} else {
|
3351
|
+
accumulator = arguments[0];
|
3352
|
+
}
|
3353
|
+
return new AnonymousObservable(function (observer) {
|
3354
|
+
var hasAccumulation, accumulation, hasValue;
|
3355
|
+
return source.subscribe (
|
3356
|
+
function (x) {
|
3357
|
+
!hasValue && (hasValue = true);
|
3358
|
+
try {
|
3359
|
+
if (hasAccumulation) {
|
3360
|
+
accumulation = accumulator(accumulation, x);
|
3361
|
+
} else {
|
3362
|
+
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3363
|
+
hasAccumulation = true;
|
3364
|
+
}
|
3365
|
+
} catch (e) {
|
3366
|
+
observer.onError(e);
|
3367
|
+
return;
|
3368
|
+
}
|
3369
|
+
|
3370
|
+
observer.onNext(accumulation);
|
3371
|
+
},
|
3372
|
+
observer.onError.bind(observer),
|
3373
|
+
function () {
|
3374
|
+
!hasValue && hasSeed && observer.onNext(seed);
|
3375
|
+
observer.onCompleted();
|
3375
3376
|
}
|
3376
|
-
|
3377
|
-
|
3378
|
-
|
3379
|
-
function (x) {
|
3380
|
-
try {
|
3381
|
-
if (!hasValue) {
|
3382
|
-
hasValue = true;
|
3383
|
-
}
|
3384
|
-
|
3385
|
-
if (hasAccumulation) {
|
3386
|
-
accumulation = accumulator(accumulation, x);
|
3387
|
-
} else {
|
3388
|
-
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3389
|
-
hasAccumulation = true;
|
3390
|
-
}
|
3391
|
-
} catch (e) {
|
3392
|
-
observer.onError(e);
|
3393
|
-
return;
|
3394
|
-
}
|
3395
|
-
|
3396
|
-
observer.onNext(accumulation);
|
3397
|
-
},
|
3398
|
-
observer.onError.bind(observer),
|
3399
|
-
function () {
|
3400
|
-
if (!hasValue && hasSeed) {
|
3401
|
-
observer.onNext(seed);
|
3402
|
-
}
|
3403
|
-
observer.onCompleted();
|
3404
|
-
}
|
3405
|
-
);
|
3406
|
-
});
|
3407
|
-
};
|
3377
|
+
);
|
3378
|
+
});
|
3379
|
+
};
|
3408
3380
|
|
3409
|
-
|
3410
|
-
|
3411
|
-
|
3412
|
-
|
3413
|
-
|
3414
|
-
|
3415
|
-
|
3416
|
-
|
3417
|
-
|
3418
|
-
|
3419
|
-
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
3427
|
-
});
|
3428
|
-
};
|
3381
|
+
/**
|
3382
|
+
* Bypasses a specified number of elements at the end of an observable sequence.
|
3383
|
+
* @description
|
3384
|
+
* This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
|
3385
|
+
* received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
|
3386
|
+
* @param count Number of elements to bypass at the end of the source sequence.
|
3387
|
+
* @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
|
3388
|
+
*/
|
3389
|
+
observableProto.skipLast = function (count) {
|
3390
|
+
var source = this;
|
3391
|
+
return new AnonymousObservable(function (observer) {
|
3392
|
+
var q = [];
|
3393
|
+
return source.subscribe(function (x) {
|
3394
|
+
q.push(x);
|
3395
|
+
q.length > count && observer.onNext(q.shift());
|
3396
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3397
|
+
});
|
3398
|
+
};
|
3429
3399
|
|
3430
|
-
|
3431
|
-
|
3432
|
-
|
3433
|
-
|
3434
|
-
|
3435
|
-
|
3436
|
-
|
3437
|
-
|
3438
|
-
|
3439
|
-
|
3440
|
-
|
3441
|
-
|
3442
|
-
|
3443
|
-
|
3444
|
-
|
3445
|
-
|
3446
|
-
|
3447
|
-
|
3448
|
-
|
3449
|
-
};
|
3400
|
+
/**
|
3401
|
+
* Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
|
3402
|
+
* @example
|
3403
|
+
* var res = source.startWith(1, 2, 3);
|
3404
|
+
* var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
|
3405
|
+
* @param {Arguments} args The specified values to prepend to the observable sequence
|
3406
|
+
* @returns {Observable} The source sequence prepended with the specified values.
|
3407
|
+
*/
|
3408
|
+
observableProto.startWith = function () {
|
3409
|
+
var values, scheduler, start = 0;
|
3410
|
+
if (!!arguments.length && isScheduler(arguments[0])) {
|
3411
|
+
scheduler = arguments[0];
|
3412
|
+
start = 1;
|
3413
|
+
} else {
|
3414
|
+
scheduler = immediateScheduler;
|
3415
|
+
}
|
3416
|
+
values = slice.call(arguments, start);
|
3417
|
+
return enumerableFor([observableFromArray(values, scheduler), this]).concat();
|
3418
|
+
};
|
3450
3419
|
|
3451
3420
|
/**
|
3452
3421
|
* Returns a specified number of contiguous elements from the end of an observable sequence.
|
3453
|
-
*
|
3454
|
-
* @example
|
3455
|
-
* var res = source.takeLast(5);
|
3456
|
-
*
|
3457
3422
|
* @description
|
3458
3423
|
* This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
|
3459
3424
|
* the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
|
@@ -3869,14 +3834,14 @@
|
|
3869
3834
|
});
|
3870
3835
|
};
|
3871
3836
|
|
3872
|
-
|
3873
|
-
|
3874
|
-
|
3875
|
-
|
3876
|
-
|
3877
|
-
|
3878
|
-
|
3879
|
-
|
3837
|
+
/**
|
3838
|
+
* Retrieves the value of a specified property from all elements in the Observable sequence.
|
3839
|
+
* @param {String} prop The property to pluck.
|
3840
|
+
* @returns {Observable} Returns a new Observable sequence of property values.
|
3841
|
+
*/
|
3842
|
+
observableProto.pluck = function (prop) {
|
3843
|
+
return this.map(function (x) { return x[prop]; });
|
3844
|
+
};
|
3880
3845
|
|
3881
3846
|
function flatMap(source, selector, thisArg) {
|
3882
3847
|
return source.map(function (x, i) {
|
@@ -3972,133 +3937,118 @@
|
|
3972
3937
|
});
|
3973
3938
|
}).mergeAll();
|
3974
3939
|
};
|
3975
|
-
|
3976
|
-
|
3977
|
-
|
3978
|
-
|
3979
|
-
|
3980
|
-
|
3981
|
-
|
3982
|
-
|
3983
|
-
|
3984
|
-
|
3985
|
-
|
3940
|
+
/**
|
3941
|
+
* Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
|
3942
|
+
* transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
3943
|
+
* @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
|
3944
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3945
|
+
* @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
|
3946
|
+
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
3947
|
+
*/
|
3948
|
+
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
3949
|
+
return this.select(selector, thisArg).switchLatest();
|
3950
|
+
};
|
3986
3951
|
|
3987
|
-
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
3991
|
-
|
3992
|
-
|
3993
|
-
|
3994
|
-
|
3952
|
+
/**
|
3953
|
+
* Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
|
3954
|
+
* @param {Number} count The number of elements to skip before returning the remaining elements.
|
3955
|
+
* @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
|
3956
|
+
*/
|
3957
|
+
observableProto.skip = function (count) {
|
3958
|
+
if (count < 0) { throw new Error(argumentOutOfRange); }
|
3959
|
+
var source = this;
|
3960
|
+
return new AnonymousObservable(function (observer) {
|
3961
|
+
var remaining = count;
|
3962
|
+
return source.subscribe(function (x) {
|
3963
|
+
if (remaining <= 0) {
|
3964
|
+
observer.onNext(x);
|
3965
|
+
} else {
|
3966
|
+
remaining--;
|
3967
|
+
}
|
3968
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3969
|
+
});
|
3970
|
+
};
|
3971
|
+
|
3972
|
+
/**
|
3973
|
+
* Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
|
3974
|
+
* The element's index is used in the logic of the predicate function.
|
3975
|
+
*
|
3976
|
+
* var res = source.skipWhile(function (value) { return value < 10; });
|
3977
|
+
* var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
|
3978
|
+
* @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
|
3979
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3980
|
+
* @returns {Observable} An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
|
3981
|
+
*/
|
3982
|
+
observableProto.skipWhile = function (predicate, thisArg) {
|
3983
|
+
var source = this;
|
3984
|
+
return new AnonymousObservable(function (observer) {
|
3985
|
+
var i = 0, running = false;
|
3986
|
+
return source.subscribe(function (x) {
|
3987
|
+
if (!running) {
|
3988
|
+
try {
|
3989
|
+
running = !predicate.call(thisArg, x, i++, source);
|
3990
|
+
} catch (e) {
|
3991
|
+
observer.onError(e);
|
3992
|
+
return;
|
3993
|
+
}
|
3995
3994
|
}
|
3996
|
-
|
3997
|
-
|
3998
|
-
|
3999
|
-
|
4000
|
-
if (remaining <= 0) {
|
4001
|
-
observer.onNext(x);
|
4002
|
-
} else {
|
4003
|
-
remaining--;
|
4004
|
-
}
|
4005
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4006
|
-
});
|
4007
|
-
};
|
3995
|
+
running && observer.onNext(x);
|
3996
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3997
|
+
});
|
3998
|
+
};
|
4008
3999
|
|
4009
|
-
|
4010
|
-
|
4011
|
-
|
4012
|
-
|
4013
|
-
|
4014
|
-
|
4015
|
-
|
4016
|
-
|
4017
|
-
|
4018
|
-
|
4019
|
-
|
4020
|
-
|
4021
|
-
|
4022
|
-
|
4023
|
-
|
4024
|
-
|
4025
|
-
|
4026
|
-
|
4027
|
-
|
4028
|
-
|
4029
|
-
|
4030
|
-
|
4031
|
-
|
4032
|
-
if (running) {
|
4033
|
-
observer.onNext(x);
|
4034
|
-
}
|
4035
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4036
|
-
});
|
4037
|
-
};
|
4000
|
+
/**
|
4001
|
+
* Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of take(0).
|
4002
|
+
*
|
4003
|
+
* var res = source.take(5);
|
4004
|
+
* var res = source.take(0, Rx.Scheduler.timeout);
|
4005
|
+
* @param {Number} count The number of elements to return.
|
4006
|
+
* @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
|
4007
|
+
* @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
|
4008
|
+
*/
|
4009
|
+
observableProto.take = function (count, scheduler) {
|
4010
|
+
if (count < 0) { throw new RangeError(argumentOutOfRange); }
|
4011
|
+
if (count === 0) { return observableEmpty(scheduler); }
|
4012
|
+
var observable = this;
|
4013
|
+
return new AnonymousObservable(function (observer) {
|
4014
|
+
var remaining = count;
|
4015
|
+
return observable.subscribe(function (x) {
|
4016
|
+
if (remaining-- > 0) {
|
4017
|
+
observer.onNext(x);
|
4018
|
+
remaining === 0 && observer.onCompleted();
|
4019
|
+
}
|
4020
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4021
|
+
});
|
4022
|
+
};
|
4038
4023
|
|
4039
|
-
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4043
|
-
|
4044
|
-
|
4045
|
-
|
4046
|
-
|
4047
|
-
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4024
|
+
/**
|
4025
|
+
* Returns elements from an observable sequence as long as a specified condition is true.
|
4026
|
+
* The element's index is used in the logic of the predicate function.
|
4027
|
+
* @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
|
4028
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4029
|
+
* @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
|
4030
|
+
*/
|
4031
|
+
observableProto.takeWhile = function (predicate, thisArg) {
|
4032
|
+
var observable = this;
|
4033
|
+
return new AnonymousObservable(function (observer) {
|
4034
|
+
var i = 0, running = true;
|
4035
|
+
return observable.subscribe(function (x) {
|
4036
|
+
if (running) {
|
4037
|
+
try {
|
4038
|
+
running = predicate.call(thisArg, x, i++, observable);
|
4039
|
+
} catch (e) {
|
4040
|
+
observer.onError(e);
|
4041
|
+
return;
|
4042
|
+
}
|
4043
|
+
if (running) {
|
4044
|
+
observer.onNext(x);
|
4045
|
+
} else {
|
4046
|
+
observer.onCompleted();
|
4047
|
+
}
|
4054
4048
|
}
|
4055
|
-
|
4056
|
-
|
4057
|
-
|
4058
|
-
return observable.subscribe(function (x) {
|
4059
|
-
if (remaining > 0) {
|
4060
|
-
remaining--;
|
4061
|
-
observer.onNext(x);
|
4062
|
-
if (remaining === 0) {
|
4063
|
-
observer.onCompleted();
|
4064
|
-
}
|
4065
|
-
}
|
4066
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4067
|
-
});
|
4068
|
-
};
|
4069
|
-
|
4070
|
-
/**
|
4071
|
-
* Returns elements from an observable sequence as long as a specified condition is true.
|
4072
|
-
* The element's index is used in the logic of the predicate function.
|
4073
|
-
*
|
4074
|
-
* @example
|
4075
|
-
* var res = source.takeWhile(function (value) { return value < 10; });
|
4076
|
-
* var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
|
4077
|
-
* @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
|
4078
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4079
|
-
* @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
|
4080
|
-
*/
|
4081
|
-
observableProto.takeWhile = function (predicate, thisArg) {
|
4082
|
-
var observable = this;
|
4083
|
-
return new AnonymousObservable(function (observer) {
|
4084
|
-
var i = 0, running = true;
|
4085
|
-
return observable.subscribe(function (x) {
|
4086
|
-
if (running) {
|
4087
|
-
try {
|
4088
|
-
running = predicate.call(thisArg, x, i++, observable);
|
4089
|
-
} catch (e) {
|
4090
|
-
observer.onError(e);
|
4091
|
-
return;
|
4092
|
-
}
|
4093
|
-
if (running) {
|
4094
|
-
observer.onNext(x);
|
4095
|
-
} else {
|
4096
|
-
observer.onCompleted();
|
4097
|
-
}
|
4098
|
-
}
|
4099
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4100
|
-
});
|
4101
|
-
};
|
4049
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4050
|
+
});
|
4051
|
+
};
|
4102
4052
|
|
4103
4053
|
/**
|
4104
4054
|
* Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
|
@@ -4147,42 +4097,40 @@
|
|
4147
4097
|
});
|
4148
4098
|
};
|
4149
4099
|
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
4173
|
-
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
|
4183
|
-
|
4184
|
-
});
|
4185
|
-
}
|
4100
|
+
function extremaBy(source, keySelector, comparer) {
|
4101
|
+
return new AnonymousObservable(function (observer) {
|
4102
|
+
var hasValue = false, lastKey = null, list = [];
|
4103
|
+
return source.subscribe(function (x) {
|
4104
|
+
var comparison, key;
|
4105
|
+
try {
|
4106
|
+
key = keySelector(x);
|
4107
|
+
} catch (ex) {
|
4108
|
+
observer.onError(ex);
|
4109
|
+
return;
|
4110
|
+
}
|
4111
|
+
comparison = 0;
|
4112
|
+
if (!hasValue) {
|
4113
|
+
hasValue = true;
|
4114
|
+
lastKey = key;
|
4115
|
+
} else {
|
4116
|
+
try {
|
4117
|
+
comparison = comparer(key, lastKey);
|
4118
|
+
} catch (ex1) {
|
4119
|
+
observer.onError(ex1);
|
4120
|
+
return;
|
4121
|
+
}
|
4122
|
+
}
|
4123
|
+
if (comparison > 0) {
|
4124
|
+
lastKey = key;
|
4125
|
+
list = [];
|
4126
|
+
}
|
4127
|
+
if (comparison >= 0) { list.push(x); }
|
4128
|
+
}, observer.onError.bind(observer), function () {
|
4129
|
+
observer.onNext(list);
|
4130
|
+
observer.onCompleted();
|
4131
|
+
});
|
4132
|
+
});
|
4133
|
+
}
|
4186
4134
|
|
4187
4135
|
function firstOnly(x) {
|
4188
4136
|
if (x.length === 0) {
|
@@ -4313,25 +4261,25 @@
|
|
4313
4261
|
});
|
4314
4262
|
};
|
4315
4263
|
|
4264
|
+
/**
|
4265
|
+
* Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
|
4266
|
+
* @example
|
4267
|
+
* var res = source.sum();
|
4268
|
+
* var res = source.sum(function (x) { return x.value; });
|
4269
|
+
* @param {Function} [selector] A transform function to apply to each element.
|
4270
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4271
|
+
* @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
|
4272
|
+
*/
|
4273
|
+
observableProto.sum = function (keySelector, thisArg) {
|
4274
|
+
return keySelector && isFunction(keySelector) ?
|
4275
|
+
this.map(keySelector, thisArg).sum() :
|
4276
|
+
this.aggregate(0, function (prev, curr) {
|
4277
|
+
return prev + curr;
|
4278
|
+
});
|
4279
|
+
};
|
4280
|
+
|
4316
4281
|
/**
|
4317
|
-
*
|
4318
|
-
* @example
|
4319
|
-
* var res = source.sum();
|
4320
|
-
* var res = source.sum(function (x) { return x.value; });
|
4321
|
-
* @param {Function} [selector] A transform function to apply to each element.
|
4322
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4323
|
-
* @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
|
4324
|
-
*/
|
4325
|
-
observableProto.sum = function (keySelector, thisArg) {
|
4326
|
-
return keySelector ?
|
4327
|
-
this.select(keySelector, thisArg).sum() :
|
4328
|
-
this.aggregate(0, function (prev, curr) {
|
4329
|
-
return prev + curr;
|
4330
|
-
});
|
4331
|
-
};
|
4332
|
-
|
4333
|
-
/**
|
4334
|
-
* Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
|
4282
|
+
* Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
|
4335
4283
|
* @example
|
4336
4284
|
* var res = source.minBy(function (x) { return x.value; });
|
4337
4285
|
* var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
|
@@ -4417,27 +4365,25 @@
|
|
4417
4365
|
};
|
4418
4366
|
|
4419
4367
|
function sequenceEqualArray(first, second, comparer) {
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
if (!equal) {
|
4433
|
-
observer.onNext(false);
|
4434
|
-
observer.onCompleted();
|
4435
|
-
}
|
4436
|
-
}, observer.onError.bind(observer), function () {
|
4437
|
-
observer.onNext(count === len);
|
4368
|
+
return new AnonymousObservable(function (observer) {
|
4369
|
+
var count = 0, len = second.length;
|
4370
|
+
return first.subscribe(function (value) {
|
4371
|
+
var equal = false;
|
4372
|
+
try {
|
4373
|
+
count < len && (equal = comparer(value, second[count++]));
|
4374
|
+
} catch (e) {
|
4375
|
+
observer.onError(e);
|
4376
|
+
return;
|
4377
|
+
}
|
4378
|
+
if (!equal) {
|
4379
|
+
observer.onNext(false);
|
4438
4380
|
observer.onCompleted();
|
4439
|
-
}
|
4381
|
+
}
|
4382
|
+
}, observer.onError.bind(observer), function () {
|
4383
|
+
observer.onNext(count === len);
|
4384
|
+
observer.onCompleted();
|
4440
4385
|
});
|
4386
|
+
});
|
4441
4387
|
}
|
4442
4388
|
|
4443
4389
|
/**
|
@@ -4463,17 +4409,17 @@
|
|
4463
4409
|
var subscription1 = first.subscribe(function (x) {
|
4464
4410
|
var equal, v;
|
4465
4411
|
if (qr.length > 0) {
|
4466
|
-
|
4467
|
-
|
4468
|
-
|
4469
|
-
|
4470
|
-
|
4471
|
-
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4412
|
+
v = qr.shift();
|
4413
|
+
try {
|
4414
|
+
equal = comparer(v, x);
|
4415
|
+
} catch (e) {
|
4416
|
+
observer.onError(e);
|
4417
|
+
return;
|
4418
|
+
}
|
4419
|
+
if (!equal) {
|
4420
|
+
observer.onNext(false);
|
4421
|
+
observer.onCompleted();
|
4422
|
+
}
|
4477
4423
|
} else if (doner) {
|
4478
4424
|
observer.onNext(false);
|
4479
4425
|
observer.onCompleted();
|
@@ -4495,9 +4441,9 @@
|
|
4495
4441
|
|
4496
4442
|
isPromise(second) && (second = observableFromPromise(second));
|
4497
4443
|
var subscription2 = second.subscribe(function (x) {
|
4498
|
-
var equal
|
4444
|
+
var equal;
|
4499
4445
|
if (ql.length > 0) {
|
4500
|
-
v = ql.shift();
|
4446
|
+
var v = ql.shift();
|
4501
4447
|
try {
|
4502
4448
|
equal = comparer(v, x);
|
4503
4449
|
} catch (exception) {
|
@@ -4577,60 +4523,60 @@
|
|
4577
4523
|
return elementAtOrDefault(this, index, true, defaultValue);
|
4578
4524
|
};
|
4579
4525
|
|
4580
|
-
|
4581
|
-
|
4582
|
-
|
4583
|
-
|
4584
|
-
|
4585
|
-
|
4586
|
-
|
4587
|
-
|
4588
|
-
|
4589
|
-
|
4590
|
-
|
4591
|
-
|
4592
|
-
|
4593
|
-
|
4594
|
-
|
4595
|
-
|
4596
|
-
|
4597
|
-
|
4598
|
-
|
4599
|
-
|
4526
|
+
function singleOrDefaultAsync(source, hasDefault, defaultValue) {
|
4527
|
+
return new AnonymousObservable(function (observer) {
|
4528
|
+
var value = defaultValue, seenValue = false;
|
4529
|
+
return source.subscribe(function (x) {
|
4530
|
+
if (seenValue) {
|
4531
|
+
observer.onError(new Error('Sequence contains more than one element'));
|
4532
|
+
} else {
|
4533
|
+
value = x;
|
4534
|
+
seenValue = true;
|
4535
|
+
}
|
4536
|
+
}, observer.onError.bind(observer), function () {
|
4537
|
+
if (!seenValue && !hasDefault) {
|
4538
|
+
observer.onError(new Error(sequenceContainsNoElements));
|
4539
|
+
} else {
|
4540
|
+
observer.onNext(value);
|
4541
|
+
observer.onCompleted();
|
4542
|
+
}
|
4543
|
+
});
|
4544
|
+
});
|
4545
|
+
}
|
4600
4546
|
|
4601
|
-
|
4602
|
-
|
4603
|
-
|
4604
|
-
|
4605
|
-
|
4606
|
-
|
4607
|
-
|
4608
|
-
|
4609
|
-
|
4610
|
-
|
4611
|
-
|
4612
|
-
|
4613
|
-
|
4614
|
-
|
4547
|
+
/**
|
4548
|
+
* Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
|
4549
|
+
* @example
|
4550
|
+
* var res = res = source.single();
|
4551
|
+
* var res = res = source.single(function (x) { return x === 42; });
|
4552
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
4553
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
4554
|
+
* @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
|
4555
|
+
*/
|
4556
|
+
observableProto.single = function (predicate, thisArg) {
|
4557
|
+
return predicate && isFunction(predicate) ?
|
4558
|
+
this.where(predicate, thisArg).single() :
|
4559
|
+
singleOrDefaultAsync(this, false);
|
4560
|
+
};
|
4615
4561
|
|
4616
|
-
|
4617
|
-
|
4618
|
-
|
4619
|
-
|
4620
|
-
|
4621
|
-
|
4622
|
-
|
4623
|
-
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4628
|
-
|
4629
|
-
|
4630
|
-
|
4631
|
-
|
4632
|
-
|
4633
|
-
|
4562
|
+
/**
|
4563
|
+
* Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists; this method reports an exception if there is more than one element in the observable sequence.
|
4564
|
+
* @example
|
4565
|
+
* var res = res = source.singleOrDefault();
|
4566
|
+
* var res = res = source.singleOrDefault(function (x) { return x === 42; });
|
4567
|
+
* res = source.singleOrDefault(function (x) { return x === 42; }, 0);
|
4568
|
+
* res = source.singleOrDefault(null, 0);
|
4569
|
+
* @memberOf Observable#
|
4570
|
+
* @param {Function} predicate A predicate function to evaluate for elements in the source sequence.
|
4571
|
+
* @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
|
4572
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
4573
|
+
* @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
|
4574
|
+
*/
|
4575
|
+
observableProto.singleOrDefault = function (predicate, defaultValue, thisArg) {
|
4576
|
+
return predicate && isFunction(predicate) ?
|
4577
|
+
this.where(predicate, thisArg).singleOrDefault(null, defaultValue) :
|
4578
|
+
singleOrDefaultAsync(this, true, defaultValue);
|
4579
|
+
};
|
4634
4580
|
function firstOrDefaultAsync(source, hasDefault, defaultValue) {
|
4635
4581
|
return new AnonymousObservable(function (observer) {
|
4636
4582
|
return source.subscribe(function (x) {
|
@@ -4775,71 +4721,26 @@
|
|
4775
4721
|
return findValue(this, predicate, thisArg, true);
|
4776
4722
|
};
|
4777
4723
|
|
4778
|
-
function toSet(source, type) {
|
4779
|
-
return new AnonymousObservable(function (observer) {
|
4780
|
-
var s = new type();
|
4781
|
-
return source.subscribe(
|
4782
|
-
s.add.bind(s),
|
4783
|
-
observer.onError.bind(observer),
|
4784
|
-
function () {
|
4785
|
-
observer.onNext(s);
|
4786
|
-
observer.onCompleted();
|
4787
|
-
});
|
4788
|
-
});
|
4789
|
-
}
|
4790
4724
|
if (!!root.Set) {
|
4791
4725
|
/**
|
4792
4726
|
* Converts the observable sequence to a Set if it exists.
|
4793
4727
|
* @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
|
4794
4728
|
*/
|
4795
4729
|
observableProto.toSet = function () {
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4730
|
+
var source = this;
|
4731
|
+
return new AnonymousObservable(function (observer) {
|
4732
|
+
var s = new root.Set();
|
4733
|
+
return source.subscribe(
|
4734
|
+
s.add.bind(s),
|
4735
|
+
observer.onError.bind(observer),
|
4736
|
+
function () {
|
4737
|
+
observer.onNext(s);
|
4738
|
+
observer.onCompleted();
|
4739
|
+
});
|
4740
|
+
});
|
4807
4741
|
};
|
4808
4742
|
}
|
4809
4743
|
|
4810
|
-
function toMap(source, type, keySelector, elementSelector) {
|
4811
|
-
return new AnonymousObservable(function (observer) {
|
4812
|
-
var m = new type();
|
4813
|
-
return source.subscribe(
|
4814
|
-
function (x) {
|
4815
|
-
var key;
|
4816
|
-
try {
|
4817
|
-
key = keySelector(x);
|
4818
|
-
} catch (e) {
|
4819
|
-
observer.onError(e);
|
4820
|
-
return;
|
4821
|
-
}
|
4822
|
-
|
4823
|
-
var element = x;
|
4824
|
-
if (elementSelector) {
|
4825
|
-
try {
|
4826
|
-
element = elementSelector(x);
|
4827
|
-
} catch (e) {
|
4828
|
-
observer.onError(e);
|
4829
|
-
return;
|
4830
|
-
}
|
4831
|
-
}
|
4832
|
-
|
4833
|
-
m.set(key, element);
|
4834
|
-
},
|
4835
|
-
observer.onError.bind(observer),
|
4836
|
-
function () {
|
4837
|
-
observer.onNext(m);
|
4838
|
-
observer.onCompleted();
|
4839
|
-
});
|
4840
|
-
});
|
4841
|
-
}
|
4842
|
-
|
4843
4744
|
if (!!root.Map) {
|
4844
4745
|
/**
|
4845
4746
|
* Converts the observable sequence to a Map if it exists.
|
@@ -4848,84 +4749,343 @@
|
|
4848
4749
|
* @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
|
4849
4750
|
*/
|
4850
4751
|
observableProto.toMap = function (keySelector, elementSelector) {
|
4851
|
-
|
4752
|
+
var source = this;
|
4753
|
+
return new AnonymousObservable(function (observer) {
|
4754
|
+
var m = new root.Map();
|
4755
|
+
return source.subscribe(
|
4756
|
+
function (x) {
|
4757
|
+
var key;
|
4758
|
+
try {
|
4759
|
+
key = keySelector(x);
|
4760
|
+
} catch (e) {
|
4761
|
+
observer.onError(e);
|
4762
|
+
return;
|
4763
|
+
}
|
4764
|
+
|
4765
|
+
var element = x;
|
4766
|
+
if (elementSelector) {
|
4767
|
+
try {
|
4768
|
+
element = elementSelector(x);
|
4769
|
+
} catch (e) {
|
4770
|
+
observer.onError(e);
|
4771
|
+
return;
|
4772
|
+
}
|
4773
|
+
}
|
4774
|
+
|
4775
|
+
m.set(key, element);
|
4776
|
+
},
|
4777
|
+
observer.onError.bind(observer),
|
4778
|
+
function () {
|
4779
|
+
observer.onNext(m);
|
4780
|
+
observer.onCompleted();
|
4781
|
+
});
|
4782
|
+
});
|
4852
4783
|
};
|
4853
4784
|
}
|
4854
4785
|
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
|
4863
|
-
return
|
4864
|
-
}
|
4786
|
+
var fnString = 'function';
|
4787
|
+
|
4788
|
+
function toThunk(obj, ctx) {
|
4789
|
+
if (Array.isArray(obj)) {
|
4790
|
+
return objectToThunk.call(ctx, obj);
|
4791
|
+
}
|
4792
|
+
|
4793
|
+
if (isGeneratorFunction(obj)) {
|
4794
|
+
return observableSpawn(obj.call(ctx));
|
4795
|
+
}
|
4796
|
+
|
4797
|
+
if (isGenerator(obj)) {
|
4798
|
+
return observableSpawn(obj);
|
4799
|
+
}
|
4800
|
+
|
4801
|
+
if (isObservable(obj)) {
|
4802
|
+
return observableToThunk(obj);
|
4803
|
+
}
|
4804
|
+
|
4805
|
+
if (isPromise(obj)) {
|
4806
|
+
return promiseToThunk(obj);
|
4807
|
+
}
|
4808
|
+
|
4809
|
+
if (typeof obj === fnString) {
|
4810
|
+
return obj;
|
4811
|
+
}
|
4812
|
+
|
4813
|
+
if (isObject(obj) || Array.isArray(obj)) {
|
4814
|
+
return objectToThunk.call(ctx, obj);
|
4815
|
+
}
|
4816
|
+
|
4817
|
+
return obj;
|
4865
4818
|
}
|
4866
4819
|
|
4867
|
-
|
4868
|
-
|
4869
|
-
*
|
4870
|
-
* @example
|
4871
|
-
* var res = Rx.Observable.start(function () { console.log('hello'); });
|
4872
|
-
* var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
|
4873
|
-
* var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
|
4874
|
-
*
|
4875
|
-
* @param {Function} func Function to run asynchronously.
|
4876
|
-
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
4877
|
-
* @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4878
|
-
* @returns {Observable} An observable sequence exposing the function's result value, or an exception.
|
4879
|
-
*
|
4880
|
-
* Remarks
|
4881
|
-
* * The function is called immediately, not during the subscription of the resulting sequence.
|
4882
|
-
* * Multiple subscriptions to the resulting sequence can observe the function's result.
|
4883
|
-
*/
|
4884
|
-
Observable.start = function (func, context, scheduler) {
|
4885
|
-
return observableToAsync(func, context, scheduler)();
|
4886
|
-
};
|
4820
|
+
function objectToThunk(obj) {
|
4821
|
+
var ctx = this;
|
4887
4822
|
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4893
|
-
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
4894
|
-
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
4895
|
-
*
|
4896
|
-
* @param {Function} function Function to convert to an asynchronous function.
|
4897
|
-
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
4898
|
-
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4899
|
-
* @returns {Function} Asynchronous function.
|
4900
|
-
*/
|
4901
|
-
var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
4902
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4903
|
-
return function () {
|
4904
|
-
var args = arguments,
|
4905
|
-
subject = new AsyncSubject();
|
4823
|
+
return function (done) {
|
4824
|
+
var keys = Object.keys(obj),
|
4825
|
+
pending = keys.length,
|
4826
|
+
results = new obj.constructor(),
|
4827
|
+
finished;
|
4906
4828
|
|
4907
|
-
|
4908
|
-
|
4829
|
+
if (!pending) {
|
4830
|
+
timeoutScheduler.schedule(function () { done(null, results); });
|
4831
|
+
return;
|
4832
|
+
}
|
4833
|
+
|
4834
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
4835
|
+
run(obj[keys[i]], keys[i]);
|
4836
|
+
}
|
4837
|
+
|
4838
|
+
function run(fn, key) {
|
4839
|
+
if (finished) { return; }
|
4909
4840
|
try {
|
4910
|
-
|
4841
|
+
fn = toThunk(fn, ctx);
|
4842
|
+
|
4843
|
+
if (typeof fn !== fnString) {
|
4844
|
+
results[key] = fn;
|
4845
|
+
return --pending || done(null, results);
|
4846
|
+
}
|
4847
|
+
|
4848
|
+
fn.call(ctx, function(err, res){
|
4849
|
+
if (finished) { return; }
|
4850
|
+
|
4851
|
+
if (err) {
|
4852
|
+
finished = true;
|
4853
|
+
return done(err);
|
4854
|
+
}
|
4855
|
+
|
4856
|
+
results[key] = res;
|
4857
|
+
--pending || done(null, results);
|
4858
|
+
});
|
4911
4859
|
} catch (e) {
|
4912
|
-
|
4913
|
-
|
4860
|
+
finished = true;
|
4861
|
+
done(e);
|
4914
4862
|
}
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
return subject.asObservable();
|
4919
|
-
};
|
4920
|
-
};
|
4863
|
+
}
|
4864
|
+
}
|
4865
|
+
}
|
4921
4866
|
|
4922
|
-
|
4923
|
-
|
4924
|
-
|
4925
|
-
|
4926
|
-
|
4927
|
-
|
4928
|
-
|
4867
|
+
function observableToThink(observable) {
|
4868
|
+
return function (fn) {
|
4869
|
+
var value, hasValue = false;
|
4870
|
+
observable.subscribe(
|
4871
|
+
function (v) {
|
4872
|
+
value = v;
|
4873
|
+
hasValue = true;
|
4874
|
+
},
|
4875
|
+
fn,
|
4876
|
+
function () {
|
4877
|
+
hasValue && fn(null, value);
|
4878
|
+
});
|
4879
|
+
}
|
4880
|
+
}
|
4881
|
+
|
4882
|
+
function promiseToThunk(promise) {
|
4883
|
+
return function(fn){
|
4884
|
+
promise.then(function(res) {
|
4885
|
+
fn(null, res);
|
4886
|
+
}, fn);
|
4887
|
+
}
|
4888
|
+
}
|
4889
|
+
|
4890
|
+
function isObservable(obj) {
|
4891
|
+
return obj && obj.prototype.subscribe === fnString;
|
4892
|
+
}
|
4893
|
+
|
4894
|
+
function isGeneratorFunction(obj) {
|
4895
|
+
return obj && obj.constructor && obj.constructor.name === 'GeneratorFunction';
|
4896
|
+
}
|
4897
|
+
|
4898
|
+
function isGenerator(obj) {
|
4899
|
+
return obj && typeof obj.next === fnString && typeof obj.throw === fnString;
|
4900
|
+
}
|
4901
|
+
|
4902
|
+
function isObject(val) {
|
4903
|
+
return val && val.constructor === Object;
|
4904
|
+
}
|
4905
|
+
|
4906
|
+
/*
|
4907
|
+
* Spawns a generator function which allows for Promises, Observable sequences, Arrays, Objects, Generators and functions.
|
4908
|
+
* @param {Function} The spawning function.
|
4909
|
+
* @returns {Function} a function which has a done continuation.
|
4910
|
+
*/
|
4911
|
+
var observableSpawn = Rx.spawn = function (fn) {
|
4912
|
+
var isGenFun = isGeneratorFunction(fn);
|
4913
|
+
|
4914
|
+
return function (done) {
|
4915
|
+
var ctx = this,
|
4916
|
+
gen = fan;
|
4917
|
+
|
4918
|
+
if (isGenFun) {
|
4919
|
+
var args = slice.call(arguments),
|
4920
|
+
len = args.length,
|
4921
|
+
hasCallback = len && typeof args[len - 1] === fnString;
|
4922
|
+
|
4923
|
+
done = hasCallback ? args.pop() : error;
|
4924
|
+
gen = fn.apply(this, args);
|
4925
|
+
} else {
|
4926
|
+
done = done || error;
|
4927
|
+
}
|
4928
|
+
|
4929
|
+
next();
|
4930
|
+
|
4931
|
+
function exit(err, res) {
|
4932
|
+
timeoutScheduler.schedule(done.bind(ctx, err, res));
|
4933
|
+
}
|
4934
|
+
|
4935
|
+
function next(err, res) {
|
4936
|
+
var ret;
|
4937
|
+
|
4938
|
+
// multiple args
|
4939
|
+
if (arguments.length > 2) res = slice.call(arguments, 1);
|
4940
|
+
|
4941
|
+
if (err) {
|
4942
|
+
try {
|
4943
|
+
ret = gen.throw(err);
|
4944
|
+
} catch (e) {
|
4945
|
+
return exit(e);
|
4946
|
+
}
|
4947
|
+
}
|
4948
|
+
|
4949
|
+
if (!err) {
|
4950
|
+
try {
|
4951
|
+
ret = gen.next(res);
|
4952
|
+
} catch (e) {
|
4953
|
+
return exit(e);
|
4954
|
+
}
|
4955
|
+
}
|
4956
|
+
|
4957
|
+
if (ret.done) {
|
4958
|
+
return exit(null, ret.value);
|
4959
|
+
}
|
4960
|
+
|
4961
|
+
ret.value = toThunk(ret.value, ctx);
|
4962
|
+
|
4963
|
+
if (typeof ret.value === fnString) {
|
4964
|
+
var called = false;
|
4965
|
+
try {
|
4966
|
+
ret.value.call(ctx, function(){
|
4967
|
+
if (called) {
|
4968
|
+
return;
|
4969
|
+
}
|
4970
|
+
|
4971
|
+
called = true;
|
4972
|
+
next.apply(ctx, arguments);
|
4973
|
+
});
|
4974
|
+
} catch (e) {
|
4975
|
+
timeoutScheduler.schedule(function () {
|
4976
|
+
if (called) {
|
4977
|
+
return;
|
4978
|
+
}
|
4979
|
+
|
4980
|
+
called = true;
|
4981
|
+
next.call(ctx, e);
|
4982
|
+
});
|
4983
|
+
}
|
4984
|
+
return;
|
4985
|
+
}
|
4986
|
+
|
4987
|
+
// Not supported
|
4988
|
+
next(new TypeError('Rx.spawn only supports a function, Promise, Observable, Object or Array.'));
|
4989
|
+
}
|
4990
|
+
}
|
4991
|
+
};
|
4992
|
+
|
4993
|
+
/**
|
4994
|
+
* Takes a function with a callback and turns it into a thunk.
|
4995
|
+
* @param {Function} A function with a callback such as fs.readFile
|
4996
|
+
* @returns {Function} A function, when executed will continue the state machine.
|
4997
|
+
*/
|
4998
|
+
Rx.denodify = function (fn) {
|
4999
|
+
return function (){
|
5000
|
+
var args = slice.call(arguments),
|
5001
|
+
results,
|
5002
|
+
called,
|
5003
|
+
callback;
|
5004
|
+
|
5005
|
+
args.push(function(){
|
5006
|
+
results = arguments;
|
5007
|
+
|
5008
|
+
if (callback && !called) {
|
5009
|
+
called = true;
|
5010
|
+
cb.apply(this, results);
|
5011
|
+
}
|
5012
|
+
});
|
5013
|
+
|
5014
|
+
fn.apply(this, args);
|
5015
|
+
|
5016
|
+
return function (fn){
|
5017
|
+
callback = fn;
|
5018
|
+
|
5019
|
+
if (results && !called) {
|
5020
|
+
called = true;
|
5021
|
+
fn.apply(this, results);
|
5022
|
+
}
|
5023
|
+
}
|
5024
|
+
}
|
5025
|
+
};
|
5026
|
+
|
5027
|
+
/**
|
5028
|
+
* Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
|
5029
|
+
*
|
5030
|
+
* @example
|
5031
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); });
|
5032
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
|
5033
|
+
* var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
|
5034
|
+
*
|
5035
|
+
* @param {Function} func Function to run asynchronously.
|
5036
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5037
|
+
* @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5038
|
+
* @returns {Observable} An observable sequence exposing the function's result value, or an exception.
|
5039
|
+
*
|
5040
|
+
* Remarks
|
5041
|
+
* * The function is called immediately, not during the subscription of the resulting sequence.
|
5042
|
+
* * Multiple subscriptions to the resulting sequence can observe the function's result.
|
5043
|
+
*/
|
5044
|
+
Observable.start = function (func, context, scheduler) {
|
5045
|
+
return observableToAsync(func, context, scheduler)();
|
5046
|
+
};
|
5047
|
+
|
5048
|
+
/**
|
5049
|
+
* 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.
|
5050
|
+
*
|
5051
|
+
* @example
|
5052
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
|
5053
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
5054
|
+
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
5055
|
+
*
|
5056
|
+
* @param {Function} function Function to convert to an asynchronous function.
|
5057
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5058
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5059
|
+
* @returns {Function} Asynchronous function.
|
5060
|
+
*/
|
5061
|
+
var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
5062
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
5063
|
+
return function () {
|
5064
|
+
var args = arguments,
|
5065
|
+
subject = new AsyncSubject();
|
5066
|
+
|
5067
|
+
scheduler.schedule(function () {
|
5068
|
+
var result;
|
5069
|
+
try {
|
5070
|
+
result = func.apply(context, args);
|
5071
|
+
} catch (e) {
|
5072
|
+
subject.onError(e);
|
5073
|
+
return;
|
5074
|
+
}
|
5075
|
+
subject.onNext(result);
|
5076
|
+
subject.onCompleted();
|
5077
|
+
});
|
5078
|
+
return subject.asObservable();
|
5079
|
+
};
|
5080
|
+
};
|
5081
|
+
|
5082
|
+
/**
|
5083
|
+
* Converts a callback function to an observable sequence.
|
5084
|
+
*
|
5085
|
+
* @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
|
5086
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5087
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
5088
|
+
* @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.
|
4929
5089
|
*/
|
4930
5090
|
Observable.fromCallback = function (func, context, selector) {
|
4931
5091
|
return function () {
|
@@ -5276,6 +5436,7 @@
|
|
5276
5436
|
.subscribe(
|
5277
5437
|
function (results) {
|
5278
5438
|
if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
|
5439
|
+
previousShouldFire = results.shouldFire;
|
5279
5440
|
// change in shouldFire
|
5280
5441
|
if (results.shouldFire) {
|
5281
5442
|
while (q.length > 0) {
|
@@ -5283,6 +5444,7 @@
|
|
5283
5444
|
}
|
5284
5445
|
}
|
5285
5446
|
} else {
|
5447
|
+
previousShouldFire = results.shouldFire;
|
5286
5448
|
// new data
|
5287
5449
|
if (results.shouldFire) {
|
5288
5450
|
observer.onNext(results.data);
|
@@ -5290,9 +5452,7 @@
|
|
5290
5452
|
q.push(results.data);
|
5291
5453
|
}
|
5292
5454
|
}
|
5293
|
-
|
5294
|
-
|
5295
|
-
},
|
5455
|
+
},
|
5296
5456
|
function (err) {
|
5297
5457
|
// Empty buffer before sending error
|
5298
5458
|
while (q.length > 0) {
|
@@ -5531,121 +5691,114 @@
|
|
5531
5691
|
var source = this;
|
5532
5692
|
return typeof subjectOrSubjectSelector === 'function' ?
|
5533
5693
|
new AnonymousObservable(function (observer) {
|
5534
|
-
|
5535
|
-
|
5694
|
+
var connectable = source.multicast(subjectOrSubjectSelector());
|
5695
|
+
return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
|
5536
5696
|
}) :
|
5537
5697
|
new ConnectableObservable(source, subjectOrSubjectSelector);
|
5538
5698
|
};
|
5539
5699
|
|
5540
|
-
|
5541
|
-
|
5542
|
-
|
5543
|
-
|
5544
|
-
|
5545
|
-
|
5546
|
-
|
5547
|
-
|
5548
|
-
|
5549
|
-
|
5550
|
-
|
5551
|
-
|
5552
|
-
|
5553
|
-
|
5554
|
-
|
5555
|
-
|
5556
|
-
}, selector);
|
5557
|
-
};
|
5700
|
+
/**
|
5701
|
+
* Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence.
|
5702
|
+
* This operator is a specialization of Multicast using a regular Subject.
|
5703
|
+
*
|
5704
|
+
* @example
|
5705
|
+
* var resres = source.publish();
|
5706
|
+
* var res = source.publish(function (x) { return x; });
|
5707
|
+
*
|
5708
|
+
* @param {Function} [selector] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
|
5709
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5710
|
+
*/
|
5711
|
+
observableProto.publish = function (selector) {
|
5712
|
+
return selector && isFunction(selector) ?
|
5713
|
+
this.multicast(function () { return new Subject(); }, selector) :
|
5714
|
+
this.multicast(new Subject());
|
5715
|
+
};
|
5558
5716
|
|
5559
|
-
|
5560
|
-
|
5561
|
-
|
5562
|
-
|
5563
|
-
|
5564
|
-
|
5565
|
-
|
5566
|
-
|
5567
|
-
|
5568
|
-
|
5569
|
-
|
5570
|
-
|
5717
|
+
/**
|
5718
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence.
|
5719
|
+
* This operator is a specialization of publish 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.
|
5720
|
+
*
|
5721
|
+
* @example
|
5722
|
+
* var res = source.share();
|
5723
|
+
*
|
5724
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
5725
|
+
*/
|
5726
|
+
observableProto.share = function () {
|
5727
|
+
return this.publish().refCount();
|
5728
|
+
};
|
5571
5729
|
|
5572
|
-
|
5573
|
-
|
5574
|
-
|
5575
|
-
|
5576
|
-
|
5577
|
-
|
5578
|
-
|
5579
|
-
|
5580
|
-
|
5581
|
-
|
5582
|
-
|
5583
|
-
|
5584
|
-
|
5585
|
-
|
5586
|
-
|
5587
|
-
|
5588
|
-
}, selector);
|
5589
|
-
};
|
5730
|
+
/**
|
5731
|
+
* Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification.
|
5732
|
+
* This operator is a specialization of Multicast using a AsyncSubject.
|
5733
|
+
*
|
5734
|
+
* @example
|
5735
|
+
* var res = source.publishLast();
|
5736
|
+
* var res = source.publishLast(function (x) { return x; });
|
5737
|
+
*
|
5738
|
+
* @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source.
|
5739
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5740
|
+
*/
|
5741
|
+
observableProto.publishLast = function (selector) {
|
5742
|
+
return selector && isFunction(selector) ?
|
5743
|
+
this.multicast(function () { return new AsyncSubject(); }, selector) :
|
5744
|
+
this.multicast(new AsyncSubject());
|
5745
|
+
};
|
5590
5746
|
|
5591
|
-
|
5592
|
-
|
5593
|
-
|
5594
|
-
|
5595
|
-
|
5596
|
-
|
5597
|
-
|
5598
|
-
|
5599
|
-
|
5600
|
-
|
5601
|
-
|
5602
|
-
|
5603
|
-
|
5604
|
-
|
5605
|
-
|
5606
|
-
|
5607
|
-
|
5608
|
-
|
5609
|
-
|
5747
|
+
/**
|
5748
|
+
* Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue.
|
5749
|
+
* This operator is a specialization of Multicast using a BehaviorSubject.
|
5750
|
+
*
|
5751
|
+
* @example
|
5752
|
+
* var res = source.publishValue(42);
|
5753
|
+
* var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
|
5754
|
+
*
|
5755
|
+
* @param {Function} [selector] Optional selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.
|
5756
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
5757
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5758
|
+
*/
|
5759
|
+
observableProto.publishValue = function (initialValueOrSelector, initialValue) {
|
5760
|
+
return arguments.length === 2 ?
|
5761
|
+
this.multicast(function () {
|
5762
|
+
return new BehaviorSubject(initialValue);
|
5763
|
+
}, initialValueOrSelector) :
|
5764
|
+
this.multicast(new BehaviorSubject(initialValueOrSelector));
|
5765
|
+
};
|
5610
5766
|
|
5611
|
-
|
5612
|
-
|
5613
|
-
|
5614
|
-
|
5615
|
-
|
5616
|
-
|
5617
|
-
|
5618
|
-
|
5619
|
-
|
5620
|
-
|
5621
|
-
|
5622
|
-
|
5623
|
-
|
5624
|
-
};
|
5767
|
+
/**
|
5768
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
|
5769
|
+
* This operator is a specialization of publishValue 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.
|
5770
|
+
*
|
5771
|
+
* @example
|
5772
|
+
* var res = source.shareValue(42);
|
5773
|
+
*
|
5774
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
5775
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
5776
|
+
*/
|
5777
|
+
observableProto.shareValue = function (initialValue) {
|
5778
|
+
return this.publishValue(initialValue).refCount();
|
5779
|
+
};
|
5625
5780
|
|
5626
|
-
|
5627
|
-
|
5628
|
-
|
5629
|
-
|
5630
|
-
|
5631
|
-
|
5632
|
-
|
5633
|
-
|
5634
|
-
|
5635
|
-
|
5636
|
-
|
5637
|
-
|
5638
|
-
|
5639
|
-
|
5640
|
-
|
5641
|
-
|
5642
|
-
|
5643
|
-
|
5644
|
-
|
5645
|
-
|
5646
|
-
|
5647
|
-
}, selector);
|
5648
|
-
};
|
5781
|
+
/**
|
5782
|
+
* Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.
|
5783
|
+
* This operator is a specialization of Multicast using a ReplaySubject.
|
5784
|
+
*
|
5785
|
+
* @example
|
5786
|
+
* var res = source.replay(null, 3);
|
5787
|
+
* var res = source.replay(null, 3, 500);
|
5788
|
+
* var res = source.replay(null, 3, 500, scheduler);
|
5789
|
+
* var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
|
5790
|
+
*
|
5791
|
+
* @param selector [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.
|
5792
|
+
* @param bufferSize [Optional] Maximum element count of the replay buffer.
|
5793
|
+
* @param window [Optional] Maximum time length of the replay buffer.
|
5794
|
+
* @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
|
5795
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5796
|
+
*/
|
5797
|
+
observableProto.replay = function (selector, bufferSize, window, scheduler) {
|
5798
|
+
return selector && isFunction(selector) ?
|
5799
|
+
this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
|
5800
|
+
this.multicast(new ReplaySubject(bufferSize, window, scheduler));
|
5801
|
+
};
|
5649
5802
|
|
5650
5803
|
/**
|
5651
5804
|
* 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.
|
@@ -5684,267 +5837,247 @@
|
|
5684
5837
|
}
|
5685
5838
|
};
|
5686
5839
|
|
5687
|
-
|
5688
|
-
|
5689
|
-
|
5690
|
-
|
5691
|
-
|
5692
|
-
|
5693
|
-
|
5694
|
-
|
5695
|
-
|
5696
|
-
|
5697
|
-
|
5698
|
-
|
5699
|
-
|
5700
|
-
|
5701
|
-
|
5702
|
-
|
5703
|
-
|
5704
|
-
|
5705
|
-
|
5706
|
-
|
5840
|
+
/**
|
5841
|
+
* Represents a value that changes over time.
|
5842
|
+
* Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
|
5843
|
+
*/
|
5844
|
+
var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
|
5845
|
+
function subscribe(observer) {
|
5846
|
+
checkDisposed.call(this);
|
5847
|
+
if (!this.isStopped) {
|
5848
|
+
this.observers.push(observer);
|
5849
|
+
observer.onNext(this.value);
|
5850
|
+
return new InnerSubscription(this, observer);
|
5851
|
+
}
|
5852
|
+
var ex = this.exception;
|
5853
|
+
if (ex) {
|
5854
|
+
observer.onError(ex);
|
5855
|
+
} else {
|
5856
|
+
observer.onCompleted();
|
5857
|
+
}
|
5858
|
+
return disposableEmpty;
|
5859
|
+
}
|
5707
5860
|
|
5708
|
-
|
5861
|
+
inherits(BehaviorSubject, __super__);
|
5709
5862
|
|
5710
|
-
|
5711
|
-
|
5712
|
-
|
5713
|
-
|
5714
|
-
|
5715
|
-
|
5716
|
-
|
5863
|
+
/**
|
5864
|
+
* @constructor
|
5865
|
+
* Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
|
5866
|
+
* @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
|
5867
|
+
*/
|
5868
|
+
function BehaviorSubject(value) {
|
5869
|
+
__super__.call(this, subscribe);
|
5870
|
+
this.value = value,
|
5871
|
+
this.observers = [],
|
5872
|
+
this.isDisposed = false,
|
5873
|
+
this.isStopped = false,
|
5874
|
+
this.exception = null;
|
5875
|
+
}
|
5717
5876
|
|
5718
|
-
|
5719
|
-
|
5720
|
-
|
5721
|
-
|
5722
|
-
|
5877
|
+
addProperties(BehaviorSubject.prototype, Observer, {
|
5878
|
+
/**
|
5879
|
+
* Indicates whether the subject has observers subscribed to it.
|
5880
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5881
|
+
*/
|
5882
|
+
hasObservers: function () {
|
5883
|
+
return this.observers.length > 0;
|
5884
|
+
},
|
5885
|
+
/**
|
5886
|
+
* Notifies all subscribed observers about the end of the sequence.
|
5887
|
+
*/
|
5888
|
+
onCompleted: function () {
|
5889
|
+
checkDisposed.call(this);
|
5890
|
+
if (this.isStopped) { return; }
|
5891
|
+
this.isStopped = true;
|
5892
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5893
|
+
os[i].onCompleted();
|
5723
5894
|
}
|
5724
5895
|
|
5725
|
-
|
5726
|
-
|
5727
|
-
|
5728
|
-
|
5729
|
-
|
5730
|
-
|
5731
|
-
|
5732
|
-
|
5733
|
-
|
5734
|
-
|
5735
|
-
|
5736
|
-
onCompleted: function () {
|
5737
|
-
checkDisposed.call(this);
|
5738
|
-
if (!this.isStopped) {
|
5739
|
-
var os = this.observers.slice(0);
|
5740
|
-
this.isStopped = true;
|
5741
|
-
for (var i = 0, len = os.length; i < len; i++) {
|
5742
|
-
os[i].onCompleted();
|
5743
|
-
}
|
5896
|
+
this.observers = [];
|
5897
|
+
},
|
5898
|
+
/**
|
5899
|
+
* Notifies all subscribed observers about the exception.
|
5900
|
+
* @param {Mixed} error The exception to send to all observers.
|
5901
|
+
*/
|
5902
|
+
onError: function (error) {
|
5903
|
+
checkDisposed.call(this);
|
5904
|
+
if (this.isStopped) { return; }
|
5905
|
+
this.isStopped = true;
|
5906
|
+
this.exception = error;
|
5744
5907
|
|
5745
|
-
|
5746
|
-
|
5747
|
-
|
5748
|
-
/**
|
5749
|
-
* Notifies all subscribed observers about the exception.
|
5750
|
-
* @param {Mixed} error The exception to send to all observers.
|
5751
|
-
*/
|
5752
|
-
onError: function (error) {
|
5753
|
-
checkDisposed.call(this);
|
5754
|
-
if (!this.isStopped) {
|
5755
|
-
var os = this.observers.slice(0);
|
5756
|
-
this.isStopped = true;
|
5757
|
-
this.exception = error;
|
5908
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5909
|
+
os[i].onError(error);
|
5910
|
+
}
|
5758
5911
|
|
5759
|
-
|
5760
|
-
|
5761
|
-
|
5912
|
+
this.observers = [];
|
5913
|
+
},
|
5914
|
+
/**
|
5915
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5916
|
+
* @param {Mixed} value The value to send to all observers.
|
5917
|
+
*/
|
5918
|
+
onNext: function (value) {
|
5919
|
+
checkDisposed.call(this);
|
5920
|
+
if (this.isStopped) { return; }
|
5921
|
+
this.value = value;
|
5922
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5923
|
+
os[i].onNext(value);
|
5924
|
+
}
|
5925
|
+
},
|
5926
|
+
/**
|
5927
|
+
* Unsubscribe all observers and release resources.
|
5928
|
+
*/
|
5929
|
+
dispose: function () {
|
5930
|
+
this.isDisposed = true;
|
5931
|
+
this.observers = null;
|
5932
|
+
this.value = null;
|
5933
|
+
this.exception = null;
|
5934
|
+
}
|
5935
|
+
});
|
5762
5936
|
|
5763
|
-
|
5764
|
-
|
5765
|
-
},
|
5766
|
-
/**
|
5767
|
-
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5768
|
-
* @param {Mixed} value The value to send to all observers.
|
5769
|
-
*/
|
5770
|
-
onNext: function (value) {
|
5771
|
-
checkDisposed.call(this);
|
5772
|
-
if (!this.isStopped) {
|
5773
|
-
this.value = value;
|
5774
|
-
var os = this.observers.slice(0);
|
5775
|
-
for (var i = 0, len = os.length; i < len; i++) {
|
5776
|
-
os[i].onNext(value);
|
5777
|
-
}
|
5778
|
-
}
|
5779
|
-
},
|
5780
|
-
/**
|
5781
|
-
* Unsubscribe all observers and release resources.
|
5782
|
-
*/
|
5783
|
-
dispose: function () {
|
5784
|
-
this.isDisposed = true;
|
5785
|
-
this.observers = null;
|
5786
|
-
this.value = null;
|
5787
|
-
this.exception = null;
|
5788
|
-
}
|
5789
|
-
});
|
5937
|
+
return BehaviorSubject;
|
5938
|
+
}(Observable));
|
5790
5939
|
|
5791
|
-
|
5792
|
-
|
5940
|
+
/**
|
5941
|
+
* Represents an object that is both an observable sequence as well as an observer.
|
5942
|
+
* Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
|
5943
|
+
*/
|
5944
|
+
var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
|
5793
5945
|
|
5794
|
-
|
5795
|
-
|
5796
|
-
|
5797
|
-
|
5798
|
-
|
5946
|
+
function createRemovableDisposable(subject, observer) {
|
5947
|
+
return disposableCreate(function () {
|
5948
|
+
observer.dispose();
|
5949
|
+
!subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
|
5950
|
+
});
|
5951
|
+
}
|
5799
5952
|
|
5800
|
-
|
5801
|
-
|
5802
|
-
|
5803
|
-
|
5953
|
+
function subscribe(observer) {
|
5954
|
+
var so = new ScheduledObserver(this.scheduler, observer),
|
5955
|
+
subscription = createRemovableDisposable(this, so);
|
5956
|
+
checkDisposed.call(this);
|
5957
|
+
this._trim(this.scheduler.now());
|
5958
|
+
this.observers.push(so);
|
5804
5959
|
|
5805
|
-
|
5806
|
-
this.observer.dispose();
|
5807
|
-
if (!this.subject.isDisposed) {
|
5808
|
-
var idx = this.subject.observers.indexOf(this.observer);
|
5809
|
-
this.subject.observers.splice(idx, 1);
|
5810
|
-
}
|
5811
|
-
};
|
5960
|
+
var n = this.q.length;
|
5812
5961
|
|
5813
|
-
|
5814
|
-
|
5815
|
-
|
5816
|
-
checkDisposed.call(this);
|
5817
|
-
this._trim(this.scheduler.now());
|
5818
|
-
this.observers.push(so);
|
5962
|
+
for (var i = 0, len = this.q.length; i < len; i++) {
|
5963
|
+
so.onNext(this.q[i].value);
|
5964
|
+
}
|
5819
5965
|
|
5820
|
-
|
5966
|
+
if (this.hasError) {
|
5967
|
+
n++;
|
5968
|
+
so.onError(this.error);
|
5969
|
+
} else if (this.isStopped) {
|
5970
|
+
n++;
|
5971
|
+
so.onCompleted();
|
5972
|
+
}
|
5821
5973
|
|
5822
|
-
|
5823
|
-
|
5824
|
-
|
5974
|
+
so.ensureActive(n);
|
5975
|
+
return subscription;
|
5976
|
+
}
|
5825
5977
|
|
5826
|
-
|
5827
|
-
n++;
|
5828
|
-
so.onError(this.error);
|
5829
|
-
} else if (this.isStopped) {
|
5830
|
-
n++;
|
5831
|
-
so.onCompleted();
|
5832
|
-
}
|
5978
|
+
inherits(ReplaySubject, __super__);
|
5833
5979
|
|
5834
|
-
|
5835
|
-
|
5836
|
-
|
5980
|
+
/**
|
5981
|
+
* Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
|
5982
|
+
* @param {Number} [bufferSize] Maximum element count of the replay buffer.
|
5983
|
+
* @param {Number} [windowSize] Maximum time length of the replay buffer.
|
5984
|
+
* @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
|
5985
|
+
*/
|
5986
|
+
function ReplaySubject(bufferSize, windowSize, scheduler) {
|
5987
|
+
this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
|
5988
|
+
this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
|
5989
|
+
this.scheduler = scheduler || currentThreadScheduler;
|
5990
|
+
this.q = [];
|
5991
|
+
this.observers = [];
|
5992
|
+
this.isStopped = false;
|
5993
|
+
this.isDisposed = false;
|
5994
|
+
this.hasError = false;
|
5995
|
+
this.error = null;
|
5996
|
+
__super__.call(this, subscribe);
|
5997
|
+
}
|
5837
5998
|
|
5838
|
-
|
5999
|
+
addProperties(ReplaySubject.prototype, Observer, {
|
6000
|
+
/**
|
6001
|
+
* Indicates whether the subject has observers subscribed to it.
|
6002
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
6003
|
+
*/
|
6004
|
+
hasObservers: function () {
|
6005
|
+
return this.observers.length > 0;
|
6006
|
+
},
|
6007
|
+
_trim: function (now) {
|
6008
|
+
while (this.q.length > this.bufferSize) {
|
6009
|
+
this.q.shift();
|
6010
|
+
}
|
6011
|
+
while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
6012
|
+
this.q.shift();
|
6013
|
+
}
|
6014
|
+
},
|
6015
|
+
/**
|
6016
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
6017
|
+
* @param {Mixed} value The value to send to all observers.
|
6018
|
+
*/
|
6019
|
+
onNext: function (value) {
|
6020
|
+
checkDisposed.call(this);
|
6021
|
+
if (this.isStopped) { return; }
|
6022
|
+
var now = this.scheduler.now();
|
6023
|
+
this.q.push({ interval: now, value: value });
|
6024
|
+
this._trim(now);
|
5839
6025
|
|
5840
|
-
|
5841
|
-
|
5842
|
-
|
5843
|
-
|
5844
|
-
|
5845
|
-
|
5846
|
-
|
5847
|
-
|
5848
|
-
|
5849
|
-
|
5850
|
-
|
5851
|
-
|
5852
|
-
|
5853
|
-
|
5854
|
-
|
5855
|
-
|
5856
|
-
|
6026
|
+
var o = this.observers.slice(0);
|
6027
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6028
|
+
var observer = o[i];
|
6029
|
+
observer.onNext(value);
|
6030
|
+
observer.ensureActive();
|
6031
|
+
}
|
6032
|
+
},
|
6033
|
+
/**
|
6034
|
+
* Notifies all subscribed observers about the exception.
|
6035
|
+
* @param {Mixed} error The exception to send to all observers.
|
6036
|
+
*/
|
6037
|
+
onError: function (error) {
|
6038
|
+
checkDisposed.call(this);
|
6039
|
+
if (this.isStopped) { return; }
|
6040
|
+
this.isStopped = true;
|
6041
|
+
this.error = error;
|
6042
|
+
this.hasError = true;
|
6043
|
+
var now = this.scheduler.now();
|
6044
|
+
this._trim(now);
|
6045
|
+
var o = this.observers.slice(0);
|
6046
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6047
|
+
var observer = o[i];
|
6048
|
+
observer.onError(error);
|
6049
|
+
observer.ensureActive();
|
6050
|
+
}
|
6051
|
+
this.observers = [];
|
6052
|
+
},
|
6053
|
+
/**
|
6054
|
+
* Notifies all subscribed observers about the end of the sequence.
|
6055
|
+
*/
|
6056
|
+
onCompleted: function () {
|
6057
|
+
checkDisposed.call(this);
|
6058
|
+
if (this.isStopped) { return; }
|
6059
|
+
this.isStopped = true;
|
6060
|
+
var now = this.scheduler.now();
|
6061
|
+
this._trim(now);
|
6062
|
+
var o = this.observers.slice(0);
|
6063
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6064
|
+
var observer = o[i];
|
6065
|
+
observer.onCompleted();
|
6066
|
+
observer.ensureActive();
|
5857
6067
|
}
|
6068
|
+
this.observers = [];
|
6069
|
+
},
|
6070
|
+
/**
|
6071
|
+
* Unsubscribe all observers and release resources.
|
6072
|
+
*/
|
6073
|
+
dispose: function () {
|
6074
|
+
this.isDisposed = true;
|
6075
|
+
this.observers = null;
|
6076
|
+
}
|
6077
|
+
});
|
5858
6078
|
|
5859
|
-
|
5860
|
-
|
5861
|
-
* Indicates whether the subject has observers subscribed to it.
|
5862
|
-
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5863
|
-
*/
|
5864
|
-
hasObservers: function () {
|
5865
|
-
return this.observers.length > 0;
|
5866
|
-
},
|
5867
|
-
/* @private */
|
5868
|
-
_trim: function (now) {
|
5869
|
-
while (this.q.length > this.bufferSize) {
|
5870
|
-
this.q.shift();
|
5871
|
-
}
|
5872
|
-
while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
5873
|
-
this.q.shift();
|
5874
|
-
}
|
5875
|
-
},
|
5876
|
-
/**
|
5877
|
-
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5878
|
-
* @param {Mixed} value The value to send to all observers.
|
5879
|
-
*/
|
5880
|
-
onNext: function (value) {
|
5881
|
-
var observer;
|
5882
|
-
checkDisposed.call(this);
|
5883
|
-
if (!this.isStopped) {
|
5884
|
-
var now = this.scheduler.now();
|
5885
|
-
this.q.push({ interval: now, value: value });
|
5886
|
-
this._trim(now);
|
5887
|
-
|
5888
|
-
var o = this.observers.slice(0);
|
5889
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
5890
|
-
observer = o[i];
|
5891
|
-
observer.onNext(value);
|
5892
|
-
observer.ensureActive();
|
5893
|
-
}
|
5894
|
-
}
|
5895
|
-
},
|
5896
|
-
/**
|
5897
|
-
* Notifies all subscribed observers about the exception.
|
5898
|
-
* @param {Mixed} error The exception to send to all observers.
|
5899
|
-
*/
|
5900
|
-
onError: function (error) {
|
5901
|
-
var observer;
|
5902
|
-
checkDisposed.call(this);
|
5903
|
-
if (!this.isStopped) {
|
5904
|
-
this.isStopped = true;
|
5905
|
-
this.error = error;
|
5906
|
-
this.hasError = true;
|
5907
|
-
var now = this.scheduler.now();
|
5908
|
-
this._trim(now);
|
5909
|
-
var o = this.observers.slice(0);
|
5910
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
5911
|
-
observer = o[i];
|
5912
|
-
observer.onError(error);
|
5913
|
-
observer.ensureActive();
|
5914
|
-
}
|
5915
|
-
this.observers = [];
|
5916
|
-
}
|
5917
|
-
},
|
5918
|
-
/**
|
5919
|
-
* Notifies all subscribed observers about the end of the sequence.
|
5920
|
-
*/
|
5921
|
-
onCompleted: function () {
|
5922
|
-
var observer;
|
5923
|
-
checkDisposed.call(this);
|
5924
|
-
if (!this.isStopped) {
|
5925
|
-
this.isStopped = true;
|
5926
|
-
var now = this.scheduler.now();
|
5927
|
-
this._trim(now);
|
5928
|
-
var o = this.observers.slice(0);
|
5929
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
5930
|
-
observer = o[i];
|
5931
|
-
observer.onCompleted();
|
5932
|
-
observer.ensureActive();
|
5933
|
-
}
|
5934
|
-
this.observers = [];
|
5935
|
-
}
|
5936
|
-
},
|
5937
|
-
/**
|
5938
|
-
* Unsubscribe all observers and release resources.
|
5939
|
-
*/
|
5940
|
-
dispose: function () {
|
5941
|
-
this.isDisposed = true;
|
5942
|
-
this.observers = null;
|
5943
|
-
}
|
5944
|
-
});
|
5945
|
-
|
5946
|
-
return ReplaySubject;
|
5947
|
-
}(Observable));
|
6079
|
+
return ReplaySubject;
|
6080
|
+
}(Observable));
|
5948
6081
|
|
5949
6082
|
var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
|
5950
6083
|
inherits(ConnectableObservable, __super__);
|
@@ -7407,18 +7540,6 @@
|
|
7407
7540
|
|
7408
7541
|
/**
|
7409
7542
|
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
7410
|
-
*
|
7411
|
-
* @example
|
7412
|
-
* 1 - res = Rx.Observable.timer(new Date());
|
7413
|
-
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
7414
|
-
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
7415
|
-
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
7416
|
-
*
|
7417
|
-
* 5 - res = Rx.Observable.timer(5000);
|
7418
|
-
* 6 - res = Rx.Observable.timer(5000, 1000);
|
7419
|
-
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
7420
|
-
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
7421
|
-
*
|
7422
7543
|
* @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.
|
7423
7544
|
* @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.
|
7424
7545
|
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
@@ -7429,7 +7550,7 @@
|
|
7429
7550
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7430
7551
|
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
7431
7552
|
period = periodOrScheduler;
|
7432
|
-
} else if (periodOrScheduler
|
7553
|
+
} else if (isScheduler(periodOrScheduler)) {
|
7433
7554
|
scheduler = periodOrScheduler;
|
7434
7555
|
}
|
7435
7556
|
if (dueTime instanceof Date && period === undefined) {
|
@@ -7548,7 +7669,37 @@
|
|
7548
7669
|
*/
|
7549
7670
|
observableProto.throttle = function (dueTime, scheduler) {
|
7550
7671
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7551
|
-
|
7672
|
+
var source = this;
|
7673
|
+
return new AnonymousObservable(function (observer) {
|
7674
|
+
var cancelable = new SerialDisposable(), hasvalue = false, value, id = 0;
|
7675
|
+
var subscription = source.subscribe(
|
7676
|
+
function (x) {
|
7677
|
+
hasvalue = true;
|
7678
|
+
value = x;
|
7679
|
+
id++;
|
7680
|
+
var currentId = id,
|
7681
|
+
d = new SingleAssignmentDisposable();
|
7682
|
+
cancelable.setDisposable(d);
|
7683
|
+
d.setDisposable(scheduler.scheduleWithRelative(dueTime, function () {
|
7684
|
+
hasValue && id === currentId && observer.onNext(value);
|
7685
|
+
hasvalue = false;
|
7686
|
+
}));
|
7687
|
+
},
|
7688
|
+
function (e) {
|
7689
|
+
cancelable.dispose();
|
7690
|
+
observer.onError(e);
|
7691
|
+
hasvalue = false;
|
7692
|
+
id++;
|
7693
|
+
},
|
7694
|
+
function () {
|
7695
|
+
cancelable.dispose();
|
7696
|
+
hasvalue && observer.onNext(value);
|
7697
|
+
observer.onCompleted();
|
7698
|
+
hasvalue = false;
|
7699
|
+
id++;
|
7700
|
+
});
|
7701
|
+
return new CompositeDisposable(subscription, cancelable);
|
7702
|
+
});
|
7552
7703
|
};
|
7553
7704
|
|
7554
7705
|
/**
|
@@ -7565,70 +7716,49 @@
|
|
7565
7716
|
*/
|
7566
7717
|
observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
7567
7718
|
var source = this, timeShift;
|
7568
|
-
|
7569
|
-
|
7719
|
+
if (timeShiftOrScheduler === undefined) {
|
7720
|
+
timeShift = timeSpan;
|
7721
|
+
}
|
7570
7722
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7571
7723
|
if (typeof timeShiftOrScheduler === 'number') {
|
7572
7724
|
timeShift = timeShiftOrScheduler;
|
7573
|
-
} else if (
|
7725
|
+
} else if (isScheduler(timeShiftOrScheduler)) {
|
7574
7726
|
timeShift = timeSpan;
|
7575
7727
|
scheduler = timeShiftOrScheduler;
|
7576
7728
|
}
|
7577
7729
|
return new AnonymousObservable(function (observer) {
|
7578
7730
|
var groupDisposable,
|
7579
|
-
|
7580
|
-
|
7581
|
-
|
7582
|
-
|
7583
|
-
|
7584
|
-
|
7585
|
-
|
7586
|
-
|
7587
|
-
|
7588
|
-
|
7589
|
-
q.push(new Subject());
|
7590
|
-
observer.onNext(addRef(q[0], refCountDisposable));
|
7591
|
-
createTimer();
|
7592
|
-
groupDisposable.add(source.subscribe(function (x) {
|
7593
|
-
var i, len;
|
7594
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7595
|
-
q[i].onNext(x);
|
7596
|
-
}
|
7597
|
-
}, function (e) {
|
7598
|
-
var i, len;
|
7599
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7600
|
-
q[i].onError(e);
|
7601
|
-
}
|
7602
|
-
observer.onError(e);
|
7603
|
-
}, function () {
|
7604
|
-
var i, len;
|
7605
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7606
|
-
q[i].onCompleted();
|
7607
|
-
}
|
7608
|
-
observer.onCompleted();
|
7609
|
-
}));
|
7610
|
-
|
7611
|
-
return refCountDisposable;
|
7731
|
+
nextShift = timeShift,
|
7732
|
+
nextSpan = timeSpan,
|
7733
|
+
q = [],
|
7734
|
+
refCountDisposable,
|
7735
|
+
timerD = new SerialDisposable(),
|
7736
|
+
totalTime = 0;
|
7737
|
+
groupDisposable = new CompositeDisposable(timerD),
|
7738
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7612
7739
|
|
7613
|
-
|
7614
|
-
var m = new SingleAssignmentDisposable(),
|
7740
|
+
function createTimer () {
|
7741
|
+
var m = new SingleAssignmentDisposable(),
|
7742
|
+
isSpan = false,
|
7743
|
+
isShift = false;
|
7615
7744
|
timerD.setDisposable(m);
|
7616
|
-
|
7617
7745
|
if (nextSpan === nextShift) {
|
7618
7746
|
isSpan = true;
|
7619
7747
|
isShift = true;
|
7620
7748
|
} else if (nextSpan < nextShift) {
|
7621
|
-
|
7749
|
+
isSpan = true;
|
7622
7750
|
} else {
|
7623
7751
|
isShift = true;
|
7624
7752
|
}
|
7625
|
-
|
7626
7753
|
var newTotalTime = isSpan ? nextSpan : nextShift,
|
7627
|
-
|
7754
|
+
ts = newTotalTime - totalTime;
|
7628
7755
|
totalTime = newTotalTime;
|
7629
|
-
|
7630
|
-
|
7631
|
-
|
7756
|
+
if (isSpan) {
|
7757
|
+
nextSpan += timeShift;
|
7758
|
+
}
|
7759
|
+
if (isShift) {
|
7760
|
+
nextShift += timeShift;
|
7761
|
+
}
|
7632
7762
|
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
7633
7763
|
var s;
|
7634
7764
|
if (isShift) {
|
@@ -7642,17 +7772,30 @@
|
|
7642
7772
|
}
|
7643
7773
|
createTimer();
|
7644
7774
|
}));
|
7645
|
-
}
|
7775
|
+
};
|
7776
|
+
q.push(new Subject());
|
7777
|
+
observer.onNext(addRef(q[0], refCountDisposable));
|
7778
|
+
createTimer();
|
7779
|
+
groupDisposable.add(source.subscribe(function (x) {
|
7780
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
7781
|
+
q[i].onNext(x);
|
7782
|
+
}
|
7783
|
+
}, function (e) {
|
7784
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
7785
|
+
q[i].onError(e);
|
7786
|
+
}
|
7787
|
+
observer.onError(e);
|
7788
|
+
}, function () {
|
7789
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
7790
|
+
q[i].onCompleted();
|
7791
|
+
}
|
7792
|
+
observer.onCompleted();
|
7793
|
+
}));
|
7794
|
+
return refCountDisposable;
|
7646
7795
|
});
|
7647
7796
|
};
|
7648
|
-
|
7649
7797
|
/**
|
7650
7798
|
* 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.
|
7651
|
-
* @example
|
7652
|
-
* 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
|
7653
|
-
* 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
|
7654
|
-
*
|
7655
|
-
* @memberOf Observable#
|
7656
7799
|
* @param {Number} timeSpan Maximum time length of a window.
|
7657
7800
|
* @param {Number} count Maximum element count of a window.
|
7658
7801
|
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
@@ -7663,15 +7806,31 @@
|
|
7663
7806
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7664
7807
|
return new AnonymousObservable(function (observer) {
|
7665
7808
|
var createTimer,
|
7666
|
-
|
7667
|
-
|
7668
|
-
|
7669
|
-
|
7670
|
-
|
7671
|
-
|
7809
|
+
groupDisposable,
|
7810
|
+
n = 0,
|
7811
|
+
refCountDisposable,
|
7812
|
+
s,
|
7813
|
+
timerD = new SerialDisposable(),
|
7814
|
+
windowId = 0;
|
7672
7815
|
groupDisposable = new CompositeDisposable(timerD);
|
7673
7816
|
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7674
|
-
|
7817
|
+
createTimer = function (id) {
|
7818
|
+
var m = new SingleAssignmentDisposable();
|
7819
|
+
timerD.setDisposable(m);
|
7820
|
+
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
7821
|
+
var newId;
|
7822
|
+
if (id !== windowId) {
|
7823
|
+
return;
|
7824
|
+
}
|
7825
|
+
n = 0;
|
7826
|
+
newId = ++windowId;
|
7827
|
+
s.onCompleted();
|
7828
|
+
s = new Subject();
|
7829
|
+
observer.onNext(addRef(s, refCountDisposable));
|
7830
|
+
createTimer(newId);
|
7831
|
+
}));
|
7832
|
+
};
|
7833
|
+
s = new Subject();
|
7675
7834
|
observer.onNext(addRef(s, refCountDisposable));
|
7676
7835
|
createTimer(0);
|
7677
7836
|
groupDisposable.add(source.subscribe(function (x) {
|
@@ -7686,34 +7845,19 @@
|
|
7686
7845
|
s = new Subject();
|
7687
7846
|
observer.onNext(addRef(s, refCountDisposable));
|
7688
7847
|
}
|
7689
|
-
|
7848
|
+
if (newWindow) {
|
7849
|
+
createTimer(newId);
|
7850
|
+
}
|
7690
7851
|
}, function (e) {
|
7691
7852
|
s.onError(e);
|
7692
7853
|
observer.onError(e);
|
7693
7854
|
}, function () {
|
7694
7855
|
s.onCompleted();
|
7695
7856
|
observer.onCompleted();
|
7696
|
-
}));
|
7697
|
-
|
7698
|
-
return refCountDisposable;
|
7699
|
-
|
7700
|
-
function createTimer(id) {
|
7701
|
-
var m = new SingleAssignmentDisposable();
|
7702
|
-
timerD.setDisposable(m);
|
7703
|
-
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
7704
|
-
var newId;
|
7705
|
-
if (id !== windowId) { return; }
|
7706
|
-
n = 0;
|
7707
|
-
newId = ++windowId;
|
7708
|
-
s.onCompleted();
|
7709
|
-
s = new Subject();
|
7710
|
-
observer.onNext(addRef(s, refCountDisposable));
|
7711
|
-
createTimer(newId);
|
7712
|
-
}));
|
7713
|
-
}
|
7857
|
+
}));
|
7858
|
+
return refCountDisposable;
|
7714
7859
|
});
|
7715
7860
|
};
|
7716
|
-
|
7717
7861
|
/**
|
7718
7862
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
|
7719
7863
|
*
|
@@ -7833,16 +7977,7 @@
|
|
7833
7977
|
};
|
7834
7978
|
|
7835
7979
|
/**
|
7836
|
-
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
7837
|
-
*
|
7838
|
-
* @example
|
7839
|
-
* 1 - res = source.timeout(new Date()); // As a date
|
7840
|
-
* 2 - res = source.timeout(5000); // 5 seconds
|
7841
|
-
* 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
|
7842
|
-
* 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
|
7843
|
-
* 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
|
7844
|
-
* 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
|
7845
|
-
*
|
7980
|
+
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
7846
7981
|
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
|
7847
7982
|
* @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
|
7848
7983
|
* @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
|
@@ -7865,7 +8000,7 @@
|
|
7865
8000
|
|
7866
8001
|
subscription.setDisposable(original);
|
7867
8002
|
|
7868
|
-
|
8003
|
+
function createTimer() {
|
7869
8004
|
var myId = id;
|
7870
8005
|
timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
|
7871
8006
|
if (id === myId) {
|
@@ -7873,7 +8008,7 @@
|
|
7873
8008
|
subscription.setDisposable(other.subscribe(observer));
|
7874
8009
|
}
|
7875
8010
|
}));
|
7876
|
-
}
|
8011
|
+
}
|
7877
8012
|
|
7878
8013
|
createTimer();
|
7879
8014
|
|
@@ -8086,83 +8221,71 @@
|
|
8086
8221
|
|
8087
8222
|
/**
|
8088
8223
|
* Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
|
8089
|
-
*
|
8090
|
-
* @example
|
8091
|
-
* 1 - res = source.timeoutWithSelector(Rx.Observable.timer(500));
|
8092
|
-
* 2 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); });
|
8093
|
-
* 3 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); }, Rx.Observable.returnValue(42));
|
8094
|
-
*
|
8095
8224
|
* @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
|
8096
8225
|
* @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
|
8097
8226
|
* @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
|
8098
8227
|
* @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
|
8099
8228
|
*/
|
8100
8229
|
observableProto.timeoutWithSelector = function (firstTimeout, timeoutdurationSelector, other) {
|
8101
|
-
|
8102
|
-
|
8103
|
-
|
8104
|
-
|
8105
|
-
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8230
|
+
if (arguments.length === 1) {
|
8231
|
+
timeoutdurationSelector = firstTimeout;
|
8232
|
+
firstTimeout = observableNever();
|
8233
|
+
}
|
8234
|
+
other || (other = observableThrow(new Error('Timeout')));
|
8235
|
+
var source = this;
|
8236
|
+
return new AnonymousObservable(function (observer) {
|
8237
|
+
var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
|
8109
8238
|
|
8110
|
-
|
8239
|
+
subscription.setDisposable(original);
|
8111
8240
|
|
8112
|
-
|
8113
|
-
var myId = id, timerWins = function () {
|
8114
|
-
return id === myId;
|
8115
|
-
};
|
8116
|
-
var d = new SingleAssignmentDisposable();
|
8117
|
-
timer.setDisposable(d);
|
8118
|
-
d.setDisposable(timeout.subscribe(function () {
|
8119
|
-
if (timerWins()) {
|
8120
|
-
subscription.setDisposable(other.subscribe(observer));
|
8121
|
-
}
|
8122
|
-
d.dispose();
|
8123
|
-
}, function (e) {
|
8124
|
-
if (timerWins()) {
|
8125
|
-
observer.onError(e);
|
8126
|
-
}
|
8127
|
-
}, function () {
|
8128
|
-
if (timerWins()) {
|
8129
|
-
subscription.setDisposable(other.subscribe(observer));
|
8130
|
-
}
|
8131
|
-
}));
|
8132
|
-
};
|
8241
|
+
var id = 0, switched = false;
|
8133
8242
|
|
8134
|
-
|
8135
|
-
|
8136
|
-
var res = !switched;
|
8137
|
-
if (res) {
|
8138
|
-
id++;
|
8139
|
-
}
|
8140
|
-
return res;
|
8141
|
-
};
|
8243
|
+
function setTimer(timeout) {
|
8244
|
+
var myId = id;
|
8142
8245
|
|
8143
|
-
|
8144
|
-
|
8145
|
-
|
8146
|
-
|
8147
|
-
|
8148
|
-
|
8149
|
-
|
8150
|
-
|
8151
|
-
|
8152
|
-
|
8153
|
-
|
8154
|
-
|
8155
|
-
|
8156
|
-
|
8157
|
-
|
8158
|
-
|
8159
|
-
|
8160
|
-
|
8161
|
-
|
8162
|
-
|
8163
|
-
|
8164
|
-
|
8165
|
-
}
|
8246
|
+
function timerWins () {
|
8247
|
+
return id === myId;
|
8248
|
+
}
|
8249
|
+
|
8250
|
+
var d = new SingleAssignmentDisposable();
|
8251
|
+
timer.setDisposable(d);
|
8252
|
+
d.setDisposable(timeout.subscribe(function () {
|
8253
|
+
timerWins() && subscription.setDisposable(other.subscribe(observer));
|
8254
|
+
d.dispose();
|
8255
|
+
}, function (e) {
|
8256
|
+
timerWins() && observer.onError(e);
|
8257
|
+
}, function () {
|
8258
|
+
timerWins() && subscription.setDisposable(other.subscribe(observer));
|
8259
|
+
}));
|
8260
|
+
};
|
8261
|
+
|
8262
|
+
setTimer(firstTimeout);
|
8263
|
+
|
8264
|
+
function observerWins() {
|
8265
|
+
var res = !switched;
|
8266
|
+
if (res) { id++; }
|
8267
|
+
return res;
|
8268
|
+
}
|
8269
|
+
|
8270
|
+
original.setDisposable(source.subscribe(function (x) {
|
8271
|
+
if (observerWins()) {
|
8272
|
+
observer.onNext(x);
|
8273
|
+
var timeout;
|
8274
|
+
try {
|
8275
|
+
timeout = timeoutdurationSelector(x);
|
8276
|
+
} catch (e) {
|
8277
|
+
observer.onError(e);
|
8278
|
+
return;
|
8279
|
+
}
|
8280
|
+
setTimer(isPromise(timeout) ? observableFromPromise(timeout) : timeout);
|
8281
|
+
}
|
8282
|
+
}, function (e) {
|
8283
|
+
observerWins() && observer.onError(e);
|
8284
|
+
}, function () {
|
8285
|
+
observerWins() && observer.onCompleted();
|
8286
|
+
}));
|
8287
|
+
return new CompositeDisposable(subscription, timer);
|
8288
|
+
});
|
8166
8289
|
};
|
8167
8290
|
|
8168
8291
|
/**
|
@@ -8177,7 +8300,8 @@
|
|
8177
8300
|
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
8178
8301
|
var source = this;
|
8179
8302
|
return new AnonymousObservable(function (observer) {
|
8180
|
-
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0
|
8303
|
+
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
|
8304
|
+
var subscription = source.subscribe(function (x) {
|
8181
8305
|
var throttle;
|
8182
8306
|
try {
|
8183
8307
|
throttle = throttleDurationSelector(x);
|
@@ -8185,21 +8309,20 @@
|
|
8185
8309
|
observer.onError(e);
|
8186
8310
|
return;
|
8187
8311
|
}
|
8312
|
+
|
8313
|
+
isPromise(throttle) && (throttle = observableFromPromise(throttle));
|
8314
|
+
|
8188
8315
|
hasValue = true;
|
8189
8316
|
value = x;
|
8190
8317
|
id++;
|
8191
8318
|
var currentid = id, d = new SingleAssignmentDisposable();
|
8192
8319
|
cancelable.setDisposable(d);
|
8193
8320
|
d.setDisposable(throttle.subscribe(function () {
|
8194
|
-
|
8195
|
-
observer.onNext(value);
|
8196
|
-
}
|
8321
|
+
hasValue && id === currentid && observer.onNext(value);
|
8197
8322
|
hasValue = false;
|
8198
8323
|
d.dispose();
|
8199
8324
|
}, observer.onError.bind(observer), function () {
|
8200
|
-
|
8201
|
-
observer.onNext(value);
|
8202
|
-
}
|
8325
|
+
hasValue && id === currentid && observer.onNext(value);
|
8203
8326
|
hasValue = false;
|
8204
8327
|
d.dispose();
|
8205
8328
|
}));
|
@@ -8210,9 +8333,7 @@
|
|
8210
8333
|
id++;
|
8211
8334
|
}, function () {
|
8212
8335
|
cancelable.dispose();
|
8213
|
-
|
8214
|
-
observer.onNext(value);
|
8215
|
-
}
|
8336
|
+
hasValue && observer.onNext(value);
|
8216
8337
|
observer.onCompleted();
|
8217
8338
|
hasValue = false;
|
8218
8339
|
id++;
|
@@ -8258,9 +8379,6 @@
|
|
8258
8379
|
|
8259
8380
|
/**
|
8260
8381
|
* 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.
|
8261
|
-
*
|
8262
|
-
* @example
|
8263
|
-
* 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
|
8264
8382
|
* @description
|
8265
8383
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8266
8384
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
@@ -8274,7 +8392,6 @@
|
|
8274
8392
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8275
8393
|
return new AnonymousObservable(function (observer) {
|
8276
8394
|
var q = [];
|
8277
|
-
|
8278
8395
|
return source.subscribe(function (x) {
|
8279
8396
|
var now = scheduler.now();
|
8280
8397
|
q.push({ interval: now, value: x });
|
@@ -8285,11 +8402,8 @@
|
|
8285
8402
|
var now = scheduler.now();
|
8286
8403
|
while (q.length > 0) {
|
8287
8404
|
var next = q.shift();
|
8288
|
-
if (now - next.interval <= duration) {
|
8289
|
-
observer.onNext(next.value);
|
8290
|
-
}
|
8405
|
+
if (now - next.interval <= duration) { observer.onNext(next.value); }
|
8291
8406
|
}
|
8292
|
-
|
8293
8407
|
observer.onCompleted();
|
8294
8408
|
});
|
8295
8409
|
});
|
@@ -8297,9 +8411,6 @@
|
|
8297
8411
|
|
8298
8412
|
/**
|
8299
8413
|
* 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.
|
8300
|
-
*
|
8301
|
-
* @example
|
8302
|
-
* 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
|
8303
8414
|
* @description
|
8304
8415
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8305
8416
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
@@ -8313,7 +8424,6 @@
|
|
8313
8424
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8314
8425
|
return new AnonymousObservable(function (observer) {
|
8315
8426
|
var q = [];
|
8316
|
-
|
8317
8427
|
return source.subscribe(function (x) {
|
8318
8428
|
var now = scheduler.now();
|
8319
8429
|
q.push({ interval: now, value: x });
|
@@ -8324,11 +8434,8 @@
|
|
8324
8434
|
var now = scheduler.now(), res = [];
|
8325
8435
|
while (q.length > 0) {
|
8326
8436
|
var next = q.shift();
|
8327
|
-
if (now - next.interval <= duration) {
|
8328
|
-
res.push(next.value);
|
8329
|
-
}
|
8437
|
+
if (now - next.interval <= duration) { res.push(next.value); }
|
8330
8438
|
}
|
8331
|
-
|
8332
8439
|
observer.onNext(res);
|
8333
8440
|
observer.onCompleted();
|
8334
8441
|
});
|
@@ -8388,10 +8495,10 @@
|
|
8388
8495
|
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
|
8389
8496
|
*
|
8390
8497
|
* @examples
|
8391
|
-
* 1 - res = source.skipUntilWithTime(new Date(), [
|
8392
|
-
* 2 - res = source.skipUntilWithTime(5000, [
|
8393
|
-
* @param startTime Time to start taking elements from the source sequence. If this value is less than or equal to Date(), no elements will be skipped.
|
8394
|
-
* @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8498
|
+
* 1 - res = source.skipUntilWithTime(new Date(), [scheduler]);
|
8499
|
+
* 2 - res = source.skipUntilWithTime(5000, [scheduler]);
|
8500
|
+
* @param {Date|Number} startTime Time to start taking elements from the source sequence. If this value is less than or equal to Date(), no elements will be skipped.
|
8501
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8395
8502
|
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
8396
8503
|
*/
|
8397
8504
|
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
@@ -8412,13 +8519,9 @@
|
|
8412
8519
|
};
|
8413
8520
|
|
8414
8521
|
/**
|
8415
|
-
* Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
|
8416
|
-
*
|
8417
|
-
* @example
|
8418
|
-
* 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
|
8419
|
-
* 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
|
8522
|
+
* Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
|
8420
8523
|
* @param {Number | Date} endTime Time to stop taking elements from the source sequence. If this value is less than or equal to new Date(), the result stream will complete immediately.
|
8421
|
-
* @param {Scheduler} scheduler Scheduler to run the timer on.
|
8524
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on.
|
8422
8525
|
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
8423
8526
|
*/
|
8424
8527
|
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
@@ -8427,9 +8530,9 @@
|
|
8427
8530
|
'scheduleWithAbsolute' :
|
8428
8531
|
'scheduleWithRelative';
|
8429
8532
|
return new AnonymousObservable(function (observer) {
|
8430
|
-
return new CompositeDisposable(
|
8431
|
-
observer.onCompleted()
|
8432
|
-
|
8533
|
+
return new CompositeDisposable(
|
8534
|
+
scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
|
8535
|
+
source.subscribe(observer));
|
8433
8536
|
});
|
8434
8537
|
};
|
8435
8538
|
|
@@ -8923,30 +9026,25 @@
|
|
8923
9026
|
return AutoDetachObserver;
|
8924
9027
|
}(AbstractObserver));
|
8925
9028
|
|
8926
|
-
|
8927
|
-
|
8928
|
-
inherits(GroupedObservable, _super);
|
9029
|
+
var GroupedObservable = (function (__super__) {
|
9030
|
+
inherits(GroupedObservable, __super__);
|
8929
9031
|
|
8930
|
-
|
8931
|
-
|
8932
|
-
|
9032
|
+
function subscribe(observer) {
|
9033
|
+
return this.underlyingObservable.subscribe(observer);
|
9034
|
+
}
|
8933
9035
|
|
8934
|
-
|
8935
|
-
|
8936
|
-
|
8937
|
-
|
8938
|
-
|
8939
|
-
|
8940
|
-
|
8941
|
-
|
8942
|
-
|
8943
|
-
new AnonymousObservable(function (observer) {
|
8944
|
-
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
8945
|
-
});
|
8946
|
-
}
|
9036
|
+
function GroupedObservable(key, underlyingObservable, mergedDisposable) {
|
9037
|
+
__super__.call(this, subscribe);
|
9038
|
+
this.key = key;
|
9039
|
+
this.underlyingObservable = !mergedDisposable ?
|
9040
|
+
underlyingObservable :
|
9041
|
+
new AnonymousObservable(function (observer) {
|
9042
|
+
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
9043
|
+
});
|
9044
|
+
}
|
8947
9045
|
|
8948
|
-
|
8949
|
-
|
9046
|
+
return GroupedObservable;
|
9047
|
+
}(Observable));
|
8950
9048
|
|
8951
9049
|
/**
|
8952
9050
|
* Represents an object that is both an observable sequence as well as an observer.
|