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, [], []);
|
@@ -546,101 +550,91 @@ if (!Array.prototype.forEach) {
|
|
546
550
|
};
|
547
551
|
}
|
548
552
|
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
553
|
+
// Collections
|
554
|
+
function IndexedItem(id, value) {
|
555
|
+
this.id = id;
|
556
|
+
this.value = value;
|
557
|
+
}
|
554
558
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
return c;
|
561
|
-
};
|
559
|
+
IndexedItem.prototype.compareTo = function (other) {
|
560
|
+
var c = this.value.compareTo(other.value);
|
561
|
+
c === 0 && (c = this.id - other.id);
|
562
|
+
return c;
|
563
|
+
};
|
562
564
|
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
565
|
+
// Priority Queue for Scheduling
|
566
|
+
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
567
|
+
this.items = new Array(capacity);
|
568
|
+
this.length = 0;
|
569
|
+
};
|
568
570
|
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
571
|
+
var priorityProto = PriorityQueue.prototype;
|
572
|
+
priorityProto.isHigherPriority = function (left, right) {
|
573
|
+
return this.items[left].compareTo(this.items[right]) < 0;
|
574
|
+
};
|
573
575
|
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
this.items[parent] = temp;
|
586
|
-
this.percolate(parent);
|
587
|
-
}
|
588
|
-
};
|
576
|
+
priorityProto.percolate = function (index) {
|
577
|
+
if (index >= this.length || index < 0) { return; }
|
578
|
+
var parent = index - 1 >> 1;
|
579
|
+
if (parent < 0 || parent === index) { return; }
|
580
|
+
if (this.isHigherPriority(index, parent)) {
|
581
|
+
var temp = this.items[index];
|
582
|
+
this.items[index] = this.items[parent];
|
583
|
+
this.items[parent] = temp;
|
584
|
+
this.percolate(parent);
|
585
|
+
}
|
586
|
+
};
|
589
587
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
}
|
612
|
-
};
|
613
|
-
|
614
|
-
priorityProto.peek = function () { return this.items[0].value; };
|
588
|
+
priorityProto.heapify = function (index) {
|
589
|
+
+index || (index = 0);
|
590
|
+
if (index >= this.length || index < 0) { return; }
|
591
|
+
var left = 2 * index + 1,
|
592
|
+
right = 2 * index + 2,
|
593
|
+
first = index;
|
594
|
+
if (left < this.length && this.isHigherPriority(left, first)) {
|
595
|
+
first = left;
|
596
|
+
}
|
597
|
+
if (right < this.length && this.isHigherPriority(right, first)) {
|
598
|
+
first = right;
|
599
|
+
}
|
600
|
+
if (first !== index) {
|
601
|
+
var temp = this.items[index];
|
602
|
+
this.items[index] = this.items[first];
|
603
|
+
this.items[first] = temp;
|
604
|
+
this.heapify(first);
|
605
|
+
}
|
606
|
+
};
|
607
|
+
|
608
|
+
priorityProto.peek = function () { return this.items[0].value; };
|
615
609
|
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
610
|
+
priorityProto.removeAt = function (index) {
|
611
|
+
this.items[index] = this.items[--this.length];
|
612
|
+
delete this.items[this.length];
|
613
|
+
this.heapify();
|
614
|
+
};
|
621
615
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
616
|
+
priorityProto.dequeue = function () {
|
617
|
+
var result = this.peek();
|
618
|
+
this.removeAt(0);
|
619
|
+
return result;
|
620
|
+
};
|
627
621
|
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
622
|
+
priorityProto.enqueue = function (item) {
|
623
|
+
var index = this.length++;
|
624
|
+
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
625
|
+
this.percolate(index);
|
626
|
+
};
|
633
627
|
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
628
|
+
priorityProto.remove = function (item) {
|
629
|
+
for (var i = 0; i < this.length; i++) {
|
630
|
+
if (this.items[i].value === item) {
|
631
|
+
this.removeAt(i);
|
632
|
+
return true;
|
633
|
+
}
|
634
|
+
}
|
635
|
+
return false;
|
636
|
+
};
|
637
|
+
PriorityQueue.count = 0;
|
644
638
|
/**
|
645
639
|
* Represents a group of disposable resources that are disposed together.
|
646
640
|
* @constructor
|
@@ -709,39 +703,38 @@ if (!Array.prototype.forEach) {
|
|
709
703
|
return this.disposables.slice(0);
|
710
704
|
};
|
711
705
|
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
706
|
+
/**
|
707
|
+
* Provides a set of static methods for creating Disposables.
|
708
|
+
*
|
709
|
+
* @constructor
|
710
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
711
|
+
*/
|
712
|
+
var Disposable = Rx.Disposable = function (action) {
|
713
|
+
this.isDisposed = false;
|
714
|
+
this.action = action || noop;
|
715
|
+
};
|
722
716
|
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
717
|
+
/** Performs the task of cleaning up resources. */
|
718
|
+
Disposable.prototype.dispose = function () {
|
719
|
+
if (!this.isDisposed) {
|
720
|
+
this.action();
|
721
|
+
this.isDisposed = true;
|
722
|
+
}
|
723
|
+
};
|
730
724
|
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
725
|
+
/**
|
726
|
+
* Creates a disposable object that invokes the specified action when disposed.
|
727
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
728
|
+
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
729
|
+
*/
|
730
|
+
var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
|
737
731
|
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
732
|
+
/**
|
733
|
+
* Gets the disposable that does nothing when disposed.
|
734
|
+
*/
|
735
|
+
var disposableEmpty = Disposable.empty = { dispose: noop };
|
742
736
|
|
743
|
-
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable =
|
744
|
-
SerialDisposable = Rx.SerialDisposable = (function () {
|
737
|
+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function () {
|
745
738
|
function BooleanDisposable () {
|
746
739
|
this.isDisposed = false;
|
747
740
|
this.current = null;
|
@@ -786,6 +779,7 @@ if (!Array.prototype.forEach) {
|
|
786
779
|
|
787
780
|
return BooleanDisposable;
|
788
781
|
}());
|
782
|
+
var SerialDisposable = Rx.SerialDisposable = SingleAssignmentDisposable;
|
789
783
|
/**
|
790
784
|
* Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
|
791
785
|
*/
|
@@ -1154,6 +1148,7 @@ if (!Array.prototype.forEach) {
|
|
1154
1148
|
}(Scheduler.prototype));
|
1155
1149
|
|
1156
1150
|
(function (schedulerProto) {
|
1151
|
+
|
1157
1152
|
/**
|
1158
1153
|
* 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.
|
1159
1154
|
* @param {Number} period Period for running the work periodically.
|
@@ -1171,17 +1166,19 @@ if (!Array.prototype.forEach) {
|
|
1171
1166
|
* @param {Function} action Action to be executed, potentially updating the state.
|
1172
1167
|
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1173
1168
|
*/
|
1174
|
-
Scheduler.prototype.schedulePeriodicWithState = function
|
1169
|
+
Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
|
1170
|
+
if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
|
1175
1171
|
var s = state;
|
1176
|
-
|
1177
|
-
var id = setInterval(function () {
|
1172
|
+
|
1173
|
+
var id = root.setInterval(function () {
|
1178
1174
|
s = action(s);
|
1179
1175
|
}, period);
|
1180
1176
|
|
1181
1177
|
return disposableCreate(function () {
|
1182
|
-
clearInterval(id);
|
1178
|
+
root.clearInterval(id);
|
1183
1179
|
});
|
1184
1180
|
};
|
1181
|
+
|
1185
1182
|
}(Scheduler.prototype));
|
1186
1183
|
|
1187
1184
|
(function (schedulerProto) {
|
@@ -1303,100 +1300,121 @@ if (!Array.prototype.forEach) {
|
|
1303
1300
|
return currentScheduler;
|
1304
1301
|
}());
|
1305
1302
|
|
1306
|
-
|
1307
1303
|
var scheduleMethod, clearMethod = noop;
|
1308
|
-
(function () {
|
1304
|
+
var localTimer = (function () {
|
1305
|
+
var localSetTimeout, localClearTimeout = noop;
|
1306
|
+
if ('WScript' in this) {
|
1307
|
+
localSetTimeout = function (fn, time) {
|
1308
|
+
WScript.Sleep(time);
|
1309
|
+
fn();
|
1310
|
+
};
|
1311
|
+
} else if (!!root.setTimeout) {
|
1312
|
+
localSetTimeout = root.setTimeout;
|
1313
|
+
localClearTimeout = root.clearTimeout;
|
1314
|
+
} else {
|
1315
|
+
throw new Error('No concurrency detected!');
|
1316
|
+
}
|
1309
1317
|
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1318
|
+
return {
|
1319
|
+
setTimeout: localSetTimeout,
|
1320
|
+
clearTimeout: localClearTimeout
|
1321
|
+
};
|
1322
|
+
}());
|
1323
|
+
var localSetTimeout = localTimer.setTimeout,
|
1324
|
+
localClearTimeout = localTimer.clearTimeout;
|
1325
|
+
|
1326
|
+
(function () {
|
1327
|
+
|
1328
|
+
var reNative = RegExp('^' +
|
1329
|
+
String(toString)
|
1330
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1331
|
+
.replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1332
|
+
);
|
1333
|
+
|
1334
|
+
var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1335
|
+
!reNative.test(setImmediate) && setImmediate,
|
1336
|
+
clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
|
1337
|
+
!reNative.test(clearImmediate) && clearImmediate;
|
1338
|
+
|
1339
|
+
function postMessageSupported () {
|
1340
|
+
// Ensure not in a worker
|
1341
|
+
if (!root.postMessage || root.importScripts) { return false; }
|
1342
|
+
var isAsync = false,
|
1343
|
+
oldHandler = root.onmessage;
|
1344
|
+
// Test for async
|
1345
|
+
root.onmessage = function () { isAsync = true; };
|
1346
|
+
root.postMessage('','*');
|
1347
|
+
root.onmessage = oldHandler;
|
1348
|
+
|
1349
|
+
return isAsync;
|
1350
|
+
}
|
1315
1351
|
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1352
|
+
// Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
|
1353
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1354
|
+
scheduleMethod = process.nextTick;
|
1355
|
+
} else if (typeof setImmediate === 'function') {
|
1356
|
+
scheduleMethod = setImmediate;
|
1357
|
+
clearMethod = clearImmediate;
|
1358
|
+
} else if (postMessageSupported()) {
|
1359
|
+
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1360
|
+
tasks = {},
|
1361
|
+
taskId = 0;
|
1362
|
+
|
1363
|
+
function onGlobalPostMessage(event) {
|
1364
|
+
// Only if we're a match to avoid any other global events
|
1365
|
+
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1366
|
+
var handleId = event.data.substring(MSG_PREFIX.length),
|
1367
|
+
action = tasks[handleId];
|
1368
|
+
action();
|
1369
|
+
delete tasks[handleId];
|
1370
|
+
}
|
1332
1371
|
}
|
1333
1372
|
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
clearMethod = clearImmediate;
|
1340
|
-
} else if (postMessageSupported()) {
|
1341
|
-
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1342
|
-
tasks = {},
|
1343
|
-
taskId = 0;
|
1344
|
-
|
1345
|
-
function onGlobalPostMessage(event) {
|
1346
|
-
// Only if we're a match to avoid any other global events
|
1347
|
-
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1348
|
-
var handleId = event.data.substring(MSG_PREFIX.length),
|
1349
|
-
action = tasks[handleId];
|
1350
|
-
action();
|
1351
|
-
delete tasks[handleId];
|
1352
|
-
}
|
1353
|
-
}
|
1354
|
-
|
1355
|
-
if (root.addEventListener) {
|
1356
|
-
root.addEventListener('message', onGlobalPostMessage, false);
|
1357
|
-
} else {
|
1358
|
-
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1359
|
-
}
|
1373
|
+
if (root.addEventListener) {
|
1374
|
+
root.addEventListener('message', onGlobalPostMessage, false);
|
1375
|
+
} else {
|
1376
|
+
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1377
|
+
}
|
1360
1378
|
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1379
|
+
scheduleMethod = function (action) {
|
1380
|
+
var currentId = taskId++;
|
1381
|
+
tasks[currentId] = action;
|
1382
|
+
root.postMessage(MSG_PREFIX + currentId, '*');
|
1383
|
+
};
|
1384
|
+
} else if (!!root.MessageChannel) {
|
1385
|
+
var channel = new root.MessageChannel(),
|
1386
|
+
channelTasks = {},
|
1387
|
+
channelTaskId = 0;
|
1388
|
+
|
1389
|
+
channel.port1.onmessage = function (event) {
|
1390
|
+
var id = event.data,
|
1391
|
+
action = channelTasks[id];
|
1392
|
+
action();
|
1393
|
+
delete channelTasks[id];
|
1394
|
+
};
|
1377
1395
|
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
};
|
1393
|
-
root.document.documentElement.appendChild(scriptElement);
|
1396
|
+
scheduleMethod = function (action) {
|
1397
|
+
var id = channelTaskId++;
|
1398
|
+
channelTasks[id] = action;
|
1399
|
+
channel.port2.postMessage(id);
|
1400
|
+
};
|
1401
|
+
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1402
|
+
|
1403
|
+
scheduleMethod = function (action) {
|
1404
|
+
var scriptElement = root.document.createElement('script');
|
1405
|
+
scriptElement.onreadystatechange = function () {
|
1406
|
+
action();
|
1407
|
+
scriptElement.onreadystatechange = null;
|
1408
|
+
scriptElement.parentNode.removeChild(scriptElement);
|
1409
|
+
scriptElement = null;
|
1394
1410
|
};
|
1411
|
+
root.document.documentElement.appendChild(scriptElement);
|
1412
|
+
};
|
1395
1413
|
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1414
|
+
} else {
|
1415
|
+
scheduleMethod = function (action) { return localSetTimeout(action, 0); };
|
1416
|
+
clearMethod = localClearTimeout;
|
1417
|
+
}
|
1400
1418
|
}());
|
1401
1419
|
|
1402
1420
|
/**
|
@@ -1405,33 +1423,33 @@ if (!Array.prototype.forEach) {
|
|
1405
1423
|
var timeoutScheduler = Scheduler.timeout = (function () {
|
1406
1424
|
|
1407
1425
|
function scheduleNow(state, action) {
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1426
|
+
var scheduler = this,
|
1427
|
+
disposable = new SingleAssignmentDisposable();
|
1428
|
+
var id = scheduleMethod(function () {
|
1429
|
+
if (!disposable.isDisposed) {
|
1430
|
+
disposable.setDisposable(action(scheduler, state));
|
1431
|
+
}
|
1432
|
+
});
|
1433
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1434
|
+
clearMethod(id);
|
1435
|
+
}));
|
1418
1436
|
}
|
1419
1437
|
|
1420
1438
|
function scheduleRelative(state, dueTime, action) {
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1439
|
+
var scheduler = this,
|
1440
|
+
dt = Scheduler.normalize(dueTime);
|
1441
|
+
if (dt === 0) {
|
1442
|
+
return scheduler.scheduleWithState(state, action);
|
1443
|
+
}
|
1444
|
+
var disposable = new SingleAssignmentDisposable();
|
1445
|
+
var id = localSetTimeout(function () {
|
1446
|
+
if (!disposable.isDisposed) {
|
1447
|
+
disposable.setDisposable(action(scheduler, state));
|
1448
|
+
}
|
1449
|
+
}, dt);
|
1450
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1451
|
+
localClearTimeout(id);
|
1452
|
+
}));
|
1435
1453
|
}
|
1436
1454
|
|
1437
1455
|
function scheduleAbsolute(state, dueTime, action) {
|
@@ -2023,11 +2041,11 @@ if (!Array.prototype.forEach) {
|
|
2023
2041
|
return CheckedObserver;
|
2024
2042
|
}(Observer));
|
2025
2043
|
|
2026
|
-
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (
|
2027
|
-
inherits(ScheduledObserver,
|
2044
|
+
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
|
2045
|
+
inherits(ScheduledObserver, __super__);
|
2028
2046
|
|
2029
2047
|
function ScheduledObserver(scheduler, observer) {
|
2030
|
-
|
2048
|
+
__super__.call(this);
|
2031
2049
|
this.scheduler = scheduler;
|
2032
2050
|
this.observer = observer;
|
2033
2051
|
this.isAcquired = false;
|
@@ -2043,10 +2061,10 @@ if (!Array.prototype.forEach) {
|
|
2043
2061
|
});
|
2044
2062
|
};
|
2045
2063
|
|
2046
|
-
ScheduledObserver.prototype.error = function (
|
2064
|
+
ScheduledObserver.prototype.error = function (err) {
|
2047
2065
|
var self = this;
|
2048
2066
|
this.queue.push(function () {
|
2049
|
-
self.observer.onError(
|
2067
|
+
self.observer.onError(err);
|
2050
2068
|
});
|
2051
2069
|
};
|
2052
2070
|
|
@@ -2085,42 +2103,37 @@ if (!Array.prototype.forEach) {
|
|
2085
2103
|
};
|
2086
2104
|
|
2087
2105
|
ScheduledObserver.prototype.dispose = function () {
|
2088
|
-
|
2106
|
+
__super__.prototype.dispose.call(this);
|
2089
2107
|
this.disposable.dispose();
|
2090
2108
|
};
|
2091
2109
|
|
2092
2110
|
return ScheduledObserver;
|
2093
2111
|
}(AbstractObserver));
|
2094
2112
|
|
2095
|
-
|
2096
|
-
|
2097
|
-
inherits(ObserveOnObserver, _super);
|
2113
|
+
var ObserveOnObserver = (function (__super__) {
|
2114
|
+
inherits(ObserveOnObserver, __super__);
|
2098
2115
|
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
}
|
2116
|
+
function ObserveOnObserver() {
|
2117
|
+
__super__.apply(this, arguments);
|
2118
|
+
}
|
2103
2119
|
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
};
|
2120
|
+
ObserveOnObserver.prototype.next = function (value) {
|
2121
|
+
__super__.prototype.next.call(this, value);
|
2122
|
+
this.ensureActive();
|
2123
|
+
};
|
2109
2124
|
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
};
|
2125
|
+
ObserveOnObserver.prototype.error = function (e) {
|
2126
|
+
__super__.prototype.error.call(this, e);
|
2127
|
+
this.ensureActive();
|
2128
|
+
};
|
2115
2129
|
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
};
|
2130
|
+
ObserveOnObserver.prototype.completed = function () {
|
2131
|
+
__super__.prototype.completed.call(this);
|
2132
|
+
this.ensureActive();
|
2133
|
+
};
|
2121
2134
|
|
2122
|
-
|
2123
|
-
|
2135
|
+
return ObserveOnObserver;
|
2136
|
+
})(ScheduledObserver);
|
2124
2137
|
|
2125
2138
|
var observableProto;
|
2126
2139
|
|
@@ -2160,43 +2173,43 @@ if (!Array.prototype.forEach) {
|
|
2160
2173
|
return Observable;
|
2161
2174
|
})();
|
2162
2175
|
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2176
|
+
/**
|
2177
|
+
* Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
|
2178
|
+
*
|
2179
|
+
* This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects
|
2180
|
+
* that require to be run on a scheduler, use subscribeOn.
|
2181
|
+
*
|
2182
|
+
* @param {Scheduler} scheduler Scheduler to notify observers on.
|
2183
|
+
* @returns {Observable} The source sequence whose observations happen on the specified scheduler.
|
2184
|
+
*/
|
2185
|
+
observableProto.observeOn = function (scheduler) {
|
2186
|
+
var source = this;
|
2187
|
+
return new AnonymousObservable(function (observer) {
|
2188
|
+
return source.subscribe(new ObserveOnObserver(scheduler, observer));
|
2189
|
+
});
|
2190
|
+
};
|
2178
2191
|
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2192
|
+
/**
|
2193
|
+
* Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;
|
2194
|
+
* see the remarks section for more information on the distinction between subscribeOn and observeOn.
|
2182
2195
|
|
2183
|
-
|
2184
|
-
|
2196
|
+
* This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer
|
2197
|
+
* callbacks on a scheduler, use observeOn.
|
2185
2198
|
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2199
|
+
* @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on.
|
2200
|
+
* @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
|
2201
|
+
*/
|
2202
|
+
observableProto.subscribeOn = function (scheduler) {
|
2203
|
+
var source = this;
|
2204
|
+
return new AnonymousObservable(function (observer) {
|
2205
|
+
var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
|
2206
|
+
d.setDisposable(m);
|
2207
|
+
m.setDisposable(scheduler.schedule(function () {
|
2208
|
+
d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
|
2209
|
+
}));
|
2210
|
+
return d;
|
2211
|
+
});
|
2212
|
+
};
|
2200
2213
|
|
2201
2214
|
/**
|
2202
2215
|
* Converts a Promise to an Observable sequence
|
@@ -2219,38 +2232,32 @@ if (!Array.prototype.forEach) {
|
|
2219
2232
|
return subject;
|
2220
2233
|
});
|
2221
2234
|
};
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
if (hasValue) {
|
2249
|
-
resolve(value);
|
2250
|
-
}
|
2251
|
-
});
|
2252
|
-
});
|
2253
|
-
};
|
2235
|
+
/*
|
2236
|
+
* Converts an existing observable sequence to an ES6 Compatible Promise
|
2237
|
+
* @example
|
2238
|
+
* var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
|
2239
|
+
*
|
2240
|
+
* // With config
|
2241
|
+
* Rx.config.Promise = RSVP.Promise;
|
2242
|
+
* var promise = Rx.Observable.return(42).toPromise();
|
2243
|
+
* @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
|
2244
|
+
* @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
|
2245
|
+
*/
|
2246
|
+
observableProto.toPromise = function (promiseCtor) {
|
2247
|
+
promiseCtor || (promiseCtor = Rx.config.Promise);
|
2248
|
+
if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
|
2249
|
+
var source = this;
|
2250
|
+
return new promiseCtor(function (resolve, reject) {
|
2251
|
+
// No cancellation can be done
|
2252
|
+
var value, hasValue = false;
|
2253
|
+
source.subscribe(function (v) {
|
2254
|
+
value = v;
|
2255
|
+
hasValue = true;
|
2256
|
+
}, reject, function () {
|
2257
|
+
hasValue && resolve(value);
|
2258
|
+
});
|
2259
|
+
});
|
2260
|
+
};
|
2254
2261
|
/**
|
2255
2262
|
* Creates a list from an observable sequence.
|
2256
2263
|
* @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
|
@@ -2504,15 +2511,15 @@ if (!Array.prototype.forEach) {
|
|
2504
2511
|
return observableFromArray(args, scheduler);
|
2505
2512
|
};
|
2506
2513
|
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2514
|
+
/**
|
2515
|
+
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2516
|
+
* @returns {Observable} An observable sequence whose observers will never get called.
|
2517
|
+
*/
|
2518
|
+
var observableNever = Observable.never = function () {
|
2519
|
+
return new AnonymousObservable(function () {
|
2520
|
+
return disposableEmpty;
|
2521
|
+
});
|
2522
|
+
};
|
2516
2523
|
|
2517
2524
|
/**
|
2518
2525
|
* Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.
|
@@ -2580,16 +2587,12 @@ if (!Array.prototype.forEach) {
|
|
2580
2587
|
|
2581
2588
|
/**
|
2582
2589
|
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2583
|
-
* There is an alias to this method called '
|
2584
|
-
*
|
2585
|
-
* @example
|
2586
|
-
* var res = Rx.Observable.throw(new Error('Error'));
|
2587
|
-
* var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
|
2590
|
+
* There is an alias to this method called 'throwError' for browsers <IE9.
|
2588
2591
|
* @param {Mixed} exception An object used for the sequence's termination.
|
2589
2592
|
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2590
2593
|
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2591
2594
|
*/
|
2592
|
-
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2595
|
+
var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
|
2593
2596
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2594
2597
|
return new AnonymousObservable(function (observer) {
|
2595
2598
|
return scheduler.schedule(function () {
|
@@ -2599,10 +2602,7 @@ if (!Array.prototype.forEach) {
|
|
2599
2602
|
};
|
2600
2603
|
|
2601
2604
|
/**
|
2602
|
-
*
|
2603
|
-
*
|
2604
|
-
* @example
|
2605
|
-
* var res = Rx.Observable.using(function () { return new AsyncSubject(); }, function (s) { return s; });
|
2605
|
+
* Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
|
2606
2606
|
* @param {Function} resourceFactory Factory function to obtain a resource object.
|
2607
2607
|
* @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource.
|
2608
2608
|
* @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object.
|
@@ -2612,9 +2612,7 @@ if (!Array.prototype.forEach) {
|
|
2612
2612
|
var disposable = disposableEmpty, resource, source;
|
2613
2613
|
try {
|
2614
2614
|
resource = resourceFactory();
|
2615
|
-
|
2616
|
-
disposable = resource;
|
2617
|
-
}
|
2615
|
+
resource && (disposable = resource);
|
2618
2616
|
source = observableFactory(resource);
|
2619
2617
|
} catch (exception) {
|
2620
2618
|
return new CompositeDisposable(observableThrow(exception).subscribe(observer), disposable);
|
@@ -2971,20 +2969,16 @@ if (!Array.prototype.forEach) {
|
|
2971
2969
|
var innerSubscription = new SingleAssignmentDisposable();
|
2972
2970
|
group.add(innerSubscription);
|
2973
2971
|
|
2974
|
-
// Check
|
2975
|
-
|
2976
|
-
innerSource = observableFromPromise(innerSource);
|
2977
|
-
}
|
2972
|
+
// Check for promises support
|
2973
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
2978
2974
|
|
2979
|
-
innerSubscription.setDisposable(innerSource.subscribe(function (
|
2980
|
-
|
2981
|
-
|
2982
|
-
group.remove(innerSubscription);
|
2983
|
-
if (isStopped && group.length === 1) { observer.onCompleted(); }
|
2975
|
+
innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
|
2976
|
+
group.remove(innerSubscription);
|
2977
|
+
isStopped && group.length === 1 && observer.onCompleted();
|
2984
2978
|
}));
|
2985
2979
|
}, observer.onError.bind(observer), function () {
|
2986
2980
|
isStopped = true;
|
2987
|
-
|
2981
|
+
group.length === 1 && observer.onCompleted();
|
2988
2982
|
}));
|
2989
2983
|
return group;
|
2990
2984
|
});
|
@@ -2996,9 +2990,7 @@ if (!Array.prototype.forEach) {
|
|
2996
2990
|
* @returns {Observable} An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.
|
2997
2991
|
*/
|
2998
2992
|
observableProto.onErrorResumeNext = function (second) {
|
2999
|
-
if (!second) {
|
3000
|
-
throw new Error('Second observable is required');
|
3001
|
-
}
|
2993
|
+
if (!second) { throw new Error('Second observable is required'); }
|
3002
2994
|
return onErrorResumeNext([this, second]);
|
3003
2995
|
};
|
3004
2996
|
|
@@ -3021,11 +3013,7 @@ if (!Array.prototype.forEach) {
|
|
3021
3013
|
isPromise(current) && (current = observableFromPromise(current));
|
3022
3014
|
d = new SingleAssignmentDisposable();
|
3023
3015
|
subscription.setDisposable(d);
|
3024
|
-
d.setDisposable(current.subscribe(observer.onNext.bind(observer),
|
3025
|
-
self();
|
3026
|
-
}, function () {
|
3027
|
-
self();
|
3028
|
-
}));
|
3016
|
+
d.setDisposable(current.subscribe(observer.onNext.bind(observer), self, self));
|
3029
3017
|
} else {
|
3030
3018
|
observer.onCompleted();
|
3031
3019
|
}
|
@@ -3064,52 +3052,44 @@ if (!Array.prototype.forEach) {
|
|
3064
3052
|
});
|
3065
3053
|
};
|
3066
3054
|
|
3067
|
-
|
3068
|
-
|
3069
|
-
|
3070
|
-
|
3071
|
-
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3077
|
-
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3082
|
-
|
3083
|
-
|
3084
|
-
|
3085
|
-
|
3086
|
-
}
|
3055
|
+
/**
|
3056
|
+
* Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
3057
|
+
* @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.
|
3058
|
+
*/
|
3059
|
+
observableProto['switch'] = observableProto.switchLatest = function () {
|
3060
|
+
var sources = this;
|
3061
|
+
return new AnonymousObservable(function (observer) {
|
3062
|
+
var hasLatest = false,
|
3063
|
+
innerSubscription = new SerialDisposable(),
|
3064
|
+
isStopped = false,
|
3065
|
+
latest = 0,
|
3066
|
+
subscription = sources.subscribe(
|
3067
|
+
function (innerSource) {
|
3068
|
+
var d = new SingleAssignmentDisposable(), id = ++latest;
|
3069
|
+
hasLatest = true;
|
3070
|
+
innerSubscription.setDisposable(d);
|
3071
|
+
|
3072
|
+
// Check if Promise or Observable
|
3073
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
3087
3074
|
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3091
|
-
|
3092
|
-
|
3093
|
-
|
3094
|
-
|
3095
|
-
|
3096
|
-
|
3097
|
-
|
3098
|
-
|
3099
|
-
|
3100
|
-
|
3101
|
-
|
3102
|
-
|
3103
|
-
|
3104
|
-
|
3105
|
-
|
3106
|
-
if (!hasLatest) {
|
3107
|
-
observer.onCompleted();
|
3108
|
-
}
|
3109
|
-
});
|
3110
|
-
return new CompositeDisposable(subscription, innerSubscription);
|
3111
|
-
});
|
3112
|
-
};
|
3075
|
+
d.setDisposable(innerSource.subscribe(
|
3076
|
+
function (x) { latest === id && observer.onNext(x); },
|
3077
|
+
function (e) { latest === id && observer.onError(e); },
|
3078
|
+
function () {
|
3079
|
+
if (latest === id) {
|
3080
|
+
hasLatest = false;
|
3081
|
+
isStopped && observer.onCompleted();
|
3082
|
+
}
|
3083
|
+
}));
|
3084
|
+
},
|
3085
|
+
observer.onError.bind(observer),
|
3086
|
+
function () {
|
3087
|
+
isStopped = true;
|
3088
|
+
!hasLatest && observer.onCompleted();
|
3089
|
+
});
|
3090
|
+
return new CompositeDisposable(subscription, innerSubscription);
|
3091
|
+
});
|
3092
|
+
};
|
3113
3093
|
|
3114
3094
|
/**
|
3115
3095
|
* Returns the values from the source observable sequence until the other observable sequence produces a value.
|
@@ -3274,16 +3254,13 @@ if (!Array.prototype.forEach) {
|
|
3274
3254
|
});
|
3275
3255
|
};
|
3276
3256
|
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3284
|
-
return source.subscribe(observer);
|
3285
|
-
});
|
3286
|
-
};
|
3257
|
+
/**
|
3258
|
+
* Hides the identity of an observable sequence.
|
3259
|
+
* @returns {Observable} An observable sequence that hides the identity of the source sequence.
|
3260
|
+
*/
|
3261
|
+
observableProto.asObservable = function () {
|
3262
|
+
return new AnonymousObservable(this.subscribe.bind(this));
|
3263
|
+
};
|
3287
3264
|
|
3288
3265
|
/**
|
3289
3266
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.
|
@@ -3448,35 +3425,35 @@ if (!Array.prototype.forEach) {
|
|
3448
3425
|
});
|
3449
3426
|
};
|
3450
3427
|
|
3451
|
-
|
3452
|
-
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
3456
|
-
|
3457
|
-
|
3458
|
-
|
3459
|
-
|
3460
|
-
|
3428
|
+
/**
|
3429
|
+
* Ignores all elements in an observable sequence leaving only the termination messages.
|
3430
|
+
* @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
|
3431
|
+
*/
|
3432
|
+
observableProto.ignoreElements = function () {
|
3433
|
+
var source = this;
|
3434
|
+
return new AnonymousObservable(function (observer) {
|
3435
|
+
return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3436
|
+
});
|
3437
|
+
};
|
3461
3438
|
|
3462
|
-
|
3463
|
-
|
3464
|
-
|
3465
|
-
|
3466
|
-
|
3467
|
-
|
3468
|
-
|
3469
|
-
|
3470
|
-
|
3471
|
-
|
3472
|
-
|
3473
|
-
|
3474
|
-
|
3475
|
-
|
3476
|
-
|
3477
|
-
|
3478
|
-
|
3479
|
-
|
3439
|
+
/**
|
3440
|
+
* Materializes the implicit notifications of an observable sequence as explicit notification values.
|
3441
|
+
* @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
|
3442
|
+
*/
|
3443
|
+
observableProto.materialize = function () {
|
3444
|
+
var source = this;
|
3445
|
+
return new AnonymousObservable(function (observer) {
|
3446
|
+
return source.subscribe(function (value) {
|
3447
|
+
observer.onNext(notificationCreateOnNext(value));
|
3448
|
+
}, function (e) {
|
3449
|
+
observer.onNext(notificationCreateOnError(e));
|
3450
|
+
observer.onCompleted();
|
3451
|
+
}, function () {
|
3452
|
+
observer.onNext(notificationCreateOnCompleted());
|
3453
|
+
observer.onCompleted();
|
3454
|
+
});
|
3455
|
+
});
|
3456
|
+
};
|
3480
3457
|
|
3481
3458
|
/**
|
3482
3459
|
* Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
|
@@ -3505,106 +3482,94 @@ if (!Array.prototype.forEach) {
|
|
3505
3482
|
return enumerableRepeat(this, retryCount).catchException();
|
3506
3483
|
};
|
3507
3484
|
|
3508
|
-
|
3509
|
-
|
3510
|
-
|
3511
|
-
|
3512
|
-
|
3513
|
-
|
3514
|
-
|
3515
|
-
|
3516
|
-
|
3517
|
-
|
3518
|
-
|
3519
|
-
|
3520
|
-
|
3521
|
-
|
3522
|
-
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3485
|
+
/**
|
3486
|
+
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
3487
|
+
* For aggregation behavior with no intermediate results, see Observable.aggregate.
|
3488
|
+
* @example
|
3489
|
+
* var res = source.scan(function (acc, x) { return acc + x; });
|
3490
|
+
* var res = source.scan(0, function (acc, x) { return acc + x; });
|
3491
|
+
* @param {Mixed} [seed] The initial accumulator value.
|
3492
|
+
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
3493
|
+
* @returns {Observable} An observable sequence containing the accumulated values.
|
3494
|
+
*/
|
3495
|
+
observableProto.scan = function () {
|
3496
|
+
var hasSeed = false, seed, accumulator, source = this;
|
3497
|
+
if (arguments.length === 2) {
|
3498
|
+
hasSeed = true;
|
3499
|
+
seed = arguments[0];
|
3500
|
+
accumulator = arguments[1];
|
3501
|
+
} else {
|
3502
|
+
accumulator = arguments[0];
|
3503
|
+
}
|
3504
|
+
return new AnonymousObservable(function (observer) {
|
3505
|
+
var hasAccumulation, accumulation, hasValue;
|
3506
|
+
return source.subscribe (
|
3507
|
+
function (x) {
|
3508
|
+
!hasValue && (hasValue = true);
|
3509
|
+
try {
|
3510
|
+
if (hasAccumulation) {
|
3511
|
+
accumulation = accumulator(accumulation, x);
|
3512
|
+
} else {
|
3513
|
+
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3514
|
+
hasAccumulation = true;
|
3515
|
+
}
|
3516
|
+
} catch (e) {
|
3517
|
+
observer.onError(e);
|
3518
|
+
return;
|
3519
|
+
}
|
3520
|
+
|
3521
|
+
observer.onNext(accumulation);
|
3522
|
+
},
|
3523
|
+
observer.onError.bind(observer),
|
3524
|
+
function () {
|
3525
|
+
!hasValue && hasSeed && observer.onNext(seed);
|
3526
|
+
observer.onCompleted();
|
3526
3527
|
}
|
3527
|
-
|
3528
|
-
|
3529
|
-
|
3530
|
-
function (x) {
|
3531
|
-
try {
|
3532
|
-
if (!hasValue) {
|
3533
|
-
hasValue = true;
|
3534
|
-
}
|
3535
|
-
|
3536
|
-
if (hasAccumulation) {
|
3537
|
-
accumulation = accumulator(accumulation, x);
|
3538
|
-
} else {
|
3539
|
-
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3540
|
-
hasAccumulation = true;
|
3541
|
-
}
|
3542
|
-
} catch (e) {
|
3543
|
-
observer.onError(e);
|
3544
|
-
return;
|
3545
|
-
}
|
3546
|
-
|
3547
|
-
observer.onNext(accumulation);
|
3548
|
-
},
|
3549
|
-
observer.onError.bind(observer),
|
3550
|
-
function () {
|
3551
|
-
if (!hasValue && hasSeed) {
|
3552
|
-
observer.onNext(seed);
|
3553
|
-
}
|
3554
|
-
observer.onCompleted();
|
3555
|
-
}
|
3556
|
-
);
|
3557
|
-
});
|
3558
|
-
};
|
3528
|
+
);
|
3529
|
+
});
|
3530
|
+
};
|
3559
3531
|
|
3560
|
-
|
3561
|
-
|
3562
|
-
|
3563
|
-
|
3564
|
-
|
3565
|
-
|
3566
|
-
|
3567
|
-
|
3568
|
-
|
3569
|
-
|
3570
|
-
|
3571
|
-
|
3572
|
-
|
3573
|
-
|
3574
|
-
|
3575
|
-
|
3576
|
-
|
3577
|
-
|
3578
|
-
});
|
3579
|
-
};
|
3532
|
+
/**
|
3533
|
+
* Bypasses a specified number of elements at the end of an observable sequence.
|
3534
|
+
* @description
|
3535
|
+
* This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
|
3536
|
+
* received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
|
3537
|
+
* @param count Number of elements to bypass at the end of the source sequence.
|
3538
|
+
* @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
|
3539
|
+
*/
|
3540
|
+
observableProto.skipLast = function (count) {
|
3541
|
+
var source = this;
|
3542
|
+
return new AnonymousObservable(function (observer) {
|
3543
|
+
var q = [];
|
3544
|
+
return source.subscribe(function (x) {
|
3545
|
+
q.push(x);
|
3546
|
+
q.length > count && observer.onNext(q.shift());
|
3547
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3548
|
+
});
|
3549
|
+
};
|
3580
3550
|
|
3581
|
-
|
3582
|
-
|
3583
|
-
|
3584
|
-
|
3585
|
-
|
3586
|
-
|
3587
|
-
|
3588
|
-
|
3589
|
-
|
3590
|
-
|
3591
|
-
|
3592
|
-
|
3593
|
-
|
3594
|
-
|
3595
|
-
|
3596
|
-
|
3597
|
-
|
3598
|
-
|
3599
|
-
|
3600
|
-
};
|
3551
|
+
/**
|
3552
|
+
* Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
|
3553
|
+
* @example
|
3554
|
+
* var res = source.startWith(1, 2, 3);
|
3555
|
+
* var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
|
3556
|
+
* @param {Arguments} args The specified values to prepend to the observable sequence
|
3557
|
+
* @returns {Observable} The source sequence prepended with the specified values.
|
3558
|
+
*/
|
3559
|
+
observableProto.startWith = function () {
|
3560
|
+
var values, scheduler, start = 0;
|
3561
|
+
if (!!arguments.length && isScheduler(arguments[0])) {
|
3562
|
+
scheduler = arguments[0];
|
3563
|
+
start = 1;
|
3564
|
+
} else {
|
3565
|
+
scheduler = immediateScheduler;
|
3566
|
+
}
|
3567
|
+
values = slice.call(arguments, start);
|
3568
|
+
return enumerableFor([observableFromArray(values, scheduler), this]).concat();
|
3569
|
+
};
|
3601
3570
|
|
3602
3571
|
/**
|
3603
3572
|
* Returns a specified number of contiguous elements from the end of an observable sequence.
|
3604
|
-
*
|
3605
|
-
* @example
|
3606
|
-
* var res = source.takeLast(5);
|
3607
|
-
*
|
3608
3573
|
* @description
|
3609
3574
|
* This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
|
3610
3575
|
* the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
|
@@ -4020,14 +3985,14 @@ if (!Array.prototype.forEach) {
|
|
4020
3985
|
});
|
4021
3986
|
};
|
4022
3987
|
|
4023
|
-
|
4024
|
-
|
4025
|
-
|
4026
|
-
|
4027
|
-
|
4028
|
-
|
4029
|
-
|
4030
|
-
|
3988
|
+
/**
|
3989
|
+
* Retrieves the value of a specified property from all elements in the Observable sequence.
|
3990
|
+
* @param {String} prop The property to pluck.
|
3991
|
+
* @returns {Observable} Returns a new Observable sequence of property values.
|
3992
|
+
*/
|
3993
|
+
observableProto.pluck = function (prop) {
|
3994
|
+
return this.map(function (x) { return x[prop]; });
|
3995
|
+
};
|
4031
3996
|
|
4032
3997
|
function flatMap(source, selector, thisArg) {
|
4033
3998
|
return source.map(function (x, i) {
|
@@ -4123,133 +4088,118 @@ if (!Array.prototype.forEach) {
|
|
4123
4088
|
});
|
4124
4089
|
}).mergeAll();
|
4125
4090
|
};
|
4126
|
-
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
|
4131
|
-
|
4132
|
-
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4136
|
-
|
4091
|
+
/**
|
4092
|
+
* Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
|
4093
|
+
* transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
4094
|
+
* @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.
|
4095
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4096
|
+
* @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
|
4097
|
+
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
4098
|
+
*/
|
4099
|
+
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
4100
|
+
return this.select(selector, thisArg).switchLatest();
|
4101
|
+
};
|
4137
4102
|
|
4138
|
-
|
4139
|
-
|
4140
|
-
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4145
|
-
|
4103
|
+
/**
|
4104
|
+
* Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
|
4105
|
+
* @param {Number} count The number of elements to skip before returning the remaining elements.
|
4106
|
+
* @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
|
4107
|
+
*/
|
4108
|
+
observableProto.skip = function (count) {
|
4109
|
+
if (count < 0) { throw new Error(argumentOutOfRange); }
|
4110
|
+
var source = this;
|
4111
|
+
return new AnonymousObservable(function (observer) {
|
4112
|
+
var remaining = count;
|
4113
|
+
return source.subscribe(function (x) {
|
4114
|
+
if (remaining <= 0) {
|
4115
|
+
observer.onNext(x);
|
4116
|
+
} else {
|
4117
|
+
remaining--;
|
4118
|
+
}
|
4119
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4120
|
+
});
|
4121
|
+
};
|
4122
|
+
|
4123
|
+
/**
|
4124
|
+
* Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
|
4125
|
+
* The element's index is used in the logic of the predicate function.
|
4126
|
+
*
|
4127
|
+
* var res = source.skipWhile(function (value) { return value < 10; });
|
4128
|
+
* var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
|
4129
|
+
* @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.
|
4130
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4131
|
+
* @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.
|
4132
|
+
*/
|
4133
|
+
observableProto.skipWhile = function (predicate, thisArg) {
|
4134
|
+
var source = this;
|
4135
|
+
return new AnonymousObservable(function (observer) {
|
4136
|
+
var i = 0, running = false;
|
4137
|
+
return source.subscribe(function (x) {
|
4138
|
+
if (!running) {
|
4139
|
+
try {
|
4140
|
+
running = !predicate.call(thisArg, x, i++, source);
|
4141
|
+
} catch (e) {
|
4142
|
+
observer.onError(e);
|
4143
|
+
return;
|
4144
|
+
}
|
4146
4145
|
}
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
if (remaining <= 0) {
|
4152
|
-
observer.onNext(x);
|
4153
|
-
} else {
|
4154
|
-
remaining--;
|
4155
|
-
}
|
4156
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4157
|
-
});
|
4158
|
-
};
|
4146
|
+
running && observer.onNext(x);
|
4147
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4148
|
+
});
|
4149
|
+
};
|
4159
4150
|
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
4173
|
-
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
|
4183
|
-
if (running) {
|
4184
|
-
observer.onNext(x);
|
4185
|
-
}
|
4186
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4187
|
-
});
|
4188
|
-
};
|
4151
|
+
/**
|
4152
|
+
* 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).
|
4153
|
+
*
|
4154
|
+
* var res = source.take(5);
|
4155
|
+
* var res = source.take(0, Rx.Scheduler.timeout);
|
4156
|
+
* @param {Number} count The number of elements to return.
|
4157
|
+
* @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
|
4158
|
+
* @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
|
4159
|
+
*/
|
4160
|
+
observableProto.take = function (count, scheduler) {
|
4161
|
+
if (count < 0) { throw new RangeError(argumentOutOfRange); }
|
4162
|
+
if (count === 0) { return observableEmpty(scheduler); }
|
4163
|
+
var observable = this;
|
4164
|
+
return new AnonymousObservable(function (observer) {
|
4165
|
+
var remaining = count;
|
4166
|
+
return observable.subscribe(function (x) {
|
4167
|
+
if (remaining-- > 0) {
|
4168
|
+
observer.onNext(x);
|
4169
|
+
remaining === 0 && observer.onCompleted();
|
4170
|
+
}
|
4171
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4172
|
+
});
|
4173
|
+
};
|
4189
4174
|
|
4190
|
-
|
4191
|
-
|
4192
|
-
|
4193
|
-
|
4194
|
-
|
4195
|
-
|
4196
|
-
|
4197
|
-
|
4198
|
-
|
4199
|
-
|
4200
|
-
|
4201
|
-
|
4202
|
-
|
4203
|
-
|
4204
|
-
|
4175
|
+
/**
|
4176
|
+
* Returns elements from an observable sequence as long as a specified condition is true.
|
4177
|
+
* The element's index is used in the logic of the predicate function.
|
4178
|
+
* @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.
|
4179
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4180
|
+
* @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.
|
4181
|
+
*/
|
4182
|
+
observableProto.takeWhile = function (predicate, thisArg) {
|
4183
|
+
var observable = this;
|
4184
|
+
return new AnonymousObservable(function (observer) {
|
4185
|
+
var i = 0, running = true;
|
4186
|
+
return observable.subscribe(function (x) {
|
4187
|
+
if (running) {
|
4188
|
+
try {
|
4189
|
+
running = predicate.call(thisArg, x, i++, observable);
|
4190
|
+
} catch (e) {
|
4191
|
+
observer.onError(e);
|
4192
|
+
return;
|
4193
|
+
}
|
4194
|
+
if (running) {
|
4195
|
+
observer.onNext(x);
|
4196
|
+
} else {
|
4197
|
+
observer.onCompleted();
|
4198
|
+
}
|
4205
4199
|
}
|
4206
|
-
|
4207
|
-
|
4208
|
-
|
4209
|
-
return observable.subscribe(function (x) {
|
4210
|
-
if (remaining > 0) {
|
4211
|
-
remaining--;
|
4212
|
-
observer.onNext(x);
|
4213
|
-
if (remaining === 0) {
|
4214
|
-
observer.onCompleted();
|
4215
|
-
}
|
4216
|
-
}
|
4217
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4218
|
-
});
|
4219
|
-
};
|
4220
|
-
|
4221
|
-
/**
|
4222
|
-
* Returns elements from an observable sequence as long as a specified condition is true.
|
4223
|
-
* The element's index is used in the logic of the predicate function.
|
4224
|
-
*
|
4225
|
-
* @example
|
4226
|
-
* var res = source.takeWhile(function (value) { return value < 10; });
|
4227
|
-
* var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
|
4228
|
-
* @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.
|
4229
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4230
|
-
* @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.
|
4231
|
-
*/
|
4232
|
-
observableProto.takeWhile = function (predicate, thisArg) {
|
4233
|
-
var observable = this;
|
4234
|
-
return new AnonymousObservable(function (observer) {
|
4235
|
-
var i = 0, running = true;
|
4236
|
-
return observable.subscribe(function (x) {
|
4237
|
-
if (running) {
|
4238
|
-
try {
|
4239
|
-
running = predicate.call(thisArg, x, i++, observable);
|
4240
|
-
} catch (e) {
|
4241
|
-
observer.onError(e);
|
4242
|
-
return;
|
4243
|
-
}
|
4244
|
-
if (running) {
|
4245
|
-
observer.onNext(x);
|
4246
|
-
} else {
|
4247
|
-
observer.onCompleted();
|
4248
|
-
}
|
4249
|
-
}
|
4250
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4251
|
-
});
|
4252
|
-
};
|
4200
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
4201
|
+
});
|
4202
|
+
};
|
4253
4203
|
|
4254
4204
|
/**
|
4255
4205
|
* Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
|
@@ -4298,42 +4248,40 @@ if (!Array.prototype.forEach) {
|
|
4298
4248
|
});
|
4299
4249
|
};
|
4300
4250
|
|
4301
|
-
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4307
|
-
|
4308
|
-
|
4309
|
-
|
4310
|
-
|
4311
|
-
|
4312
|
-
|
4313
|
-
|
4314
|
-
|
4315
|
-
|
4316
|
-
|
4317
|
-
|
4318
|
-
|
4319
|
-
|
4320
|
-
|
4321
|
-
|
4322
|
-
|
4323
|
-
|
4324
|
-
|
4325
|
-
|
4326
|
-
|
4327
|
-
|
4328
|
-
|
4329
|
-
|
4330
|
-
|
4331
|
-
|
4332
|
-
|
4333
|
-
|
4334
|
-
|
4335
|
-
});
|
4336
|
-
}
|
4251
|
+
function extremaBy(source, keySelector, comparer) {
|
4252
|
+
return new AnonymousObservable(function (observer) {
|
4253
|
+
var hasValue = false, lastKey = null, list = [];
|
4254
|
+
return source.subscribe(function (x) {
|
4255
|
+
var comparison, key;
|
4256
|
+
try {
|
4257
|
+
key = keySelector(x);
|
4258
|
+
} catch (ex) {
|
4259
|
+
observer.onError(ex);
|
4260
|
+
return;
|
4261
|
+
}
|
4262
|
+
comparison = 0;
|
4263
|
+
if (!hasValue) {
|
4264
|
+
hasValue = true;
|
4265
|
+
lastKey = key;
|
4266
|
+
} else {
|
4267
|
+
try {
|
4268
|
+
comparison = comparer(key, lastKey);
|
4269
|
+
} catch (ex1) {
|
4270
|
+
observer.onError(ex1);
|
4271
|
+
return;
|
4272
|
+
}
|
4273
|
+
}
|
4274
|
+
if (comparison > 0) {
|
4275
|
+
lastKey = key;
|
4276
|
+
list = [];
|
4277
|
+
}
|
4278
|
+
if (comparison >= 0) { list.push(x); }
|
4279
|
+
}, observer.onError.bind(observer), function () {
|
4280
|
+
observer.onNext(list);
|
4281
|
+
observer.onCompleted();
|
4282
|
+
});
|
4283
|
+
});
|
4284
|
+
}
|
4337
4285
|
|
4338
4286
|
function firstOnly(x) {
|
4339
4287
|
if (x.length === 0) {
|
@@ -4464,25 +4412,25 @@ if (!Array.prototype.forEach) {
|
|
4464
4412
|
});
|
4465
4413
|
};
|
4466
4414
|
|
4415
|
+
/**
|
4416
|
+
* 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.
|
4417
|
+
* @example
|
4418
|
+
* var res = source.sum();
|
4419
|
+
* var res = source.sum(function (x) { return x.value; });
|
4420
|
+
* @param {Function} [selector] A transform function to apply to each element.
|
4421
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4422
|
+
* @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
|
4423
|
+
*/
|
4424
|
+
observableProto.sum = function (keySelector, thisArg) {
|
4425
|
+
return keySelector && isFunction(keySelector) ?
|
4426
|
+
this.map(keySelector, thisArg).sum() :
|
4427
|
+
this.aggregate(0, function (prev, curr) {
|
4428
|
+
return prev + curr;
|
4429
|
+
});
|
4430
|
+
};
|
4431
|
+
|
4467
4432
|
/**
|
4468
|
-
*
|
4469
|
-
* @example
|
4470
|
-
* var res = source.sum();
|
4471
|
-
* var res = source.sum(function (x) { return x.value; });
|
4472
|
-
* @param {Function} [selector] A transform function to apply to each element.
|
4473
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4474
|
-
* @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
|
4475
|
-
*/
|
4476
|
-
observableProto.sum = function (keySelector, thisArg) {
|
4477
|
-
return keySelector ?
|
4478
|
-
this.select(keySelector, thisArg).sum() :
|
4479
|
-
this.aggregate(0, function (prev, curr) {
|
4480
|
-
return prev + curr;
|
4481
|
-
});
|
4482
|
-
};
|
4483
|
-
|
4484
|
-
/**
|
4485
|
-
* Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
|
4433
|
+
* Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
|
4486
4434
|
* @example
|
4487
4435
|
* var res = source.minBy(function (x) { return x.value; });
|
4488
4436
|
* var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
|
@@ -4568,27 +4516,25 @@ if (!Array.prototype.forEach) {
|
|
4568
4516
|
};
|
4569
4517
|
|
4570
4518
|
function sequenceEqualArray(first, second, comparer) {
|
4571
|
-
|
4572
|
-
|
4573
|
-
|
4574
|
-
|
4575
|
-
|
4576
|
-
|
4577
|
-
|
4578
|
-
|
4579
|
-
|
4580
|
-
|
4581
|
-
|
4582
|
-
|
4583
|
-
if (!equal) {
|
4584
|
-
observer.onNext(false);
|
4585
|
-
observer.onCompleted();
|
4586
|
-
}
|
4587
|
-
}, observer.onError.bind(observer), function () {
|
4588
|
-
observer.onNext(count === len);
|
4519
|
+
return new AnonymousObservable(function (observer) {
|
4520
|
+
var count = 0, len = second.length;
|
4521
|
+
return first.subscribe(function (value) {
|
4522
|
+
var equal = false;
|
4523
|
+
try {
|
4524
|
+
count < len && (equal = comparer(value, second[count++]));
|
4525
|
+
} catch (e) {
|
4526
|
+
observer.onError(e);
|
4527
|
+
return;
|
4528
|
+
}
|
4529
|
+
if (!equal) {
|
4530
|
+
observer.onNext(false);
|
4589
4531
|
observer.onCompleted();
|
4590
|
-
}
|
4532
|
+
}
|
4533
|
+
}, observer.onError.bind(observer), function () {
|
4534
|
+
observer.onNext(count === len);
|
4535
|
+
observer.onCompleted();
|
4591
4536
|
});
|
4537
|
+
});
|
4592
4538
|
}
|
4593
4539
|
|
4594
4540
|
/**
|
@@ -4614,17 +4560,17 @@ if (!Array.prototype.forEach) {
|
|
4614
4560
|
var subscription1 = first.subscribe(function (x) {
|
4615
4561
|
var equal, v;
|
4616
4562
|
if (qr.length > 0) {
|
4617
|
-
|
4618
|
-
|
4619
|
-
|
4620
|
-
|
4621
|
-
|
4622
|
-
|
4623
|
-
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4563
|
+
v = qr.shift();
|
4564
|
+
try {
|
4565
|
+
equal = comparer(v, x);
|
4566
|
+
} catch (e) {
|
4567
|
+
observer.onError(e);
|
4568
|
+
return;
|
4569
|
+
}
|
4570
|
+
if (!equal) {
|
4571
|
+
observer.onNext(false);
|
4572
|
+
observer.onCompleted();
|
4573
|
+
}
|
4628
4574
|
} else if (doner) {
|
4629
4575
|
observer.onNext(false);
|
4630
4576
|
observer.onCompleted();
|
@@ -4646,9 +4592,9 @@ if (!Array.prototype.forEach) {
|
|
4646
4592
|
|
4647
4593
|
isPromise(second) && (second = observableFromPromise(second));
|
4648
4594
|
var subscription2 = second.subscribe(function (x) {
|
4649
|
-
var equal
|
4595
|
+
var equal;
|
4650
4596
|
if (ql.length > 0) {
|
4651
|
-
v = ql.shift();
|
4597
|
+
var v = ql.shift();
|
4652
4598
|
try {
|
4653
4599
|
equal = comparer(v, x);
|
4654
4600
|
} catch (exception) {
|
@@ -4728,60 +4674,60 @@ if (!Array.prototype.forEach) {
|
|
4728
4674
|
return elementAtOrDefault(this, index, true, defaultValue);
|
4729
4675
|
};
|
4730
4676
|
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4677
|
+
function singleOrDefaultAsync(source, hasDefault, defaultValue) {
|
4678
|
+
return new AnonymousObservable(function (observer) {
|
4679
|
+
var value = defaultValue, seenValue = false;
|
4680
|
+
return source.subscribe(function (x) {
|
4681
|
+
if (seenValue) {
|
4682
|
+
observer.onError(new Error('Sequence contains more than one element'));
|
4683
|
+
} else {
|
4684
|
+
value = x;
|
4685
|
+
seenValue = true;
|
4686
|
+
}
|
4687
|
+
}, observer.onError.bind(observer), function () {
|
4688
|
+
if (!seenValue && !hasDefault) {
|
4689
|
+
observer.onError(new Error(sequenceContainsNoElements));
|
4690
|
+
} else {
|
4691
|
+
observer.onNext(value);
|
4692
|
+
observer.onCompleted();
|
4693
|
+
}
|
4694
|
+
});
|
4695
|
+
});
|
4696
|
+
}
|
4751
4697
|
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4698
|
+
/**
|
4699
|
+
* 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.
|
4700
|
+
* @example
|
4701
|
+
* var res = res = source.single();
|
4702
|
+
* var res = res = source.single(function (x) { return x === 42; });
|
4703
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
4704
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
4705
|
+
* @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
|
4706
|
+
*/
|
4707
|
+
observableProto.single = function (predicate, thisArg) {
|
4708
|
+
return predicate && isFunction(predicate) ?
|
4709
|
+
this.where(predicate, thisArg).single() :
|
4710
|
+
singleOrDefaultAsync(this, false);
|
4711
|
+
};
|
4766
4712
|
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4713
|
+
/**
|
4714
|
+
* 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.
|
4715
|
+
* @example
|
4716
|
+
* var res = res = source.singleOrDefault();
|
4717
|
+
* var res = res = source.singleOrDefault(function (x) { return x === 42; });
|
4718
|
+
* res = source.singleOrDefault(function (x) { return x === 42; }, 0);
|
4719
|
+
* res = source.singleOrDefault(null, 0);
|
4720
|
+
* @memberOf Observable#
|
4721
|
+
* @param {Function} predicate A predicate function to evaluate for elements in the source sequence.
|
4722
|
+
* @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
|
4723
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
4724
|
+
* @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.
|
4725
|
+
*/
|
4726
|
+
observableProto.singleOrDefault = function (predicate, defaultValue, thisArg) {
|
4727
|
+
return predicate && isFunction(predicate) ?
|
4728
|
+
this.where(predicate, thisArg).singleOrDefault(null, defaultValue) :
|
4729
|
+
singleOrDefaultAsync(this, true, defaultValue);
|
4730
|
+
};
|
4785
4731
|
function firstOrDefaultAsync(source, hasDefault, defaultValue) {
|
4786
4732
|
return new AnonymousObservable(function (observer) {
|
4787
4733
|
return source.subscribe(function (x) {
|
@@ -4926,71 +4872,26 @@ if (!Array.prototype.forEach) {
|
|
4926
4872
|
return findValue(this, predicate, thisArg, true);
|
4927
4873
|
};
|
4928
4874
|
|
4929
|
-
function toSet(source, type) {
|
4930
|
-
return new AnonymousObservable(function (observer) {
|
4931
|
-
var s = new type();
|
4932
|
-
return source.subscribe(
|
4933
|
-
s.add.bind(s),
|
4934
|
-
observer.onError.bind(observer),
|
4935
|
-
function () {
|
4936
|
-
observer.onNext(s);
|
4937
|
-
observer.onCompleted();
|
4938
|
-
});
|
4939
|
-
});
|
4940
|
-
}
|
4941
4875
|
if (!!root.Set) {
|
4942
4876
|
/**
|
4943
4877
|
* Converts the observable sequence to a Set if it exists.
|
4944
4878
|
* @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
|
4945
4879
|
*/
|
4946
4880
|
observableProto.toSet = function () {
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
|
4881
|
+
var source = this;
|
4882
|
+
return new AnonymousObservable(function (observer) {
|
4883
|
+
var s = new root.Set();
|
4884
|
+
return source.subscribe(
|
4885
|
+
s.add.bind(s),
|
4886
|
+
observer.onError.bind(observer),
|
4887
|
+
function () {
|
4888
|
+
observer.onNext(s);
|
4889
|
+
observer.onCompleted();
|
4890
|
+
});
|
4891
|
+
});
|
4958
4892
|
};
|
4959
4893
|
}
|
4960
4894
|
|
4961
|
-
function toMap(source, type, keySelector, elementSelector) {
|
4962
|
-
return new AnonymousObservable(function (observer) {
|
4963
|
-
var m = new type();
|
4964
|
-
return source.subscribe(
|
4965
|
-
function (x) {
|
4966
|
-
var key;
|
4967
|
-
try {
|
4968
|
-
key = keySelector(x);
|
4969
|
-
} catch (e) {
|
4970
|
-
observer.onError(e);
|
4971
|
-
return;
|
4972
|
-
}
|
4973
|
-
|
4974
|
-
var element = x;
|
4975
|
-
if (elementSelector) {
|
4976
|
-
try {
|
4977
|
-
element = elementSelector(x);
|
4978
|
-
} catch (e) {
|
4979
|
-
observer.onError(e);
|
4980
|
-
return;
|
4981
|
-
}
|
4982
|
-
}
|
4983
|
-
|
4984
|
-
m.set(key, element);
|
4985
|
-
},
|
4986
|
-
observer.onError.bind(observer),
|
4987
|
-
function () {
|
4988
|
-
observer.onNext(m);
|
4989
|
-
observer.onCompleted();
|
4990
|
-
});
|
4991
|
-
});
|
4992
|
-
}
|
4993
|
-
|
4994
4895
|
if (!!root.Map) {
|
4995
4896
|
/**
|
4996
4897
|
* Converts the observable sequence to a Map if it exists.
|
@@ -4999,86 +4900,345 @@ if (!Array.prototype.forEach) {
|
|
4999
4900
|
* @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
|
5000
4901
|
*/
|
5001
4902
|
observableProto.toMap = function (keySelector, elementSelector) {
|
5002
|
-
|
4903
|
+
var source = this;
|
4904
|
+
return new AnonymousObservable(function (observer) {
|
4905
|
+
var m = new root.Map();
|
4906
|
+
return source.subscribe(
|
4907
|
+
function (x) {
|
4908
|
+
var key;
|
4909
|
+
try {
|
4910
|
+
key = keySelector(x);
|
4911
|
+
} catch (e) {
|
4912
|
+
observer.onError(e);
|
4913
|
+
return;
|
4914
|
+
}
|
4915
|
+
|
4916
|
+
var element = x;
|
4917
|
+
if (elementSelector) {
|
4918
|
+
try {
|
4919
|
+
element = elementSelector(x);
|
4920
|
+
} catch (e) {
|
4921
|
+
observer.onError(e);
|
4922
|
+
return;
|
4923
|
+
}
|
4924
|
+
}
|
4925
|
+
|
4926
|
+
m.set(key, element);
|
4927
|
+
},
|
4928
|
+
observer.onError.bind(observer),
|
4929
|
+
function () {
|
4930
|
+
observer.onNext(m);
|
4931
|
+
observer.onCompleted();
|
4932
|
+
});
|
4933
|
+
});
|
5003
4934
|
};
|
5004
4935
|
}
|
5005
4936
|
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
5010
|
-
|
5011
|
-
|
5012
|
-
|
5013
|
-
|
5014
|
-
return
|
5015
|
-
}
|
4937
|
+
var fnString = 'function';
|
4938
|
+
|
4939
|
+
function toThunk(obj, ctx) {
|
4940
|
+
if (Array.isArray(obj)) {
|
4941
|
+
return objectToThunk.call(ctx, obj);
|
4942
|
+
}
|
4943
|
+
|
4944
|
+
if (isGeneratorFunction(obj)) {
|
4945
|
+
return observableSpawn(obj.call(ctx));
|
4946
|
+
}
|
4947
|
+
|
4948
|
+
if (isGenerator(obj)) {
|
4949
|
+
return observableSpawn(obj);
|
4950
|
+
}
|
4951
|
+
|
4952
|
+
if (isObservable(obj)) {
|
4953
|
+
return observableToThunk(obj);
|
4954
|
+
}
|
4955
|
+
|
4956
|
+
if (isPromise(obj)) {
|
4957
|
+
return promiseToThunk(obj);
|
4958
|
+
}
|
4959
|
+
|
4960
|
+
if (typeof obj === fnString) {
|
4961
|
+
return obj;
|
4962
|
+
}
|
4963
|
+
|
4964
|
+
if (isObject(obj) || Array.isArray(obj)) {
|
4965
|
+
return objectToThunk.call(ctx, obj);
|
4966
|
+
}
|
4967
|
+
|
4968
|
+
return obj;
|
5016
4969
|
}
|
5017
4970
|
|
5018
|
-
|
5019
|
-
|
5020
|
-
*
|
5021
|
-
* @example
|
5022
|
-
* var res = Rx.Observable.start(function () { console.log('hello'); });
|
5023
|
-
* var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
|
5024
|
-
* var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
|
5025
|
-
*
|
5026
|
-
* @param {Function} func Function to run asynchronously.
|
5027
|
-
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5028
|
-
* @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5029
|
-
* @returns {Observable} An observable sequence exposing the function's result value, or an exception.
|
5030
|
-
*
|
5031
|
-
* Remarks
|
5032
|
-
* * The function is called immediately, not during the subscription of the resulting sequence.
|
5033
|
-
* * Multiple subscriptions to the resulting sequence can observe the function's result.
|
5034
|
-
*/
|
5035
|
-
Observable.start = function (func, context, scheduler) {
|
5036
|
-
return observableToAsync(func, context, scheduler)();
|
5037
|
-
};
|
4971
|
+
function objectToThunk(obj) {
|
4972
|
+
var ctx = this;
|
5038
4973
|
|
5039
|
-
|
5040
|
-
|
5041
|
-
|
5042
|
-
|
5043
|
-
|
5044
|
-
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
5045
|
-
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
5046
|
-
*
|
5047
|
-
* @param {Function} function Function to convert to an asynchronous function.
|
5048
|
-
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5049
|
-
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5050
|
-
* @returns {Function} Asynchronous function.
|
5051
|
-
*/
|
5052
|
-
var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
5053
|
-
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
5054
|
-
return function () {
|
5055
|
-
var args = arguments,
|
5056
|
-
subject = new AsyncSubject();
|
4974
|
+
return function (done) {
|
4975
|
+
var keys = Object.keys(obj),
|
4976
|
+
pending = keys.length,
|
4977
|
+
results = new obj.constructor(),
|
4978
|
+
finished;
|
5057
4979
|
|
5058
|
-
|
5059
|
-
|
4980
|
+
if (!pending) {
|
4981
|
+
timeoutScheduler.schedule(function () { done(null, results); });
|
4982
|
+
return;
|
4983
|
+
}
|
4984
|
+
|
4985
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
4986
|
+
run(obj[keys[i]], keys[i]);
|
4987
|
+
}
|
4988
|
+
|
4989
|
+
function run(fn, key) {
|
4990
|
+
if (finished) { return; }
|
5060
4991
|
try {
|
5061
|
-
|
4992
|
+
fn = toThunk(fn, ctx);
|
4993
|
+
|
4994
|
+
if (typeof fn !== fnString) {
|
4995
|
+
results[key] = fn;
|
4996
|
+
return --pending || done(null, results);
|
4997
|
+
}
|
4998
|
+
|
4999
|
+
fn.call(ctx, function(err, res){
|
5000
|
+
if (finished) { return; }
|
5001
|
+
|
5002
|
+
if (err) {
|
5003
|
+
finished = true;
|
5004
|
+
return done(err);
|
5005
|
+
}
|
5006
|
+
|
5007
|
+
results[key] = res;
|
5008
|
+
--pending || done(null, results);
|
5009
|
+
});
|
5062
5010
|
} catch (e) {
|
5063
|
-
|
5064
|
-
|
5011
|
+
finished = true;
|
5012
|
+
done(e);
|
5065
5013
|
}
|
5066
|
-
|
5067
|
-
|
5068
|
-
|
5069
|
-
return subject.asObservable();
|
5070
|
-
};
|
5071
|
-
};
|
5014
|
+
}
|
5015
|
+
}
|
5016
|
+
}
|
5072
5017
|
|
5073
|
-
|
5074
|
-
|
5075
|
-
|
5076
|
-
|
5077
|
-
|
5078
|
-
|
5079
|
-
|
5080
|
-
|
5081
|
-
|
5018
|
+
function observableToThink(observable) {
|
5019
|
+
return function (fn) {
|
5020
|
+
var value, hasValue = false;
|
5021
|
+
observable.subscribe(
|
5022
|
+
function (v) {
|
5023
|
+
value = v;
|
5024
|
+
hasValue = true;
|
5025
|
+
},
|
5026
|
+
fn,
|
5027
|
+
function () {
|
5028
|
+
hasValue && fn(null, value);
|
5029
|
+
});
|
5030
|
+
}
|
5031
|
+
}
|
5032
|
+
|
5033
|
+
function promiseToThunk(promise) {
|
5034
|
+
return function(fn){
|
5035
|
+
promise.then(function(res) {
|
5036
|
+
fn(null, res);
|
5037
|
+
}, fn);
|
5038
|
+
}
|
5039
|
+
}
|
5040
|
+
|
5041
|
+
function isObservable(obj) {
|
5042
|
+
return obj && obj.prototype.subscribe === fnString;
|
5043
|
+
}
|
5044
|
+
|
5045
|
+
function isGeneratorFunction(obj) {
|
5046
|
+
return obj && obj.constructor && obj.constructor.name === 'GeneratorFunction';
|
5047
|
+
}
|
5048
|
+
|
5049
|
+
function isGenerator(obj) {
|
5050
|
+
return obj && typeof obj.next === fnString && typeof obj.throw === fnString;
|
5051
|
+
}
|
5052
|
+
|
5053
|
+
function isObject(val) {
|
5054
|
+
return val && val.constructor === Object;
|
5055
|
+
}
|
5056
|
+
|
5057
|
+
/*
|
5058
|
+
* Spawns a generator function which allows for Promises, Observable sequences, Arrays, Objects, Generators and functions.
|
5059
|
+
* @param {Function} The spawning function.
|
5060
|
+
* @returns {Function} a function which has a done continuation.
|
5061
|
+
*/
|
5062
|
+
var observableSpawn = Rx.spawn = function (fn) {
|
5063
|
+
var isGenFun = isGeneratorFunction(fn);
|
5064
|
+
|
5065
|
+
return function (done) {
|
5066
|
+
var ctx = this,
|
5067
|
+
gen = fan;
|
5068
|
+
|
5069
|
+
if (isGenFun) {
|
5070
|
+
var args = slice.call(arguments),
|
5071
|
+
len = args.length,
|
5072
|
+
hasCallback = len && typeof args[len - 1] === fnString;
|
5073
|
+
|
5074
|
+
done = hasCallback ? args.pop() : error;
|
5075
|
+
gen = fn.apply(this, args);
|
5076
|
+
} else {
|
5077
|
+
done = done || error;
|
5078
|
+
}
|
5079
|
+
|
5080
|
+
next();
|
5081
|
+
|
5082
|
+
function exit(err, res) {
|
5083
|
+
timeoutScheduler.schedule(done.bind(ctx, err, res));
|
5084
|
+
}
|
5085
|
+
|
5086
|
+
function next(err, res) {
|
5087
|
+
var ret;
|
5088
|
+
|
5089
|
+
// multiple args
|
5090
|
+
if (arguments.length > 2) res = slice.call(arguments, 1);
|
5091
|
+
|
5092
|
+
if (err) {
|
5093
|
+
try {
|
5094
|
+
ret = gen.throw(err);
|
5095
|
+
} catch (e) {
|
5096
|
+
return exit(e);
|
5097
|
+
}
|
5098
|
+
}
|
5099
|
+
|
5100
|
+
if (!err) {
|
5101
|
+
try {
|
5102
|
+
ret = gen.next(res);
|
5103
|
+
} catch (e) {
|
5104
|
+
return exit(e);
|
5105
|
+
}
|
5106
|
+
}
|
5107
|
+
|
5108
|
+
if (ret.done) {
|
5109
|
+
return exit(null, ret.value);
|
5110
|
+
}
|
5111
|
+
|
5112
|
+
ret.value = toThunk(ret.value, ctx);
|
5113
|
+
|
5114
|
+
if (typeof ret.value === fnString) {
|
5115
|
+
var called = false;
|
5116
|
+
try {
|
5117
|
+
ret.value.call(ctx, function(){
|
5118
|
+
if (called) {
|
5119
|
+
return;
|
5120
|
+
}
|
5121
|
+
|
5122
|
+
called = true;
|
5123
|
+
next.apply(ctx, arguments);
|
5124
|
+
});
|
5125
|
+
} catch (e) {
|
5126
|
+
timeoutScheduler.schedule(function () {
|
5127
|
+
if (called) {
|
5128
|
+
return;
|
5129
|
+
}
|
5130
|
+
|
5131
|
+
called = true;
|
5132
|
+
next.call(ctx, e);
|
5133
|
+
});
|
5134
|
+
}
|
5135
|
+
return;
|
5136
|
+
}
|
5137
|
+
|
5138
|
+
// Not supported
|
5139
|
+
next(new TypeError('Rx.spawn only supports a function, Promise, Observable, Object or Array.'));
|
5140
|
+
}
|
5141
|
+
}
|
5142
|
+
};
|
5143
|
+
|
5144
|
+
/**
|
5145
|
+
* Takes a function with a callback and turns it into a thunk.
|
5146
|
+
* @param {Function} A function with a callback such as fs.readFile
|
5147
|
+
* @returns {Function} A function, when executed will continue the state machine.
|
5148
|
+
*/
|
5149
|
+
Rx.denodify = function (fn) {
|
5150
|
+
return function (){
|
5151
|
+
var args = slice.call(arguments),
|
5152
|
+
results,
|
5153
|
+
called,
|
5154
|
+
callback;
|
5155
|
+
|
5156
|
+
args.push(function(){
|
5157
|
+
results = arguments;
|
5158
|
+
|
5159
|
+
if (callback && !called) {
|
5160
|
+
called = true;
|
5161
|
+
cb.apply(this, results);
|
5162
|
+
}
|
5163
|
+
});
|
5164
|
+
|
5165
|
+
fn.apply(this, args);
|
5166
|
+
|
5167
|
+
return function (fn){
|
5168
|
+
callback = fn;
|
5169
|
+
|
5170
|
+
if (results && !called) {
|
5171
|
+
called = true;
|
5172
|
+
fn.apply(this, results);
|
5173
|
+
}
|
5174
|
+
}
|
5175
|
+
}
|
5176
|
+
};
|
5177
|
+
|
5178
|
+
/**
|
5179
|
+
* Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
|
5180
|
+
*
|
5181
|
+
* @example
|
5182
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); });
|
5183
|
+
* var res = Rx.Observable.start(function () { console.log('hello'); }, Rx.Scheduler.timeout);
|
5184
|
+
* var res = Rx.Observable.start(function () { this.log('hello'); }, Rx.Scheduler.timeout, console);
|
5185
|
+
*
|
5186
|
+
* @param {Function} func Function to run asynchronously.
|
5187
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5188
|
+
* @param [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5189
|
+
* @returns {Observable} An observable sequence exposing the function's result value, or an exception.
|
5190
|
+
*
|
5191
|
+
* Remarks
|
5192
|
+
* * The function is called immediately, not during the subscription of the resulting sequence.
|
5193
|
+
* * Multiple subscriptions to the resulting sequence can observe the function's result.
|
5194
|
+
*/
|
5195
|
+
Observable.start = function (func, context, scheduler) {
|
5196
|
+
return observableToAsync(func, context, scheduler)();
|
5197
|
+
};
|
5198
|
+
|
5199
|
+
/**
|
5200
|
+
* 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.
|
5201
|
+
*
|
5202
|
+
* @example
|
5203
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
|
5204
|
+
* var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
|
5205
|
+
* var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
|
5206
|
+
*
|
5207
|
+
* @param {Function} function Function to convert to an asynchronous function.
|
5208
|
+
* @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
|
5209
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5210
|
+
* @returns {Function} Asynchronous function.
|
5211
|
+
*/
|
5212
|
+
var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
5213
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
5214
|
+
return function () {
|
5215
|
+
var args = arguments,
|
5216
|
+
subject = new AsyncSubject();
|
5217
|
+
|
5218
|
+
scheduler.schedule(function () {
|
5219
|
+
var result;
|
5220
|
+
try {
|
5221
|
+
result = func.apply(context, args);
|
5222
|
+
} catch (e) {
|
5223
|
+
subject.onError(e);
|
5224
|
+
return;
|
5225
|
+
}
|
5226
|
+
subject.onNext(result);
|
5227
|
+
subject.onCompleted();
|
5228
|
+
});
|
5229
|
+
return subject.asObservable();
|
5230
|
+
};
|
5231
|
+
};
|
5232
|
+
|
5233
|
+
/**
|
5234
|
+
* Converts a callback function to an observable sequence.
|
5235
|
+
*
|
5236
|
+
* @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
|
5237
|
+
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
5238
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
5239
|
+
* @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.
|
5240
|
+
*/
|
5241
|
+
Observable.fromCallback = function (func, context, selector) {
|
5082
5242
|
return function () {
|
5083
5243
|
var args = slice.call(arguments, 0);
|
5084
5244
|
|
@@ -5495,6 +5655,7 @@ if (!Array.prototype.forEach) {
|
|
5495
5655
|
.subscribe(
|
5496
5656
|
function (results) {
|
5497
5657
|
if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
|
5658
|
+
previousShouldFire = results.shouldFire;
|
5498
5659
|
// change in shouldFire
|
5499
5660
|
if (results.shouldFire) {
|
5500
5661
|
while (q.length > 0) {
|
@@ -5502,6 +5663,7 @@ if (!Array.prototype.forEach) {
|
|
5502
5663
|
}
|
5503
5664
|
}
|
5504
5665
|
} else {
|
5666
|
+
previousShouldFire = results.shouldFire;
|
5505
5667
|
// new data
|
5506
5668
|
if (results.shouldFire) {
|
5507
5669
|
observer.onNext(results.data);
|
@@ -5509,9 +5671,7 @@ if (!Array.prototype.forEach) {
|
|
5509
5671
|
q.push(results.data);
|
5510
5672
|
}
|
5511
5673
|
}
|
5512
|
-
|
5513
|
-
|
5514
|
-
},
|
5674
|
+
},
|
5515
5675
|
function (err) {
|
5516
5676
|
// Empty buffer before sending error
|
5517
5677
|
while (q.length > 0) {
|
@@ -5750,121 +5910,114 @@ if (!Array.prototype.forEach) {
|
|
5750
5910
|
var source = this;
|
5751
5911
|
return typeof subjectOrSubjectSelector === 'function' ?
|
5752
5912
|
new AnonymousObservable(function (observer) {
|
5753
|
-
|
5754
|
-
|
5913
|
+
var connectable = source.multicast(subjectOrSubjectSelector());
|
5914
|
+
return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
|
5755
5915
|
}) :
|
5756
5916
|
new ConnectableObservable(source, subjectOrSubjectSelector);
|
5757
5917
|
};
|
5758
5918
|
|
5759
|
-
|
5760
|
-
|
5761
|
-
|
5762
|
-
|
5763
|
-
|
5764
|
-
|
5765
|
-
|
5766
|
-
|
5767
|
-
|
5768
|
-
|
5769
|
-
|
5770
|
-
|
5771
|
-
|
5772
|
-
|
5773
|
-
|
5774
|
-
|
5775
|
-
}, selector);
|
5776
|
-
};
|
5919
|
+
/**
|
5920
|
+
* 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.
|
5921
|
+
* This operator is a specialization of Multicast using a regular Subject.
|
5922
|
+
*
|
5923
|
+
* @example
|
5924
|
+
* var resres = source.publish();
|
5925
|
+
* var res = source.publish(function (x) { return x; });
|
5926
|
+
*
|
5927
|
+
* @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.
|
5928
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5929
|
+
*/
|
5930
|
+
observableProto.publish = function (selector) {
|
5931
|
+
return selector && isFunction(selector) ?
|
5932
|
+
this.multicast(function () { return new Subject(); }, selector) :
|
5933
|
+
this.multicast(new Subject());
|
5934
|
+
};
|
5777
5935
|
|
5778
|
-
|
5779
|
-
|
5780
|
-
|
5781
|
-
|
5782
|
-
|
5783
|
-
|
5784
|
-
|
5785
|
-
|
5786
|
-
|
5787
|
-
|
5788
|
-
|
5789
|
-
|
5936
|
+
/**
|
5937
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence.
|
5938
|
+
* 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.
|
5939
|
+
*
|
5940
|
+
* @example
|
5941
|
+
* var res = source.share();
|
5942
|
+
*
|
5943
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
5944
|
+
*/
|
5945
|
+
observableProto.share = function () {
|
5946
|
+
return this.publish().refCount();
|
5947
|
+
};
|
5790
5948
|
|
5791
|
-
|
5792
|
-
|
5793
|
-
|
5794
|
-
|
5795
|
-
|
5796
|
-
|
5797
|
-
|
5798
|
-
|
5799
|
-
|
5800
|
-
|
5801
|
-
|
5802
|
-
|
5803
|
-
|
5804
|
-
|
5805
|
-
|
5806
|
-
|
5807
|
-
}, selector);
|
5808
|
-
};
|
5949
|
+
/**
|
5950
|
+
* 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.
|
5951
|
+
* This operator is a specialization of Multicast using a AsyncSubject.
|
5952
|
+
*
|
5953
|
+
* @example
|
5954
|
+
* var res = source.publishLast();
|
5955
|
+
* var res = source.publishLast(function (x) { return x; });
|
5956
|
+
*
|
5957
|
+
* @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.
|
5958
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5959
|
+
*/
|
5960
|
+
observableProto.publishLast = function (selector) {
|
5961
|
+
return selector && isFunction(selector) ?
|
5962
|
+
this.multicast(function () { return new AsyncSubject(); }, selector) :
|
5963
|
+
this.multicast(new AsyncSubject());
|
5964
|
+
};
|
5809
5965
|
|
5810
|
-
|
5811
|
-
|
5812
|
-
|
5813
|
-
|
5814
|
-
|
5815
|
-
|
5816
|
-
|
5817
|
-
|
5818
|
-
|
5819
|
-
|
5820
|
-
|
5821
|
-
|
5822
|
-
|
5823
|
-
|
5824
|
-
|
5825
|
-
|
5826
|
-
|
5827
|
-
|
5828
|
-
|
5966
|
+
/**
|
5967
|
+
* 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.
|
5968
|
+
* This operator is a specialization of Multicast using a BehaviorSubject.
|
5969
|
+
*
|
5970
|
+
* @example
|
5971
|
+
* var res = source.publishValue(42);
|
5972
|
+
* var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
|
5973
|
+
*
|
5974
|
+
* @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.
|
5975
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
5976
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
5977
|
+
*/
|
5978
|
+
observableProto.publishValue = function (initialValueOrSelector, initialValue) {
|
5979
|
+
return arguments.length === 2 ?
|
5980
|
+
this.multicast(function () {
|
5981
|
+
return new BehaviorSubject(initialValue);
|
5982
|
+
}, initialValueOrSelector) :
|
5983
|
+
this.multicast(new BehaviorSubject(initialValueOrSelector));
|
5984
|
+
};
|
5829
5985
|
|
5830
|
-
|
5831
|
-
|
5832
|
-
|
5833
|
-
|
5834
|
-
|
5835
|
-
|
5836
|
-
|
5837
|
-
|
5838
|
-
|
5839
|
-
|
5840
|
-
|
5841
|
-
|
5842
|
-
|
5843
|
-
};
|
5986
|
+
/**
|
5987
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
|
5988
|
+
* 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.
|
5989
|
+
*
|
5990
|
+
* @example
|
5991
|
+
* var res = source.shareValue(42);
|
5992
|
+
*
|
5993
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
5994
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
5995
|
+
*/
|
5996
|
+
observableProto.shareValue = function (initialValue) {
|
5997
|
+
return this.publishValue(initialValue).refCount();
|
5998
|
+
};
|
5844
5999
|
|
5845
|
-
|
5846
|
-
|
5847
|
-
|
5848
|
-
|
5849
|
-
|
5850
|
-
|
5851
|
-
|
5852
|
-
|
5853
|
-
|
5854
|
-
|
5855
|
-
|
5856
|
-
|
5857
|
-
|
5858
|
-
|
5859
|
-
|
5860
|
-
|
5861
|
-
|
5862
|
-
|
5863
|
-
|
5864
|
-
|
5865
|
-
|
5866
|
-
}, selector);
|
5867
|
-
};
|
6000
|
+
/**
|
6001
|
+
* 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.
|
6002
|
+
* This operator is a specialization of Multicast using a ReplaySubject.
|
6003
|
+
*
|
6004
|
+
* @example
|
6005
|
+
* var res = source.replay(null, 3);
|
6006
|
+
* var res = source.replay(null, 3, 500);
|
6007
|
+
* var res = source.replay(null, 3, 500, scheduler);
|
6008
|
+
* var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
|
6009
|
+
*
|
6010
|
+
* @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.
|
6011
|
+
* @param bufferSize [Optional] Maximum element count of the replay buffer.
|
6012
|
+
* @param window [Optional] Maximum time length of the replay buffer.
|
6013
|
+
* @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
|
6014
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
6015
|
+
*/
|
6016
|
+
observableProto.replay = function (selector, bufferSize, window, scheduler) {
|
6017
|
+
return selector && isFunction(selector) ?
|
6018
|
+
this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
|
6019
|
+
this.multicast(new ReplaySubject(bufferSize, window, scheduler));
|
6020
|
+
};
|
5868
6021
|
|
5869
6022
|
/**
|
5870
6023
|
* 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.
|
@@ -5903,267 +6056,247 @@ if (!Array.prototype.forEach) {
|
|
5903
6056
|
}
|
5904
6057
|
};
|
5905
6058
|
|
5906
|
-
|
5907
|
-
|
5908
|
-
|
5909
|
-
|
5910
|
-
|
5911
|
-
|
5912
|
-
|
5913
|
-
|
5914
|
-
|
5915
|
-
|
5916
|
-
|
5917
|
-
|
5918
|
-
|
5919
|
-
|
5920
|
-
|
5921
|
-
|
5922
|
-
|
5923
|
-
|
5924
|
-
|
5925
|
-
|
6059
|
+
/**
|
6060
|
+
* Represents a value that changes over time.
|
6061
|
+
* Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
|
6062
|
+
*/
|
6063
|
+
var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
|
6064
|
+
function subscribe(observer) {
|
6065
|
+
checkDisposed.call(this);
|
6066
|
+
if (!this.isStopped) {
|
6067
|
+
this.observers.push(observer);
|
6068
|
+
observer.onNext(this.value);
|
6069
|
+
return new InnerSubscription(this, observer);
|
6070
|
+
}
|
6071
|
+
var ex = this.exception;
|
6072
|
+
if (ex) {
|
6073
|
+
observer.onError(ex);
|
6074
|
+
} else {
|
6075
|
+
observer.onCompleted();
|
6076
|
+
}
|
6077
|
+
return disposableEmpty;
|
6078
|
+
}
|
5926
6079
|
|
5927
|
-
|
6080
|
+
inherits(BehaviorSubject, __super__);
|
5928
6081
|
|
5929
|
-
|
5930
|
-
|
5931
|
-
|
5932
|
-
|
5933
|
-
|
5934
|
-
|
5935
|
-
|
6082
|
+
/**
|
6083
|
+
* @constructor
|
6084
|
+
* Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
|
6085
|
+
* @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
|
6086
|
+
*/
|
6087
|
+
function BehaviorSubject(value) {
|
6088
|
+
__super__.call(this, subscribe);
|
6089
|
+
this.value = value,
|
6090
|
+
this.observers = [],
|
6091
|
+
this.isDisposed = false,
|
6092
|
+
this.isStopped = false,
|
6093
|
+
this.exception = null;
|
6094
|
+
}
|
5936
6095
|
|
5937
|
-
|
5938
|
-
|
5939
|
-
|
5940
|
-
|
5941
|
-
|
6096
|
+
addProperties(BehaviorSubject.prototype, Observer, {
|
6097
|
+
/**
|
6098
|
+
* Indicates whether the subject has observers subscribed to it.
|
6099
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
6100
|
+
*/
|
6101
|
+
hasObservers: function () {
|
6102
|
+
return this.observers.length > 0;
|
6103
|
+
},
|
6104
|
+
/**
|
6105
|
+
* Notifies all subscribed observers about the end of the sequence.
|
6106
|
+
*/
|
6107
|
+
onCompleted: function () {
|
6108
|
+
checkDisposed.call(this);
|
6109
|
+
if (this.isStopped) { return; }
|
6110
|
+
this.isStopped = true;
|
6111
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
6112
|
+
os[i].onCompleted();
|
5942
6113
|
}
|
5943
6114
|
|
5944
|
-
|
5945
|
-
|
5946
|
-
|
5947
|
-
|
5948
|
-
|
5949
|
-
|
5950
|
-
|
5951
|
-
|
5952
|
-
|
5953
|
-
|
5954
|
-
|
5955
|
-
onCompleted: function () {
|
5956
|
-
checkDisposed.call(this);
|
5957
|
-
if (!this.isStopped) {
|
5958
|
-
var os = this.observers.slice(0);
|
5959
|
-
this.isStopped = true;
|
5960
|
-
for (var i = 0, len = os.length; i < len; i++) {
|
5961
|
-
os[i].onCompleted();
|
5962
|
-
}
|
6115
|
+
this.observers = [];
|
6116
|
+
},
|
6117
|
+
/**
|
6118
|
+
* Notifies all subscribed observers about the exception.
|
6119
|
+
* @param {Mixed} error The exception to send to all observers.
|
6120
|
+
*/
|
6121
|
+
onError: function (error) {
|
6122
|
+
checkDisposed.call(this);
|
6123
|
+
if (this.isStopped) { return; }
|
6124
|
+
this.isStopped = true;
|
6125
|
+
this.exception = error;
|
5963
6126
|
|
5964
|
-
|
5965
|
-
|
5966
|
-
|
5967
|
-
/**
|
5968
|
-
* Notifies all subscribed observers about the exception.
|
5969
|
-
* @param {Mixed} error The exception to send to all observers.
|
5970
|
-
*/
|
5971
|
-
onError: function (error) {
|
5972
|
-
checkDisposed.call(this);
|
5973
|
-
if (!this.isStopped) {
|
5974
|
-
var os = this.observers.slice(0);
|
5975
|
-
this.isStopped = true;
|
5976
|
-
this.exception = error;
|
6127
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
6128
|
+
os[i].onError(error);
|
6129
|
+
}
|
5977
6130
|
|
5978
|
-
|
5979
|
-
|
5980
|
-
|
6131
|
+
this.observers = [];
|
6132
|
+
},
|
6133
|
+
/**
|
6134
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
6135
|
+
* @param {Mixed} value The value to send to all observers.
|
6136
|
+
*/
|
6137
|
+
onNext: function (value) {
|
6138
|
+
checkDisposed.call(this);
|
6139
|
+
if (this.isStopped) { return; }
|
6140
|
+
this.value = value;
|
6141
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
6142
|
+
os[i].onNext(value);
|
6143
|
+
}
|
6144
|
+
},
|
6145
|
+
/**
|
6146
|
+
* Unsubscribe all observers and release resources.
|
6147
|
+
*/
|
6148
|
+
dispose: function () {
|
6149
|
+
this.isDisposed = true;
|
6150
|
+
this.observers = null;
|
6151
|
+
this.value = null;
|
6152
|
+
this.exception = null;
|
6153
|
+
}
|
6154
|
+
});
|
5981
6155
|
|
5982
|
-
|
5983
|
-
|
5984
|
-
},
|
5985
|
-
/**
|
5986
|
-
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5987
|
-
* @param {Mixed} value The value to send to all observers.
|
5988
|
-
*/
|
5989
|
-
onNext: function (value) {
|
5990
|
-
checkDisposed.call(this);
|
5991
|
-
if (!this.isStopped) {
|
5992
|
-
this.value = value;
|
5993
|
-
var os = this.observers.slice(0);
|
5994
|
-
for (var i = 0, len = os.length; i < len; i++) {
|
5995
|
-
os[i].onNext(value);
|
5996
|
-
}
|
5997
|
-
}
|
5998
|
-
},
|
5999
|
-
/**
|
6000
|
-
* Unsubscribe all observers and release resources.
|
6001
|
-
*/
|
6002
|
-
dispose: function () {
|
6003
|
-
this.isDisposed = true;
|
6004
|
-
this.observers = null;
|
6005
|
-
this.value = null;
|
6006
|
-
this.exception = null;
|
6007
|
-
}
|
6008
|
-
});
|
6156
|
+
return BehaviorSubject;
|
6157
|
+
}(Observable));
|
6009
6158
|
|
6010
|
-
|
6011
|
-
|
6159
|
+
/**
|
6160
|
+
* Represents an object that is both an observable sequence as well as an observer.
|
6161
|
+
* Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
|
6162
|
+
*/
|
6163
|
+
var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
|
6012
6164
|
|
6013
|
-
|
6014
|
-
|
6015
|
-
|
6016
|
-
|
6017
|
-
|
6165
|
+
function createRemovableDisposable(subject, observer) {
|
6166
|
+
return disposableCreate(function () {
|
6167
|
+
observer.dispose();
|
6168
|
+
!subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
|
6169
|
+
});
|
6170
|
+
}
|
6018
6171
|
|
6019
|
-
|
6020
|
-
|
6021
|
-
|
6022
|
-
|
6172
|
+
function subscribe(observer) {
|
6173
|
+
var so = new ScheduledObserver(this.scheduler, observer),
|
6174
|
+
subscription = createRemovableDisposable(this, so);
|
6175
|
+
checkDisposed.call(this);
|
6176
|
+
this._trim(this.scheduler.now());
|
6177
|
+
this.observers.push(so);
|
6023
6178
|
|
6024
|
-
|
6025
|
-
this.observer.dispose();
|
6026
|
-
if (!this.subject.isDisposed) {
|
6027
|
-
var idx = this.subject.observers.indexOf(this.observer);
|
6028
|
-
this.subject.observers.splice(idx, 1);
|
6029
|
-
}
|
6030
|
-
};
|
6179
|
+
var n = this.q.length;
|
6031
6180
|
|
6032
|
-
|
6033
|
-
|
6034
|
-
|
6035
|
-
checkDisposed.call(this);
|
6036
|
-
this._trim(this.scheduler.now());
|
6037
|
-
this.observers.push(so);
|
6181
|
+
for (var i = 0, len = this.q.length; i < len; i++) {
|
6182
|
+
so.onNext(this.q[i].value);
|
6183
|
+
}
|
6038
6184
|
|
6039
|
-
|
6185
|
+
if (this.hasError) {
|
6186
|
+
n++;
|
6187
|
+
so.onError(this.error);
|
6188
|
+
} else if (this.isStopped) {
|
6189
|
+
n++;
|
6190
|
+
so.onCompleted();
|
6191
|
+
}
|
6040
6192
|
|
6041
|
-
|
6042
|
-
|
6043
|
-
|
6193
|
+
so.ensureActive(n);
|
6194
|
+
return subscription;
|
6195
|
+
}
|
6044
6196
|
|
6045
|
-
|
6046
|
-
n++;
|
6047
|
-
so.onError(this.error);
|
6048
|
-
} else if (this.isStopped) {
|
6049
|
-
n++;
|
6050
|
-
so.onCompleted();
|
6051
|
-
}
|
6197
|
+
inherits(ReplaySubject, __super__);
|
6052
6198
|
|
6053
|
-
|
6054
|
-
|
6055
|
-
|
6199
|
+
/**
|
6200
|
+
* Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
|
6201
|
+
* @param {Number} [bufferSize] Maximum element count of the replay buffer.
|
6202
|
+
* @param {Number} [windowSize] Maximum time length of the replay buffer.
|
6203
|
+
* @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
|
6204
|
+
*/
|
6205
|
+
function ReplaySubject(bufferSize, windowSize, scheduler) {
|
6206
|
+
this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
|
6207
|
+
this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
|
6208
|
+
this.scheduler = scheduler || currentThreadScheduler;
|
6209
|
+
this.q = [];
|
6210
|
+
this.observers = [];
|
6211
|
+
this.isStopped = false;
|
6212
|
+
this.isDisposed = false;
|
6213
|
+
this.hasError = false;
|
6214
|
+
this.error = null;
|
6215
|
+
__super__.call(this, subscribe);
|
6216
|
+
}
|
6056
6217
|
|
6057
|
-
|
6218
|
+
addProperties(ReplaySubject.prototype, Observer, {
|
6219
|
+
/**
|
6220
|
+
* Indicates whether the subject has observers subscribed to it.
|
6221
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
6222
|
+
*/
|
6223
|
+
hasObservers: function () {
|
6224
|
+
return this.observers.length > 0;
|
6225
|
+
},
|
6226
|
+
_trim: function (now) {
|
6227
|
+
while (this.q.length > this.bufferSize) {
|
6228
|
+
this.q.shift();
|
6229
|
+
}
|
6230
|
+
while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
6231
|
+
this.q.shift();
|
6232
|
+
}
|
6233
|
+
},
|
6234
|
+
/**
|
6235
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
6236
|
+
* @param {Mixed} value The value to send to all observers.
|
6237
|
+
*/
|
6238
|
+
onNext: function (value) {
|
6239
|
+
checkDisposed.call(this);
|
6240
|
+
if (this.isStopped) { return; }
|
6241
|
+
var now = this.scheduler.now();
|
6242
|
+
this.q.push({ interval: now, value: value });
|
6243
|
+
this._trim(now);
|
6058
6244
|
|
6059
|
-
|
6060
|
-
|
6061
|
-
|
6062
|
-
|
6063
|
-
|
6064
|
-
|
6065
|
-
|
6066
|
-
|
6067
|
-
|
6068
|
-
|
6069
|
-
|
6070
|
-
|
6071
|
-
|
6072
|
-
|
6073
|
-
|
6074
|
-
|
6075
|
-
|
6245
|
+
var o = this.observers.slice(0);
|
6246
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6247
|
+
var observer = o[i];
|
6248
|
+
observer.onNext(value);
|
6249
|
+
observer.ensureActive();
|
6250
|
+
}
|
6251
|
+
},
|
6252
|
+
/**
|
6253
|
+
* Notifies all subscribed observers about the exception.
|
6254
|
+
* @param {Mixed} error The exception to send to all observers.
|
6255
|
+
*/
|
6256
|
+
onError: function (error) {
|
6257
|
+
checkDisposed.call(this);
|
6258
|
+
if (this.isStopped) { return; }
|
6259
|
+
this.isStopped = true;
|
6260
|
+
this.error = error;
|
6261
|
+
this.hasError = true;
|
6262
|
+
var now = this.scheduler.now();
|
6263
|
+
this._trim(now);
|
6264
|
+
var o = this.observers.slice(0);
|
6265
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6266
|
+
var observer = o[i];
|
6267
|
+
observer.onError(error);
|
6268
|
+
observer.ensureActive();
|
6269
|
+
}
|
6270
|
+
this.observers = [];
|
6271
|
+
},
|
6272
|
+
/**
|
6273
|
+
* Notifies all subscribed observers about the end of the sequence.
|
6274
|
+
*/
|
6275
|
+
onCompleted: function () {
|
6276
|
+
checkDisposed.call(this);
|
6277
|
+
if (this.isStopped) { return; }
|
6278
|
+
this.isStopped = true;
|
6279
|
+
var now = this.scheduler.now();
|
6280
|
+
this._trim(now);
|
6281
|
+
var o = this.observers.slice(0);
|
6282
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
6283
|
+
var observer = o[i];
|
6284
|
+
observer.onCompleted();
|
6285
|
+
observer.ensureActive();
|
6076
6286
|
}
|
6287
|
+
this.observers = [];
|
6288
|
+
},
|
6289
|
+
/**
|
6290
|
+
* Unsubscribe all observers and release resources.
|
6291
|
+
*/
|
6292
|
+
dispose: function () {
|
6293
|
+
this.isDisposed = true;
|
6294
|
+
this.observers = null;
|
6295
|
+
}
|
6296
|
+
});
|
6077
6297
|
|
6078
|
-
|
6079
|
-
|
6080
|
-
* Indicates whether the subject has observers subscribed to it.
|
6081
|
-
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
6082
|
-
*/
|
6083
|
-
hasObservers: function () {
|
6084
|
-
return this.observers.length > 0;
|
6085
|
-
},
|
6086
|
-
/* @private */
|
6087
|
-
_trim: function (now) {
|
6088
|
-
while (this.q.length > this.bufferSize) {
|
6089
|
-
this.q.shift();
|
6090
|
-
}
|
6091
|
-
while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
6092
|
-
this.q.shift();
|
6093
|
-
}
|
6094
|
-
},
|
6095
|
-
/**
|
6096
|
-
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
6097
|
-
* @param {Mixed} value The value to send to all observers.
|
6098
|
-
*/
|
6099
|
-
onNext: function (value) {
|
6100
|
-
var observer;
|
6101
|
-
checkDisposed.call(this);
|
6102
|
-
if (!this.isStopped) {
|
6103
|
-
var now = this.scheduler.now();
|
6104
|
-
this.q.push({ interval: now, value: value });
|
6105
|
-
this._trim(now);
|
6106
|
-
|
6107
|
-
var o = this.observers.slice(0);
|
6108
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
6109
|
-
observer = o[i];
|
6110
|
-
observer.onNext(value);
|
6111
|
-
observer.ensureActive();
|
6112
|
-
}
|
6113
|
-
}
|
6114
|
-
},
|
6115
|
-
/**
|
6116
|
-
* Notifies all subscribed observers about the exception.
|
6117
|
-
* @param {Mixed} error The exception to send to all observers.
|
6118
|
-
*/
|
6119
|
-
onError: function (error) {
|
6120
|
-
var observer;
|
6121
|
-
checkDisposed.call(this);
|
6122
|
-
if (!this.isStopped) {
|
6123
|
-
this.isStopped = true;
|
6124
|
-
this.error = error;
|
6125
|
-
this.hasError = true;
|
6126
|
-
var now = this.scheduler.now();
|
6127
|
-
this._trim(now);
|
6128
|
-
var o = this.observers.slice(0);
|
6129
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
6130
|
-
observer = o[i];
|
6131
|
-
observer.onError(error);
|
6132
|
-
observer.ensureActive();
|
6133
|
-
}
|
6134
|
-
this.observers = [];
|
6135
|
-
}
|
6136
|
-
},
|
6137
|
-
/**
|
6138
|
-
* Notifies all subscribed observers about the end of the sequence.
|
6139
|
-
*/
|
6140
|
-
onCompleted: function () {
|
6141
|
-
var observer;
|
6142
|
-
checkDisposed.call(this);
|
6143
|
-
if (!this.isStopped) {
|
6144
|
-
this.isStopped = true;
|
6145
|
-
var now = this.scheduler.now();
|
6146
|
-
this._trim(now);
|
6147
|
-
var o = this.observers.slice(0);
|
6148
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
6149
|
-
observer = o[i];
|
6150
|
-
observer.onCompleted();
|
6151
|
-
observer.ensureActive();
|
6152
|
-
}
|
6153
|
-
this.observers = [];
|
6154
|
-
}
|
6155
|
-
},
|
6156
|
-
/**
|
6157
|
-
* Unsubscribe all observers and release resources.
|
6158
|
-
*/
|
6159
|
-
dispose: function () {
|
6160
|
-
this.isDisposed = true;
|
6161
|
-
this.observers = null;
|
6162
|
-
}
|
6163
|
-
});
|
6164
|
-
|
6165
|
-
return ReplaySubject;
|
6166
|
-
}(Observable));
|
6298
|
+
return ReplaySubject;
|
6299
|
+
}(Observable));
|
6167
6300
|
|
6168
6301
|
var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
|
6169
6302
|
inherits(ConnectableObservable, __super__);
|
@@ -7626,18 +7759,6 @@ if (!Array.prototype.forEach) {
|
|
7626
7759
|
|
7627
7760
|
/**
|
7628
7761
|
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
7629
|
-
*
|
7630
|
-
* @example
|
7631
|
-
* 1 - res = Rx.Observable.timer(new Date());
|
7632
|
-
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
7633
|
-
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
7634
|
-
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
7635
|
-
*
|
7636
|
-
* 5 - res = Rx.Observable.timer(5000);
|
7637
|
-
* 6 - res = Rx.Observable.timer(5000, 1000);
|
7638
|
-
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
7639
|
-
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
7640
|
-
*
|
7641
7762
|
* @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.
|
7642
7763
|
* @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.
|
7643
7764
|
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
@@ -7648,7 +7769,7 @@ if (!Array.prototype.forEach) {
|
|
7648
7769
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7649
7770
|
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
7650
7771
|
period = periodOrScheduler;
|
7651
|
-
} else if (periodOrScheduler
|
7772
|
+
} else if (isScheduler(periodOrScheduler)) {
|
7652
7773
|
scheduler = periodOrScheduler;
|
7653
7774
|
}
|
7654
7775
|
if (dueTime instanceof Date && period === undefined) {
|
@@ -7767,7 +7888,37 @@ if (!Array.prototype.forEach) {
|
|
7767
7888
|
*/
|
7768
7889
|
observableProto.throttle = function (dueTime, scheduler) {
|
7769
7890
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7770
|
-
|
7891
|
+
var source = this;
|
7892
|
+
return new AnonymousObservable(function (observer) {
|
7893
|
+
var cancelable = new SerialDisposable(), hasvalue = false, value, id = 0;
|
7894
|
+
var subscription = source.subscribe(
|
7895
|
+
function (x) {
|
7896
|
+
hasvalue = true;
|
7897
|
+
value = x;
|
7898
|
+
id++;
|
7899
|
+
var currentId = id,
|
7900
|
+
d = new SingleAssignmentDisposable();
|
7901
|
+
cancelable.setDisposable(d);
|
7902
|
+
d.setDisposable(scheduler.scheduleWithRelative(dueTime, function () {
|
7903
|
+
hasValue && id === currentId && observer.onNext(value);
|
7904
|
+
hasvalue = false;
|
7905
|
+
}));
|
7906
|
+
},
|
7907
|
+
function (e) {
|
7908
|
+
cancelable.dispose();
|
7909
|
+
observer.onError(e);
|
7910
|
+
hasvalue = false;
|
7911
|
+
id++;
|
7912
|
+
},
|
7913
|
+
function () {
|
7914
|
+
cancelable.dispose();
|
7915
|
+
hasvalue && observer.onNext(value);
|
7916
|
+
observer.onCompleted();
|
7917
|
+
hasvalue = false;
|
7918
|
+
id++;
|
7919
|
+
});
|
7920
|
+
return new CompositeDisposable(subscription, cancelable);
|
7921
|
+
});
|
7771
7922
|
};
|
7772
7923
|
|
7773
7924
|
/**
|
@@ -7784,70 +7935,49 @@ if (!Array.prototype.forEach) {
|
|
7784
7935
|
*/
|
7785
7936
|
observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
7786
7937
|
var source = this, timeShift;
|
7787
|
-
|
7788
|
-
|
7938
|
+
if (timeShiftOrScheduler === undefined) {
|
7939
|
+
timeShift = timeSpan;
|
7940
|
+
}
|
7789
7941
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7790
7942
|
if (typeof timeShiftOrScheduler === 'number') {
|
7791
7943
|
timeShift = timeShiftOrScheduler;
|
7792
|
-
} else if (
|
7944
|
+
} else if (isScheduler(timeShiftOrScheduler)) {
|
7793
7945
|
timeShift = timeSpan;
|
7794
7946
|
scheduler = timeShiftOrScheduler;
|
7795
7947
|
}
|
7796
7948
|
return new AnonymousObservable(function (observer) {
|
7797
7949
|
var groupDisposable,
|
7798
|
-
|
7799
|
-
|
7800
|
-
|
7801
|
-
|
7802
|
-
|
7803
|
-
|
7804
|
-
|
7805
|
-
|
7806
|
-
|
7807
|
-
|
7808
|
-
q.push(new Subject());
|
7809
|
-
observer.onNext(addRef(q[0], refCountDisposable));
|
7810
|
-
createTimer();
|
7811
|
-
groupDisposable.add(source.subscribe(function (x) {
|
7812
|
-
var i, len;
|
7813
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7814
|
-
q[i].onNext(x);
|
7815
|
-
}
|
7816
|
-
}, function (e) {
|
7817
|
-
var i, len;
|
7818
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7819
|
-
q[i].onError(e);
|
7820
|
-
}
|
7821
|
-
observer.onError(e);
|
7822
|
-
}, function () {
|
7823
|
-
var i, len;
|
7824
|
-
for (i = 0, len = q.length; i < len; i++) {
|
7825
|
-
q[i].onCompleted();
|
7826
|
-
}
|
7827
|
-
observer.onCompleted();
|
7828
|
-
}));
|
7829
|
-
|
7830
|
-
return refCountDisposable;
|
7950
|
+
nextShift = timeShift,
|
7951
|
+
nextSpan = timeSpan,
|
7952
|
+
q = [],
|
7953
|
+
refCountDisposable,
|
7954
|
+
timerD = new SerialDisposable(),
|
7955
|
+
totalTime = 0;
|
7956
|
+
groupDisposable = new CompositeDisposable(timerD),
|
7957
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7831
7958
|
|
7832
|
-
|
7833
|
-
var m = new SingleAssignmentDisposable(),
|
7959
|
+
function createTimer () {
|
7960
|
+
var m = new SingleAssignmentDisposable(),
|
7961
|
+
isSpan = false,
|
7962
|
+
isShift = false;
|
7834
7963
|
timerD.setDisposable(m);
|
7835
|
-
|
7836
7964
|
if (nextSpan === nextShift) {
|
7837
7965
|
isSpan = true;
|
7838
7966
|
isShift = true;
|
7839
7967
|
} else if (nextSpan < nextShift) {
|
7840
|
-
|
7968
|
+
isSpan = true;
|
7841
7969
|
} else {
|
7842
7970
|
isShift = true;
|
7843
7971
|
}
|
7844
|
-
|
7845
7972
|
var newTotalTime = isSpan ? nextSpan : nextShift,
|
7846
|
-
|
7973
|
+
ts = newTotalTime - totalTime;
|
7847
7974
|
totalTime = newTotalTime;
|
7848
|
-
|
7849
|
-
|
7850
|
-
|
7975
|
+
if (isSpan) {
|
7976
|
+
nextSpan += timeShift;
|
7977
|
+
}
|
7978
|
+
if (isShift) {
|
7979
|
+
nextShift += timeShift;
|
7980
|
+
}
|
7851
7981
|
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
7852
7982
|
var s;
|
7853
7983
|
if (isShift) {
|
@@ -7861,17 +7991,30 @@ if (!Array.prototype.forEach) {
|
|
7861
7991
|
}
|
7862
7992
|
createTimer();
|
7863
7993
|
}));
|
7864
|
-
}
|
7994
|
+
};
|
7995
|
+
q.push(new Subject());
|
7996
|
+
observer.onNext(addRef(q[0], refCountDisposable));
|
7997
|
+
createTimer();
|
7998
|
+
groupDisposable.add(source.subscribe(function (x) {
|
7999
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
8000
|
+
q[i].onNext(x);
|
8001
|
+
}
|
8002
|
+
}, function (e) {
|
8003
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
8004
|
+
q[i].onError(e);
|
8005
|
+
}
|
8006
|
+
observer.onError(e);
|
8007
|
+
}, function () {
|
8008
|
+
for (var i = 0, len = q.length; i < len; i++) {
|
8009
|
+
q[i].onCompleted();
|
8010
|
+
}
|
8011
|
+
observer.onCompleted();
|
8012
|
+
}));
|
8013
|
+
return refCountDisposable;
|
7865
8014
|
});
|
7866
8015
|
};
|
7867
|
-
|
7868
8016
|
/**
|
7869
8017
|
* 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.
|
7870
|
-
* @example
|
7871
|
-
* 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
|
7872
|
-
* 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
|
7873
|
-
*
|
7874
|
-
* @memberOf Observable#
|
7875
8018
|
* @param {Number} timeSpan Maximum time length of a window.
|
7876
8019
|
* @param {Number} count Maximum element count of a window.
|
7877
8020
|
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
@@ -7882,15 +8025,31 @@ if (!Array.prototype.forEach) {
|
|
7882
8025
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
7883
8026
|
return new AnonymousObservable(function (observer) {
|
7884
8027
|
var createTimer,
|
7885
|
-
|
7886
|
-
|
7887
|
-
|
7888
|
-
|
7889
|
-
|
7890
|
-
|
8028
|
+
groupDisposable,
|
8029
|
+
n = 0,
|
8030
|
+
refCountDisposable,
|
8031
|
+
s,
|
8032
|
+
timerD = new SerialDisposable(),
|
8033
|
+
windowId = 0;
|
7891
8034
|
groupDisposable = new CompositeDisposable(timerD);
|
7892
8035
|
refCountDisposable = new RefCountDisposable(groupDisposable);
|
7893
|
-
|
8036
|
+
createTimer = function (id) {
|
8037
|
+
var m = new SingleAssignmentDisposable();
|
8038
|
+
timerD.setDisposable(m);
|
8039
|
+
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
8040
|
+
var newId;
|
8041
|
+
if (id !== windowId) {
|
8042
|
+
return;
|
8043
|
+
}
|
8044
|
+
n = 0;
|
8045
|
+
newId = ++windowId;
|
8046
|
+
s.onCompleted();
|
8047
|
+
s = new Subject();
|
8048
|
+
observer.onNext(addRef(s, refCountDisposable));
|
8049
|
+
createTimer(newId);
|
8050
|
+
}));
|
8051
|
+
};
|
8052
|
+
s = new Subject();
|
7894
8053
|
observer.onNext(addRef(s, refCountDisposable));
|
7895
8054
|
createTimer(0);
|
7896
8055
|
groupDisposable.add(source.subscribe(function (x) {
|
@@ -7905,34 +8064,19 @@ if (!Array.prototype.forEach) {
|
|
7905
8064
|
s = new Subject();
|
7906
8065
|
observer.onNext(addRef(s, refCountDisposable));
|
7907
8066
|
}
|
7908
|
-
|
8067
|
+
if (newWindow) {
|
8068
|
+
createTimer(newId);
|
8069
|
+
}
|
7909
8070
|
}, function (e) {
|
7910
8071
|
s.onError(e);
|
7911
8072
|
observer.onError(e);
|
7912
8073
|
}, function () {
|
7913
8074
|
s.onCompleted();
|
7914
8075
|
observer.onCompleted();
|
7915
|
-
}));
|
7916
|
-
|
7917
|
-
return refCountDisposable;
|
7918
|
-
|
7919
|
-
function createTimer(id) {
|
7920
|
-
var m = new SingleAssignmentDisposable();
|
7921
|
-
timerD.setDisposable(m);
|
7922
|
-
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
7923
|
-
var newId;
|
7924
|
-
if (id !== windowId) { return; }
|
7925
|
-
n = 0;
|
7926
|
-
newId = ++windowId;
|
7927
|
-
s.onCompleted();
|
7928
|
-
s = new Subject();
|
7929
|
-
observer.onNext(addRef(s, refCountDisposable));
|
7930
|
-
createTimer(newId);
|
7931
|
-
}));
|
7932
|
-
}
|
8076
|
+
}));
|
8077
|
+
return refCountDisposable;
|
7933
8078
|
});
|
7934
8079
|
};
|
7935
|
-
|
7936
8080
|
/**
|
7937
8081
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
|
7938
8082
|
*
|
@@ -8052,16 +8196,7 @@ if (!Array.prototype.forEach) {
|
|
8052
8196
|
};
|
8053
8197
|
|
8054
8198
|
/**
|
8055
|
-
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
8056
|
-
*
|
8057
|
-
* @example
|
8058
|
-
* 1 - res = source.timeout(new Date()); // As a date
|
8059
|
-
* 2 - res = source.timeout(5000); // 5 seconds
|
8060
|
-
* 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
|
8061
|
-
* 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
|
8062
|
-
* 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
|
8063
|
-
* 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
|
8064
|
-
*
|
8199
|
+
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
8065
8200
|
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
|
8066
8201
|
* @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
|
8067
8202
|
* @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
|
@@ -8084,7 +8219,7 @@ if (!Array.prototype.forEach) {
|
|
8084
8219
|
|
8085
8220
|
subscription.setDisposable(original);
|
8086
8221
|
|
8087
|
-
|
8222
|
+
function createTimer() {
|
8088
8223
|
var myId = id;
|
8089
8224
|
timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
|
8090
8225
|
if (id === myId) {
|
@@ -8092,7 +8227,7 @@ if (!Array.prototype.forEach) {
|
|
8092
8227
|
subscription.setDisposable(other.subscribe(observer));
|
8093
8228
|
}
|
8094
8229
|
}));
|
8095
|
-
}
|
8230
|
+
}
|
8096
8231
|
|
8097
8232
|
createTimer();
|
8098
8233
|
|
@@ -8305,83 +8440,71 @@ if (!Array.prototype.forEach) {
|
|
8305
8440
|
|
8306
8441
|
/**
|
8307
8442
|
* Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
|
8308
|
-
*
|
8309
|
-
* @example
|
8310
|
-
* 1 - res = source.timeoutWithSelector(Rx.Observable.timer(500));
|
8311
|
-
* 2 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); });
|
8312
|
-
* 3 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); }, Rx.Observable.returnValue(42));
|
8313
|
-
*
|
8314
8443
|
* @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
|
8315
8444
|
* @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
|
8316
8445
|
* @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
|
8317
8446
|
* @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
|
8318
8447
|
*/
|
8319
8448
|
observableProto.timeoutWithSelector = function (firstTimeout, timeoutdurationSelector, other) {
|
8320
|
-
|
8321
|
-
|
8322
|
-
|
8323
|
-
|
8324
|
-
|
8325
|
-
|
8326
|
-
|
8327
|
-
|
8449
|
+
if (arguments.length === 1) {
|
8450
|
+
timeoutdurationSelector = firstTimeout;
|
8451
|
+
firstTimeout = observableNever();
|
8452
|
+
}
|
8453
|
+
other || (other = observableThrow(new Error('Timeout')));
|
8454
|
+
var source = this;
|
8455
|
+
return new AnonymousObservable(function (observer) {
|
8456
|
+
var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
|
8328
8457
|
|
8329
|
-
|
8458
|
+
subscription.setDisposable(original);
|
8330
8459
|
|
8331
|
-
|
8332
|
-
var myId = id, timerWins = function () {
|
8333
|
-
return id === myId;
|
8334
|
-
};
|
8335
|
-
var d = new SingleAssignmentDisposable();
|
8336
|
-
timer.setDisposable(d);
|
8337
|
-
d.setDisposable(timeout.subscribe(function () {
|
8338
|
-
if (timerWins()) {
|
8339
|
-
subscription.setDisposable(other.subscribe(observer));
|
8340
|
-
}
|
8341
|
-
d.dispose();
|
8342
|
-
}, function (e) {
|
8343
|
-
if (timerWins()) {
|
8344
|
-
observer.onError(e);
|
8345
|
-
}
|
8346
|
-
}, function () {
|
8347
|
-
if (timerWins()) {
|
8348
|
-
subscription.setDisposable(other.subscribe(observer));
|
8349
|
-
}
|
8350
|
-
}));
|
8351
|
-
};
|
8460
|
+
var id = 0, switched = false;
|
8352
8461
|
|
8353
|
-
|
8354
|
-
|
8355
|
-
var res = !switched;
|
8356
|
-
if (res) {
|
8357
|
-
id++;
|
8358
|
-
}
|
8359
|
-
return res;
|
8360
|
-
};
|
8462
|
+
function setTimer(timeout) {
|
8463
|
+
var myId = id;
|
8361
8464
|
|
8362
|
-
|
8363
|
-
|
8364
|
-
|
8365
|
-
|
8366
|
-
|
8367
|
-
|
8368
|
-
|
8369
|
-
|
8370
|
-
|
8371
|
-
|
8372
|
-
|
8373
|
-
|
8374
|
-
|
8375
|
-
|
8376
|
-
|
8377
|
-
|
8378
|
-
|
8379
|
-
|
8380
|
-
|
8381
|
-
|
8382
|
-
|
8383
|
-
|
8384
|
-
}
|
8465
|
+
function timerWins () {
|
8466
|
+
return id === myId;
|
8467
|
+
}
|
8468
|
+
|
8469
|
+
var d = new SingleAssignmentDisposable();
|
8470
|
+
timer.setDisposable(d);
|
8471
|
+
d.setDisposable(timeout.subscribe(function () {
|
8472
|
+
timerWins() && subscription.setDisposable(other.subscribe(observer));
|
8473
|
+
d.dispose();
|
8474
|
+
}, function (e) {
|
8475
|
+
timerWins() && observer.onError(e);
|
8476
|
+
}, function () {
|
8477
|
+
timerWins() && subscription.setDisposable(other.subscribe(observer));
|
8478
|
+
}));
|
8479
|
+
};
|
8480
|
+
|
8481
|
+
setTimer(firstTimeout);
|
8482
|
+
|
8483
|
+
function observerWins() {
|
8484
|
+
var res = !switched;
|
8485
|
+
if (res) { id++; }
|
8486
|
+
return res;
|
8487
|
+
}
|
8488
|
+
|
8489
|
+
original.setDisposable(source.subscribe(function (x) {
|
8490
|
+
if (observerWins()) {
|
8491
|
+
observer.onNext(x);
|
8492
|
+
var timeout;
|
8493
|
+
try {
|
8494
|
+
timeout = timeoutdurationSelector(x);
|
8495
|
+
} catch (e) {
|
8496
|
+
observer.onError(e);
|
8497
|
+
return;
|
8498
|
+
}
|
8499
|
+
setTimer(isPromise(timeout) ? observableFromPromise(timeout) : timeout);
|
8500
|
+
}
|
8501
|
+
}, function (e) {
|
8502
|
+
observerWins() && observer.onError(e);
|
8503
|
+
}, function () {
|
8504
|
+
observerWins() && observer.onCompleted();
|
8505
|
+
}));
|
8506
|
+
return new CompositeDisposable(subscription, timer);
|
8507
|
+
});
|
8385
8508
|
};
|
8386
8509
|
|
8387
8510
|
/**
|
@@ -8396,7 +8519,8 @@ if (!Array.prototype.forEach) {
|
|
8396
8519
|
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
8397
8520
|
var source = this;
|
8398
8521
|
return new AnonymousObservable(function (observer) {
|
8399
|
-
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0
|
8522
|
+
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
|
8523
|
+
var subscription = source.subscribe(function (x) {
|
8400
8524
|
var throttle;
|
8401
8525
|
try {
|
8402
8526
|
throttle = throttleDurationSelector(x);
|
@@ -8404,21 +8528,20 @@ if (!Array.prototype.forEach) {
|
|
8404
8528
|
observer.onError(e);
|
8405
8529
|
return;
|
8406
8530
|
}
|
8531
|
+
|
8532
|
+
isPromise(throttle) && (throttle = observableFromPromise(throttle));
|
8533
|
+
|
8407
8534
|
hasValue = true;
|
8408
8535
|
value = x;
|
8409
8536
|
id++;
|
8410
8537
|
var currentid = id, d = new SingleAssignmentDisposable();
|
8411
8538
|
cancelable.setDisposable(d);
|
8412
8539
|
d.setDisposable(throttle.subscribe(function () {
|
8413
|
-
|
8414
|
-
observer.onNext(value);
|
8415
|
-
}
|
8540
|
+
hasValue && id === currentid && observer.onNext(value);
|
8416
8541
|
hasValue = false;
|
8417
8542
|
d.dispose();
|
8418
8543
|
}, observer.onError.bind(observer), function () {
|
8419
|
-
|
8420
|
-
observer.onNext(value);
|
8421
|
-
}
|
8544
|
+
hasValue && id === currentid && observer.onNext(value);
|
8422
8545
|
hasValue = false;
|
8423
8546
|
d.dispose();
|
8424
8547
|
}));
|
@@ -8429,9 +8552,7 @@ if (!Array.prototype.forEach) {
|
|
8429
8552
|
id++;
|
8430
8553
|
}, function () {
|
8431
8554
|
cancelable.dispose();
|
8432
|
-
|
8433
|
-
observer.onNext(value);
|
8434
|
-
}
|
8555
|
+
hasValue && observer.onNext(value);
|
8435
8556
|
observer.onCompleted();
|
8436
8557
|
hasValue = false;
|
8437
8558
|
id++;
|
@@ -8477,9 +8598,6 @@ if (!Array.prototype.forEach) {
|
|
8477
8598
|
|
8478
8599
|
/**
|
8479
8600
|
* 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.
|
8480
|
-
*
|
8481
|
-
* @example
|
8482
|
-
* 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
|
8483
8601
|
* @description
|
8484
8602
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8485
8603
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
@@ -8493,7 +8611,6 @@ if (!Array.prototype.forEach) {
|
|
8493
8611
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8494
8612
|
return new AnonymousObservable(function (observer) {
|
8495
8613
|
var q = [];
|
8496
|
-
|
8497
8614
|
return source.subscribe(function (x) {
|
8498
8615
|
var now = scheduler.now();
|
8499
8616
|
q.push({ interval: now, value: x });
|
@@ -8504,11 +8621,8 @@ if (!Array.prototype.forEach) {
|
|
8504
8621
|
var now = scheduler.now();
|
8505
8622
|
while (q.length > 0) {
|
8506
8623
|
var next = q.shift();
|
8507
|
-
if (now - next.interval <= duration) {
|
8508
|
-
observer.onNext(next.value);
|
8509
|
-
}
|
8624
|
+
if (now - next.interval <= duration) { observer.onNext(next.value); }
|
8510
8625
|
}
|
8511
|
-
|
8512
8626
|
observer.onCompleted();
|
8513
8627
|
});
|
8514
8628
|
});
|
@@ -8516,9 +8630,6 @@ if (!Array.prototype.forEach) {
|
|
8516
8630
|
|
8517
8631
|
/**
|
8518
8632
|
* 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.
|
8519
|
-
*
|
8520
|
-
* @example
|
8521
|
-
* 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
|
8522
8633
|
* @description
|
8523
8634
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
8524
8635
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
@@ -8532,7 +8643,6 @@ if (!Array.prototype.forEach) {
|
|
8532
8643
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
8533
8644
|
return new AnonymousObservable(function (observer) {
|
8534
8645
|
var q = [];
|
8535
|
-
|
8536
8646
|
return source.subscribe(function (x) {
|
8537
8647
|
var now = scheduler.now();
|
8538
8648
|
q.push({ interval: now, value: x });
|
@@ -8543,11 +8653,8 @@ if (!Array.prototype.forEach) {
|
|
8543
8653
|
var now = scheduler.now(), res = [];
|
8544
8654
|
while (q.length > 0) {
|
8545
8655
|
var next = q.shift();
|
8546
|
-
if (now - next.interval <= duration) {
|
8547
|
-
res.push(next.value);
|
8548
|
-
}
|
8656
|
+
if (now - next.interval <= duration) { res.push(next.value); }
|
8549
8657
|
}
|
8550
|
-
|
8551
8658
|
observer.onNext(res);
|
8552
8659
|
observer.onCompleted();
|
8553
8660
|
});
|
@@ -8607,10 +8714,10 @@ if (!Array.prototype.forEach) {
|
|
8607
8714
|
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.
|
8608
8715
|
*
|
8609
8716
|
* @examples
|
8610
|
-
* 1 - res = source.skipUntilWithTime(new Date(), [
|
8611
|
-
* 2 - res = source.skipUntilWithTime(5000, [
|
8612
|
-
* @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.
|
8613
|
-
* @param scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8717
|
+
* 1 - res = source.skipUntilWithTime(new Date(), [scheduler]);
|
8718
|
+
* 2 - res = source.skipUntilWithTime(5000, [scheduler]);
|
8719
|
+
* @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.
|
8720
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
8614
8721
|
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
8615
8722
|
*/
|
8616
8723
|
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
@@ -8631,13 +8738,9 @@ if (!Array.prototype.forEach) {
|
|
8631
8738
|
};
|
8632
8739
|
|
8633
8740
|
/**
|
8634
|
-
* Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
|
8635
|
-
*
|
8636
|
-
* @example
|
8637
|
-
* 1 - res = source.takeUntilWithTime(new Date(), [optional scheduler]);
|
8638
|
-
* 2 - res = source.takeUntilWithTime(5000, [optional scheduler]);
|
8741
|
+
* Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
|
8639
8742
|
* @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.
|
8640
|
-
* @param {Scheduler} scheduler Scheduler to run the timer on.
|
8743
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on.
|
8641
8744
|
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
8642
8745
|
*/
|
8643
8746
|
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
@@ -8646,9 +8749,9 @@ if (!Array.prototype.forEach) {
|
|
8646
8749
|
'scheduleWithAbsolute' :
|
8647
8750
|
'scheduleWithRelative';
|
8648
8751
|
return new AnonymousObservable(function (observer) {
|
8649
|
-
return new CompositeDisposable(
|
8650
|
-
observer.onCompleted()
|
8651
|
-
|
8752
|
+
return new CompositeDisposable(
|
8753
|
+
scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
|
8754
|
+
source.subscribe(observer));
|
8652
8755
|
});
|
8653
8756
|
};
|
8654
8757
|
|
@@ -9142,30 +9245,25 @@ if (!Array.prototype.forEach) {
|
|
9142
9245
|
return AutoDetachObserver;
|
9143
9246
|
}(AbstractObserver));
|
9144
9247
|
|
9145
|
-
|
9146
|
-
|
9147
|
-
inherits(GroupedObservable, _super);
|
9248
|
+
var GroupedObservable = (function (__super__) {
|
9249
|
+
inherits(GroupedObservable, __super__);
|
9148
9250
|
|
9149
|
-
|
9150
|
-
|
9151
|
-
|
9251
|
+
function subscribe(observer) {
|
9252
|
+
return this.underlyingObservable.subscribe(observer);
|
9253
|
+
}
|
9152
9254
|
|
9153
|
-
|
9154
|
-
|
9155
|
-
|
9156
|
-
|
9157
|
-
|
9158
|
-
|
9159
|
-
|
9160
|
-
|
9161
|
-
|
9162
|
-
new AnonymousObservable(function (observer) {
|
9163
|
-
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
9164
|
-
});
|
9165
|
-
}
|
9255
|
+
function GroupedObservable(key, underlyingObservable, mergedDisposable) {
|
9256
|
+
__super__.call(this, subscribe);
|
9257
|
+
this.key = key;
|
9258
|
+
this.underlyingObservable = !mergedDisposable ?
|
9259
|
+
underlyingObservable :
|
9260
|
+
new AnonymousObservable(function (observer) {
|
9261
|
+
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
9262
|
+
});
|
9263
|
+
}
|
9166
9264
|
|
9167
|
-
|
9168
|
-
|
9265
|
+
return GroupedObservable;
|
9266
|
+
}(Observable));
|
9169
9267
|
|
9170
9268
|
/**
|
9171
9269
|
* Represents an object that is both an observable sequence as well as an observer.
|