rxjs-rails 2.5.2 → 3.1.0
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 +367 -284
- data/vendor/assets/javascripts/rx.aggregates.map +1 -1
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +2405 -2438
- data/vendor/assets/javascripts/rx.all.compat.map +1 -1
- data/vendor/assets/javascripts/rx.all.compat.min.js +4 -4
- data/vendor/assets/javascripts/rx.all.js +2380 -2395
- data/vendor/assets/javascripts/rx.all.map +1 -1
- data/vendor/assets/javascripts/rx.all.min.js +4 -4
- data/vendor/assets/javascripts/rx.async.compat.js +311 -333
- data/vendor/assets/javascripts/rx.async.compat.map +1 -1
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +280 -327
- data/vendor/assets/javascripts/rx.async.map +1 -1
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.js +208 -176
- data/vendor/assets/javascripts/rx.backpressure.map +1 -1
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +44 -27
- data/vendor/assets/javascripts/rx.binding.map +1 -1
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.js +220 -453
- data/vendor/assets/javascripts/rx.coincidence.map +1 -1
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +1366 -1173
- data/vendor/assets/javascripts/rx.compat.map +1 -1
- data/vendor/assets/javascripts/rx.compat.min.js +3 -2
- data/vendor/assets/javascripts/rx.core.binding.js +823 -0
- data/vendor/assets/javascripts/rx.core.binding.map +1 -0
- data/vendor/assets/javascripts/rx.core.binding.min.js +3 -0
- data/vendor/assets/javascripts/rx.core.js +1281 -0
- data/vendor/assets/javascripts/rx.core.map +1 -0
- data/vendor/assets/javascripts/rx.core.min.js +3 -0
- data/vendor/assets/javascripts/rx.core.testing.js +1242 -0
- data/vendor/assets/javascripts/rx.core.testing.map +1 -0
- data/vendor/assets/javascripts/rx.core.testing.min.js +3 -0
- data/vendor/assets/javascripts/rx.experimental.js +85 -123
- data/vendor/assets/javascripts/rx.experimental.map +1 -1
- data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
- data/vendor/assets/javascripts/rx.joinpatterns.js +48 -37
- data/vendor/assets/javascripts/rx.joinpatterns.map +1 -1
- data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
- data/vendor/assets/javascripts/rx.js +1367 -1174
- data/vendor/assets/javascripts/rx.lite.compat.js +1621 -1403
- data/vendor/assets/javascripts/rx.lite.compat.map +1 -1
- data/vendor/assets/javascripts/rx.lite.compat.min.js +3 -3
- data/vendor/assets/javascripts/rx.lite.extras.compat.js +119 -89
- data/vendor/assets/javascripts/rx.lite.extras.compat.map +1 -1
- data/vendor/assets/javascripts/rx.lite.extras.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.extras.js +119 -89
- data/vendor/assets/javascripts/rx.lite.extras.map +1 -1
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +1583 -1390
- data/vendor/assets/javascripts/rx.lite.map +1 -1
- data/vendor/assets/javascripts/rx.lite.min.js +3 -3
- data/vendor/assets/javascripts/rx.map +1 -1
- data/vendor/assets/javascripts/rx.min.js +3 -2
- data/vendor/assets/javascripts/rx.sorting.js +23 -27
- data/vendor/assets/javascripts/rx.sorting.map +1 -1
- data/vendor/assets/javascripts/rx.sorting.min.js +1 -1
- data/vendor/assets/javascripts/rx.testing.js +11 -15
- data/vendor/assets/javascripts/rx.testing.map +1 -1
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +117 -133
- data/vendor/assets/javascripts/rx.time.map +1 -1
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.js +120 -39
- data/vendor/assets/javascripts/rx.virtualtime.map +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
- metadata +12 -3
@@ -3,46 +3,37 @@
|
|
3
3
|
;(function (undefined) {
|
4
4
|
|
5
5
|
var objectTypes = {
|
6
|
-
'boolean': false,
|
7
6
|
'function': true,
|
8
|
-
'object': true
|
9
|
-
'number': false,
|
10
|
-
'string': false,
|
11
|
-
'undefined': false
|
7
|
+
'object': true
|
12
8
|
};
|
13
9
|
|
14
|
-
var
|
10
|
+
var
|
15
11
|
freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports,
|
12
|
+
freeSelf = objectTypes[typeof self] && self.Object && self,
|
13
|
+
freeWindow = objectTypes[typeof window] && window && window.Object && window,
|
16
14
|
freeModule = objectTypes[typeof module] && module && !module.nodeType && module,
|
17
15
|
moduleExports = freeModule && freeModule.exports === freeExports && freeExports,
|
18
|
-
freeGlobal =
|
16
|
+
freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
|
19
17
|
|
20
|
-
|
21
|
-
root = freeGlobal;
|
22
|
-
}
|
18
|
+
var root = root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
|
23
19
|
|
24
20
|
var Rx = {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
internals: {},
|
22
|
+
config: {
|
23
|
+
Promise: root.Promise
|
24
|
+
},
|
25
|
+
helpers: { }
|
30
26
|
};
|
31
27
|
|
32
28
|
// Defaults
|
33
29
|
var noop = Rx.helpers.noop = function () { },
|
34
|
-
notDefined = Rx.helpers.notDefined = function (x) { return typeof x === 'undefined'; },
|
35
30
|
identity = Rx.helpers.identity = function (x) { return x; },
|
36
|
-
pluck = Rx.helpers.pluck = function (property) { return function (x) { return x[property]; }; },
|
37
|
-
just = Rx.helpers.just = function (value) { return function () { return value; }; },
|
38
31
|
defaultNow = Rx.helpers.defaultNow = (function () { return !!Date.now ? Date.now : function () { return +new Date; }; }()),
|
39
32
|
defaultComparer = Rx.helpers.defaultComparer = function (x, y) { return isEqual(x, y); },
|
40
33
|
defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
|
41
34
|
defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
|
42
35
|
defaultError = Rx.helpers.defaultError = function (err) { throw err; },
|
43
|
-
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function'; },
|
44
|
-
asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
|
45
|
-
not = Rx.helpers.not = function (a) { return !a; },
|
36
|
+
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.subscribe !== 'function' && typeof p.then === 'function'; },
|
46
37
|
isFunction = Rx.helpers.isFunction = (function () {
|
47
38
|
|
48
39
|
var isFn = function (value) {
|
@@ -65,45 +56,59 @@
|
|
65
56
|
return a;
|
66
57
|
}
|
67
58
|
|
68
|
-
|
69
|
-
var
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
var errorObj = {e: {}};
|
60
|
+
var tryCatchTarget;
|
61
|
+
function tryCatcher() {
|
62
|
+
try {
|
63
|
+
return tryCatchTarget.apply(this, arguments);
|
64
|
+
} catch (e) {
|
65
|
+
errorObj.e = e;
|
66
|
+
return errorObj;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
function tryCatch(fn) {
|
70
|
+
if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
|
71
|
+
tryCatchTarget = fn;
|
72
|
+
return tryCatcher;
|
73
|
+
}
|
74
|
+
function thrower(e) {
|
75
|
+
throw e;
|
74
76
|
}
|
75
77
|
|
78
|
+
Rx.config.longStackSupport = false;
|
79
|
+
var hasStacks = false, stacks = tryCatch(function () { throw new Error(); })();
|
80
|
+
hasStacks = !!stacks.e && !!stacks.e.stack;
|
81
|
+
|
76
82
|
// All code after this point will be filtered from stack traces reported by RxJS
|
77
83
|
var rStartingLine = captureLine(), rFileName;
|
78
84
|
|
79
|
-
var STACK_JUMP_SEPARATOR =
|
85
|
+
var STACK_JUMP_SEPARATOR = 'From previous event:';
|
80
86
|
|
81
87
|
function makeStackTraceLong(error, observable) {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
}
|
88
|
+
// If possible, transform the error stack trace by removing Node and RxJS
|
89
|
+
// cruft, then concatenating with the stack trace of `observable`.
|
90
|
+
if (hasStacks &&
|
91
|
+
observable.stack &&
|
92
|
+
typeof error === 'object' &&
|
93
|
+
error !== null &&
|
94
|
+
error.stack &&
|
95
|
+
error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
|
96
|
+
) {
|
97
|
+
var stacks = [];
|
98
|
+
for (var o = observable; !!o; o = o.source) {
|
99
|
+
if (o.stack) {
|
100
|
+
stacks.unshift(o.stack);
|
96
101
|
}
|
97
|
-
|
102
|
+
}
|
103
|
+
stacks.unshift(error.stack);
|
98
104
|
|
99
|
-
|
100
|
-
|
105
|
+
var concatedStacks = stacks.join('\n' + STACK_JUMP_SEPARATOR + '\n');
|
106
|
+
error.stack = filterStackString(concatedStacks);
|
101
107
|
}
|
102
108
|
}
|
103
109
|
|
104
110
|
function filterStackString(stackString) {
|
105
|
-
var lines = stackString.split(
|
106
|
-
desiredLines = [];
|
111
|
+
var lines = stackString.split('\n'), desiredLines = [];
|
107
112
|
for (var i = 0, len = lines.length; i < len; i++) {
|
108
113
|
var line = lines[i];
|
109
114
|
|
@@ -111,7 +116,7 @@
|
|
111
116
|
desiredLines.push(line);
|
112
117
|
}
|
113
118
|
}
|
114
|
-
return desiredLines.join(
|
119
|
+
return desiredLines.join('\n');
|
115
120
|
}
|
116
121
|
|
117
122
|
function isInternalFrame(stackLine) {
|
@@ -127,8 +132,8 @@
|
|
127
132
|
}
|
128
133
|
|
129
134
|
function isNodeFrame(stackLine) {
|
130
|
-
return stackLine.indexOf(
|
131
|
-
stackLine.indexOf(
|
135
|
+
return stackLine.indexOf('(module.js:') !== -1 ||
|
136
|
+
stackLine.indexOf('(node.js:') !== -1;
|
132
137
|
}
|
133
138
|
|
134
139
|
function captureLine() {
|
@@ -137,8 +142,8 @@
|
|
137
142
|
try {
|
138
143
|
throw new Error();
|
139
144
|
} catch (e) {
|
140
|
-
var lines = e.stack.split(
|
141
|
-
var firstLine = lines[0].indexOf(
|
145
|
+
var lines = e.stack.split('\n');
|
146
|
+
var firstLine = lines[0].indexOf('@') > 0 ? lines[1] : lines[2];
|
142
147
|
var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
|
143
148
|
if (!fileNameAndLineNumber) { return; }
|
144
149
|
|
@@ -148,45 +153,50 @@
|
|
148
153
|
}
|
149
154
|
|
150
155
|
function getFileNameAndLineNumber(stackLine) {
|
151
|
-
// Named functions:
|
156
|
+
// Named functions: 'at functionName (filename:lineNumber:columnNumber)'
|
152
157
|
var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
|
153
158
|
if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
|
154
159
|
|
155
|
-
// Anonymous functions:
|
160
|
+
// Anonymous functions: 'at filename:lineNumber:columnNumber'
|
156
161
|
var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
|
157
162
|
if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
|
158
163
|
|
159
|
-
// Firefox style:
|
164
|
+
// Firefox style: 'function@filename:lineNumber or @filename:lineNumber'
|
160
165
|
var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
|
161
166
|
if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
|
162
167
|
}
|
163
168
|
|
164
169
|
var EmptyError = Rx.EmptyError = function() {
|
165
170
|
this.message = 'Sequence contains no elements.';
|
171
|
+
this.name = 'EmptyError';
|
166
172
|
Error.call(this);
|
167
173
|
};
|
168
174
|
EmptyError.prototype = Error.prototype;
|
169
175
|
|
170
176
|
var ObjectDisposedError = Rx.ObjectDisposedError = function() {
|
171
177
|
this.message = 'Object has been disposed';
|
178
|
+
this.name = 'ObjectDisposedError';
|
172
179
|
Error.call(this);
|
173
180
|
};
|
174
181
|
ObjectDisposedError.prototype = Error.prototype;
|
175
182
|
|
176
183
|
var ArgumentOutOfRangeError = Rx.ArgumentOutOfRangeError = function () {
|
177
184
|
this.message = 'Argument out of range';
|
185
|
+
this.name = 'ArgumentOutOfRangeError';
|
178
186
|
Error.call(this);
|
179
187
|
};
|
180
188
|
ArgumentOutOfRangeError.prototype = Error.prototype;
|
181
189
|
|
182
190
|
var NotSupportedError = Rx.NotSupportedError = function (message) {
|
183
191
|
this.message = message || 'This operation is not supported';
|
192
|
+
this.name = 'NotSupportedError';
|
184
193
|
Error.call(this);
|
185
194
|
};
|
186
195
|
NotSupportedError.prototype = Error.prototype;
|
187
196
|
|
188
197
|
var NotImplementedError = Rx.NotImplementedError = function (message) {
|
189
198
|
this.message = message || 'This operation is not implemented';
|
199
|
+
this.name = 'NotImplementedError';
|
190
200
|
Error.call(this);
|
191
201
|
};
|
192
202
|
NotImplementedError.prototype = Error.prototype;
|
@@ -530,29 +540,10 @@
|
|
530
540
|
return result;
|
531
541
|
}
|
532
542
|
|
533
|
-
var errorObj = {e: {}};
|
534
|
-
var tryCatchTarget;
|
535
|
-
function tryCatcher() {
|
536
|
-
try {
|
537
|
-
return tryCatchTarget.apply(this, arguments);
|
538
|
-
} catch (e) {
|
539
|
-
errorObj.e = e;
|
540
|
-
return errorObj;
|
541
|
-
}
|
542
|
-
}
|
543
|
-
function tryCatch(fn) {
|
544
|
-
if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
|
545
|
-
tryCatchTarget = fn;
|
546
|
-
return tryCatcher;
|
547
|
-
}
|
548
|
-
function thrower(e) {
|
549
|
-
throw e;
|
550
|
-
}
|
551
|
-
|
552
543
|
var hasProp = {}.hasOwnProperty,
|
553
544
|
slice = Array.prototype.slice;
|
554
545
|
|
555
|
-
var inherits =
|
546
|
+
var inherits = Rx.internals.inherits = function (child, parent) {
|
556
547
|
function __() { this.constructor = child; }
|
557
548
|
__.prototype = parent.prototype;
|
558
549
|
child.prototype = new __();
|
@@ -772,92 +763,6 @@
|
|
772
763
|
}());
|
773
764
|
}
|
774
765
|
|
775
|
-
// Collections
|
776
|
-
function IndexedItem(id, value) {
|
777
|
-
this.id = id;
|
778
|
-
this.value = value;
|
779
|
-
}
|
780
|
-
|
781
|
-
IndexedItem.prototype.compareTo = function (other) {
|
782
|
-
var c = this.value.compareTo(other.value);
|
783
|
-
c === 0 && (c = this.id - other.id);
|
784
|
-
return c;
|
785
|
-
};
|
786
|
-
|
787
|
-
// Priority Queue for Scheduling
|
788
|
-
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
789
|
-
this.items = new Array(capacity);
|
790
|
-
this.length = 0;
|
791
|
-
};
|
792
|
-
|
793
|
-
var priorityProto = PriorityQueue.prototype;
|
794
|
-
priorityProto.isHigherPriority = function (left, right) {
|
795
|
-
return this.items[left].compareTo(this.items[right]) < 0;
|
796
|
-
};
|
797
|
-
|
798
|
-
priorityProto.percolate = function (index) {
|
799
|
-
if (index >= this.length || index < 0) { return; }
|
800
|
-
var parent = index - 1 >> 1;
|
801
|
-
if (parent < 0 || parent === index) { return; }
|
802
|
-
if (this.isHigherPriority(index, parent)) {
|
803
|
-
var temp = this.items[index];
|
804
|
-
this.items[index] = this.items[parent];
|
805
|
-
this.items[parent] = temp;
|
806
|
-
this.percolate(parent);
|
807
|
-
}
|
808
|
-
};
|
809
|
-
|
810
|
-
priorityProto.heapify = function (index) {
|
811
|
-
+index || (index = 0);
|
812
|
-
if (index >= this.length || index < 0) { return; }
|
813
|
-
var left = 2 * index + 1,
|
814
|
-
right = 2 * index + 2,
|
815
|
-
first = index;
|
816
|
-
if (left < this.length && this.isHigherPriority(left, first)) {
|
817
|
-
first = left;
|
818
|
-
}
|
819
|
-
if (right < this.length && this.isHigherPriority(right, first)) {
|
820
|
-
first = right;
|
821
|
-
}
|
822
|
-
if (first !== index) {
|
823
|
-
var temp = this.items[index];
|
824
|
-
this.items[index] = this.items[first];
|
825
|
-
this.items[first] = temp;
|
826
|
-
this.heapify(first);
|
827
|
-
}
|
828
|
-
};
|
829
|
-
|
830
|
-
priorityProto.peek = function () { return this.items[0].value; };
|
831
|
-
|
832
|
-
priorityProto.removeAt = function (index) {
|
833
|
-
this.items[index] = this.items[--this.length];
|
834
|
-
this.items[this.length] = undefined;
|
835
|
-
this.heapify();
|
836
|
-
};
|
837
|
-
|
838
|
-
priorityProto.dequeue = function () {
|
839
|
-
var result = this.peek();
|
840
|
-
this.removeAt(0);
|
841
|
-
return result;
|
842
|
-
};
|
843
|
-
|
844
|
-
priorityProto.enqueue = function (item) {
|
845
|
-
var index = this.length++;
|
846
|
-
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
847
|
-
this.percolate(index);
|
848
|
-
};
|
849
|
-
|
850
|
-
priorityProto.remove = function (item) {
|
851
|
-
for (var i = 0; i < this.length; i++) {
|
852
|
-
if (this.items[i].value === item) {
|
853
|
-
this.removeAt(i);
|
854
|
-
return true;
|
855
|
-
}
|
856
|
-
}
|
857
|
-
return false;
|
858
|
-
};
|
859
|
-
PriorityQueue.count = 0;
|
860
|
-
|
861
766
|
/**
|
862
767
|
* Represents a group of disposable resources that are disposed together.
|
863
768
|
* @constructor
|
@@ -1210,52 +1115,62 @@
|
|
1210
1115
|
|
1211
1116
|
function invokeRecImmediate(scheduler, pair) {
|
1212
1117
|
var state = pair[0], action = pair[1], group = new CompositeDisposable();
|
1118
|
+
action(state, innerAction);
|
1119
|
+
return group;
|
1213
1120
|
|
1214
|
-
function
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
isAdded = true;
|
1121
|
+
function innerAction(state2) {
|
1122
|
+
var isAdded = false, isDone = false;
|
1123
|
+
|
1124
|
+
var d = scheduler.scheduleWithState(state2, scheduleWork);
|
1125
|
+
if (!isDone) {
|
1126
|
+
group.add(d);
|
1127
|
+
isAdded = true;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
function scheduleWork(_, state3) {
|
1131
|
+
if (isAdded) {
|
1132
|
+
group.remove(d);
|
1133
|
+
} else {
|
1134
|
+
isDone = true;
|
1229
1135
|
}
|
1230
|
-
|
1136
|
+
action(state3, innerAction);
|
1137
|
+
return disposableEmpty;
|
1138
|
+
}
|
1231
1139
|
}
|
1232
|
-
|
1233
|
-
recursiveAction(state);
|
1234
|
-
return group;
|
1235
1140
|
}
|
1236
1141
|
|
1237
1142
|
function invokeRecDate(scheduler, pair, method) {
|
1238
1143
|
var state = pair[0], action = pair[1], group = new CompositeDisposable();
|
1239
|
-
|
1240
|
-
action(state1, function (state2, dueTime1) {
|
1241
|
-
var isAdded = false, isDone = false,
|
1242
|
-
d = scheduler[method](state2, dueTime1, function (scheduler1, state3) {
|
1243
|
-
if (isAdded) {
|
1244
|
-
group.remove(d);
|
1245
|
-
} else {
|
1246
|
-
isDone = true;
|
1247
|
-
}
|
1248
|
-
recursiveAction(state3);
|
1249
|
-
return disposableEmpty;
|
1250
|
-
});
|
1251
|
-
if (!isDone) {
|
1252
|
-
group.add(d);
|
1253
|
-
isAdded = true;
|
1254
|
-
}
|
1255
|
-
});
|
1256
|
-
};
|
1257
|
-
recursiveAction(state);
|
1144
|
+
action(state, innerAction);
|
1258
1145
|
return group;
|
1146
|
+
|
1147
|
+
function innerAction(state2, dueTime1) {
|
1148
|
+
var isAdded = false, isDone = false;
|
1149
|
+
|
1150
|
+
var d = scheduler[method](state2, dueTime1, scheduleWork);
|
1151
|
+
if (!isDone) {
|
1152
|
+
group.add(d);
|
1153
|
+
isAdded = true;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
function scheduleWork(_, state3) {
|
1157
|
+
if (isAdded) {
|
1158
|
+
group.remove(d);
|
1159
|
+
} else {
|
1160
|
+
isDone = true;
|
1161
|
+
}
|
1162
|
+
action(state3, innerAction);
|
1163
|
+
return disposableEmpty;
|
1164
|
+
}
|
1165
|
+
}
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
function invokeRecDateRelative(s, p) {
|
1169
|
+
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
function invokeRecDateAbsolute(s, p) {
|
1173
|
+
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1259
1174
|
}
|
1260
1175
|
|
1261
1176
|
function scheduleInnerRecursive(action, self) {
|
@@ -1268,8 +1183,7 @@
|
|
1268
1183
|
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1269
1184
|
*/
|
1270
1185
|
schedulerProto.scheduleRecursive = function (action) {
|
1271
|
-
return this.scheduleRecursiveWithState(action,
|
1272
|
-
_action(function () { self(_action); }); });
|
1186
|
+
return this.scheduleRecursiveWithState(action, scheduleInnerRecursive);
|
1273
1187
|
};
|
1274
1188
|
|
1275
1189
|
/**
|
@@ -1300,9 +1214,7 @@
|
|
1300
1214
|
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1301
1215
|
*/
|
1302
1216
|
schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
|
1303
|
-
return this._scheduleRelative([state, action], dueTime,
|
1304
|
-
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1305
|
-
});
|
1217
|
+
return this._scheduleRelative([state, action], dueTime, invokeRecDateRelative);
|
1306
1218
|
};
|
1307
1219
|
|
1308
1220
|
/**
|
@@ -1323,9 +1235,7 @@
|
|
1323
1235
|
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1324
1236
|
*/
|
1325
1237
|
schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
|
1326
|
-
return this._scheduleAbsolute([state, action], dueTime,
|
1327
|
-
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1328
|
-
});
|
1238
|
+
return this._scheduleAbsolute([state, action], dueTime, invokeRecDateAbsolute);
|
1329
1239
|
};
|
1330
1240
|
}(Scheduler.prototype));
|
1331
1241
|
|
@@ -1371,7 +1281,7 @@
|
|
1371
1281
|
|
1372
1282
|
function runTrampoline () {
|
1373
1283
|
while (queue.length > 0) {
|
1374
|
-
var item = queue.
|
1284
|
+
var item = queue.shift();
|
1375
1285
|
!item.isCancelled() && item.invoke();
|
1376
1286
|
}
|
1377
1287
|
}
|
@@ -1380,14 +1290,13 @@
|
|
1380
1290
|
var si = new ScheduledItem(this, state, action, this.now());
|
1381
1291
|
|
1382
1292
|
if (!queue) {
|
1383
|
-
queue =
|
1384
|
-
queue.enqueue(si);
|
1293
|
+
queue = [si];
|
1385
1294
|
|
1386
1295
|
var result = tryCatch(runTrampoline)();
|
1387
1296
|
queue = null;
|
1388
1297
|
if (result === errorObj) { return thrower(result.e); }
|
1389
1298
|
} else {
|
1390
|
-
queue.
|
1299
|
+
queue.push(si);
|
1391
1300
|
}
|
1392
1301
|
return si.disposable;
|
1393
1302
|
}
|
@@ -1703,188 +1612,6 @@
|
|
1703
1612
|
};
|
1704
1613
|
}());
|
1705
1614
|
|
1706
|
-
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1707
|
-
this._next = next;
|
1708
|
-
};
|
1709
|
-
|
1710
|
-
Enumerator.prototype.next = function () {
|
1711
|
-
return this._next();
|
1712
|
-
};
|
1713
|
-
|
1714
|
-
Enumerator.prototype[$iterator$] = function () { return this; }
|
1715
|
-
|
1716
|
-
var Enumerable = Rx.internals.Enumerable = function (iterator) {
|
1717
|
-
this._iterator = iterator;
|
1718
|
-
};
|
1719
|
-
|
1720
|
-
Enumerable.prototype[$iterator$] = function () {
|
1721
|
-
return this._iterator();
|
1722
|
-
};
|
1723
|
-
|
1724
|
-
Enumerable.prototype.concat = function () {
|
1725
|
-
var sources = this;
|
1726
|
-
return new AnonymousObservable(function (o) {
|
1727
|
-
var e = sources[$iterator$]();
|
1728
|
-
|
1729
|
-
var isDisposed, subscription = new SerialDisposable();
|
1730
|
-
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1731
|
-
if (isDisposed) { return; }
|
1732
|
-
try {
|
1733
|
-
var currentItem = e.next();
|
1734
|
-
} catch (ex) {
|
1735
|
-
return o.onError(ex);
|
1736
|
-
}
|
1737
|
-
|
1738
|
-
if (currentItem.done) {
|
1739
|
-
return o.onCompleted();
|
1740
|
-
}
|
1741
|
-
|
1742
|
-
// Check if promise
|
1743
|
-
var currentValue = currentItem.value;
|
1744
|
-
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1745
|
-
|
1746
|
-
var d = new SingleAssignmentDisposable();
|
1747
|
-
subscription.setDisposable(d);
|
1748
|
-
d.setDisposable(currentValue.subscribe(
|
1749
|
-
function(x) { o.onNext(x); },
|
1750
|
-
function(err) { o.onError(err); },
|
1751
|
-
self)
|
1752
|
-
);
|
1753
|
-
});
|
1754
|
-
|
1755
|
-
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1756
|
-
isDisposed = true;
|
1757
|
-
}));
|
1758
|
-
});
|
1759
|
-
};
|
1760
|
-
|
1761
|
-
Enumerable.prototype.catchError = function () {
|
1762
|
-
var sources = this;
|
1763
|
-
return new AnonymousObservable(function (o) {
|
1764
|
-
var e = sources[$iterator$]();
|
1765
|
-
|
1766
|
-
var isDisposed, subscription = new SerialDisposable();
|
1767
|
-
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
|
1768
|
-
if (isDisposed) { return; }
|
1769
|
-
|
1770
|
-
try {
|
1771
|
-
var currentItem = e.next();
|
1772
|
-
} catch (ex) {
|
1773
|
-
return observer.onError(ex);
|
1774
|
-
}
|
1775
|
-
|
1776
|
-
if (currentItem.done) {
|
1777
|
-
if (lastException !== null) {
|
1778
|
-
o.onError(lastException);
|
1779
|
-
} else {
|
1780
|
-
o.onCompleted();
|
1781
|
-
}
|
1782
|
-
return;
|
1783
|
-
}
|
1784
|
-
|
1785
|
-
// Check if promise
|
1786
|
-
var currentValue = currentItem.value;
|
1787
|
-
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1788
|
-
|
1789
|
-
var d = new SingleAssignmentDisposable();
|
1790
|
-
subscription.setDisposable(d);
|
1791
|
-
d.setDisposable(currentValue.subscribe(
|
1792
|
-
function(x) { o.onNext(x); },
|
1793
|
-
self,
|
1794
|
-
function() { o.onCompleted(); }));
|
1795
|
-
});
|
1796
|
-
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1797
|
-
isDisposed = true;
|
1798
|
-
}));
|
1799
|
-
});
|
1800
|
-
};
|
1801
|
-
|
1802
|
-
|
1803
|
-
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
|
1804
|
-
var sources = this;
|
1805
|
-
return new AnonymousObservable(function (o) {
|
1806
|
-
var exceptions = new Subject(),
|
1807
|
-
notifier = new Subject(),
|
1808
|
-
handled = notificationHandler(exceptions),
|
1809
|
-
notificationDisposable = handled.subscribe(notifier);
|
1810
|
-
|
1811
|
-
var e = sources[$iterator$]();
|
1812
|
-
|
1813
|
-
var isDisposed,
|
1814
|
-
lastException,
|
1815
|
-
subscription = new SerialDisposable();
|
1816
|
-
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1817
|
-
if (isDisposed) { return; }
|
1818
|
-
|
1819
|
-
try {
|
1820
|
-
var currentItem = e.next();
|
1821
|
-
} catch (ex) {
|
1822
|
-
return o.onError(ex);
|
1823
|
-
}
|
1824
|
-
|
1825
|
-
if (currentItem.done) {
|
1826
|
-
if (lastException) {
|
1827
|
-
o.onError(lastException);
|
1828
|
-
} else {
|
1829
|
-
o.onCompleted();
|
1830
|
-
}
|
1831
|
-
return;
|
1832
|
-
}
|
1833
|
-
|
1834
|
-
// Check if promise
|
1835
|
-
var currentValue = currentItem.value;
|
1836
|
-
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1837
|
-
|
1838
|
-
var outer = new SingleAssignmentDisposable();
|
1839
|
-
var inner = new SingleAssignmentDisposable();
|
1840
|
-
subscription.setDisposable(new CompositeDisposable(inner, outer));
|
1841
|
-
outer.setDisposable(currentValue.subscribe(
|
1842
|
-
function(x) { o.onNext(x); },
|
1843
|
-
function (exn) {
|
1844
|
-
inner.setDisposable(notifier.subscribe(self, function(ex) {
|
1845
|
-
o.onError(ex);
|
1846
|
-
}, function() {
|
1847
|
-
o.onCompleted();
|
1848
|
-
}));
|
1849
|
-
|
1850
|
-
exceptions.onNext(exn);
|
1851
|
-
},
|
1852
|
-
function() { o.onCompleted(); }));
|
1853
|
-
});
|
1854
|
-
|
1855
|
-
return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
|
1856
|
-
isDisposed = true;
|
1857
|
-
}));
|
1858
|
-
});
|
1859
|
-
};
|
1860
|
-
|
1861
|
-
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
1862
|
-
if (repeatCount == null) { repeatCount = -1; }
|
1863
|
-
return new Enumerable(function () {
|
1864
|
-
var left = repeatCount;
|
1865
|
-
return new Enumerator(function () {
|
1866
|
-
if (left === 0) { return doneEnumerator; }
|
1867
|
-
if (left > 0) { left--; }
|
1868
|
-
return { done: false, value: value };
|
1869
|
-
});
|
1870
|
-
});
|
1871
|
-
};
|
1872
|
-
|
1873
|
-
var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
|
1874
|
-
if (selector) {
|
1875
|
-
var selectorFn = bindCallback(selector, thisArg, 3);
|
1876
|
-
}
|
1877
|
-
return new Enumerable(function () {
|
1878
|
-
var index = -1;
|
1879
|
-
return new Enumerator(
|
1880
|
-
function () {
|
1881
|
-
return ++index < source.length ?
|
1882
|
-
{ done: false, value: !selector ? source[index] : selectorFn(source[index], index, source) } :
|
1883
|
-
doneEnumerator;
|
1884
|
-
});
|
1885
|
-
});
|
1886
|
-
};
|
1887
|
-
|
1888
1615
|
/**
|
1889
1616
|
* Supports push-style iteration over an observable sequence.
|
1890
1617
|
*/
|
@@ -1916,7 +1643,6 @@
|
|
1916
1643
|
*/
|
1917
1644
|
function AbstractObserver() {
|
1918
1645
|
this.isStopped = false;
|
1919
|
-
__super__.call(this);
|
1920
1646
|
}
|
1921
1647
|
|
1922
1648
|
// Must be implemented by other observers
|
@@ -1929,7 +1655,7 @@
|
|
1929
1655
|
* @param {Any} value Next element in the sequence.
|
1930
1656
|
*/
|
1931
1657
|
AbstractObserver.prototype.onNext = function (value) {
|
1932
|
-
|
1658
|
+
!this.isStopped && this.next(value);
|
1933
1659
|
};
|
1934
1660
|
|
1935
1661
|
/**
|
@@ -1956,9 +1682,7 @@
|
|
1956
1682
|
/**
|
1957
1683
|
* Disposes the observer, causing it to transition to the stopped state.
|
1958
1684
|
*/
|
1959
|
-
AbstractObserver.prototype.dispose = function () {
|
1960
|
-
this.isStopped = true;
|
1961
|
-
};
|
1685
|
+
AbstractObserver.prototype.dispose = function () { this.isStopped = true; };
|
1962
1686
|
|
1963
1687
|
AbstractObserver.prototype.fail = function (e) {
|
1964
1688
|
if (!this.isStopped) {
|
@@ -2025,25 +1749,23 @@
|
|
2025
1749
|
*/
|
2026
1750
|
var Observable = Rx.Observable = (function () {
|
2027
1751
|
|
2028
|
-
function
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
}
|
2035
|
-
|
2036
|
-
var self = this;
|
2037
|
-
this._subscribe = function (observer) {
|
2038
|
-
var oldOnError = observer.onError.bind(observer);
|
1752
|
+
function makeSubscribe(self, subscribe) {
|
1753
|
+
return function (o) {
|
1754
|
+
var oldOnError = o.onError;
|
1755
|
+
o.onError = function (e) {
|
1756
|
+
makeStackTraceLong(e, self);
|
1757
|
+
oldOnError.call(o, e);
|
1758
|
+
};
|
2039
1759
|
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
};
|
1760
|
+
return subscribe.call(self, o);
|
1761
|
+
};
|
1762
|
+
}
|
2044
1763
|
|
2045
|
-
|
2046
|
-
|
1764
|
+
function Observable(subscribe) {
|
1765
|
+
if (Rx.config.longStackSupport && hasStacks) {
|
1766
|
+
var e = tryCatch(thrower)(new Error()).e;
|
1767
|
+
this.stack = e.stack.substring(e.stack.indexOf('\n') + 1);
|
1768
|
+
this._subscribe = makeSubscribe(this, subscribe);
|
2047
1769
|
} else {
|
2048
1770
|
this._subscribe = subscribe;
|
2049
1771
|
}
|
@@ -2052,16 +1774,25 @@
|
|
2052
1774
|
observableProto = Observable.prototype;
|
2053
1775
|
|
2054
1776
|
/**
|
2055
|
-
|
2056
|
-
|
1777
|
+
* Determines whether the given object is an Observable
|
1778
|
+
* @param {Any} An object to determine whether it is an Observable
|
1779
|
+
* @returns {Boolean} true if an Observable, else false.
|
1780
|
+
*/
|
1781
|
+
Observable.isObservable = function (o) {
|
1782
|
+
return o && isFunction(o.subscribe);
|
1783
|
+
}
|
1784
|
+
|
1785
|
+
/**
|
1786
|
+
* Subscribes an o to the observable sequence.
|
1787
|
+
* @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
|
2057
1788
|
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
|
2058
1789
|
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
|
2059
1790
|
* @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
|
2060
1791
|
*/
|
2061
|
-
observableProto.subscribe = observableProto.forEach = function (
|
2062
|
-
return this._subscribe(typeof
|
2063
|
-
|
2064
|
-
observerCreate(
|
1792
|
+
observableProto.subscribe = observableProto.forEach = function (oOrOnNext, onError, onCompleted) {
|
1793
|
+
return this._subscribe(typeof oOrOnNext === 'object' ?
|
1794
|
+
oOrOnNext :
|
1795
|
+
observerCreate(oOrOnNext, onError, onCompleted));
|
2065
1796
|
};
|
2066
1797
|
|
2067
1798
|
/**
|
@@ -2135,6 +1866,294 @@
|
|
2135
1866
|
return ObservableBase;
|
2136
1867
|
}(Observable));
|
2137
1868
|
|
1869
|
+
var FlatMapObservable = (function(__super__){
|
1870
|
+
|
1871
|
+
inherits(FlatMapObservable, __super__);
|
1872
|
+
|
1873
|
+
function FlatMapObservable(source, selector, resultSelector, thisArg) {
|
1874
|
+
this.resultSelector = Rx.helpers.isFunction(resultSelector) ?
|
1875
|
+
resultSelector : null;
|
1876
|
+
|
1877
|
+
this.selector = Rx.internals.bindCallback(Rx.helpers.isFunction(selector) ? selector : function() { return selector; }, thisArg, 3);
|
1878
|
+
this.source = source;
|
1879
|
+
|
1880
|
+
__super__.call(this);
|
1881
|
+
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
FlatMapObservable.prototype.subscribeCore = function(o) {
|
1885
|
+
return this.source.subscribe(new InnerObserver(o, this.selector, this.resultSelector, this));
|
1886
|
+
};
|
1887
|
+
|
1888
|
+
function InnerObserver(observer, selector, resultSelector, source) {
|
1889
|
+
this.i = 0;
|
1890
|
+
this.selector = selector;
|
1891
|
+
this.resultSelector = resultSelector;
|
1892
|
+
this.source = source;
|
1893
|
+
this.isStopped = false;
|
1894
|
+
this.o = observer;
|
1895
|
+
}
|
1896
|
+
|
1897
|
+
InnerObserver.prototype._wrapResult = function(result, x, i) {
|
1898
|
+
return this.resultSelector ?
|
1899
|
+
result.map(function(y, i2) { return this.resultSelector(x, y, i, i2); }, this) :
|
1900
|
+
result;
|
1901
|
+
};
|
1902
|
+
|
1903
|
+
InnerObserver.prototype.onNext = function(x) {
|
1904
|
+
|
1905
|
+
if (this.isStopped) return;
|
1906
|
+
|
1907
|
+
var i = this.i++;
|
1908
|
+
var result = tryCatch(this.selector)(x, i, this.source);
|
1909
|
+
|
1910
|
+
if (result === errorObj) {
|
1911
|
+
return this.o.onError(result.e);
|
1912
|
+
}
|
1913
|
+
|
1914
|
+
Rx.helpers.isPromise(result) && (result = Rx.Observable.fromPromise(result));
|
1915
|
+
(Rx.helpers.isArrayLike(result) || Rx.helpers.isIterable(result)) && (result = Rx.Observable.from(result));
|
1916
|
+
|
1917
|
+
this.o.onNext(this._wrapResult(result, x, i));
|
1918
|
+
|
1919
|
+
};
|
1920
|
+
|
1921
|
+
InnerObserver.prototype.onError = function(e) {
|
1922
|
+
if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
|
1923
|
+
};
|
1924
|
+
|
1925
|
+
InnerObserver.prototype.onCompleted = function() {
|
1926
|
+
if (!this.isStopped) {this.isStopped = true; this.o.onCompleted(); }
|
1927
|
+
};
|
1928
|
+
|
1929
|
+
return FlatMapObservable;
|
1930
|
+
|
1931
|
+
}(ObservableBase));
|
1932
|
+
|
1933
|
+
var Enumerable = Rx.internals.Enumerable = function () { };
|
1934
|
+
|
1935
|
+
var ConcatEnumerableObservable = (function(__super__) {
|
1936
|
+
inherits(ConcatEnumerableObservable, __super__);
|
1937
|
+
function ConcatEnumerableObservable(sources) {
|
1938
|
+
this.sources = sources;
|
1939
|
+
__super__.call(this);
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
ConcatEnumerableObservable.prototype.subscribeCore = function (o) {
|
1943
|
+
var isDisposed, subscription = new SerialDisposable();
|
1944
|
+
var cancelable = immediateScheduler.scheduleRecursiveWithState(this.sources[$iterator$](), function (e, self) {
|
1945
|
+
if (isDisposed) { return; }
|
1946
|
+
var currentItem = tryCatch(e.next).call(e);
|
1947
|
+
if (currentItem === errorObj) { return o.onError(currentItem.e); }
|
1948
|
+
|
1949
|
+
if (currentItem.done) {
|
1950
|
+
return o.onCompleted();
|
1951
|
+
}
|
1952
|
+
|
1953
|
+
// Check if promise
|
1954
|
+
var currentValue = currentItem.value;
|
1955
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1956
|
+
|
1957
|
+
var d = new SingleAssignmentDisposable();
|
1958
|
+
subscription.setDisposable(d);
|
1959
|
+
d.setDisposable(currentValue.subscribe(new InnerObserver(o, self, e)));
|
1960
|
+
});
|
1961
|
+
|
1962
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1963
|
+
isDisposed = true;
|
1964
|
+
}));
|
1965
|
+
};
|
1966
|
+
|
1967
|
+
function InnerObserver(o, s, e) {
|
1968
|
+
this.o = o;
|
1969
|
+
this.s = s;
|
1970
|
+
this.e = e;
|
1971
|
+
this.isStopped = false;
|
1972
|
+
}
|
1973
|
+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
|
1974
|
+
InnerObserver.prototype.onError = function (err) {
|
1975
|
+
if (!this.isStopped) {
|
1976
|
+
this.isStopped = true;
|
1977
|
+
this.o.onError(err);
|
1978
|
+
}
|
1979
|
+
};
|
1980
|
+
InnerObserver.prototype.onCompleted = function () {
|
1981
|
+
if (!this.isStopped) {
|
1982
|
+
this.isStopped = true;
|
1983
|
+
this.s(this.e);
|
1984
|
+
}
|
1985
|
+
};
|
1986
|
+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
|
1987
|
+
InnerObserver.prototype.fail = function (err) {
|
1988
|
+
if (!this.isStopped) {
|
1989
|
+
this.isStopped = true;
|
1990
|
+
this.o.onError(err);
|
1991
|
+
return true;
|
1992
|
+
}
|
1993
|
+
return false;
|
1994
|
+
};
|
1995
|
+
|
1996
|
+
return ConcatEnumerableObservable;
|
1997
|
+
}(ObservableBase));
|
1998
|
+
|
1999
|
+
Enumerable.prototype.concat = function () {
|
2000
|
+
return new ConcatEnumerableObservable(this);
|
2001
|
+
};
|
2002
|
+
|
2003
|
+
var CatchErrorObservable = (function(__super__) {
|
2004
|
+
inherits(CatchErrorObservable, __super__);
|
2005
|
+
function CatchErrorObservable(sources) {
|
2006
|
+
this.sources = sources;
|
2007
|
+
__super__.call(this);
|
2008
|
+
}
|
2009
|
+
|
2010
|
+
CatchErrorObservable.prototype.subscribeCore = function (o) {
|
2011
|
+
var e = this.sources[$iterator$]();
|
2012
|
+
|
2013
|
+
var isDisposed, subscription = new SerialDisposable();
|
2014
|
+
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
|
2015
|
+
if (isDisposed) { return; }
|
2016
|
+
var currentItem = tryCatch(e.next).call(e);
|
2017
|
+
if (currentItem === errorObj) { return o.onError(currentItem.e); }
|
2018
|
+
|
2019
|
+
if (currentItem.done) {
|
2020
|
+
return lastException !== null ? o.onError(lastException) : o.onCompleted();
|
2021
|
+
}
|
2022
|
+
|
2023
|
+
// Check if promise
|
2024
|
+
var currentValue = currentItem.value;
|
2025
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
2026
|
+
|
2027
|
+
var d = new SingleAssignmentDisposable();
|
2028
|
+
subscription.setDisposable(d);
|
2029
|
+
d.setDisposable(currentValue.subscribe(
|
2030
|
+
function(x) { o.onNext(x); },
|
2031
|
+
self,
|
2032
|
+
function() { o.onCompleted(); }));
|
2033
|
+
});
|
2034
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
2035
|
+
isDisposed = true;
|
2036
|
+
}));
|
2037
|
+
};
|
2038
|
+
|
2039
|
+
return CatchErrorObservable;
|
2040
|
+
}(ObservableBase));
|
2041
|
+
|
2042
|
+
Enumerable.prototype.catchError = function () {
|
2043
|
+
return new CatchErrorObservable(this);
|
2044
|
+
};
|
2045
|
+
|
2046
|
+
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
|
2047
|
+
var sources = this;
|
2048
|
+
return new AnonymousObservable(function (o) {
|
2049
|
+
var exceptions = new Subject(),
|
2050
|
+
notifier = new Subject(),
|
2051
|
+
handled = notificationHandler(exceptions),
|
2052
|
+
notificationDisposable = handled.subscribe(notifier);
|
2053
|
+
|
2054
|
+
var e = sources[$iterator$]();
|
2055
|
+
|
2056
|
+
var isDisposed,
|
2057
|
+
lastException,
|
2058
|
+
subscription = new SerialDisposable();
|
2059
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
2060
|
+
if (isDisposed) { return; }
|
2061
|
+
var currentItem = tryCatch(e.next).call(e);
|
2062
|
+
if (currentItem === errorObj) { return o.onError(currentItem.e); }
|
2063
|
+
|
2064
|
+
if (currentItem.done) {
|
2065
|
+
if (lastException) {
|
2066
|
+
o.onError(lastException);
|
2067
|
+
} else {
|
2068
|
+
o.onCompleted();
|
2069
|
+
}
|
2070
|
+
return;
|
2071
|
+
}
|
2072
|
+
|
2073
|
+
// Check if promise
|
2074
|
+
var currentValue = currentItem.value;
|
2075
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
2076
|
+
|
2077
|
+
var outer = new SingleAssignmentDisposable();
|
2078
|
+
var inner = new SingleAssignmentDisposable();
|
2079
|
+
subscription.setDisposable(new CompositeDisposable(inner, outer));
|
2080
|
+
outer.setDisposable(currentValue.subscribe(
|
2081
|
+
function(x) { o.onNext(x); },
|
2082
|
+
function (exn) {
|
2083
|
+
inner.setDisposable(notifier.subscribe(self, function(ex) {
|
2084
|
+
o.onError(ex);
|
2085
|
+
}, function() {
|
2086
|
+
o.onCompleted();
|
2087
|
+
}));
|
2088
|
+
|
2089
|
+
exceptions.onNext(exn);
|
2090
|
+
},
|
2091
|
+
function() { o.onCompleted(); }));
|
2092
|
+
});
|
2093
|
+
|
2094
|
+
return new CompositeDisposable(notificationDisposable, subscription, cancelable, disposableCreate(function () {
|
2095
|
+
isDisposed = true;
|
2096
|
+
}));
|
2097
|
+
});
|
2098
|
+
};
|
2099
|
+
|
2100
|
+
var RepeatEnumerable = (function (__super__) {
|
2101
|
+
inherits(RepeatEnumerable, __super__);
|
2102
|
+
|
2103
|
+
function RepeatEnumerable(v, c) {
|
2104
|
+
this.v = v;
|
2105
|
+
this.c = c == null ? -1 : c;
|
2106
|
+
}
|
2107
|
+
RepeatEnumerable.prototype[$iterator$] = function () {
|
2108
|
+
return new RepeatEnumerator(this);
|
2109
|
+
};
|
2110
|
+
|
2111
|
+
function RepeatEnumerator(p) {
|
2112
|
+
this.v = p.v;
|
2113
|
+
this.l = p.c;
|
2114
|
+
}
|
2115
|
+
RepeatEnumerator.prototype.next = function () {
|
2116
|
+
if (this.l === 0) { return doneEnumerator; }
|
2117
|
+
if (this.l > 0) { this.l--; }
|
2118
|
+
return { done: false, value: this.v };
|
2119
|
+
};
|
2120
|
+
|
2121
|
+
return RepeatEnumerable;
|
2122
|
+
}(Enumerable));
|
2123
|
+
|
2124
|
+
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
2125
|
+
return new RepeatEnumerable(value, repeatCount);
|
2126
|
+
};
|
2127
|
+
|
2128
|
+
var OfEnumerable = (function(__super__) {
|
2129
|
+
inherits(OfEnumerable, __super__);
|
2130
|
+
function OfEnumerable(s, fn, thisArg) {
|
2131
|
+
this.s = s;
|
2132
|
+
this.fn = fn ? bindCallback(fn, thisArg, 3) : null;
|
2133
|
+
}
|
2134
|
+
OfEnumerable.prototype[$iterator$] = function () {
|
2135
|
+
return new OfEnumerator(this);
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
function OfEnumerator(p) {
|
2139
|
+
this.i = -1;
|
2140
|
+
this.s = p.s;
|
2141
|
+
this.l = this.s.length;
|
2142
|
+
this.fn = p.fn;
|
2143
|
+
}
|
2144
|
+
OfEnumerator.prototype.next = function () {
|
2145
|
+
return ++this.i < this.l ?
|
2146
|
+
{ done: false, value: !this.fn ? this.s[this.i] : this.fn(this.s[this.i], this.i, this.s) } :
|
2147
|
+
doneEnumerator;
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
return OfEnumerable;
|
2151
|
+
}(Enumerable));
|
2152
|
+
|
2153
|
+
var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
|
2154
|
+
return new OfEnumerable(source, selector, thisArg);
|
2155
|
+
};
|
2156
|
+
|
2138
2157
|
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
|
2139
2158
|
inherits(ScheduledObserver, __super__);
|
2140
2159
|
|
@@ -2164,13 +2183,13 @@
|
|
2164
2183
|
};
|
2165
2184
|
|
2166
2185
|
ScheduledObserver.prototype.ensureActive = function () {
|
2167
|
-
var isOwner = false
|
2186
|
+
var isOwner = false;
|
2168
2187
|
if (!this.hasFaulted && this.queue.length > 0) {
|
2169
2188
|
isOwner = !this.isAcquired;
|
2170
2189
|
this.isAcquired = true;
|
2171
2190
|
}
|
2172
2191
|
if (isOwner) {
|
2173
|
-
this.disposable.setDisposable(this.scheduler.
|
2192
|
+
this.disposable.setDisposable(this.scheduler.scheduleRecursiveWithState(this, function (parent, self) {
|
2174
2193
|
var work;
|
2175
2194
|
if (parent.queue.length > 0) {
|
2176
2195
|
work = parent.queue.shift();
|
@@ -2178,14 +2197,13 @@
|
|
2178
2197
|
parent.isAcquired = false;
|
2179
2198
|
return;
|
2180
2199
|
}
|
2181
|
-
|
2182
|
-
|
2183
|
-
} catch (ex) {
|
2200
|
+
var res = tryCatch(work)();
|
2201
|
+
if (res === errorObj) {
|
2184
2202
|
parent.queue = [];
|
2185
2203
|
parent.hasFaulted = true;
|
2186
|
-
|
2204
|
+
return thrower(res.e);
|
2187
2205
|
}
|
2188
|
-
self();
|
2206
|
+
self(parent);
|
2189
2207
|
}));
|
2190
2208
|
}
|
2191
2209
|
};
|
@@ -2205,42 +2223,42 @@
|
|
2205
2223
|
__super__.call(this);
|
2206
2224
|
}
|
2207
2225
|
|
2208
|
-
ToArrayObservable.prototype.subscribeCore = function(
|
2209
|
-
return this.source.subscribe(new
|
2226
|
+
ToArrayObservable.prototype.subscribeCore = function(o) {
|
2227
|
+
return this.source.subscribe(new InnerObserver(o));
|
2210
2228
|
};
|
2211
2229
|
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
this.observer = observer;
|
2217
|
-
this.a = [];
|
2218
|
-
this.isStopped = false;
|
2219
|
-
}
|
2220
|
-
ToArrayObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
|
2221
|
-
ToArrayObserver.prototype.onError = function (e) {
|
2222
|
-
if (!this.isStopped) {
|
2223
|
-
this.isStopped = true;
|
2224
|
-
this.observer.onError(e);
|
2225
|
-
}
|
2226
|
-
};
|
2227
|
-
ToArrayObserver.prototype.onCompleted = function () {
|
2228
|
-
if (!this.isStopped) {
|
2229
|
-
this.isStopped = true;
|
2230
|
-
this.observer.onNext(this.a);
|
2231
|
-
this.observer.onCompleted();
|
2232
|
-
}
|
2233
|
-
};
|
2234
|
-
ToArrayObserver.prototype.dispose = function () { this.isStopped = true; }
|
2235
|
-
ToArrayObserver.prototype.fail = function (e) {
|
2236
|
-
if (!this.isStopped) {
|
2237
|
-
this.isStopped = true;
|
2238
|
-
this.observer.onError(e);
|
2239
|
-
return true;
|
2230
|
+
function InnerObserver(o) {
|
2231
|
+
this.o = o;
|
2232
|
+
this.a = [];
|
2233
|
+
this.isStopped = false;
|
2240
2234
|
}
|
2235
|
+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.a.push(x); } };
|
2236
|
+
InnerObserver.prototype.onError = function (e) {
|
2237
|
+
if (!this.isStopped) {
|
2238
|
+
this.isStopped = true;
|
2239
|
+
this.o.onError(e);
|
2240
|
+
}
|
2241
|
+
};
|
2242
|
+
InnerObserver.prototype.onCompleted = function () {
|
2243
|
+
if (!this.isStopped) {
|
2244
|
+
this.isStopped = true;
|
2245
|
+
this.o.onNext(this.a);
|
2246
|
+
this.o.onCompleted();
|
2247
|
+
}
|
2248
|
+
};
|
2249
|
+
InnerObserver.prototype.dispose = function () { this.isStopped = true; }
|
2250
|
+
InnerObserver.prototype.fail = function (e) {
|
2251
|
+
if (!this.isStopped) {
|
2252
|
+
this.isStopped = true;
|
2253
|
+
this.o.onError(e);
|
2254
|
+
return true;
|
2255
|
+
}
|
2256
|
+
|
2257
|
+
return false;
|
2258
|
+
};
|
2241
2259
|
|
2242
|
-
return
|
2243
|
-
};
|
2260
|
+
return ToArrayObservable;
|
2261
|
+
}(ObservableBase));
|
2244
2262
|
|
2245
2263
|
/**
|
2246
2264
|
* Creates an array from an observable sequence.
|
@@ -2259,7 +2277,7 @@
|
|
2259
2277
|
* @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable.
|
2260
2278
|
* @returns {Observable} The observable sequence with the specified implementation for the Subscribe method.
|
2261
2279
|
*/
|
2262
|
-
Observable.create =
|
2280
|
+
Observable.create = function (subscribe, parent) {
|
2263
2281
|
return new AnonymousObservable(subscribe, parent);
|
2264
2282
|
};
|
2265
2283
|
|
@@ -2292,26 +2310,29 @@
|
|
2292
2310
|
}
|
2293
2311
|
|
2294
2312
|
EmptyObservable.prototype.subscribeCore = function (observer) {
|
2295
|
-
var sink = new EmptySink(observer, this);
|
2313
|
+
var sink = new EmptySink(observer, this.scheduler);
|
2296
2314
|
return sink.run();
|
2297
2315
|
};
|
2298
2316
|
|
2299
|
-
function EmptySink(observer,
|
2317
|
+
function EmptySink(observer, scheduler) {
|
2300
2318
|
this.observer = observer;
|
2301
|
-
this.
|
2319
|
+
this.scheduler = scheduler;
|
2302
2320
|
}
|
2303
2321
|
|
2304
2322
|
function scheduleItem(s, state) {
|
2305
2323
|
state.onCompleted();
|
2324
|
+
return disposableEmpty;
|
2306
2325
|
}
|
2307
2326
|
|
2308
2327
|
EmptySink.prototype.run = function () {
|
2309
|
-
return this.
|
2328
|
+
return this.scheduler.scheduleWithState(this.observer, scheduleItem);
|
2310
2329
|
};
|
2311
2330
|
|
2312
2331
|
return EmptyObservable;
|
2313
2332
|
}(ObservableBase));
|
2314
2333
|
|
2334
|
+
var EMPTY_OBSERVABLE = new EmptyObservable(immediateScheduler);
|
2335
|
+
|
2315
2336
|
/**
|
2316
2337
|
* Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.
|
2317
2338
|
*
|
@@ -2323,7 +2344,7 @@
|
|
2323
2344
|
*/
|
2324
2345
|
var observableEmpty = Observable.empty = function (scheduler) {
|
2325
2346
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2326
|
-
return new EmptyObservable(scheduler);
|
2347
|
+
return scheduler === immediateScheduler ? EMPTY_OBSERVABLE : new EmptyObservable(scheduler);
|
2327
2348
|
};
|
2328
2349
|
|
2329
2350
|
var FromObservable = (function(__super__) {
|
@@ -2335,8 +2356,8 @@
|
|
2335
2356
|
__super__.call(this);
|
2336
2357
|
}
|
2337
2358
|
|
2338
|
-
FromObservable.prototype.subscribeCore = function (
|
2339
|
-
var sink = new FromSink(
|
2359
|
+
FromObservable.prototype.subscribeCore = function (o) {
|
2360
|
+
var sink = new FromSink(o, this);
|
2340
2361
|
return sink.run();
|
2341
2362
|
};
|
2342
2363
|
|
@@ -2344,38 +2365,30 @@
|
|
2344
2365
|
}(ObservableBase));
|
2345
2366
|
|
2346
2367
|
var FromSink = (function () {
|
2347
|
-
function FromSink(
|
2348
|
-
this.
|
2368
|
+
function FromSink(o, parent) {
|
2369
|
+
this.o = o;
|
2349
2370
|
this.parent = parent;
|
2350
2371
|
}
|
2351
2372
|
|
2352
2373
|
FromSink.prototype.run = function () {
|
2353
2374
|
var list = Object(this.parent.iterable),
|
2354
2375
|
it = getIterable(list),
|
2355
|
-
|
2376
|
+
o = this.o,
|
2356
2377
|
mapper = this.parent.mapper;
|
2357
2378
|
|
2358
2379
|
function loopRecursive(i, recurse) {
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
return observer.onError(e);
|
2363
|
-
}
|
2364
|
-
if (next.done) {
|
2365
|
-
return observer.onCompleted();
|
2366
|
-
}
|
2380
|
+
var next = tryCatch(it.next).call(it);
|
2381
|
+
if (next === errorObj) { return o.onError(next.e); }
|
2382
|
+
if (next.done) { return o.onCompleted(); }
|
2367
2383
|
|
2368
2384
|
var result = next.value;
|
2369
2385
|
|
2370
|
-
if (mapper) {
|
2371
|
-
|
2372
|
-
|
2373
|
-
} catch (e) {
|
2374
|
-
return observer.onError(e);
|
2375
|
-
}
|
2386
|
+
if (isFunction(mapper)) {
|
2387
|
+
result = tryCatch(mapper)(result, i);
|
2388
|
+
if (result === errorObj) { return o.onError(result.e); }
|
2376
2389
|
}
|
2377
2390
|
|
2378
|
-
|
2391
|
+
o.onNext(result);
|
2379
2392
|
recurse(i + 1);
|
2380
2393
|
}
|
2381
2394
|
|
@@ -2387,7 +2400,7 @@
|
|
2387
2400
|
|
2388
2401
|
var maxSafeInteger = Math.pow(2, 53) - 1;
|
2389
2402
|
|
2390
|
-
function StringIterable(
|
2403
|
+
function StringIterable(s) {
|
2391
2404
|
this._s = s;
|
2392
2405
|
}
|
2393
2406
|
|
@@ -2395,7 +2408,7 @@
|
|
2395
2408
|
return new StringIterator(this._s);
|
2396
2409
|
};
|
2397
2410
|
|
2398
|
-
function StringIterator(
|
2411
|
+
function StringIterator(s) {
|
2399
2412
|
this._s = s;
|
2400
2413
|
this._l = s.length;
|
2401
2414
|
this._i = 0;
|
@@ -2550,12 +2563,14 @@
|
|
2550
2563
|
return NeverObservable;
|
2551
2564
|
}(ObservableBase));
|
2552
2565
|
|
2566
|
+
var NEVER_OBSERVABLE = new NeverObservable();
|
2567
|
+
|
2553
2568
|
/**
|
2554
2569
|
* Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins).
|
2555
2570
|
* @returns {Observable} An observable sequence whose observers will never get called.
|
2556
2571
|
*/
|
2557
2572
|
var observableNever = Observable.never = function () {
|
2558
|
-
return
|
2573
|
+
return NEVER_OBSERVABLE;
|
2559
2574
|
};
|
2560
2575
|
|
2561
2576
|
function observableOf (scheduler, array) {
|
@@ -2636,7 +2651,7 @@
|
|
2636
2651
|
inherits(RangeObservable, __super__);
|
2637
2652
|
function RangeObservable(start, count, scheduler) {
|
2638
2653
|
this.start = start;
|
2639
|
-
this.
|
2654
|
+
this.rangeCount = count;
|
2640
2655
|
this.scheduler = scheduler;
|
2641
2656
|
__super__.call(this);
|
2642
2657
|
}
|
@@ -2656,7 +2671,7 @@
|
|
2656
2671
|
}
|
2657
2672
|
|
2658
2673
|
RangeSink.prototype.run = function () {
|
2659
|
-
var start = this.parent.start, count = this.parent.
|
2674
|
+
var start = this.parent.start, count = this.parent.rangeCount, observer = this.observer;
|
2660
2675
|
function loopRecursive(i, recurse) {
|
2661
2676
|
if (i < count) {
|
2662
2677
|
observer.onNext(start + i);
|
@@ -2741,23 +2756,28 @@
|
|
2741
2756
|
}
|
2742
2757
|
|
2743
2758
|
JustObservable.prototype.subscribeCore = function (observer) {
|
2744
|
-
var sink = new JustSink(observer, this);
|
2759
|
+
var sink = new JustSink(observer, this.value, this.scheduler);
|
2745
2760
|
return sink.run();
|
2746
2761
|
};
|
2747
2762
|
|
2748
|
-
function JustSink(observer,
|
2763
|
+
function JustSink(observer, value, scheduler) {
|
2749
2764
|
this.observer = observer;
|
2750
|
-
this.
|
2765
|
+
this.value = value;
|
2766
|
+
this.scheduler = scheduler;
|
2751
2767
|
}
|
2752
2768
|
|
2753
2769
|
function scheduleItem(s, state) {
|
2754
2770
|
var value = state[0], observer = state[1];
|
2755
2771
|
observer.onNext(value);
|
2756
2772
|
observer.onCompleted();
|
2773
|
+
return disposableEmpty;
|
2757
2774
|
}
|
2758
2775
|
|
2759
2776
|
JustSink.prototype.run = function () {
|
2760
|
-
|
2777
|
+
var state = [this.value, this.observer];
|
2778
|
+
return this.scheduler === immediateScheduler ?
|
2779
|
+
scheduleItem(null, state) :
|
2780
|
+
this.scheduler.scheduleWithState(state, scheduleItem);
|
2761
2781
|
};
|
2762
2782
|
|
2763
2783
|
return JustObservable;
|
@@ -2770,7 +2790,7 @@
|
|
2770
2790
|
* @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
|
2771
2791
|
* @returns {Observable} An observable sequence containing the single specified element.
|
2772
2792
|
*/
|
2773
|
-
var observableReturn = Observable['return'] = Observable.just =
|
2793
|
+
var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
|
2774
2794
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2775
2795
|
return new JustObservable(value, scheduler);
|
2776
2796
|
};
|
@@ -2783,23 +2803,23 @@
|
|
2783
2803
|
__super__.call(this);
|
2784
2804
|
}
|
2785
2805
|
|
2786
|
-
ThrowObservable.prototype.subscribeCore = function (
|
2787
|
-
var sink = new ThrowSink(
|
2806
|
+
ThrowObservable.prototype.subscribeCore = function (o) {
|
2807
|
+
var sink = new ThrowSink(o, this);
|
2788
2808
|
return sink.run();
|
2789
2809
|
};
|
2790
2810
|
|
2791
|
-
function ThrowSink(
|
2792
|
-
this.
|
2793
|
-
this.
|
2811
|
+
function ThrowSink(o, p) {
|
2812
|
+
this.o = o;
|
2813
|
+
this.p = p;
|
2794
2814
|
}
|
2795
2815
|
|
2796
2816
|
function scheduleItem(s, state) {
|
2797
|
-
var
|
2798
|
-
|
2817
|
+
var e = state[0], o = state[1];
|
2818
|
+
o.onError(e);
|
2799
2819
|
}
|
2800
2820
|
|
2801
2821
|
ThrowSink.prototype.run = function () {
|
2802
|
-
return this.
|
2822
|
+
return this.p.scheduler.scheduleWithState([this.p.error, this.o], scheduleItem);
|
2803
2823
|
};
|
2804
2824
|
|
2805
2825
|
return ThrowObservable;
|
@@ -2812,44 +2832,51 @@
|
|
2812
2832
|
* @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate.
|
2813
2833
|
* @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object.
|
2814
2834
|
*/
|
2815
|
-
var observableThrow = Observable['throw'] =
|
2835
|
+
var observableThrow = Observable['throw'] = function (error, scheduler) {
|
2816
2836
|
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2817
2837
|
return new ThrowObservable(error, scheduler);
|
2818
2838
|
};
|
2819
2839
|
|
2840
|
+
var CatchObserver = (function(__super__) {
|
2841
|
+
inherits(CatchObserver, __super__);
|
2842
|
+
function CatchObserver(o, s, fn) {
|
2843
|
+
this._o = o;
|
2844
|
+
this._s = s;
|
2845
|
+
this._fn = fn;
|
2846
|
+
__super__.call(this);
|
2847
|
+
}
|
2848
|
+
|
2849
|
+
CatchObserver.prototype.next = function (x) { this._o.onNext(x); };
|
2850
|
+
CatchObserver.prototype.completed = function () { return this._o.onCompleted(); };
|
2851
|
+
CatchObserver.prototype.error = function (e) {
|
2852
|
+
var result = tryCatch(this._fn)(e);
|
2853
|
+
if (result === errorObj) { return this._o.onError(result.e); }
|
2854
|
+
isPromise(result) && (result = observableFromPromise(result));
|
2855
|
+
|
2856
|
+
var d = new SingleAssignmentDisposable();
|
2857
|
+
this._s.setDisposable(d);
|
2858
|
+
d.setDisposable(result.subscribe(this._o));
|
2859
|
+
};
|
2860
|
+
|
2861
|
+
return CatchObserver;
|
2862
|
+
}(AbstractObserver));
|
2863
|
+
|
2820
2864
|
function observableCatchHandler(source, handler) {
|
2821
2865
|
return new AnonymousObservable(function (o) {
|
2822
2866
|
var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
|
2823
2867
|
subscription.setDisposable(d1);
|
2824
|
-
d1.setDisposable(source.subscribe(
|
2825
|
-
try {
|
2826
|
-
var result = handler(e);
|
2827
|
-
} catch (ex) {
|
2828
|
-
return o.onError(ex);
|
2829
|
-
}
|
2830
|
-
isPromise(result) && (result = observableFromPromise(result));
|
2831
|
-
|
2832
|
-
var d = new SingleAssignmentDisposable();
|
2833
|
-
subscription.setDisposable(d);
|
2834
|
-
d.setDisposable(result.subscribe(o));
|
2835
|
-
}, function (x) { o.onCompleted(x); }));
|
2836
|
-
|
2868
|
+
d1.setDisposable(source.subscribe(new CatchObserver(o, subscription, handler)));
|
2837
2869
|
return subscription;
|
2838
2870
|
}, source);
|
2839
2871
|
}
|
2840
2872
|
|
2841
2873
|
/**
|
2842
2874
|
* Continues an observable sequence that is terminated by an exception with the next observable sequence.
|
2843
|
-
* @example
|
2844
|
-
* 1 - xs.catchException(ys)
|
2845
|
-
* 2 - xs.catchException(function (ex) { return ys(ex); })
|
2846
2875
|
* @param {Mixed} handlerOrSecond Exception handler function that returns an observable sequence given the error that occurred in the first sequence, or a second observable sequence used to produce results when an error occurred in the first sequence.
|
2847
2876
|
* @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
|
2848
2877
|
*/
|
2849
|
-
observableProto['catch'] =
|
2850
|
-
return
|
2851
|
-
observableCatchHandler(this, handlerOrSecond) :
|
2852
|
-
observableCatch([this, handlerOrSecond]);
|
2878
|
+
observableProto['catch'] = function (handlerOrSecond) {
|
2879
|
+
return isFunction(handlerOrSecond) ? observableCatchHandler(this, handlerOrSecond) : observableCatch([this, handlerOrSecond]);
|
2853
2880
|
};
|
2854
2881
|
|
2855
2882
|
/**
|
@@ -2857,12 +2884,14 @@
|
|
2857
2884
|
* @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
|
2858
2885
|
* @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
|
2859
2886
|
*/
|
2860
|
-
var observableCatch = Observable
|
2861
|
-
var items
|
2887
|
+
var observableCatch = Observable['catch'] = function () {
|
2888
|
+
var items;
|
2862
2889
|
if (Array.isArray(arguments[0])) {
|
2863
2890
|
items = arguments[0];
|
2864
2891
|
} else {
|
2865
|
-
|
2892
|
+
var len = arguments.length;
|
2893
|
+
items = new Array(len);
|
2894
|
+
for(var i = 0; i < len; i++) { items[i] = arguments[i]; }
|
2866
2895
|
}
|
2867
2896
|
return enumerableOf(items).catchError();
|
2868
2897
|
};
|
@@ -2887,6 +2916,13 @@
|
|
2887
2916
|
return combineLatest.apply(this, args);
|
2888
2917
|
};
|
2889
2918
|
|
2919
|
+
function falseFactory() { return false; }
|
2920
|
+
function argumentsToArray() {
|
2921
|
+
var len = arguments.length, args = new Array(len);
|
2922
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
2923
|
+
return args;
|
2924
|
+
}
|
2925
|
+
|
2890
2926
|
/**
|
2891
2927
|
* Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences or Promises produces an element.
|
2892
2928
|
*
|
@@ -2898,12 +2934,11 @@
|
|
2898
2934
|
var combineLatest = Observable.combineLatest = function () {
|
2899
2935
|
var len = arguments.length, args = new Array(len);
|
2900
2936
|
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
2901
|
-
var resultSelector = args.pop();
|
2937
|
+
var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
2902
2938
|
Array.isArray(args[0]) && (args = args[0]);
|
2903
2939
|
|
2904
2940
|
return new AnonymousObservable(function (o) {
|
2905
2941
|
var n = args.length,
|
2906
|
-
falseFactory = function () { return false; },
|
2907
2942
|
hasValue = arrayInitialize(n, falseFactory),
|
2908
2943
|
hasValueAll = false,
|
2909
2944
|
isDone = arrayInitialize(n, falseFactory),
|
@@ -2958,6 +2993,52 @@
|
|
2958
2993
|
return observableConcat.apply(null, args);
|
2959
2994
|
};
|
2960
2995
|
|
2996
|
+
var ConcatObservable = (function(__super__) {
|
2997
|
+
inherits(ConcatObservable, __super__);
|
2998
|
+
function ConcatObservable(sources) {
|
2999
|
+
this.sources = sources;
|
3000
|
+
__super__.call(this);
|
3001
|
+
}
|
3002
|
+
|
3003
|
+
ConcatObservable.prototype.subscribeCore = function(o) {
|
3004
|
+
var sink = new ConcatSink(this.sources, o);
|
3005
|
+
return sink.run();
|
3006
|
+
};
|
3007
|
+
|
3008
|
+
function ConcatSink(sources, o) {
|
3009
|
+
this.sources = sources;
|
3010
|
+
this.o = o;
|
3011
|
+
}
|
3012
|
+
ConcatSink.prototype.run = function () {
|
3013
|
+
var isDisposed, subscription = new SerialDisposable(), sources = this.sources, length = sources.length, o = this.o;
|
3014
|
+
var cancelable = immediateScheduler.scheduleRecursiveWithState(0, function (i, self) {
|
3015
|
+
if (isDisposed) { return; }
|
3016
|
+
if (i === length) {
|
3017
|
+
return o.onCompleted();
|
3018
|
+
}
|
3019
|
+
|
3020
|
+
// Check if promise
|
3021
|
+
var currentValue = sources[i];
|
3022
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
3023
|
+
|
3024
|
+
var d = new SingleAssignmentDisposable();
|
3025
|
+
subscription.setDisposable(d);
|
3026
|
+
d.setDisposable(currentValue.subscribe(
|
3027
|
+
function (x) { o.onNext(x); },
|
3028
|
+
function (e) { o.onError(e); },
|
3029
|
+
function () { self(i + 1); }
|
3030
|
+
));
|
3031
|
+
});
|
3032
|
+
|
3033
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
3034
|
+
isDisposed = true;
|
3035
|
+
}));
|
3036
|
+
};
|
3037
|
+
|
3038
|
+
|
3039
|
+
return ConcatObservable;
|
3040
|
+
}(ObservableBase));
|
3041
|
+
|
2961
3042
|
/**
|
2962
3043
|
* Concatenates all the observable sequences.
|
2963
3044
|
* @param {Array | Arguments} args Arguments or an array to concat to the observable sequence.
|
@@ -2971,14 +3052,14 @@
|
|
2971
3052
|
args = new Array(arguments.length);
|
2972
3053
|
for(var i = 0, len = arguments.length; i < len; i++) { args[i] = arguments[i]; }
|
2973
3054
|
}
|
2974
|
-
return
|
3055
|
+
return new ConcatObservable(args);
|
2975
3056
|
};
|
2976
3057
|
|
2977
3058
|
/**
|
2978
3059
|
* Concatenates an observable sequence of observable sequences.
|
2979
3060
|
* @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
|
2980
3061
|
*/
|
2981
|
-
observableProto.concatAll =
|
3062
|
+
observableProto.concatAll = function () {
|
2982
3063
|
return this.merge(1);
|
2983
3064
|
};
|
2984
3065
|
|
@@ -3147,11 +3228,6 @@
|
|
3147
3228
|
return g;
|
3148
3229
|
};
|
3149
3230
|
|
3150
|
-
return MergeAllObservable;
|
3151
|
-
}(ObservableBase));
|
3152
|
-
|
3153
|
-
var MergeAllObserver = (function() {
|
3154
|
-
|
3155
3231
|
function MergeAllObserver(o, g) {
|
3156
3232
|
this.o = o;
|
3157
3233
|
this.g = g;
|
@@ -3165,7 +3241,7 @@
|
|
3165
3241
|
|
3166
3242
|
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
3167
3243
|
|
3168
|
-
sad.setDisposable(innerSource.subscribe(new InnerObserver(this,
|
3244
|
+
sad.setDisposable(innerSource.subscribe(new InnerObserver(this, sad)));
|
3169
3245
|
};
|
3170
3246
|
MergeAllObserver.prototype.onError = function (e) {
|
3171
3247
|
if(!this.isStopped) {
|
@@ -3191,9 +3267,8 @@
|
|
3191
3267
|
return false;
|
3192
3268
|
};
|
3193
3269
|
|
3194
|
-
function InnerObserver(parent,
|
3270
|
+
function InnerObserver(parent, sad) {
|
3195
3271
|
this.parent = parent;
|
3196
|
-
this.g = g;
|
3197
3272
|
this.sad = sad;
|
3198
3273
|
this.isStopped = false;
|
3199
3274
|
}
|
@@ -3223,15 +3298,14 @@
|
|
3223
3298
|
return false;
|
3224
3299
|
};
|
3225
3300
|
|
3226
|
-
return
|
3227
|
-
|
3228
|
-
}());
|
3301
|
+
return MergeAllObservable;
|
3302
|
+
}(ObservableBase));
|
3229
3303
|
|
3230
3304
|
/**
|
3231
3305
|
* Merges an observable sequence of observable sequences into an observable sequence.
|
3232
3306
|
* @returns {Observable} The observable sequence that merges the elements of the inner sequences.
|
3233
3307
|
*/
|
3234
|
-
observableProto.mergeAll =
|
3308
|
+
observableProto.mergeAll = function () {
|
3235
3309
|
return new MergeAllObservable(this);
|
3236
3310
|
};
|
3237
3311
|
|
@@ -3346,87 +3420,171 @@
|
|
3346
3420
|
}, source);
|
3347
3421
|
};
|
3348
3422
|
|
3423
|
+
var SwitchObservable = (function(__super__) {
|
3424
|
+
inherits(SwitchObservable, __super__);
|
3425
|
+
function SwitchObservable(source) {
|
3426
|
+
this.source = source;
|
3427
|
+
__super__.call(this);
|
3428
|
+
}
|
3429
|
+
|
3430
|
+
SwitchObservable.prototype.subscribeCore = function (o) {
|
3431
|
+
var inner = new SerialDisposable(), s = this.source.subscribe(new SwitchObserver(o, inner));
|
3432
|
+
return new CompositeDisposable(s, inner);
|
3433
|
+
};
|
3434
|
+
|
3435
|
+
function SwitchObserver(o, inner) {
|
3436
|
+
this.o = o;
|
3437
|
+
this.inner = inner;
|
3438
|
+
this.stopped = false;
|
3439
|
+
this.latest = 0;
|
3440
|
+
this.hasLatest = false;
|
3441
|
+
this.isStopped = false;
|
3442
|
+
}
|
3443
|
+
SwitchObserver.prototype.onNext = function (innerSource) {
|
3444
|
+
if (this.isStopped) { return; }
|
3445
|
+
var d = new SingleAssignmentDisposable(), id = ++this.latest;
|
3446
|
+
this.hasLatest = true;
|
3447
|
+
this.inner.setDisposable(d);
|
3448
|
+
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
3449
|
+
d.setDisposable(innerSource.subscribe(new InnerObserver(this, id)));
|
3450
|
+
};
|
3451
|
+
SwitchObserver.prototype.onError = function (e) {
|
3452
|
+
if (!this.isStopped) {
|
3453
|
+
this.isStopped = true;
|
3454
|
+
this.o.onError(e);
|
3455
|
+
}
|
3456
|
+
};
|
3457
|
+
SwitchObserver.prototype.onCompleted = function () {
|
3458
|
+
if (!this.isStopped) {
|
3459
|
+
this.isStopped = true;
|
3460
|
+
this.stopped = true;
|
3461
|
+
!this.hasLatest && this.o.onCompleted();
|
3462
|
+
}
|
3463
|
+
};
|
3464
|
+
SwitchObserver.prototype.dispose = function () { this.isStopped = true; };
|
3465
|
+
SwitchObserver.prototype.fail = function (e) {
|
3466
|
+
if(!this.isStopped) {
|
3467
|
+
this.isStopped = true;
|
3468
|
+
this.o.onError(e);
|
3469
|
+
return true;
|
3470
|
+
}
|
3471
|
+
return false;
|
3472
|
+
};
|
3473
|
+
|
3474
|
+
function InnerObserver(parent, id) {
|
3475
|
+
this.parent = parent;
|
3476
|
+
this.id = id;
|
3477
|
+
this.isStopped = false;
|
3478
|
+
}
|
3479
|
+
InnerObserver.prototype.onNext = function (x) {
|
3480
|
+
if (this.isStopped) { return; }
|
3481
|
+
this.parent.latest === this.id && this.parent.o.onNext(x);
|
3482
|
+
};
|
3483
|
+
InnerObserver.prototype.onError = function (e) {
|
3484
|
+
if (!this.isStopped) {
|
3485
|
+
this.isStopped = true;
|
3486
|
+
this.parent.latest === this.id && this.parent.o.onError(e);
|
3487
|
+
}
|
3488
|
+
};
|
3489
|
+
InnerObserver.prototype.onCompleted = function () {
|
3490
|
+
if (!this.isStopped) {
|
3491
|
+
this.isStopped = true;
|
3492
|
+
if (this.parent.latest === this.id) {
|
3493
|
+
this.parent.hasLatest = false;
|
3494
|
+
this.parent.isStopped && this.parent.o.onCompleted();
|
3495
|
+
}
|
3496
|
+
}
|
3497
|
+
};
|
3498
|
+
InnerObserver.prototype.dispose = function () { this.isStopped = true; }
|
3499
|
+
InnerObserver.prototype.fail = function (e) {
|
3500
|
+
if(!this.isStopped) {
|
3501
|
+
this.isStopped = true;
|
3502
|
+
this.parent.o.onError(e);
|
3503
|
+
return true;
|
3504
|
+
}
|
3505
|
+
return false;
|
3506
|
+
};
|
3507
|
+
|
3508
|
+
return SwitchObservable;
|
3509
|
+
}(ObservableBase));
|
3510
|
+
|
3349
3511
|
/**
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3512
|
+
* Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
|
3513
|
+
* @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.
|
3514
|
+
*/
|
3353
3515
|
observableProto['switch'] = observableProto.switchLatest = function () {
|
3354
|
-
|
3355
|
-
return new AnonymousObservable(function (observer) {
|
3356
|
-
var hasLatest = false,
|
3357
|
-
innerSubscription = new SerialDisposable(),
|
3358
|
-
isStopped = false,
|
3359
|
-
latest = 0,
|
3360
|
-
subscription = sources.subscribe(
|
3361
|
-
function (innerSource) {
|
3362
|
-
var d = new SingleAssignmentDisposable(), id = ++latest;
|
3363
|
-
hasLatest = true;
|
3364
|
-
innerSubscription.setDisposable(d);
|
3365
|
-
|
3366
|
-
// Check if Promise or Observable
|
3367
|
-
isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
3368
|
-
|
3369
|
-
d.setDisposable(innerSource.subscribe(
|
3370
|
-
function (x) { latest === id && observer.onNext(x); },
|
3371
|
-
function (e) { latest === id && observer.onError(e); },
|
3372
|
-
function () {
|
3373
|
-
if (latest === id) {
|
3374
|
-
hasLatest = false;
|
3375
|
-
isStopped && observer.onCompleted();
|
3376
|
-
}
|
3377
|
-
}));
|
3378
|
-
},
|
3379
|
-
function (e) { observer.onError(e); },
|
3380
|
-
function () {
|
3381
|
-
isStopped = true;
|
3382
|
-
!hasLatest && observer.onCompleted();
|
3383
|
-
});
|
3384
|
-
return new CompositeDisposable(subscription, innerSubscription);
|
3385
|
-
}, sources);
|
3516
|
+
return new SwitchObservable(this);
|
3386
3517
|
};
|
3387
3518
|
|
3519
|
+
var TakeUntilObservable = (function(__super__) {
|
3520
|
+
inherits(TakeUntilObservable, __super__);
|
3521
|
+
|
3522
|
+
function TakeUntilObservable(source, other) {
|
3523
|
+
this.source = source;
|
3524
|
+
this.other = isPromise(other) ? observableFromPromise(other) : other;
|
3525
|
+
__super__.call(this);
|
3526
|
+
}
|
3527
|
+
|
3528
|
+
TakeUntilObservable.prototype.subscribeCore = function(o) {
|
3529
|
+
return new CompositeDisposable(
|
3530
|
+
this.source.subscribe(o),
|
3531
|
+
this.other.subscribe(new InnerObserver(o))
|
3532
|
+
);
|
3533
|
+
};
|
3534
|
+
|
3535
|
+
function InnerObserver(o) {
|
3536
|
+
this.o = o;
|
3537
|
+
this.isStopped = false;
|
3538
|
+
}
|
3539
|
+
InnerObserver.prototype.onNext = function (x) {
|
3540
|
+
if (this.isStopped) { return; }
|
3541
|
+
this.o.onCompleted();
|
3542
|
+
};
|
3543
|
+
InnerObserver.prototype.onError = function (err) {
|
3544
|
+
if (!this.isStopped) {
|
3545
|
+
this.isStopped = true;
|
3546
|
+
this.o.onError(err);
|
3547
|
+
}
|
3548
|
+
};
|
3549
|
+
InnerObserver.prototype.onCompleted = function () {
|
3550
|
+
!this.isStopped && (this.isStopped = true);
|
3551
|
+
};
|
3552
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
3553
|
+
InnerObserver.prototype.fail = function (e) {
|
3554
|
+
if (!this.isStopped) {
|
3555
|
+
this.isStopped = true;
|
3556
|
+
this.o.onError(e);
|
3557
|
+
return true;
|
3558
|
+
}
|
3559
|
+
return false;
|
3560
|
+
};
|
3561
|
+
|
3562
|
+
return TakeUntilObservable;
|
3563
|
+
}(ObservableBase));
|
3564
|
+
|
3388
3565
|
/**
|
3389
3566
|
* Returns the values from the source observable sequence until the other observable sequence produces a value.
|
3390
3567
|
* @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence.
|
3391
3568
|
* @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
|
3392
3569
|
*/
|
3393
3570
|
observableProto.takeUntil = function (other) {
|
3394
|
-
|
3395
|
-
return new AnonymousObservable(function (o) {
|
3396
|
-
isPromise(other) && (other = observableFromPromise(other));
|
3397
|
-
return new CompositeDisposable(
|
3398
|
-
source.subscribe(o),
|
3399
|
-
other.subscribe(function () { o.onCompleted(); }, function (e) { o.onError(e); }, noop)
|
3400
|
-
);
|
3401
|
-
}, source);
|
3571
|
+
return new TakeUntilObservable(this, other);
|
3402
3572
|
};
|
3403
3573
|
|
3574
|
+
function falseFactory() { return false; }
|
3575
|
+
|
3404
3576
|
/**
|
3405
3577
|
* Merges the specified observable sequences into one observable sequence by using the selector function only when the (first) source observable sequence produces an element.
|
3406
|
-
*
|
3407
|
-
* @example
|
3408
|
-
* 1 - obs = obs1.withLatestFrom(obs2, obs3, function (o1, o2, o3) { return o1 + o2 + o3; });
|
3409
|
-
* 2 - obs = obs1.withLatestFrom([obs2, obs3], function (o1, o2, o3) { return o1 + o2 + o3; });
|
3410
3578
|
* @returns {Observable} An observable sequence containing the result of combining elements of the sources using the specified result selector function.
|
3411
3579
|
*/
|
3412
3580
|
observableProto.withLatestFrom = function () {
|
3413
3581
|
var len = arguments.length, args = new Array(len)
|
3414
3582
|
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3415
3583
|
var resultSelector = args.pop(), source = this;
|
3416
|
-
|
3417
|
-
if (typeof source === 'undefined') {
|
3418
|
-
throw new Error('Source observable not found for withLatestFrom().');
|
3419
|
-
}
|
3420
|
-
if (typeof resultSelector !== 'function') {
|
3421
|
-
throw new Error('withLatestFrom() expects a resultSelector function.');
|
3422
|
-
}
|
3423
|
-
if (Array.isArray(args[0])) {
|
3424
|
-
args = args[0];
|
3425
|
-
}
|
3584
|
+
Array.isArray(args[0]) && (args = args[0]);
|
3426
3585
|
|
3427
3586
|
return new AnonymousObservable(function (observer) {
|
3428
|
-
var
|
3429
|
-
n = args.length,
|
3587
|
+
var n = args.length,
|
3430
3588
|
hasValue = arrayInitialize(n, falseFactory),
|
3431
3589
|
hasValueAll = false,
|
3432
3590
|
values = new Array(n);
|
@@ -3440,24 +3598,19 @@
|
|
3440
3598
|
values[i] = x;
|
3441
3599
|
hasValue[i] = true;
|
3442
3600
|
hasValueAll = hasValue.every(identity);
|
3443
|
-
},
|
3601
|
+
}, function (e) { observer.onError(e); }, noop));
|
3444
3602
|
subscriptions[i] = sad;
|
3445
3603
|
}(idx));
|
3446
3604
|
}
|
3447
3605
|
|
3448
3606
|
var sad = new SingleAssignmentDisposable();
|
3449
3607
|
sad.setDisposable(source.subscribe(function (x) {
|
3450
|
-
var res;
|
3451
3608
|
var allValues = [x].concat(values);
|
3452
|
-
if (!hasValueAll) return;
|
3453
|
-
|
3454
|
-
|
3455
|
-
} catch (ex) {
|
3456
|
-
observer.onError(ex);
|
3457
|
-
return;
|
3458
|
-
}
|
3609
|
+
if (!hasValueAll) { return; }
|
3610
|
+
var res = tryCatch(resultSelector).apply(null, allValues);
|
3611
|
+
if (res === errorObj) { return observer.onError(res.e); }
|
3459
3612
|
observer.onNext(res);
|
3460
|
-
}, observer.onError
|
3613
|
+
}, function (e) { observer.onError(e); }, function () {
|
3461
3614
|
observer.onCompleted();
|
3462
3615
|
}));
|
3463
3616
|
subscriptions[n] = sad;
|
@@ -3466,83 +3619,54 @@
|
|
3466
3619
|
}, this);
|
3467
3620
|
};
|
3468
3621
|
|
3469
|
-
function zipArray(second, resultSelector) {
|
3470
|
-
var first = this;
|
3471
|
-
return new AnonymousObservable(function (observer) {
|
3472
|
-
var index = 0, len = second.length;
|
3473
|
-
return first.subscribe(function (left) {
|
3474
|
-
if (index < len) {
|
3475
|
-
var right = second[index++], result;
|
3476
|
-
try {
|
3477
|
-
result = resultSelector(left, right);
|
3478
|
-
} catch (e) {
|
3479
|
-
return observer.onError(e);
|
3480
|
-
}
|
3481
|
-
observer.onNext(result);
|
3482
|
-
} else {
|
3483
|
-
observer.onCompleted();
|
3484
|
-
}
|
3485
|
-
}, function (e) { observer.onError(e); }, function () { observer.onCompleted(); });
|
3486
|
-
}, first);
|
3487
|
-
}
|
3488
|
-
|
3489
3622
|
function falseFactory() { return false; }
|
3490
3623
|
function emptyArrayFactory() { return []; }
|
3624
|
+
function argumentsToArray() {
|
3625
|
+
var len = arguments.length, args = new Array(len);
|
3626
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3627
|
+
return args;
|
3628
|
+
}
|
3491
3629
|
|
3492
3630
|
/**
|
3493
3631
|
* Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences or an array have produced an element at a corresponding index.
|
3494
3632
|
* The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
|
3495
|
-
*
|
3496
|
-
* @example
|
3497
|
-
* 1 - res = obs1.zip(obs2, fn);
|
3498
|
-
* 1 - res = x1.zip([1,2,3], fn);
|
3499
3633
|
* @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
|
3500
3634
|
*/
|
3501
3635
|
observableProto.zip = function () {
|
3502
|
-
if (
|
3636
|
+
if (arguments.length === 0) { throw new Error('invalid arguments'); }
|
3637
|
+
|
3503
3638
|
var len = arguments.length, args = new Array(len);
|
3504
3639
|
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3640
|
+
var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
3641
|
+
Array.isArray(args[0]) && (args = args[0]);
|
3505
3642
|
|
3506
|
-
var parent = this
|
3643
|
+
var parent = this;
|
3507
3644
|
args.unshift(parent);
|
3508
|
-
return new AnonymousObservable(function (
|
3645
|
+
return new AnonymousObservable(function (o) {
|
3509
3646
|
var n = args.length,
|
3510
3647
|
queues = arrayInitialize(n, emptyArrayFactory),
|
3511
3648
|
isDone = arrayInitialize(n, falseFactory);
|
3512
3649
|
|
3513
|
-
function next(i) {
|
3514
|
-
var res, queuedValues;
|
3515
|
-
if (queues.every(function (x) { return x.length > 0; })) {
|
3516
|
-
try {
|
3517
|
-
queuedValues = queues.map(function (x) { return x.shift(); });
|
3518
|
-
res = resultSelector.apply(parent, queuedValues);
|
3519
|
-
} catch (ex) {
|
3520
|
-
observer.onError(ex);
|
3521
|
-
return;
|
3522
|
-
}
|
3523
|
-
observer.onNext(res);
|
3524
|
-
} else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
|
3525
|
-
observer.onCompleted();
|
3526
|
-
}
|
3527
|
-
};
|
3528
|
-
|
3529
|
-
function done(i) {
|
3530
|
-
isDone[i] = true;
|
3531
|
-
if (isDone.every(function (x) { return x; })) {
|
3532
|
-
observer.onCompleted();
|
3533
|
-
}
|
3534
|
-
}
|
3535
|
-
|
3536
3650
|
var subscriptions = new Array(n);
|
3537
3651
|
for (var idx = 0; idx < n; idx++) {
|
3538
3652
|
(function (i) {
|
3539
3653
|
var source = args[i], sad = new SingleAssignmentDisposable();
|
3654
|
+
|
3540
3655
|
isPromise(source) && (source = observableFromPromise(source));
|
3656
|
+
|
3541
3657
|
sad.setDisposable(source.subscribe(function (x) {
|
3542
3658
|
queues[i].push(x);
|
3543
|
-
|
3544
|
-
|
3545
|
-
|
3659
|
+
if (queues.every(function (x) { return x.length > 0; })) {
|
3660
|
+
var queuedValues = queues.map(function (x) { return x.shift(); }),
|
3661
|
+
res = tryCatch(resultSelector).apply(parent, queuedValues);
|
3662
|
+
if (res === errorObj) { return o.onError(res.e); }
|
3663
|
+
o.onNext(res);
|
3664
|
+
} else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
|
3665
|
+
o.onCompleted();
|
3666
|
+
}
|
3667
|
+
}, function (e) { o.onError(e); }, function () {
|
3668
|
+
isDone[i] = true;
|
3669
|
+
isDone.every(identity) && o.onCompleted();
|
3546
3670
|
}));
|
3547
3671
|
subscriptions[i] = sad;
|
3548
3672
|
})(idx);
|
@@ -3565,67 +3689,72 @@
|
|
3565
3689
|
return first.zip.apply(first, args);
|
3566
3690
|
};
|
3567
3691
|
|
3568
|
-
|
3569
|
-
|
3570
|
-
|
3571
|
-
|
3572
|
-
|
3573
|
-
|
3574
|
-
|
3575
|
-
|
3576
|
-
|
3577
|
-
|
3578
|
-
|
3579
|
-
|
3580
|
-
|
3692
|
+
function falseFactory() { return false; }
|
3693
|
+
function emptyArrayFactory() { return []; }
|
3694
|
+
function argumentsToArray() {
|
3695
|
+
var len = arguments.length, args = new Array(len);
|
3696
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3697
|
+
return args;
|
3698
|
+
}
|
3699
|
+
|
3700
|
+
/**
|
3701
|
+
* Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences or an array have produced an element at a corresponding index.
|
3702
|
+
* The last element in the arguments must be a function to invoke for each series of elements at corresponding indexes in the args.
|
3703
|
+
* @returns {Observable} An observable sequence containing the result of combining elements of the args using the specified result selector function.
|
3704
|
+
*/
|
3705
|
+
observableProto.zipIterable = function () {
|
3706
|
+
if (arguments.length === 0) { throw new Error('invalid arguments'); }
|
3707
|
+
|
3708
|
+
var len = arguments.length, args = new Array(len);
|
3709
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3710
|
+
var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
3711
|
+
|
3712
|
+
var parent = this;
|
3713
|
+
args.unshift(parent);
|
3714
|
+
return new AnonymousObservable(function (o) {
|
3715
|
+
var n = args.length,
|
3716
|
+
queues = arrayInitialize(n, emptyArrayFactory),
|
3717
|
+
isDone = arrayInitialize(n, falseFactory);
|
3718
|
+
|
3719
|
+
var subscriptions = new Array(n);
|
3720
|
+
for (var idx = 0; idx < n; idx++) {
|
3721
|
+
(function (i) {
|
3722
|
+
var source = args[i], sad = new SingleAssignmentDisposable();
|
3723
|
+
|
3724
|
+
(isArrayLike(source) || isIterable(source)) && (source = observableFrom(source));
|
3725
|
+
|
3726
|
+
sad.setDisposable(source.subscribe(function (x) {
|
3727
|
+
queues[i].push(x);
|
3728
|
+
if (queues.every(function (x) { return x.length > 0; })) {
|
3729
|
+
var queuedValues = queues.map(function (x) { return x.shift(); }),
|
3730
|
+
res = tryCatch(resultSelector).apply(parent, queuedValues);
|
3731
|
+
if (res === errorObj) { return o.onError(res.e); }
|
3732
|
+
o.onNext(res);
|
3733
|
+
} else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
|
3734
|
+
o.onCompleted();
|
3735
|
+
}
|
3736
|
+
}, function (e) { o.onError(e); }, function () {
|
3737
|
+
isDone[i] = true;
|
3738
|
+
isDone.every(identity) && o.onCompleted();
|
3739
|
+
}));
|
3740
|
+
subscriptions[i] = sad;
|
3741
|
+
})(idx);
|
3581
3742
|
}
|
3582
|
-
return new AnonymousObservable(function (observer) {
|
3583
|
-
var n = sources.length,
|
3584
|
-
queues = arrayInitialize(n, function () { return []; }),
|
3585
|
-
isDone = arrayInitialize(n, function () { return false; });
|
3586
|
-
|
3587
|
-
function next(i) {
|
3588
|
-
if (queues.every(function (x) { return x.length > 0; })) {
|
3589
|
-
var res = queues.map(function (x) { return x.shift(); });
|
3590
|
-
observer.onNext(res);
|
3591
|
-
} else if (isDone.filter(function (x, j) { return j !== i; }).every(identity)) {
|
3592
|
-
observer.onCompleted();
|
3593
|
-
return;
|
3594
|
-
}
|
3595
|
-
};
|
3596
|
-
|
3597
|
-
function done(i) {
|
3598
|
-
isDone[i] = true;
|
3599
|
-
if (isDone.every(identity)) {
|
3600
|
-
observer.onCompleted();
|
3601
|
-
return;
|
3602
|
-
}
|
3603
|
-
}
|
3604
3743
|
|
3605
|
-
|
3606
|
-
|
3607
|
-
|
3608
|
-
subscriptions[i] = new SingleAssignmentDisposable();
|
3609
|
-
subscriptions[i].setDisposable(sources[i].subscribe(function (x) {
|
3610
|
-
queues[i].push(x);
|
3611
|
-
next(i);
|
3612
|
-
}, function (e) { observer.onError(e); }, function () {
|
3613
|
-
done(i);
|
3614
|
-
}));
|
3615
|
-
})(idx);
|
3616
|
-
}
|
3744
|
+
return new CompositeDisposable(subscriptions);
|
3745
|
+
}, parent);
|
3746
|
+
};
|
3617
3747
|
|
3618
|
-
|
3619
|
-
|
3620
|
-
}
|
3748
|
+
function asObservable(source) {
|
3749
|
+
return function subscribe(o) { return source.subscribe(o); };
|
3750
|
+
}
|
3621
3751
|
|
3622
3752
|
/**
|
3623
3753
|
* Hides the identity of an observable sequence.
|
3624
3754
|
* @returns {Observable} An observable sequence that hides the identity of the source sequence.
|
3625
3755
|
*/
|
3626
3756
|
observableProto.asObservable = function () {
|
3627
|
-
|
3628
|
-
return new AnonymousObservable(function (o) { return source.subscribe(o); }, this);
|
3757
|
+
return new AnonymousObservable(asObservable(this), this);
|
3629
3758
|
};
|
3630
3759
|
|
3631
3760
|
/**
|
@@ -3639,118 +3768,167 @@
|
|
3639
3768
|
}, this);
|
3640
3769
|
};
|
3641
3770
|
|
3771
|
+
var DistinctUntilChangedObservable = (function(__super__) {
|
3772
|
+
inherits(DistinctUntilChangedObservable, __super__);
|
3773
|
+
function DistinctUntilChangedObservable(source, keyFn, comparer) {
|
3774
|
+
this.source = source;
|
3775
|
+
this.keyFn = keyFn;
|
3776
|
+
this.comparer = comparer;
|
3777
|
+
__super__.call(this);
|
3778
|
+
}
|
3779
|
+
|
3780
|
+
DistinctUntilChangedObservable.prototype.subscribeCore = function (o) {
|
3781
|
+
return this.source.subscribe(new DistinctUntilChangedObserver(o, this.keyFn, this.comparer));
|
3782
|
+
};
|
3783
|
+
|
3784
|
+
return DistinctUntilChangedObservable;
|
3785
|
+
}(ObservableBase));
|
3786
|
+
|
3787
|
+
var DistinctUntilChangedObserver = (function(__super__) {
|
3788
|
+
inherits(DistinctUntilChangedObserver, __super__);
|
3789
|
+
function DistinctUntilChangedObserver(o, keyFn, comparer) {
|
3790
|
+
this.o = o;
|
3791
|
+
this.keyFn = keyFn;
|
3792
|
+
this.comparer = comparer;
|
3793
|
+
this.hasCurrentKey = false;
|
3794
|
+
this.currentKey = null;
|
3795
|
+
__super__.call(this);
|
3796
|
+
}
|
3797
|
+
|
3798
|
+
DistinctUntilChangedObserver.prototype.next = function (x) {
|
3799
|
+
var key = x, comparerEquals;
|
3800
|
+
if (isFunction(this.keyFn)) {
|
3801
|
+
key = tryCatch(this.keyFn)(x);
|
3802
|
+
if (key === errorObj) { return this.o.onError(key.e); }
|
3803
|
+
}
|
3804
|
+
if (this.hasCurrentKey) {
|
3805
|
+
comparerEquals = tryCatch(this.comparer)(this.currentKey, key);
|
3806
|
+
if (comparerEquals === errorObj) { return this.o.onError(comparerEquals.e); }
|
3807
|
+
}
|
3808
|
+
if (!this.hasCurrentKey || !comparerEquals) {
|
3809
|
+
this.hasCurrentKey = true;
|
3810
|
+
this.currentKey = key;
|
3811
|
+
this.o.onNext(x);
|
3812
|
+
}
|
3813
|
+
};
|
3814
|
+
DistinctUntilChangedObserver.prototype.error = function(e) {
|
3815
|
+
this.o.onError(e);
|
3816
|
+
};
|
3817
|
+
DistinctUntilChangedObserver.prototype.completed = function () {
|
3818
|
+
this.o.onCompleted();
|
3819
|
+
};
|
3820
|
+
|
3821
|
+
return DistinctUntilChangedObserver;
|
3822
|
+
}(AbstractObserver));
|
3823
|
+
|
3642
3824
|
/**
|
3643
|
-
|
3644
|
-
|
3645
|
-
|
3646
|
-
|
3647
|
-
|
3648
|
-
|
3649
|
-
* @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
|
3650
|
-
* @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
|
3651
|
-
* @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
|
3652
|
-
*/
|
3653
|
-
observableProto.distinctUntilChanged = function (keySelector, comparer) {
|
3654
|
-
var source = this;
|
3825
|
+
* Returns an observable sequence that contains only distinct contiguous elements according to the keyFn and the comparer.
|
3826
|
+
* @param {Function} [keyFn] A function to compute the comparison key for each element. If not provided, it projects the value.
|
3827
|
+
* @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
|
3828
|
+
* @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
|
3829
|
+
*/
|
3830
|
+
observableProto.distinctUntilChanged = function (keyFn, comparer) {
|
3655
3831
|
comparer || (comparer = defaultComparer);
|
3656
|
-
return new
|
3657
|
-
var hasCurrentKey = false, currentKey;
|
3658
|
-
return source.subscribe(function (value) {
|
3659
|
-
var key = value;
|
3660
|
-
if (keySelector) {
|
3661
|
-
try {
|
3662
|
-
key = keySelector(value);
|
3663
|
-
} catch (e) {
|
3664
|
-
o.onError(e);
|
3665
|
-
return;
|
3666
|
-
}
|
3667
|
-
}
|
3668
|
-
if (hasCurrentKey) {
|
3669
|
-
try {
|
3670
|
-
var comparerEquals = comparer(currentKey, key);
|
3671
|
-
} catch (e) {
|
3672
|
-
o.onError(e);
|
3673
|
-
return;
|
3674
|
-
}
|
3675
|
-
}
|
3676
|
-
if (!hasCurrentKey || !comparerEquals) {
|
3677
|
-
hasCurrentKey = true;
|
3678
|
-
currentKey = key;
|
3679
|
-
o.onNext(value);
|
3680
|
-
}
|
3681
|
-
}, function (e) { o.onError(e); }, function () { o.onCompleted(); });
|
3682
|
-
}, this);
|
3832
|
+
return new DistinctUntilChangedObservable(this, keyFn, comparer);
|
3683
3833
|
};
|
3684
3834
|
|
3835
|
+
var TapObservable = (function(__super__) {
|
3836
|
+
inherits(TapObservable,__super__);
|
3837
|
+
function TapObservable(source, observerOrOnNext, onError, onCompleted) {
|
3838
|
+
this.source = source;
|
3839
|
+
this._oN = observerOrOnNext;
|
3840
|
+
this._oE = onError;
|
3841
|
+
this._oC = onCompleted;
|
3842
|
+
__super__.call(this);
|
3843
|
+
}
|
3844
|
+
|
3845
|
+
TapObservable.prototype.subscribeCore = function(o) {
|
3846
|
+
return this.source.subscribe(new InnerObserver(o, this));
|
3847
|
+
};
|
3848
|
+
|
3849
|
+
function InnerObserver(o, p) {
|
3850
|
+
this.o = o;
|
3851
|
+
this.t = !p._oN || isFunction(p._oN) ?
|
3852
|
+
observerCreate(p._oN || noop, p._oE || noop, p._oC || noop) :
|
3853
|
+
p._oN;
|
3854
|
+
this.isStopped = false;
|
3855
|
+
}
|
3856
|
+
InnerObserver.prototype.onNext = function(x) {
|
3857
|
+
if (this.isStopped) { return; }
|
3858
|
+
var res = tryCatch(this.t.onNext).call(this.t, x);
|
3859
|
+
if (res === errorObj) { this.o.onError(res.e); }
|
3860
|
+
this.o.onNext(x);
|
3861
|
+
};
|
3862
|
+
InnerObserver.prototype.onError = function(err) {
|
3863
|
+
if (!this.isStopped) {
|
3864
|
+
this.isStopped = true;
|
3865
|
+
var res = tryCatch(this.t.onError).call(this.t, err);
|
3866
|
+
if (res === errorObj) { return this.o.onError(res.e); }
|
3867
|
+
this.o.onError(err);
|
3868
|
+
}
|
3869
|
+
};
|
3870
|
+
InnerObserver.prototype.onCompleted = function() {
|
3871
|
+
if (!this.isStopped) {
|
3872
|
+
this.isStopped = true;
|
3873
|
+
var res = tryCatch(this.t.onCompleted).call(this.t);
|
3874
|
+
if (res === errorObj) { return this.o.onError(res.e); }
|
3875
|
+
this.o.onCompleted();
|
3876
|
+
}
|
3877
|
+
};
|
3878
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
3879
|
+
InnerObserver.prototype.fail = function (e) {
|
3880
|
+
if (!this.isStopped) {
|
3881
|
+
this.isStopped = true;
|
3882
|
+
this.o.onError(e);
|
3883
|
+
return true;
|
3884
|
+
}
|
3885
|
+
return false;
|
3886
|
+
};
|
3887
|
+
|
3888
|
+
return TapObservable;
|
3889
|
+
}(ObservableBase));
|
3890
|
+
|
3685
3891
|
/**
|
3686
|
-
|
3687
|
-
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
|
3892
|
+
* Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
|
3893
|
+
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
3894
|
+
* @param {Function | Observer} observerOrOnNext Action to invoke for each element in the observable sequence or an o.
|
3895
|
+
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
3896
|
+
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
|
3897
|
+
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
3898
|
+
*/
|
3693
3899
|
observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
|
3694
|
-
|
3695
|
-
return new AnonymousObservable(function (observer) {
|
3696
|
-
var tapObserver = !observerOrOnNext || isFunction(observerOrOnNext) ?
|
3697
|
-
observerCreate(observerOrOnNext || noop, onError || noop, onCompleted || noop) :
|
3698
|
-
observerOrOnNext;
|
3699
|
-
|
3700
|
-
return source.subscribe(function (x) {
|
3701
|
-
try {
|
3702
|
-
tapObserver.onNext(x);
|
3703
|
-
} catch (e) {
|
3704
|
-
observer.onError(e);
|
3705
|
-
}
|
3706
|
-
observer.onNext(x);
|
3707
|
-
}, function (err) {
|
3708
|
-
try {
|
3709
|
-
tapObserver.onError(err);
|
3710
|
-
} catch (e) {
|
3711
|
-
observer.onError(e);
|
3712
|
-
}
|
3713
|
-
observer.onError(err);
|
3714
|
-
}, function () {
|
3715
|
-
try {
|
3716
|
-
tapObserver.onCompleted();
|
3717
|
-
} catch (e) {
|
3718
|
-
observer.onError(e);
|
3719
|
-
}
|
3720
|
-
observer.onCompleted();
|
3721
|
-
});
|
3722
|
-
}, this);
|
3900
|
+
return new TapObservable(this, observerOrOnNext, onError, onCompleted);
|
3723
3901
|
};
|
3724
3902
|
|
3725
3903
|
/**
|
3726
|
-
|
3727
|
-
|
3728
|
-
|
3729
|
-
|
3730
|
-
|
3731
|
-
|
3904
|
+
* Invokes an action for each element in the observable sequence.
|
3905
|
+
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
3906
|
+
* @param {Function} onNext Action to invoke for each element in the observable sequence.
|
3907
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3908
|
+
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
3909
|
+
*/
|
3732
3910
|
observableProto.doOnNext = observableProto.tapOnNext = function (onNext, thisArg) {
|
3733
3911
|
return this.tap(typeof thisArg !== 'undefined' ? function (x) { onNext.call(thisArg, x); } : onNext);
|
3734
3912
|
};
|
3735
3913
|
|
3736
3914
|
/**
|
3737
|
-
|
3738
|
-
|
3739
|
-
|
3740
|
-
|
3741
|
-
|
3742
|
-
|
3915
|
+
* Invokes an action upon exceptional termination of the observable sequence.
|
3916
|
+
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
3917
|
+
* @param {Function} onError Action to invoke upon exceptional termination of the observable sequence.
|
3918
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3919
|
+
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
3920
|
+
*/
|
3743
3921
|
observableProto.doOnError = observableProto.tapOnError = function (onError, thisArg) {
|
3744
3922
|
return this.tap(noop, typeof thisArg !== 'undefined' ? function (e) { onError.call(thisArg, e); } : onError);
|
3745
3923
|
};
|
3746
3924
|
|
3747
3925
|
/**
|
3748
|
-
|
3749
|
-
|
3750
|
-
|
3751
|
-
|
3752
|
-
|
3753
|
-
|
3926
|
+
* Invokes an action upon graceful termination of the observable sequence.
|
3927
|
+
* This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.
|
3928
|
+
* @param {Function} onCompleted Action to invoke upon graceful termination of the observable sequence.
|
3929
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
3930
|
+
* @returns {Observable} The source sequence with the side-effecting behavior applied.
|
3931
|
+
*/
|
3754
3932
|
observableProto.doOnCompleted = observableProto.tapOnCompleted = function (onCompleted, thisArg) {
|
3755
3933
|
return this.tap(noop, null, typeof thisArg !== 'undefined' ? function () { onCompleted.call(thisArg); } : onCompleted);
|
3756
3934
|
};
|
@@ -3760,45 +3938,71 @@
|
|
3760
3938
|
* @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
|
3761
3939
|
* @returns {Observable} Source sequence with the action-invoking termination behavior applied.
|
3762
3940
|
*/
|
3763
|
-
observableProto['finally'] =
|
3941
|
+
observableProto['finally'] = function (action) {
|
3764
3942
|
var source = this;
|
3765
3943
|
return new AnonymousObservable(function (observer) {
|
3766
|
-
var subscription;
|
3767
|
-
|
3768
|
-
subscription = source.subscribe(observer);
|
3769
|
-
} catch (e) {
|
3944
|
+
var subscription = tryCatch(source.subscribe).call(source, observer);
|
3945
|
+
if (subscription === errorObj) {
|
3770
3946
|
action();
|
3771
|
-
|
3947
|
+
return thrower(subscription.e);
|
3772
3948
|
}
|
3773
3949
|
return disposableCreate(function () {
|
3774
|
-
|
3775
|
-
|
3776
|
-
|
3777
|
-
throw e;
|
3778
|
-
} finally {
|
3779
|
-
action();
|
3780
|
-
}
|
3950
|
+
var r = tryCatch(subscription.dispose).call(subscription);
|
3951
|
+
action();
|
3952
|
+
r === errorObj && thrower(r.e);
|
3781
3953
|
});
|
3782
3954
|
}, this);
|
3783
3955
|
};
|
3784
3956
|
|
3785
|
-
|
3786
|
-
|
3787
|
-
|
3788
|
-
|
3789
|
-
|
3790
|
-
|
3791
|
-
|
3957
|
+
var IgnoreElementsObservable = (function(__super__) {
|
3958
|
+
inherits(IgnoreElementsObservable, __super__);
|
3959
|
+
|
3960
|
+
function IgnoreElementsObservable(source) {
|
3961
|
+
this.source = source;
|
3962
|
+
__super__.call(this);
|
3963
|
+
}
|
3964
|
+
|
3965
|
+
IgnoreElementsObservable.prototype.subscribeCore = function (o) {
|
3966
|
+
return this.source.subscribe(new InnerObserver(o));
|
3967
|
+
};
|
3968
|
+
|
3969
|
+
function InnerObserver(o) {
|
3970
|
+
this.o = o;
|
3971
|
+
this.isStopped = false;
|
3972
|
+
}
|
3973
|
+
InnerObserver.prototype.onNext = noop;
|
3974
|
+
InnerObserver.prototype.onError = function (err) {
|
3975
|
+
if(!this.isStopped) {
|
3976
|
+
this.isStopped = true;
|
3977
|
+
this.o.onError(err);
|
3978
|
+
}
|
3979
|
+
};
|
3980
|
+
InnerObserver.prototype.onCompleted = function () {
|
3981
|
+
if(!this.isStopped) {
|
3982
|
+
this.isStopped = true;
|
3983
|
+
this.o.onCompleted();
|
3984
|
+
}
|
3985
|
+
};
|
3986
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
3987
|
+
InnerObserver.prototype.fail = function (e) {
|
3988
|
+
if (!this.isStopped) {
|
3989
|
+
this.isStopped = true;
|
3990
|
+
this.observer.onError(e);
|
3991
|
+
return true;
|
3992
|
+
}
|
3993
|
+
|
3994
|
+
return false;
|
3995
|
+
};
|
3996
|
+
|
3997
|
+
return IgnoreElementsObservable;
|
3998
|
+
}(ObservableBase));
|
3792
3999
|
|
3793
4000
|
/**
|
3794
4001
|
* Ignores all elements in an observable sequence leaving only the termination messages.
|
3795
4002
|
* @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
|
3796
4003
|
*/
|
3797
4004
|
observableProto.ignoreElements = function () {
|
3798
|
-
|
3799
|
-
return new AnonymousObservable(function (o) {
|
3800
|
-
return source.subscribe(noop, function (e) { o.onError(e); }, function () { o.onCompleted(); });
|
3801
|
-
}, source);
|
4005
|
+
return new IgnoreElementsObservable(this);
|
3802
4006
|
};
|
3803
4007
|
|
3804
4008
|
/**
|
@@ -3856,51 +4060,84 @@
|
|
3856
4060
|
observableProto.retryWhen = function (notifier) {
|
3857
4061
|
return enumerableRepeat(this).catchErrorWhen(notifier);
|
3858
4062
|
};
|
4063
|
+
var ScanObservable = (function(__super__) {
|
4064
|
+
inherits(ScanObservable, __super__);
|
4065
|
+
function ScanObservable(source, accumulator, hasSeed, seed) {
|
4066
|
+
this.source = source;
|
4067
|
+
this.accumulator = accumulator;
|
4068
|
+
this.hasSeed = hasSeed;
|
4069
|
+
this.seed = seed;
|
4070
|
+
__super__.call(this);
|
4071
|
+
}
|
4072
|
+
|
4073
|
+
ScanObservable.prototype.subscribeCore = function(o) {
|
4074
|
+
return this.source.subscribe(new InnerObserver(o,this));
|
4075
|
+
};
|
4076
|
+
|
4077
|
+
return ScanObservable;
|
4078
|
+
}(ObservableBase));
|
4079
|
+
|
4080
|
+
function InnerObserver(o, parent) {
|
4081
|
+
this.o = o;
|
4082
|
+
this.accumulator = parent.accumulator;
|
4083
|
+
this.hasSeed = parent.hasSeed;
|
4084
|
+
this.seed = parent.seed;
|
4085
|
+
this.hasAccumulation = false;
|
4086
|
+
this.accumulation = null;
|
4087
|
+
this.hasValue = false;
|
4088
|
+
this.isStopped = false;
|
4089
|
+
}
|
4090
|
+
InnerObserver.prototype = {
|
4091
|
+
onNext: function (x) {
|
4092
|
+
if (this.isStopped) { return; }
|
4093
|
+
!this.hasValue && (this.hasValue = true);
|
4094
|
+
if (this.hasAccumulation) {
|
4095
|
+
this.accumulation = tryCatch(this.accumulator)(this.accumulation, x);
|
4096
|
+
} else {
|
4097
|
+
this.accumulation = this.hasSeed ? tryCatch(this.accumulator)(this.seed, x) : x;
|
4098
|
+
this.hasAccumulation = true;
|
4099
|
+
}
|
4100
|
+
if (this.accumulation === errorObj) { return this.o.onError(this.accumulation.e); }
|
4101
|
+
this.o.onNext(this.accumulation);
|
4102
|
+
},
|
4103
|
+
onError: function (e) {
|
4104
|
+
if (!this.isStopped) {
|
4105
|
+
this.isStopped = true;
|
4106
|
+
this.o.onError(e);
|
4107
|
+
}
|
4108
|
+
},
|
4109
|
+
onCompleted: function () {
|
4110
|
+
if (!this.isStopped) {
|
4111
|
+
this.isStopped = true;
|
4112
|
+
!this.hasValue && this.hasSeed && this.o.onNext(this.seed);
|
4113
|
+
this.o.onCompleted();
|
4114
|
+
}
|
4115
|
+
},
|
4116
|
+
dispose: function() { this.isStopped = true; },
|
4117
|
+
fail: function (e) {
|
4118
|
+
if (!this.isStopped) {
|
4119
|
+
this.isStopped = true;
|
4120
|
+
this.o.onError(e);
|
4121
|
+
return true;
|
4122
|
+
}
|
4123
|
+
return false;
|
4124
|
+
}
|
4125
|
+
};
|
4126
|
+
|
3859
4127
|
/**
|
3860
|
-
|
3861
|
-
|
3862
|
-
|
3863
|
-
|
3864
|
-
|
3865
|
-
|
3866
|
-
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
3867
|
-
* @returns {Observable} An observable sequence containing the accumulated values.
|
3868
|
-
*/
|
4128
|
+
* Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
|
4129
|
+
* For aggregation behavior with no intermediate results, see Observable.aggregate.
|
4130
|
+
* @param {Mixed} [seed] The initial accumulator value.
|
4131
|
+
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
4132
|
+
* @returns {Observable} An observable sequence containing the accumulated values.
|
4133
|
+
*/
|
3869
4134
|
observableProto.scan = function () {
|
3870
|
-
var hasSeed = false, seed, accumulator
|
4135
|
+
var hasSeed = false, seed, accumulator = arguments[0];
|
3871
4136
|
if (arguments.length === 2) {
|
3872
4137
|
hasSeed = true;
|
3873
|
-
seed = arguments[
|
3874
|
-
accumulator = arguments[1];
|
3875
|
-
} else {
|
3876
|
-
accumulator = arguments[0];
|
4138
|
+
seed = arguments[1];
|
3877
4139
|
}
|
3878
|
-
return new
|
3879
|
-
var hasAccumulation, accumulation, hasValue;
|
3880
|
-
return source.subscribe (
|
3881
|
-
function (x) {
|
3882
|
-
!hasValue && (hasValue = true);
|
3883
|
-
try {
|
3884
|
-
if (hasAccumulation) {
|
3885
|
-
accumulation = accumulator(accumulation, x);
|
3886
|
-
} else {
|
3887
|
-
accumulation = hasSeed ? accumulator(seed, x) : x;
|
3888
|
-
hasAccumulation = true;
|
3889
|
-
}
|
3890
|
-
} catch (e) {
|
3891
|
-
o.onError(e);
|
3892
|
-
return;
|
3893
|
-
}
|
3894
|
-
|
3895
|
-
o.onNext(accumulation);
|
3896
|
-
},
|
3897
|
-
function (e) { o.onError(e); },
|
3898
|
-
function () {
|
3899
|
-
!hasValue && hasSeed && o.onNext(seed);
|
3900
|
-
o.onCompleted();
|
3901
|
-
}
|
3902
|
-
);
|
3903
|
-
}, source);
|
4140
|
+
return new ScanObservable(this, accumulator, hasSeed, seed);
|
3904
4141
|
};
|
3905
4142
|
|
3906
4143
|
/**
|
@@ -3966,52 +4203,9 @@
|
|
3966
4203
|
}, source);
|
3967
4204
|
};
|
3968
4205
|
|
3969
|
-
|
3970
|
-
|
3971
|
-
|
3972
|
-
var result = selectorFunc(x, i, source);
|
3973
|
-
isPromise(result) && (result = observableFromPromise(result));
|
3974
|
-
(isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
|
3975
|
-
return result;
|
3976
|
-
}).concatAll();
|
3977
|
-
}
|
3978
|
-
|
3979
|
-
/**
|
3980
|
-
* One of the Following:
|
3981
|
-
* Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
|
3982
|
-
*
|
3983
|
-
* @example
|
3984
|
-
* var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
|
3985
|
-
* Or:
|
3986
|
-
* Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
|
3987
|
-
*
|
3988
|
-
* var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
|
3989
|
-
* Or:
|
3990
|
-
* Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
|
3991
|
-
*
|
3992
|
-
* var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
|
3993
|
-
* @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the
|
3994
|
-
* source sequence onto which could be either an observable or Promise.
|
3995
|
-
* @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
|
3996
|
-
* @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
|
3997
|
-
*/
|
3998
|
-
observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
|
3999
|
-
if (isFunction(selector) && isFunction(resultSelector)) {
|
4000
|
-
return this.concatMap(function (x, i) {
|
4001
|
-
var selectorResult = selector(x, i);
|
4002
|
-
isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
|
4003
|
-
(isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
|
4004
|
-
|
4005
|
-
return selectorResult.map(function (y, i2) {
|
4006
|
-
return resultSelector(x, y, i, i2);
|
4007
|
-
});
|
4008
|
-
});
|
4009
|
-
}
|
4010
|
-
return isFunction(selector) ?
|
4011
|
-
concatMap(this, selector, thisArg) :
|
4012
|
-
concatMap(this, function () { return selector; });
|
4013
|
-
};
|
4014
|
-
|
4206
|
+
observableProto.flatMapConcat = observableProto.concatMap = function(selector, resultSelector, thisArg) {
|
4207
|
+
return new FlatMapObservable(this, selector, resultSelector, thisArg).merge(1);
|
4208
|
+
};
|
4015
4209
|
var MapObservable = (function (__super__) {
|
4016
4210
|
inherits(MapObservable, __super__);
|
4017
4211
|
|
@@ -4021,51 +4215,52 @@
|
|
4021
4215
|
__super__.call(this);
|
4022
4216
|
}
|
4023
4217
|
|
4218
|
+
function innerMap(selector, self) {
|
4219
|
+
return function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); }
|
4220
|
+
}
|
4221
|
+
|
4024
4222
|
MapObservable.prototype.internalMap = function (selector, thisArg) {
|
4025
|
-
|
4026
|
-
return new MapObservable(this.source, function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); }, thisArg)
|
4223
|
+
return new MapObservable(this.source, innerMap(selector, this), thisArg);
|
4027
4224
|
};
|
4028
4225
|
|
4029
|
-
MapObservable.prototype.subscribeCore = function (
|
4030
|
-
return this.source.subscribe(new
|
4226
|
+
MapObservable.prototype.subscribeCore = function (o) {
|
4227
|
+
return this.source.subscribe(new InnerObserver(o, this.selector, this));
|
4031
4228
|
};
|
4032
4229
|
|
4033
|
-
|
4230
|
+
function InnerObserver(o, selector, source) {
|
4231
|
+
this.o = o;
|
4232
|
+
this.selector = selector;
|
4233
|
+
this.source = source;
|
4234
|
+
this.i = 0;
|
4235
|
+
this.isStopped = false;
|
4236
|
+
}
|
4034
4237
|
|
4035
|
-
|
4238
|
+
InnerObserver.prototype.onNext = function(x) {
|
4239
|
+
if (this.isStopped) { return; }
|
4240
|
+
var result = tryCatch(this.selector)(x, this.i++, this.source);
|
4241
|
+
if (result === errorObj) { return this.o.onError(result.e); }
|
4242
|
+
this.o.onNext(result);
|
4243
|
+
};
|
4244
|
+
InnerObserver.prototype.onError = function (e) {
|
4245
|
+
if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
|
4246
|
+
};
|
4247
|
+
InnerObserver.prototype.onCompleted = function () {
|
4248
|
+
if(!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
|
4249
|
+
};
|
4250
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
4251
|
+
InnerObserver.prototype.fail = function (e) {
|
4252
|
+
if (!this.isStopped) {
|
4253
|
+
this.isStopped = true;
|
4254
|
+
this.o.onError(e);
|
4255
|
+
return true;
|
4256
|
+
}
|
4036
4257
|
|
4037
|
-
|
4038
|
-
|
4039
|
-
this.selector = selector;
|
4040
|
-
this.source = source;
|
4041
|
-
this.i = 0;
|
4042
|
-
this.isStopped = false;
|
4043
|
-
}
|
4258
|
+
return false;
|
4259
|
+
};
|
4044
4260
|
|
4045
|
-
|
4046
|
-
if (this.isStopped) { return; }
|
4047
|
-
var result = tryCatch(this.selector).call(this, x, this.i++, this.source);
|
4048
|
-
if (result === errorObj) {
|
4049
|
-
return this.observer.onError(result.e);
|
4050
|
-
}
|
4051
|
-
this.observer.onNext(result);
|
4052
|
-
};
|
4053
|
-
MapObserver.prototype.onError = function (e) {
|
4054
|
-
if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
|
4055
|
-
};
|
4056
|
-
MapObserver.prototype.onCompleted = function () {
|
4057
|
-
if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
|
4058
|
-
};
|
4059
|
-
MapObserver.prototype.dispose = function() { this.isStopped = true; };
|
4060
|
-
MapObserver.prototype.fail = function (e) {
|
4061
|
-
if (!this.isStopped) {
|
4062
|
-
this.isStopped = true;
|
4063
|
-
this.observer.onError(e);
|
4064
|
-
return true;
|
4065
|
-
}
|
4261
|
+
return MapObservable;
|
4066
4262
|
|
4067
|
-
|
4068
|
-
};
|
4263
|
+
}(ObservableBase));
|
4069
4264
|
|
4070
4265
|
/**
|
4071
4266
|
* Projects each element of an observable sequence into a new form by incorporating the element's index.
|
@@ -4080,16 +4275,8 @@
|
|
4080
4275
|
new MapObservable(this, selectorFn, thisArg);
|
4081
4276
|
};
|
4082
4277
|
|
4083
|
-
|
4084
|
-
|
4085
|
-
* the Observable sequence.
|
4086
|
-
* @param {Arguments} arguments The nested properties to pluck.
|
4087
|
-
* @returns {Observable} Returns a new Observable sequence of property values.
|
4088
|
-
*/
|
4089
|
-
observableProto.pluck = function () {
|
4090
|
-
var args = arguments, len = arguments.length;
|
4091
|
-
if (len === 0) { throw new Error('List of properties cannot be empty.'); }
|
4092
|
-
return this.map(function (x) {
|
4278
|
+
function plucker(args, len) {
|
4279
|
+
return function mapper(x) {
|
4093
4280
|
var currentProp = x;
|
4094
4281
|
for (var i = 0; i < len; i++) {
|
4095
4282
|
var p = currentProp[args[i]];
|
@@ -4100,87 +4287,90 @@
|
|
4100
4287
|
}
|
4101
4288
|
}
|
4102
4289
|
return currentProp;
|
4103
|
-
}
|
4104
|
-
};
|
4105
|
-
|
4106
|
-
function flatMap(source, selector, thisArg) {
|
4107
|
-
var selectorFunc = bindCallback(selector, thisArg, 3);
|
4108
|
-
return source.map(function (x, i) {
|
4109
|
-
var result = selectorFunc(x, i, source);
|
4110
|
-
isPromise(result) && (result = observableFromPromise(result));
|
4111
|
-
(isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
|
4112
|
-
return result;
|
4113
|
-
}).mergeAll();
|
4290
|
+
}
|
4114
4291
|
}
|
4115
4292
|
|
4116
4293
|
/**
|
4117
|
-
*
|
4118
|
-
*
|
4119
|
-
*
|
4120
|
-
* @
|
4121
|
-
* var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
|
4122
|
-
* Or:
|
4123
|
-
* Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
|
4124
|
-
*
|
4125
|
-
* var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
|
4126
|
-
* Or:
|
4127
|
-
* Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
|
4128
|
-
*
|
4129
|
-
* var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
|
4130
|
-
* @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto which could be either an observable or Promise.
|
4131
|
-
* @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
|
4132
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4133
|
-
* @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
|
4294
|
+
* Retrieves the value of a specified nested property from all elements in
|
4295
|
+
* the Observable sequence.
|
4296
|
+
* @param {Arguments} arguments The nested properties to pluck.
|
4297
|
+
* @returns {Observable} Returns a new Observable sequence of property values.
|
4134
4298
|
*/
|
4135
|
-
observableProto.
|
4136
|
-
|
4137
|
-
|
4138
|
-
|
4139
|
-
|
4140
|
-
(isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
|
4141
|
-
|
4142
|
-
return selectorResult.map(function (y, i2) {
|
4143
|
-
return resultSelector(x, y, i, i2);
|
4144
|
-
});
|
4145
|
-
}, thisArg);
|
4146
|
-
}
|
4147
|
-
return isFunction(selector) ?
|
4148
|
-
flatMap(this, selector, thisArg) :
|
4149
|
-
flatMap(this, function () { return selector; });
|
4299
|
+
observableProto.pluck = function () {
|
4300
|
+
var len = arguments.length, args = new Array(len);
|
4301
|
+
if (len === 0) { throw new Error('List of properties cannot be empty.'); }
|
4302
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4303
|
+
return this.map(plucker(args, len));
|
4150
4304
|
};
|
4151
4305
|
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
* @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.
|
4156
|
-
* @param {Any} [thisArg] Object to use as this when executing callback.
|
4157
|
-
* @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
|
4158
|
-
* and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
|
4159
|
-
*/
|
4160
|
-
observableProto.selectSwitch = observableProto.flatMapLatest = observableProto.switchMap = function (selector, thisArg) {
|
4161
|
-
return this.select(selector, thisArg).switchLatest();
|
4162
|
-
};
|
4306
|
+
observableProto.flatMap = observableProto.selectMany = function(selector, resultSelector, thisArg) {
|
4307
|
+
return new FlatMapObservable(this, selector, resultSelector, thisArg).mergeAll();
|
4308
|
+
};
|
4163
4309
|
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
return new
|
4173
|
-
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4310
|
+
|
4311
|
+
//
|
4312
|
+
//Rx.Observable.prototype.flatMapWithMaxConcurrent = function(limit, selector, resultSelector, thisArg) {
|
4313
|
+
// return new FlatMapObservable(this, selector, resultSelector, thisArg).merge(limit);
|
4314
|
+
//};
|
4315
|
+
//
|
4316
|
+
|
4317
|
+
Rx.Observable.prototype.flatMapLatest = function(selector, resultSelector, thisArg) {
|
4318
|
+
return new FlatMapObservable(this, selector, resultSelector, thisArg).switchLatest();
|
4319
|
+
};
|
4320
|
+
var SkipObservable = (function(__super__) {
|
4321
|
+
inherits(SkipObservable, __super__);
|
4322
|
+
function SkipObservable(source, count) {
|
4323
|
+
this.source = source;
|
4324
|
+
this.skipCount = count;
|
4325
|
+
__super__.call(this);
|
4326
|
+
}
|
4327
|
+
|
4328
|
+
SkipObservable.prototype.subscribeCore = function (o) {
|
4329
|
+
return this.source.subscribe(new InnerObserver(o, this.skipCount));
|
4330
|
+
};
|
4331
|
+
|
4332
|
+
function InnerObserver(o, c) {
|
4333
|
+
this.c = c;
|
4334
|
+
this.r = c;
|
4335
|
+
this.o = o;
|
4336
|
+
this.isStopped = false;
|
4337
|
+
}
|
4338
|
+
InnerObserver.prototype.onNext = function (x) {
|
4339
|
+
if (this.isStopped) { return; }
|
4340
|
+
if (this.r <= 0) {
|
4341
|
+
this.o.onNext(x);
|
4342
|
+
} else {
|
4343
|
+
this.r--;
|
4344
|
+
}
|
4345
|
+
};
|
4346
|
+
InnerObserver.prototype.onError = function(e) {
|
4347
|
+
if (!this.isStopped) { this.isStopped = true; this.o.onError(e); }
|
4348
|
+
};
|
4349
|
+
InnerObserver.prototype.onCompleted = function() {
|
4350
|
+
if (!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
|
4351
|
+
};
|
4352
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
4353
|
+
InnerObserver.prototype.fail = function(e) {
|
4354
|
+
if (!this.isStopped) {
|
4355
|
+
this.isStopped = true;
|
4356
|
+
this.o.onError(e);
|
4357
|
+
return true;
|
4358
|
+
}
|
4359
|
+
return false;
|
4360
|
+
};
|
4361
|
+
|
4362
|
+
return SkipObservable;
|
4363
|
+
}(ObservableBase));
|
4364
|
+
|
4365
|
+
/**
|
4366
|
+
* Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
|
4367
|
+
* @param {Number} count The number of elements to skip before returning the remaining elements.
|
4368
|
+
* @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
|
4369
|
+
*/
|
4370
|
+
observableProto.skip = function (count) {
|
4371
|
+
if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
4372
|
+
return new SkipObservable(this, count);
|
4182
4373
|
};
|
4183
|
-
|
4184
4374
|
/**
|
4185
4375
|
* Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
|
4186
4376
|
* The element's index is used in the logic of the predicate function.
|
@@ -4228,7 +4418,7 @@
|
|
4228
4418
|
return source.subscribe(function (x) {
|
4229
4419
|
if (remaining-- > 0) {
|
4230
4420
|
o.onNext(x);
|
4231
|
-
remaining
|
4421
|
+
remaining <= 0 && o.onCompleted();
|
4232
4422
|
}
|
4233
4423
|
}, function (e) { o.onError(e); }, function () { o.onCompleted(); });
|
4234
4424
|
}, source);
|
@@ -4273,51 +4463,54 @@
|
|
4273
4463
|
__super__.call(this);
|
4274
4464
|
}
|
4275
4465
|
|
4276
|
-
FilterObservable.prototype.subscribeCore = function (
|
4277
|
-
return this.source.subscribe(new
|
4466
|
+
FilterObservable.prototype.subscribeCore = function (o) {
|
4467
|
+
return this.source.subscribe(new InnerObserver(o, this.predicate, this));
|
4278
4468
|
};
|
4469
|
+
|
4470
|
+
function innerPredicate(predicate, self) {
|
4471
|
+
return function(x, i, o) { return self.predicate(x, i, o) && predicate.call(this, x, i, o); }
|
4472
|
+
}
|
4279
4473
|
|
4280
4474
|
FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
|
4281
|
-
|
4282
|
-
|
4475
|
+
return new FilterObservable(this.source, innerPredicate(predicate, this), thisArg);
|
4476
|
+
};
|
4477
|
+
|
4478
|
+
function InnerObserver(o, predicate, source) {
|
4479
|
+
this.o = o;
|
4480
|
+
this.predicate = predicate;
|
4481
|
+
this.source = source;
|
4482
|
+
this.i = 0;
|
4483
|
+
this.isStopped = false;
|
4484
|
+
}
|
4485
|
+
|
4486
|
+
InnerObserver.prototype.onNext = function(x) {
|
4487
|
+
if (this.isStopped) { return; }
|
4488
|
+
var shouldYield = tryCatch(this.predicate)(x, this.i++, this.source);
|
4489
|
+
if (shouldYield === errorObj) {
|
4490
|
+
return this.o.onError(shouldYield.e);
|
4491
|
+
}
|
4492
|
+
shouldYield && this.o.onNext(x);
|
4493
|
+
};
|
4494
|
+
InnerObserver.prototype.onError = function (e) {
|
4495
|
+
if(!this.isStopped) { this.isStopped = true; this.o.onError(e); }
|
4496
|
+
};
|
4497
|
+
InnerObserver.prototype.onCompleted = function () {
|
4498
|
+
if(!this.isStopped) { this.isStopped = true; this.o.onCompleted(); }
|
4499
|
+
};
|
4500
|
+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
4501
|
+
InnerObserver.prototype.fail = function (e) {
|
4502
|
+
if (!this.isStopped) {
|
4503
|
+
this.isStopped = true;
|
4504
|
+
this.o.onError(e);
|
4505
|
+
return true;
|
4506
|
+
}
|
4507
|
+
return false;
|
4283
4508
|
};
|
4284
4509
|
|
4285
4510
|
return FilterObservable;
|
4286
4511
|
|
4287
4512
|
}(ObservableBase));
|
4288
4513
|
|
4289
|
-
function FilterObserver(observer, predicate, source) {
|
4290
|
-
this.observer = observer;
|
4291
|
-
this.predicate = predicate;
|
4292
|
-
this.source = source;
|
4293
|
-
this.i = 0;
|
4294
|
-
this.isStopped = false;
|
4295
|
-
}
|
4296
|
-
|
4297
|
-
FilterObserver.prototype.onNext = function(x) {
|
4298
|
-
if (this.isStopped) { return; }
|
4299
|
-
var shouldYield = tryCatch(this.predicate).call(this, x, this.i++, this.source);
|
4300
|
-
if (shouldYield === errorObj) {
|
4301
|
-
return this.observer.onError(shouldYield.e);
|
4302
|
-
}
|
4303
|
-
shouldYield && this.observer.onNext(x);
|
4304
|
-
};
|
4305
|
-
FilterObserver.prototype.onError = function (e) {
|
4306
|
-
if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); }
|
4307
|
-
};
|
4308
|
-
FilterObserver.prototype.onCompleted = function () {
|
4309
|
-
if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); }
|
4310
|
-
};
|
4311
|
-
FilterObserver.prototype.dispose = function() { this.isStopped = true; };
|
4312
|
-
FilterObserver.prototype.fail = function (e) {
|
4313
|
-
if (!this.isStopped) {
|
4314
|
-
this.isStopped = true;
|
4315
|
-
this.observer.onError(e);
|
4316
|
-
return true;
|
4317
|
-
}
|
4318
|
-
return false;
|
4319
|
-
};
|
4320
|
-
|
4321
4514
|
/**
|
4322
4515
|
* Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
|
4323
4516
|
* @param {Function} predicate A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
|
@@ -4329,94 +4522,112 @@
|
|
4329
4522
|
new FilterObservable(this, predicate, thisArg);
|
4330
4523
|
};
|
4331
4524
|
|
4332
|
-
|
4333
|
-
|
4334
|
-
*
|
4335
|
-
* @param {Function} function Function with a callback as the last parameter to convert to an Observable sequence.
|
4336
|
-
* @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4337
|
-
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
4338
|
-
* @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.
|
4339
|
-
*/
|
4340
|
-
Observable.fromCallback = function (func, context, selector) {
|
4341
|
-
return function () {
|
4342
|
-
var len = arguments.length, args = new Array(len)
|
4343
|
-
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4525
|
+
function createCbObservable(fn, ctx, selector, args) {
|
4526
|
+
var o = new AsyncSubject();
|
4344
4527
|
|
4345
|
-
|
4346
|
-
|
4347
|
-
var len = arguments.length, results = new Array(len);
|
4348
|
-
for(var i = 0; i < len; i++) { results[i] = arguments[i]; }
|
4349
|
-
|
4350
|
-
if (selector) {
|
4351
|
-
try {
|
4352
|
-
results = selector.apply(context, results);
|
4353
|
-
} catch (e) {
|
4354
|
-
return observer.onError(e);
|
4355
|
-
}
|
4528
|
+
args.push(createCbHandler(o, ctx, selector));
|
4529
|
+
fn.apply(ctx, args);
|
4356
4530
|
|
4357
|
-
|
4358
|
-
|
4359
|
-
if (results.length <= 1) {
|
4360
|
-
observer.onNext.apply(observer, results);
|
4361
|
-
} else {
|
4362
|
-
observer.onNext(results);
|
4363
|
-
}
|
4364
|
-
}
|
4531
|
+
return o.asObservable();
|
4532
|
+
}
|
4365
4533
|
|
4366
|
-
|
4367
|
-
|
4534
|
+
function createCbHandler(o, ctx, selector) {
|
4535
|
+
return function handler () {
|
4536
|
+
var len = arguments.length, results = new Array(len);
|
4537
|
+
for(var i = 0; i < len; i++) { results[i] = arguments[i]; }
|
4368
4538
|
|
4369
|
-
|
4370
|
-
|
4371
|
-
|
4372
|
-
|
4539
|
+
if (isFunction(selector)) {
|
4540
|
+
results = tryCatch(selector).apply(ctx, results);
|
4541
|
+
if (results === errorObj) { return o.onError(results.e); }
|
4542
|
+
o.onNext(results);
|
4543
|
+
} else {
|
4544
|
+
if (results.length <= 1) {
|
4545
|
+
o.onNext(results[0]);
|
4546
|
+
} else {
|
4547
|
+
o.onNext(results);
|
4548
|
+
}
|
4549
|
+
}
|
4550
|
+
|
4551
|
+
o.onCompleted();
|
4373
4552
|
};
|
4553
|
+
}
|
4374
4554
|
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4385
|
-
|
4555
|
+
/**
|
4556
|
+
* Converts a callback function to an observable sequence.
|
4557
|
+
*
|
4558
|
+
* @param {Function} fn Function with a callback as the last parameter to convert to an Observable sequence.
|
4559
|
+
* @param {Mixed} [ctx] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4560
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback to produce a single item to yield on next.
|
4561
|
+
* @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.
|
4562
|
+
*/
|
4563
|
+
Observable.fromCallback = function (fn, ctx, selector) {
|
4564
|
+
return function () {
|
4565
|
+
typeof ctx === 'undefined' && (ctx = this);
|
4386
4566
|
|
4387
|
-
|
4388
|
-
|
4389
|
-
|
4390
|
-
|
4391
|
-
|
4392
|
-
}
|
4567
|
+
var len = arguments.length, args = new Array(len)
|
4568
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4569
|
+
return createCbObservable(fn, ctx, selector, args);
|
4570
|
+
};
|
4571
|
+
};
|
4393
4572
|
|
4394
|
-
|
4395
|
-
|
4573
|
+
function createNodeObservable(fn, ctx, selector, args) {
|
4574
|
+
var o = new AsyncSubject();
|
4396
4575
|
|
4397
|
-
|
4398
|
-
|
4399
|
-
results = selector.apply(context, results);
|
4400
|
-
} catch (e) {
|
4401
|
-
return observer.onError(e);
|
4402
|
-
}
|
4403
|
-
observer.onNext(results);
|
4404
|
-
} else {
|
4405
|
-
if (results.length <= 1) {
|
4406
|
-
observer.onNext.apply(observer, results);
|
4407
|
-
} else {
|
4408
|
-
observer.onNext(results);
|
4409
|
-
}
|
4410
|
-
}
|
4576
|
+
args.push(createNodeHandler(o, ctx, selector));
|
4577
|
+
fn.apply(ctx, args);
|
4411
4578
|
|
4412
|
-
|
4413
|
-
|
4579
|
+
return o.asObservable();
|
4580
|
+
}
|
4414
4581
|
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4418
|
-
}
|
4582
|
+
function createNodeHandler(o, ctx, selector) {
|
4583
|
+
return function handler () {
|
4584
|
+
var err = arguments[0];
|
4585
|
+
if (err) { return o.onError(err); }
|
4586
|
+
|
4587
|
+
var len = arguments.length, results = [];
|
4588
|
+
for(var i = 1; i < len; i++) { results[i - 1] = arguments[i]; }
|
4589
|
+
|
4590
|
+
if (isFunction(selector)) {
|
4591
|
+
var results = tryCatch(selector).apply(ctx, results);
|
4592
|
+
if (results === errorObj) { return o.onError(results.e); }
|
4593
|
+
o.onNext(results);
|
4594
|
+
} else {
|
4595
|
+
if (results.length <= 1) {
|
4596
|
+
o.onNext(results[0]);
|
4597
|
+
} else {
|
4598
|
+
o.onNext(results);
|
4599
|
+
}
|
4600
|
+
}
|
4601
|
+
|
4602
|
+
o.onCompleted();
|
4603
|
+
};
|
4604
|
+
}
|
4605
|
+
|
4606
|
+
/**
|
4607
|
+
* Converts a Node.js callback style function to an observable sequence. This must be in function (err, ...) format.
|
4608
|
+
* @param {Function} fn The function to call
|
4609
|
+
* @param {Mixed} [ctx] The context for the func parameter to be executed. If not specified, defaults to undefined.
|
4610
|
+
* @param {Function} [selector] A selector which takes the arguments from the callback minus the error to produce a single item to yield on next.
|
4611
|
+
* @returns {Function} An async function which when applied, returns an observable sequence with the callback arguments as an array.
|
4612
|
+
*/
|
4613
|
+
Observable.fromNodeCallback = function (fn, ctx, selector) {
|
4614
|
+
return function () {
|
4615
|
+
typeof ctx === 'undefined' && (ctx = this);
|
4616
|
+
var len = arguments.length, args = new Array(len);
|
4617
|
+
for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4618
|
+
return createNodeObservable(fn, ctx, selector, args);
|
4419
4619
|
};
|
4620
|
+
};
|
4621
|
+
|
4622
|
+
function isNodeList(el) {
|
4623
|
+
if (window.StaticNodeList) {
|
4624
|
+
// IE8 Specific
|
4625
|
+
// instanceof is slower than Object#toString, but Object#toString will not work as intended in IE8
|
4626
|
+
return (el instanceof window.StaticNodeList || el instanceof window.NodeList);
|
4627
|
+
} else {
|
4628
|
+
return (Object.prototype.toString.call(el) == '[object NodeList]')
|
4629
|
+
}
|
4630
|
+
}
|
4420
4631
|
|
4421
4632
|
function fixEvent(event) {
|
4422
4633
|
var stopPropagation = function () {
|
@@ -4471,36 +4682,61 @@
|
|
4471
4682
|
return event;
|
4472
4683
|
}
|
4473
4684
|
|
4474
|
-
function
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4685
|
+
function ListenDisposable(e, n, fn) {
|
4686
|
+
this._e = e;
|
4687
|
+
this._n = n;
|
4688
|
+
this._fn = fn;
|
4689
|
+
this._e.addEventListener(this._n, this._fn, false);
|
4690
|
+
this.isDisposed = false;
|
4691
|
+
}
|
4692
|
+
ListenDisposable.prototype.dispose = function () {
|
4693
|
+
if (!this.isDisposed) {
|
4694
|
+
this._e.removeEventListener(this._n, this._fn, false);
|
4695
|
+
this.isDisposed = true;
|
4481
4696
|
}
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4697
|
+
};
|
4698
|
+
|
4699
|
+
function AttachEventDisposable(e, n, fn) {
|
4700
|
+
this._e = e;
|
4701
|
+
this._n = 'on' + n;
|
4702
|
+
this._fn = function (e) { fn(fixEvent(e)); };
|
4703
|
+
this._e.attachEvent(this._n, this._fn);
|
4704
|
+
this.isDisposed = false;
|
4705
|
+
}
|
4706
|
+
AttachEventDisposable.prototype.dispose = function () {
|
4707
|
+
if (!this.isDisposed) {
|
4708
|
+
this._e.detachEvent(this._n, this._fn);
|
4709
|
+
this.isDisposed = true;
|
4491
4710
|
}
|
4492
|
-
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
4711
|
+
};
|
4712
|
+
function LevelOneDisposable(e, n, fn) {
|
4713
|
+
this._e = e;
|
4714
|
+
this._n = 'on' + n;
|
4715
|
+
this._e[this._n] = fn;
|
4716
|
+
this.isDisposed = false;
|
4717
|
+
}
|
4718
|
+
LevelOneDisposable.prototype.dispose = function () {
|
4719
|
+
if (!this.isDisposed) {
|
4720
|
+
this._e[this._n] = null;
|
4721
|
+
this.isDisposed = true;
|
4722
|
+
}
|
4723
|
+
};
|
4724
|
+
|
4725
|
+
function createListener (el, eventName, handler) {
|
4726
|
+
if (el.addEventListener) {
|
4727
|
+
return new ListenDisposable(el, eventName, handler)
|
4728
|
+
}
|
4729
|
+
if (el.attachEvent) {
|
4730
|
+
return new AttachEventDisposable(el, eventName, handler);
|
4731
|
+
}
|
4732
|
+
return LevelOneDisposable(el, eventName, handler);
|
4497
4733
|
}
|
4498
4734
|
|
4499
4735
|
function createEventListener (el, eventName, handler) {
|
4500
4736
|
var disposables = new CompositeDisposable();
|
4501
4737
|
|
4502
4738
|
// Asume NodeList
|
4503
|
-
if (Object.prototype.toString.call(el) === '[object
|
4739
|
+
if (isNodeList(el) || Object.prototype.toString.call(el) === '[object HTMLCollection]') {
|
4504
4740
|
for (var i = 0, len = el.length; i < len; i++) {
|
4505
4741
|
disposables.add(createEventListener(el.item(i), eventName, handler));
|
4506
4742
|
}
|
@@ -4518,10 +4754,6 @@
|
|
4518
4754
|
|
4519
4755
|
/**
|
4520
4756
|
* Creates an observable sequence by adding an event listener to the matching DOMElement or each item in the NodeList.
|
4521
|
-
*
|
4522
|
-
* @example
|
4523
|
-
* var source = Rx.Observable.fromEvent(element, 'mouseup');
|
4524
|
-
*
|
4525
4757
|
* @param {Object} element The DOMElement or NodeList to attach a listener.
|
4526
4758
|
* @param {String} eventName The event name to attach the observable sequence.
|
4527
4759
|
* @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next.
|
@@ -4546,22 +4778,17 @@
|
|
4546
4778
|
selector);
|
4547
4779
|
}
|
4548
4780
|
}
|
4549
|
-
return new AnonymousObservable(function (
|
4781
|
+
return new AnonymousObservable(function (o) {
|
4550
4782
|
return createEventListener(
|
4551
4783
|
element,
|
4552
4784
|
eventName,
|
4553
|
-
function handler (
|
4554
|
-
var results =
|
4555
|
-
|
4556
|
-
|
4557
|
-
|
4558
|
-
results = selector(arguments);
|
4559
|
-
} catch (err) {
|
4560
|
-
return observer.onError(err);
|
4561
|
-
}
|
4785
|
+
function handler () {
|
4786
|
+
var results = arguments[0];
|
4787
|
+
if (isFunction(selector)) {
|
4788
|
+
results = tryCatch(selector).apply(null, arguments);
|
4789
|
+
if (results === errorObj) { return o.onError(results.e); }
|
4562
4790
|
}
|
4563
|
-
|
4564
|
-
observer.onNext(results);
|
4791
|
+
o.onNext(results);
|
4565
4792
|
});
|
4566
4793
|
}).publish().refCount();
|
4567
4794
|
};
|
@@ -4571,51 +4798,54 @@
|
|
4571
4798
|
* @param {Function} addHandler The function to add a handler to the emitter.
|
4572
4799
|
* @param {Function} [removeHandler] The optional function to remove a handler from an emitter.
|
4573
4800
|
* @param {Function} [selector] A selector which takes the arguments from the event handler to produce a single item to yield on next.
|
4801
|
+
* @param {Scheduler} [scheduler] A scheduler used to schedule the remove handler.
|
4574
4802
|
* @returns {Observable} An observable sequence which wraps an event from an event emitter
|
4575
4803
|
*/
|
4576
|
-
var fromEventPattern = Observable.fromEventPattern = function (addHandler, removeHandler, selector) {
|
4577
|
-
|
4578
|
-
|
4579
|
-
|
4580
|
-
|
4581
|
-
|
4582
|
-
|
4583
|
-
|
4584
|
-
return observer.onError(err);
|
4585
|
-
}
|
4804
|
+
var fromEventPattern = Observable.fromEventPattern = function (addHandler, removeHandler, selector, scheduler) {
|
4805
|
+
isScheduler(scheduler) || (scheduler = immediateScheduler);
|
4806
|
+
return new AnonymousObservable(function (o) {
|
4807
|
+
function innerHandler () {
|
4808
|
+
var result = arguments[0];
|
4809
|
+
if (isFunction(selector)) {
|
4810
|
+
result = tryCatch(selector).apply(null, arguments);
|
4811
|
+
if (result === errorObj) { return o.onError(result.e); }
|
4586
4812
|
}
|
4587
|
-
|
4813
|
+
o.onNext(result);
|
4588
4814
|
}
|
4589
4815
|
|
4590
4816
|
var returnValue = addHandler(innerHandler);
|
4591
4817
|
return disposableCreate(function () {
|
4592
|
-
|
4593
|
-
removeHandler(innerHandler, returnValue);
|
4594
|
-
}
|
4818
|
+
isFunction(removeHandler) && removeHandler(innerHandler, returnValue);
|
4595
4819
|
});
|
4596
4820
|
}).publish().refCount();
|
4597
4821
|
};
|
4598
4822
|
|
4599
|
-
|
4600
|
-
|
4601
|
-
|
4602
|
-
|
4603
|
-
|
4604
|
-
|
4605
|
-
return observableDefer(function () {
|
4606
|
-
var subject = new Rx.AsyncSubject();
|
4823
|
+
var FromPromiseObservable = (function(__super__) {
|
4824
|
+
inherits(FromPromiseObservable, __super__);
|
4825
|
+
function FromPromiseObservable(p) {
|
4826
|
+
this.p = p;
|
4827
|
+
__super__.call(this);
|
4828
|
+
}
|
4607
4829
|
|
4608
|
-
|
4609
|
-
|
4610
|
-
|
4611
|
-
|
4612
|
-
|
4613
|
-
|
4830
|
+
FromPromiseObservable.prototype.subscribeCore = function(o) {
|
4831
|
+
this.p.then(function (data) {
|
4832
|
+
o.onNext(data);
|
4833
|
+
o.onCompleted();
|
4834
|
+
}, function (err) { o.onError(err); });
|
4835
|
+
return disposableEmpty;
|
4836
|
+
};
|
4614
4837
|
|
4615
|
-
|
4616
|
-
|
4617
|
-
};
|
4838
|
+
return FromPromiseObservable;
|
4839
|
+
}(ObservableBase));
|
4618
4840
|
|
4841
|
+
/**
|
4842
|
+
* Converts a Promise to an Observable sequence
|
4843
|
+
* @param {Promise} An ES6 Compliant promise.
|
4844
|
+
* @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
|
4845
|
+
*/
|
4846
|
+
var observableFromPromise = Observable.fromPromise = function (promise) {
|
4847
|
+
return new FromPromiseObservable(promise);
|
4848
|
+
};
|
4619
4849
|
/*
|
4620
4850
|
* Converts an existing observable sequence to an ES6 Compatible Promise
|
4621
4851
|
* @example
|
@@ -4907,7 +5137,7 @@
|
|
4907
5137
|
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
4908
5138
|
var period;
|
4909
5139
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
4910
|
-
if (periodOrScheduler
|
5140
|
+
if (periodOrScheduler != null && typeof periodOrScheduler === 'number') {
|
4911
5141
|
period = periodOrScheduler;
|
4912
5142
|
} else if (isScheduler(periodOrScheduler)) {
|
4913
5143
|
scheduler = periodOrScheduler;
|
@@ -4916,8 +5146,7 @@
|
|
4916
5146
|
return observableTimerDate(dueTime.getTime(), scheduler);
|
4917
5147
|
}
|
4918
5148
|
if (dueTime instanceof Date && period !== undefined) {
|
4919
|
-
|
4920
|
-
return observableTimerDateAndPeriod(dueTime.getTime(), period, scheduler);
|
5149
|
+
return observableTimerDateAndPeriod(dueTime.getTime(), periodOrScheduler, scheduler);
|
4921
5150
|
}
|
4922
5151
|
return period === undefined ?
|
4923
5152
|
observableTimerTimeSpan(dueTime, scheduler) :
|
@@ -5021,7 +5250,7 @@
|
|
5021
5250
|
* @param {Scheduler} [scheduler] Scheduler to run the debounce timers on. If not specified, the timeout scheduler is used.
|
5022
5251
|
* @returns {Observable} The debounced sequence.
|
5023
5252
|
*/
|
5024
|
-
observableProto.debounce =
|
5253
|
+
observableProto.debounce = function (dueTime, scheduler) {
|
5025
5254
|
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
5026
5255
|
var source = this;
|
5027
5256
|
return new AnonymousObservable(function (observer) {
|
@@ -5082,25 +5311,33 @@
|
|
5082
5311
|
};
|
5083
5312
|
|
5084
5313
|
function sampleObservable(source, sampler) {
|
5085
|
-
return new AnonymousObservable(function (
|
5086
|
-
var atEnd, value, hasValue;
|
5314
|
+
return new AnonymousObservable(function (o) {
|
5315
|
+
var atEnd = false, value, hasValue = false;
|
5087
5316
|
|
5088
5317
|
function sampleSubscribe() {
|
5089
5318
|
if (hasValue) {
|
5090
5319
|
hasValue = false;
|
5091
|
-
|
5320
|
+
o.onNext(value);
|
5092
5321
|
}
|
5093
|
-
atEnd &&
|
5322
|
+
atEnd && o.onCompleted();
|
5094
5323
|
}
|
5095
5324
|
|
5096
|
-
|
5097
|
-
|
5325
|
+
var sourceSubscription = new SingleAssignmentDisposable();
|
5326
|
+
sourceSubscription.setDisposable(source.subscribe(
|
5327
|
+
function (newValue) {
|
5098
5328
|
hasValue = true;
|
5099
5329
|
value = newValue;
|
5100
|
-
},
|
5330
|
+
},
|
5331
|
+
function (e) { o.onError(e); },
|
5332
|
+
function () {
|
5101
5333
|
atEnd = true;
|
5102
|
-
|
5103
|
-
|
5334
|
+
sourceSubscription.dispose();
|
5335
|
+
}
|
5336
|
+
));
|
5337
|
+
|
5338
|
+
return new CompositeDisposable(
|
5339
|
+
sourceSubscription,
|
5340
|
+
sampler.subscribe(sampleSubscribe, function (e) { o.onError(e); }, sampleSubscribe)
|
5104
5341
|
);
|
5105
5342
|
}, source);
|
5106
5343
|
}
|
@@ -5273,26 +5510,15 @@
|
|
5273
5510
|
err;
|
5274
5511
|
|
5275
5512
|
function next(x, i) {
|
5276
|
-
values[i] = x
|
5277
|
-
var res;
|
5513
|
+
values[i] = x;
|
5278
5514
|
hasValue[i] = true;
|
5279
5515
|
if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
|
5280
|
-
if (err) {
|
5281
|
-
|
5282
|
-
|
5283
|
-
}
|
5284
|
-
|
5285
|
-
try {
|
5286
|
-
res = resultSelector.apply(null, values);
|
5287
|
-
} catch (ex) {
|
5288
|
-
o.onError(ex);
|
5289
|
-
return;
|
5290
|
-
}
|
5516
|
+
if (err) { return o.onError(err); }
|
5517
|
+
var res = tryCatch(resultSelector).apply(null, values);
|
5518
|
+
if (res === errorObj) { return o.onError(res.e); }
|
5291
5519
|
o.onNext(res);
|
5292
5520
|
}
|
5293
|
-
|
5294
|
-
o.onCompleted();
|
5295
|
-
}
|
5521
|
+
isDone && values[1] && o.onCompleted();
|
5296
5522
|
}
|
5297
5523
|
|
5298
5524
|
return new CompositeDisposable(
|
@@ -5331,10 +5557,12 @@
|
|
5331
5557
|
function subscribe(o) {
|
5332
5558
|
var q = [], previousShouldFire;
|
5333
5559
|
|
5560
|
+
function drainQueue() { while (q.length > 0) { o.onNext(q.shift()); } }
|
5561
|
+
|
5334
5562
|
var subscription =
|
5335
5563
|
combineLatestSource(
|
5336
5564
|
this.source,
|
5337
|
-
this.pauser.
|
5565
|
+
this.pauser.startWith(false).distinctUntilChanged(),
|
5338
5566
|
function (data, shouldFire) {
|
5339
5567
|
return { data: data, shouldFire: shouldFire };
|
5340
5568
|
})
|
@@ -5343,11 +5571,7 @@
|
|
5343
5571
|
if (previousShouldFire !== undefined && results.shouldFire != previousShouldFire) {
|
5344
5572
|
previousShouldFire = results.shouldFire;
|
5345
5573
|
// change in shouldFire
|
5346
|
-
if (results.shouldFire) {
|
5347
|
-
while (q.length > 0) {
|
5348
|
-
o.onNext(q.shift());
|
5349
|
-
}
|
5350
|
-
}
|
5574
|
+
if (results.shouldFire) { drainQueue(); }
|
5351
5575
|
} else {
|
5352
5576
|
previousShouldFire = results.shouldFire;
|
5353
5577
|
// new data
|
@@ -5359,17 +5583,11 @@
|
|
5359
5583
|
}
|
5360
5584
|
},
|
5361
5585
|
function (err) {
|
5362
|
-
|
5363
|
-
while (q.length > 0) {
|
5364
|
-
o.onNext(q.shift());
|
5365
|
-
}
|
5586
|
+
drainQueue();
|
5366
5587
|
o.onError(err);
|
5367
5588
|
},
|
5368
5589
|
function () {
|
5369
|
-
|
5370
|
-
while (q.length > 0) {
|
5371
|
-
o.onNext(q.shift());
|
5372
|
-
}
|
5590
|
+
drainQueue();
|
5373
5591
|
o.onCompleted();
|
5374
5592
|
}
|
5375
5593
|
);
|
@@ -5414,144 +5632,147 @@
|
|
5414
5632
|
return new PausableBufferedObservable(this, subject);
|
5415
5633
|
};
|
5416
5634
|
|
5417
|
-
|
5418
|
-
|
5419
|
-
inherits(ControlledObservable, __super__);
|
5635
|
+
var ControlledObservable = (function (__super__) {
|
5420
5636
|
|
5421
|
-
|
5422
|
-
return this.source.subscribe(observer);
|
5423
|
-
}
|
5424
|
-
|
5425
|
-
function ControlledObservable (source, enableQueue, scheduler) {
|
5426
|
-
__super__.call(this, subscribe, source);
|
5427
|
-
this.subject = new ControlledSubject(enableQueue, scheduler);
|
5428
|
-
this.source = source.multicast(this.subject).refCount();
|
5429
|
-
}
|
5637
|
+
inherits(ControlledObservable, __super__);
|
5430
5638
|
|
5431
|
-
|
5432
|
-
|
5433
|
-
|
5639
|
+
function subscribe (observer) {
|
5640
|
+
return this.source.subscribe(observer);
|
5641
|
+
}
|
5434
5642
|
|
5435
|
-
|
5643
|
+
function ControlledObservable (source, enableQueue, scheduler) {
|
5644
|
+
__super__.call(this, subscribe, source);
|
5645
|
+
this.subject = new ControlledSubject(enableQueue, scheduler);
|
5646
|
+
this.source = source.multicast(this.subject).refCount();
|
5647
|
+
}
|
5436
5648
|
|
5437
|
-
|
5649
|
+
ControlledObservable.prototype.request = function (numberOfItems) {
|
5650
|
+
return this.subject.request(numberOfItems == null ? -1 : numberOfItems);
|
5651
|
+
};
|
5438
5652
|
|
5439
|
-
|
5653
|
+
return ControlledObservable;
|
5440
5654
|
|
5441
|
-
|
5442
|
-
return this.subject.subscribe(observer);
|
5443
|
-
}
|
5655
|
+
}(Observable));
|
5444
5656
|
|
5445
|
-
|
5657
|
+
var ControlledSubject = (function (__super__) {
|
5446
5658
|
|
5447
|
-
|
5448
|
-
|
5659
|
+
function subscribe (observer) {
|
5660
|
+
return this.subject.subscribe(observer);
|
5661
|
+
}
|
5449
5662
|
|
5450
|
-
|
5451
|
-
|
5452
|
-
|
5453
|
-
|
5454
|
-
|
5455
|
-
|
5456
|
-
|
5457
|
-
|
5458
|
-
|
5459
|
-
|
5460
|
-
|
5663
|
+
inherits(ControlledSubject, __super__);
|
5664
|
+
|
5665
|
+
function ControlledSubject(enableQueue, scheduler) {
|
5666
|
+
enableQueue == null && (enableQueue = true);
|
5667
|
+
|
5668
|
+
__super__.call(this, subscribe);
|
5669
|
+
this.subject = new Subject();
|
5670
|
+
this.enableQueue = enableQueue;
|
5671
|
+
this.queue = enableQueue ? [] : null;
|
5672
|
+
this.requestedCount = 0;
|
5673
|
+
this.requestedDisposable = null;
|
5674
|
+
this.error = null;
|
5675
|
+
this.hasFailed = false;
|
5676
|
+
this.hasCompleted = false;
|
5677
|
+
this.scheduler = scheduler || currentThreadScheduler;
|
5678
|
+
}
|
5461
5679
|
|
5462
|
-
|
5463
|
-
|
5464
|
-
|
5465
|
-
|
5466
|
-
|
5467
|
-
|
5468
|
-
|
5469
|
-
|
5470
|
-
}
|
5471
|
-
|
5472
|
-
|
5473
|
-
|
5474
|
-
|
5475
|
-
|
5476
|
-
|
5477
|
-
|
5680
|
+
addProperties(ControlledSubject.prototype, Observer, {
|
5681
|
+
onCompleted: function () {
|
5682
|
+
this.hasCompleted = true;
|
5683
|
+
if (!this.enableQueue || this.queue.length === 0) {
|
5684
|
+
this.subject.onCompleted();
|
5685
|
+
this.disposeCurrentRequest()
|
5686
|
+
} else {
|
5687
|
+
this.queue.push(Notification.createOnCompleted());
|
5688
|
+
}
|
5689
|
+
},
|
5690
|
+
onError: function (error) {
|
5691
|
+
this.hasFailed = true;
|
5692
|
+
this.error = error;
|
5693
|
+
if (!this.enableQueue || this.queue.length === 0) {
|
5694
|
+
this.subject.onError(error);
|
5695
|
+
this.disposeCurrentRequest()
|
5696
|
+
} else {
|
5697
|
+
this.queue.push(Notification.createOnError(error));
|
5698
|
+
}
|
5699
|
+
},
|
5700
|
+
onNext: function (value) {
|
5701
|
+
if (this.requestedCount <= 0) {
|
5702
|
+
this.enableQueue && this.queue.push(Notification.createOnNext(value));
|
5703
|
+
} else {
|
5704
|
+
(this.requestedCount-- === 0) && this.disposeCurrentRequest();
|
5705
|
+
this.subject.onNext(value);
|
5706
|
+
}
|
5707
|
+
},
|
5708
|
+
_processRequest: function (numberOfItems) {
|
5709
|
+
if (this.enableQueue) {
|
5710
|
+
while (this.queue.length > 0 && (numberOfItems > 0 || this.queue[0].kind !== 'N')) {
|
5711
|
+
var first = this.queue.shift();
|
5712
|
+
first.accept(this.subject);
|
5713
|
+
if (first.kind === 'N') {
|
5714
|
+
numberOfItems--;
|
5715
|
+
} else {
|
5716
|
+
this.disposeCurrentRequest();
|
5717
|
+
this.queue = [];
|
5718
|
+
}
|
5478
5719
|
}
|
5479
|
-
}
|
5480
|
-
onNext: function (value) {
|
5481
|
-
var hasRequested = false;
|
5720
|
+
}
|
5482
5721
|
|
5483
|
-
|
5484
|
-
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5488
|
-
}
|
5489
|
-
hasRequested && this.subject.onNext(value);
|
5490
|
-
},
|
5491
|
-
_processRequest: function (numberOfItems) {
|
5492
|
-
if (this.enableQueue) {
|
5493
|
-
while ((this.queue.length >= numberOfItems && numberOfItems > 0) ||
|
5494
|
-
(this.queue.length > 0 && this.queue[0].kind !== 'N')) {
|
5495
|
-
var first = this.queue.shift();
|
5496
|
-
first.accept(this.subject);
|
5497
|
-
if (first.kind === 'N') {
|
5498
|
-
numberOfItems--;
|
5499
|
-
} else {
|
5500
|
-
this.disposeCurrentRequest();
|
5501
|
-
this.queue = [];
|
5502
|
-
}
|
5503
|
-
}
|
5722
|
+
return numberOfItems;
|
5723
|
+
},
|
5724
|
+
request: function (number) {
|
5725
|
+
this.disposeCurrentRequest();
|
5726
|
+
var self = this;
|
5504
5727
|
|
5505
|
-
|
5506
|
-
|
5728
|
+
this.requestedDisposable = this.scheduler.scheduleWithState(number,
|
5729
|
+
function(s, i) {
|
5730
|
+
var remaining = self._processRequest(i);
|
5731
|
+
var stopped = self.hasCompleted || self.hasFailed
|
5732
|
+
if (!stopped && remaining > 0) {
|
5733
|
+
self.requestedCount = remaining;
|
5507
5734
|
|
5508
|
-
|
5509
|
-
|
5510
|
-
|
5511
|
-
|
5512
|
-
|
5513
|
-
|
5514
|
-
|
5515
|
-
|
5516
|
-
var r = self._processRequest(i), remaining = r.numberOfItems;
|
5517
|
-
if (!r.returnValue) {
|
5518
|
-
self.requestedCount = remaining;
|
5519
|
-
self.requestedDisposable = disposableCreate(function () {
|
5520
|
-
self.requestedCount = 0;
|
5521
|
-
});
|
5522
|
-
}
|
5523
|
-
});
|
5735
|
+
return disposableCreate(function () {
|
5736
|
+
self.requestedCount = 0;
|
5737
|
+
});
|
5738
|
+
// Scheduled item is still in progress. Return a new
|
5739
|
+
// disposable to allow the request to be interrupted
|
5740
|
+
// via dispose.
|
5741
|
+
}
|
5742
|
+
});
|
5524
5743
|
|
5525
|
-
|
5526
|
-
|
5527
|
-
|
5744
|
+
return this.requestedDisposable;
|
5745
|
+
},
|
5746
|
+
disposeCurrentRequest: function () {
|
5747
|
+
if (this.requestedDisposable) {
|
5528
5748
|
this.requestedDisposable.dispose();
|
5529
|
-
this.requestedDisposable =
|
5749
|
+
this.requestedDisposable = null;
|
5530
5750
|
}
|
5531
|
-
});
|
5532
|
-
|
5533
|
-
return ControlledSubject;
|
5534
|
-
}(Observable));
|
5535
|
-
|
5536
|
-
/**
|
5537
|
-
* Attaches a controller to the observable sequence with the ability to queue.
|
5538
|
-
* @example
|
5539
|
-
* var source = Rx.Observable.interval(100).controlled();
|
5540
|
-
* source.request(3); // Reads 3 values
|
5541
|
-
* @param {bool} enableQueue truthy value to determine if values should be queued pending the next request
|
5542
|
-
* @param {Scheduler} scheduler determines how the requests will be scheduled
|
5543
|
-
* @returns {Observable} The observable sequence which is paused based upon the pauser.
|
5544
|
-
*/
|
5545
|
-
observableProto.controlled = function (enableQueue, scheduler) {
|
5546
|
-
|
5547
|
-
if (enableQueue && isScheduler(enableQueue)) {
|
5548
|
-
scheduler = enableQueue;
|
5549
|
-
enableQueue = true;
|
5550
5751
|
}
|
5752
|
+
});
|
5753
|
+
|
5754
|
+
return ControlledSubject;
|
5755
|
+
}(Observable));
|
5756
|
+
|
5757
|
+
/**
|
5758
|
+
* Attaches a controller to the observable sequence with the ability to queue.
|
5759
|
+
* @example
|
5760
|
+
* var source = Rx.Observable.interval(100).controlled();
|
5761
|
+
* source.request(3); // Reads 3 values
|
5762
|
+
* @param {bool} enableQueue truthy value to determine if values should be queued pending the next request
|
5763
|
+
* @param {Scheduler} scheduler determines how the requests will be scheduled
|
5764
|
+
* @returns {Observable} The observable sequence which only propagates values on request.
|
5765
|
+
*/
|
5766
|
+
observableProto.controlled = function (enableQueue, scheduler) {
|
5767
|
+
|
5768
|
+
if (enableQueue && isScheduler(enableQueue)) {
|
5769
|
+
scheduler = enableQueue;
|
5770
|
+
enableQueue = true;
|
5771
|
+
}
|
5551
5772
|
|
5552
|
-
|
5553
|
-
|
5554
|
-
|
5773
|
+
if (enableQueue == null) { enableQueue = true; }
|
5774
|
+
return new ControlledObservable(this, enableQueue, scheduler);
|
5775
|
+
};
|
5555
5776
|
|
5556
5777
|
/**
|
5557
5778
|
* Pipes the existing Observable sequence into a Node.js Stream.
|
@@ -5611,11 +5832,8 @@
|
|
5611
5832
|
var xform = transducer(transformForObserver(o));
|
5612
5833
|
return source.subscribe(
|
5613
5834
|
function(v) {
|
5614
|
-
|
5615
|
-
|
5616
|
-
} catch (e) {
|
5617
|
-
o.onError(e);
|
5618
|
-
}
|
5835
|
+
var res = tryCatch(xform['@@transducer/step']).call(xform, o, v);
|
5836
|
+
if (res === errorObj) { o.onError(res.e); }
|
5619
5837
|
},
|
5620
5838
|
function (e) { o.onError(e); },
|
5621
5839
|
function() { xform['@@transducer/result'](o); }
|
@@ -5633,8 +5851,8 @@
|
|
5633
5851
|
}
|
5634
5852
|
|
5635
5853
|
function setDisposable(s, state) {
|
5636
|
-
var ado = state[0],
|
5637
|
-
var sub = tryCatch(
|
5854
|
+
var ado = state[0], self = state[1];
|
5855
|
+
var sub = tryCatch(self.__subscribe).call(self, ado);
|
5638
5856
|
|
5639
5857
|
if (sub === errorObj) {
|
5640
5858
|
if(!ado.fail(errorObj.e)) { return thrower(errorObj.e); }
|
@@ -5642,21 +5860,21 @@
|
|
5642
5860
|
ado.setDisposable(fixSubscriber(sub));
|
5643
5861
|
}
|
5644
5862
|
|
5645
|
-
function
|
5646
|
-
|
5647
|
-
|
5648
|
-
function s(observer) {
|
5649
|
-
var ado = new AutoDetachObserver(observer), state = [ado, subscribe];
|
5863
|
+
function innerSubscribe(observer) {
|
5864
|
+
var ado = new AutoDetachObserver(observer), state = [ado, this];
|
5650
5865
|
|
5651
|
-
|
5652
|
-
|
5653
|
-
|
5654
|
-
|
5655
|
-
}
|
5656
|
-
return ado;
|
5866
|
+
if (currentThreadScheduler.scheduleRequired()) {
|
5867
|
+
currentThreadScheduler.scheduleWithState(state, setDisposable);
|
5868
|
+
} else {
|
5869
|
+
setDisposable(null, state);
|
5657
5870
|
}
|
5871
|
+
return ado;
|
5872
|
+
}
|
5658
5873
|
|
5659
|
-
|
5874
|
+
function AnonymousObservable(subscribe, parent) {
|
5875
|
+
this.source = parent;
|
5876
|
+
this.__subscribe = subscribe;
|
5877
|
+
__super__.call(this, innerSubscribe);
|
5660
5878
|
}
|
5661
5879
|
|
5662
5880
|
return AnonymousObservable;
|