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
|
*/
|
@@ -1138,6 +1132,7 @@ if (!Array.prototype.forEach) {
|
|
1138
1132
|
}(Scheduler.prototype));
|
1139
1133
|
|
1140
1134
|
(function (schedulerProto) {
|
1135
|
+
|
1141
1136
|
/**
|
1142
1137
|
* 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.
|
1143
1138
|
* @param {Number} period Period for running the work periodically.
|
@@ -1155,17 +1150,19 @@ if (!Array.prototype.forEach) {
|
|
1155
1150
|
* @param {Function} action Action to be executed, potentially updating the state.
|
1156
1151
|
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1157
1152
|
*/
|
1158
|
-
Scheduler.prototype.schedulePeriodicWithState = function
|
1153
|
+
Scheduler.prototype.schedulePeriodicWithState = function(state, period, action) {
|
1154
|
+
if (typeof root.setInterval === 'undefined') { throw new Error('Periodic scheduling not supported.'); }
|
1159
1155
|
var s = state;
|
1160
|
-
|
1161
|
-
var id = setInterval(function () {
|
1156
|
+
|
1157
|
+
var id = root.setInterval(function () {
|
1162
1158
|
s = action(s);
|
1163
1159
|
}, period);
|
1164
1160
|
|
1165
1161
|
return disposableCreate(function () {
|
1166
|
-
clearInterval(id);
|
1162
|
+
root.clearInterval(id);
|
1167
1163
|
});
|
1168
1164
|
};
|
1165
|
+
|
1169
1166
|
}(Scheduler.prototype));
|
1170
1167
|
|
1171
1168
|
/**
|
@@ -1276,100 +1273,121 @@ if (!Array.prototype.forEach) {
|
|
1276
1273
|
return SchedulePeriodicRecursive;
|
1277
1274
|
}());
|
1278
1275
|
|
1279
|
-
|
1280
1276
|
var scheduleMethod, clearMethod = noop;
|
1281
|
-
(function () {
|
1277
|
+
var localTimer = (function () {
|
1278
|
+
var localSetTimeout, localClearTimeout = noop;
|
1279
|
+
if ('WScript' in this) {
|
1280
|
+
localSetTimeout = function (fn, time) {
|
1281
|
+
WScript.Sleep(time);
|
1282
|
+
fn();
|
1283
|
+
};
|
1284
|
+
} else if (!!root.setTimeout) {
|
1285
|
+
localSetTimeout = root.setTimeout;
|
1286
|
+
localClearTimeout = root.clearTimeout;
|
1287
|
+
} else {
|
1288
|
+
throw new Error('No concurrency detected!');
|
1289
|
+
}
|
1282
1290
|
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1291
|
+
return {
|
1292
|
+
setTimeout: localSetTimeout,
|
1293
|
+
clearTimeout: localClearTimeout
|
1294
|
+
};
|
1295
|
+
}());
|
1296
|
+
var localSetTimeout = localTimer.setTimeout,
|
1297
|
+
localClearTimeout = localTimer.clearTimeout;
|
1298
|
+
|
1299
|
+
(function () {
|
1300
|
+
|
1301
|
+
var reNative = RegExp('^' +
|
1302
|
+
String(toString)
|
1303
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1304
|
+
.replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1305
|
+
);
|
1306
|
+
|
1307
|
+
var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1308
|
+
!reNative.test(setImmediate) && setImmediate,
|
1309
|
+
clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
|
1310
|
+
!reNative.test(clearImmediate) && clearImmediate;
|
1311
|
+
|
1312
|
+
function postMessageSupported () {
|
1313
|
+
// Ensure not in a worker
|
1314
|
+
if (!root.postMessage || root.importScripts) { return false; }
|
1315
|
+
var isAsync = false,
|
1316
|
+
oldHandler = root.onmessage;
|
1317
|
+
// Test for async
|
1318
|
+
root.onmessage = function () { isAsync = true; };
|
1319
|
+
root.postMessage('','*');
|
1320
|
+
root.onmessage = oldHandler;
|
1321
|
+
|
1322
|
+
return isAsync;
|
1323
|
+
}
|
1288
1324
|
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1325
|
+
// Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
|
1326
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1327
|
+
scheduleMethod = process.nextTick;
|
1328
|
+
} else if (typeof setImmediate === 'function') {
|
1329
|
+
scheduleMethod = setImmediate;
|
1330
|
+
clearMethod = clearImmediate;
|
1331
|
+
} else if (postMessageSupported()) {
|
1332
|
+
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1333
|
+
tasks = {},
|
1334
|
+
taskId = 0;
|
1335
|
+
|
1336
|
+
function onGlobalPostMessage(event) {
|
1337
|
+
// Only if we're a match to avoid any other global events
|
1338
|
+
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1339
|
+
var handleId = event.data.substring(MSG_PREFIX.length),
|
1340
|
+
action = tasks[handleId];
|
1341
|
+
action();
|
1342
|
+
delete tasks[handleId];
|
1343
|
+
}
|
1305
1344
|
}
|
1306
1345
|
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
clearMethod = clearImmediate;
|
1313
|
-
} else if (postMessageSupported()) {
|
1314
|
-
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1315
|
-
tasks = {},
|
1316
|
-
taskId = 0;
|
1317
|
-
|
1318
|
-
function onGlobalPostMessage(event) {
|
1319
|
-
// Only if we're a match to avoid any other global events
|
1320
|
-
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1321
|
-
var handleId = event.data.substring(MSG_PREFIX.length),
|
1322
|
-
action = tasks[handleId];
|
1323
|
-
action();
|
1324
|
-
delete tasks[handleId];
|
1325
|
-
}
|
1326
|
-
}
|
1346
|
+
if (root.addEventListener) {
|
1347
|
+
root.addEventListener('message', onGlobalPostMessage, false);
|
1348
|
+
} else {
|
1349
|
+
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1350
|
+
}
|
1327
1351
|
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1352
|
+
scheduleMethod = function (action) {
|
1353
|
+
var currentId = taskId++;
|
1354
|
+
tasks[currentId] = action;
|
1355
|
+
root.postMessage(MSG_PREFIX + currentId, '*');
|
1356
|
+
};
|
1357
|
+
} else if (!!root.MessageChannel) {
|
1358
|
+
var channel = new root.MessageChannel(),
|
1359
|
+
channelTasks = {},
|
1360
|
+
channelTaskId = 0;
|
1361
|
+
|
1362
|
+
channel.port1.onmessage = function (event) {
|
1363
|
+
var id = event.data,
|
1364
|
+
action = channelTasks[id];
|
1365
|
+
action();
|
1366
|
+
delete channelTasks[id];
|
1367
|
+
};
|
1333
1368
|
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
delete channelTasks[id];
|
1349
|
-
};
|
1350
|
-
|
1351
|
-
scheduleMethod = function (action) {
|
1352
|
-
var id = channelTaskId++;
|
1353
|
-
channelTasks[id] = action;
|
1354
|
-
channel.port2.postMessage(id);
|
1355
|
-
};
|
1356
|
-
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1357
|
-
|
1358
|
-
scheduleMethod = function (action) {
|
1359
|
-
var scriptElement = root.document.createElement('script');
|
1360
|
-
scriptElement.onreadystatechange = function () {
|
1361
|
-
action();
|
1362
|
-
scriptElement.onreadystatechange = null;
|
1363
|
-
scriptElement.parentNode.removeChild(scriptElement);
|
1364
|
-
scriptElement = null;
|
1365
|
-
};
|
1366
|
-
root.document.documentElement.appendChild(scriptElement);
|
1369
|
+
scheduleMethod = function (action) {
|
1370
|
+
var id = channelTaskId++;
|
1371
|
+
channelTasks[id] = action;
|
1372
|
+
channel.port2.postMessage(id);
|
1373
|
+
};
|
1374
|
+
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1375
|
+
|
1376
|
+
scheduleMethod = function (action) {
|
1377
|
+
var scriptElement = root.document.createElement('script');
|
1378
|
+
scriptElement.onreadystatechange = function () {
|
1379
|
+
action();
|
1380
|
+
scriptElement.onreadystatechange = null;
|
1381
|
+
scriptElement.parentNode.removeChild(scriptElement);
|
1382
|
+
scriptElement = null;
|
1367
1383
|
};
|
1384
|
+
root.document.documentElement.appendChild(scriptElement);
|
1385
|
+
};
|
1368
1386
|
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1387
|
+
} else {
|
1388
|
+
scheduleMethod = function (action) { return localSetTimeout(action, 0); };
|
1389
|
+
clearMethod = localClearTimeout;
|
1390
|
+
}
|
1373
1391
|
}());
|
1374
1392
|
|
1375
1393
|
/**
|
@@ -1378,33 +1396,33 @@ if (!Array.prototype.forEach) {
|
|
1378
1396
|
var timeoutScheduler = Scheduler.timeout = (function () {
|
1379
1397
|
|
1380
1398
|
function scheduleNow(state, action) {
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1399
|
+
var scheduler = this,
|
1400
|
+
disposable = new SingleAssignmentDisposable();
|
1401
|
+
var id = scheduleMethod(function () {
|
1402
|
+
if (!disposable.isDisposed) {
|
1403
|
+
disposable.setDisposable(action(scheduler, state));
|
1404
|
+
}
|
1405
|
+
});
|
1406
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1407
|
+
clearMethod(id);
|
1408
|
+
}));
|
1391
1409
|
}
|
1392
1410
|
|
1393
1411
|
function scheduleRelative(state, dueTime, action) {
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1412
|
+
var scheduler = this,
|
1413
|
+
dt = Scheduler.normalize(dueTime);
|
1414
|
+
if (dt === 0) {
|
1415
|
+
return scheduler.scheduleWithState(state, action);
|
1416
|
+
}
|
1417
|
+
var disposable = new SingleAssignmentDisposable();
|
1418
|
+
var id = localSetTimeout(function () {
|
1419
|
+
if (!disposable.isDisposed) {
|
1420
|
+
disposable.setDisposable(action(scheduler, state));
|
1398
1421
|
}
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
}
|
1404
|
-
}, dt);
|
1405
|
-
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1406
|
-
clearTimeout(id);
|
1407
|
-
}));
|
1422
|
+
}, dt);
|
1423
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1424
|
+
localClearTimeout(id);
|
1425
|
+
}));
|
1408
1426
|
}
|
1409
1427
|
|
1410
1428
|
function scheduleAbsolute(state, dueTime, action) {
|
@@ -1882,11 +1900,11 @@ if (!Array.prototype.forEach) {
|
|
1882
1900
|
return Observable;
|
1883
1901
|
})();
|
1884
1902
|
|
1885
|
-
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (
|
1886
|
-
inherits(ScheduledObserver,
|
1903
|
+
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
|
1904
|
+
inherits(ScheduledObserver, __super__);
|
1887
1905
|
|
1888
1906
|
function ScheduledObserver(scheduler, observer) {
|
1889
|
-
|
1907
|
+
__super__.call(this);
|
1890
1908
|
this.scheduler = scheduler;
|
1891
1909
|
this.observer = observer;
|
1892
1910
|
this.isAcquired = false;
|
@@ -1902,10 +1920,10 @@ if (!Array.prototype.forEach) {
|
|
1902
1920
|
});
|
1903
1921
|
};
|
1904
1922
|
|
1905
|
-
ScheduledObserver.prototype.error = function (
|
1923
|
+
ScheduledObserver.prototype.error = function (err) {
|
1906
1924
|
var self = this;
|
1907
1925
|
this.queue.push(function () {
|
1908
|
-
self.observer.onError(
|
1926
|
+
self.observer.onError(err);
|
1909
1927
|
});
|
1910
1928
|
};
|
1911
1929
|
|
@@ -1944,7 +1962,7 @@ if (!Array.prototype.forEach) {
|
|
1944
1962
|
};
|
1945
1963
|
|
1946
1964
|
ScheduledObserver.prototype.dispose = function () {
|
1947
|
-
|
1965
|
+
__super__.prototype.dispose.call(this);
|
1948
1966
|
this.disposable.dispose();
|
1949
1967
|
};
|
1950
1968
|
|
@@ -2136,15 +2154,15 @@ if (!Array.prototype.forEach) {
|
|
2136
2154
|
});
|
2137
2155
|
};
|
2138
2156
|
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2157
|
+
/**
|
2158
|
+
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2159
|
+
* @returns {Observable} An observable sequence whose observers will never get called.
|
2160
|
+
*/
|
2161
|
+
var observableNever = Observable.never = function () {
|
2162
|
+
return new AnonymousObservable(function () {
|
2163
|
+
return disposableEmpty;
|
2164
|
+
});
|
2165
|
+
};
|
2148
2166
|
|
2149
2167
|
/**
|
2150
2168
|
* This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
|
@@ -2237,16 +2255,12 @@ if (!Array.prototype.forEach) {
|
|
2237
2255
|
|
2238
2256
|
/**
|
2239
2257
|
* Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
|
2240
|
-
* There is an alias to this method called '
|
2241
|
-
*
|
2242
|
-
* @example
|
2243
|
-
* var res = Rx.Observable.throw(new Error('Error'));
|
2244
|
-
* var res = Rx.Observable.throw(new Error('Error'), Rx.Scheduler.timeout);
|
2258
|
+
* There is an alias to this method called 'throwError' for browsers <IE9.
|
2245
2259
|
* @param {Mixed} exception An object used for the sequence's termination.
|
2246
2260
|
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2247
2261
|
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2248
2262
|
*/
|
2249
|
-
var observableThrow = Observable['throw'] = Observable.throwException = function (exception, scheduler) {
|
2263
|
+
var observableThrow = Observable['throw'] = Observable.throwException = Observable.throwError = function (exception, scheduler) {
|
2250
2264
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2251
2265
|
return new AnonymousObservable(function (observer) {
|
2252
2266
|
return scheduler.schedule(function () {
|
@@ -2517,20 +2531,16 @@ if (!Array.prototype.forEach) {
|
|
2517
2531
|
var innerSubscription = new SingleAssignmentDisposable();
|
2518
2532
|
group.add(innerSubscription);
|
2519
2533
|
|
2520
|
-
// Check
|
2521
|
-
|
2522
|
-
innerSource = observableFromPromise(innerSource);
|
2523
|
-
}
|
2534
|
+
// Check for promises support
|
2535
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
2524
2536
|
|
2525
|
-
innerSubscription.setDisposable(innerSource.subscribe(function (
|
2526
|
-
|
2527
|
-
|
2528
|
-
group.remove(innerSubscription);
|
2529
|
-
if (isStopped && group.length === 1) { observer.onCompleted(); }
|
2537
|
+
innerSubscription.setDisposable(innerSource.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
|
2538
|
+
group.remove(innerSubscription);
|
2539
|
+
isStopped && group.length === 1 && observer.onCompleted();
|
2530
2540
|
}));
|
2531
2541
|
}, observer.onError.bind(observer), function () {
|
2532
2542
|
isStopped = true;
|
2533
|
-
|
2543
|
+
group.length === 1 && observer.onCompleted();
|
2534
2544
|
}));
|
2535
2545
|
return group;
|
2536
2546
|
});
|
@@ -2566,52 +2576,44 @@ if (!Array.prototype.forEach) {
|
|
2566
2576
|
});
|
2567
2577
|
};
|
2568
2578
|
|
2569
|
-
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
}
|
2579
|
+
/**
|
2580
|
+
* Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
2581
|
+
* @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.
|
2582
|
+
*/
|
2583
|
+
observableProto['switch'] = observableProto.switchLatest = function () {
|
2584
|
+
var sources = this;
|
2585
|
+
return new AnonymousObservable(function (observer) {
|
2586
|
+
var hasLatest = false,
|
2587
|
+
innerSubscription = new SerialDisposable(),
|
2588
|
+
isStopped = false,
|
2589
|
+
latest = 0,
|
2590
|
+
subscription = sources.subscribe(
|
2591
|
+
function (innerSource) {
|
2592
|
+
var d = new SingleAssignmentDisposable(), id = ++latest;
|
2593
|
+
hasLatest = true;
|
2594
|
+
innerSubscription.setDisposable(d);
|
2595
|
+
|
2596
|
+
// Check if Promise or Observable
|
2597
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
2589
2598
|
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
if (!hasLatest) {
|
2609
|
-
observer.onCompleted();
|
2610
|
-
}
|
2611
|
-
});
|
2612
|
-
return new CompositeDisposable(subscription, innerSubscription);
|
2613
|
-
});
|
2614
|
-
};
|
2599
|
+
d.setDisposable(innerSource.subscribe(
|
2600
|
+
function (x) { latest === id && observer.onNext(x); },
|
2601
|
+
function (e) { latest === id && observer.onError(e); },
|
2602
|
+
function () {
|
2603
|
+
if (latest === id) {
|
2604
|
+
hasLatest = false;
|
2605
|
+
isStopped && observer.onCompleted();
|
2606
|
+
}
|
2607
|
+
}));
|
2608
|
+
},
|
2609
|
+
observer.onError.bind(observer),
|
2610
|
+
function () {
|
2611
|
+
isStopped = true;
|
2612
|
+
!hasLatest && observer.onCompleted();
|
2613
|
+
});
|
2614
|
+
return new CompositeDisposable(subscription, innerSubscription);
|
2615
|
+
});
|
2616
|
+
};
|
2615
2617
|
|
2616
2618
|
/**
|
2617
2619
|
* Returns the values from the source observable sequence until the other observable sequence produces a value.
|
@@ -2776,16 +2778,13 @@ if (!Array.prototype.forEach) {
|
|
2776
2778
|
});
|
2777
2779
|
};
|
2778
2780
|
|
2779
|
-
|
2780
|
-
|
2781
|
-
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2785
|
-
|
2786
|
-
return source.subscribe(observer);
|
2787
|
-
});
|
2788
|
-
};
|
2781
|
+
/**
|
2782
|
+
* Hides the identity of an observable sequence.
|
2783
|
+
* @returns {Observable} An observable sequence that hides the identity of the source sequence.
|
2784
|
+
*/
|
2785
|
+
observableProto.asObservable = function () {
|
2786
|
+
return new AnonymousObservable(this.subscribe.bind(this));
|
2787
|
+
};
|
2789
2788
|
|
2790
2789
|
/**
|
2791
2790
|
* Dematerializes the explicit notification values of an observable sequence as implicit notifications.
|
@@ -2929,35 +2928,35 @@ if (!Array.prototype.forEach) {
|
|
2929
2928
|
});
|
2930
2929
|
};
|
2931
2930
|
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2931
|
+
/**
|
2932
|
+
* Ignores all elements in an observable sequence leaving only the termination messages.
|
2933
|
+
* @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
|
2934
|
+
*/
|
2935
|
+
observableProto.ignoreElements = function () {
|
2936
|
+
var source = this;
|
2937
|
+
return new AnonymousObservable(function (observer) {
|
2938
|
+
return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
2939
|
+
});
|
2940
|
+
};
|
2942
2941
|
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2942
|
+
/**
|
2943
|
+
* Materializes the implicit notifications of an observable sequence as explicit notification values.
|
2944
|
+
* @returns {Observable} An observable sequence containing the materialized notification values from the source sequence.
|
2945
|
+
*/
|
2946
|
+
observableProto.materialize = function () {
|
2947
|
+
var source = this;
|
2948
|
+
return new AnonymousObservable(function (observer) {
|
2949
|
+
return source.subscribe(function (value) {
|
2950
|
+
observer.onNext(notificationCreateOnNext(value));
|
2951
|
+
}, function (e) {
|
2952
|
+
observer.onNext(notificationCreateOnError(e));
|
2953
|
+
observer.onCompleted();
|
2954
|
+
}, function () {
|
2955
|
+
observer.onNext(notificationCreateOnCompleted());
|
2956
|
+
observer.onCompleted();
|
2957
|
+
});
|
2958
|
+
});
|
2959
|
+
};
|
2961
2960
|
|
2962
2961
|
/**
|
2963
2962
|
* Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
|
@@ -2986,112 +2985,100 @@ if (!Array.prototype.forEach) {
|
|
2986
2985
|
return enumerableRepeat(this, retryCount).catchException();
|
2987
2986
|
};
|
2988
2987
|
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
2994
|
-
|
2995
|
-
|
2996
|
-
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3000
|
-
|
3001
|
-
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
|
3013
|
-
|
3014
|
-
|
3015
|
-
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3024
|
-
observer.onError(e);
|
3025
|
-
return;
|
3026
|
-
}
|
3027
|
-
|
3028
|
-
observer.onNext(accumulation);
|
3029
|
-
},
|
3030
|
-
observer.onError.bind(observer),
|
3031
|
-
function () {
|
3032
|
-
if (!hasValue && hasSeed) {
|
3033
|
-
observer.onNext(seed);
|
3034
|
-
}
|
3035
|
-
observer.onCompleted();
|
3036
|
-
}
|
3037
|
-
);
|
3038
|
-
});
|
3039
|
-
};
|
3040
|
-
|
3041
|
-
/**
|
3042
|
-
* Bypasses a specified number of elements at the end of an observable sequence.
|
3043
|
-
* @description
|
3044
|
-
* This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
|
3045
|
-
* received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
|
3046
|
-
* @param count Number of elements to bypass at the end of the source sequence.
|
3047
|
-
* @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
|
3048
|
-
*/
|
3049
|
-
observableProto.skipLast = function (count) {
|
3050
|
-
var source = this;
|
3051
|
-
return new AnonymousObservable(function (observer) {
|
3052
|
-
var q = [];
|
3053
|
-
return source.subscribe(function (x) {
|
3054
|
-
q.push(x);
|
3055
|
-
if (q.length > count) {
|
3056
|
-
observer.onNext(q.shift());
|
3057
|
-
}
|
3058
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3059
|
-
});
|
3060
|
-
};
|
2988
|
+
/**
|
2989
|
+
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
2990
|
+
* For aggregation behavior with no intermediate results, see Observable.aggregate.
|
2991
|
+
* @example
|
2992
|
+
* var res = source.scan(function (acc, x) { return acc + x; });
|
2993
|
+
* var res = source.scan(0, function (acc, x) { return acc + x; });
|
2994
|
+
* @param {Mixed} [seed] The initial accumulator value.
|
2995
|
+
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
2996
|
+
* @returns {Observable} An observable sequence containing the accumulated values.
|
2997
|
+
*/
|
2998
|
+
observableProto.scan = function () {
|
2999
|
+
var hasSeed = false, seed, accumulator, source = this;
|
3000
|
+
if (arguments.length === 2) {
|
3001
|
+
hasSeed = true;
|
3002
|
+
seed = arguments[0];
|
3003
|
+
accumulator = arguments[1];
|
3004
|
+
} else {
|
3005
|
+
accumulator = arguments[0];
|
3006
|
+
}
|
3007
|
+
return new AnonymousObservable(function (observer) {
|
3008
|
+
var hasAccumulation, accumulation, hasValue;
|
3009
|
+
return source.subscribe (
|
3010
|
+
function (x) {
|
3011
|
+
!hasValue && (hasValue = true);
|
3012
|
+
try {
|
3013
|
+
if (hasAccumulation) {
|
3014
|
+
accumulation = accumulator(accumulation, x);
|
3015
|
+
} else {
|
3016
|
+
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3017
|
+
hasAccumulation = true;
|
3018
|
+
}
|
3019
|
+
} catch (e) {
|
3020
|
+
observer.onError(e);
|
3021
|
+
return;
|
3022
|
+
}
|
3061
3023
|
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
|
3068
|
-
* @memberOf Observable#
|
3069
|
-
* @returns {Observable} The source sequence prepended with the specified values.
|
3070
|
-
*/
|
3071
|
-
observableProto.startWith = function () {
|
3072
|
-
var values, scheduler, start = 0;
|
3073
|
-
if (!!arguments.length && 'now' in Object(arguments[0])) {
|
3074
|
-
scheduler = arguments[0];
|
3075
|
-
start = 1;
|
3076
|
-
} else {
|
3077
|
-
scheduler = immediateScheduler;
|
3024
|
+
observer.onNext(accumulation);
|
3025
|
+
},
|
3026
|
+
observer.onError.bind(observer),
|
3027
|
+
function () {
|
3028
|
+
!hasValue && hasSeed && observer.onNext(seed);
|
3029
|
+
observer.onCompleted();
|
3078
3030
|
}
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3031
|
+
);
|
3032
|
+
});
|
3033
|
+
};
|
3082
3034
|
|
3083
3035
|
/**
|
3084
|
-
*
|
3085
|
-
*
|
3086
|
-
* @example
|
3087
|
-
* var res = source.takeLast(5);
|
3088
|
-
*
|
3036
|
+
* Bypasses a specified number of elements at the end of an observable sequence.
|
3089
3037
|
* @description
|
3090
|
-
* This operator accumulates a
|
3091
|
-
* the
|
3092
|
-
* @param
|
3093
|
-
* @returns {Observable} An observable sequence containing the
|
3094
|
-
*/
|
3038
|
+
* This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
|
3039
|
+
* received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
|
3040
|
+
* @param count Number of elements to bypass at the end of the source sequence.
|
3041
|
+
* @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
|
3042
|
+
*/
|
3043
|
+
observableProto.skipLast = function (count) {
|
3044
|
+
var source = this;
|
3045
|
+
return new AnonymousObservable(function (observer) {
|
3046
|
+
var q = [];
|
3047
|
+
return source.subscribe(function (x) {
|
3048
|
+
q.push(x);
|
3049
|
+
q.length > count && observer.onNext(q.shift());
|
3050
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3051
|
+
});
|
3052
|
+
};
|
3053
|
+
|
3054
|
+
/**
|
3055
|
+
* Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend.
|
3056
|
+
* @example
|
3057
|
+
* var res = source.startWith(1, 2, 3);
|
3058
|
+
* var res = source.startWith(Rx.Scheduler.timeout, 1, 2, 3);
|
3059
|
+
* @param {Arguments} args The specified values to prepend to the observable sequence
|
3060
|
+
* @returns {Observable} The source sequence prepended with the specified values.
|
3061
|
+
*/
|
3062
|
+
observableProto.startWith = function () {
|
3063
|
+
var values, scheduler, start = 0;
|
3064
|
+
if (!!arguments.length && isScheduler(arguments[0])) {
|
3065
|
+
scheduler = arguments[0];
|
3066
|
+
start = 1;
|
3067
|
+
} else {
|
3068
|
+
scheduler = immediateScheduler;
|
3069
|
+
}
|
3070
|
+
values = slice.call(arguments, start);
|
3071
|
+
return enumerableFor([observableFromArray(values, scheduler), this]).concat();
|
3072
|
+
};
|
3073
|
+
|
3074
|
+
/**
|
3075
|
+
* Returns a specified number of contiguous elements from the end of an observable sequence.
|
3076
|
+
* @description
|
3077
|
+
* This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of
|
3078
|
+
* the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
|
3079
|
+
* @param {Number} count Number of elements to take from the end of the source sequence.
|
3080
|
+
* @returns {Observable} An observable sequence containing the specified number of elements from the end of the source sequence.
|
3081
|
+
*/
|
3095
3082
|
observableProto.takeLast = function (count) {
|
3096
3083
|
var source = this;
|
3097
3084
|
return new AnonymousObservable(function (observer) {
|
@@ -3171,14 +3158,14 @@ if (!Array.prototype.forEach) {
|
|
3171
3158
|
});
|
3172
3159
|
};
|
3173
3160
|
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3161
|
+
/**
|
3162
|
+
* Retrieves the value of a specified property from all elements in the Observable sequence.
|
3163
|
+
* @param {String} prop The property to pluck.
|
3164
|
+
* @returns {Observable} Returns a new Observable sequence of property values.
|
3165
|
+
*/
|
3166
|
+
observableProto.pluck = function (prop) {
|
3167
|
+
return this.map(function (x) { return x[prop]; });
|
3168
|
+
};
|
3182
3169
|
|
3183
3170
|
function flatMap(source, selector, thisArg) {
|
3184
3171
|
return source.map(function (x, i) {
|
@@ -3223,133 +3210,118 @@ if (!Array.prototype.forEach) {
|
|
3223
3210
|
flatMap(this, function () { return selector; });
|
3224
3211
|
};
|
3225
3212
|
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3234
|
-
|
3235
|
-
|
3236
|
-
|
3213
|
+
/**
|
3214
|
+
* Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
|
3215
|
+
* transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
3216
|
+
* @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.
|
3217
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3218
|
+
* @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
|
3219
|
+
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
3220
|
+
*/
|
3221
|
+
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
3222
|
+
return this.select(selector, thisArg).switchLatest();
|
3223
|
+
};
|
3237
3224
|
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
|
3225
|
+
/**
|
3226
|
+
* Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
|
3227
|
+
* @param {Number} count The number of elements to skip before returning the remaining elements.
|
3228
|
+
* @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
|
3229
|
+
*/
|
3230
|
+
observableProto.skip = function (count) {
|
3231
|
+
if (count < 0) { throw new Error(argumentOutOfRange); }
|
3232
|
+
var source = this;
|
3233
|
+
return new AnonymousObservable(function (observer) {
|
3234
|
+
var remaining = count;
|
3235
|
+
return source.subscribe(function (x) {
|
3236
|
+
if (remaining <= 0) {
|
3237
|
+
observer.onNext(x);
|
3238
|
+
} else {
|
3239
|
+
remaining--;
|
3240
|
+
}
|
3241
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3242
|
+
});
|
3243
|
+
};
|
3244
|
+
|
3245
|
+
/**
|
3246
|
+
* Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
|
3247
|
+
* The element's index is used in the logic of the predicate function.
|
3248
|
+
*
|
3249
|
+
* var res = source.skipWhile(function (value) { return value < 10; });
|
3250
|
+
* var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
|
3251
|
+
* @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.
|
3252
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3253
|
+
* @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.
|
3254
|
+
*/
|
3255
|
+
observableProto.skipWhile = function (predicate, thisArg) {
|
3256
|
+
var source = this;
|
3257
|
+
return new AnonymousObservable(function (observer) {
|
3258
|
+
var i = 0, running = false;
|
3259
|
+
return source.subscribe(function (x) {
|
3260
|
+
if (!running) {
|
3261
|
+
try {
|
3262
|
+
running = !predicate.call(thisArg, x, i++, source);
|
3263
|
+
} catch (e) {
|
3264
|
+
observer.onError(e);
|
3265
|
+
return;
|
3266
|
+
}
|
3246
3267
|
}
|
3247
|
-
|
3248
|
-
|
3249
|
-
|
3250
|
-
|
3251
|
-
if (remaining <= 0) {
|
3252
|
-
observer.onNext(x);
|
3253
|
-
} else {
|
3254
|
-
remaining--;
|
3255
|
-
}
|
3256
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3257
|
-
});
|
3258
|
-
};
|
3268
|
+
running && observer.onNext(x);
|
3269
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3270
|
+
});
|
3271
|
+
};
|
3259
3272
|
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
if (running) {
|
3284
|
-
observer.onNext(x);
|
3285
|
-
}
|
3286
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3287
|
-
});
|
3288
|
-
};
|
3273
|
+
/**
|
3274
|
+
* 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).
|
3275
|
+
*
|
3276
|
+
* var res = source.take(5);
|
3277
|
+
* var res = source.take(0, Rx.Scheduler.timeout);
|
3278
|
+
* @param {Number} count The number of elements to return.
|
3279
|
+
* @param {Scheduler} [scheduler] Scheduler used to produce an OnCompleted message in case <paramref name="count count</paramref> is set to 0.
|
3280
|
+
* @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
|
3281
|
+
*/
|
3282
|
+
observableProto.take = function (count, scheduler) {
|
3283
|
+
if (count < 0) { throw new RangeError(argumentOutOfRange); }
|
3284
|
+
if (count === 0) { return observableEmpty(scheduler); }
|
3285
|
+
var observable = this;
|
3286
|
+
return new AnonymousObservable(function (observer) {
|
3287
|
+
var remaining = count;
|
3288
|
+
return observable.subscribe(function (x) {
|
3289
|
+
if (remaining-- > 0) {
|
3290
|
+
observer.onNext(x);
|
3291
|
+
remaining === 0 && observer.onCompleted();
|
3292
|
+
}
|
3293
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3294
|
+
});
|
3295
|
+
};
|
3289
3296
|
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
|
3294
|
-
|
3295
|
-
|
3296
|
-
|
3297
|
-
|
3298
|
-
|
3299
|
-
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3297
|
+
/**
|
3298
|
+
* Returns elements from an observable sequence as long as a specified condition is true.
|
3299
|
+
* The element's index is used in the logic of the predicate function.
|
3300
|
+
* @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.
|
3301
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3302
|
+
* @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.
|
3303
|
+
*/
|
3304
|
+
observableProto.takeWhile = function (predicate, thisArg) {
|
3305
|
+
var observable = this;
|
3306
|
+
return new AnonymousObservable(function (observer) {
|
3307
|
+
var i = 0, running = true;
|
3308
|
+
return observable.subscribe(function (x) {
|
3309
|
+
if (running) {
|
3310
|
+
try {
|
3311
|
+
running = predicate.call(thisArg, x, i++, observable);
|
3312
|
+
} catch (e) {
|
3313
|
+
observer.onError(e);
|
3314
|
+
return;
|
3315
|
+
}
|
3316
|
+
if (running) {
|
3317
|
+
observer.onNext(x);
|
3318
|
+
} else {
|
3319
|
+
observer.onCompleted();
|
3320
|
+
}
|
3305
3321
|
}
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
return observable.subscribe(function (x) {
|
3310
|
-
if (remaining > 0) {
|
3311
|
-
remaining--;
|
3312
|
-
observer.onNext(x);
|
3313
|
-
if (remaining === 0) {
|
3314
|
-
observer.onCompleted();
|
3315
|
-
}
|
3316
|
-
}
|
3317
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3318
|
-
});
|
3319
|
-
};
|
3320
|
-
|
3321
|
-
/**
|
3322
|
-
* Returns elements from an observable sequence as long as a specified condition is true.
|
3323
|
-
* The element's index is used in the logic of the predicate function.
|
3324
|
-
*
|
3325
|
-
* @example
|
3326
|
-
* var res = source.takeWhile(function (value) { return value < 10; });
|
3327
|
-
* var res = source.takeWhile(function (value, index) { return value < 10 || index < 10; });
|
3328
|
-
* @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.
|
3329
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3330
|
-
* @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.
|
3331
|
-
*/
|
3332
|
-
observableProto.takeWhile = function (predicate, thisArg) {
|
3333
|
-
var observable = this;
|
3334
|
-
return new AnonymousObservable(function (observer) {
|
3335
|
-
var i = 0, running = true;
|
3336
|
-
return observable.subscribe(function (x) {
|
3337
|
-
if (running) {
|
3338
|
-
try {
|
3339
|
-
running = predicate.call(thisArg, x, i++, observable);
|
3340
|
-
} catch (e) {
|
3341
|
-
observer.onError(e);
|
3342
|
-
return;
|
3343
|
-
}
|
3344
|
-
if (running) {
|
3345
|
-
observer.onNext(x);
|
3346
|
-
} else {
|
3347
|
-
observer.onCompleted();
|
3348
|
-
}
|
3349
|
-
}
|
3350
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3351
|
-
});
|
3352
|
-
};
|
3322
|
+
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
3323
|
+
});
|
3324
|
+
};
|
3353
3325
|
|
3354
3326
|
/**
|
3355
3327
|
* Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
|
@@ -3693,38 +3665,32 @@ if (!Array.prototype.forEach) {
|
|
3693
3665
|
return subject;
|
3694
3666
|
});
|
3695
3667
|
};
|
3696
|
-
|
3697
|
-
|
3698
|
-
|
3699
|
-
|
3700
|
-
|
3701
|
-
|
3702
|
-
|
3703
|
-
|
3704
|
-
|
3705
|
-
|
3706
|
-
|
3707
|
-
|
3708
|
-
|
3709
|
-
|
3710
|
-
|
3711
|
-
|
3712
|
-
|
3713
|
-
|
3714
|
-
|
3715
|
-
|
3716
|
-
|
3717
|
-
|
3718
|
-
|
3719
|
-
|
3720
|
-
|
3721
|
-
|
3722
|
-
if (hasValue) {
|
3723
|
-
resolve(value);
|
3724
|
-
}
|
3725
|
-
});
|
3726
|
-
});
|
3727
|
-
};
|
3668
|
+
/*
|
3669
|
+
* Converts an existing observable sequence to an ES6 Compatible Promise
|
3670
|
+
* @example
|
3671
|
+
* var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
|
3672
|
+
*
|
3673
|
+
* // With config
|
3674
|
+
* Rx.config.Promise = RSVP.Promise;
|
3675
|
+
* var promise = Rx.Observable.return(42).toPromise();
|
3676
|
+
* @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
|
3677
|
+
* @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
|
3678
|
+
*/
|
3679
|
+
observableProto.toPromise = function (promiseCtor) {
|
3680
|
+
promiseCtor || (promiseCtor = Rx.config.Promise);
|
3681
|
+
if (!promiseCtor) { throw new TypeError('Promise type not provided nor in Rx.config.Promise'); }
|
3682
|
+
var source = this;
|
3683
|
+
return new promiseCtor(function (resolve, reject) {
|
3684
|
+
// No cancellation can be done
|
3685
|
+
var value, hasValue = false;
|
3686
|
+
source.subscribe(function (v) {
|
3687
|
+
value = v;
|
3688
|
+
hasValue = true;
|
3689
|
+
}, reject, function () {
|
3690
|
+
hasValue && resolve(value);
|
3691
|
+
});
|
3692
|
+
});
|
3693
|
+
};
|
3728
3694
|
/**
|
3729
3695
|
* Invokes the asynchronous function, surfacing the result through an observable sequence.
|
3730
3696
|
* @param {Function} functionAsync Asynchronous function which returns a Promise to run.
|
@@ -3761,121 +3727,114 @@ if (!Array.prototype.forEach) {
|
|
3761
3727
|
var source = this;
|
3762
3728
|
return typeof subjectOrSubjectSelector === 'function' ?
|
3763
3729
|
new AnonymousObservable(function (observer) {
|
3764
|
-
|
3765
|
-
|
3730
|
+
var connectable = source.multicast(subjectOrSubjectSelector());
|
3731
|
+
return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
|
3766
3732
|
}) :
|
3767
3733
|
new ConnectableObservable(source, subjectOrSubjectSelector);
|
3768
3734
|
};
|
3769
3735
|
|
3770
|
-
|
3771
|
-
|
3772
|
-
|
3773
|
-
|
3774
|
-
|
3775
|
-
|
3776
|
-
|
3777
|
-
|
3778
|
-
|
3779
|
-
|
3780
|
-
|
3781
|
-
|
3782
|
-
|
3783
|
-
|
3784
|
-
|
3785
|
-
|
3786
|
-
}, selector);
|
3787
|
-
};
|
3736
|
+
/**
|
3737
|
+
* 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.
|
3738
|
+
* This operator is a specialization of Multicast using a regular Subject.
|
3739
|
+
*
|
3740
|
+
* @example
|
3741
|
+
* var resres = source.publish();
|
3742
|
+
* var res = source.publish(function (x) { return x; });
|
3743
|
+
*
|
3744
|
+
* @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.
|
3745
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
3746
|
+
*/
|
3747
|
+
observableProto.publish = function (selector) {
|
3748
|
+
return selector && isFunction(selector) ?
|
3749
|
+
this.multicast(function () { return new Subject(); }, selector) :
|
3750
|
+
this.multicast(new Subject());
|
3751
|
+
};
|
3788
3752
|
|
3789
|
-
|
3790
|
-
|
3791
|
-
|
3792
|
-
|
3793
|
-
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
3797
|
-
|
3798
|
-
|
3799
|
-
|
3800
|
-
|
3753
|
+
/**
|
3754
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence.
|
3755
|
+
* 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.
|
3756
|
+
*
|
3757
|
+
* @example
|
3758
|
+
* var res = source.share();
|
3759
|
+
*
|
3760
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
3761
|
+
*/
|
3762
|
+
observableProto.share = function () {
|
3763
|
+
return this.publish().refCount();
|
3764
|
+
};
|
3801
3765
|
|
3802
|
-
|
3803
|
-
|
3804
|
-
|
3805
|
-
|
3806
|
-
|
3807
|
-
|
3808
|
-
|
3809
|
-
|
3810
|
-
|
3811
|
-
|
3812
|
-
|
3813
|
-
|
3814
|
-
|
3815
|
-
|
3816
|
-
|
3817
|
-
|
3818
|
-
}, selector);
|
3819
|
-
};
|
3766
|
+
/**
|
3767
|
+
* 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.
|
3768
|
+
* This operator is a specialization of Multicast using a AsyncSubject.
|
3769
|
+
*
|
3770
|
+
* @example
|
3771
|
+
* var res = source.publishLast();
|
3772
|
+
* var res = source.publishLast(function (x) { return x; });
|
3773
|
+
*
|
3774
|
+
* @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.
|
3775
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
3776
|
+
*/
|
3777
|
+
observableProto.publishLast = function (selector) {
|
3778
|
+
return selector && isFunction(selector) ?
|
3779
|
+
this.multicast(function () { return new AsyncSubject(); }, selector) :
|
3780
|
+
this.multicast(new AsyncSubject());
|
3781
|
+
};
|
3820
3782
|
|
3821
|
-
|
3822
|
-
|
3823
|
-
|
3824
|
-
|
3825
|
-
|
3826
|
-
|
3827
|
-
|
3828
|
-
|
3829
|
-
|
3830
|
-
|
3831
|
-
|
3832
|
-
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
3837
|
-
|
3838
|
-
|
3839
|
-
|
3783
|
+
/**
|
3784
|
+
* 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.
|
3785
|
+
* This operator is a specialization of Multicast using a BehaviorSubject.
|
3786
|
+
*
|
3787
|
+
* @example
|
3788
|
+
* var res = source.publishValue(42);
|
3789
|
+
* var res = source.publishValue(function (x) { return x.select(function (y) { return y * y; }) }, 42);
|
3790
|
+
*
|
3791
|
+
* @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.
|
3792
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
3793
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
3794
|
+
*/
|
3795
|
+
observableProto.publishValue = function (initialValueOrSelector, initialValue) {
|
3796
|
+
return arguments.length === 2 ?
|
3797
|
+
this.multicast(function () {
|
3798
|
+
return new BehaviorSubject(initialValue);
|
3799
|
+
}, initialValueOrSelector) :
|
3800
|
+
this.multicast(new BehaviorSubject(initialValueOrSelector));
|
3801
|
+
};
|
3840
3802
|
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
|
3845
|
-
|
3846
|
-
|
3847
|
-
|
3848
|
-
|
3849
|
-
|
3850
|
-
|
3851
|
-
|
3852
|
-
|
3853
|
-
|
3854
|
-
};
|
3803
|
+
/**
|
3804
|
+
* Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
|
3805
|
+
* 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.
|
3806
|
+
*
|
3807
|
+
* @example
|
3808
|
+
* var res = source.shareValue(42);
|
3809
|
+
*
|
3810
|
+
* @param {Mixed} initialValue Initial value received by observers upon subscription.
|
3811
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
|
3812
|
+
*/
|
3813
|
+
observableProto.shareValue = function (initialValue) {
|
3814
|
+
return this.publishValue(initialValue).refCount();
|
3815
|
+
};
|
3855
3816
|
|
3856
|
-
|
3857
|
-
|
3858
|
-
|
3859
|
-
|
3860
|
-
|
3861
|
-
|
3862
|
-
|
3863
|
-
|
3864
|
-
|
3865
|
-
|
3866
|
-
|
3867
|
-
|
3868
|
-
|
3869
|
-
|
3870
|
-
|
3871
|
-
|
3872
|
-
|
3873
|
-
|
3874
|
-
|
3875
|
-
|
3876
|
-
|
3877
|
-
}, selector);
|
3878
|
-
};
|
3817
|
+
/**
|
3818
|
+
* 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.
|
3819
|
+
* This operator is a specialization of Multicast using a ReplaySubject.
|
3820
|
+
*
|
3821
|
+
* @example
|
3822
|
+
* var res = source.replay(null, 3);
|
3823
|
+
* var res = source.replay(null, 3, 500);
|
3824
|
+
* var res = source.replay(null, 3, 500, scheduler);
|
3825
|
+
* var res = source.replay(function (x) { return x.take(6).repeat(); }, 3, 500, scheduler);
|
3826
|
+
*
|
3827
|
+
* @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.
|
3828
|
+
* @param bufferSize [Optional] Maximum element count of the replay buffer.
|
3829
|
+
* @param window [Optional] Maximum time length of the replay buffer.
|
3830
|
+
* @param scheduler [Optional] Scheduler where connected observers within the selector function will be invoked on.
|
3831
|
+
* @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
|
3832
|
+
*/
|
3833
|
+
observableProto.replay = function (selector, bufferSize, window, scheduler) {
|
3834
|
+
return selector && isFunction(selector) ?
|
3835
|
+
this.multicast(function () { return new ReplaySubject(bufferSize, window, scheduler); }, selector) :
|
3836
|
+
this.multicast(new ReplaySubject(bufferSize, window, scheduler));
|
3837
|
+
};
|
3879
3838
|
|
3880
3839
|
/**
|
3881
3840
|
* 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.
|
@@ -3995,18 +3954,6 @@ if (!Array.prototype.forEach) {
|
|
3995
3954
|
|
3996
3955
|
/**
|
3997
3956
|
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
3998
|
-
*
|
3999
|
-
* @example
|
4000
|
-
* 1 - res = Rx.Observable.timer(new Date());
|
4001
|
-
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
4002
|
-
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
4003
|
-
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
4004
|
-
*
|
4005
|
-
* 5 - res = Rx.Observable.timer(5000);
|
4006
|
-
* 6 - res = Rx.Observable.timer(5000, 1000);
|
4007
|
-
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
4008
|
-
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
4009
|
-
*
|
4010
3957
|
* @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.
|
4011
3958
|
* @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.
|
4012
3959
|
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
@@ -4017,7 +3964,7 @@ if (!Array.prototype.forEach) {
|
|
4017
3964
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4018
3965
|
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
4019
3966
|
period = periodOrScheduler;
|
4020
|
-
} else if (periodOrScheduler
|
3967
|
+
} else if (isScheduler(periodOrScheduler)) {
|
4021
3968
|
scheduler = periodOrScheduler;
|
4022
3969
|
}
|
4023
3970
|
if (dueTime instanceof Date && period === undefined) {
|
@@ -4136,7 +4083,37 @@ if (!Array.prototype.forEach) {
|
|
4136
4083
|
*/
|
4137
4084
|
observableProto.throttle = function (dueTime, scheduler) {
|
4138
4085
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4139
|
-
|
4086
|
+
var source = this;
|
4087
|
+
return new AnonymousObservable(function (observer) {
|
4088
|
+
var cancelable = new SerialDisposable(), hasvalue = false, value, id = 0;
|
4089
|
+
var subscription = source.subscribe(
|
4090
|
+
function (x) {
|
4091
|
+
hasvalue = true;
|
4092
|
+
value = x;
|
4093
|
+
id++;
|
4094
|
+
var currentId = id,
|
4095
|
+
d = new SingleAssignmentDisposable();
|
4096
|
+
cancelable.setDisposable(d);
|
4097
|
+
d.setDisposable(scheduler.scheduleWithRelative(dueTime, function () {
|
4098
|
+
hasValue && id === currentId && observer.onNext(value);
|
4099
|
+
hasvalue = false;
|
4100
|
+
}));
|
4101
|
+
},
|
4102
|
+
function (e) {
|
4103
|
+
cancelable.dispose();
|
4104
|
+
observer.onError(e);
|
4105
|
+
hasvalue = false;
|
4106
|
+
id++;
|
4107
|
+
},
|
4108
|
+
function () {
|
4109
|
+
cancelable.dispose();
|
4110
|
+
hasvalue && observer.onNext(value);
|
4111
|
+
observer.onCompleted();
|
4112
|
+
hasvalue = false;
|
4113
|
+
id++;
|
4114
|
+
});
|
4115
|
+
return new CompositeDisposable(subscription, cancelable);
|
4116
|
+
});
|
4140
4117
|
};
|
4141
4118
|
|
4142
4119
|
/**
|
@@ -4201,16 +4178,7 @@ if (!Array.prototype.forEach) {
|
|
4201
4178
|
};
|
4202
4179
|
|
4203
4180
|
/**
|
4204
|
-
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
4205
|
-
*
|
4206
|
-
* @example
|
4207
|
-
* 1 - res = source.timeout(new Date()); // As a date
|
4208
|
-
* 2 - res = source.timeout(5000); // 5 seconds
|
4209
|
-
* 3 - res = source.timeout(new Date(), Rx.Observable.returnValue(42)); // As a date and timeout observable
|
4210
|
-
* 4 - res = source.timeout(5000, Rx.Observable.returnValue(42)); // 5 seconds and timeout observable
|
4211
|
-
* 5 - res = source.timeout(new Date(), Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // As a date and timeout observable
|
4212
|
-
* 6 - res = source.timeout(5000, Rx.Observable.returnValue(42), Rx.Scheduler.timeout); // 5 seconds and timeout observable
|
4213
|
-
*
|
4181
|
+
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
4214
4182
|
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
|
4215
4183
|
* @param {Observable} [other] Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.
|
4216
4184
|
* @param {Scheduler} [scheduler] Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
|
@@ -4233,7 +4201,7 @@ if (!Array.prototype.forEach) {
|
|
4233
4201
|
|
4234
4202
|
subscription.setDisposable(original);
|
4235
4203
|
|
4236
|
-
|
4204
|
+
function createTimer() {
|
4237
4205
|
var myId = id;
|
4238
4206
|
timer.setDisposable(scheduler[schedulerMethod](dueTime, function () {
|
4239
4207
|
if (id === myId) {
|
@@ -4241,7 +4209,7 @@ if (!Array.prototype.forEach) {
|
|
4241
4209
|
subscription.setDisposable(other.subscribe(observer));
|
4242
4210
|
}
|
4243
4211
|
}));
|
4244
|
-
}
|
4212
|
+
}
|
4245
4213
|
|
4246
4214
|
createTimer();
|
4247
4215
|
|
@@ -4344,143 +4312,6 @@ if (!Array.prototype.forEach) {
|
|
4344
4312
|
});
|
4345
4313
|
};
|
4346
4314
|
|
4347
|
-
/**
|
4348
|
-
* Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
|
4349
|
-
*
|
4350
|
-
* @example
|
4351
|
-
* 1 - res = source.timeoutWithSelector(Rx.Observable.timer(500));
|
4352
|
-
* 2 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); });
|
4353
|
-
* 3 - res = source.timeoutWithSelector(Rx.Observable.timer(500), function (x) { return Rx.Observable.timer(200); }, Rx.Observable.returnValue(42));
|
4354
|
-
*
|
4355
|
-
* @param {Observable} [firstTimeout] Observable sequence that represents the timeout for the first element. If not provided, this defaults to Observable.never().
|
4356
|
-
* @param {Function} [timeoutDurationSelector] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.
|
4357
|
-
* @param {Observable} [other] Sequence to return in case of a timeout. If not provided, this is set to Observable.throwException().
|
4358
|
-
* @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
|
4359
|
-
*/
|
4360
|
-
observableProto.timeoutWithSelector = function (firstTimeout, timeoutdurationSelector, other) {
|
4361
|
-
if (arguments.length === 1) {
|
4362
|
-
timeoutdurationSelector = firstTimeout;
|
4363
|
-
var firstTimeout = observableNever();
|
4364
|
-
}
|
4365
|
-
other || (other = observableThrow(new Error('Timeout')));
|
4366
|
-
var source = this;
|
4367
|
-
return new AnonymousObservable(function (observer) {
|
4368
|
-
var subscription = new SerialDisposable(), timer = new SerialDisposable(), original = new SingleAssignmentDisposable();
|
4369
|
-
|
4370
|
-
subscription.setDisposable(original);
|
4371
|
-
|
4372
|
-
var id = 0, switched = false, setTimer = function (timeout) {
|
4373
|
-
var myId = id, timerWins = function () {
|
4374
|
-
return id === myId;
|
4375
|
-
};
|
4376
|
-
var d = new SingleAssignmentDisposable();
|
4377
|
-
timer.setDisposable(d);
|
4378
|
-
d.setDisposable(timeout.subscribe(function () {
|
4379
|
-
if (timerWins()) {
|
4380
|
-
subscription.setDisposable(other.subscribe(observer));
|
4381
|
-
}
|
4382
|
-
d.dispose();
|
4383
|
-
}, function (e) {
|
4384
|
-
if (timerWins()) {
|
4385
|
-
observer.onError(e);
|
4386
|
-
}
|
4387
|
-
}, function () {
|
4388
|
-
if (timerWins()) {
|
4389
|
-
subscription.setDisposable(other.subscribe(observer));
|
4390
|
-
}
|
4391
|
-
}));
|
4392
|
-
};
|
4393
|
-
|
4394
|
-
setTimer(firstTimeout);
|
4395
|
-
var observerWins = function () {
|
4396
|
-
var res = !switched;
|
4397
|
-
if (res) {
|
4398
|
-
id++;
|
4399
|
-
}
|
4400
|
-
return res;
|
4401
|
-
};
|
4402
|
-
|
4403
|
-
original.setDisposable(source.subscribe(function (x) {
|
4404
|
-
if (observerWins()) {
|
4405
|
-
observer.onNext(x);
|
4406
|
-
var timeout;
|
4407
|
-
try {
|
4408
|
-
timeout = timeoutdurationSelector(x);
|
4409
|
-
} catch (e) {
|
4410
|
-
observer.onError(e);
|
4411
|
-
return;
|
4412
|
-
}
|
4413
|
-
setTimer(timeout);
|
4414
|
-
}
|
4415
|
-
}, function (e) {
|
4416
|
-
if (observerWins()) {
|
4417
|
-
observer.onError(e);
|
4418
|
-
}
|
4419
|
-
}, function () {
|
4420
|
-
if (observerWins()) {
|
4421
|
-
observer.onCompleted();
|
4422
|
-
}
|
4423
|
-
}));
|
4424
|
-
return new CompositeDisposable(subscription, timer);
|
4425
|
-
});
|
4426
|
-
};
|
4427
|
-
|
4428
|
-
/**
|
4429
|
-
* Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
|
4430
|
-
*
|
4431
|
-
* @example
|
4432
|
-
* 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
|
4433
|
-
*
|
4434
|
-
* @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
|
4435
|
-
* @returns {Observable} The throttled sequence.
|
4436
|
-
*/
|
4437
|
-
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
4438
|
-
var source = this;
|
4439
|
-
return new AnonymousObservable(function (observer) {
|
4440
|
-
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
|
4441
|
-
var throttle;
|
4442
|
-
try {
|
4443
|
-
throttle = throttleDurationSelector(x);
|
4444
|
-
} catch (e) {
|
4445
|
-
observer.onError(e);
|
4446
|
-
return;
|
4447
|
-
}
|
4448
|
-
hasValue = true;
|
4449
|
-
value = x;
|
4450
|
-
id++;
|
4451
|
-
var currentid = id, d = new SingleAssignmentDisposable();
|
4452
|
-
cancelable.setDisposable(d);
|
4453
|
-
d.setDisposable(throttle.subscribe(function () {
|
4454
|
-
if (hasValue && id === currentid) {
|
4455
|
-
observer.onNext(value);
|
4456
|
-
}
|
4457
|
-
hasValue = false;
|
4458
|
-
d.dispose();
|
4459
|
-
}, observer.onError.bind(observer), function () {
|
4460
|
-
if (hasValue && id === currentid) {
|
4461
|
-
observer.onNext(value);
|
4462
|
-
}
|
4463
|
-
hasValue = false;
|
4464
|
-
d.dispose();
|
4465
|
-
}));
|
4466
|
-
}, function (e) {
|
4467
|
-
cancelable.dispose();
|
4468
|
-
observer.onError(e);
|
4469
|
-
hasValue = false;
|
4470
|
-
id++;
|
4471
|
-
}, function () {
|
4472
|
-
cancelable.dispose();
|
4473
|
-
if (hasValue) {
|
4474
|
-
observer.onNext(value);
|
4475
|
-
}
|
4476
|
-
observer.onCompleted();
|
4477
|
-
hasValue = false;
|
4478
|
-
id++;
|
4479
|
-
});
|
4480
|
-
return new CompositeDisposable(subscription, cancelable);
|
4481
|
-
});
|
4482
|
-
};
|
4483
|
-
|
4484
4315
|
/**
|
4485
4316
|
* Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
4486
4317
|
*
|
@@ -4518,9 +4349,6 @@ if (!Array.prototype.forEach) {
|
|
4518
4349
|
|
4519
4350
|
/**
|
4520
4351
|
* 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.
|
4521
|
-
*
|
4522
|
-
* @example
|
4523
|
-
* 1 - res = source.takeLastWithTime(5000, [optional timer scheduler], [optional loop scheduler]);
|
4524
4352
|
* @description
|
4525
4353
|
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
4526
4354
|
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
@@ -4534,7 +4362,6 @@ if (!Array.prototype.forEach) {
|
|
4534
4362
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4535
4363
|
return new AnonymousObservable(function (observer) {
|
4536
4364
|
var q = [];
|
4537
|
-
|
4538
4365
|
return source.subscribe(function (x) {
|
4539
4366
|
var now = scheduler.now();
|
4540
4367
|
q.push({ interval: now, value: x });
|
@@ -4545,11 +4372,8 @@ if (!Array.prototype.forEach) {
|
|
4545
4372
|
var now = scheduler.now();
|
4546
4373
|
while (q.length > 0) {
|
4547
4374
|
var next = q.shift();
|
4548
|
-
if (now - next.interval <= duration) {
|
4549
|
-
observer.onNext(next.value);
|
4550
|
-
}
|
4375
|
+
if (now - next.interval <= duration) { observer.onNext(next.value); }
|
4551
4376
|
}
|
4552
|
-
|
4553
4377
|
observer.onCompleted();
|
4554
4378
|
});
|
4555
4379
|
});
|
@@ -4721,6 +4545,7 @@ if (!Array.prototype.forEach) {
|
|
4721
4545
|
.subscribe(
|
4722
4546
|
function (results) {
|
4723
4547
|
if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
|
4548
|
+
previousShouldFire = results.shouldFire;
|
4724
4549
|
// change in shouldFire
|
4725
4550
|
if (results.shouldFire) {
|
4726
4551
|
while (q.length > 0) {
|
@@ -4728,6 +4553,7 @@ if (!Array.prototype.forEach) {
|
|
4728
4553
|
}
|
4729
4554
|
}
|
4730
4555
|
} else {
|
4556
|
+
previousShouldFire = results.shouldFire;
|
4731
4557
|
// new data
|
4732
4558
|
if (results.shouldFire) {
|
4733
4559
|
observer.onNext(results.data);
|
@@ -4735,9 +4561,7 @@ if (!Array.prototype.forEach) {
|
|
4735
4561
|
q.push(results.data);
|
4736
4562
|
}
|
4737
4563
|
}
|
4738
|
-
|
4739
|
-
|
4740
|
-
},
|
4564
|
+
},
|
4741
4565
|
function (err) {
|
4742
4566
|
// Empty buffer before sending error
|
4743
4567
|
while (q.length > 0) {
|
@@ -5445,267 +5269,247 @@ if (!Array.prototype.forEach) {
|
|
5445
5269
|
return AnonymousSubject;
|
5446
5270
|
}(Observable));
|
5447
5271
|
|
5448
|
-
|
5449
|
-
|
5450
|
-
|
5451
|
-
|
5452
|
-
|
5453
|
-
|
5454
|
-
|
5455
|
-
|
5456
|
-
|
5457
|
-
|
5458
|
-
|
5459
|
-
|
5460
|
-
|
5461
|
-
|
5462
|
-
|
5463
|
-
|
5464
|
-
|
5465
|
-
|
5466
|
-
|
5467
|
-
|
5272
|
+
/**
|
5273
|
+
* Represents a value that changes over time.
|
5274
|
+
* Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
|
5275
|
+
*/
|
5276
|
+
var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
|
5277
|
+
function subscribe(observer) {
|
5278
|
+
checkDisposed.call(this);
|
5279
|
+
if (!this.isStopped) {
|
5280
|
+
this.observers.push(observer);
|
5281
|
+
observer.onNext(this.value);
|
5282
|
+
return new InnerSubscription(this, observer);
|
5283
|
+
}
|
5284
|
+
var ex = this.exception;
|
5285
|
+
if (ex) {
|
5286
|
+
observer.onError(ex);
|
5287
|
+
} else {
|
5288
|
+
observer.onCompleted();
|
5289
|
+
}
|
5290
|
+
return disposableEmpty;
|
5291
|
+
}
|
5468
5292
|
|
5469
|
-
|
5293
|
+
inherits(BehaviorSubject, __super__);
|
5470
5294
|
|
5471
|
-
|
5472
|
-
|
5473
|
-
|
5474
|
-
|
5475
|
-
|
5476
|
-
|
5477
|
-
|
5295
|
+
/**
|
5296
|
+
* @constructor
|
5297
|
+
* Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value.
|
5298
|
+
* @param {Mixed} value Initial value sent to observers when no other value has been received by the subject yet.
|
5299
|
+
*/
|
5300
|
+
function BehaviorSubject(value) {
|
5301
|
+
__super__.call(this, subscribe);
|
5302
|
+
this.value = value,
|
5303
|
+
this.observers = [],
|
5304
|
+
this.isDisposed = false,
|
5305
|
+
this.isStopped = false,
|
5306
|
+
this.exception = null;
|
5307
|
+
}
|
5478
5308
|
|
5479
|
-
|
5480
|
-
|
5481
|
-
|
5482
|
-
|
5483
|
-
|
5309
|
+
addProperties(BehaviorSubject.prototype, Observer, {
|
5310
|
+
/**
|
5311
|
+
* Indicates whether the subject has observers subscribed to it.
|
5312
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5313
|
+
*/
|
5314
|
+
hasObservers: function () {
|
5315
|
+
return this.observers.length > 0;
|
5316
|
+
},
|
5317
|
+
/**
|
5318
|
+
* Notifies all subscribed observers about the end of the sequence.
|
5319
|
+
*/
|
5320
|
+
onCompleted: function () {
|
5321
|
+
checkDisposed.call(this);
|
5322
|
+
if (this.isStopped) { return; }
|
5323
|
+
this.isStopped = true;
|
5324
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5325
|
+
os[i].onCompleted();
|
5484
5326
|
}
|
5485
5327
|
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
|
5495
|
-
|
5496
|
-
|
5497
|
-
onCompleted: function () {
|
5498
|
-
checkDisposed.call(this);
|
5499
|
-
if (!this.isStopped) {
|
5500
|
-
var os = this.observers.slice(0);
|
5501
|
-
this.isStopped = true;
|
5502
|
-
for (var i = 0, len = os.length; i < len; i++) {
|
5503
|
-
os[i].onCompleted();
|
5504
|
-
}
|
5505
|
-
|
5506
|
-
this.observers = [];
|
5507
|
-
}
|
5508
|
-
},
|
5509
|
-
/**
|
5510
|
-
* Notifies all subscribed observers about the exception.
|
5511
|
-
* @param {Mixed} error The exception to send to all observers.
|
5512
|
-
*/
|
5513
|
-
onError: function (error) {
|
5514
|
-
checkDisposed.call(this);
|
5515
|
-
if (!this.isStopped) {
|
5516
|
-
var os = this.observers.slice(0);
|
5517
|
-
this.isStopped = true;
|
5518
|
-
this.exception = error;
|
5328
|
+
this.observers = [];
|
5329
|
+
},
|
5330
|
+
/**
|
5331
|
+
* Notifies all subscribed observers about the exception.
|
5332
|
+
* @param {Mixed} error The exception to send to all observers.
|
5333
|
+
*/
|
5334
|
+
onError: function (error) {
|
5335
|
+
checkDisposed.call(this);
|
5336
|
+
if (this.isStopped) { return; }
|
5337
|
+
this.isStopped = true;
|
5338
|
+
this.exception = error;
|
5519
5339
|
|
5520
|
-
|
5521
|
-
|
5522
|
-
|
5340
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5341
|
+
os[i].onError(error);
|
5342
|
+
}
|
5523
5343
|
|
5524
|
-
|
5525
|
-
|
5526
|
-
|
5527
|
-
|
5528
|
-
|
5529
|
-
|
5530
|
-
|
5531
|
-
|
5532
|
-
|
5533
|
-
|
5534
|
-
|
5535
|
-
|
5536
|
-
|
5537
|
-
|
5538
|
-
|
5539
|
-
|
5540
|
-
|
5541
|
-
|
5542
|
-
|
5543
|
-
|
5544
|
-
|
5545
|
-
|
5546
|
-
|
5547
|
-
|
5548
|
-
this.exception = null;
|
5549
|
-
}
|
5550
|
-
});
|
5344
|
+
this.observers = [];
|
5345
|
+
},
|
5346
|
+
/**
|
5347
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5348
|
+
* @param {Mixed} value The value to send to all observers.
|
5349
|
+
*/
|
5350
|
+
onNext: function (value) {
|
5351
|
+
checkDisposed.call(this);
|
5352
|
+
if (this.isStopped) { return; }
|
5353
|
+
this.value = value;
|
5354
|
+
for (var i = 0, os = this.observers.slice(0), len = os.length; i < len; i++) {
|
5355
|
+
os[i].onNext(value);
|
5356
|
+
}
|
5357
|
+
},
|
5358
|
+
/**
|
5359
|
+
* Unsubscribe all observers and release resources.
|
5360
|
+
*/
|
5361
|
+
dispose: function () {
|
5362
|
+
this.isDisposed = true;
|
5363
|
+
this.observers = null;
|
5364
|
+
this.value = null;
|
5365
|
+
this.exception = null;
|
5366
|
+
}
|
5367
|
+
});
|
5551
5368
|
|
5552
|
-
|
5553
|
-
|
5369
|
+
return BehaviorSubject;
|
5370
|
+
}(Observable));
|
5554
5371
|
|
5555
|
-
|
5556
|
-
|
5557
|
-
|
5558
|
-
|
5559
|
-
|
5372
|
+
/**
|
5373
|
+
* Represents an object that is both an observable sequence as well as an observer.
|
5374
|
+
* Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.
|
5375
|
+
*/
|
5376
|
+
var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
|
5560
5377
|
|
5561
|
-
|
5562
|
-
|
5563
|
-
|
5564
|
-
|
5378
|
+
function createRemovableDisposable(subject, observer) {
|
5379
|
+
return disposableCreate(function () {
|
5380
|
+
observer.dispose();
|
5381
|
+
!subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
|
5382
|
+
});
|
5383
|
+
}
|
5565
5384
|
|
5566
|
-
|
5567
|
-
|
5568
|
-
|
5569
|
-
|
5570
|
-
|
5571
|
-
|
5572
|
-
};
|
5385
|
+
function subscribe(observer) {
|
5386
|
+
var so = new ScheduledObserver(this.scheduler, observer),
|
5387
|
+
subscription = createRemovableDisposable(this, so);
|
5388
|
+
checkDisposed.call(this);
|
5389
|
+
this._trim(this.scheduler.now());
|
5390
|
+
this.observers.push(so);
|
5573
5391
|
|
5574
|
-
|
5575
|
-
var so = new ScheduledObserver(this.scheduler, observer),
|
5576
|
-
subscription = new RemovableDisposable(this, so);
|
5577
|
-
checkDisposed.call(this);
|
5578
|
-
this._trim(this.scheduler.now());
|
5579
|
-
this.observers.push(so);
|
5392
|
+
var n = this.q.length;
|
5580
5393
|
|
5581
|
-
|
5394
|
+
for (var i = 0, len = this.q.length; i < len; i++) {
|
5395
|
+
so.onNext(this.q[i].value);
|
5396
|
+
}
|
5582
5397
|
|
5583
|
-
|
5584
|
-
|
5585
|
-
|
5398
|
+
if (this.hasError) {
|
5399
|
+
n++;
|
5400
|
+
so.onError(this.error);
|
5401
|
+
} else if (this.isStopped) {
|
5402
|
+
n++;
|
5403
|
+
so.onCompleted();
|
5404
|
+
}
|
5586
5405
|
|
5587
|
-
|
5588
|
-
|
5589
|
-
|
5590
|
-
} else if (this.isStopped) {
|
5591
|
-
n++;
|
5592
|
-
so.onCompleted();
|
5593
|
-
}
|
5406
|
+
so.ensureActive(n);
|
5407
|
+
return subscription;
|
5408
|
+
}
|
5594
5409
|
|
5595
|
-
|
5596
|
-
return subscription;
|
5597
|
-
}
|
5410
|
+
inherits(ReplaySubject, __super__);
|
5598
5411
|
|
5599
|
-
|
5412
|
+
/**
|
5413
|
+
* Initializes a new instance of the ReplaySubject class with the specified buffer size, window size and scheduler.
|
5414
|
+
* @param {Number} [bufferSize] Maximum element count of the replay buffer.
|
5415
|
+
* @param {Number} [windowSize] Maximum time length of the replay buffer.
|
5416
|
+
* @param {Scheduler} [scheduler] Scheduler the observers are invoked on.
|
5417
|
+
*/
|
5418
|
+
function ReplaySubject(bufferSize, windowSize, scheduler) {
|
5419
|
+
this.bufferSize = bufferSize == null ? Number.MAX_VALUE : bufferSize;
|
5420
|
+
this.windowSize = windowSize == null ? Number.MAX_VALUE : windowSize;
|
5421
|
+
this.scheduler = scheduler || currentThreadScheduler;
|
5422
|
+
this.q = [];
|
5423
|
+
this.observers = [];
|
5424
|
+
this.isStopped = false;
|
5425
|
+
this.isDisposed = false;
|
5426
|
+
this.hasError = false;
|
5427
|
+
this.error = null;
|
5428
|
+
__super__.call(this, subscribe);
|
5429
|
+
}
|
5600
5430
|
|
5601
|
-
|
5602
|
-
|
5603
|
-
|
5604
|
-
|
5605
|
-
|
5606
|
-
|
5607
|
-
|
5608
|
-
|
5609
|
-
|
5610
|
-
|
5611
|
-
|
5612
|
-
|
5613
|
-
|
5614
|
-
|
5615
|
-
this.hasError = false;
|
5616
|
-
this.error = null;
|
5617
|
-
_super.call(this, subscribe);
|
5431
|
+
addProperties(ReplaySubject.prototype, Observer, {
|
5432
|
+
/**
|
5433
|
+
* Indicates whether the subject has observers subscribed to it.
|
5434
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
5435
|
+
*/
|
5436
|
+
hasObservers: function () {
|
5437
|
+
return this.observers.length > 0;
|
5438
|
+
},
|
5439
|
+
_trim: function (now) {
|
5440
|
+
while (this.q.length > this.bufferSize) {
|
5441
|
+
this.q.shift();
|
5442
|
+
}
|
5443
|
+
while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
5444
|
+
this.q.shift();
|
5618
5445
|
}
|
5446
|
+
},
|
5447
|
+
/**
|
5448
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
5449
|
+
* @param {Mixed} value The value to send to all observers.
|
5450
|
+
*/
|
5451
|
+
onNext: function (value) {
|
5452
|
+
checkDisposed.call(this);
|
5453
|
+
if (this.isStopped) { return; }
|
5454
|
+
var now = this.scheduler.now();
|
5455
|
+
this.q.push({ interval: now, value: value });
|
5456
|
+
this._trim(now);
|
5619
5457
|
|
5620
|
-
|
5621
|
-
|
5622
|
-
|
5623
|
-
|
5624
|
-
|
5625
|
-
|
5626
|
-
|
5627
|
-
|
5628
|
-
|
5629
|
-
|
5630
|
-
|
5631
|
-
|
5632
|
-
|
5633
|
-
|
5634
|
-
|
5635
|
-
|
5636
|
-
|
5637
|
-
|
5638
|
-
|
5639
|
-
|
5640
|
-
|
5641
|
-
|
5642
|
-
|
5643
|
-
|
5644
|
-
|
5645
|
-
|
5646
|
-
|
5647
|
-
|
5648
|
-
|
5649
|
-
|
5650
|
-
|
5651
|
-
|
5652
|
-
|
5653
|
-
|
5654
|
-
|
5655
|
-
|
5656
|
-
|
5657
|
-
|
5658
|
-
|
5659
|
-
|
5660
|
-
|
5661
|
-
|
5662
|
-
|
5663
|
-
|
5664
|
-
|
5665
|
-
|
5666
|
-
|
5667
|
-
|
5668
|
-
|
5669
|
-
|
5670
|
-
|
5671
|
-
|
5672
|
-
observer = o[i];
|
5673
|
-
observer.onError(error);
|
5674
|
-
observer.ensureActive();
|
5675
|
-
}
|
5676
|
-
this.observers = [];
|
5677
|
-
}
|
5678
|
-
},
|
5679
|
-
/**
|
5680
|
-
* Notifies all subscribed observers about the end of the sequence.
|
5681
|
-
*/
|
5682
|
-
onCompleted: function () {
|
5683
|
-
var observer;
|
5684
|
-
checkDisposed.call(this);
|
5685
|
-
if (!this.isStopped) {
|
5686
|
-
this.isStopped = true;
|
5687
|
-
var now = this.scheduler.now();
|
5688
|
-
this._trim(now);
|
5689
|
-
var o = this.observers.slice(0);
|
5690
|
-
for (var i = 0, len = o.length; i < len; i++) {
|
5691
|
-
observer = o[i];
|
5692
|
-
observer.onCompleted();
|
5693
|
-
observer.ensureActive();
|
5694
|
-
}
|
5695
|
-
this.observers = [];
|
5696
|
-
}
|
5697
|
-
},
|
5698
|
-
/**
|
5699
|
-
* Unsubscribe all observers and release resources.
|
5700
|
-
*/
|
5701
|
-
dispose: function () {
|
5702
|
-
this.isDisposed = true;
|
5703
|
-
this.observers = null;
|
5704
|
-
}
|
5705
|
-
});
|
5458
|
+
var o = this.observers.slice(0);
|
5459
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
5460
|
+
var observer = o[i];
|
5461
|
+
observer.onNext(value);
|
5462
|
+
observer.ensureActive();
|
5463
|
+
}
|
5464
|
+
},
|
5465
|
+
/**
|
5466
|
+
* Notifies all subscribed observers about the exception.
|
5467
|
+
* @param {Mixed} error The exception to send to all observers.
|
5468
|
+
*/
|
5469
|
+
onError: function (error) {
|
5470
|
+
checkDisposed.call(this);
|
5471
|
+
if (this.isStopped) { return; }
|
5472
|
+
this.isStopped = true;
|
5473
|
+
this.error = error;
|
5474
|
+
this.hasError = true;
|
5475
|
+
var now = this.scheduler.now();
|
5476
|
+
this._trim(now);
|
5477
|
+
var o = this.observers.slice(0);
|
5478
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
5479
|
+
var observer = o[i];
|
5480
|
+
observer.onError(error);
|
5481
|
+
observer.ensureActive();
|
5482
|
+
}
|
5483
|
+
this.observers = [];
|
5484
|
+
},
|
5485
|
+
/**
|
5486
|
+
* Notifies all subscribed observers about the end of the sequence.
|
5487
|
+
*/
|
5488
|
+
onCompleted: function () {
|
5489
|
+
checkDisposed.call(this);
|
5490
|
+
if (this.isStopped) { return; }
|
5491
|
+
this.isStopped = true;
|
5492
|
+
var now = this.scheduler.now();
|
5493
|
+
this._trim(now);
|
5494
|
+
var o = this.observers.slice(0);
|
5495
|
+
for (var i = 0, len = o.length; i < len; i++) {
|
5496
|
+
var observer = o[i];
|
5497
|
+
observer.onCompleted();
|
5498
|
+
observer.ensureActive();
|
5499
|
+
}
|
5500
|
+
this.observers = [];
|
5501
|
+
},
|
5502
|
+
/**
|
5503
|
+
* Unsubscribe all observers and release resources.
|
5504
|
+
*/
|
5505
|
+
dispose: function () {
|
5506
|
+
this.isDisposed = true;
|
5507
|
+
this.observers = null;
|
5508
|
+
}
|
5509
|
+
});
|
5706
5510
|
|
5707
|
-
|
5708
|
-
|
5511
|
+
return ReplaySubject;
|
5512
|
+
}(Observable));
|
5709
5513
|
|
5710
5514
|
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
5711
5515
|
root.Rx = Rx;
|