rxjs-rails 2.2.20 → 2.2.26
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 +38 -20
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +9288 -0
- data/vendor/assets/javascripts/rx.all.compat.min.js +3 -0
- data/vendor/assets/javascripts/rx.all.js +9102 -0
- data/vendor/assets/javascripts/rx.all.min.js +3 -0
- data/vendor/assets/javascripts/rx.async.compat.js +5 -4
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +5 -4
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.js +24 -12
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +85 -85
- data/vendor/assets/javascripts/rx.coincidence.js +59 -15
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +809 -742
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.core.compat.js +2629 -0
- data/vendor/assets/javascripts/rx.core.compat.min.js +1 -0
- data/vendor/assets/javascripts/rx.core.js +2511 -0
- data/vendor/assets/javascripts/rx.core.min.js +1 -0
- data/vendor/assets/javascripts/rx.experimental.js +43 -43
- data/vendor/assets/javascripts/rx.joinpatterns.js +281 -281
- data/vendor/assets/javascripts/rx.js +792 -725
- data/vendor/assets/javascripts/rx.lite.compat.js +890 -758
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.js +664 -0
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -0
- data/vendor/assets/javascripts/rx.lite.js +890 -758
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.testing.js +166 -166
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +132 -131
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.js +2 -2
- metadata +13 -4
- data/vendor/assets/javascripts/rx.node.js +0 -142
@@ -0,0 +1,2511 @@
|
|
1
|
+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
2
|
+
|
3
|
+
;(function (undefined) {
|
4
|
+
|
5
|
+
var objectTypes = {
|
6
|
+
'boolean': false,
|
7
|
+
'function': true,
|
8
|
+
'object': true,
|
9
|
+
'number': false,
|
10
|
+
'string': false,
|
11
|
+
'undefined': false
|
12
|
+
};
|
13
|
+
|
14
|
+
var root = (objectTypes[typeof window] && window) || this,
|
15
|
+
freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports,
|
16
|
+
freeModule = objectTypes[typeof module] && module && !module.nodeType && module,
|
17
|
+
moduleExports = freeModule && freeModule.exports === freeExports && freeExports,
|
18
|
+
freeGlobal = objectTypes[typeof global] && global;
|
19
|
+
|
20
|
+
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
|
21
|
+
root = freeGlobal;
|
22
|
+
}
|
23
|
+
|
24
|
+
var Rx = {
|
25
|
+
internals: {},
|
26
|
+
config: {
|
27
|
+
Promise: root.Promise // Detect if promise exists
|
28
|
+
},
|
29
|
+
helpers: { }
|
30
|
+
};
|
31
|
+
|
32
|
+
// Defaults
|
33
|
+
var noop = Rx.helpers.noop = function () { },
|
34
|
+
identity = Rx.helpers.identity = function (x) { return x; },
|
35
|
+
defaultNow = Rx.helpers.defaultNow = Date.now,
|
36
|
+
defaultComparer = Rx.helpers.defaultComparer = function (x, y) { return isEqual(x, y); },
|
37
|
+
defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
|
38
|
+
defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
|
39
|
+
defaultError = Rx.helpers.defaultError = function (err) { throw err; },
|
40
|
+
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.then === 'function' && p.then !== Rx.Observable.prototype.then; },
|
41
|
+
asArray = Rx.helpers.asArray = function () { return Array.prototype.slice.call(arguments); },
|
42
|
+
not = Rx.helpers.not = function (a) { return !a; };
|
43
|
+
|
44
|
+
// Errors
|
45
|
+
var sequenceContainsNoElements = 'Sequence contains no elements.';
|
46
|
+
var argumentOutOfRange = 'Argument out of range';
|
47
|
+
var objectDisposed = 'Object has been disposed';
|
48
|
+
function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
|
49
|
+
|
50
|
+
// Shim in iterator support
|
51
|
+
var $iterator$ = (typeof Symbol === 'object' && Symbol.iterator) ||
|
52
|
+
'_es6shim_iterator_';
|
53
|
+
// Firefox ships a partial implementation using the name @@iterator.
|
54
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
|
55
|
+
// So use that name if we detect it.
|
56
|
+
if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
|
57
|
+
$iterator$ = '@@iterator';
|
58
|
+
}
|
59
|
+
var doneEnumerator = { done: true, value: undefined };
|
60
|
+
|
61
|
+
/** `Object#toString` result shortcuts */
|
62
|
+
var argsClass = '[object Arguments]',
|
63
|
+
arrayClass = '[object Array]',
|
64
|
+
boolClass = '[object Boolean]',
|
65
|
+
dateClass = '[object Date]',
|
66
|
+
errorClass = '[object Error]',
|
67
|
+
funcClass = '[object Function]',
|
68
|
+
numberClass = '[object Number]',
|
69
|
+
objectClass = '[object Object]',
|
70
|
+
regexpClass = '[object RegExp]',
|
71
|
+
stringClass = '[object String]';
|
72
|
+
|
73
|
+
var toString = Object.prototype.toString,
|
74
|
+
hasOwnProperty = Object.prototype.hasOwnProperty,
|
75
|
+
supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
|
76
|
+
suportNodeClass,
|
77
|
+
errorProto = Error.prototype,
|
78
|
+
objectProto = Object.prototype,
|
79
|
+
propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
80
|
+
|
81
|
+
try {
|
82
|
+
suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
|
83
|
+
} catch(e) {
|
84
|
+
suportNodeClass = true;
|
85
|
+
}
|
86
|
+
|
87
|
+
var shadowedProps = [
|
88
|
+
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'
|
89
|
+
];
|
90
|
+
|
91
|
+
var nonEnumProps = {};
|
92
|
+
nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
|
93
|
+
nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
|
94
|
+
nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
|
95
|
+
nonEnumProps[objectClass] = { 'constructor': true };
|
96
|
+
|
97
|
+
var support = {};
|
98
|
+
(function () {
|
99
|
+
var ctor = function() { this.x = 1; },
|
100
|
+
props = [];
|
101
|
+
|
102
|
+
ctor.prototype = { 'valueOf': 1, 'y': 1 };
|
103
|
+
for (var key in new ctor) { props.push(key); }
|
104
|
+
for (key in arguments) { }
|
105
|
+
|
106
|
+
// Detect if `name` or `message` properties of `Error.prototype` are enumerable by default.
|
107
|
+
support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
|
108
|
+
|
109
|
+
// Detect if `prototype` properties are enumerable by default.
|
110
|
+
support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
|
111
|
+
|
112
|
+
// Detect if `arguments` object indexes are non-enumerable
|
113
|
+
support.nonEnumArgs = key != 0;
|
114
|
+
|
115
|
+
// Detect if properties shadowing those on `Object.prototype` are non-enumerable.
|
116
|
+
support.nonEnumShadows = !/valueOf/.test(props);
|
117
|
+
}(1));
|
118
|
+
|
119
|
+
function isObject(value) {
|
120
|
+
// check if the value is the ECMAScript language type of Object
|
121
|
+
// http://es5.github.io/#x8
|
122
|
+
// and avoid a V8 bug
|
123
|
+
// https://code.google.com/p/v8/issues/detail?id=2291
|
124
|
+
var type = typeof value;
|
125
|
+
return value && (type == 'function' || type == 'object') || false;
|
126
|
+
}
|
127
|
+
|
128
|
+
function keysIn(object) {
|
129
|
+
var result = [];
|
130
|
+
if (!isObject(object)) {
|
131
|
+
return result;
|
132
|
+
}
|
133
|
+
if (support.nonEnumArgs && object.length && isArguments(object)) {
|
134
|
+
object = slice.call(object);
|
135
|
+
}
|
136
|
+
var skipProto = support.enumPrototypes && typeof object == 'function',
|
137
|
+
skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error);
|
138
|
+
|
139
|
+
for (var key in object) {
|
140
|
+
if (!(skipProto && key == 'prototype') &&
|
141
|
+
!(skipErrorProps && (key == 'message' || key == 'name'))) {
|
142
|
+
result.push(key);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
if (support.nonEnumShadows && object !== objectProto) {
|
147
|
+
var ctor = object.constructor,
|
148
|
+
index = -1,
|
149
|
+
length = shadowedProps.length;
|
150
|
+
|
151
|
+
if (object === (ctor && ctor.prototype)) {
|
152
|
+
var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),
|
153
|
+
nonEnum = nonEnumProps[className];
|
154
|
+
}
|
155
|
+
while (++index < length) {
|
156
|
+
key = shadowedProps[index];
|
157
|
+
if (!(nonEnum && nonEnum[key]) && hasOwnProperty.call(object, key)) {
|
158
|
+
result.push(key);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
return result;
|
163
|
+
}
|
164
|
+
|
165
|
+
function internalFor(object, callback, keysFunc) {
|
166
|
+
var index = -1,
|
167
|
+
props = keysFunc(object),
|
168
|
+
length = props.length;
|
169
|
+
|
170
|
+
while (++index < length) {
|
171
|
+
var key = props[index];
|
172
|
+
if (callback(object[key], key, object) === false) {
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
return object;
|
177
|
+
}
|
178
|
+
|
179
|
+
function internalForIn(object, callback) {
|
180
|
+
return internalFor(object, callback, keysIn);
|
181
|
+
}
|
182
|
+
|
183
|
+
function isNode(value) {
|
184
|
+
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
185
|
+
// methods that are `typeof` "string" and still can coerce nodes to strings
|
186
|
+
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
187
|
+
}
|
188
|
+
|
189
|
+
function isArguments(value) {
|
190
|
+
return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
|
191
|
+
}
|
192
|
+
|
193
|
+
// fallback for browsers that can't detect `arguments` objects by [[Class]]
|
194
|
+
if (!supportsArgsClass) {
|
195
|
+
isArguments = function(value) {
|
196
|
+
return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
|
197
|
+
};
|
198
|
+
}
|
199
|
+
|
200
|
+
function isFunction(value) {
|
201
|
+
return typeof value == 'function' || false;
|
202
|
+
}
|
203
|
+
|
204
|
+
// fallback for older versions of Chrome and Safari
|
205
|
+
if (isFunction(/x/)) {
|
206
|
+
isFunction = function(value) {
|
207
|
+
return typeof value == 'function' && toString.call(value) == funcClass;
|
208
|
+
};
|
209
|
+
}
|
210
|
+
|
211
|
+
var isEqual = Rx.internals.isEqual = function (x, y) {
|
212
|
+
return deepEquals(x, y, [], []);
|
213
|
+
};
|
214
|
+
|
215
|
+
/** @private
|
216
|
+
* Used for deep comparison
|
217
|
+
**/
|
218
|
+
function deepEquals(a, b, stackA, stackB) {
|
219
|
+
// exit early for identical values
|
220
|
+
if (a === b) {
|
221
|
+
// treat `+0` vs. `-0` as not equal
|
222
|
+
return a !== 0 || (1 / a == 1 / b);
|
223
|
+
}
|
224
|
+
|
225
|
+
var type = typeof a,
|
226
|
+
otherType = typeof b;
|
227
|
+
|
228
|
+
// exit early for unlike primitive values
|
229
|
+
if (a === a && (a == null || b == null ||
|
230
|
+
(type != 'function' && type != 'object' && otherType != 'function' && otherType != 'object'))) {
|
231
|
+
return false;
|
232
|
+
}
|
233
|
+
|
234
|
+
// compare [[Class]] names
|
235
|
+
var className = toString.call(a),
|
236
|
+
otherClass = toString.call(b);
|
237
|
+
|
238
|
+
if (className == argsClass) {
|
239
|
+
className = objectClass;
|
240
|
+
}
|
241
|
+
if (otherClass == argsClass) {
|
242
|
+
otherClass = objectClass;
|
243
|
+
}
|
244
|
+
if (className != otherClass) {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
switch (className) {
|
248
|
+
case boolClass:
|
249
|
+
case dateClass:
|
250
|
+
// coerce dates and booleans to numbers, dates to milliseconds and booleans
|
251
|
+
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal
|
252
|
+
return +a == +b;
|
253
|
+
|
254
|
+
case numberClass:
|
255
|
+
// treat `NaN` vs. `NaN` as equal
|
256
|
+
return (a != +a)
|
257
|
+
? b != +b
|
258
|
+
// but treat `-0` vs. `+0` as not equal
|
259
|
+
: (a == 0 ? (1 / a == 1 / b) : a == +b);
|
260
|
+
|
261
|
+
case regexpClass:
|
262
|
+
case stringClass:
|
263
|
+
// coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
|
264
|
+
// treat string primitives and their corresponding object instances as equal
|
265
|
+
return a == String(b);
|
266
|
+
}
|
267
|
+
var isArr = className == arrayClass;
|
268
|
+
if (!isArr) {
|
269
|
+
|
270
|
+
// exit for functions and DOM nodes
|
271
|
+
if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
|
272
|
+
return false;
|
273
|
+
}
|
274
|
+
// in older versions of Opera, `arguments` objects have `Array` constructors
|
275
|
+
var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
|
276
|
+
ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
|
277
|
+
|
278
|
+
// non `Object` object instances with different constructors are not equal
|
279
|
+
if (ctorA != ctorB &&
|
280
|
+
!(hasOwnProperty.call(a, 'constructor') && hasOwnProperty.call(b, 'constructor')) &&
|
281
|
+
!(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
|
282
|
+
('constructor' in a && 'constructor' in b)
|
283
|
+
) {
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
// assume cyclic structures are equal
|
288
|
+
// the algorithm for detecting cyclic structures is adapted from ES 5.1
|
289
|
+
// section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
|
290
|
+
var initedStack = !stackA;
|
291
|
+
stackA || (stackA = []);
|
292
|
+
stackB || (stackB = []);
|
293
|
+
|
294
|
+
var length = stackA.length;
|
295
|
+
while (length--) {
|
296
|
+
if (stackA[length] == a) {
|
297
|
+
return stackB[length] == b;
|
298
|
+
}
|
299
|
+
}
|
300
|
+
var size = 0;
|
301
|
+
result = true;
|
302
|
+
|
303
|
+
// add `a` and `b` to the stack of traversed objects
|
304
|
+
stackA.push(a);
|
305
|
+
stackB.push(b);
|
306
|
+
|
307
|
+
// recursively compare objects and arrays (susceptible to call stack limits)
|
308
|
+
if (isArr) {
|
309
|
+
// compare lengths to determine if a deep comparison is necessary
|
310
|
+
length = a.length;
|
311
|
+
size = b.length;
|
312
|
+
result = size == length;
|
313
|
+
|
314
|
+
if (result) {
|
315
|
+
// deep compare the contents, ignoring non-numeric properties
|
316
|
+
while (size--) {
|
317
|
+
var index = length,
|
318
|
+
value = b[size];
|
319
|
+
|
320
|
+
if (!(result = deepEquals(a[size], value, stackA, stackB))) {
|
321
|
+
break;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
else {
|
327
|
+
// deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
|
328
|
+
// which, in this case, is more costly
|
329
|
+
internalForIn(b, function(value, key, b) {
|
330
|
+
if (hasOwnProperty.call(b, key)) {
|
331
|
+
// count the number of properties.
|
332
|
+
size++;
|
333
|
+
// deep compare each property value.
|
334
|
+
return (result = hasOwnProperty.call(a, key) && deepEquals(a[key], value, stackA, stackB));
|
335
|
+
}
|
336
|
+
});
|
337
|
+
|
338
|
+
if (result) {
|
339
|
+
// ensure both objects have the same number of properties
|
340
|
+
internalForIn(a, function(value, key, a) {
|
341
|
+
if (hasOwnProperty.call(a, key)) {
|
342
|
+
// `size` will be `-1` if `a` has more properties than `b`
|
343
|
+
return (result = --size > -1);
|
344
|
+
}
|
345
|
+
});
|
346
|
+
}
|
347
|
+
}
|
348
|
+
stackA.pop();
|
349
|
+
stackB.pop();
|
350
|
+
|
351
|
+
return result;
|
352
|
+
}
|
353
|
+
var slice = Array.prototype.slice;
|
354
|
+
function argsOrArray(args, idx) {
|
355
|
+
return args.length === 1 && Array.isArray(args[idx]) ?
|
356
|
+
args[idx] :
|
357
|
+
slice.call(args);
|
358
|
+
}
|
359
|
+
var hasProp = {}.hasOwnProperty;
|
360
|
+
|
361
|
+
/** @private */
|
362
|
+
var inherits = this.inherits = Rx.internals.inherits = function (child, parent) {
|
363
|
+
function __() { this.constructor = child; }
|
364
|
+
__.prototype = parent.prototype;
|
365
|
+
child.prototype = new __();
|
366
|
+
};
|
367
|
+
|
368
|
+
/** @private */
|
369
|
+
var addProperties = Rx.internals.addProperties = function (obj) {
|
370
|
+
var sources = slice.call(arguments, 1);
|
371
|
+
for (var i = 0, len = sources.length; i < len; i++) {
|
372
|
+
var source = sources[i];
|
373
|
+
for (var prop in source) {
|
374
|
+
obj[prop] = source[prop];
|
375
|
+
}
|
376
|
+
}
|
377
|
+
};
|
378
|
+
|
379
|
+
// Rx Utils
|
380
|
+
var addRef = Rx.internals.addRef = function (xs, r) {
|
381
|
+
return new AnonymousObservable(function (observer) {
|
382
|
+
return new CompositeDisposable(r.getDisposable(), xs.subscribe(observer));
|
383
|
+
});
|
384
|
+
};
|
385
|
+
|
386
|
+
// Collection polyfills
|
387
|
+
function arrayInitialize(count, factory) {
|
388
|
+
var a = new Array(count);
|
389
|
+
for (var i = 0; i < count; i++) {
|
390
|
+
a[i] = factory();
|
391
|
+
}
|
392
|
+
return a;
|
393
|
+
}
|
394
|
+
|
395
|
+
// Collections
|
396
|
+
var IndexedItem = function (id, value) {
|
397
|
+
this.id = id;
|
398
|
+
this.value = value;
|
399
|
+
};
|
400
|
+
|
401
|
+
IndexedItem.prototype.compareTo = function (other) {
|
402
|
+
var c = this.value.compareTo(other.value);
|
403
|
+
if (c === 0) {
|
404
|
+
c = this.id - other.id;
|
405
|
+
}
|
406
|
+
return c;
|
407
|
+
};
|
408
|
+
|
409
|
+
// Priority Queue for Scheduling
|
410
|
+
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
411
|
+
this.items = new Array(capacity);
|
412
|
+
this.length = 0;
|
413
|
+
};
|
414
|
+
|
415
|
+
var priorityProto = PriorityQueue.prototype;
|
416
|
+
priorityProto.isHigherPriority = function (left, right) {
|
417
|
+
return this.items[left].compareTo(this.items[right]) < 0;
|
418
|
+
};
|
419
|
+
|
420
|
+
priorityProto.percolate = function (index) {
|
421
|
+
if (index >= this.length || index < 0) {
|
422
|
+
return;
|
423
|
+
}
|
424
|
+
var parent = index - 1 >> 1;
|
425
|
+
if (parent < 0 || parent === index) {
|
426
|
+
return;
|
427
|
+
}
|
428
|
+
if (this.isHigherPriority(index, parent)) {
|
429
|
+
var temp = this.items[index];
|
430
|
+
this.items[index] = this.items[parent];
|
431
|
+
this.items[parent] = temp;
|
432
|
+
this.percolate(parent);
|
433
|
+
}
|
434
|
+
};
|
435
|
+
|
436
|
+
priorityProto.heapify = function (index) {
|
437
|
+
if (index === undefined) {
|
438
|
+
index = 0;
|
439
|
+
}
|
440
|
+
if (index >= this.length || index < 0) {
|
441
|
+
return;
|
442
|
+
}
|
443
|
+
var left = 2 * index + 1,
|
444
|
+
right = 2 * index + 2,
|
445
|
+
first = index;
|
446
|
+
if (left < this.length && this.isHigherPriority(left, first)) {
|
447
|
+
first = left;
|
448
|
+
}
|
449
|
+
if (right < this.length && this.isHigherPriority(right, first)) {
|
450
|
+
first = right;
|
451
|
+
}
|
452
|
+
if (first !== index) {
|
453
|
+
var temp = this.items[index];
|
454
|
+
this.items[index] = this.items[first];
|
455
|
+
this.items[first] = temp;
|
456
|
+
this.heapify(first);
|
457
|
+
}
|
458
|
+
};
|
459
|
+
|
460
|
+
priorityProto.peek = function () { return this.items[0].value; };
|
461
|
+
|
462
|
+
priorityProto.removeAt = function (index) {
|
463
|
+
this.items[index] = this.items[--this.length];
|
464
|
+
delete this.items[this.length];
|
465
|
+
this.heapify();
|
466
|
+
};
|
467
|
+
|
468
|
+
priorityProto.dequeue = function () {
|
469
|
+
var result = this.peek();
|
470
|
+
this.removeAt(0);
|
471
|
+
return result;
|
472
|
+
};
|
473
|
+
|
474
|
+
priorityProto.enqueue = function (item) {
|
475
|
+
var index = this.length++;
|
476
|
+
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
477
|
+
this.percolate(index);
|
478
|
+
};
|
479
|
+
|
480
|
+
priorityProto.remove = function (item) {
|
481
|
+
for (var i = 0; i < this.length; i++) {
|
482
|
+
if (this.items[i].value === item) {
|
483
|
+
this.removeAt(i);
|
484
|
+
return true;
|
485
|
+
}
|
486
|
+
}
|
487
|
+
return false;
|
488
|
+
};
|
489
|
+
PriorityQueue.count = 0;
|
490
|
+
/**
|
491
|
+
* Represents a group of disposable resources that are disposed together.
|
492
|
+
* @constructor
|
493
|
+
*/
|
494
|
+
var CompositeDisposable = Rx.CompositeDisposable = function () {
|
495
|
+
this.disposables = argsOrArray(arguments, 0);
|
496
|
+
this.isDisposed = false;
|
497
|
+
this.length = this.disposables.length;
|
498
|
+
};
|
499
|
+
|
500
|
+
var CompositeDisposablePrototype = CompositeDisposable.prototype;
|
501
|
+
|
502
|
+
/**
|
503
|
+
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
504
|
+
* @param {Mixed} item Disposable to add.
|
505
|
+
*/
|
506
|
+
CompositeDisposablePrototype.add = function (item) {
|
507
|
+
if (this.isDisposed) {
|
508
|
+
item.dispose();
|
509
|
+
} else {
|
510
|
+
this.disposables.push(item);
|
511
|
+
this.length++;
|
512
|
+
}
|
513
|
+
};
|
514
|
+
|
515
|
+
/**
|
516
|
+
* Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
|
517
|
+
* @param {Mixed} item Disposable to remove.
|
518
|
+
* @returns {Boolean} true if found; false otherwise.
|
519
|
+
*/
|
520
|
+
CompositeDisposablePrototype.remove = function (item) {
|
521
|
+
var shouldDispose = false;
|
522
|
+
if (!this.isDisposed) {
|
523
|
+
var idx = this.disposables.indexOf(item);
|
524
|
+
if (idx !== -1) {
|
525
|
+
shouldDispose = true;
|
526
|
+
this.disposables.splice(idx, 1);
|
527
|
+
this.length--;
|
528
|
+
item.dispose();
|
529
|
+
}
|
530
|
+
|
531
|
+
}
|
532
|
+
return shouldDispose;
|
533
|
+
};
|
534
|
+
|
535
|
+
/**
|
536
|
+
* Disposes all disposables in the group and removes them from the group.
|
537
|
+
*/
|
538
|
+
CompositeDisposablePrototype.dispose = function () {
|
539
|
+
if (!this.isDisposed) {
|
540
|
+
this.isDisposed = true;
|
541
|
+
var currentDisposables = this.disposables.slice(0);
|
542
|
+
this.disposables = [];
|
543
|
+
this.length = 0;
|
544
|
+
|
545
|
+
for (var i = 0, len = currentDisposables.length; i < len; i++) {
|
546
|
+
currentDisposables[i].dispose();
|
547
|
+
}
|
548
|
+
}
|
549
|
+
};
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Removes and disposes all disposables from the CompositeDisposable, but does not dispose the CompositeDisposable.
|
553
|
+
*/
|
554
|
+
CompositeDisposablePrototype.clear = function () {
|
555
|
+
var currentDisposables = this.disposables.slice(0);
|
556
|
+
this.disposables = [];
|
557
|
+
this.length = 0;
|
558
|
+
for (var i = 0, len = currentDisposables.length; i < len; i++) {
|
559
|
+
currentDisposables[i].dispose();
|
560
|
+
}
|
561
|
+
};
|
562
|
+
|
563
|
+
/**
|
564
|
+
* Determines whether the CompositeDisposable contains a specific disposable.
|
565
|
+
* @param {Mixed} item Disposable to search for.
|
566
|
+
* @returns {Boolean} true if the disposable was found; otherwise, false.
|
567
|
+
*/
|
568
|
+
CompositeDisposablePrototype.contains = function (item) {
|
569
|
+
return this.disposables.indexOf(item) !== -1;
|
570
|
+
};
|
571
|
+
|
572
|
+
/**
|
573
|
+
* Converts the existing CompositeDisposable to an array of disposables
|
574
|
+
* @returns {Array} An array of disposable objects.
|
575
|
+
*/
|
576
|
+
CompositeDisposablePrototype.toArray = function () {
|
577
|
+
return this.disposables.slice(0);
|
578
|
+
};
|
579
|
+
|
580
|
+
/**
|
581
|
+
* Provides a set of static methods for creating Disposables.
|
582
|
+
*
|
583
|
+
* @constructor
|
584
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
585
|
+
*/
|
586
|
+
var Disposable = Rx.Disposable = function (action) {
|
587
|
+
this.isDisposed = false;
|
588
|
+
this.action = action || noop;
|
589
|
+
};
|
590
|
+
|
591
|
+
/** Performs the task of cleaning up resources. */
|
592
|
+
Disposable.prototype.dispose = function () {
|
593
|
+
if (!this.isDisposed) {
|
594
|
+
this.action();
|
595
|
+
this.isDisposed = true;
|
596
|
+
}
|
597
|
+
};
|
598
|
+
|
599
|
+
/**
|
600
|
+
* Creates a disposable object that invokes the specified action when disposed.
|
601
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
602
|
+
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
603
|
+
*/
|
604
|
+
var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
|
605
|
+
|
606
|
+
/**
|
607
|
+
* Gets the disposable that does nothing when disposed.
|
608
|
+
*/
|
609
|
+
var disposableEmpty = Disposable.empty = { dispose: noop };
|
610
|
+
|
611
|
+
var BooleanDisposable = (function () {
|
612
|
+
function BooleanDisposable (isSingle) {
|
613
|
+
this.isSingle = isSingle;
|
614
|
+
this.isDisposed = false;
|
615
|
+
this.current = null;
|
616
|
+
}
|
617
|
+
|
618
|
+
var booleanDisposablePrototype = BooleanDisposable.prototype;
|
619
|
+
|
620
|
+
/**
|
621
|
+
* Gets the underlying disposable.
|
622
|
+
* @return The underlying disposable.
|
623
|
+
*/
|
624
|
+
booleanDisposablePrototype.getDisposable = function () {
|
625
|
+
return this.current;
|
626
|
+
};
|
627
|
+
|
628
|
+
/**
|
629
|
+
* Sets the underlying disposable.
|
630
|
+
* @param {Disposable} value The new underlying disposable.
|
631
|
+
*/
|
632
|
+
booleanDisposablePrototype.setDisposable = function (value) {
|
633
|
+
if (this.current && this.isSingle) {
|
634
|
+
throw new Error('Disposable has already been assigned');
|
635
|
+
}
|
636
|
+
|
637
|
+
var shouldDispose = this.isDisposed, old;
|
638
|
+
if (!shouldDispose) {
|
639
|
+
old = this.current;
|
640
|
+
this.current = value;
|
641
|
+
}
|
642
|
+
if (old) {
|
643
|
+
old.dispose();
|
644
|
+
}
|
645
|
+
if (shouldDispose && value) {
|
646
|
+
value.dispose();
|
647
|
+
}
|
648
|
+
};
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Disposes the underlying disposable as well as all future replacements.
|
652
|
+
*/
|
653
|
+
booleanDisposablePrototype.dispose = function () {
|
654
|
+
var old;
|
655
|
+
if (!this.isDisposed) {
|
656
|
+
this.isDisposed = true;
|
657
|
+
old = this.current;
|
658
|
+
this.current = null;
|
659
|
+
}
|
660
|
+
if (old) {
|
661
|
+
old.dispose();
|
662
|
+
}
|
663
|
+
};
|
664
|
+
|
665
|
+
return BooleanDisposable;
|
666
|
+
}());
|
667
|
+
|
668
|
+
/**
|
669
|
+
* Represents a disposable resource which only allows a single assignment of its underlying disposable resource.
|
670
|
+
* If an underlying disposable resource has already been set, future attempts to set the underlying disposable resource will throw an Error.
|
671
|
+
*/
|
672
|
+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function (super_) {
|
673
|
+
inherits(SingleAssignmentDisposable, super_);
|
674
|
+
|
675
|
+
function SingleAssignmentDisposable() {
|
676
|
+
super_.call(this, true);
|
677
|
+
}
|
678
|
+
|
679
|
+
return SingleAssignmentDisposable;
|
680
|
+
}(BooleanDisposable));
|
681
|
+
|
682
|
+
/**
|
683
|
+
* Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
|
684
|
+
*/
|
685
|
+
var SerialDisposable = Rx.SerialDisposable = (function (super_) {
|
686
|
+
inherits(SerialDisposable, super_);
|
687
|
+
|
688
|
+
function SerialDisposable() {
|
689
|
+
super_.call(this, false);
|
690
|
+
}
|
691
|
+
|
692
|
+
return SerialDisposable;
|
693
|
+
}(BooleanDisposable));
|
694
|
+
|
695
|
+
/**
|
696
|
+
* Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
|
697
|
+
*/
|
698
|
+
var RefCountDisposable = Rx.RefCountDisposable = (function () {
|
699
|
+
|
700
|
+
function InnerDisposable(disposable) {
|
701
|
+
this.disposable = disposable;
|
702
|
+
this.disposable.count++;
|
703
|
+
this.isInnerDisposed = false;
|
704
|
+
}
|
705
|
+
|
706
|
+
InnerDisposable.prototype.dispose = function () {
|
707
|
+
if (!this.disposable.isDisposed) {
|
708
|
+
if (!this.isInnerDisposed) {
|
709
|
+
this.isInnerDisposed = true;
|
710
|
+
this.disposable.count--;
|
711
|
+
if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
|
712
|
+
this.disposable.isDisposed = true;
|
713
|
+
this.disposable.underlyingDisposable.dispose();
|
714
|
+
}
|
715
|
+
}
|
716
|
+
}
|
717
|
+
};
|
718
|
+
|
719
|
+
/**
|
720
|
+
* Initializes a new instance of the RefCountDisposable with the specified disposable.
|
721
|
+
* @constructor
|
722
|
+
* @param {Disposable} disposable Underlying disposable.
|
723
|
+
*/
|
724
|
+
function RefCountDisposable(disposable) {
|
725
|
+
this.underlyingDisposable = disposable;
|
726
|
+
this.isDisposed = false;
|
727
|
+
this.isPrimaryDisposed = false;
|
728
|
+
this.count = 0;
|
729
|
+
}
|
730
|
+
|
731
|
+
/**
|
732
|
+
* Disposes the underlying disposable only when all dependent disposables have been disposed
|
733
|
+
*/
|
734
|
+
RefCountDisposable.prototype.dispose = function () {
|
735
|
+
if (!this.isDisposed) {
|
736
|
+
if (!this.isPrimaryDisposed) {
|
737
|
+
this.isPrimaryDisposed = true;
|
738
|
+
if (this.count === 0) {
|
739
|
+
this.isDisposed = true;
|
740
|
+
this.underlyingDisposable.dispose();
|
741
|
+
}
|
742
|
+
}
|
743
|
+
}
|
744
|
+
};
|
745
|
+
|
746
|
+
/**
|
747
|
+
* Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
|
748
|
+
* @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
|
749
|
+
*/
|
750
|
+
RefCountDisposable.prototype.getDisposable = function () {
|
751
|
+
return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
|
752
|
+
};
|
753
|
+
|
754
|
+
return RefCountDisposable;
|
755
|
+
})();
|
756
|
+
|
757
|
+
function ScheduledDisposable(scheduler, disposable) {
|
758
|
+
this.scheduler = scheduler;
|
759
|
+
this.disposable = disposable;
|
760
|
+
this.isDisposed = false;
|
761
|
+
}
|
762
|
+
|
763
|
+
ScheduledDisposable.prototype.dispose = function () {
|
764
|
+
var parent = this;
|
765
|
+
this.scheduler.schedule(function () {
|
766
|
+
if (!parent.isDisposed) {
|
767
|
+
parent.isDisposed = true;
|
768
|
+
parent.disposable.dispose();
|
769
|
+
}
|
770
|
+
});
|
771
|
+
};
|
772
|
+
|
773
|
+
var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
|
774
|
+
this.scheduler = scheduler;
|
775
|
+
this.state = state;
|
776
|
+
this.action = action;
|
777
|
+
this.dueTime = dueTime;
|
778
|
+
this.comparer = comparer || defaultSubComparer;
|
779
|
+
this.disposable = new SingleAssignmentDisposable();
|
780
|
+
}
|
781
|
+
|
782
|
+
ScheduledItem.prototype.invoke = function () {
|
783
|
+
this.disposable.setDisposable(this.invokeCore());
|
784
|
+
};
|
785
|
+
|
786
|
+
ScheduledItem.prototype.compareTo = function (other) {
|
787
|
+
return this.comparer(this.dueTime, other.dueTime);
|
788
|
+
};
|
789
|
+
|
790
|
+
ScheduledItem.prototype.isCancelled = function () {
|
791
|
+
return this.disposable.isDisposed;
|
792
|
+
};
|
793
|
+
|
794
|
+
ScheduledItem.prototype.invokeCore = function () {
|
795
|
+
return this.action(this.scheduler, this.state);
|
796
|
+
};
|
797
|
+
|
798
|
+
/** Provides a set of static properties to access commonly used schedulers. */
|
799
|
+
var Scheduler = Rx.Scheduler = (function () {
|
800
|
+
|
801
|
+
/**
|
802
|
+
* @constructor
|
803
|
+
* @private
|
804
|
+
*/
|
805
|
+
function Scheduler(now, schedule, scheduleRelative, scheduleAbsolute) {
|
806
|
+
this.now = now;
|
807
|
+
this._schedule = schedule;
|
808
|
+
this._scheduleRelative = scheduleRelative;
|
809
|
+
this._scheduleAbsolute = scheduleAbsolute;
|
810
|
+
}
|
811
|
+
|
812
|
+
function invokeRecImmediate(scheduler, pair) {
|
813
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
814
|
+
recursiveAction = function (state1) {
|
815
|
+
action(state1, function (state2) {
|
816
|
+
var isAdded = false, isDone = false,
|
817
|
+
d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
|
818
|
+
if (isAdded) {
|
819
|
+
group.remove(d);
|
820
|
+
} else {
|
821
|
+
isDone = true;
|
822
|
+
}
|
823
|
+
recursiveAction(state3);
|
824
|
+
return disposableEmpty;
|
825
|
+
});
|
826
|
+
if (!isDone) {
|
827
|
+
group.add(d);
|
828
|
+
isAdded = true;
|
829
|
+
}
|
830
|
+
});
|
831
|
+
};
|
832
|
+
recursiveAction(state);
|
833
|
+
return group;
|
834
|
+
}
|
835
|
+
|
836
|
+
function invokeRecDate(scheduler, pair, method) {
|
837
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
838
|
+
recursiveAction = function (state1) {
|
839
|
+
action(state1, function (state2, dueTime1) {
|
840
|
+
var isAdded = false, isDone = false,
|
841
|
+
d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
|
842
|
+
if (isAdded) {
|
843
|
+
group.remove(d);
|
844
|
+
} else {
|
845
|
+
isDone = true;
|
846
|
+
}
|
847
|
+
recursiveAction(state3);
|
848
|
+
return disposableEmpty;
|
849
|
+
});
|
850
|
+
if (!isDone) {
|
851
|
+
group.add(d);
|
852
|
+
isAdded = true;
|
853
|
+
}
|
854
|
+
});
|
855
|
+
};
|
856
|
+
recursiveAction(state);
|
857
|
+
return group;
|
858
|
+
}
|
859
|
+
|
860
|
+
function invokeAction(scheduler, action) {
|
861
|
+
action();
|
862
|
+
return disposableEmpty;
|
863
|
+
}
|
864
|
+
|
865
|
+
var schedulerProto = Scheduler.prototype;
|
866
|
+
|
867
|
+
/**
|
868
|
+
* Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions.
|
869
|
+
* @param {Function} handler Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.
|
870
|
+
* @returns {Scheduler} Wrapper around the original scheduler, enforcing exception handling.
|
871
|
+
*/
|
872
|
+
schedulerProto.catchException = schedulerProto['catch'] = function (handler) {
|
873
|
+
return new CatchScheduler(this, handler);
|
874
|
+
};
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
878
|
+
* @param {Number} period Period for running the work periodically.
|
879
|
+
* @param {Function} action Action to be executed.
|
880
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
881
|
+
*/
|
882
|
+
schedulerProto.schedulePeriodic = function (period, action) {
|
883
|
+
return this.schedulePeriodicWithState(null, period, function () {
|
884
|
+
action();
|
885
|
+
});
|
886
|
+
};
|
887
|
+
|
888
|
+
/**
|
889
|
+
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
890
|
+
* @param {Mixed} state Initial state passed to the action upon the first iteration.
|
891
|
+
* @param {Number} period Period for running the work periodically.
|
892
|
+
* @param {Function} action Action to be executed, potentially updating the state.
|
893
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
894
|
+
*/
|
895
|
+
schedulerProto.schedulePeriodicWithState = function (state, period, action) {
|
896
|
+
var s = state, id = setInterval(function () {
|
897
|
+
s = action(s);
|
898
|
+
}, period);
|
899
|
+
return disposableCreate(function () {
|
900
|
+
clearInterval(id);
|
901
|
+
});
|
902
|
+
};
|
903
|
+
|
904
|
+
/**
|
905
|
+
* Schedules an action to be executed.
|
906
|
+
* @param {Function} action Action to execute.
|
907
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
908
|
+
*/
|
909
|
+
schedulerProto.schedule = function (action) {
|
910
|
+
return this._schedule(action, invokeAction);
|
911
|
+
};
|
912
|
+
|
913
|
+
/**
|
914
|
+
* Schedules an action to be executed.
|
915
|
+
* @param state State passed to the action to be executed.
|
916
|
+
* @param {Function} action Action to be executed.
|
917
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
918
|
+
*/
|
919
|
+
schedulerProto.scheduleWithState = function (state, action) {
|
920
|
+
return this._schedule(state, action);
|
921
|
+
};
|
922
|
+
|
923
|
+
/**
|
924
|
+
* Schedules an action to be executed after the specified relative due time.
|
925
|
+
* @param {Function} action Action to execute.
|
926
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
927
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
928
|
+
*/
|
929
|
+
schedulerProto.scheduleWithRelative = function (dueTime, action) {
|
930
|
+
return this._scheduleRelative(action, dueTime, invokeAction);
|
931
|
+
};
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Schedules an action to be executed after dueTime.
|
935
|
+
* @param state State passed to the action to be executed.
|
936
|
+
* @param {Function} action Action to be executed.
|
937
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
938
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
939
|
+
*/
|
940
|
+
schedulerProto.scheduleWithRelativeAndState = function (state, dueTime, action) {
|
941
|
+
return this._scheduleRelative(state, dueTime, action);
|
942
|
+
};
|
943
|
+
|
944
|
+
/**
|
945
|
+
* Schedules an action to be executed at the specified absolute due time.
|
946
|
+
* @param {Function} action Action to execute.
|
947
|
+
* @param {Number} dueTime Absolute time at which to execute the action.
|
948
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
949
|
+
*/
|
950
|
+
schedulerProto.scheduleWithAbsolute = function (dueTime, action) {
|
951
|
+
return this._scheduleAbsolute(action, dueTime, invokeAction);
|
952
|
+
};
|
953
|
+
|
954
|
+
/**
|
955
|
+
* Schedules an action to be executed at dueTime.
|
956
|
+
* @param {Mixed} state State passed to the action to be executed.
|
957
|
+
* @param {Function} action Action to be executed.
|
958
|
+
* @param {Number}dueTime Absolute time at which to execute the action.
|
959
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
960
|
+
*/
|
961
|
+
schedulerProto.scheduleWithAbsoluteAndState = function (state, dueTime, action) {
|
962
|
+
return this._scheduleAbsolute(state, dueTime, action);
|
963
|
+
};
|
964
|
+
|
965
|
+
/**
|
966
|
+
* Schedules an action to be executed recursively.
|
967
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.
|
968
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
969
|
+
*/
|
970
|
+
schedulerProto.scheduleRecursive = function (action) {
|
971
|
+
return this.scheduleRecursiveWithState(action, function (_action, self) {
|
972
|
+
_action(function () {
|
973
|
+
self(_action);
|
974
|
+
});
|
975
|
+
});
|
976
|
+
};
|
977
|
+
|
978
|
+
/**
|
979
|
+
* Schedules an action to be executed recursively.
|
980
|
+
* @param {Mixed} state State passed to the action to be executed.
|
981
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.
|
982
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
983
|
+
*/
|
984
|
+
schedulerProto.scheduleRecursiveWithState = function (state, action) {
|
985
|
+
return this.scheduleWithState({ first: state, second: action }, function (s, p) {
|
986
|
+
return invokeRecImmediate(s, p);
|
987
|
+
});
|
988
|
+
};
|
989
|
+
|
990
|
+
/**
|
991
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
992
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified relative time.
|
993
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
994
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
995
|
+
*/
|
996
|
+
schedulerProto.scheduleRecursiveWithRelative = function (dueTime, action) {
|
997
|
+
return this.scheduleRecursiveWithRelativeAndState(action, dueTime, function (_action, self) {
|
998
|
+
_action(function (dt) {
|
999
|
+
self(_action, dt);
|
1000
|
+
});
|
1001
|
+
});
|
1002
|
+
};
|
1003
|
+
|
1004
|
+
/**
|
1005
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
1006
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1007
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1008
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1009
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1010
|
+
*/
|
1011
|
+
schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
|
1012
|
+
return this._scheduleRelative({ first: state, second: action }, dueTime, function (s, p) {
|
1013
|
+
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1014
|
+
});
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
/**
|
1018
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1019
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified absolute time.
|
1020
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1021
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1022
|
+
*/
|
1023
|
+
schedulerProto.scheduleRecursiveWithAbsolute = function (dueTime, action) {
|
1024
|
+
return this.scheduleRecursiveWithAbsoluteAndState(action, dueTime, function (_action, self) {
|
1025
|
+
_action(function (dt) {
|
1026
|
+
self(_action, dt);
|
1027
|
+
});
|
1028
|
+
});
|
1029
|
+
};
|
1030
|
+
|
1031
|
+
/**
|
1032
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1033
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1034
|
+
* @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.
|
1035
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1036
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1037
|
+
*/
|
1038
|
+
schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
|
1039
|
+
return this._scheduleAbsolute({ first: state, second: action }, dueTime, function (s, p) {
|
1040
|
+
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1041
|
+
});
|
1042
|
+
};
|
1043
|
+
|
1044
|
+
/** Gets the current time according to the local machine's system clock. */
|
1045
|
+
Scheduler.now = defaultNow;
|
1046
|
+
|
1047
|
+
/**
|
1048
|
+
* Normalizes the specified TimeSpan value to a positive value.
|
1049
|
+
* @param {Number} timeSpan The time span value to normalize.
|
1050
|
+
* @returns {Number} The specified TimeSpan value if it is zero or positive; otherwise, 0
|
1051
|
+
*/
|
1052
|
+
Scheduler.normalize = function (timeSpan) {
|
1053
|
+
if (timeSpan < 0) {
|
1054
|
+
timeSpan = 0;
|
1055
|
+
}
|
1056
|
+
return timeSpan;
|
1057
|
+
};
|
1058
|
+
|
1059
|
+
return Scheduler;
|
1060
|
+
}());
|
1061
|
+
|
1062
|
+
var normalizeTime = Scheduler.normalize;
|
1063
|
+
|
1064
|
+
var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
|
1065
|
+
function tick(command, recurse) {
|
1066
|
+
recurse(0, this._period);
|
1067
|
+
try {
|
1068
|
+
this._state = this._action(this._state);
|
1069
|
+
} catch (e) {
|
1070
|
+
this._cancel.dispose();
|
1071
|
+
throw e;
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
function SchedulePeriodicRecursive(scheduler, state, period, action) {
|
1076
|
+
this._scheduler = scheduler;
|
1077
|
+
this._state = state;
|
1078
|
+
this._period = period;
|
1079
|
+
this._action = action;
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
SchedulePeriodicRecursive.prototype.start = function () {
|
1083
|
+
var d = new SingleAssignmentDisposable();
|
1084
|
+
this._cancel = d;
|
1085
|
+
d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
|
1086
|
+
|
1087
|
+
return d;
|
1088
|
+
};
|
1089
|
+
|
1090
|
+
return SchedulePeriodicRecursive;
|
1091
|
+
}());
|
1092
|
+
|
1093
|
+
/**
|
1094
|
+
* Gets a scheduler that schedules work immediately on the current thread.
|
1095
|
+
*/
|
1096
|
+
var immediateScheduler = Scheduler.immediate = (function () {
|
1097
|
+
|
1098
|
+
function scheduleNow(state, action) { return action(this, state); }
|
1099
|
+
|
1100
|
+
function scheduleRelative(state, dueTime, action) {
|
1101
|
+
var dt = normalizeTime(dt);
|
1102
|
+
while (dt - this.now() > 0) { }
|
1103
|
+
return action(this, state);
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1107
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1111
|
+
}());
|
1112
|
+
|
1113
|
+
/**
|
1114
|
+
* Gets a scheduler that schedules work as soon as possible on the current thread.
|
1115
|
+
*/
|
1116
|
+
var currentThreadScheduler = Scheduler.currentThread = (function () {
|
1117
|
+
var queue;
|
1118
|
+
|
1119
|
+
function runTrampoline (q) {
|
1120
|
+
var item;
|
1121
|
+
while (q.length > 0) {
|
1122
|
+
item = q.dequeue();
|
1123
|
+
if (!item.isCancelled()) {
|
1124
|
+
// Note, do not schedule blocking work!
|
1125
|
+
while (item.dueTime - Scheduler.now() > 0) {
|
1126
|
+
}
|
1127
|
+
if (!item.isCancelled()) {
|
1128
|
+
item.invoke();
|
1129
|
+
}
|
1130
|
+
}
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
function scheduleNow(state, action) {
|
1135
|
+
return this.scheduleWithRelativeAndState(state, 0, action);
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
function scheduleRelative(state, dueTime, action) {
|
1139
|
+
var dt = this.now() + Scheduler.normalize(dueTime),
|
1140
|
+
si = new ScheduledItem(this, state, action, dt),
|
1141
|
+
t;
|
1142
|
+
if (!queue) {
|
1143
|
+
queue = new PriorityQueue(4);
|
1144
|
+
queue.enqueue(si);
|
1145
|
+
try {
|
1146
|
+
runTrampoline(queue);
|
1147
|
+
} catch (e) {
|
1148
|
+
throw e;
|
1149
|
+
} finally {
|
1150
|
+
queue = null;
|
1151
|
+
}
|
1152
|
+
} else {
|
1153
|
+
queue.enqueue(si);
|
1154
|
+
}
|
1155
|
+
return si.disposable;
|
1156
|
+
}
|
1157
|
+
|
1158
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1159
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
var currentScheduler = new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1163
|
+
currentScheduler.scheduleRequired = function () { return queue === null; };
|
1164
|
+
currentScheduler.ensureTrampoline = function (action) {
|
1165
|
+
if (queue === null) {
|
1166
|
+
return this.schedule(action);
|
1167
|
+
} else {
|
1168
|
+
return action();
|
1169
|
+
}
|
1170
|
+
};
|
1171
|
+
|
1172
|
+
return currentScheduler;
|
1173
|
+
}());
|
1174
|
+
|
1175
|
+
|
1176
|
+
var scheduleMethod, clearMethod = noop;
|
1177
|
+
(function () {
|
1178
|
+
|
1179
|
+
var reNative = RegExp('^' +
|
1180
|
+
String(toString)
|
1181
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1182
|
+
.replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1183
|
+
);
|
1184
|
+
|
1185
|
+
var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1186
|
+
!reNative.test(setImmediate) && setImmediate,
|
1187
|
+
clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
|
1188
|
+
!reNative.test(clearImmediate) && clearImmediate;
|
1189
|
+
|
1190
|
+
function postMessageSupported () {
|
1191
|
+
// Ensure not in a worker
|
1192
|
+
if (!root.postMessage || root.importScripts) { return false; }
|
1193
|
+
var isAsync = false,
|
1194
|
+
oldHandler = root.onmessage;
|
1195
|
+
// Test for async
|
1196
|
+
root.onmessage = function () { isAsync = true; };
|
1197
|
+
root.postMessage('','*');
|
1198
|
+
root.onmessage = oldHandler;
|
1199
|
+
|
1200
|
+
return isAsync;
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
// Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
|
1204
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1205
|
+
scheduleMethod = process.nextTick;
|
1206
|
+
} else if (typeof setImmediate === 'function') {
|
1207
|
+
scheduleMethod = setImmediate;
|
1208
|
+
clearMethod = clearImmediate;
|
1209
|
+
} else if (postMessageSupported()) {
|
1210
|
+
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1211
|
+
tasks = {},
|
1212
|
+
taskId = 0;
|
1213
|
+
|
1214
|
+
function onGlobalPostMessage(event) {
|
1215
|
+
// Only if we're a match to avoid any other global events
|
1216
|
+
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1217
|
+
var handleId = event.data.substring(MSG_PREFIX.length),
|
1218
|
+
action = tasks[handleId];
|
1219
|
+
action();
|
1220
|
+
delete tasks[handleId];
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
if (root.addEventListener) {
|
1225
|
+
root.addEventListener('message', onGlobalPostMessage, false);
|
1226
|
+
} else {
|
1227
|
+
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
scheduleMethod = function (action) {
|
1231
|
+
var currentId = taskId++;
|
1232
|
+
tasks[currentId] = action;
|
1233
|
+
root.postMessage(MSG_PREFIX + currentId, '*');
|
1234
|
+
};
|
1235
|
+
} else if (!!root.MessageChannel) {
|
1236
|
+
var channel = new root.MessageChannel(),
|
1237
|
+
channelTasks = {},
|
1238
|
+
channelTaskId = 0;
|
1239
|
+
|
1240
|
+
channel.port1.onmessage = function (event) {
|
1241
|
+
var id = event.data,
|
1242
|
+
action = channelTasks[id];
|
1243
|
+
action();
|
1244
|
+
delete channelTasks[id];
|
1245
|
+
};
|
1246
|
+
|
1247
|
+
scheduleMethod = function (action) {
|
1248
|
+
var id = channelTaskId++;
|
1249
|
+
channelTasks[id] = action;
|
1250
|
+
channel.port2.postMessage(id);
|
1251
|
+
};
|
1252
|
+
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1253
|
+
|
1254
|
+
scheduleMethod = function (action) {
|
1255
|
+
var scriptElement = root.document.createElement('script');
|
1256
|
+
scriptElement.onreadystatechange = function () {
|
1257
|
+
action();
|
1258
|
+
scriptElement.onreadystatechange = null;
|
1259
|
+
scriptElement.parentNode.removeChild(scriptElement);
|
1260
|
+
scriptElement = null;
|
1261
|
+
};
|
1262
|
+
root.document.documentElement.appendChild(scriptElement);
|
1263
|
+
};
|
1264
|
+
|
1265
|
+
} else {
|
1266
|
+
scheduleMethod = function (action) { return setTimeout(action, 0); };
|
1267
|
+
clearMethod = clearTimeout;
|
1268
|
+
}
|
1269
|
+
}());
|
1270
|
+
|
1271
|
+
/**
|
1272
|
+
* Gets a scheduler that schedules work via a timed callback based upon platform.
|
1273
|
+
*/
|
1274
|
+
var timeoutScheduler = Scheduler.timeout = (function () {
|
1275
|
+
|
1276
|
+
function scheduleNow(state, action) {
|
1277
|
+
var scheduler = this,
|
1278
|
+
disposable = new SingleAssignmentDisposable();
|
1279
|
+
var id = scheduleMethod(function () {
|
1280
|
+
if (!disposable.isDisposed) {
|
1281
|
+
disposable.setDisposable(action(scheduler, state));
|
1282
|
+
}
|
1283
|
+
});
|
1284
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1285
|
+
clearMethod(id);
|
1286
|
+
}));
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
function scheduleRelative(state, dueTime, action) {
|
1290
|
+
var scheduler = this,
|
1291
|
+
dt = Scheduler.normalize(dueTime);
|
1292
|
+
if (dt === 0) {
|
1293
|
+
return scheduler.scheduleWithState(state, action);
|
1294
|
+
}
|
1295
|
+
var disposable = new SingleAssignmentDisposable();
|
1296
|
+
var id = setTimeout(function () {
|
1297
|
+
if (!disposable.isDisposed) {
|
1298
|
+
disposable.setDisposable(action(scheduler, state));
|
1299
|
+
}
|
1300
|
+
}, dt);
|
1301
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1302
|
+
clearTimeout(id);
|
1303
|
+
}));
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1307
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1308
|
+
}
|
1309
|
+
|
1310
|
+
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1311
|
+
})();
|
1312
|
+
|
1313
|
+
/** @private */
|
1314
|
+
var CatchScheduler = (function (_super) {
|
1315
|
+
|
1316
|
+
function localNow() {
|
1317
|
+
return this._scheduler.now();
|
1318
|
+
}
|
1319
|
+
|
1320
|
+
function scheduleNow(state, action) {
|
1321
|
+
return this._scheduler.scheduleWithState(state, this._wrap(action));
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
function scheduleRelative(state, dueTime, action) {
|
1325
|
+
return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
|
1326
|
+
}
|
1327
|
+
|
1328
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1329
|
+
return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
|
1330
|
+
}
|
1331
|
+
|
1332
|
+
inherits(CatchScheduler, _super);
|
1333
|
+
|
1334
|
+
/** @private */
|
1335
|
+
function CatchScheduler(scheduler, handler) {
|
1336
|
+
this._scheduler = scheduler;
|
1337
|
+
this._handler = handler;
|
1338
|
+
this._recursiveOriginal = null;
|
1339
|
+
this._recursiveWrapper = null;
|
1340
|
+
_super.call(this, localNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
/** @private */
|
1344
|
+
CatchScheduler.prototype._clone = function (scheduler) {
|
1345
|
+
return new CatchScheduler(scheduler, this._handler);
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
/** @private */
|
1349
|
+
CatchScheduler.prototype._wrap = function (action) {
|
1350
|
+
var parent = this;
|
1351
|
+
return function (self, state) {
|
1352
|
+
try {
|
1353
|
+
return action(parent._getRecursiveWrapper(self), state);
|
1354
|
+
} catch (e) {
|
1355
|
+
if (!parent._handler(e)) { throw e; }
|
1356
|
+
return disposableEmpty;
|
1357
|
+
}
|
1358
|
+
};
|
1359
|
+
};
|
1360
|
+
|
1361
|
+
/** @private */
|
1362
|
+
CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
|
1363
|
+
if (this._recursiveOriginal !== scheduler) {
|
1364
|
+
this._recursiveOriginal = scheduler;
|
1365
|
+
var wrapper = this._clone(scheduler);
|
1366
|
+
wrapper._recursiveOriginal = scheduler;
|
1367
|
+
wrapper._recursiveWrapper = wrapper;
|
1368
|
+
this._recursiveWrapper = wrapper;
|
1369
|
+
}
|
1370
|
+
return this._recursiveWrapper;
|
1371
|
+
};
|
1372
|
+
|
1373
|
+
/** @private */
|
1374
|
+
CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
|
1375
|
+
var self = this, failed = false, d = new SingleAssignmentDisposable();
|
1376
|
+
|
1377
|
+
d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
|
1378
|
+
if (failed) { return null; }
|
1379
|
+
try {
|
1380
|
+
return action(state1);
|
1381
|
+
} catch (e) {
|
1382
|
+
failed = true;
|
1383
|
+
if (!self._handler(e)) { throw e; }
|
1384
|
+
d.dispose();
|
1385
|
+
return null;
|
1386
|
+
}
|
1387
|
+
}));
|
1388
|
+
|
1389
|
+
return d;
|
1390
|
+
};
|
1391
|
+
|
1392
|
+
return CatchScheduler;
|
1393
|
+
}(Scheduler));
|
1394
|
+
|
1395
|
+
/**
|
1396
|
+
* Represents a notification to an observer.
|
1397
|
+
*/
|
1398
|
+
var Notification = Rx.Notification = (function () {
|
1399
|
+
function Notification(kind, hasValue) {
|
1400
|
+
this.hasValue = hasValue == null ? false : hasValue;
|
1401
|
+
this.kind = kind;
|
1402
|
+
}
|
1403
|
+
|
1404
|
+
var NotificationPrototype = Notification.prototype;
|
1405
|
+
|
1406
|
+
/**
|
1407
|
+
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1408
|
+
*
|
1409
|
+
* @memberOf Notification
|
1410
|
+
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1411
|
+
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1412
|
+
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1413
|
+
* @returns {Any} Result produced by the observation.
|
1414
|
+
*/
|
1415
|
+
NotificationPrototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1416
|
+
if (arguments.length === 1 && typeof observerOrOnNext === 'object') {
|
1417
|
+
return this._acceptObservable(observerOrOnNext);
|
1418
|
+
}
|
1419
|
+
return this._accept(observerOrOnNext, onError, onCompleted);
|
1420
|
+
};
|
1421
|
+
|
1422
|
+
/**
|
1423
|
+
* Returns an observable sequence with a single notification.
|
1424
|
+
*
|
1425
|
+
* @memberOf Notification
|
1426
|
+
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1427
|
+
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1428
|
+
*/
|
1429
|
+
NotificationPrototype.toObservable = function (scheduler) {
|
1430
|
+
var notification = this;
|
1431
|
+
scheduler || (scheduler = immediateScheduler);
|
1432
|
+
return new AnonymousObservable(function (observer) {
|
1433
|
+
return scheduler.schedule(function () {
|
1434
|
+
notification._acceptObservable(observer);
|
1435
|
+
if (notification.kind === 'N') {
|
1436
|
+
observer.onCompleted();
|
1437
|
+
}
|
1438
|
+
});
|
1439
|
+
});
|
1440
|
+
};
|
1441
|
+
|
1442
|
+
return Notification;
|
1443
|
+
})();
|
1444
|
+
|
1445
|
+
/**
|
1446
|
+
* Creates an object that represents an OnNext notification to an observer.
|
1447
|
+
* @param {Any} value The value contained in the notification.
|
1448
|
+
* @returns {Notification} The OnNext notification containing the value.
|
1449
|
+
*/
|
1450
|
+
var notificationCreateOnNext = Notification.createOnNext = (function () {
|
1451
|
+
|
1452
|
+
function _accept (onNext) {
|
1453
|
+
return onNext(this.value);
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
function _acceptObservable(observer) {
|
1457
|
+
return observer.onNext(this.value);
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
function toString () {
|
1461
|
+
return 'OnNext(' + this.value + ')';
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
return function (value) {
|
1465
|
+
var notification = new Notification('N', true);
|
1466
|
+
notification.value = value;
|
1467
|
+
notification._accept = _accept;
|
1468
|
+
notification._acceptObservable = _acceptObservable;
|
1469
|
+
notification.toString = toString;
|
1470
|
+
return notification;
|
1471
|
+
};
|
1472
|
+
}());
|
1473
|
+
|
1474
|
+
/**
|
1475
|
+
* Creates an object that represents an OnError notification to an observer.
|
1476
|
+
* @param {Any} error The exception contained in the notification.
|
1477
|
+
* @returns {Notification} The OnError notification containing the exception.
|
1478
|
+
*/
|
1479
|
+
var notificationCreateOnError = Notification.createOnError = (function () {
|
1480
|
+
|
1481
|
+
function _accept (onNext, onError) {
|
1482
|
+
return onError(this.exception);
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
function _acceptObservable(observer) {
|
1486
|
+
return observer.onError(this.exception);
|
1487
|
+
}
|
1488
|
+
|
1489
|
+
function toString () {
|
1490
|
+
return 'OnError(' + this.exception + ')';
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
return function (exception) {
|
1494
|
+
var notification = new Notification('E');
|
1495
|
+
notification.exception = exception;
|
1496
|
+
notification._accept = _accept;
|
1497
|
+
notification._acceptObservable = _acceptObservable;
|
1498
|
+
notification.toString = toString;
|
1499
|
+
return notification;
|
1500
|
+
};
|
1501
|
+
}());
|
1502
|
+
|
1503
|
+
/**
|
1504
|
+
* Creates an object that represents an OnCompleted notification to an observer.
|
1505
|
+
* @returns {Notification} The OnCompleted notification.
|
1506
|
+
*/
|
1507
|
+
var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
|
1508
|
+
|
1509
|
+
function _accept (onNext, onError, onCompleted) {
|
1510
|
+
return onCompleted();
|
1511
|
+
}
|
1512
|
+
|
1513
|
+
function _acceptObservable(observer) {
|
1514
|
+
return observer.onCompleted();
|
1515
|
+
}
|
1516
|
+
|
1517
|
+
function toString () {
|
1518
|
+
return 'OnCompleted()';
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
return function () {
|
1522
|
+
var notification = new Notification('C');
|
1523
|
+
notification._accept = _accept;
|
1524
|
+
notification._acceptObservable = _acceptObservable;
|
1525
|
+
notification.toString = toString;
|
1526
|
+
return notification;
|
1527
|
+
};
|
1528
|
+
}());
|
1529
|
+
|
1530
|
+
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1531
|
+
this._next = next;
|
1532
|
+
};
|
1533
|
+
|
1534
|
+
Enumerator.prototype.next = function () {
|
1535
|
+
return this._next();
|
1536
|
+
};
|
1537
|
+
|
1538
|
+
Enumerator.prototype[$iterator$] = function () { return this; }
|
1539
|
+
|
1540
|
+
var Enumerable = Rx.internals.Enumerable = function (iterator) {
|
1541
|
+
this._iterator = iterator;
|
1542
|
+
};
|
1543
|
+
|
1544
|
+
Enumerable.prototype[$iterator$] = function () {
|
1545
|
+
return this._iterator();
|
1546
|
+
};
|
1547
|
+
|
1548
|
+
Enumerable.prototype.concat = function () {
|
1549
|
+
var sources = this;
|
1550
|
+
return new AnonymousObservable(function (observer) {
|
1551
|
+
var e;
|
1552
|
+
try {
|
1553
|
+
e = sources[$iterator$]();
|
1554
|
+
} catch(err) {
|
1555
|
+
observer.onError();
|
1556
|
+
return;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
var isDisposed,
|
1560
|
+
subscription = new SerialDisposable();
|
1561
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1562
|
+
var currentItem;
|
1563
|
+
if (isDisposed) { return; }
|
1564
|
+
|
1565
|
+
try {
|
1566
|
+
currentItem = e.next();
|
1567
|
+
} catch (ex) {
|
1568
|
+
observer.onError(ex);
|
1569
|
+
return;
|
1570
|
+
}
|
1571
|
+
|
1572
|
+
if (currentItem.done) {
|
1573
|
+
observer.onCompleted();
|
1574
|
+
return;
|
1575
|
+
}
|
1576
|
+
|
1577
|
+
// Check if promise
|
1578
|
+
var currentValue = currentItem.value;
|
1579
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1580
|
+
|
1581
|
+
var d = new SingleAssignmentDisposable();
|
1582
|
+
subscription.setDisposable(d);
|
1583
|
+
d.setDisposable(currentValue.subscribe(
|
1584
|
+
observer.onNext.bind(observer),
|
1585
|
+
observer.onError.bind(observer),
|
1586
|
+
function () { self(); })
|
1587
|
+
);
|
1588
|
+
});
|
1589
|
+
|
1590
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1591
|
+
isDisposed = true;
|
1592
|
+
}));
|
1593
|
+
});
|
1594
|
+
};
|
1595
|
+
|
1596
|
+
Enumerable.prototype.catchException = function () {
|
1597
|
+
var sources = this;
|
1598
|
+
return new AnonymousObservable(function (observer) {
|
1599
|
+
var e;
|
1600
|
+
try {
|
1601
|
+
e = sources[$iterator$]();
|
1602
|
+
} catch(err) {
|
1603
|
+
observer.onError();
|
1604
|
+
return;
|
1605
|
+
}
|
1606
|
+
|
1607
|
+
var isDisposed,
|
1608
|
+
lastException,
|
1609
|
+
subscription = new SerialDisposable();
|
1610
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1611
|
+
if (isDisposed) { return; }
|
1612
|
+
|
1613
|
+
var currentItem;
|
1614
|
+
try {
|
1615
|
+
currentItem = e.next();
|
1616
|
+
} catch (ex) {
|
1617
|
+
observer.onError(ex);
|
1618
|
+
return;
|
1619
|
+
}
|
1620
|
+
|
1621
|
+
if (currentItem.done) {
|
1622
|
+
if (lastException) {
|
1623
|
+
observer.onError(lastException);
|
1624
|
+
} else {
|
1625
|
+
observer.onCompleted();
|
1626
|
+
}
|
1627
|
+
return;
|
1628
|
+
}
|
1629
|
+
|
1630
|
+
// Check if promise
|
1631
|
+
var currentValue = currentItem.value;
|
1632
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1633
|
+
|
1634
|
+
var d = new SingleAssignmentDisposable();
|
1635
|
+
subscription.setDisposable(d);
|
1636
|
+
d.setDisposable(currentValue.subscribe(
|
1637
|
+
observer.onNext.bind(observer),
|
1638
|
+
function (exn) {
|
1639
|
+
lastException = exn;
|
1640
|
+
self();
|
1641
|
+
},
|
1642
|
+
observer.onCompleted.bind(observer)));
|
1643
|
+
});
|
1644
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1645
|
+
isDisposed = true;
|
1646
|
+
}));
|
1647
|
+
});
|
1648
|
+
};
|
1649
|
+
|
1650
|
+
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
1651
|
+
if (repeatCount == null) { repeatCount = -1; }
|
1652
|
+
return new Enumerable(function () {
|
1653
|
+
var left = repeatCount;
|
1654
|
+
return new Enumerator(function () {
|
1655
|
+
if (left === 0) { return doneEnumerator; }
|
1656
|
+
if (left > 0) { left--; }
|
1657
|
+
return { done: false, value: value };
|
1658
|
+
});
|
1659
|
+
});
|
1660
|
+
};
|
1661
|
+
|
1662
|
+
var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
|
1663
|
+
selector || (selector = identity);
|
1664
|
+
return new Enumerable(function () {
|
1665
|
+
var index = -1;
|
1666
|
+
return new Enumerator(
|
1667
|
+
function () {
|
1668
|
+
return ++index < source.length ?
|
1669
|
+
{ done: false, value: selector.call(thisArg, source[index], index, source) } :
|
1670
|
+
doneEnumerator;
|
1671
|
+
});
|
1672
|
+
});
|
1673
|
+
};
|
1674
|
+
|
1675
|
+
/**
|
1676
|
+
* Supports push-style iteration over an observable sequence.
|
1677
|
+
*/
|
1678
|
+
var Observer = Rx.Observer = function () { };
|
1679
|
+
|
1680
|
+
/**
|
1681
|
+
* Creates a notification callback from an observer.
|
1682
|
+
*
|
1683
|
+
* @param observer Observer object.
|
1684
|
+
* @returns The action that forwards its input notification to the underlying observer.
|
1685
|
+
*/
|
1686
|
+
Observer.prototype.toNotifier = function () {
|
1687
|
+
var observer = this;
|
1688
|
+
return function (n) {
|
1689
|
+
return n.accept(observer);
|
1690
|
+
};
|
1691
|
+
};
|
1692
|
+
|
1693
|
+
/**
|
1694
|
+
* Hides the identity of an observer.
|
1695
|
+
|
1696
|
+
* @returns An observer that hides the identity of the specified observer.
|
1697
|
+
*/
|
1698
|
+
Observer.prototype.asObserver = function () {
|
1699
|
+
return new AnonymousObserver(this.onNext.bind(this), this.onError.bind(this), this.onCompleted.bind(this));
|
1700
|
+
};
|
1701
|
+
|
1702
|
+
/**
|
1703
|
+
* Checks access to the observer for grammar violations. This includes checking for multiple OnError or OnCompleted calls, as well as reentrancy in any of the observer methods.
|
1704
|
+
* If a violation is detected, an Error is thrown from the offending observer method call.
|
1705
|
+
*
|
1706
|
+
* @returns An observer that checks callbacks invocations against the observer grammar and, if the checks pass, forwards those to the specified observer.
|
1707
|
+
*/
|
1708
|
+
Observer.prototype.checked = function () { return new CheckedObserver(this); };
|
1709
|
+
|
1710
|
+
/**
|
1711
|
+
* Creates an observer from the specified OnNext, along with optional OnError, and OnCompleted actions.
|
1712
|
+
*
|
1713
|
+
* @static
|
1714
|
+
* @memberOf Observer
|
1715
|
+
* @param {Function} [onNext] Observer's OnNext action implementation.
|
1716
|
+
* @param {Function} [onError] Observer's OnError action implementation.
|
1717
|
+
* @param {Function} [onCompleted] Observer's OnCompleted action implementation.
|
1718
|
+
* @returns {Observer} The observer object implemented using the given actions.
|
1719
|
+
*/
|
1720
|
+
var observerCreate = Observer.create = function (onNext, onError, onCompleted) {
|
1721
|
+
onNext || (onNext = noop);
|
1722
|
+
onError || (onError = defaultError);
|
1723
|
+
onCompleted || (onCompleted = noop);
|
1724
|
+
return new AnonymousObserver(onNext, onError, onCompleted);
|
1725
|
+
};
|
1726
|
+
|
1727
|
+
/**
|
1728
|
+
* Creates an observer from a notification callback.
|
1729
|
+
*
|
1730
|
+
* @static
|
1731
|
+
* @memberOf Observer
|
1732
|
+
* @param {Function} handler Action that handles a notification.
|
1733
|
+
* @returns The observer object that invokes the specified handler using a notification corresponding to each message it receives.
|
1734
|
+
*/
|
1735
|
+
Observer.fromNotifier = function (handler) {
|
1736
|
+
return new AnonymousObserver(function (x) {
|
1737
|
+
return handler(notificationCreateOnNext(x));
|
1738
|
+
}, function (exception) {
|
1739
|
+
return handler(notificationCreateOnError(exception));
|
1740
|
+
}, function () {
|
1741
|
+
return handler(notificationCreateOnCompleted());
|
1742
|
+
});
|
1743
|
+
};
|
1744
|
+
|
1745
|
+
/**
|
1746
|
+
* Schedules the invocation of observer methods on the given scheduler.
|
1747
|
+
* @param {Scheduler} scheduler Scheduler to schedule observer messages on.
|
1748
|
+
* @returns {Observer} Observer whose messages are scheduled on the given scheduler.
|
1749
|
+
*/
|
1750
|
+
Observer.notifyOn = function (scheduler) {
|
1751
|
+
return new ObserveOnObserver(scheduler, this);
|
1752
|
+
};
|
1753
|
+
|
1754
|
+
/**
|
1755
|
+
* Abstract base class for implementations of the Observer class.
|
1756
|
+
* This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
|
1757
|
+
*/
|
1758
|
+
var AbstractObserver = Rx.internals.AbstractObserver = (function (_super) {
|
1759
|
+
inherits(AbstractObserver, _super);
|
1760
|
+
|
1761
|
+
/**
|
1762
|
+
* Creates a new observer in a non-stopped state.
|
1763
|
+
*
|
1764
|
+
* @constructor
|
1765
|
+
*/
|
1766
|
+
function AbstractObserver() {
|
1767
|
+
this.isStopped = false;
|
1768
|
+
_super.call(this);
|
1769
|
+
}
|
1770
|
+
|
1771
|
+
/**
|
1772
|
+
* Notifies the observer of a new element in the sequence.
|
1773
|
+
*
|
1774
|
+
* @memberOf AbstractObserver
|
1775
|
+
* @param {Any} value Next element in the sequence.
|
1776
|
+
*/
|
1777
|
+
AbstractObserver.prototype.onNext = function (value) {
|
1778
|
+
if (!this.isStopped) {
|
1779
|
+
this.next(value);
|
1780
|
+
}
|
1781
|
+
};
|
1782
|
+
|
1783
|
+
/**
|
1784
|
+
* Notifies the observer that an exception has occurred.
|
1785
|
+
*
|
1786
|
+
* @memberOf AbstractObserver
|
1787
|
+
* @param {Any} error The error that has occurred.
|
1788
|
+
*/
|
1789
|
+
AbstractObserver.prototype.onError = function (error) {
|
1790
|
+
if (!this.isStopped) {
|
1791
|
+
this.isStopped = true;
|
1792
|
+
this.error(error);
|
1793
|
+
}
|
1794
|
+
};
|
1795
|
+
|
1796
|
+
/**
|
1797
|
+
* Notifies the observer of the end of the sequence.
|
1798
|
+
*/
|
1799
|
+
AbstractObserver.prototype.onCompleted = function () {
|
1800
|
+
if (!this.isStopped) {
|
1801
|
+
this.isStopped = true;
|
1802
|
+
this.completed();
|
1803
|
+
}
|
1804
|
+
};
|
1805
|
+
|
1806
|
+
/**
|
1807
|
+
* Disposes the observer, causing it to transition to the stopped state.
|
1808
|
+
*/
|
1809
|
+
AbstractObserver.prototype.dispose = function () {
|
1810
|
+
this.isStopped = true;
|
1811
|
+
};
|
1812
|
+
|
1813
|
+
AbstractObserver.prototype.fail = function (e) {
|
1814
|
+
if (!this.isStopped) {
|
1815
|
+
this.isStopped = true;
|
1816
|
+
this.error(e);
|
1817
|
+
return true;
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
return false;
|
1821
|
+
};
|
1822
|
+
|
1823
|
+
return AbstractObserver;
|
1824
|
+
}(Observer));
|
1825
|
+
|
1826
|
+
/**
|
1827
|
+
* Class to create an Observer instance from delegate-based implementations of the on* methods.
|
1828
|
+
*/
|
1829
|
+
var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
|
1830
|
+
inherits(AnonymousObserver, _super);
|
1831
|
+
|
1832
|
+
/**
|
1833
|
+
* Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
|
1834
|
+
* @param {Any} onNext Observer's OnNext action implementation.
|
1835
|
+
* @param {Any} onError Observer's OnError action implementation.
|
1836
|
+
* @param {Any} onCompleted Observer's OnCompleted action implementation.
|
1837
|
+
*/
|
1838
|
+
function AnonymousObserver(onNext, onError, onCompleted) {
|
1839
|
+
_super.call(this);
|
1840
|
+
this._onNext = onNext;
|
1841
|
+
this._onError = onError;
|
1842
|
+
this._onCompleted = onCompleted;
|
1843
|
+
}
|
1844
|
+
|
1845
|
+
/**
|
1846
|
+
* Calls the onNext action.
|
1847
|
+
* @param {Any} value Next element in the sequence.
|
1848
|
+
*/
|
1849
|
+
AnonymousObserver.prototype.next = function (value) {
|
1850
|
+
this._onNext(value);
|
1851
|
+
};
|
1852
|
+
|
1853
|
+
/**
|
1854
|
+
* Calls the onError action.
|
1855
|
+
* @param {Any} error The error that has occurred.
|
1856
|
+
*/
|
1857
|
+
AnonymousObserver.prototype.error = function (exception) {
|
1858
|
+
this._onError(exception);
|
1859
|
+
};
|
1860
|
+
|
1861
|
+
/**
|
1862
|
+
* Calls the onCompleted action.
|
1863
|
+
*/
|
1864
|
+
AnonymousObserver.prototype.completed = function () {
|
1865
|
+
this._onCompleted();
|
1866
|
+
};
|
1867
|
+
|
1868
|
+
return AnonymousObserver;
|
1869
|
+
}(AbstractObserver));
|
1870
|
+
|
1871
|
+
var CheckedObserver = (function (_super) {
|
1872
|
+
inherits(CheckedObserver, _super);
|
1873
|
+
|
1874
|
+
function CheckedObserver(observer) {
|
1875
|
+
_super.call(this);
|
1876
|
+
this._observer = observer;
|
1877
|
+
this._state = 0; // 0 - idle, 1 - busy, 2 - done
|
1878
|
+
}
|
1879
|
+
|
1880
|
+
var CheckedObserverPrototype = CheckedObserver.prototype;
|
1881
|
+
|
1882
|
+
CheckedObserverPrototype.onNext = function (value) {
|
1883
|
+
this.checkAccess();
|
1884
|
+
try {
|
1885
|
+
this._observer.onNext(value);
|
1886
|
+
} catch (e) {
|
1887
|
+
throw e;
|
1888
|
+
} finally {
|
1889
|
+
this._state = 0;
|
1890
|
+
}
|
1891
|
+
};
|
1892
|
+
|
1893
|
+
CheckedObserverPrototype.onError = function (err) {
|
1894
|
+
this.checkAccess();
|
1895
|
+
try {
|
1896
|
+
this._observer.onError(err);
|
1897
|
+
} catch (e) {
|
1898
|
+
throw e;
|
1899
|
+
} finally {
|
1900
|
+
this._state = 2;
|
1901
|
+
}
|
1902
|
+
};
|
1903
|
+
|
1904
|
+
CheckedObserverPrototype.onCompleted = function () {
|
1905
|
+
this.checkAccess();
|
1906
|
+
try {
|
1907
|
+
this._observer.onCompleted();
|
1908
|
+
} catch (e) {
|
1909
|
+
throw e;
|
1910
|
+
} finally {
|
1911
|
+
this._state = 2;
|
1912
|
+
}
|
1913
|
+
};
|
1914
|
+
|
1915
|
+
CheckedObserverPrototype.checkAccess = function () {
|
1916
|
+
if (this._state === 1) { throw new Error('Re-entrancy detected'); }
|
1917
|
+
if (this._state === 2) { throw new Error('Observer completed'); }
|
1918
|
+
if (this._state === 0) { this._state = 1; }
|
1919
|
+
};
|
1920
|
+
|
1921
|
+
return CheckedObserver;
|
1922
|
+
}(Observer));
|
1923
|
+
|
1924
|
+
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
|
1925
|
+
inherits(ScheduledObserver, _super);
|
1926
|
+
|
1927
|
+
function ScheduledObserver(scheduler, observer) {
|
1928
|
+
_super.call(this);
|
1929
|
+
this.scheduler = scheduler;
|
1930
|
+
this.observer = observer;
|
1931
|
+
this.isAcquired = false;
|
1932
|
+
this.hasFaulted = false;
|
1933
|
+
this.queue = [];
|
1934
|
+
this.disposable = new SerialDisposable();
|
1935
|
+
}
|
1936
|
+
|
1937
|
+
ScheduledObserver.prototype.next = function (value) {
|
1938
|
+
var self = this;
|
1939
|
+
this.queue.push(function () {
|
1940
|
+
self.observer.onNext(value);
|
1941
|
+
});
|
1942
|
+
};
|
1943
|
+
|
1944
|
+
ScheduledObserver.prototype.error = function (exception) {
|
1945
|
+
var self = this;
|
1946
|
+
this.queue.push(function () {
|
1947
|
+
self.observer.onError(exception);
|
1948
|
+
});
|
1949
|
+
};
|
1950
|
+
|
1951
|
+
ScheduledObserver.prototype.completed = function () {
|
1952
|
+
var self = this;
|
1953
|
+
this.queue.push(function () {
|
1954
|
+
self.observer.onCompleted();
|
1955
|
+
});
|
1956
|
+
};
|
1957
|
+
|
1958
|
+
ScheduledObserver.prototype.ensureActive = function () {
|
1959
|
+
var isOwner = false, parent = this;
|
1960
|
+
if (!this.hasFaulted && this.queue.length > 0) {
|
1961
|
+
isOwner = !this.isAcquired;
|
1962
|
+
this.isAcquired = true;
|
1963
|
+
}
|
1964
|
+
if (isOwner) {
|
1965
|
+
this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
|
1966
|
+
var work;
|
1967
|
+
if (parent.queue.length > 0) {
|
1968
|
+
work = parent.queue.shift();
|
1969
|
+
} else {
|
1970
|
+
parent.isAcquired = false;
|
1971
|
+
return;
|
1972
|
+
}
|
1973
|
+
try {
|
1974
|
+
work();
|
1975
|
+
} catch (ex) {
|
1976
|
+
parent.queue = [];
|
1977
|
+
parent.hasFaulted = true;
|
1978
|
+
throw ex;
|
1979
|
+
}
|
1980
|
+
self();
|
1981
|
+
}));
|
1982
|
+
}
|
1983
|
+
};
|
1984
|
+
|
1985
|
+
ScheduledObserver.prototype.dispose = function () {
|
1986
|
+
_super.prototype.dispose.call(this);
|
1987
|
+
this.disposable.dispose();
|
1988
|
+
};
|
1989
|
+
|
1990
|
+
return ScheduledObserver;
|
1991
|
+
}(AbstractObserver));
|
1992
|
+
|
1993
|
+
/** @private */
|
1994
|
+
var ObserveOnObserver = (function (_super) {
|
1995
|
+
inherits(ObserveOnObserver, _super);
|
1996
|
+
|
1997
|
+
/** @private */
|
1998
|
+
function ObserveOnObserver() {
|
1999
|
+
_super.apply(this, arguments);
|
2000
|
+
}
|
2001
|
+
|
2002
|
+
/** @private */
|
2003
|
+
ObserveOnObserver.prototype.next = function (value) {
|
2004
|
+
_super.prototype.next.call(this, value);
|
2005
|
+
this.ensureActive();
|
2006
|
+
};
|
2007
|
+
|
2008
|
+
/** @private */
|
2009
|
+
ObserveOnObserver.prototype.error = function (e) {
|
2010
|
+
_super.prototype.error.call(this, e);
|
2011
|
+
this.ensureActive();
|
2012
|
+
};
|
2013
|
+
|
2014
|
+
/** @private */
|
2015
|
+
ObserveOnObserver.prototype.completed = function () {
|
2016
|
+
_super.prototype.completed.call(this);
|
2017
|
+
this.ensureActive();
|
2018
|
+
};
|
2019
|
+
|
2020
|
+
return ObserveOnObserver;
|
2021
|
+
})(ScheduledObserver);
|
2022
|
+
|
2023
|
+
var observableProto;
|
2024
|
+
|
2025
|
+
/**
|
2026
|
+
* Represents a push-style collection.
|
2027
|
+
*/
|
2028
|
+
var Observable = Rx.Observable = (function () {
|
2029
|
+
|
2030
|
+
function Observable(subscribe) {
|
2031
|
+
this._subscribe = subscribe;
|
2032
|
+
}
|
2033
|
+
|
2034
|
+
observableProto = Observable.prototype;
|
2035
|
+
|
2036
|
+
/**
|
2037
|
+
* Subscribes an observer to the observable sequence.
|
2038
|
+
*
|
2039
|
+
* @example
|
2040
|
+
* 1 - source.subscribe();
|
2041
|
+
* 2 - source.subscribe(observer);
|
2042
|
+
* 3 - source.subscribe(function (x) { console.log(x); });
|
2043
|
+
* 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
|
2044
|
+
* 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
|
2045
|
+
* @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
|
2046
|
+
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
|
2047
|
+
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
|
2048
|
+
* @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
|
2049
|
+
*/
|
2050
|
+
observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
|
2051
|
+
var subscriber = typeof observerOrOnNext === 'object' ?
|
2052
|
+
observerOrOnNext :
|
2053
|
+
observerCreate(observerOrOnNext, onError, onCompleted);
|
2054
|
+
|
2055
|
+
return this._subscribe(subscriber);
|
2056
|
+
};
|
2057
|
+
|
2058
|
+
return Observable;
|
2059
|
+
})();
|
2060
|
+
|
2061
|
+
var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
|
2062
|
+
inherits(AnonymousObservable, __super__);
|
2063
|
+
|
2064
|
+
// Fix subscriber to check for undefined or function returned to decorate as Disposable
|
2065
|
+
function fixSubscriber(subscriber) {
|
2066
|
+
if (typeof subscriber === 'undefined') {
|
2067
|
+
subscriber = disposableEmpty;
|
2068
|
+
} else if (typeof subscriber === 'function') {
|
2069
|
+
subscriber = disposableCreate(subscriber);
|
2070
|
+
}
|
2071
|
+
|
2072
|
+
return subscriber;
|
2073
|
+
}
|
2074
|
+
|
2075
|
+
function AnonymousObservable(subscribe) {
|
2076
|
+
if (!(this instanceof AnonymousObservable)) {
|
2077
|
+
return new AnonymousObservable(subscribe);
|
2078
|
+
}
|
2079
|
+
|
2080
|
+
function s(observer) {
|
2081
|
+
var autoDetachObserver = new AutoDetachObserver(observer);
|
2082
|
+
if (currentThreadScheduler.scheduleRequired()) {
|
2083
|
+
currentThreadScheduler.schedule(function () {
|
2084
|
+
try {
|
2085
|
+
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
2086
|
+
} catch (e) {
|
2087
|
+
if (!autoDetachObserver.fail(e)) {
|
2088
|
+
throw e;
|
2089
|
+
}
|
2090
|
+
}
|
2091
|
+
});
|
2092
|
+
} else {
|
2093
|
+
try {
|
2094
|
+
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
2095
|
+
} catch (e) {
|
2096
|
+
if (!autoDetachObserver.fail(e)) {
|
2097
|
+
throw e;
|
2098
|
+
}
|
2099
|
+
}
|
2100
|
+
}
|
2101
|
+
|
2102
|
+
return autoDetachObserver;
|
2103
|
+
}
|
2104
|
+
|
2105
|
+
__super__.call(this, s);
|
2106
|
+
}
|
2107
|
+
|
2108
|
+
return AnonymousObservable;
|
2109
|
+
|
2110
|
+
}(Observable));
|
2111
|
+
|
2112
|
+
/** @private */
|
2113
|
+
var AutoDetachObserver = (function (_super) {
|
2114
|
+
inherits(AutoDetachObserver, _super);
|
2115
|
+
|
2116
|
+
function AutoDetachObserver(observer) {
|
2117
|
+
_super.call(this);
|
2118
|
+
this.observer = observer;
|
2119
|
+
this.m = new SingleAssignmentDisposable();
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
|
2123
|
+
|
2124
|
+
AutoDetachObserverPrototype.next = function (value) {
|
2125
|
+
var noError = false;
|
2126
|
+
try {
|
2127
|
+
this.observer.onNext(value);
|
2128
|
+
noError = true;
|
2129
|
+
} catch (e) {
|
2130
|
+
throw e;
|
2131
|
+
} finally {
|
2132
|
+
if (!noError) {
|
2133
|
+
this.dispose();
|
2134
|
+
}
|
2135
|
+
}
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
AutoDetachObserverPrototype.error = function (exn) {
|
2139
|
+
try {
|
2140
|
+
this.observer.onError(exn);
|
2141
|
+
} catch (e) {
|
2142
|
+
throw e;
|
2143
|
+
} finally {
|
2144
|
+
this.dispose();
|
2145
|
+
}
|
2146
|
+
};
|
2147
|
+
|
2148
|
+
AutoDetachObserverPrototype.completed = function () {
|
2149
|
+
try {
|
2150
|
+
this.observer.onCompleted();
|
2151
|
+
} catch (e) {
|
2152
|
+
throw e;
|
2153
|
+
} finally {
|
2154
|
+
this.dispose();
|
2155
|
+
}
|
2156
|
+
};
|
2157
|
+
|
2158
|
+
AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
|
2159
|
+
AutoDetachObserverPrototype.getDisposable = function (value) { return this.m.getDisposable(); };
|
2160
|
+
/* @private */
|
2161
|
+
AutoDetachObserverPrototype.disposable = function (value) {
|
2162
|
+
return arguments.length ? this.getDisposable() : setDisposable(value);
|
2163
|
+
};
|
2164
|
+
|
2165
|
+
AutoDetachObserverPrototype.dispose = function () {
|
2166
|
+
_super.prototype.dispose.call(this);
|
2167
|
+
this.m.dispose();
|
2168
|
+
};
|
2169
|
+
|
2170
|
+
return AutoDetachObserver;
|
2171
|
+
}(AbstractObserver));
|
2172
|
+
|
2173
|
+
/** @private */
|
2174
|
+
var GroupedObservable = (function (_super) {
|
2175
|
+
inherits(GroupedObservable, _super);
|
2176
|
+
|
2177
|
+
function subscribe(observer) {
|
2178
|
+
return this.underlyingObservable.subscribe(observer);
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
/**
|
2182
|
+
* @constructor
|
2183
|
+
* @private
|
2184
|
+
*/
|
2185
|
+
function GroupedObservable(key, underlyingObservable, mergedDisposable) {
|
2186
|
+
_super.call(this, subscribe);
|
2187
|
+
this.key = key;
|
2188
|
+
this.underlyingObservable = !mergedDisposable ?
|
2189
|
+
underlyingObservable :
|
2190
|
+
new AnonymousObservable(function (observer) {
|
2191
|
+
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
2192
|
+
});
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
return GroupedObservable;
|
2196
|
+
}(Observable));
|
2197
|
+
|
2198
|
+
/** @private */
|
2199
|
+
var InnerSubscription = function (subject, observer) {
|
2200
|
+
this.subject = subject;
|
2201
|
+
this.observer = observer;
|
2202
|
+
};
|
2203
|
+
|
2204
|
+
/**
|
2205
|
+
* @private
|
2206
|
+
* @memberOf InnerSubscription
|
2207
|
+
*/
|
2208
|
+
InnerSubscription.prototype.dispose = function () {
|
2209
|
+
if (!this.subject.isDisposed && this.observer !== null) {
|
2210
|
+
var idx = this.subject.observers.indexOf(this.observer);
|
2211
|
+
this.subject.observers.splice(idx, 1);
|
2212
|
+
this.observer = null;
|
2213
|
+
}
|
2214
|
+
};
|
2215
|
+
|
2216
|
+
/**
|
2217
|
+
* Represents an object that is both an observable sequence as well as an observer.
|
2218
|
+
* Each notification is broadcasted to all subscribed observers.
|
2219
|
+
*/
|
2220
|
+
var Subject = Rx.Subject = (function (_super) {
|
2221
|
+
function subscribe(observer) {
|
2222
|
+
checkDisposed.call(this);
|
2223
|
+
if (!this.isStopped) {
|
2224
|
+
this.observers.push(observer);
|
2225
|
+
return new InnerSubscription(this, observer);
|
2226
|
+
}
|
2227
|
+
if (this.exception) {
|
2228
|
+
observer.onError(this.exception);
|
2229
|
+
return disposableEmpty;
|
2230
|
+
}
|
2231
|
+
observer.onCompleted();
|
2232
|
+
return disposableEmpty;
|
2233
|
+
}
|
2234
|
+
|
2235
|
+
inherits(Subject, _super);
|
2236
|
+
|
2237
|
+
/**
|
2238
|
+
* Creates a subject.
|
2239
|
+
* @constructor
|
2240
|
+
*/
|
2241
|
+
function Subject() {
|
2242
|
+
_super.call(this, subscribe);
|
2243
|
+
this.isDisposed = false,
|
2244
|
+
this.isStopped = false,
|
2245
|
+
this.observers = [];
|
2246
|
+
}
|
2247
|
+
|
2248
|
+
addProperties(Subject.prototype, Observer, {
|
2249
|
+
/**
|
2250
|
+
* Indicates whether the subject has observers subscribed to it.
|
2251
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
2252
|
+
*/
|
2253
|
+
hasObservers: function () {
|
2254
|
+
return this.observers.length > 0;
|
2255
|
+
},
|
2256
|
+
/**
|
2257
|
+
* Notifies all subscribed observers about the end of the sequence.
|
2258
|
+
*/
|
2259
|
+
onCompleted: function () {
|
2260
|
+
checkDisposed.call(this);
|
2261
|
+
if (!this.isStopped) {
|
2262
|
+
var os = this.observers.slice(0);
|
2263
|
+
this.isStopped = true;
|
2264
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2265
|
+
os[i].onCompleted();
|
2266
|
+
}
|
2267
|
+
|
2268
|
+
this.observers = [];
|
2269
|
+
}
|
2270
|
+
},
|
2271
|
+
/**
|
2272
|
+
* Notifies all subscribed observers about the exception.
|
2273
|
+
* @param {Mixed} error The exception to send to all observers.
|
2274
|
+
*/
|
2275
|
+
onError: function (exception) {
|
2276
|
+
checkDisposed.call(this);
|
2277
|
+
if (!this.isStopped) {
|
2278
|
+
var os = this.observers.slice(0);
|
2279
|
+
this.isStopped = true;
|
2280
|
+
this.exception = exception;
|
2281
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2282
|
+
os[i].onError(exception);
|
2283
|
+
}
|
2284
|
+
|
2285
|
+
this.observers = [];
|
2286
|
+
}
|
2287
|
+
},
|
2288
|
+
/**
|
2289
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
2290
|
+
* @param {Mixed} value The value to send to all observers.
|
2291
|
+
*/
|
2292
|
+
onNext: function (value) {
|
2293
|
+
checkDisposed.call(this);
|
2294
|
+
if (!this.isStopped) {
|
2295
|
+
var os = this.observers.slice(0);
|
2296
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2297
|
+
os[i].onNext(value);
|
2298
|
+
}
|
2299
|
+
}
|
2300
|
+
},
|
2301
|
+
/**
|
2302
|
+
* Unsubscribe all observers and release resources.
|
2303
|
+
*/
|
2304
|
+
dispose: function () {
|
2305
|
+
this.isDisposed = true;
|
2306
|
+
this.observers = null;
|
2307
|
+
}
|
2308
|
+
});
|
2309
|
+
|
2310
|
+
/**
|
2311
|
+
* Creates a subject from the specified observer and observable.
|
2312
|
+
* @param {Observer} observer The observer used to send messages to the subject.
|
2313
|
+
* @param {Observable} observable The observable used to subscribe to messages sent from the subject.
|
2314
|
+
* @returns {Subject} Subject implemented using the given observer and observable.
|
2315
|
+
*/
|
2316
|
+
Subject.create = function (observer, observable) {
|
2317
|
+
return new AnonymousSubject(observer, observable);
|
2318
|
+
};
|
2319
|
+
|
2320
|
+
return Subject;
|
2321
|
+
}(Observable));
|
2322
|
+
|
2323
|
+
/**
|
2324
|
+
* Represents the result of an asynchronous operation.
|
2325
|
+
* The last value before the OnCompleted notification, or the error received through OnError, is sent to all subscribed observers.
|
2326
|
+
*/
|
2327
|
+
var AsyncSubject = Rx.AsyncSubject = (function (_super) {
|
2328
|
+
|
2329
|
+
function subscribe(observer) {
|
2330
|
+
checkDisposed.call(this);
|
2331
|
+
|
2332
|
+
if (!this.isStopped) {
|
2333
|
+
this.observers.push(observer);
|
2334
|
+
return new InnerSubscription(this, observer);
|
2335
|
+
}
|
2336
|
+
|
2337
|
+
var ex = this.exception,
|
2338
|
+
hv = this.hasValue,
|
2339
|
+
v = this.value;
|
2340
|
+
|
2341
|
+
if (ex) {
|
2342
|
+
observer.onError(ex);
|
2343
|
+
} else if (hv) {
|
2344
|
+
observer.onNext(v);
|
2345
|
+
observer.onCompleted();
|
2346
|
+
} else {
|
2347
|
+
observer.onCompleted();
|
2348
|
+
}
|
2349
|
+
|
2350
|
+
return disposableEmpty;
|
2351
|
+
}
|
2352
|
+
|
2353
|
+
inherits(AsyncSubject, _super);
|
2354
|
+
|
2355
|
+
/**
|
2356
|
+
* Creates a subject that can only receive one value and that value is cached for all future observations.
|
2357
|
+
* @constructor
|
2358
|
+
*/
|
2359
|
+
function AsyncSubject() {
|
2360
|
+
_super.call(this, subscribe);
|
2361
|
+
|
2362
|
+
this.isDisposed = false;
|
2363
|
+
this.isStopped = false;
|
2364
|
+
this.value = null;
|
2365
|
+
this.hasValue = false;
|
2366
|
+
this.observers = [];
|
2367
|
+
this.exception = null;
|
2368
|
+
}
|
2369
|
+
|
2370
|
+
addProperties(AsyncSubject.prototype, Observer, {
|
2371
|
+
/**
|
2372
|
+
* Indicates whether the subject has observers subscribed to it.
|
2373
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
2374
|
+
*/
|
2375
|
+
hasObservers: function () {
|
2376
|
+
checkDisposed.call(this);
|
2377
|
+
return this.observers.length > 0;
|
2378
|
+
},
|
2379
|
+
/**
|
2380
|
+
* Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
|
2381
|
+
*/
|
2382
|
+
onCompleted: function () {
|
2383
|
+
var o, i, len;
|
2384
|
+
checkDisposed.call(this);
|
2385
|
+
if (!this.isStopped) {
|
2386
|
+
this.isStopped = true;
|
2387
|
+
var os = this.observers.slice(0),
|
2388
|
+
v = this.value,
|
2389
|
+
hv = this.hasValue;
|
2390
|
+
|
2391
|
+
if (hv) {
|
2392
|
+
for (i = 0, len = os.length; i < len; i++) {
|
2393
|
+
o = os[i];
|
2394
|
+
o.onNext(v);
|
2395
|
+
o.onCompleted();
|
2396
|
+
}
|
2397
|
+
} else {
|
2398
|
+
for (i = 0, len = os.length; i < len; i++) {
|
2399
|
+
os[i].onCompleted();
|
2400
|
+
}
|
2401
|
+
}
|
2402
|
+
|
2403
|
+
this.observers = [];
|
2404
|
+
}
|
2405
|
+
},
|
2406
|
+
/**
|
2407
|
+
* Notifies all subscribed observers about the exception.
|
2408
|
+
* @param {Mixed} error The exception to send to all observers.
|
2409
|
+
*/
|
2410
|
+
onError: function (exception) {
|
2411
|
+
checkDisposed.call(this);
|
2412
|
+
if (!this.isStopped) {
|
2413
|
+
var os = this.observers.slice(0);
|
2414
|
+
this.isStopped = true;
|
2415
|
+
this.exception = exception;
|
2416
|
+
|
2417
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2418
|
+
os[i].onError(exception);
|
2419
|
+
}
|
2420
|
+
|
2421
|
+
this.observers = [];
|
2422
|
+
}
|
2423
|
+
},
|
2424
|
+
/**
|
2425
|
+
* Sends a value to the subject. The last value received before successful termination will be sent to all subscribed and future observers.
|
2426
|
+
* @param {Mixed} value The value to store in the subject.
|
2427
|
+
*/
|
2428
|
+
onNext: function (value) {
|
2429
|
+
checkDisposed.call(this);
|
2430
|
+
if (!this.isStopped) {
|
2431
|
+
this.value = value;
|
2432
|
+
this.hasValue = true;
|
2433
|
+
}
|
2434
|
+
},
|
2435
|
+
/**
|
2436
|
+
* Unsubscribe all observers and release resources.
|
2437
|
+
*/
|
2438
|
+
dispose: function () {
|
2439
|
+
this.isDisposed = true;
|
2440
|
+
this.observers = null;
|
2441
|
+
this.exception = null;
|
2442
|
+
this.value = null;
|
2443
|
+
}
|
2444
|
+
});
|
2445
|
+
|
2446
|
+
return AsyncSubject;
|
2447
|
+
}(Observable));
|
2448
|
+
|
2449
|
+
/** @private */
|
2450
|
+
var AnonymousSubject = (function (_super) {
|
2451
|
+
inherits(AnonymousSubject, _super);
|
2452
|
+
|
2453
|
+
function subscribe(observer) {
|
2454
|
+
return this.observable.subscribe(observer);
|
2455
|
+
}
|
2456
|
+
|
2457
|
+
/**
|
2458
|
+
* @private
|
2459
|
+
* @constructor
|
2460
|
+
*/
|
2461
|
+
function AnonymousSubject(observer, observable) {
|
2462
|
+
_super.call(this, subscribe);
|
2463
|
+
this.observer = observer;
|
2464
|
+
this.observable = observable;
|
2465
|
+
}
|
2466
|
+
|
2467
|
+
addProperties(AnonymousSubject.prototype, Observer, {
|
2468
|
+
/**
|
2469
|
+
* @private
|
2470
|
+
* @memberOf AnonymousSubject#
|
2471
|
+
*/
|
2472
|
+
onCompleted: function () {
|
2473
|
+
this.observer.onCompleted();
|
2474
|
+
},
|
2475
|
+
/**
|
2476
|
+
* @private
|
2477
|
+
* @memberOf AnonymousSubject#
|
2478
|
+
*/
|
2479
|
+
onError: function (exception) {
|
2480
|
+
this.observer.onError(exception);
|
2481
|
+
},
|
2482
|
+
/**
|
2483
|
+
* @private
|
2484
|
+
* @memberOf AnonymousSubject#
|
2485
|
+
*/
|
2486
|
+
onNext: function (value) {
|
2487
|
+
this.observer.onNext(value);
|
2488
|
+
}
|
2489
|
+
});
|
2490
|
+
|
2491
|
+
return AnonymousSubject;
|
2492
|
+
}(Observable));
|
2493
|
+
|
2494
|
+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
2495
|
+
root.Rx = Rx;
|
2496
|
+
|
2497
|
+
define(function() {
|
2498
|
+
return Rx;
|
2499
|
+
});
|
2500
|
+
} else if (freeExports && freeModule) {
|
2501
|
+
// in Node.js or RingoJS
|
2502
|
+
if (moduleExports) {
|
2503
|
+
(freeModule.exports = Rx).Rx = Rx;
|
2504
|
+
} else {
|
2505
|
+
freeExports.Rx = Rx;
|
2506
|
+
}
|
2507
|
+
} else {
|
2508
|
+
// in a browser or Rhino
|
2509
|
+
root.Rx = Rx;
|
2510
|
+
}
|
2511
|
+
}.call(this));
|