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,2629 @@
|
|
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 = (function () { return !!Date.now ? Date.now : function () { return +new Date; }; }()),
|
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
|
+
// Utilities
|
396
|
+
if (!Function.prototype.bind) {
|
397
|
+
Function.prototype.bind = function (that) {
|
398
|
+
var target = this,
|
399
|
+
args = slice.call(arguments, 1);
|
400
|
+
var bound = function () {
|
401
|
+
if (this instanceof bound) {
|
402
|
+
function F() { }
|
403
|
+
F.prototype = target.prototype;
|
404
|
+
var self = new F();
|
405
|
+
var result = target.apply(self, args.concat(slice.call(arguments)));
|
406
|
+
if (Object(result) === result) {
|
407
|
+
return result;
|
408
|
+
}
|
409
|
+
return self;
|
410
|
+
} else {
|
411
|
+
return target.apply(that, args.concat(slice.call(arguments)));
|
412
|
+
}
|
413
|
+
};
|
414
|
+
|
415
|
+
return bound;
|
416
|
+
};
|
417
|
+
}
|
418
|
+
|
419
|
+
var boxedString = Object("a"),
|
420
|
+
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
421
|
+
if (!Array.prototype.every) {
|
422
|
+
Array.prototype.every = function every(fun /*, thisp */) {
|
423
|
+
var object = Object(this),
|
424
|
+
self = splitString && {}.toString.call(this) == stringClass ?
|
425
|
+
this.split("") :
|
426
|
+
object,
|
427
|
+
length = self.length >>> 0,
|
428
|
+
thisp = arguments[1];
|
429
|
+
|
430
|
+
if ({}.toString.call(fun) != funcClass) {
|
431
|
+
throw new TypeError(fun + " is not a function");
|
432
|
+
}
|
433
|
+
|
434
|
+
for (var i = 0; i < length; i++) {
|
435
|
+
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
436
|
+
return false;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
return true;
|
440
|
+
};
|
441
|
+
}
|
442
|
+
|
443
|
+
if (!Array.prototype.map) {
|
444
|
+
Array.prototype.map = function map(fun /*, thisp*/) {
|
445
|
+
var object = Object(this),
|
446
|
+
self = splitString && {}.toString.call(this) == stringClass ?
|
447
|
+
this.split("") :
|
448
|
+
object,
|
449
|
+
length = self.length >>> 0,
|
450
|
+
result = Array(length),
|
451
|
+
thisp = arguments[1];
|
452
|
+
|
453
|
+
if ({}.toString.call(fun) != funcClass) {
|
454
|
+
throw new TypeError(fun + " is not a function");
|
455
|
+
}
|
456
|
+
|
457
|
+
for (var i = 0; i < length; i++) {
|
458
|
+
if (i in self)
|
459
|
+
result[i] = fun.call(thisp, self[i], i, object);
|
460
|
+
}
|
461
|
+
return result;
|
462
|
+
};
|
463
|
+
}
|
464
|
+
|
465
|
+
if (!Array.prototype.filter) {
|
466
|
+
Array.prototype.filter = function (predicate) {
|
467
|
+
var results = [], item, t = new Object(this);
|
468
|
+
for (var i = 0, len = t.length >>> 0; i < len; i++) {
|
469
|
+
item = t[i];
|
470
|
+
if (i in t && predicate.call(arguments[1], item, i, t)) {
|
471
|
+
results.push(item);
|
472
|
+
}
|
473
|
+
}
|
474
|
+
return results;
|
475
|
+
};
|
476
|
+
}
|
477
|
+
|
478
|
+
if (!Array.isArray) {
|
479
|
+
Array.isArray = function (arg) {
|
480
|
+
return Object.prototype.toString.call(arg) == arrayClass;
|
481
|
+
};
|
482
|
+
}
|
483
|
+
|
484
|
+
if (!Array.prototype.indexOf) {
|
485
|
+
Array.prototype.indexOf = function indexOf(searchElement) {
|
486
|
+
var t = Object(this);
|
487
|
+
var len = t.length >>> 0;
|
488
|
+
if (len === 0) {
|
489
|
+
return -1;
|
490
|
+
}
|
491
|
+
var n = 0;
|
492
|
+
if (arguments.length > 1) {
|
493
|
+
n = Number(arguments[1]);
|
494
|
+
if (n !== n) {
|
495
|
+
n = 0;
|
496
|
+
} else if (n !== 0 && n != Infinity && n !== -Infinity) {
|
497
|
+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
498
|
+
}
|
499
|
+
}
|
500
|
+
if (n >= len) {
|
501
|
+
return -1;
|
502
|
+
}
|
503
|
+
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
504
|
+
for (; k < len; k++) {
|
505
|
+
if (k in t && t[k] === searchElement) {
|
506
|
+
return k;
|
507
|
+
}
|
508
|
+
}
|
509
|
+
return -1;
|
510
|
+
};
|
511
|
+
}
|
512
|
+
|
513
|
+
// Collections
|
514
|
+
var IndexedItem = function (id, value) {
|
515
|
+
this.id = id;
|
516
|
+
this.value = value;
|
517
|
+
};
|
518
|
+
|
519
|
+
IndexedItem.prototype.compareTo = function (other) {
|
520
|
+
var c = this.value.compareTo(other.value);
|
521
|
+
if (c === 0) {
|
522
|
+
c = this.id - other.id;
|
523
|
+
}
|
524
|
+
return c;
|
525
|
+
};
|
526
|
+
|
527
|
+
// Priority Queue for Scheduling
|
528
|
+
var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
529
|
+
this.items = new Array(capacity);
|
530
|
+
this.length = 0;
|
531
|
+
};
|
532
|
+
|
533
|
+
var priorityProto = PriorityQueue.prototype;
|
534
|
+
priorityProto.isHigherPriority = function (left, right) {
|
535
|
+
return this.items[left].compareTo(this.items[right]) < 0;
|
536
|
+
};
|
537
|
+
|
538
|
+
priorityProto.percolate = function (index) {
|
539
|
+
if (index >= this.length || index < 0) {
|
540
|
+
return;
|
541
|
+
}
|
542
|
+
var parent = index - 1 >> 1;
|
543
|
+
if (parent < 0 || parent === index) {
|
544
|
+
return;
|
545
|
+
}
|
546
|
+
if (this.isHigherPriority(index, parent)) {
|
547
|
+
var temp = this.items[index];
|
548
|
+
this.items[index] = this.items[parent];
|
549
|
+
this.items[parent] = temp;
|
550
|
+
this.percolate(parent);
|
551
|
+
}
|
552
|
+
};
|
553
|
+
|
554
|
+
priorityProto.heapify = function (index) {
|
555
|
+
if (index === undefined) {
|
556
|
+
index = 0;
|
557
|
+
}
|
558
|
+
if (index >= this.length || index < 0) {
|
559
|
+
return;
|
560
|
+
}
|
561
|
+
var left = 2 * index + 1,
|
562
|
+
right = 2 * index + 2,
|
563
|
+
first = index;
|
564
|
+
if (left < this.length && this.isHigherPriority(left, first)) {
|
565
|
+
first = left;
|
566
|
+
}
|
567
|
+
if (right < this.length && this.isHigherPriority(right, first)) {
|
568
|
+
first = right;
|
569
|
+
}
|
570
|
+
if (first !== index) {
|
571
|
+
var temp = this.items[index];
|
572
|
+
this.items[index] = this.items[first];
|
573
|
+
this.items[first] = temp;
|
574
|
+
this.heapify(first);
|
575
|
+
}
|
576
|
+
};
|
577
|
+
|
578
|
+
priorityProto.peek = function () { return this.items[0].value; };
|
579
|
+
|
580
|
+
priorityProto.removeAt = function (index) {
|
581
|
+
this.items[index] = this.items[--this.length];
|
582
|
+
delete this.items[this.length];
|
583
|
+
this.heapify();
|
584
|
+
};
|
585
|
+
|
586
|
+
priorityProto.dequeue = function () {
|
587
|
+
var result = this.peek();
|
588
|
+
this.removeAt(0);
|
589
|
+
return result;
|
590
|
+
};
|
591
|
+
|
592
|
+
priorityProto.enqueue = function (item) {
|
593
|
+
var index = this.length++;
|
594
|
+
this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
595
|
+
this.percolate(index);
|
596
|
+
};
|
597
|
+
|
598
|
+
priorityProto.remove = function (item) {
|
599
|
+
for (var i = 0; i < this.length; i++) {
|
600
|
+
if (this.items[i].value === item) {
|
601
|
+
this.removeAt(i);
|
602
|
+
return true;
|
603
|
+
}
|
604
|
+
}
|
605
|
+
return false;
|
606
|
+
};
|
607
|
+
PriorityQueue.count = 0;
|
608
|
+
/**
|
609
|
+
* Represents a group of disposable resources that are disposed together.
|
610
|
+
* @constructor
|
611
|
+
*/
|
612
|
+
var CompositeDisposable = Rx.CompositeDisposable = function () {
|
613
|
+
this.disposables = argsOrArray(arguments, 0);
|
614
|
+
this.isDisposed = false;
|
615
|
+
this.length = this.disposables.length;
|
616
|
+
};
|
617
|
+
|
618
|
+
var CompositeDisposablePrototype = CompositeDisposable.prototype;
|
619
|
+
|
620
|
+
/**
|
621
|
+
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
622
|
+
* @param {Mixed} item Disposable to add.
|
623
|
+
*/
|
624
|
+
CompositeDisposablePrototype.add = function (item) {
|
625
|
+
if (this.isDisposed) {
|
626
|
+
item.dispose();
|
627
|
+
} else {
|
628
|
+
this.disposables.push(item);
|
629
|
+
this.length++;
|
630
|
+
}
|
631
|
+
};
|
632
|
+
|
633
|
+
/**
|
634
|
+
* Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
|
635
|
+
* @param {Mixed} item Disposable to remove.
|
636
|
+
* @returns {Boolean} true if found; false otherwise.
|
637
|
+
*/
|
638
|
+
CompositeDisposablePrototype.remove = function (item) {
|
639
|
+
var shouldDispose = false;
|
640
|
+
if (!this.isDisposed) {
|
641
|
+
var idx = this.disposables.indexOf(item);
|
642
|
+
if (idx !== -1) {
|
643
|
+
shouldDispose = true;
|
644
|
+
this.disposables.splice(idx, 1);
|
645
|
+
this.length--;
|
646
|
+
item.dispose();
|
647
|
+
}
|
648
|
+
|
649
|
+
}
|
650
|
+
return shouldDispose;
|
651
|
+
};
|
652
|
+
|
653
|
+
/**
|
654
|
+
* Disposes all disposables in the group and removes them from the group.
|
655
|
+
*/
|
656
|
+
CompositeDisposablePrototype.dispose = function () {
|
657
|
+
if (!this.isDisposed) {
|
658
|
+
this.isDisposed = true;
|
659
|
+
var currentDisposables = this.disposables.slice(0);
|
660
|
+
this.disposables = [];
|
661
|
+
this.length = 0;
|
662
|
+
|
663
|
+
for (var i = 0, len = currentDisposables.length; i < len; i++) {
|
664
|
+
currentDisposables[i].dispose();
|
665
|
+
}
|
666
|
+
}
|
667
|
+
};
|
668
|
+
|
669
|
+
/**
|
670
|
+
* Removes and disposes all disposables from the CompositeDisposable, but does not dispose the CompositeDisposable.
|
671
|
+
*/
|
672
|
+
CompositeDisposablePrototype.clear = function () {
|
673
|
+
var currentDisposables = this.disposables.slice(0);
|
674
|
+
this.disposables = [];
|
675
|
+
this.length = 0;
|
676
|
+
for (var i = 0, len = currentDisposables.length; i < len; i++) {
|
677
|
+
currentDisposables[i].dispose();
|
678
|
+
}
|
679
|
+
};
|
680
|
+
|
681
|
+
/**
|
682
|
+
* Determines whether the CompositeDisposable contains a specific disposable.
|
683
|
+
* @param {Mixed} item Disposable to search for.
|
684
|
+
* @returns {Boolean} true if the disposable was found; otherwise, false.
|
685
|
+
*/
|
686
|
+
CompositeDisposablePrototype.contains = function (item) {
|
687
|
+
return this.disposables.indexOf(item) !== -1;
|
688
|
+
};
|
689
|
+
|
690
|
+
/**
|
691
|
+
* Converts the existing CompositeDisposable to an array of disposables
|
692
|
+
* @returns {Array} An array of disposable objects.
|
693
|
+
*/
|
694
|
+
CompositeDisposablePrototype.toArray = function () {
|
695
|
+
return this.disposables.slice(0);
|
696
|
+
};
|
697
|
+
|
698
|
+
/**
|
699
|
+
* Provides a set of static methods for creating Disposables.
|
700
|
+
*
|
701
|
+
* @constructor
|
702
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
703
|
+
*/
|
704
|
+
var Disposable = Rx.Disposable = function (action) {
|
705
|
+
this.isDisposed = false;
|
706
|
+
this.action = action || noop;
|
707
|
+
};
|
708
|
+
|
709
|
+
/** Performs the task of cleaning up resources. */
|
710
|
+
Disposable.prototype.dispose = function () {
|
711
|
+
if (!this.isDisposed) {
|
712
|
+
this.action();
|
713
|
+
this.isDisposed = true;
|
714
|
+
}
|
715
|
+
};
|
716
|
+
|
717
|
+
/**
|
718
|
+
* Creates a disposable object that invokes the specified action when disposed.
|
719
|
+
* @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once.
|
720
|
+
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
721
|
+
*/
|
722
|
+
var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
|
723
|
+
|
724
|
+
/**
|
725
|
+
* Gets the disposable that does nothing when disposed.
|
726
|
+
*/
|
727
|
+
var disposableEmpty = Disposable.empty = { dispose: noop };
|
728
|
+
|
729
|
+
var BooleanDisposable = (function () {
|
730
|
+
function BooleanDisposable (isSingle) {
|
731
|
+
this.isSingle = isSingle;
|
732
|
+
this.isDisposed = false;
|
733
|
+
this.current = null;
|
734
|
+
}
|
735
|
+
|
736
|
+
var booleanDisposablePrototype = BooleanDisposable.prototype;
|
737
|
+
|
738
|
+
/**
|
739
|
+
* Gets the underlying disposable.
|
740
|
+
* @return The underlying disposable.
|
741
|
+
*/
|
742
|
+
booleanDisposablePrototype.getDisposable = function () {
|
743
|
+
return this.current;
|
744
|
+
};
|
745
|
+
|
746
|
+
/**
|
747
|
+
* Sets the underlying disposable.
|
748
|
+
* @param {Disposable} value The new underlying disposable.
|
749
|
+
*/
|
750
|
+
booleanDisposablePrototype.setDisposable = function (value) {
|
751
|
+
if (this.current && this.isSingle) {
|
752
|
+
throw new Error('Disposable has already been assigned');
|
753
|
+
}
|
754
|
+
|
755
|
+
var shouldDispose = this.isDisposed, old;
|
756
|
+
if (!shouldDispose) {
|
757
|
+
old = this.current;
|
758
|
+
this.current = value;
|
759
|
+
}
|
760
|
+
if (old) {
|
761
|
+
old.dispose();
|
762
|
+
}
|
763
|
+
if (shouldDispose && value) {
|
764
|
+
value.dispose();
|
765
|
+
}
|
766
|
+
};
|
767
|
+
|
768
|
+
/**
|
769
|
+
* Disposes the underlying disposable as well as all future replacements.
|
770
|
+
*/
|
771
|
+
booleanDisposablePrototype.dispose = function () {
|
772
|
+
var old;
|
773
|
+
if (!this.isDisposed) {
|
774
|
+
this.isDisposed = true;
|
775
|
+
old = this.current;
|
776
|
+
this.current = null;
|
777
|
+
}
|
778
|
+
if (old) {
|
779
|
+
old.dispose();
|
780
|
+
}
|
781
|
+
};
|
782
|
+
|
783
|
+
return BooleanDisposable;
|
784
|
+
}());
|
785
|
+
|
786
|
+
/**
|
787
|
+
* Represents a disposable resource which only allows a single assignment of its underlying disposable resource.
|
788
|
+
* If an underlying disposable resource has already been set, future attempts to set the underlying disposable resource will throw an Error.
|
789
|
+
*/
|
790
|
+
var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = (function (super_) {
|
791
|
+
inherits(SingleAssignmentDisposable, super_);
|
792
|
+
|
793
|
+
function SingleAssignmentDisposable() {
|
794
|
+
super_.call(this, true);
|
795
|
+
}
|
796
|
+
|
797
|
+
return SingleAssignmentDisposable;
|
798
|
+
}(BooleanDisposable));
|
799
|
+
|
800
|
+
/**
|
801
|
+
* Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
|
802
|
+
*/
|
803
|
+
var SerialDisposable = Rx.SerialDisposable = (function (super_) {
|
804
|
+
inherits(SerialDisposable, super_);
|
805
|
+
|
806
|
+
function SerialDisposable() {
|
807
|
+
super_.call(this, false);
|
808
|
+
}
|
809
|
+
|
810
|
+
return SerialDisposable;
|
811
|
+
}(BooleanDisposable));
|
812
|
+
|
813
|
+
/**
|
814
|
+
* Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed.
|
815
|
+
*/
|
816
|
+
var RefCountDisposable = Rx.RefCountDisposable = (function () {
|
817
|
+
|
818
|
+
function InnerDisposable(disposable) {
|
819
|
+
this.disposable = disposable;
|
820
|
+
this.disposable.count++;
|
821
|
+
this.isInnerDisposed = false;
|
822
|
+
}
|
823
|
+
|
824
|
+
InnerDisposable.prototype.dispose = function () {
|
825
|
+
if (!this.disposable.isDisposed) {
|
826
|
+
if (!this.isInnerDisposed) {
|
827
|
+
this.isInnerDisposed = true;
|
828
|
+
this.disposable.count--;
|
829
|
+
if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
|
830
|
+
this.disposable.isDisposed = true;
|
831
|
+
this.disposable.underlyingDisposable.dispose();
|
832
|
+
}
|
833
|
+
}
|
834
|
+
}
|
835
|
+
};
|
836
|
+
|
837
|
+
/**
|
838
|
+
* Initializes a new instance of the RefCountDisposable with the specified disposable.
|
839
|
+
* @constructor
|
840
|
+
* @param {Disposable} disposable Underlying disposable.
|
841
|
+
*/
|
842
|
+
function RefCountDisposable(disposable) {
|
843
|
+
this.underlyingDisposable = disposable;
|
844
|
+
this.isDisposed = false;
|
845
|
+
this.isPrimaryDisposed = false;
|
846
|
+
this.count = 0;
|
847
|
+
}
|
848
|
+
|
849
|
+
/**
|
850
|
+
* Disposes the underlying disposable only when all dependent disposables have been disposed
|
851
|
+
*/
|
852
|
+
RefCountDisposable.prototype.dispose = function () {
|
853
|
+
if (!this.isDisposed) {
|
854
|
+
if (!this.isPrimaryDisposed) {
|
855
|
+
this.isPrimaryDisposed = true;
|
856
|
+
if (this.count === 0) {
|
857
|
+
this.isDisposed = true;
|
858
|
+
this.underlyingDisposable.dispose();
|
859
|
+
}
|
860
|
+
}
|
861
|
+
}
|
862
|
+
};
|
863
|
+
|
864
|
+
/**
|
865
|
+
* Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
|
866
|
+
* @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
|
867
|
+
*/
|
868
|
+
RefCountDisposable.prototype.getDisposable = function () {
|
869
|
+
return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
|
870
|
+
};
|
871
|
+
|
872
|
+
return RefCountDisposable;
|
873
|
+
})();
|
874
|
+
|
875
|
+
function ScheduledDisposable(scheduler, disposable) {
|
876
|
+
this.scheduler = scheduler;
|
877
|
+
this.disposable = disposable;
|
878
|
+
this.isDisposed = false;
|
879
|
+
}
|
880
|
+
|
881
|
+
ScheduledDisposable.prototype.dispose = function () {
|
882
|
+
var parent = this;
|
883
|
+
this.scheduler.schedule(function () {
|
884
|
+
if (!parent.isDisposed) {
|
885
|
+
parent.isDisposed = true;
|
886
|
+
parent.disposable.dispose();
|
887
|
+
}
|
888
|
+
});
|
889
|
+
};
|
890
|
+
|
891
|
+
var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
|
892
|
+
this.scheduler = scheduler;
|
893
|
+
this.state = state;
|
894
|
+
this.action = action;
|
895
|
+
this.dueTime = dueTime;
|
896
|
+
this.comparer = comparer || defaultSubComparer;
|
897
|
+
this.disposable = new SingleAssignmentDisposable();
|
898
|
+
}
|
899
|
+
|
900
|
+
ScheduledItem.prototype.invoke = function () {
|
901
|
+
this.disposable.setDisposable(this.invokeCore());
|
902
|
+
};
|
903
|
+
|
904
|
+
ScheduledItem.prototype.compareTo = function (other) {
|
905
|
+
return this.comparer(this.dueTime, other.dueTime);
|
906
|
+
};
|
907
|
+
|
908
|
+
ScheduledItem.prototype.isCancelled = function () {
|
909
|
+
return this.disposable.isDisposed;
|
910
|
+
};
|
911
|
+
|
912
|
+
ScheduledItem.prototype.invokeCore = function () {
|
913
|
+
return this.action(this.scheduler, this.state);
|
914
|
+
};
|
915
|
+
|
916
|
+
/** Provides a set of static properties to access commonly used schedulers. */
|
917
|
+
var Scheduler = Rx.Scheduler = (function () {
|
918
|
+
|
919
|
+
/**
|
920
|
+
* @constructor
|
921
|
+
* @private
|
922
|
+
*/
|
923
|
+
function Scheduler(now, schedule, scheduleRelative, scheduleAbsolute) {
|
924
|
+
this.now = now;
|
925
|
+
this._schedule = schedule;
|
926
|
+
this._scheduleRelative = scheduleRelative;
|
927
|
+
this._scheduleAbsolute = scheduleAbsolute;
|
928
|
+
}
|
929
|
+
|
930
|
+
function invokeRecImmediate(scheduler, pair) {
|
931
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
932
|
+
recursiveAction = function (state1) {
|
933
|
+
action(state1, function (state2) {
|
934
|
+
var isAdded = false, isDone = false,
|
935
|
+
d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
|
936
|
+
if (isAdded) {
|
937
|
+
group.remove(d);
|
938
|
+
} else {
|
939
|
+
isDone = true;
|
940
|
+
}
|
941
|
+
recursiveAction(state3);
|
942
|
+
return disposableEmpty;
|
943
|
+
});
|
944
|
+
if (!isDone) {
|
945
|
+
group.add(d);
|
946
|
+
isAdded = true;
|
947
|
+
}
|
948
|
+
});
|
949
|
+
};
|
950
|
+
recursiveAction(state);
|
951
|
+
return group;
|
952
|
+
}
|
953
|
+
|
954
|
+
function invokeRecDate(scheduler, pair, method) {
|
955
|
+
var state = pair.first, action = pair.second, group = new CompositeDisposable(),
|
956
|
+
recursiveAction = function (state1) {
|
957
|
+
action(state1, function (state2, dueTime1) {
|
958
|
+
var isAdded = false, isDone = false,
|
959
|
+
d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
|
960
|
+
if (isAdded) {
|
961
|
+
group.remove(d);
|
962
|
+
} else {
|
963
|
+
isDone = true;
|
964
|
+
}
|
965
|
+
recursiveAction(state3);
|
966
|
+
return disposableEmpty;
|
967
|
+
});
|
968
|
+
if (!isDone) {
|
969
|
+
group.add(d);
|
970
|
+
isAdded = true;
|
971
|
+
}
|
972
|
+
});
|
973
|
+
};
|
974
|
+
recursiveAction(state);
|
975
|
+
return group;
|
976
|
+
}
|
977
|
+
|
978
|
+
function invokeAction(scheduler, action) {
|
979
|
+
action();
|
980
|
+
return disposableEmpty;
|
981
|
+
}
|
982
|
+
|
983
|
+
var schedulerProto = Scheduler.prototype;
|
984
|
+
|
985
|
+
/**
|
986
|
+
* Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions.
|
987
|
+
* @param {Function} handler Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.
|
988
|
+
* @returns {Scheduler} Wrapper around the original scheduler, enforcing exception handling.
|
989
|
+
*/
|
990
|
+
schedulerProto.catchException = schedulerProto['catch'] = function (handler) {
|
991
|
+
return new CatchScheduler(this, handler);
|
992
|
+
};
|
993
|
+
|
994
|
+
/**
|
995
|
+
* 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.
|
996
|
+
* @param {Number} period Period for running the work periodically.
|
997
|
+
* @param {Function} action Action to be executed.
|
998
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
999
|
+
*/
|
1000
|
+
schedulerProto.schedulePeriodic = function (period, action) {
|
1001
|
+
return this.schedulePeriodicWithState(null, period, function () {
|
1002
|
+
action();
|
1003
|
+
});
|
1004
|
+
};
|
1005
|
+
|
1006
|
+
/**
|
1007
|
+
* Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation.
|
1008
|
+
* @param {Mixed} state Initial state passed to the action upon the first iteration.
|
1009
|
+
* @param {Number} period Period for running the work periodically.
|
1010
|
+
* @param {Function} action Action to be executed, potentially updating the state.
|
1011
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort).
|
1012
|
+
*/
|
1013
|
+
schedulerProto.schedulePeriodicWithState = function (state, period, action) {
|
1014
|
+
var s = state, id = setInterval(function () {
|
1015
|
+
s = action(s);
|
1016
|
+
}, period);
|
1017
|
+
return disposableCreate(function () {
|
1018
|
+
clearInterval(id);
|
1019
|
+
});
|
1020
|
+
};
|
1021
|
+
|
1022
|
+
/**
|
1023
|
+
* Schedules an action to be executed.
|
1024
|
+
* @param {Function} action Action to execute.
|
1025
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1026
|
+
*/
|
1027
|
+
schedulerProto.schedule = function (action) {
|
1028
|
+
return this._schedule(action, invokeAction);
|
1029
|
+
};
|
1030
|
+
|
1031
|
+
/**
|
1032
|
+
* Schedules an action to be executed.
|
1033
|
+
* @param state State passed to the action to be executed.
|
1034
|
+
* @param {Function} action Action to be executed.
|
1035
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1036
|
+
*/
|
1037
|
+
schedulerProto.scheduleWithState = function (state, action) {
|
1038
|
+
return this._schedule(state, action);
|
1039
|
+
};
|
1040
|
+
|
1041
|
+
/**
|
1042
|
+
* Schedules an action to be executed after the specified relative due time.
|
1043
|
+
* @param {Function} action Action to execute.
|
1044
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
1045
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1046
|
+
*/
|
1047
|
+
schedulerProto.scheduleWithRelative = function (dueTime, action) {
|
1048
|
+
return this._scheduleRelative(action, dueTime, invokeAction);
|
1049
|
+
};
|
1050
|
+
|
1051
|
+
/**
|
1052
|
+
* Schedules an action to be executed after dueTime.
|
1053
|
+
* @param state State passed to the action to be executed.
|
1054
|
+
* @param {Function} action Action to be executed.
|
1055
|
+
* @param {Number} dueTime Relative time after which to execute the action.
|
1056
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1057
|
+
*/
|
1058
|
+
schedulerProto.scheduleWithRelativeAndState = function (state, dueTime, action) {
|
1059
|
+
return this._scheduleRelative(state, dueTime, action);
|
1060
|
+
};
|
1061
|
+
|
1062
|
+
/**
|
1063
|
+
* Schedules an action to be executed at the specified absolute due time.
|
1064
|
+
* @param {Function} action Action to execute.
|
1065
|
+
* @param {Number} dueTime Absolute time at which to execute the action.
|
1066
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1067
|
+
*/
|
1068
|
+
schedulerProto.scheduleWithAbsolute = function (dueTime, action) {
|
1069
|
+
return this._scheduleAbsolute(action, dueTime, invokeAction);
|
1070
|
+
};
|
1071
|
+
|
1072
|
+
/**
|
1073
|
+
* Schedules an action to be executed at dueTime.
|
1074
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1075
|
+
* @param {Function} action Action to be executed.
|
1076
|
+
* @param {Number}dueTime Absolute time at which to execute the action.
|
1077
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1078
|
+
*/
|
1079
|
+
schedulerProto.scheduleWithAbsoluteAndState = function (state, dueTime, action) {
|
1080
|
+
return this._scheduleAbsolute(state, dueTime, action);
|
1081
|
+
};
|
1082
|
+
|
1083
|
+
/**
|
1084
|
+
* Schedules an action to be executed recursively.
|
1085
|
+
* @param {Function} action Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.
|
1086
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1087
|
+
*/
|
1088
|
+
schedulerProto.scheduleRecursive = function (action) {
|
1089
|
+
return this.scheduleRecursiveWithState(action, function (_action, self) {
|
1090
|
+
_action(function () {
|
1091
|
+
self(_action);
|
1092
|
+
});
|
1093
|
+
});
|
1094
|
+
};
|
1095
|
+
|
1096
|
+
/**
|
1097
|
+
* Schedules an action to be executed recursively.
|
1098
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1099
|
+
* @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.
|
1100
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1101
|
+
*/
|
1102
|
+
schedulerProto.scheduleRecursiveWithState = function (state, action) {
|
1103
|
+
return this.scheduleWithState({ first: state, second: action }, function (s, p) {
|
1104
|
+
return invokeRecImmediate(s, p);
|
1105
|
+
});
|
1106
|
+
};
|
1107
|
+
|
1108
|
+
/**
|
1109
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
1110
|
+
* @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.
|
1111
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1112
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1113
|
+
*/
|
1114
|
+
schedulerProto.scheduleRecursiveWithRelative = function (dueTime, action) {
|
1115
|
+
return this.scheduleRecursiveWithRelativeAndState(action, dueTime, function (_action, self) {
|
1116
|
+
_action(function (dt) {
|
1117
|
+
self(_action, dt);
|
1118
|
+
});
|
1119
|
+
});
|
1120
|
+
};
|
1121
|
+
|
1122
|
+
/**
|
1123
|
+
* Schedules an action to be executed recursively after a specified relative due time.
|
1124
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1125
|
+
* @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.
|
1126
|
+
* @param {Number}dueTime Relative time after which to execute the action for the first time.
|
1127
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1128
|
+
*/
|
1129
|
+
schedulerProto.scheduleRecursiveWithRelativeAndState = function (state, dueTime, action) {
|
1130
|
+
return this._scheduleRelative({ first: state, second: action }, dueTime, function (s, p) {
|
1131
|
+
return invokeRecDate(s, p, 'scheduleWithRelativeAndState');
|
1132
|
+
});
|
1133
|
+
};
|
1134
|
+
|
1135
|
+
/**
|
1136
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1137
|
+
* @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.
|
1138
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1139
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1140
|
+
*/
|
1141
|
+
schedulerProto.scheduleRecursiveWithAbsolute = function (dueTime, action) {
|
1142
|
+
return this.scheduleRecursiveWithAbsoluteAndState(action, dueTime, function (_action, self) {
|
1143
|
+
_action(function (dt) {
|
1144
|
+
self(_action, dt);
|
1145
|
+
});
|
1146
|
+
});
|
1147
|
+
};
|
1148
|
+
|
1149
|
+
/**
|
1150
|
+
* Schedules an action to be executed recursively at a specified absolute due time.
|
1151
|
+
* @param {Mixed} state State passed to the action to be executed.
|
1152
|
+
* @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.
|
1153
|
+
* @param {Number}dueTime Absolute time at which to execute the action for the first time.
|
1154
|
+
* @returns {Disposable} The disposable object used to cancel the scheduled action (best effort).
|
1155
|
+
*/
|
1156
|
+
schedulerProto.scheduleRecursiveWithAbsoluteAndState = function (state, dueTime, action) {
|
1157
|
+
return this._scheduleAbsolute({ first: state, second: action }, dueTime, function (s, p) {
|
1158
|
+
return invokeRecDate(s, p, 'scheduleWithAbsoluteAndState');
|
1159
|
+
});
|
1160
|
+
};
|
1161
|
+
|
1162
|
+
/** Gets the current time according to the local machine's system clock. */
|
1163
|
+
Scheduler.now = defaultNow;
|
1164
|
+
|
1165
|
+
/**
|
1166
|
+
* Normalizes the specified TimeSpan value to a positive value.
|
1167
|
+
* @param {Number} timeSpan The time span value to normalize.
|
1168
|
+
* @returns {Number} The specified TimeSpan value if it is zero or positive; otherwise, 0
|
1169
|
+
*/
|
1170
|
+
Scheduler.normalize = function (timeSpan) {
|
1171
|
+
if (timeSpan < 0) {
|
1172
|
+
timeSpan = 0;
|
1173
|
+
}
|
1174
|
+
return timeSpan;
|
1175
|
+
};
|
1176
|
+
|
1177
|
+
return Scheduler;
|
1178
|
+
}());
|
1179
|
+
|
1180
|
+
var normalizeTime = Scheduler.normalize;
|
1181
|
+
|
1182
|
+
var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
|
1183
|
+
function tick(command, recurse) {
|
1184
|
+
recurse(0, this._period);
|
1185
|
+
try {
|
1186
|
+
this._state = this._action(this._state);
|
1187
|
+
} catch (e) {
|
1188
|
+
this._cancel.dispose();
|
1189
|
+
throw e;
|
1190
|
+
}
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
function SchedulePeriodicRecursive(scheduler, state, period, action) {
|
1194
|
+
this._scheduler = scheduler;
|
1195
|
+
this._state = state;
|
1196
|
+
this._period = period;
|
1197
|
+
this._action = action;
|
1198
|
+
}
|
1199
|
+
|
1200
|
+
SchedulePeriodicRecursive.prototype.start = function () {
|
1201
|
+
var d = new SingleAssignmentDisposable();
|
1202
|
+
this._cancel = d;
|
1203
|
+
d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
|
1204
|
+
|
1205
|
+
return d;
|
1206
|
+
};
|
1207
|
+
|
1208
|
+
return SchedulePeriodicRecursive;
|
1209
|
+
}());
|
1210
|
+
|
1211
|
+
/**
|
1212
|
+
* Gets a scheduler that schedules work immediately on the current thread.
|
1213
|
+
*/
|
1214
|
+
var immediateScheduler = Scheduler.immediate = (function () {
|
1215
|
+
|
1216
|
+
function scheduleNow(state, action) { return action(this, state); }
|
1217
|
+
|
1218
|
+
function scheduleRelative(state, dueTime, action) {
|
1219
|
+
var dt = normalizeTime(dt);
|
1220
|
+
while (dt - this.now() > 0) { }
|
1221
|
+
return action(this, state);
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1225
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1226
|
+
}
|
1227
|
+
|
1228
|
+
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1229
|
+
}());
|
1230
|
+
|
1231
|
+
/**
|
1232
|
+
* Gets a scheduler that schedules work as soon as possible on the current thread.
|
1233
|
+
*/
|
1234
|
+
var currentThreadScheduler = Scheduler.currentThread = (function () {
|
1235
|
+
var queue;
|
1236
|
+
|
1237
|
+
function runTrampoline (q) {
|
1238
|
+
var item;
|
1239
|
+
while (q.length > 0) {
|
1240
|
+
item = q.dequeue();
|
1241
|
+
if (!item.isCancelled()) {
|
1242
|
+
// Note, do not schedule blocking work!
|
1243
|
+
while (item.dueTime - Scheduler.now() > 0) {
|
1244
|
+
}
|
1245
|
+
if (!item.isCancelled()) {
|
1246
|
+
item.invoke();
|
1247
|
+
}
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
function scheduleNow(state, action) {
|
1253
|
+
return this.scheduleWithRelativeAndState(state, 0, action);
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
function scheduleRelative(state, dueTime, action) {
|
1257
|
+
var dt = this.now() + Scheduler.normalize(dueTime),
|
1258
|
+
si = new ScheduledItem(this, state, action, dt),
|
1259
|
+
t;
|
1260
|
+
if (!queue) {
|
1261
|
+
queue = new PriorityQueue(4);
|
1262
|
+
queue.enqueue(si);
|
1263
|
+
try {
|
1264
|
+
runTrampoline(queue);
|
1265
|
+
} catch (e) {
|
1266
|
+
throw e;
|
1267
|
+
} finally {
|
1268
|
+
queue = null;
|
1269
|
+
}
|
1270
|
+
} else {
|
1271
|
+
queue.enqueue(si);
|
1272
|
+
}
|
1273
|
+
return si.disposable;
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1277
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
var currentScheduler = new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1281
|
+
currentScheduler.scheduleRequired = function () { return queue === null; };
|
1282
|
+
currentScheduler.ensureTrampoline = function (action) {
|
1283
|
+
if (queue === null) {
|
1284
|
+
return this.schedule(action);
|
1285
|
+
} else {
|
1286
|
+
return action();
|
1287
|
+
}
|
1288
|
+
};
|
1289
|
+
|
1290
|
+
return currentScheduler;
|
1291
|
+
}());
|
1292
|
+
|
1293
|
+
|
1294
|
+
var scheduleMethod, clearMethod = noop;
|
1295
|
+
(function () {
|
1296
|
+
|
1297
|
+
var reNative = RegExp('^' +
|
1298
|
+
String(toString)
|
1299
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1300
|
+
.replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1301
|
+
);
|
1302
|
+
|
1303
|
+
var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1304
|
+
!reNative.test(setImmediate) && setImmediate,
|
1305
|
+
clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
|
1306
|
+
!reNative.test(clearImmediate) && clearImmediate;
|
1307
|
+
|
1308
|
+
function postMessageSupported () {
|
1309
|
+
// Ensure not in a worker
|
1310
|
+
if (!root.postMessage || root.importScripts) { return false; }
|
1311
|
+
var isAsync = false,
|
1312
|
+
oldHandler = root.onmessage;
|
1313
|
+
// Test for async
|
1314
|
+
root.onmessage = function () { isAsync = true; };
|
1315
|
+
root.postMessage('','*');
|
1316
|
+
root.onmessage = oldHandler;
|
1317
|
+
|
1318
|
+
return isAsync;
|
1319
|
+
}
|
1320
|
+
|
1321
|
+
// Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
|
1322
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1323
|
+
scheduleMethod = process.nextTick;
|
1324
|
+
} else if (typeof setImmediate === 'function') {
|
1325
|
+
scheduleMethod = setImmediate;
|
1326
|
+
clearMethod = clearImmediate;
|
1327
|
+
} else if (postMessageSupported()) {
|
1328
|
+
var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
|
1329
|
+
tasks = {},
|
1330
|
+
taskId = 0;
|
1331
|
+
|
1332
|
+
function onGlobalPostMessage(event) {
|
1333
|
+
// Only if we're a match to avoid any other global events
|
1334
|
+
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1335
|
+
var handleId = event.data.substring(MSG_PREFIX.length),
|
1336
|
+
action = tasks[handleId];
|
1337
|
+
action();
|
1338
|
+
delete tasks[handleId];
|
1339
|
+
}
|
1340
|
+
}
|
1341
|
+
|
1342
|
+
if (root.addEventListener) {
|
1343
|
+
root.addEventListener('message', onGlobalPostMessage, false);
|
1344
|
+
} else {
|
1345
|
+
root.attachEvent('onmessage', onGlobalPostMessage, false);
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
scheduleMethod = function (action) {
|
1349
|
+
var currentId = taskId++;
|
1350
|
+
tasks[currentId] = action;
|
1351
|
+
root.postMessage(MSG_PREFIX + currentId, '*');
|
1352
|
+
};
|
1353
|
+
} else if (!!root.MessageChannel) {
|
1354
|
+
var channel = new root.MessageChannel(),
|
1355
|
+
channelTasks = {},
|
1356
|
+
channelTaskId = 0;
|
1357
|
+
|
1358
|
+
channel.port1.onmessage = function (event) {
|
1359
|
+
var id = event.data,
|
1360
|
+
action = channelTasks[id];
|
1361
|
+
action();
|
1362
|
+
delete channelTasks[id];
|
1363
|
+
};
|
1364
|
+
|
1365
|
+
scheduleMethod = function (action) {
|
1366
|
+
var id = channelTaskId++;
|
1367
|
+
channelTasks[id] = action;
|
1368
|
+
channel.port2.postMessage(id);
|
1369
|
+
};
|
1370
|
+
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1371
|
+
|
1372
|
+
scheduleMethod = function (action) {
|
1373
|
+
var scriptElement = root.document.createElement('script');
|
1374
|
+
scriptElement.onreadystatechange = function () {
|
1375
|
+
action();
|
1376
|
+
scriptElement.onreadystatechange = null;
|
1377
|
+
scriptElement.parentNode.removeChild(scriptElement);
|
1378
|
+
scriptElement = null;
|
1379
|
+
};
|
1380
|
+
root.document.documentElement.appendChild(scriptElement);
|
1381
|
+
};
|
1382
|
+
|
1383
|
+
} else {
|
1384
|
+
scheduleMethod = function (action) { return setTimeout(action, 0); };
|
1385
|
+
clearMethod = clearTimeout;
|
1386
|
+
}
|
1387
|
+
}());
|
1388
|
+
|
1389
|
+
/**
|
1390
|
+
* Gets a scheduler that schedules work via a timed callback based upon platform.
|
1391
|
+
*/
|
1392
|
+
var timeoutScheduler = Scheduler.timeout = (function () {
|
1393
|
+
|
1394
|
+
function scheduleNow(state, action) {
|
1395
|
+
var scheduler = this,
|
1396
|
+
disposable = new SingleAssignmentDisposable();
|
1397
|
+
var id = scheduleMethod(function () {
|
1398
|
+
if (!disposable.isDisposed) {
|
1399
|
+
disposable.setDisposable(action(scheduler, state));
|
1400
|
+
}
|
1401
|
+
});
|
1402
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1403
|
+
clearMethod(id);
|
1404
|
+
}));
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
function scheduleRelative(state, dueTime, action) {
|
1408
|
+
var scheduler = this,
|
1409
|
+
dt = Scheduler.normalize(dueTime);
|
1410
|
+
if (dt === 0) {
|
1411
|
+
return scheduler.scheduleWithState(state, action);
|
1412
|
+
}
|
1413
|
+
var disposable = new SingleAssignmentDisposable();
|
1414
|
+
var id = setTimeout(function () {
|
1415
|
+
if (!disposable.isDisposed) {
|
1416
|
+
disposable.setDisposable(action(scheduler, state));
|
1417
|
+
}
|
1418
|
+
}, dt);
|
1419
|
+
return new CompositeDisposable(disposable, disposableCreate(function () {
|
1420
|
+
clearTimeout(id);
|
1421
|
+
}));
|
1422
|
+
}
|
1423
|
+
|
1424
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1425
|
+
return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1429
|
+
})();
|
1430
|
+
|
1431
|
+
/** @private */
|
1432
|
+
var CatchScheduler = (function (_super) {
|
1433
|
+
|
1434
|
+
function localNow() {
|
1435
|
+
return this._scheduler.now();
|
1436
|
+
}
|
1437
|
+
|
1438
|
+
function scheduleNow(state, action) {
|
1439
|
+
return this._scheduler.scheduleWithState(state, this._wrap(action));
|
1440
|
+
}
|
1441
|
+
|
1442
|
+
function scheduleRelative(state, dueTime, action) {
|
1443
|
+
return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
|
1444
|
+
}
|
1445
|
+
|
1446
|
+
function scheduleAbsolute(state, dueTime, action) {
|
1447
|
+
return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
|
1448
|
+
}
|
1449
|
+
|
1450
|
+
inherits(CatchScheduler, _super);
|
1451
|
+
|
1452
|
+
/** @private */
|
1453
|
+
function CatchScheduler(scheduler, handler) {
|
1454
|
+
this._scheduler = scheduler;
|
1455
|
+
this._handler = handler;
|
1456
|
+
this._recursiveOriginal = null;
|
1457
|
+
this._recursiveWrapper = null;
|
1458
|
+
_super.call(this, localNow, scheduleNow, scheduleRelative, scheduleAbsolute);
|
1459
|
+
}
|
1460
|
+
|
1461
|
+
/** @private */
|
1462
|
+
CatchScheduler.prototype._clone = function (scheduler) {
|
1463
|
+
return new CatchScheduler(scheduler, this._handler);
|
1464
|
+
};
|
1465
|
+
|
1466
|
+
/** @private */
|
1467
|
+
CatchScheduler.prototype._wrap = function (action) {
|
1468
|
+
var parent = this;
|
1469
|
+
return function (self, state) {
|
1470
|
+
try {
|
1471
|
+
return action(parent._getRecursiveWrapper(self), state);
|
1472
|
+
} catch (e) {
|
1473
|
+
if (!parent._handler(e)) { throw e; }
|
1474
|
+
return disposableEmpty;
|
1475
|
+
}
|
1476
|
+
};
|
1477
|
+
};
|
1478
|
+
|
1479
|
+
/** @private */
|
1480
|
+
CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
|
1481
|
+
if (this._recursiveOriginal !== scheduler) {
|
1482
|
+
this._recursiveOriginal = scheduler;
|
1483
|
+
var wrapper = this._clone(scheduler);
|
1484
|
+
wrapper._recursiveOriginal = scheduler;
|
1485
|
+
wrapper._recursiveWrapper = wrapper;
|
1486
|
+
this._recursiveWrapper = wrapper;
|
1487
|
+
}
|
1488
|
+
return this._recursiveWrapper;
|
1489
|
+
};
|
1490
|
+
|
1491
|
+
/** @private */
|
1492
|
+
CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
|
1493
|
+
var self = this, failed = false, d = new SingleAssignmentDisposable();
|
1494
|
+
|
1495
|
+
d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
|
1496
|
+
if (failed) { return null; }
|
1497
|
+
try {
|
1498
|
+
return action(state1);
|
1499
|
+
} catch (e) {
|
1500
|
+
failed = true;
|
1501
|
+
if (!self._handler(e)) { throw e; }
|
1502
|
+
d.dispose();
|
1503
|
+
return null;
|
1504
|
+
}
|
1505
|
+
}));
|
1506
|
+
|
1507
|
+
return d;
|
1508
|
+
};
|
1509
|
+
|
1510
|
+
return CatchScheduler;
|
1511
|
+
}(Scheduler));
|
1512
|
+
|
1513
|
+
/**
|
1514
|
+
* Represents a notification to an observer.
|
1515
|
+
*/
|
1516
|
+
var Notification = Rx.Notification = (function () {
|
1517
|
+
function Notification(kind, hasValue) {
|
1518
|
+
this.hasValue = hasValue == null ? false : hasValue;
|
1519
|
+
this.kind = kind;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
var NotificationPrototype = Notification.prototype;
|
1523
|
+
|
1524
|
+
/**
|
1525
|
+
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
|
1526
|
+
*
|
1527
|
+
* @memberOf Notification
|
1528
|
+
* @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on..
|
1529
|
+
* @param {Function} onError Delegate to invoke for an OnError notification.
|
1530
|
+
* @param {Function} onCompleted Delegate to invoke for an OnCompleted notification.
|
1531
|
+
* @returns {Any} Result produced by the observation.
|
1532
|
+
*/
|
1533
|
+
NotificationPrototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1534
|
+
if (arguments.length === 1 && typeof observerOrOnNext === 'object') {
|
1535
|
+
return this._acceptObservable(observerOrOnNext);
|
1536
|
+
}
|
1537
|
+
return this._accept(observerOrOnNext, onError, onCompleted);
|
1538
|
+
};
|
1539
|
+
|
1540
|
+
/**
|
1541
|
+
* Returns an observable sequence with a single notification.
|
1542
|
+
*
|
1543
|
+
* @memberOf Notification
|
1544
|
+
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
|
1545
|
+
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
|
1546
|
+
*/
|
1547
|
+
NotificationPrototype.toObservable = function (scheduler) {
|
1548
|
+
var notification = this;
|
1549
|
+
scheduler || (scheduler = immediateScheduler);
|
1550
|
+
return new AnonymousObservable(function (observer) {
|
1551
|
+
return scheduler.schedule(function () {
|
1552
|
+
notification._acceptObservable(observer);
|
1553
|
+
if (notification.kind === 'N') {
|
1554
|
+
observer.onCompleted();
|
1555
|
+
}
|
1556
|
+
});
|
1557
|
+
});
|
1558
|
+
};
|
1559
|
+
|
1560
|
+
return Notification;
|
1561
|
+
})();
|
1562
|
+
|
1563
|
+
/**
|
1564
|
+
* Creates an object that represents an OnNext notification to an observer.
|
1565
|
+
* @param {Any} value The value contained in the notification.
|
1566
|
+
* @returns {Notification} The OnNext notification containing the value.
|
1567
|
+
*/
|
1568
|
+
var notificationCreateOnNext = Notification.createOnNext = (function () {
|
1569
|
+
|
1570
|
+
function _accept (onNext) {
|
1571
|
+
return onNext(this.value);
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
function _acceptObservable(observer) {
|
1575
|
+
return observer.onNext(this.value);
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
function toString () {
|
1579
|
+
return 'OnNext(' + this.value + ')';
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
return function (value) {
|
1583
|
+
var notification = new Notification('N', true);
|
1584
|
+
notification.value = value;
|
1585
|
+
notification._accept = _accept;
|
1586
|
+
notification._acceptObservable = _acceptObservable;
|
1587
|
+
notification.toString = toString;
|
1588
|
+
return notification;
|
1589
|
+
};
|
1590
|
+
}());
|
1591
|
+
|
1592
|
+
/**
|
1593
|
+
* Creates an object that represents an OnError notification to an observer.
|
1594
|
+
* @param {Any} error The exception contained in the notification.
|
1595
|
+
* @returns {Notification} The OnError notification containing the exception.
|
1596
|
+
*/
|
1597
|
+
var notificationCreateOnError = Notification.createOnError = (function () {
|
1598
|
+
|
1599
|
+
function _accept (onNext, onError) {
|
1600
|
+
return onError(this.exception);
|
1601
|
+
}
|
1602
|
+
|
1603
|
+
function _acceptObservable(observer) {
|
1604
|
+
return observer.onError(this.exception);
|
1605
|
+
}
|
1606
|
+
|
1607
|
+
function toString () {
|
1608
|
+
return 'OnError(' + this.exception + ')';
|
1609
|
+
}
|
1610
|
+
|
1611
|
+
return function (exception) {
|
1612
|
+
var notification = new Notification('E');
|
1613
|
+
notification.exception = exception;
|
1614
|
+
notification._accept = _accept;
|
1615
|
+
notification._acceptObservable = _acceptObservable;
|
1616
|
+
notification.toString = toString;
|
1617
|
+
return notification;
|
1618
|
+
};
|
1619
|
+
}());
|
1620
|
+
|
1621
|
+
/**
|
1622
|
+
* Creates an object that represents an OnCompleted notification to an observer.
|
1623
|
+
* @returns {Notification} The OnCompleted notification.
|
1624
|
+
*/
|
1625
|
+
var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
|
1626
|
+
|
1627
|
+
function _accept (onNext, onError, onCompleted) {
|
1628
|
+
return onCompleted();
|
1629
|
+
}
|
1630
|
+
|
1631
|
+
function _acceptObservable(observer) {
|
1632
|
+
return observer.onCompleted();
|
1633
|
+
}
|
1634
|
+
|
1635
|
+
function toString () {
|
1636
|
+
return 'OnCompleted()';
|
1637
|
+
}
|
1638
|
+
|
1639
|
+
return function () {
|
1640
|
+
var notification = new Notification('C');
|
1641
|
+
notification._accept = _accept;
|
1642
|
+
notification._acceptObservable = _acceptObservable;
|
1643
|
+
notification.toString = toString;
|
1644
|
+
return notification;
|
1645
|
+
};
|
1646
|
+
}());
|
1647
|
+
|
1648
|
+
var Enumerator = Rx.internals.Enumerator = function (next) {
|
1649
|
+
this._next = next;
|
1650
|
+
};
|
1651
|
+
|
1652
|
+
Enumerator.prototype.next = function () {
|
1653
|
+
return this._next();
|
1654
|
+
};
|
1655
|
+
|
1656
|
+
Enumerator.prototype[$iterator$] = function () { return this; }
|
1657
|
+
|
1658
|
+
var Enumerable = Rx.internals.Enumerable = function (iterator) {
|
1659
|
+
this._iterator = iterator;
|
1660
|
+
};
|
1661
|
+
|
1662
|
+
Enumerable.prototype[$iterator$] = function () {
|
1663
|
+
return this._iterator();
|
1664
|
+
};
|
1665
|
+
|
1666
|
+
Enumerable.prototype.concat = function () {
|
1667
|
+
var sources = this;
|
1668
|
+
return new AnonymousObservable(function (observer) {
|
1669
|
+
var e;
|
1670
|
+
try {
|
1671
|
+
e = sources[$iterator$]();
|
1672
|
+
} catch(err) {
|
1673
|
+
observer.onError();
|
1674
|
+
return;
|
1675
|
+
}
|
1676
|
+
|
1677
|
+
var isDisposed,
|
1678
|
+
subscription = new SerialDisposable();
|
1679
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1680
|
+
var currentItem;
|
1681
|
+
if (isDisposed) { return; }
|
1682
|
+
|
1683
|
+
try {
|
1684
|
+
currentItem = e.next();
|
1685
|
+
} catch (ex) {
|
1686
|
+
observer.onError(ex);
|
1687
|
+
return;
|
1688
|
+
}
|
1689
|
+
|
1690
|
+
if (currentItem.done) {
|
1691
|
+
observer.onCompleted();
|
1692
|
+
return;
|
1693
|
+
}
|
1694
|
+
|
1695
|
+
// Check if promise
|
1696
|
+
var currentValue = currentItem.value;
|
1697
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1698
|
+
|
1699
|
+
var d = new SingleAssignmentDisposable();
|
1700
|
+
subscription.setDisposable(d);
|
1701
|
+
d.setDisposable(currentValue.subscribe(
|
1702
|
+
observer.onNext.bind(observer),
|
1703
|
+
observer.onError.bind(observer),
|
1704
|
+
function () { self(); })
|
1705
|
+
);
|
1706
|
+
});
|
1707
|
+
|
1708
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1709
|
+
isDisposed = true;
|
1710
|
+
}));
|
1711
|
+
});
|
1712
|
+
};
|
1713
|
+
|
1714
|
+
Enumerable.prototype.catchException = function () {
|
1715
|
+
var sources = this;
|
1716
|
+
return new AnonymousObservable(function (observer) {
|
1717
|
+
var e;
|
1718
|
+
try {
|
1719
|
+
e = sources[$iterator$]();
|
1720
|
+
} catch(err) {
|
1721
|
+
observer.onError();
|
1722
|
+
return;
|
1723
|
+
}
|
1724
|
+
|
1725
|
+
var isDisposed,
|
1726
|
+
lastException,
|
1727
|
+
subscription = new SerialDisposable();
|
1728
|
+
var cancelable = immediateScheduler.scheduleRecursive(function (self) {
|
1729
|
+
if (isDisposed) { return; }
|
1730
|
+
|
1731
|
+
var currentItem;
|
1732
|
+
try {
|
1733
|
+
currentItem = e.next();
|
1734
|
+
} catch (ex) {
|
1735
|
+
observer.onError(ex);
|
1736
|
+
return;
|
1737
|
+
}
|
1738
|
+
|
1739
|
+
if (currentItem.done) {
|
1740
|
+
if (lastException) {
|
1741
|
+
observer.onError(lastException);
|
1742
|
+
} else {
|
1743
|
+
observer.onCompleted();
|
1744
|
+
}
|
1745
|
+
return;
|
1746
|
+
}
|
1747
|
+
|
1748
|
+
// Check if promise
|
1749
|
+
var currentValue = currentItem.value;
|
1750
|
+
isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
1751
|
+
|
1752
|
+
var d = new SingleAssignmentDisposable();
|
1753
|
+
subscription.setDisposable(d);
|
1754
|
+
d.setDisposable(currentValue.subscribe(
|
1755
|
+
observer.onNext.bind(observer),
|
1756
|
+
function (exn) {
|
1757
|
+
lastException = exn;
|
1758
|
+
self();
|
1759
|
+
},
|
1760
|
+
observer.onCompleted.bind(observer)));
|
1761
|
+
});
|
1762
|
+
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
|
1763
|
+
isDisposed = true;
|
1764
|
+
}));
|
1765
|
+
});
|
1766
|
+
};
|
1767
|
+
|
1768
|
+
var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
1769
|
+
if (repeatCount == null) { repeatCount = -1; }
|
1770
|
+
return new Enumerable(function () {
|
1771
|
+
var left = repeatCount;
|
1772
|
+
return new Enumerator(function () {
|
1773
|
+
if (left === 0) { return doneEnumerator; }
|
1774
|
+
if (left > 0) { left--; }
|
1775
|
+
return { done: false, value: value };
|
1776
|
+
});
|
1777
|
+
});
|
1778
|
+
};
|
1779
|
+
|
1780
|
+
var enumerableFor = Enumerable.forEach = function (source, selector, thisArg) {
|
1781
|
+
selector || (selector = identity);
|
1782
|
+
return new Enumerable(function () {
|
1783
|
+
var index = -1;
|
1784
|
+
return new Enumerator(
|
1785
|
+
function () {
|
1786
|
+
return ++index < source.length ?
|
1787
|
+
{ done: false, value: selector.call(thisArg, source[index], index, source) } :
|
1788
|
+
doneEnumerator;
|
1789
|
+
});
|
1790
|
+
});
|
1791
|
+
};
|
1792
|
+
|
1793
|
+
/**
|
1794
|
+
* Supports push-style iteration over an observable sequence.
|
1795
|
+
*/
|
1796
|
+
var Observer = Rx.Observer = function () { };
|
1797
|
+
|
1798
|
+
/**
|
1799
|
+
* Creates a notification callback from an observer.
|
1800
|
+
*
|
1801
|
+
* @param observer Observer object.
|
1802
|
+
* @returns The action that forwards its input notification to the underlying observer.
|
1803
|
+
*/
|
1804
|
+
Observer.prototype.toNotifier = function () {
|
1805
|
+
var observer = this;
|
1806
|
+
return function (n) {
|
1807
|
+
return n.accept(observer);
|
1808
|
+
};
|
1809
|
+
};
|
1810
|
+
|
1811
|
+
/**
|
1812
|
+
* Hides the identity of an observer.
|
1813
|
+
|
1814
|
+
* @returns An observer that hides the identity of the specified observer.
|
1815
|
+
*/
|
1816
|
+
Observer.prototype.asObserver = function () {
|
1817
|
+
return new AnonymousObserver(this.onNext.bind(this), this.onError.bind(this), this.onCompleted.bind(this));
|
1818
|
+
};
|
1819
|
+
|
1820
|
+
/**
|
1821
|
+
* 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.
|
1822
|
+
* If a violation is detected, an Error is thrown from the offending observer method call.
|
1823
|
+
*
|
1824
|
+
* @returns An observer that checks callbacks invocations against the observer grammar and, if the checks pass, forwards those to the specified observer.
|
1825
|
+
*/
|
1826
|
+
Observer.prototype.checked = function () { return new CheckedObserver(this); };
|
1827
|
+
|
1828
|
+
/**
|
1829
|
+
* Creates an observer from the specified OnNext, along with optional OnError, and OnCompleted actions.
|
1830
|
+
*
|
1831
|
+
* @static
|
1832
|
+
* @memberOf Observer
|
1833
|
+
* @param {Function} [onNext] Observer's OnNext action implementation.
|
1834
|
+
* @param {Function} [onError] Observer's OnError action implementation.
|
1835
|
+
* @param {Function} [onCompleted] Observer's OnCompleted action implementation.
|
1836
|
+
* @returns {Observer} The observer object implemented using the given actions.
|
1837
|
+
*/
|
1838
|
+
var observerCreate = Observer.create = function (onNext, onError, onCompleted) {
|
1839
|
+
onNext || (onNext = noop);
|
1840
|
+
onError || (onError = defaultError);
|
1841
|
+
onCompleted || (onCompleted = noop);
|
1842
|
+
return new AnonymousObserver(onNext, onError, onCompleted);
|
1843
|
+
};
|
1844
|
+
|
1845
|
+
/**
|
1846
|
+
* Creates an observer from a notification callback.
|
1847
|
+
*
|
1848
|
+
* @static
|
1849
|
+
* @memberOf Observer
|
1850
|
+
* @param {Function} handler Action that handles a notification.
|
1851
|
+
* @returns The observer object that invokes the specified handler using a notification corresponding to each message it receives.
|
1852
|
+
*/
|
1853
|
+
Observer.fromNotifier = function (handler) {
|
1854
|
+
return new AnonymousObserver(function (x) {
|
1855
|
+
return handler(notificationCreateOnNext(x));
|
1856
|
+
}, function (exception) {
|
1857
|
+
return handler(notificationCreateOnError(exception));
|
1858
|
+
}, function () {
|
1859
|
+
return handler(notificationCreateOnCompleted());
|
1860
|
+
});
|
1861
|
+
};
|
1862
|
+
|
1863
|
+
/**
|
1864
|
+
* Schedules the invocation of observer methods on the given scheduler.
|
1865
|
+
* @param {Scheduler} scheduler Scheduler to schedule observer messages on.
|
1866
|
+
* @returns {Observer} Observer whose messages are scheduled on the given scheduler.
|
1867
|
+
*/
|
1868
|
+
Observer.notifyOn = function (scheduler) {
|
1869
|
+
return new ObserveOnObserver(scheduler, this);
|
1870
|
+
};
|
1871
|
+
|
1872
|
+
/**
|
1873
|
+
* Abstract base class for implementations of the Observer class.
|
1874
|
+
* This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
|
1875
|
+
*/
|
1876
|
+
var AbstractObserver = Rx.internals.AbstractObserver = (function (_super) {
|
1877
|
+
inherits(AbstractObserver, _super);
|
1878
|
+
|
1879
|
+
/**
|
1880
|
+
* Creates a new observer in a non-stopped state.
|
1881
|
+
*
|
1882
|
+
* @constructor
|
1883
|
+
*/
|
1884
|
+
function AbstractObserver() {
|
1885
|
+
this.isStopped = false;
|
1886
|
+
_super.call(this);
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
/**
|
1890
|
+
* Notifies the observer of a new element in the sequence.
|
1891
|
+
*
|
1892
|
+
* @memberOf AbstractObserver
|
1893
|
+
* @param {Any} value Next element in the sequence.
|
1894
|
+
*/
|
1895
|
+
AbstractObserver.prototype.onNext = function (value) {
|
1896
|
+
if (!this.isStopped) {
|
1897
|
+
this.next(value);
|
1898
|
+
}
|
1899
|
+
};
|
1900
|
+
|
1901
|
+
/**
|
1902
|
+
* Notifies the observer that an exception has occurred.
|
1903
|
+
*
|
1904
|
+
* @memberOf AbstractObserver
|
1905
|
+
* @param {Any} error The error that has occurred.
|
1906
|
+
*/
|
1907
|
+
AbstractObserver.prototype.onError = function (error) {
|
1908
|
+
if (!this.isStopped) {
|
1909
|
+
this.isStopped = true;
|
1910
|
+
this.error(error);
|
1911
|
+
}
|
1912
|
+
};
|
1913
|
+
|
1914
|
+
/**
|
1915
|
+
* Notifies the observer of the end of the sequence.
|
1916
|
+
*/
|
1917
|
+
AbstractObserver.prototype.onCompleted = function () {
|
1918
|
+
if (!this.isStopped) {
|
1919
|
+
this.isStopped = true;
|
1920
|
+
this.completed();
|
1921
|
+
}
|
1922
|
+
};
|
1923
|
+
|
1924
|
+
/**
|
1925
|
+
* Disposes the observer, causing it to transition to the stopped state.
|
1926
|
+
*/
|
1927
|
+
AbstractObserver.prototype.dispose = function () {
|
1928
|
+
this.isStopped = true;
|
1929
|
+
};
|
1930
|
+
|
1931
|
+
AbstractObserver.prototype.fail = function (e) {
|
1932
|
+
if (!this.isStopped) {
|
1933
|
+
this.isStopped = true;
|
1934
|
+
this.error(e);
|
1935
|
+
return true;
|
1936
|
+
}
|
1937
|
+
|
1938
|
+
return false;
|
1939
|
+
};
|
1940
|
+
|
1941
|
+
return AbstractObserver;
|
1942
|
+
}(Observer));
|
1943
|
+
|
1944
|
+
/**
|
1945
|
+
* Class to create an Observer instance from delegate-based implementations of the on* methods.
|
1946
|
+
*/
|
1947
|
+
var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
|
1948
|
+
inherits(AnonymousObserver, _super);
|
1949
|
+
|
1950
|
+
/**
|
1951
|
+
* Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
|
1952
|
+
* @param {Any} onNext Observer's OnNext action implementation.
|
1953
|
+
* @param {Any} onError Observer's OnError action implementation.
|
1954
|
+
* @param {Any} onCompleted Observer's OnCompleted action implementation.
|
1955
|
+
*/
|
1956
|
+
function AnonymousObserver(onNext, onError, onCompleted) {
|
1957
|
+
_super.call(this);
|
1958
|
+
this._onNext = onNext;
|
1959
|
+
this._onError = onError;
|
1960
|
+
this._onCompleted = onCompleted;
|
1961
|
+
}
|
1962
|
+
|
1963
|
+
/**
|
1964
|
+
* Calls the onNext action.
|
1965
|
+
* @param {Any} value Next element in the sequence.
|
1966
|
+
*/
|
1967
|
+
AnonymousObserver.prototype.next = function (value) {
|
1968
|
+
this._onNext(value);
|
1969
|
+
};
|
1970
|
+
|
1971
|
+
/**
|
1972
|
+
* Calls the onError action.
|
1973
|
+
* @param {Any} error The error that has occurred.
|
1974
|
+
*/
|
1975
|
+
AnonymousObserver.prototype.error = function (exception) {
|
1976
|
+
this._onError(exception);
|
1977
|
+
};
|
1978
|
+
|
1979
|
+
/**
|
1980
|
+
* Calls the onCompleted action.
|
1981
|
+
*/
|
1982
|
+
AnonymousObserver.prototype.completed = function () {
|
1983
|
+
this._onCompleted();
|
1984
|
+
};
|
1985
|
+
|
1986
|
+
return AnonymousObserver;
|
1987
|
+
}(AbstractObserver));
|
1988
|
+
|
1989
|
+
var CheckedObserver = (function (_super) {
|
1990
|
+
inherits(CheckedObserver, _super);
|
1991
|
+
|
1992
|
+
function CheckedObserver(observer) {
|
1993
|
+
_super.call(this);
|
1994
|
+
this._observer = observer;
|
1995
|
+
this._state = 0; // 0 - idle, 1 - busy, 2 - done
|
1996
|
+
}
|
1997
|
+
|
1998
|
+
var CheckedObserverPrototype = CheckedObserver.prototype;
|
1999
|
+
|
2000
|
+
CheckedObserverPrototype.onNext = function (value) {
|
2001
|
+
this.checkAccess();
|
2002
|
+
try {
|
2003
|
+
this._observer.onNext(value);
|
2004
|
+
} catch (e) {
|
2005
|
+
throw e;
|
2006
|
+
} finally {
|
2007
|
+
this._state = 0;
|
2008
|
+
}
|
2009
|
+
};
|
2010
|
+
|
2011
|
+
CheckedObserverPrototype.onError = function (err) {
|
2012
|
+
this.checkAccess();
|
2013
|
+
try {
|
2014
|
+
this._observer.onError(err);
|
2015
|
+
} catch (e) {
|
2016
|
+
throw e;
|
2017
|
+
} finally {
|
2018
|
+
this._state = 2;
|
2019
|
+
}
|
2020
|
+
};
|
2021
|
+
|
2022
|
+
CheckedObserverPrototype.onCompleted = function () {
|
2023
|
+
this.checkAccess();
|
2024
|
+
try {
|
2025
|
+
this._observer.onCompleted();
|
2026
|
+
} catch (e) {
|
2027
|
+
throw e;
|
2028
|
+
} finally {
|
2029
|
+
this._state = 2;
|
2030
|
+
}
|
2031
|
+
};
|
2032
|
+
|
2033
|
+
CheckedObserverPrototype.checkAccess = function () {
|
2034
|
+
if (this._state === 1) { throw new Error('Re-entrancy detected'); }
|
2035
|
+
if (this._state === 2) { throw new Error('Observer completed'); }
|
2036
|
+
if (this._state === 0) { this._state = 1; }
|
2037
|
+
};
|
2038
|
+
|
2039
|
+
return CheckedObserver;
|
2040
|
+
}(Observer));
|
2041
|
+
|
2042
|
+
var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
|
2043
|
+
inherits(ScheduledObserver, _super);
|
2044
|
+
|
2045
|
+
function ScheduledObserver(scheduler, observer) {
|
2046
|
+
_super.call(this);
|
2047
|
+
this.scheduler = scheduler;
|
2048
|
+
this.observer = observer;
|
2049
|
+
this.isAcquired = false;
|
2050
|
+
this.hasFaulted = false;
|
2051
|
+
this.queue = [];
|
2052
|
+
this.disposable = new SerialDisposable();
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
ScheduledObserver.prototype.next = function (value) {
|
2056
|
+
var self = this;
|
2057
|
+
this.queue.push(function () {
|
2058
|
+
self.observer.onNext(value);
|
2059
|
+
});
|
2060
|
+
};
|
2061
|
+
|
2062
|
+
ScheduledObserver.prototype.error = function (exception) {
|
2063
|
+
var self = this;
|
2064
|
+
this.queue.push(function () {
|
2065
|
+
self.observer.onError(exception);
|
2066
|
+
});
|
2067
|
+
};
|
2068
|
+
|
2069
|
+
ScheduledObserver.prototype.completed = function () {
|
2070
|
+
var self = this;
|
2071
|
+
this.queue.push(function () {
|
2072
|
+
self.observer.onCompleted();
|
2073
|
+
});
|
2074
|
+
};
|
2075
|
+
|
2076
|
+
ScheduledObserver.prototype.ensureActive = function () {
|
2077
|
+
var isOwner = false, parent = this;
|
2078
|
+
if (!this.hasFaulted && this.queue.length > 0) {
|
2079
|
+
isOwner = !this.isAcquired;
|
2080
|
+
this.isAcquired = true;
|
2081
|
+
}
|
2082
|
+
if (isOwner) {
|
2083
|
+
this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
|
2084
|
+
var work;
|
2085
|
+
if (parent.queue.length > 0) {
|
2086
|
+
work = parent.queue.shift();
|
2087
|
+
} else {
|
2088
|
+
parent.isAcquired = false;
|
2089
|
+
return;
|
2090
|
+
}
|
2091
|
+
try {
|
2092
|
+
work();
|
2093
|
+
} catch (ex) {
|
2094
|
+
parent.queue = [];
|
2095
|
+
parent.hasFaulted = true;
|
2096
|
+
throw ex;
|
2097
|
+
}
|
2098
|
+
self();
|
2099
|
+
}));
|
2100
|
+
}
|
2101
|
+
};
|
2102
|
+
|
2103
|
+
ScheduledObserver.prototype.dispose = function () {
|
2104
|
+
_super.prototype.dispose.call(this);
|
2105
|
+
this.disposable.dispose();
|
2106
|
+
};
|
2107
|
+
|
2108
|
+
return ScheduledObserver;
|
2109
|
+
}(AbstractObserver));
|
2110
|
+
|
2111
|
+
/** @private */
|
2112
|
+
var ObserveOnObserver = (function (_super) {
|
2113
|
+
inherits(ObserveOnObserver, _super);
|
2114
|
+
|
2115
|
+
/** @private */
|
2116
|
+
function ObserveOnObserver() {
|
2117
|
+
_super.apply(this, arguments);
|
2118
|
+
}
|
2119
|
+
|
2120
|
+
/** @private */
|
2121
|
+
ObserveOnObserver.prototype.next = function (value) {
|
2122
|
+
_super.prototype.next.call(this, value);
|
2123
|
+
this.ensureActive();
|
2124
|
+
};
|
2125
|
+
|
2126
|
+
/** @private */
|
2127
|
+
ObserveOnObserver.prototype.error = function (e) {
|
2128
|
+
_super.prototype.error.call(this, e);
|
2129
|
+
this.ensureActive();
|
2130
|
+
};
|
2131
|
+
|
2132
|
+
/** @private */
|
2133
|
+
ObserveOnObserver.prototype.completed = function () {
|
2134
|
+
_super.prototype.completed.call(this);
|
2135
|
+
this.ensureActive();
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
return ObserveOnObserver;
|
2139
|
+
})(ScheduledObserver);
|
2140
|
+
|
2141
|
+
var observableProto;
|
2142
|
+
|
2143
|
+
/**
|
2144
|
+
* Represents a push-style collection.
|
2145
|
+
*/
|
2146
|
+
var Observable = Rx.Observable = (function () {
|
2147
|
+
|
2148
|
+
function Observable(subscribe) {
|
2149
|
+
this._subscribe = subscribe;
|
2150
|
+
}
|
2151
|
+
|
2152
|
+
observableProto = Observable.prototype;
|
2153
|
+
|
2154
|
+
/**
|
2155
|
+
* Subscribes an observer to the observable sequence.
|
2156
|
+
*
|
2157
|
+
* @example
|
2158
|
+
* 1 - source.subscribe();
|
2159
|
+
* 2 - source.subscribe(observer);
|
2160
|
+
* 3 - source.subscribe(function (x) { console.log(x); });
|
2161
|
+
* 4 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); });
|
2162
|
+
* 5 - source.subscribe(function (x) { console.log(x); }, function (err) { console.log(err); }, function () { console.log('done'); });
|
2163
|
+
* @param {Mixed} [observerOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
|
2164
|
+
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
|
2165
|
+
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
|
2166
|
+
* @returns {Diposable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
|
2167
|
+
*/
|
2168
|
+
observableProto.subscribe = observableProto.forEach = function (observerOrOnNext, onError, onCompleted) {
|
2169
|
+
var subscriber = typeof observerOrOnNext === 'object' ?
|
2170
|
+
observerOrOnNext :
|
2171
|
+
observerCreate(observerOrOnNext, onError, onCompleted);
|
2172
|
+
|
2173
|
+
return this._subscribe(subscriber);
|
2174
|
+
};
|
2175
|
+
|
2176
|
+
return Observable;
|
2177
|
+
})();
|
2178
|
+
|
2179
|
+
var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
|
2180
|
+
inherits(AnonymousObservable, __super__);
|
2181
|
+
|
2182
|
+
// Fix subscriber to check for undefined or function returned to decorate as Disposable
|
2183
|
+
function fixSubscriber(subscriber) {
|
2184
|
+
if (typeof subscriber === 'undefined') {
|
2185
|
+
subscriber = disposableEmpty;
|
2186
|
+
} else if (typeof subscriber === 'function') {
|
2187
|
+
subscriber = disposableCreate(subscriber);
|
2188
|
+
}
|
2189
|
+
|
2190
|
+
return subscriber;
|
2191
|
+
}
|
2192
|
+
|
2193
|
+
function AnonymousObservable(subscribe) {
|
2194
|
+
if (!(this instanceof AnonymousObservable)) {
|
2195
|
+
return new AnonymousObservable(subscribe);
|
2196
|
+
}
|
2197
|
+
|
2198
|
+
function s(observer) {
|
2199
|
+
var autoDetachObserver = new AutoDetachObserver(observer);
|
2200
|
+
if (currentThreadScheduler.scheduleRequired()) {
|
2201
|
+
currentThreadScheduler.schedule(function () {
|
2202
|
+
try {
|
2203
|
+
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
2204
|
+
} catch (e) {
|
2205
|
+
if (!autoDetachObserver.fail(e)) {
|
2206
|
+
throw e;
|
2207
|
+
}
|
2208
|
+
}
|
2209
|
+
});
|
2210
|
+
} else {
|
2211
|
+
try {
|
2212
|
+
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
|
2213
|
+
} catch (e) {
|
2214
|
+
if (!autoDetachObserver.fail(e)) {
|
2215
|
+
throw e;
|
2216
|
+
}
|
2217
|
+
}
|
2218
|
+
}
|
2219
|
+
|
2220
|
+
return autoDetachObserver;
|
2221
|
+
}
|
2222
|
+
|
2223
|
+
__super__.call(this, s);
|
2224
|
+
}
|
2225
|
+
|
2226
|
+
return AnonymousObservable;
|
2227
|
+
|
2228
|
+
}(Observable));
|
2229
|
+
|
2230
|
+
/** @private */
|
2231
|
+
var AutoDetachObserver = (function (_super) {
|
2232
|
+
inherits(AutoDetachObserver, _super);
|
2233
|
+
|
2234
|
+
function AutoDetachObserver(observer) {
|
2235
|
+
_super.call(this);
|
2236
|
+
this.observer = observer;
|
2237
|
+
this.m = new SingleAssignmentDisposable();
|
2238
|
+
}
|
2239
|
+
|
2240
|
+
var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
|
2241
|
+
|
2242
|
+
AutoDetachObserverPrototype.next = function (value) {
|
2243
|
+
var noError = false;
|
2244
|
+
try {
|
2245
|
+
this.observer.onNext(value);
|
2246
|
+
noError = true;
|
2247
|
+
} catch (e) {
|
2248
|
+
throw e;
|
2249
|
+
} finally {
|
2250
|
+
if (!noError) {
|
2251
|
+
this.dispose();
|
2252
|
+
}
|
2253
|
+
}
|
2254
|
+
};
|
2255
|
+
|
2256
|
+
AutoDetachObserverPrototype.error = function (exn) {
|
2257
|
+
try {
|
2258
|
+
this.observer.onError(exn);
|
2259
|
+
} catch (e) {
|
2260
|
+
throw e;
|
2261
|
+
} finally {
|
2262
|
+
this.dispose();
|
2263
|
+
}
|
2264
|
+
};
|
2265
|
+
|
2266
|
+
AutoDetachObserverPrototype.completed = function () {
|
2267
|
+
try {
|
2268
|
+
this.observer.onCompleted();
|
2269
|
+
} catch (e) {
|
2270
|
+
throw e;
|
2271
|
+
} finally {
|
2272
|
+
this.dispose();
|
2273
|
+
}
|
2274
|
+
};
|
2275
|
+
|
2276
|
+
AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
|
2277
|
+
AutoDetachObserverPrototype.getDisposable = function (value) { return this.m.getDisposable(); };
|
2278
|
+
/* @private */
|
2279
|
+
AutoDetachObserverPrototype.disposable = function (value) {
|
2280
|
+
return arguments.length ? this.getDisposable() : setDisposable(value);
|
2281
|
+
};
|
2282
|
+
|
2283
|
+
AutoDetachObserverPrototype.dispose = function () {
|
2284
|
+
_super.prototype.dispose.call(this);
|
2285
|
+
this.m.dispose();
|
2286
|
+
};
|
2287
|
+
|
2288
|
+
return AutoDetachObserver;
|
2289
|
+
}(AbstractObserver));
|
2290
|
+
|
2291
|
+
/** @private */
|
2292
|
+
var GroupedObservable = (function (_super) {
|
2293
|
+
inherits(GroupedObservable, _super);
|
2294
|
+
|
2295
|
+
function subscribe(observer) {
|
2296
|
+
return this.underlyingObservable.subscribe(observer);
|
2297
|
+
}
|
2298
|
+
|
2299
|
+
/**
|
2300
|
+
* @constructor
|
2301
|
+
* @private
|
2302
|
+
*/
|
2303
|
+
function GroupedObservable(key, underlyingObservable, mergedDisposable) {
|
2304
|
+
_super.call(this, subscribe);
|
2305
|
+
this.key = key;
|
2306
|
+
this.underlyingObservable = !mergedDisposable ?
|
2307
|
+
underlyingObservable :
|
2308
|
+
new AnonymousObservable(function (observer) {
|
2309
|
+
return new CompositeDisposable(mergedDisposable.getDisposable(), underlyingObservable.subscribe(observer));
|
2310
|
+
});
|
2311
|
+
}
|
2312
|
+
|
2313
|
+
return GroupedObservable;
|
2314
|
+
}(Observable));
|
2315
|
+
|
2316
|
+
/** @private */
|
2317
|
+
var InnerSubscription = function (subject, observer) {
|
2318
|
+
this.subject = subject;
|
2319
|
+
this.observer = observer;
|
2320
|
+
};
|
2321
|
+
|
2322
|
+
/**
|
2323
|
+
* @private
|
2324
|
+
* @memberOf InnerSubscription
|
2325
|
+
*/
|
2326
|
+
InnerSubscription.prototype.dispose = function () {
|
2327
|
+
if (!this.subject.isDisposed && this.observer !== null) {
|
2328
|
+
var idx = this.subject.observers.indexOf(this.observer);
|
2329
|
+
this.subject.observers.splice(idx, 1);
|
2330
|
+
this.observer = null;
|
2331
|
+
}
|
2332
|
+
};
|
2333
|
+
|
2334
|
+
/**
|
2335
|
+
* Represents an object that is both an observable sequence as well as an observer.
|
2336
|
+
* Each notification is broadcasted to all subscribed observers.
|
2337
|
+
*/
|
2338
|
+
var Subject = Rx.Subject = (function (_super) {
|
2339
|
+
function subscribe(observer) {
|
2340
|
+
checkDisposed.call(this);
|
2341
|
+
if (!this.isStopped) {
|
2342
|
+
this.observers.push(observer);
|
2343
|
+
return new InnerSubscription(this, observer);
|
2344
|
+
}
|
2345
|
+
if (this.exception) {
|
2346
|
+
observer.onError(this.exception);
|
2347
|
+
return disposableEmpty;
|
2348
|
+
}
|
2349
|
+
observer.onCompleted();
|
2350
|
+
return disposableEmpty;
|
2351
|
+
}
|
2352
|
+
|
2353
|
+
inherits(Subject, _super);
|
2354
|
+
|
2355
|
+
/**
|
2356
|
+
* Creates a subject.
|
2357
|
+
* @constructor
|
2358
|
+
*/
|
2359
|
+
function Subject() {
|
2360
|
+
_super.call(this, subscribe);
|
2361
|
+
this.isDisposed = false,
|
2362
|
+
this.isStopped = false,
|
2363
|
+
this.observers = [];
|
2364
|
+
}
|
2365
|
+
|
2366
|
+
addProperties(Subject.prototype, Observer, {
|
2367
|
+
/**
|
2368
|
+
* Indicates whether the subject has observers subscribed to it.
|
2369
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
2370
|
+
*/
|
2371
|
+
hasObservers: function () {
|
2372
|
+
return this.observers.length > 0;
|
2373
|
+
},
|
2374
|
+
/**
|
2375
|
+
* Notifies all subscribed observers about the end of the sequence.
|
2376
|
+
*/
|
2377
|
+
onCompleted: function () {
|
2378
|
+
checkDisposed.call(this);
|
2379
|
+
if (!this.isStopped) {
|
2380
|
+
var os = this.observers.slice(0);
|
2381
|
+
this.isStopped = true;
|
2382
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2383
|
+
os[i].onCompleted();
|
2384
|
+
}
|
2385
|
+
|
2386
|
+
this.observers = [];
|
2387
|
+
}
|
2388
|
+
},
|
2389
|
+
/**
|
2390
|
+
* Notifies all subscribed observers about the exception.
|
2391
|
+
* @param {Mixed} error The exception to send to all observers.
|
2392
|
+
*/
|
2393
|
+
onError: function (exception) {
|
2394
|
+
checkDisposed.call(this);
|
2395
|
+
if (!this.isStopped) {
|
2396
|
+
var os = this.observers.slice(0);
|
2397
|
+
this.isStopped = true;
|
2398
|
+
this.exception = exception;
|
2399
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2400
|
+
os[i].onError(exception);
|
2401
|
+
}
|
2402
|
+
|
2403
|
+
this.observers = [];
|
2404
|
+
}
|
2405
|
+
},
|
2406
|
+
/**
|
2407
|
+
* Notifies all subscribed observers about the arrival of the specified element in the sequence.
|
2408
|
+
* @param {Mixed} value The value to send to all observers.
|
2409
|
+
*/
|
2410
|
+
onNext: function (value) {
|
2411
|
+
checkDisposed.call(this);
|
2412
|
+
if (!this.isStopped) {
|
2413
|
+
var os = this.observers.slice(0);
|
2414
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2415
|
+
os[i].onNext(value);
|
2416
|
+
}
|
2417
|
+
}
|
2418
|
+
},
|
2419
|
+
/**
|
2420
|
+
* Unsubscribe all observers and release resources.
|
2421
|
+
*/
|
2422
|
+
dispose: function () {
|
2423
|
+
this.isDisposed = true;
|
2424
|
+
this.observers = null;
|
2425
|
+
}
|
2426
|
+
});
|
2427
|
+
|
2428
|
+
/**
|
2429
|
+
* Creates a subject from the specified observer and observable.
|
2430
|
+
* @param {Observer} observer The observer used to send messages to the subject.
|
2431
|
+
* @param {Observable} observable The observable used to subscribe to messages sent from the subject.
|
2432
|
+
* @returns {Subject} Subject implemented using the given observer and observable.
|
2433
|
+
*/
|
2434
|
+
Subject.create = function (observer, observable) {
|
2435
|
+
return new AnonymousSubject(observer, observable);
|
2436
|
+
};
|
2437
|
+
|
2438
|
+
return Subject;
|
2439
|
+
}(Observable));
|
2440
|
+
|
2441
|
+
/**
|
2442
|
+
* Represents the result of an asynchronous operation.
|
2443
|
+
* The last value before the OnCompleted notification, or the error received through OnError, is sent to all subscribed observers.
|
2444
|
+
*/
|
2445
|
+
var AsyncSubject = Rx.AsyncSubject = (function (_super) {
|
2446
|
+
|
2447
|
+
function subscribe(observer) {
|
2448
|
+
checkDisposed.call(this);
|
2449
|
+
|
2450
|
+
if (!this.isStopped) {
|
2451
|
+
this.observers.push(observer);
|
2452
|
+
return new InnerSubscription(this, observer);
|
2453
|
+
}
|
2454
|
+
|
2455
|
+
var ex = this.exception,
|
2456
|
+
hv = this.hasValue,
|
2457
|
+
v = this.value;
|
2458
|
+
|
2459
|
+
if (ex) {
|
2460
|
+
observer.onError(ex);
|
2461
|
+
} else if (hv) {
|
2462
|
+
observer.onNext(v);
|
2463
|
+
observer.onCompleted();
|
2464
|
+
} else {
|
2465
|
+
observer.onCompleted();
|
2466
|
+
}
|
2467
|
+
|
2468
|
+
return disposableEmpty;
|
2469
|
+
}
|
2470
|
+
|
2471
|
+
inherits(AsyncSubject, _super);
|
2472
|
+
|
2473
|
+
/**
|
2474
|
+
* Creates a subject that can only receive one value and that value is cached for all future observations.
|
2475
|
+
* @constructor
|
2476
|
+
*/
|
2477
|
+
function AsyncSubject() {
|
2478
|
+
_super.call(this, subscribe);
|
2479
|
+
|
2480
|
+
this.isDisposed = false;
|
2481
|
+
this.isStopped = false;
|
2482
|
+
this.value = null;
|
2483
|
+
this.hasValue = false;
|
2484
|
+
this.observers = [];
|
2485
|
+
this.exception = null;
|
2486
|
+
}
|
2487
|
+
|
2488
|
+
addProperties(AsyncSubject.prototype, Observer, {
|
2489
|
+
/**
|
2490
|
+
* Indicates whether the subject has observers subscribed to it.
|
2491
|
+
* @returns {Boolean} Indicates whether the subject has observers subscribed to it.
|
2492
|
+
*/
|
2493
|
+
hasObservers: function () {
|
2494
|
+
checkDisposed.call(this);
|
2495
|
+
return this.observers.length > 0;
|
2496
|
+
},
|
2497
|
+
/**
|
2498
|
+
* Notifies all subscribed observers about the end of the sequence, also causing the last received value to be sent out (if any).
|
2499
|
+
*/
|
2500
|
+
onCompleted: function () {
|
2501
|
+
var o, i, len;
|
2502
|
+
checkDisposed.call(this);
|
2503
|
+
if (!this.isStopped) {
|
2504
|
+
this.isStopped = true;
|
2505
|
+
var os = this.observers.slice(0),
|
2506
|
+
v = this.value,
|
2507
|
+
hv = this.hasValue;
|
2508
|
+
|
2509
|
+
if (hv) {
|
2510
|
+
for (i = 0, len = os.length; i < len; i++) {
|
2511
|
+
o = os[i];
|
2512
|
+
o.onNext(v);
|
2513
|
+
o.onCompleted();
|
2514
|
+
}
|
2515
|
+
} else {
|
2516
|
+
for (i = 0, len = os.length; i < len; i++) {
|
2517
|
+
os[i].onCompleted();
|
2518
|
+
}
|
2519
|
+
}
|
2520
|
+
|
2521
|
+
this.observers = [];
|
2522
|
+
}
|
2523
|
+
},
|
2524
|
+
/**
|
2525
|
+
* Notifies all subscribed observers about the exception.
|
2526
|
+
* @param {Mixed} error The exception to send to all observers.
|
2527
|
+
*/
|
2528
|
+
onError: function (exception) {
|
2529
|
+
checkDisposed.call(this);
|
2530
|
+
if (!this.isStopped) {
|
2531
|
+
var os = this.observers.slice(0);
|
2532
|
+
this.isStopped = true;
|
2533
|
+
this.exception = exception;
|
2534
|
+
|
2535
|
+
for (var i = 0, len = os.length; i < len; i++) {
|
2536
|
+
os[i].onError(exception);
|
2537
|
+
}
|
2538
|
+
|
2539
|
+
this.observers = [];
|
2540
|
+
}
|
2541
|
+
},
|
2542
|
+
/**
|
2543
|
+
* Sends a value to the subject. The last value received before successful termination will be sent to all subscribed and future observers.
|
2544
|
+
* @param {Mixed} value The value to store in the subject.
|
2545
|
+
*/
|
2546
|
+
onNext: function (value) {
|
2547
|
+
checkDisposed.call(this);
|
2548
|
+
if (!this.isStopped) {
|
2549
|
+
this.value = value;
|
2550
|
+
this.hasValue = true;
|
2551
|
+
}
|
2552
|
+
},
|
2553
|
+
/**
|
2554
|
+
* Unsubscribe all observers and release resources.
|
2555
|
+
*/
|
2556
|
+
dispose: function () {
|
2557
|
+
this.isDisposed = true;
|
2558
|
+
this.observers = null;
|
2559
|
+
this.exception = null;
|
2560
|
+
this.value = null;
|
2561
|
+
}
|
2562
|
+
});
|
2563
|
+
|
2564
|
+
return AsyncSubject;
|
2565
|
+
}(Observable));
|
2566
|
+
|
2567
|
+
/** @private */
|
2568
|
+
var AnonymousSubject = (function (_super) {
|
2569
|
+
inherits(AnonymousSubject, _super);
|
2570
|
+
|
2571
|
+
function subscribe(observer) {
|
2572
|
+
return this.observable.subscribe(observer);
|
2573
|
+
}
|
2574
|
+
|
2575
|
+
/**
|
2576
|
+
* @private
|
2577
|
+
* @constructor
|
2578
|
+
*/
|
2579
|
+
function AnonymousSubject(observer, observable) {
|
2580
|
+
_super.call(this, subscribe);
|
2581
|
+
this.observer = observer;
|
2582
|
+
this.observable = observable;
|
2583
|
+
}
|
2584
|
+
|
2585
|
+
addProperties(AnonymousSubject.prototype, Observer, {
|
2586
|
+
/**
|
2587
|
+
* @private
|
2588
|
+
* @memberOf AnonymousSubject#
|
2589
|
+
*/
|
2590
|
+
onCompleted: function () {
|
2591
|
+
this.observer.onCompleted();
|
2592
|
+
},
|
2593
|
+
/**
|
2594
|
+
* @private
|
2595
|
+
* @memberOf AnonymousSubject#
|
2596
|
+
*/
|
2597
|
+
onError: function (exception) {
|
2598
|
+
this.observer.onError(exception);
|
2599
|
+
},
|
2600
|
+
/**
|
2601
|
+
* @private
|
2602
|
+
* @memberOf AnonymousSubject#
|
2603
|
+
*/
|
2604
|
+
onNext: function (value) {
|
2605
|
+
this.observer.onNext(value);
|
2606
|
+
}
|
2607
|
+
});
|
2608
|
+
|
2609
|
+
return AnonymousSubject;
|
2610
|
+
}(Observable));
|
2611
|
+
|
2612
|
+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
2613
|
+
root.Rx = Rx;
|
2614
|
+
|
2615
|
+
define(function() {
|
2616
|
+
return Rx;
|
2617
|
+
});
|
2618
|
+
} else if (freeExports && freeModule) {
|
2619
|
+
// in Node.js or RingoJS
|
2620
|
+
if (moduleExports) {
|
2621
|
+
(freeModule.exports = Rx).Rx = Rx;
|
2622
|
+
} else {
|
2623
|
+
freeExports.Rx = Rx;
|
2624
|
+
}
|
2625
|
+
} else {
|
2626
|
+
// in a browser or Rhino
|
2627
|
+
root.Rx = Rx;
|
2628
|
+
}
|
2629
|
+
}.call(this));
|