rxjs-rails 2.3.10 → 2.3.11

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