1 |
|
2 |
|
3 | ;(function (undefined) {
|
4 |
|
5 | var objectTypes = {
|
6 | 'function': true,
|
7 | 'object': true
|
8 | };
|
9 |
|
10 | function checkGlobal(value) {
|
11 | return (value && value.Object === Object) ? value : null;
|
12 | }
|
13 |
|
14 | var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
|
15 | var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
|
16 | var freeGlobal = checkGlobal(freeExports && freeModule && typeof global === 'object' && global);
|
17 | var freeSelf = checkGlobal(objectTypes[typeof self] && self);
|
18 | var freeWindow = checkGlobal(objectTypes[typeof window] && window);
|
19 | var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
|
20 | var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
|
21 | var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
|
22 |
|
23 | var Rx = {
|
24 | internals: {},
|
25 | config: {
|
26 | Promise: root.Promise
|
27 | },
|
28 | helpers: { }
|
29 | };
|
30 |
|
31 |
|
32 | var noop = Rx.helpers.noop = function () { },
|
33 | identity = Rx.helpers.identity = function (x) { return x; },
|
34 | defaultNow = Rx.helpers.defaultNow = Date.now,
|
35 | defaultComparer = Rx.helpers.defaultComparer = function (x, y) { return isEqual(x, y); },
|
36 | defaultSubComparer = Rx.helpers.defaultSubComparer = function (x, y) { return x > y ? 1 : (x < y ? -1 : 0); },
|
37 | defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
|
38 | defaultError = Rx.helpers.defaultError = function (err) { throw err; },
|
39 | isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.subscribe !== 'function' && typeof p.then === 'function'; },
|
40 | isFunction = Rx.helpers.isFunction = (function () {
|
41 |
|
42 | var isFn = function (value) {
|
43 | return typeof value == 'function' || false;
|
44 | };
|
45 |
|
46 |
|
47 | if (isFn(/x/)) {
|
48 | isFn = function(value) {
|
49 | return typeof value == 'function' && toString.call(value) == '[object Function]';
|
50 | };
|
51 | }
|
52 |
|
53 | return isFn;
|
54 | }());
|
55 |
|
56 | function cloneArray(arr) { for(var a = [], i = 0, len = arr.length; i < len; i++) { a.push(arr[i]); } return a;}
|
57 |
|
58 | var errorObj = {e: {}};
|
59 |
|
60 | function tryCatcherGen(tryCatchTarget) {
|
61 | return function tryCatcher() {
|
62 | try {
|
63 | return tryCatchTarget.apply(this, arguments);
|
64 | } catch (e) {
|
65 | errorObj.e = e;
|
66 | return errorObj;
|
67 | }
|
68 | };
|
69 | }
|
70 |
|
71 | var tryCatch = Rx.internals.tryCatch = function tryCatch(fn) {
|
72 | if (!isFunction(fn)) { throw new TypeError('fn must be a function'); }
|
73 | return tryCatcherGen(fn);
|
74 | };
|
75 |
|
76 | function thrower(e) {
|
77 | throw e;
|
78 | }
|
79 |
|
80 | Rx.config.longStackSupport = false;
|
81 | var hasStacks = false, stacks = tryCatch(function () { throw new Error(); })();
|
82 | hasStacks = !!stacks.e && !!stacks.e.stack;
|
83 |
|
84 |
|
85 | var rStartingLine = captureLine(), rFileName;
|
86 |
|
87 | var STACK_JUMP_SEPARATOR = 'From previous event:';
|
88 |
|
89 | function makeStackTraceLong(error, observable) {
|
90 |
|
91 |
|
92 | if (hasStacks &&
|
93 | observable.stack &&
|
94 | typeof error === 'object' &&
|
95 | error !== null &&
|
96 | error.stack &&
|
97 | error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
|
98 | ) {
|
99 | var stacks = [];
|
100 | for (var o = observable; !!o; o = o.source) {
|
101 | if (o.stack) {
|
102 | stacks.unshift(o.stack);
|
103 | }
|
104 | }
|
105 | stacks.unshift(error.stack);
|
106 |
|
107 | var concatedStacks = stacks.join('\n' + STACK_JUMP_SEPARATOR + '\n');
|
108 | error.stack = filterStackString(concatedStacks);
|
109 | }
|
110 | }
|
111 |
|
112 | function filterStackString(stackString) {
|
113 | var lines = stackString.split('\n'), desiredLines = [];
|
114 | for (var i = 0, len = lines.length; i < len; i++) {
|
115 | var line = lines[i];
|
116 |
|
117 | if (!isInternalFrame(line) && !isNodeFrame(line) && line) {
|
118 | desiredLines.push(line);
|
119 | }
|
120 | }
|
121 | return desiredLines.join('\n');
|
122 | }
|
123 |
|
124 | function isInternalFrame(stackLine) {
|
125 | var fileNameAndLineNumber = getFileNameAndLineNumber(stackLine);
|
126 | if (!fileNameAndLineNumber) {
|
127 | return false;
|
128 | }
|
129 | var fileName = fileNameAndLineNumber[0], lineNumber = fileNameAndLineNumber[1];
|
130 |
|
131 | return fileName === rFileName &&
|
132 | lineNumber >= rStartingLine &&
|
133 | lineNumber <= rEndingLine;
|
134 | }
|
135 |
|
136 | function isNodeFrame(stackLine) {
|
137 | return stackLine.indexOf('(module.js:') !== -1 ||
|
138 | stackLine.indexOf('(node.js:') !== -1;
|
139 | }
|
140 |
|
141 | function captureLine() {
|
142 | if (!hasStacks) { return; }
|
143 |
|
144 | try {
|
145 | throw new Error();
|
146 | } catch (e) {
|
147 | var lines = e.stack.split('\n');
|
148 | var firstLine = lines[0].indexOf('@') > 0 ? lines[1] : lines[2];
|
149 | var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
|
150 | if (!fileNameAndLineNumber) { return; }
|
151 |
|
152 | rFileName = fileNameAndLineNumber[0];
|
153 | return fileNameAndLineNumber[1];
|
154 | }
|
155 | }
|
156 |
|
157 | function getFileNameAndLineNumber(stackLine) {
|
158 |
|
159 | var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
|
160 | if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
|
161 |
|
162 |
|
163 | var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
|
164 | if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
|
165 |
|
166 |
|
167 | var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
|
168 | if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
|
169 | }
|
170 |
|
171 | var EmptyError = Rx.EmptyError = function() {
|
172 | this.message = 'Sequence contains no elements.';
|
173 | Error.call(this);
|
174 | };
|
175 | EmptyError.prototype = Object.create(Error.prototype);
|
176 | EmptyError.prototype.name = 'EmptyError';
|
177 |
|
178 | var ObjectDisposedError = Rx.ObjectDisposedError = function() {
|
179 | this.message = 'Object has been disposed';
|
180 | Error.call(this);
|
181 | };
|
182 | ObjectDisposedError.prototype = Object.create(Error.prototype);
|
183 | ObjectDisposedError.prototype.name = 'ObjectDisposedError';
|
184 |
|
185 | var ArgumentOutOfRangeError = Rx.ArgumentOutOfRangeError = function () {
|
186 | this.message = 'Argument out of range';
|
187 | Error.call(this);
|
188 | };
|
189 | ArgumentOutOfRangeError.prototype = Object.create(Error.prototype);
|
190 | ArgumentOutOfRangeError.prototype.name = 'ArgumentOutOfRangeError';
|
191 |
|
192 | var NotSupportedError = Rx.NotSupportedError = function (message) {
|
193 | this.message = message || 'This operation is not supported';
|
194 | Error.call(this);
|
195 | };
|
196 | NotSupportedError.prototype = Object.create(Error.prototype);
|
197 | NotSupportedError.prototype.name = 'NotSupportedError';
|
198 |
|
199 | var NotImplementedError = Rx.NotImplementedError = function (message) {
|
200 | this.message = message || 'This operation is not implemented';
|
201 | Error.call(this);
|
202 | };
|
203 | NotImplementedError.prototype = Object.create(Error.prototype);
|
204 | NotImplementedError.prototype.name = 'NotImplementedError';
|
205 |
|
206 | var notImplemented = Rx.helpers.notImplemented = function () {
|
207 | throw new NotImplementedError();
|
208 | };
|
209 |
|
210 | var notSupported = Rx.helpers.notSupported = function () {
|
211 | throw new NotSupportedError();
|
212 | };
|
213 |
|
214 |
|
215 | var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
|
216 | '_es6shim_iterator_';
|
217 |
|
218 | if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
|
219 | $iterator$ = '@@iterator';
|
220 | }
|
221 |
|
222 | var doneEnumerator = Rx.doneEnumerator = { done: true, value: undefined };
|
223 |
|
224 | var isIterable = Rx.helpers.isIterable = function (o) {
|
225 | return o && o[$iterator$] !== undefined;
|
226 | };
|
227 |
|
228 | var isArrayLike = Rx.helpers.isArrayLike = function (o) {
|
229 | return o && o.length !== undefined;
|
230 | };
|
231 |
|
232 | Rx.helpers.iterator = $iterator$;
|
233 |
|
234 | var bindCallback = Rx.internals.bindCallback = function (func, thisArg, argCount) {
|
235 | if (typeof thisArg === 'undefined') { return func; }
|
236 | switch(argCount) {
|
237 | case 0:
|
238 | return function() {
|
239 | return func.call(thisArg)
|
240 | };
|
241 | case 1:
|
242 | return function(arg) {
|
243 | return func.call(thisArg, arg);
|
244 | };
|
245 | case 2:
|
246 | return function(value, index) {
|
247 | return func.call(thisArg, value, index);
|
248 | };
|
249 | case 3:
|
250 | return function(value, index, collection) {
|
251 | return func.call(thisArg, value, index, collection);
|
252 | };
|
253 | }
|
254 |
|
255 | return function() {
|
256 | return func.apply(thisArg, arguments);
|
257 | };
|
258 | };
|
259 |
|
260 |
|
261 | var dontEnums = ['toString',
|
262 | 'toLocaleString',
|
263 | 'valueOf',
|
264 | 'hasOwnProperty',
|
265 | 'isPrototypeOf',
|
266 | 'propertyIsEnumerable',
|
267 | 'constructor'],
|
268 | dontEnumsLength = dontEnums.length;
|
269 |
|
270 | var argsTag = '[object Arguments]',
|
271 | arrayTag = '[object Array]',
|
272 | boolTag = '[object Boolean]',
|
273 | dateTag = '[object Date]',
|
274 | errorTag = '[object Error]',
|
275 | funcTag = '[object Function]',
|
276 | mapTag = '[object Map]',
|
277 | numberTag = '[object Number]',
|
278 | objectTag = '[object Object]',
|
279 | regexpTag = '[object RegExp]',
|
280 | setTag = '[object Set]',
|
281 | stringTag = '[object String]',
|
282 | weakMapTag = '[object WeakMap]';
|
283 |
|
284 | var arrayBufferTag = '[object ArrayBuffer]',
|
285 | float32Tag = '[object Float32Array]',
|
286 | float64Tag = '[object Float64Array]',
|
287 | int8Tag = '[object Int8Array]',
|
288 | int16Tag = '[object Int16Array]',
|
289 | int32Tag = '[object Int32Array]',
|
290 | uint8Tag = '[object Uint8Array]',
|
291 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
292 | uint16Tag = '[object Uint16Array]',
|
293 | uint32Tag = '[object Uint32Array]';
|
294 |
|
295 | var typedArrayTags = {};
|
296 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
297 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
298 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
299 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
300 | typedArrayTags[uint32Tag] = true;
|
301 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
302 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
303 | typedArrayTags[dateTag] = typedArrayTags[errorTag] =
|
304 | typedArrayTags[funcTag] = typedArrayTags[mapTag] =
|
305 | typedArrayTags[numberTag] = typedArrayTags[objectTag] =
|
306 | typedArrayTags[regexpTag] = typedArrayTags[setTag] =
|
307 | typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
308 |
|
309 | var objectProto = Object.prototype,
|
310 | hasOwnProperty = objectProto.hasOwnProperty,
|
311 | objToString = objectProto.toString,
|
312 | MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
313 |
|
314 | var keys = Object.keys || (function() {
|
315 | var hasOwnProperty = Object.prototype.hasOwnProperty,
|
316 | hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
|
317 | dontEnums = [
|
318 | 'toString',
|
319 | 'toLocaleString',
|
320 | 'valueOf',
|
321 | 'hasOwnProperty',
|
322 | 'isPrototypeOf',
|
323 | 'propertyIsEnumerable',
|
324 | 'constructor'
|
325 | ],
|
326 | dontEnumsLength = dontEnums.length;
|
327 |
|
328 | return function(obj) {
|
329 | if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
|
330 | throw new TypeError('Object.keys called on non-object');
|
331 | }
|
332 |
|
333 | var result = [], prop, i;
|
334 |
|
335 | for (prop in obj) {
|
336 | if (hasOwnProperty.call(obj, prop)) {
|
337 | result.push(prop);
|
338 | }
|
339 | }
|
340 |
|
341 | if (hasDontEnumBug) {
|
342 | for (i = 0; i < dontEnumsLength; i++) {
|
343 | if (hasOwnProperty.call(obj, dontEnums[i])) {
|
344 | result.push(dontEnums[i]);
|
345 | }
|
346 | }
|
347 | }
|
348 | return result;
|
349 | };
|
350 | }());
|
351 |
|
352 | function equalObjects(object, other, equalFunc, isLoose, stackA, stackB) {
|
353 | var objProps = keys(object),
|
354 | objLength = objProps.length,
|
355 | othProps = keys(other),
|
356 | othLength = othProps.length;
|
357 |
|
358 | if (objLength !== othLength && !isLoose) {
|
359 | return false;
|
360 | }
|
361 | var index = objLength, key;
|
362 | while (index--) {
|
363 | key = objProps[index];
|
364 | if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
|
365 | return false;
|
366 | }
|
367 | }
|
368 | var skipCtor = isLoose;
|
369 | while (++index < objLength) {
|
370 | key = objProps[index];
|
371 | var objValue = object[key],
|
372 | othValue = other[key],
|
373 | result;
|
374 |
|
375 | if (!(result === undefined ? equalFunc(objValue, othValue, isLoose, stackA, stackB) : result)) {
|
376 | return false;
|
377 | }
|
378 | skipCtor || (skipCtor = key === 'constructor');
|
379 | }
|
380 | if (!skipCtor) {
|
381 | var objCtor = object.constructor,
|
382 | othCtor = other.constructor;
|
383 |
|
384 | if (objCtor !== othCtor &&
|
385 | ('constructor' in object && 'constructor' in other) &&
|
386 | !(typeof objCtor === 'function' && objCtor instanceof objCtor &&
|
387 | typeof othCtor === 'function' && othCtor instanceof othCtor)) {
|
388 | return false;
|
389 | }
|
390 | }
|
391 | return true;
|
392 | }
|
393 |
|
394 | function equalByTag(object, other, tag) {
|
395 | switch (tag) {
|
396 | case boolTag:
|
397 | case dateTag:
|
398 | return +object === +other;
|
399 |
|
400 | case errorTag:
|
401 | return object.name === other.name && object.message === other.message;
|
402 |
|
403 | case numberTag:
|
404 | return (object !== +object) ?
|
405 | other !== +other :
|
406 | object === +other;
|
407 |
|
408 | case regexpTag:
|
409 | case stringTag:
|
410 | return object === (other + '');
|
411 | }
|
412 | return false;
|
413 | }
|
414 |
|
415 | var isObject = Rx.internals.isObject = function(value) {
|
416 | var type = typeof value;
|
417 | return !!value && (type === 'object' || type === 'function');
|
418 | };
|
419 |
|
420 | function isObjectLike(value) {
|
421 | return !!value && typeof value === 'object';
|
422 | }
|
423 |
|
424 | function isLength(value) {
|
425 | return typeof value === 'number' && value > -1 && value % 1 === 0 && value <= MAX_SAFE_INTEGER;
|
426 | }
|
427 |
|
428 | var isHostObject = (function() {
|
429 | try {
|
430 | Object({ 'toString': 0 } + '');
|
431 | } catch(e) {
|
432 | return function() { return false; };
|
433 | }
|
434 | return function(value) {
|
435 | return typeof value.toString !== 'function' && typeof (value + '') === 'string';
|
436 | };
|
437 | }());
|
438 |
|
439 | function isTypedArray(value) {
|
440 | return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
|
441 | }
|
442 |
|
443 | var isArray = Array.isArray || function(value) {
|
444 | return isObjectLike(value) && isLength(value.length) && objToString.call(value) === arrayTag;
|
445 | };
|
446 |
|
447 | function arraySome (array, predicate) {
|
448 | var index = -1,
|
449 | length = array.length;
|
450 |
|
451 | while (++index < length) {
|
452 | if (predicate(array[index], index, array)) {
|
453 | return true;
|
454 | }
|
455 | }
|
456 | return false;
|
457 | }
|
458 |
|
459 | function equalArrays(array, other, equalFunc, isLoose, stackA, stackB) {
|
460 | var index = -1,
|
461 | arrLength = array.length,
|
462 | othLength = other.length;
|
463 |
|
464 | if (arrLength !== othLength && !(isLoose && othLength > arrLength)) {
|
465 | return false;
|
466 | }
|
467 |
|
468 | while (++index < arrLength) {
|
469 | var arrValue = array[index],
|
470 | othValue = other[index],
|
471 | result;
|
472 |
|
473 | if (result !== undefined) {
|
474 | if (result) {
|
475 | continue;
|
476 | }
|
477 | return false;
|
478 | }
|
479 |
|
480 | if (isLoose) {
|
481 | if (!arraySome(other, function(othValue) {
|
482 | return arrValue === othValue || equalFunc(arrValue, othValue, isLoose, stackA, stackB);
|
483 | })) {
|
484 | return false;
|
485 | }
|
486 | } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, isLoose, stackA, stackB))) {
|
487 | return false;
|
488 | }
|
489 | }
|
490 | return true;
|
491 | }
|
492 |
|
493 | function baseIsEqualDeep(object, other, equalFunc, isLoose, stackA, stackB) {
|
494 | var objIsArr = isArray(object),
|
495 | othIsArr = isArray(other),
|
496 | objTag = arrayTag,
|
497 | othTag = arrayTag;
|
498 |
|
499 | if (!objIsArr) {
|
500 | objTag = objToString.call(object);
|
501 | if (objTag === argsTag) {
|
502 | objTag = objectTag;
|
503 | } else if (objTag !== objectTag) {
|
504 | objIsArr = isTypedArray(object);
|
505 | }
|
506 | }
|
507 | if (!othIsArr) {
|
508 | othTag = objToString.call(other);
|
509 | if (othTag === argsTag) {
|
510 | othTag = objectTag;
|
511 | }
|
512 | }
|
513 | var objIsObj = objTag === objectTag && !isHostObject(object),
|
514 | othIsObj = othTag === objectTag && !isHostObject(other),
|
515 | isSameTag = objTag === othTag;
|
516 |
|
517 | if (isSameTag && !(objIsArr || objIsObj)) {
|
518 | return equalByTag(object, other, objTag);
|
519 | }
|
520 | if (!isLoose) {
|
521 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
522 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
523 |
|
524 | if (objIsWrapped || othIsWrapped) {
|
525 | return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, isLoose, stackA, stackB);
|
526 | }
|
527 | }
|
528 | if (!isSameTag) {
|
529 | return false;
|
530 | }
|
531 |
|
532 |
|
533 | stackA || (stackA = []);
|
534 | stackB || (stackB = []);
|
535 |
|
536 | var length = stackA.length;
|
537 | while (length--) {
|
538 | if (stackA[length] === object) {
|
539 | return stackB[length] === other;
|
540 | }
|
541 | }
|
542 |
|
543 | stackA.push(object);
|
544 | stackB.push(other);
|
545 |
|
546 | var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, isLoose, stackA, stackB);
|
547 |
|
548 | stackA.pop();
|
549 | stackB.pop();
|
550 |
|
551 | return result;
|
552 | }
|
553 |
|
554 | function baseIsEqual(value, other, isLoose, stackA, stackB) {
|
555 | if (value === other) {
|
556 | return true;
|
557 | }
|
558 | if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
559 | return value !== value && other !== other;
|
560 | }
|
561 | return baseIsEqualDeep(value, other, baseIsEqual, isLoose, stackA, stackB);
|
562 | }
|
563 |
|
564 | var isEqual = Rx.internals.isEqual = function (value, other) {
|
565 | return baseIsEqual(value, other);
|
566 | };
|
567 |
|
568 | var hasProp = {}.hasOwnProperty,
|
569 | slice = Array.prototype.slice;
|
570 |
|
571 | var inherits = Rx.internals.inherits = function (child, parent) {
|
572 | function __() { this.constructor = child; }
|
573 | __.prototype = parent.prototype;
|
574 | child.prototype = new __();
|
575 | };
|
576 |
|
577 | var addProperties = Rx.internals.addProperties = function (obj) {
|
578 | for(var sources = [], i = 1, len = arguments.length; i < len; i++) { sources.push(arguments[i]); }
|
579 | for (var idx = 0, ln = sources.length; idx < ln; idx++) {
|
580 | var source = sources[idx];
|
581 | for (var prop in source) {
|
582 | obj[prop] = source[prop];
|
583 | }
|
584 | }
|
585 | };
|
586 |
|
587 |
|
588 | var addRef = Rx.internals.addRef = function (xs, r) {
|
589 | return new AnonymousObservable(function (observer) {
|
590 | return new BinaryDisposable(r.getDisposable(), xs.subscribe(observer));
|
591 | });
|
592 | };
|
593 |
|
594 | function arrayInitialize(count, factory) {
|
595 | var a = new Array(count);
|
596 | for (var i = 0; i < count; i++) {
|
597 | a[i] = factory();
|
598 | }
|
599 | return a;
|
600 | }
|
601 |
|
602 | function IndexedItem(id, value) {
|
603 | this.id = id;
|
604 | this.value = value;
|
605 | }
|
606 |
|
607 | IndexedItem.prototype.compareTo = function (other) {
|
608 | var c = this.value.compareTo(other.value);
|
609 | c === 0 && (c = this.id - other.id);
|
610 | return c;
|
611 | };
|
612 |
|
613 | var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
|
614 | this.items = new Array(capacity);
|
615 | this.length = 0;
|
616 | };
|
617 |
|
618 | var priorityProto = PriorityQueue.prototype;
|
619 | priorityProto.isHigherPriority = function (left, right) {
|
620 | return this.items[left].compareTo(this.items[right]) < 0;
|
621 | };
|
622 |
|
623 | priorityProto.percolate = function (index) {
|
624 | if (index >= this.length || index < 0) { return; }
|
625 | var parent = index - 1 >> 1;
|
626 | if (parent < 0 || parent === index) { return; }
|
627 | if (this.isHigherPriority(index, parent)) {
|
628 | var temp = this.items[index];
|
629 | this.items[index] = this.items[parent];
|
630 | this.items[parent] = temp;
|
631 | this.percolate(parent);
|
632 | }
|
633 | };
|
634 |
|
635 | priorityProto.heapify = function (index) {
|
636 | +index || (index = 0);
|
637 | if (index >= this.length || index < 0) { return; }
|
638 | var left = 2 * index + 1,
|
639 | right = 2 * index + 2,
|
640 | first = index;
|
641 | if (left < this.length && this.isHigherPriority(left, first)) {
|
642 | first = left;
|
643 | }
|
644 | if (right < this.length && this.isHigherPriority(right, first)) {
|
645 | first = right;
|
646 | }
|
647 | if (first !== index) {
|
648 | var temp = this.items[index];
|
649 | this.items[index] = this.items[first];
|
650 | this.items[first] = temp;
|
651 | this.heapify(first);
|
652 | }
|
653 | };
|
654 |
|
655 | priorityProto.peek = function () { return this.items[0].value; };
|
656 |
|
657 | priorityProto.removeAt = function (index) {
|
658 | this.items[index] = this.items[--this.length];
|
659 | this.items[this.length] = undefined;
|
660 | this.heapify();
|
661 | };
|
662 |
|
663 | priorityProto.dequeue = function () {
|
664 | var result = this.peek();
|
665 | this.removeAt(0);
|
666 | return result;
|
667 | };
|
668 |
|
669 | priorityProto.enqueue = function (item) {
|
670 | var index = this.length++;
|
671 | this.items[index] = new IndexedItem(PriorityQueue.count++, item);
|
672 | this.percolate(index);
|
673 | };
|
674 |
|
675 | priorityProto.remove = function (item) {
|
676 | for (var i = 0; i < this.length; i++) {
|
677 | if (this.items[i].value === item) {
|
678 | this.removeAt(i);
|
679 | return true;
|
680 | }
|
681 | }
|
682 | return false;
|
683 | };
|
684 | PriorityQueue.count = 0;
|
685 |
|
686 | |
687 |
|
688 |
|
689 |
|
690 | var CompositeDisposable = Rx.CompositeDisposable = function () {
|
691 | var args = [], i, len;
|
692 | if (Array.isArray(arguments[0])) {
|
693 | args = arguments[0];
|
694 | } else {
|
695 | len = arguments.length;
|
696 | args = new Array(len);
|
697 | for(i = 0; i < len; i++) { args[i] = arguments[i]; }
|
698 | }
|
699 | this.disposables = args;
|
700 | this.isDisposed = false;
|
701 | this.length = args.length;
|
702 | };
|
703 |
|
704 | var CompositeDisposablePrototype = CompositeDisposable.prototype;
|
705 |
|
706 | |
707 |
|
708 |
|
709 |
|
710 | CompositeDisposablePrototype.add = function (item) {
|
711 | if (this.isDisposed) {
|
712 | item.dispose();
|
713 | } else {
|
714 | this.disposables.push(item);
|
715 | this.length++;
|
716 | }
|
717 | };
|
718 |
|
719 | |
720 |
|
721 |
|
722 |
|
723 |
|
724 | CompositeDisposablePrototype.remove = function (item) {
|
725 | var shouldDispose = false;
|
726 | if (!this.isDisposed) {
|
727 | var idx = this.disposables.indexOf(item);
|
728 | if (idx !== -1) {
|
729 | shouldDispose = true;
|
730 | this.disposables.splice(idx, 1);
|
731 | this.length--;
|
732 | item.dispose();
|
733 | }
|
734 | }
|
735 | return shouldDispose;
|
736 | };
|
737 |
|
738 | |
739 |
|
740 |
|
741 | CompositeDisposablePrototype.dispose = function () {
|
742 | if (!this.isDisposed) {
|
743 | this.isDisposed = true;
|
744 | var len = this.disposables.length, currentDisposables = new Array(len);
|
745 | for(var i = 0; i < len; i++) { currentDisposables[i] = this.disposables[i]; }
|
746 | this.disposables = [];
|
747 | this.length = 0;
|
748 |
|
749 | for (i = 0; i < len; i++) {
|
750 | currentDisposables[i].dispose();
|
751 | }
|
752 | }
|
753 | };
|
754 |
|
755 | |
756 |
|
757 |
|
758 |
|
759 | var Disposable = Rx.Disposable = function (action) {
|
760 | this.isDisposed = false;
|
761 | this.action = action || noop;
|
762 | };
|
763 |
|
764 |
|
765 | Disposable.prototype.dispose = function () {
|
766 | if (!this.isDisposed) {
|
767 | this.action();
|
768 | this.isDisposed = true;
|
769 | }
|
770 | };
|
771 |
|
772 | |
773 |
|
774 |
|
775 |
|
776 |
|
777 | var disposableCreate = Disposable.create = function (action) { return new Disposable(action); };
|
778 |
|
779 | |
780 |
|
781 |
|
782 | var disposableEmpty = Disposable.empty = { dispose: noop };
|
783 |
|
784 | |
785 |
|
786 |
|
787 |
|
788 |
|
789 | var isDisposable = Disposable.isDisposable = function (d) {
|
790 | return d && isFunction(d.dispose);
|
791 | };
|
792 |
|
793 | var checkDisposed = Disposable.checkDisposed = function (disposable) {
|
794 | if (disposable.isDisposed) { throw new ObjectDisposedError(); }
|
795 | };
|
796 |
|
797 | var disposableFixup = Disposable._fixup = function (result) {
|
798 | return isDisposable(result) ? result : disposableEmpty;
|
799 | };
|
800 |
|
801 |
|
802 | var SingleAssignmentDisposable = Rx.SingleAssignmentDisposable = function () {
|
803 | this.isDisposed = false;
|
804 | this.current = null;
|
805 | };
|
806 | SingleAssignmentDisposable.prototype.getDisposable = function () {
|
807 | return this.current;
|
808 | };
|
809 | SingleAssignmentDisposable.prototype.setDisposable = function (value) {
|
810 | if (this.current) { throw new Error('Disposable has already been assigned'); }
|
811 | var shouldDispose = this.isDisposed;
|
812 | !shouldDispose && (this.current = value);
|
813 | shouldDispose && value && value.dispose();
|
814 | };
|
815 | SingleAssignmentDisposable.prototype.dispose = function () {
|
816 | if (!this.isDisposed) {
|
817 | this.isDisposed = true;
|
818 | var old = this.current;
|
819 | this.current = null;
|
820 | old && old.dispose();
|
821 | }
|
822 | };
|
823 |
|
824 |
|
825 | var SerialDisposable = Rx.SerialDisposable = function () {
|
826 | this.isDisposed = false;
|
827 | this.current = null;
|
828 | };
|
829 | SerialDisposable.prototype.getDisposable = function () {
|
830 | return this.current;
|
831 | };
|
832 | SerialDisposable.prototype.setDisposable = function (value) {
|
833 | var shouldDispose = this.isDisposed;
|
834 | if (!shouldDispose) {
|
835 | var old = this.current;
|
836 | this.current = value;
|
837 | }
|
838 | old && old.dispose();
|
839 | shouldDispose && value && value.dispose();
|
840 | };
|
841 | SerialDisposable.prototype.dispose = function () {
|
842 | if (!this.isDisposed) {
|
843 | this.isDisposed = true;
|
844 | var old = this.current;
|
845 | this.current = null;
|
846 | }
|
847 | old && old.dispose();
|
848 | };
|
849 |
|
850 | var BinaryDisposable = Rx.BinaryDisposable = function (first, second) {
|
851 | this._first = first;
|
852 | this._second = second;
|
853 | this.isDisposed = false;
|
854 | };
|
855 |
|
856 | BinaryDisposable.prototype.dispose = function () {
|
857 | if (!this.isDisposed) {
|
858 | this.isDisposed = true;
|
859 | var old1 = this._first;
|
860 | this._first = null;
|
861 | old1 && old1.dispose();
|
862 | var old2 = this._second;
|
863 | this._second = null;
|
864 | old2 && old2.dispose();
|
865 | }
|
866 | };
|
867 |
|
868 | var NAryDisposable = Rx.NAryDisposable = function (disposables) {
|
869 | this._disposables = disposables;
|
870 | this.isDisposed = false;
|
871 | };
|
872 |
|
873 | NAryDisposable.prototype.dispose = function () {
|
874 | if (!this.isDisposed) {
|
875 | this.isDisposed = true;
|
876 | for (var i = 0, len = this._disposables.length; i < len; i++) {
|
877 | this._disposables[i].dispose();
|
878 | }
|
879 | this._disposables.length = 0;
|
880 | }
|
881 | };
|
882 |
|
883 | |
884 |
|
885 |
|
886 | var RefCountDisposable = Rx.RefCountDisposable = (function () {
|
887 |
|
888 | function InnerDisposable(disposable) {
|
889 | this.disposable = disposable;
|
890 | this.disposable.count++;
|
891 | this.isInnerDisposed = false;
|
892 | }
|
893 |
|
894 | InnerDisposable.prototype.dispose = function () {
|
895 | if (!this.disposable.isDisposed && !this.isInnerDisposed) {
|
896 | this.isInnerDisposed = true;
|
897 | this.disposable.count--;
|
898 | if (this.disposable.count === 0 && this.disposable.isPrimaryDisposed) {
|
899 | this.disposable.isDisposed = true;
|
900 | this.disposable.underlyingDisposable.dispose();
|
901 | }
|
902 | }
|
903 | };
|
904 |
|
905 | |
906 |
|
907 |
|
908 |
|
909 |
|
910 | function RefCountDisposable(disposable) {
|
911 | this.underlyingDisposable = disposable;
|
912 | this.isDisposed = false;
|
913 | this.isPrimaryDisposed = false;
|
914 | this.count = 0;
|
915 | }
|
916 |
|
917 | |
918 |
|
919 |
|
920 | RefCountDisposable.prototype.dispose = function () {
|
921 | if (!this.isDisposed && !this.isPrimaryDisposed) {
|
922 | this.isPrimaryDisposed = true;
|
923 | if (this.count === 0) {
|
924 | this.isDisposed = true;
|
925 | this.underlyingDisposable.dispose();
|
926 | }
|
927 | }
|
928 | };
|
929 |
|
930 | |
931 |
|
932 |
|
933 |
|
934 | RefCountDisposable.prototype.getDisposable = function () {
|
935 | return this.isDisposed ? disposableEmpty : new InnerDisposable(this);
|
936 | };
|
937 |
|
938 | return RefCountDisposable;
|
939 | })();
|
940 |
|
941 | function ScheduledDisposable(scheduler, disposable) {
|
942 | this.scheduler = scheduler;
|
943 | this.disposable = disposable;
|
944 | this.isDisposed = false;
|
945 | }
|
946 |
|
947 | function scheduleItem(s, self) {
|
948 | if (!self.isDisposed) {
|
949 | self.isDisposed = true;
|
950 | self.disposable.dispose();
|
951 | }
|
952 | }
|
953 |
|
954 | ScheduledDisposable.prototype.dispose = function () {
|
955 | this.scheduler.schedule(this, scheduleItem);
|
956 | };
|
957 |
|
958 | var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
|
959 | this.scheduler = scheduler;
|
960 | this.state = state;
|
961 | this.action = action;
|
962 | this.dueTime = dueTime;
|
963 | this.comparer = comparer || defaultSubComparer;
|
964 | this.disposable = new SingleAssignmentDisposable();
|
965 | };
|
966 |
|
967 | ScheduledItem.prototype.invoke = function () {
|
968 | this.disposable.setDisposable(this.invokeCore());
|
969 | };
|
970 |
|
971 | ScheduledItem.prototype.compareTo = function (other) {
|
972 | return this.comparer(this.dueTime, other.dueTime);
|
973 | };
|
974 |
|
975 | ScheduledItem.prototype.isCancelled = function () {
|
976 | return this.disposable.isDisposed;
|
977 | };
|
978 |
|
979 | ScheduledItem.prototype.invokeCore = function () {
|
980 | return disposableFixup(this.action(this.scheduler, this.state));
|
981 | };
|
982 |
|
983 |
|
984 | var Scheduler = Rx.Scheduler = (function () {
|
985 |
|
986 | function Scheduler() { }
|
987 |
|
988 |
|
989 | Scheduler.isScheduler = function (s) {
|
990 | return s instanceof Scheduler;
|
991 | };
|
992 |
|
993 | var schedulerProto = Scheduler.prototype;
|
994 |
|
995 | |
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 | schedulerProto.schedule = function (state, action) {
|
1002 | throw new NotImplementedError();
|
1003 | };
|
1004 |
|
1005 | |
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 | schedulerProto.scheduleFuture = function (state, dueTime, action) {
|
1013 | var dt = dueTime;
|
1014 | dt instanceof Date && (dt = dt - this.now());
|
1015 | dt = Scheduler.normalize(dt);
|
1016 |
|
1017 | if (dt === 0) { return this.schedule(state, action); }
|
1018 |
|
1019 | return this._scheduleFuture(state, dt, action);
|
1020 | };
|
1021 |
|
1022 | schedulerProto._scheduleFuture = function (state, dueTime, action) {
|
1023 | throw new NotImplementedError();
|
1024 | };
|
1025 |
|
1026 |
|
1027 | Scheduler.now = defaultNow;
|
1028 |
|
1029 |
|
1030 | Scheduler.prototype.now = defaultNow;
|
1031 |
|
1032 | |
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 | Scheduler.normalize = function (timeSpan) {
|
1038 | timeSpan < 0 && (timeSpan = 0);
|
1039 | return timeSpan;
|
1040 | };
|
1041 |
|
1042 | return Scheduler;
|
1043 | }());
|
1044 |
|
1045 | var normalizeTime = Scheduler.normalize, isScheduler = Scheduler.isScheduler;
|
1046 |
|
1047 | (function (schedulerProto) {
|
1048 |
|
1049 | function invokeRecImmediate(scheduler, pair) {
|
1050 | var state = pair[0], action = pair[1], group = new CompositeDisposable();
|
1051 | action(state, innerAction);
|
1052 | return group;
|
1053 |
|
1054 | function innerAction(state2) {
|
1055 | var isAdded = false, isDone = false;
|
1056 |
|
1057 | var d = scheduler.schedule(state2, scheduleWork);
|
1058 | if (!isDone) {
|
1059 | group.add(d);
|
1060 | isAdded = true;
|
1061 | }
|
1062 |
|
1063 | function scheduleWork(_, state3) {
|
1064 | if (isAdded) {
|
1065 | group.remove(d);
|
1066 | } else {
|
1067 | isDone = true;
|
1068 | }
|
1069 | action(state3, innerAction);
|
1070 | return disposableEmpty;
|
1071 | }
|
1072 | }
|
1073 | }
|
1074 |
|
1075 | function invokeRecDate(scheduler, pair) {
|
1076 | var state = pair[0], action = pair[1], group = new CompositeDisposable();
|
1077 | action(state, innerAction);
|
1078 | return group;
|
1079 |
|
1080 | function innerAction(state2, dueTime1) {
|
1081 | var isAdded = false, isDone = false;
|
1082 |
|
1083 | var d = scheduler.scheduleFuture(state2, dueTime1, scheduleWork);
|
1084 | if (!isDone) {
|
1085 | group.add(d);
|
1086 | isAdded = true;
|
1087 | }
|
1088 |
|
1089 | function scheduleWork(_, state3) {
|
1090 | if (isAdded) {
|
1091 | group.remove(d);
|
1092 | } else {
|
1093 | isDone = true;
|
1094 | }
|
1095 | action(state3, innerAction);
|
1096 | return disposableEmpty;
|
1097 | }
|
1098 | }
|
1099 | }
|
1100 |
|
1101 | |
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 | schedulerProto.scheduleRecursive = function (state, action) {
|
1108 | return this.schedule([state, action], invokeRecImmediate);
|
1109 | };
|
1110 |
|
1111 | |
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 | schedulerProto.scheduleRecursiveFuture = function (state, dueTime, action) {
|
1119 | return this.scheduleFuture([state, action], dueTime, invokeRecDate);
|
1120 | };
|
1121 |
|
1122 | }(Scheduler.prototype));
|
1123 |
|
1124 | (function (schedulerProto) {
|
1125 |
|
1126 | |
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 | schedulerProto.schedulePeriodic = function(state, period, action) {
|
1134 | if (typeof root.setInterval === 'undefined') { throw new NotSupportedError(); }
|
1135 | period = normalizeTime(period);
|
1136 | var s = state, id = root.setInterval(function () { s = action(s); }, period);
|
1137 | return disposableCreate(function () { root.clearInterval(id); });
|
1138 | };
|
1139 |
|
1140 | }(Scheduler.prototype));
|
1141 |
|
1142 | (function (schedulerProto) {
|
1143 | |
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 | schedulerProto.catchError = schedulerProto['catch'] = function (handler) {
|
1149 | return new CatchScheduler(this, handler);
|
1150 | };
|
1151 | }(Scheduler.prototype));
|
1152 |
|
1153 | var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
|
1154 | function createTick(self) {
|
1155 | return function tick(command, recurse) {
|
1156 | recurse(0, self._period);
|
1157 | var state = tryCatch(self._action)(self._state);
|
1158 | if (state === errorObj) {
|
1159 | self._cancel.dispose();
|
1160 | thrower(state.e);
|
1161 | }
|
1162 | self._state = state;
|
1163 | };
|
1164 | }
|
1165 |
|
1166 | function SchedulePeriodicRecursive(scheduler, state, period, action) {
|
1167 | this._scheduler = scheduler;
|
1168 | this._state = state;
|
1169 | this._period = period;
|
1170 | this._action = action;
|
1171 | }
|
1172 |
|
1173 | SchedulePeriodicRecursive.prototype.start = function () {
|
1174 | var d = new SingleAssignmentDisposable();
|
1175 | this._cancel = d;
|
1176 | d.setDisposable(this._scheduler.scheduleRecursiveFuture(0, this._period, createTick(this)));
|
1177 |
|
1178 | return d;
|
1179 | };
|
1180 |
|
1181 | return SchedulePeriodicRecursive;
|
1182 | }());
|
1183 |
|
1184 |
|
1185 | var ImmediateScheduler = (function (__super__) {
|
1186 | inherits(ImmediateScheduler, __super__);
|
1187 | function ImmediateScheduler() {
|
1188 | __super__.call(this);
|
1189 | }
|
1190 |
|
1191 | ImmediateScheduler.prototype.schedule = function (state, action) {
|
1192 | return disposableFixup(action(this, state));
|
1193 | };
|
1194 |
|
1195 | return ImmediateScheduler;
|
1196 | }(Scheduler));
|
1197 |
|
1198 | var immediateScheduler = Scheduler.immediate = new ImmediateScheduler();
|
1199 |
|
1200 | |
1201 |
|
1202 |
|
1203 | var CurrentThreadScheduler = (function (__super__) {
|
1204 | var queue;
|
1205 |
|
1206 | function runTrampoline () {
|
1207 | while (queue.length > 0) {
|
1208 | var item = queue.dequeue();
|
1209 | !item.isCancelled() && item.invoke();
|
1210 | }
|
1211 | }
|
1212 |
|
1213 | inherits(CurrentThreadScheduler, __super__);
|
1214 | function CurrentThreadScheduler() {
|
1215 | __super__.call(this);
|
1216 | }
|
1217 |
|
1218 | CurrentThreadScheduler.prototype.schedule = function (state, action) {
|
1219 | var si = new ScheduledItem(this, state, action, this.now());
|
1220 |
|
1221 | if (!queue) {
|
1222 | queue = new PriorityQueue(4);
|
1223 | queue.enqueue(si);
|
1224 |
|
1225 | var result = tryCatch(runTrampoline)();
|
1226 | queue = null;
|
1227 | if (result === errorObj) { thrower(result.e); }
|
1228 | } else {
|
1229 | queue.enqueue(si);
|
1230 | }
|
1231 | return si.disposable;
|
1232 | };
|
1233 |
|
1234 | CurrentThreadScheduler.prototype.scheduleRequired = function () { return !queue; };
|
1235 |
|
1236 | return CurrentThreadScheduler;
|
1237 | }(Scheduler));
|
1238 |
|
1239 | var currentThreadScheduler = Scheduler.currentThread = new CurrentThreadScheduler();
|
1240 |
|
1241 | var scheduleMethod, clearMethod;
|
1242 |
|
1243 | var localTimer = (function () {
|
1244 | var localSetTimeout, localClearTimeout = noop;
|
1245 | if (!!root.setTimeout) {
|
1246 | localSetTimeout = root.setTimeout;
|
1247 | localClearTimeout = root.clearTimeout;
|
1248 | } else if (!!root.WScript) {
|
1249 | localSetTimeout = function (fn, time) {
|
1250 | root.WScript.Sleep(time);
|
1251 | fn();
|
1252 | };
|
1253 | } else {
|
1254 | throw new NotSupportedError();
|
1255 | }
|
1256 |
|
1257 | return {
|
1258 | setTimeout: localSetTimeout,
|
1259 | clearTimeout: localClearTimeout
|
1260 | };
|
1261 | }());
|
1262 | var localSetTimeout = localTimer.setTimeout,
|
1263 | localClearTimeout = localTimer.clearTimeout;
|
1264 |
|
1265 | (function () {
|
1266 |
|
1267 | var nextHandle = 1, tasksByHandle = {}, currentlyRunning = false;
|
1268 |
|
1269 | clearMethod = function (handle) {
|
1270 | delete tasksByHandle[handle];
|
1271 | };
|
1272 |
|
1273 | function runTask(handle) {
|
1274 | if (currentlyRunning) {
|
1275 | localSetTimeout(function () { runTask(handle); }, 0);
|
1276 | } else {
|
1277 | var task = tasksByHandle[handle];
|
1278 | if (task) {
|
1279 | currentlyRunning = true;
|
1280 | var result = tryCatch(task)();
|
1281 | clearMethod(handle);
|
1282 | currentlyRunning = false;
|
1283 | if (result === errorObj) { thrower(result.e); }
|
1284 | }
|
1285 | }
|
1286 | }
|
1287 |
|
1288 | var reNative = new RegExp('^' +
|
1289 | String(toString)
|
1290 | .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
1291 | .replace(/toString| for [^\]]+/g, '.*?') + '$'
|
1292 | );
|
1293 |
|
1294 | var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
|
1295 | !reNative.test(setImmediate) && setImmediate;
|
1296 |
|
1297 | function postMessageSupported () {
|
1298 |
|
1299 | if (!root.postMessage || root.importScripts) { return false; }
|
1300 | var isAsync = false, oldHandler = root.onmessage;
|
1301 |
|
1302 | root.onmessage = function () { isAsync = true; };
|
1303 | root.postMessage('', '*');
|
1304 | root.onmessage = oldHandler;
|
1305 |
|
1306 | return isAsync;
|
1307 | }
|
1308 |
|
1309 |
|
1310 | if (isFunction(setImmediate)) {
|
1311 | scheduleMethod = function (action) {
|
1312 | var id = nextHandle++;
|
1313 | tasksByHandle[id] = action;
|
1314 | setImmediate(function () { runTask(id); });
|
1315 |
|
1316 | return id;
|
1317 | };
|
1318 | } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1319 | scheduleMethod = function (action) {
|
1320 | var id = nextHandle++;
|
1321 | tasksByHandle[id] = action;
|
1322 | process.nextTick(function () { runTask(id); });
|
1323 |
|
1324 | return id;
|
1325 | };
|
1326 | } else if (postMessageSupported()) {
|
1327 | var MSG_PREFIX = 'ms.rx.schedule' + Math.random();
|
1328 |
|
1329 | var onGlobalPostMessage = function (event) {
|
1330 |
|
1331 | if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
|
1332 | runTask(event.data.substring(MSG_PREFIX.length));
|
1333 | }
|
1334 | };
|
1335 |
|
1336 | root.addEventListener('message', onGlobalPostMessage, false);
|
1337 |
|
1338 | scheduleMethod = function (action) {
|
1339 | var id = nextHandle++;
|
1340 | tasksByHandle[id] = action;
|
1341 | root.postMessage(MSG_PREFIX + currentId, '*');
|
1342 | return id;
|
1343 | };
|
1344 | } else if (!!root.MessageChannel) {
|
1345 | var channel = new root.MessageChannel();
|
1346 |
|
1347 | channel.port1.onmessage = function (e) { runTask(e.data); };
|
1348 |
|
1349 | scheduleMethod = function (action) {
|
1350 | var id = nextHandle++;
|
1351 | tasksByHandle[id] = action;
|
1352 | channel.port2.postMessage(id);
|
1353 | return id;
|
1354 | };
|
1355 | } else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
|
1356 |
|
1357 | scheduleMethod = function (action) {
|
1358 | var scriptElement = root.document.createElement('script');
|
1359 | var id = nextHandle++;
|
1360 | tasksByHandle[id] = action;
|
1361 |
|
1362 | scriptElement.onreadystatechange = function () {
|
1363 | runTask(id);
|
1364 | scriptElement.onreadystatechange = null;
|
1365 | scriptElement.parentNode.removeChild(scriptElement);
|
1366 | scriptElement = null;
|
1367 | };
|
1368 | root.document.documentElement.appendChild(scriptElement);
|
1369 | return id;
|
1370 | };
|
1371 |
|
1372 | } else {
|
1373 | scheduleMethod = function (action) {
|
1374 | var id = nextHandle++;
|
1375 | tasksByHandle[id] = action;
|
1376 | localSetTimeout(function () {
|
1377 | runTask(id);
|
1378 | }, 0);
|
1379 |
|
1380 | return id;
|
1381 | };
|
1382 | }
|
1383 | }());
|
1384 |
|
1385 | |
1386 |
|
1387 |
|
1388 | var DefaultScheduler = (function (__super__) {
|
1389 | inherits(DefaultScheduler, __super__);
|
1390 | function DefaultScheduler() {
|
1391 | __super__.call(this);
|
1392 | }
|
1393 |
|
1394 | function scheduleAction(disposable, action, scheduler, state) {
|
1395 | return function schedule() {
|
1396 | disposable.setDisposable(Disposable._fixup(action(scheduler, state)));
|
1397 | };
|
1398 | }
|
1399 |
|
1400 | function ClearDisposable(id) {
|
1401 | this._id = id;
|
1402 | this.isDisposed = false;
|
1403 | }
|
1404 |
|
1405 | ClearDisposable.prototype.dispose = function () {
|
1406 | if (!this.isDisposed) {
|
1407 | this.isDisposed = true;
|
1408 | clearMethod(this._id);
|
1409 | }
|
1410 | };
|
1411 |
|
1412 | function LocalClearDisposable(id) {
|
1413 | this._id = id;
|
1414 | this.isDisposed = false;
|
1415 | }
|
1416 |
|
1417 | LocalClearDisposable.prototype.dispose = function () {
|
1418 | if (!this.isDisposed) {
|
1419 | this.isDisposed = true;
|
1420 | localClearTimeout(this._id);
|
1421 | }
|
1422 | };
|
1423 |
|
1424 | DefaultScheduler.prototype.schedule = function (state, action) {
|
1425 | var disposable = new SingleAssignmentDisposable(),
|
1426 | id = scheduleMethod(scheduleAction(disposable, action, this, state));
|
1427 | return new BinaryDisposable(disposable, new ClearDisposable(id));
|
1428 | };
|
1429 |
|
1430 | DefaultScheduler.prototype._scheduleFuture = function (state, dueTime, action) {
|
1431 | if (dueTime === 0) { return this.schedule(state, action); }
|
1432 | var disposable = new SingleAssignmentDisposable(),
|
1433 | id = localSetTimeout(scheduleAction(disposable, action, this, state), dueTime);
|
1434 | return new BinaryDisposable(disposable, new LocalClearDisposable(id));
|
1435 | };
|
1436 |
|
1437 | return DefaultScheduler;
|
1438 | }(Scheduler));
|
1439 |
|
1440 | var defaultScheduler = Scheduler['default'] = Scheduler.async = new DefaultScheduler();
|
1441 |
|
1442 | var CatchScheduler = (function (__super__) {
|
1443 | inherits(CatchScheduler, __super__);
|
1444 |
|
1445 | function CatchScheduler(scheduler, handler) {
|
1446 | this._scheduler = scheduler;
|
1447 | this._handler = handler;
|
1448 | this._recursiveOriginal = null;
|
1449 | this._recursiveWrapper = null;
|
1450 | __super__.call(this);
|
1451 | }
|
1452 |
|
1453 | CatchScheduler.prototype.schedule = function (state, action) {
|
1454 | return this._scheduler.schedule(state, this._wrap(action));
|
1455 | };
|
1456 |
|
1457 | CatchScheduler.prototype._scheduleFuture = function (state, dueTime, action) {
|
1458 | return this._scheduler.schedule(state, dueTime, this._wrap(action));
|
1459 | };
|
1460 |
|
1461 | CatchScheduler.prototype.now = function () { return this._scheduler.now(); };
|
1462 |
|
1463 | CatchScheduler.prototype._clone = function (scheduler) {
|
1464 | return new CatchScheduler(scheduler, this._handler);
|
1465 | };
|
1466 |
|
1467 | CatchScheduler.prototype._wrap = function (action) {
|
1468 | var parent = this;
|
1469 | return function (self, state) {
|
1470 | var res = tryCatch(action)(parent._getRecursiveWrapper(self), state);
|
1471 | if (res === errorObj) {
|
1472 | if (!parent._handler(res.e)) { thrower(res.e); }
|
1473 | return disposableEmpty;
|
1474 | }
|
1475 | return disposableFixup(res);
|
1476 | };
|
1477 | };
|
1478 |
|
1479 | CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
|
1480 | if (this._recursiveOriginal !== scheduler) {
|
1481 | this._recursiveOriginal = scheduler;
|
1482 | var wrapper = this._clone(scheduler);
|
1483 | wrapper._recursiveOriginal = scheduler;
|
1484 | wrapper._recursiveWrapper = wrapper;
|
1485 | this._recursiveWrapper = wrapper;
|
1486 | }
|
1487 | return this._recursiveWrapper;
|
1488 | };
|
1489 |
|
1490 | CatchScheduler.prototype.schedulePeriodic = function (state, period, action) {
|
1491 | var self = this, failed = false, d = new SingleAssignmentDisposable();
|
1492 |
|
1493 | d.setDisposable(this._scheduler.schedulePeriodic(state, period, function (state1) {
|
1494 | if (failed) { return null; }
|
1495 | var res = tryCatch(action)(state1);
|
1496 | if (res === errorObj) {
|
1497 | failed = true;
|
1498 | if (!self._handler(res.e)) { thrower(res.e); }
|
1499 | d.dispose();
|
1500 | return null;
|
1501 | }
|
1502 | return res;
|
1503 | }));
|
1504 |
|
1505 | return d;
|
1506 | };
|
1507 |
|
1508 | return CatchScheduler;
|
1509 | }(Scheduler));
|
1510 |
|
1511 | |
1512 |
|
1513 |
|
1514 | var Notification = Rx.Notification = (function () {
|
1515 | function Notification() {
|
1516 |
|
1517 | }
|
1518 |
|
1519 | Notification.prototype._accept = function (onNext, onError, onCompleted) {
|
1520 | throw new NotImplementedError();
|
1521 | };
|
1522 |
|
1523 | Notification.prototype._acceptObserver = function (onNext, onError, onCompleted) {
|
1524 | throw new NotImplementedError();
|
1525 | };
|
1526 |
|
1527 | |
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 | Notification.prototype.accept = function (observerOrOnNext, onError, onCompleted) {
|
1535 | return observerOrOnNext && typeof observerOrOnNext === 'object' ?
|
1536 | this._acceptObserver(observerOrOnNext) :
|
1537 | this._accept(observerOrOnNext, onError, onCompleted);
|
1538 | };
|
1539 |
|
1540 | |
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 | Notification.prototype.toObservable = function (scheduler) {
|
1548 | var self = this;
|
1549 | isScheduler(scheduler) || (scheduler = immediateScheduler);
|
1550 | return new AnonymousObservable(function (o) {
|
1551 | return scheduler.schedule(self, function (_, notification) {
|
1552 | notification._acceptObserver(o);
|
1553 | notification.kind === 'N' && o.onCompleted();
|
1554 | });
|
1555 | });
|
1556 | };
|
1557 |
|
1558 | return Notification;
|
1559 | })();
|
1560 |
|
1561 | var OnNextNotification = (function (__super__) {
|
1562 | inherits(OnNextNotification, __super__);
|
1563 | function OnNextNotification(value) {
|
1564 | this.value = value;
|
1565 | this.kind = 'N';
|
1566 | }
|
1567 |
|
1568 | OnNextNotification.prototype._accept = function (onNext) {
|
1569 | return onNext(this.value);
|
1570 | };
|
1571 |
|
1572 | OnNextNotification.prototype._acceptObserver = function (o) {
|
1573 | return o.onNext(this.value);
|
1574 | };
|
1575 |
|
1576 | OnNextNotification.prototype.toString = function () {
|
1577 | return 'OnNext(' + this.value + ')';
|
1578 | };
|
1579 |
|
1580 | return OnNextNotification;
|
1581 | }(Notification));
|
1582 |
|
1583 | var OnErrorNotification = (function (__super__) {
|
1584 | inherits(OnErrorNotification, __super__);
|
1585 | function OnErrorNotification(error) {
|
1586 | this.error = error;
|
1587 | this.kind = 'E';
|
1588 | }
|
1589 |
|
1590 | OnErrorNotification.prototype._accept = function (onNext, onError) {
|
1591 | return onError(this.error);
|
1592 | };
|
1593 |
|
1594 | OnErrorNotification.prototype._acceptObserver = function (o) {
|
1595 | return o.onError(this.error);
|
1596 | };
|
1597 |
|
1598 | OnErrorNotification.prototype.toString = function () {
|
1599 | return 'OnError(' + this.error + ')';
|
1600 | };
|
1601 |
|
1602 | return OnErrorNotification;
|
1603 | }(Notification));
|
1604 |
|
1605 | var OnCompletedNotification = (function (__super__) {
|
1606 | inherits(OnCompletedNotification, __super__);
|
1607 | function OnCompletedNotification() {
|
1608 | this.kind = 'C';
|
1609 | }
|
1610 |
|
1611 | OnCompletedNotification.prototype._accept = function (onNext, onError, onCompleted) {
|
1612 | return onCompleted();
|
1613 | };
|
1614 |
|
1615 | OnCompletedNotification.prototype._acceptObserver = function (o) {
|
1616 | return o.onCompleted();
|
1617 | };
|
1618 |
|
1619 | OnCompletedNotification.prototype.toString = function () {
|
1620 | return 'OnCompleted()';
|
1621 | };
|
1622 |
|
1623 | return OnCompletedNotification;
|
1624 | }(Notification));
|
1625 |
|
1626 | |
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 | var notificationCreateOnNext = Notification.createOnNext = function (value) {
|
1632 | return new OnNextNotification(value);
|
1633 | };
|
1634 |
|
1635 | |
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 | var notificationCreateOnError = Notification.createOnError = function (error) {
|
1641 | return new OnErrorNotification(error);
|
1642 | };
|
1643 |
|
1644 | |
1645 |
|
1646 |
|
1647 |
|
1648 | var notificationCreateOnCompleted = Notification.createOnCompleted = function () {
|
1649 | return new OnCompletedNotification();
|
1650 | };
|
1651 |
|
1652 | |
1653 |
|
1654 |
|
1655 | var Observer = Rx.Observer = function () { };
|
1656 |
|
1657 | |
1658 |
|
1659 |
|
1660 |
|
1661 | Observer.prototype.toNotifier = function () {
|
1662 | var observer = this;
|
1663 | return function (n) { return n.accept(observer); };
|
1664 | };
|
1665 |
|
1666 | |
1667 |
|
1668 |
|
1669 |
|
1670 | Observer.prototype.asObserver = function () {
|
1671 | var self = this;
|
1672 | return new AnonymousObserver(
|
1673 | function (x) { self.onNext(x); },
|
1674 | function (err) { self.onError(err); },
|
1675 | function () { self.onCompleted(); });
|
1676 | };
|
1677 |
|
1678 | |
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 | Observer.prototype.checked = function () { return new CheckedObserver(this); };
|
1684 |
|
1685 | |
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 | var observerCreate = Observer.create = function (onNext, onError, onCompleted) {
|
1693 | onNext || (onNext = noop);
|
1694 | onError || (onError = defaultError);
|
1695 | onCompleted || (onCompleted = noop);
|
1696 | return new AnonymousObserver(onNext, onError, onCompleted);
|
1697 | };
|
1698 |
|
1699 | |
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 | Observer.fromNotifier = function (handler, thisArg) {
|
1705 | var cb = bindCallback(handler, thisArg, 1);
|
1706 | return new AnonymousObserver(function (x) {
|
1707 | return cb(notificationCreateOnNext(x));
|
1708 | }, function (e) {
|
1709 | return cb(notificationCreateOnError(e));
|
1710 | }, function () {
|
1711 | return cb(notificationCreateOnCompleted());
|
1712 | });
|
1713 | };
|
1714 |
|
1715 | |
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 | Observer.prototype.notifyOn = function (scheduler) {
|
1721 | return new ObserveOnObserver(scheduler, this);
|
1722 | };
|
1723 |
|
1724 | Observer.prototype.makeSafe = function(disposable) {
|
1725 | return new AnonymousSafeObserver(this._onNext, this._onError, this._onCompleted, disposable);
|
1726 | };
|
1727 |
|
1728 | |
1729 |
|
1730 |
|
1731 |
|
1732 | var AbstractObserver = Rx.internals.AbstractObserver = (function (__super__) {
|
1733 | inherits(AbstractObserver, __super__);
|
1734 |
|
1735 | |
1736 |
|
1737 |
|
1738 | function AbstractObserver() {
|
1739 | this.isStopped = false;
|
1740 | }
|
1741 |
|
1742 |
|
1743 | AbstractObserver.prototype.next = notImplemented;
|
1744 | AbstractObserver.prototype.error = notImplemented;
|
1745 | AbstractObserver.prototype.completed = notImplemented;
|
1746 |
|
1747 | |
1748 |
|
1749 |
|
1750 |
|
1751 | AbstractObserver.prototype.onNext = function (value) {
|
1752 | !this.isStopped && this.next(value);
|
1753 | };
|
1754 |
|
1755 | |
1756 |
|
1757 |
|
1758 |
|
1759 | AbstractObserver.prototype.onError = function (error) {
|
1760 | if (!this.isStopped) {
|
1761 | this.isStopped = true;
|
1762 | this.error(error);
|
1763 | }
|
1764 | };
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 | AbstractObserver.prototype.onCompleted = function () {
|
1770 | if (!this.isStopped) {
|
1771 | this.isStopped = true;
|
1772 | this.completed();
|
1773 | }
|
1774 | };
|
1775 |
|
1776 | |
1777 |
|
1778 |
|
1779 | AbstractObserver.prototype.dispose = function () { this.isStopped = true; };
|
1780 |
|
1781 | AbstractObserver.prototype.fail = function (e) {
|
1782 | if (!this.isStopped) {
|
1783 | this.isStopped = true;
|
1784 | this.error(e);
|
1785 | return true;
|
1786 | }
|
1787 |
|
1788 | return false;
|
1789 | };
|
1790 |
|
1791 | return AbstractObserver;
|
1792 | }(Observer));
|
1793 |
|
1794 | |
1795 |
|
1796 |
|
1797 | var AnonymousObserver = Rx.AnonymousObserver = (function (__super__) {
|
1798 | inherits(AnonymousObserver, __super__);
|
1799 |
|
1800 | |
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 | function AnonymousObserver(onNext, onError, onCompleted) {
|
1807 | __super__.call(this);
|
1808 | this._onNext = onNext;
|
1809 | this._onError = onError;
|
1810 | this._onCompleted = onCompleted;
|
1811 | }
|
1812 |
|
1813 | |
1814 |
|
1815 |
|
1816 |
|
1817 | AnonymousObserver.prototype.next = function (value) {
|
1818 | this._onNext(value);
|
1819 | };
|
1820 |
|
1821 | |
1822 |
|
1823 |
|
1824 |
|
1825 | AnonymousObserver.prototype.error = function (error) {
|
1826 | this._onError(error);
|
1827 | };
|
1828 |
|
1829 | |
1830 |
|
1831 |
|
1832 | AnonymousObserver.prototype.completed = function () {
|
1833 | this._onCompleted();
|
1834 | };
|
1835 |
|
1836 | return AnonymousObserver;
|
1837 | }(AbstractObserver));
|
1838 |
|
1839 | var CheckedObserver = (function (__super__) {
|
1840 | inherits(CheckedObserver, __super__);
|
1841 |
|
1842 | function CheckedObserver(observer) {
|
1843 | __super__.call(this);
|
1844 | this._observer = observer;
|
1845 | this._state = 0;
|
1846 | }
|
1847 |
|
1848 | var CheckedObserverPrototype = CheckedObserver.prototype;
|
1849 |
|
1850 | CheckedObserverPrototype.onNext = function (value) {
|
1851 | this.checkAccess();
|
1852 | var res = tryCatch(this._observer.onNext).call(this._observer, value);
|
1853 | this._state = 0;
|
1854 | res === errorObj && thrower(res.e);
|
1855 | };
|
1856 |
|
1857 | CheckedObserverPrototype.onError = function (err) {
|
1858 | this.checkAccess();
|
1859 | var res = tryCatch(this._observer.onError).call(this._observer, err);
|
1860 | this._state = 2;
|
1861 | res === errorObj && thrower(res.e);
|
1862 | };
|
1863 |
|
1864 | CheckedObserverPrototype.onCompleted = function () {
|
1865 | this.checkAccess();
|
1866 | var res = tryCatch(this._observer.onCompleted).call(this._observer);
|
1867 | this._state = 2;
|
1868 | res === errorObj && thrower(res.e);
|
1869 | };
|
1870 |
|
1871 | CheckedObserverPrototype.checkAccess = function () {
|
1872 | if (this._state === 1) { throw new Error('Re-entrancy detected'); }
|
1873 | if (this._state === 2) { throw new Error('Observer completed'); }
|
1874 | if (this._state === 0) { this._state = 1; }
|
1875 | };
|
1876 |
|
1877 | return CheckedObserver;
|
1878 | }(Observer));
|
1879 |
|
1880 | var ScheduledObserver = Rx.internals.ScheduledObserver = (function (__super__) {
|
1881 | inherits(ScheduledObserver, __super__);
|
1882 |
|
1883 | function ScheduledObserver(scheduler, observer) {
|
1884 | __super__.call(this);
|
1885 | this.scheduler = scheduler;
|
1886 | this.observer = observer;
|
1887 | this.isAcquired = false;
|
1888 | this.hasFaulted = false;
|
1889 | this.queue = [];
|
1890 | this.disposable = new SerialDisposable();
|
1891 | }
|
1892 |
|
1893 | function enqueueNext(observer, x) { return function () { observer.onNext(x); }; }
|
1894 | function enqueueError(observer, e) { return function () { observer.onError(e); }; }
|
1895 | function enqueueCompleted(observer) { return function () { observer.onCompleted(); }; }
|
1896 |
|
1897 | ScheduledObserver.prototype.next = function (x) {
|
1898 | this.queue.push(enqueueNext(this.observer, x));
|
1899 | };
|
1900 |
|
1901 | ScheduledObserver.prototype.error = function (e) {
|
1902 | this.queue.push(enqueueError(this.observer, e));
|
1903 | };
|
1904 |
|
1905 | ScheduledObserver.prototype.completed = function () {
|
1906 | this.queue.push(enqueueCompleted(this.observer));
|
1907 | };
|
1908 |
|
1909 |
|
1910 | function scheduleMethod(state, recurse) {
|
1911 | var work;
|
1912 | if (state.queue.length > 0) {
|
1913 | work = state.queue.shift();
|
1914 | } else {
|
1915 | state.isAcquired = false;
|
1916 | return;
|
1917 | }
|
1918 | var res = tryCatch(work)();
|
1919 | if (res === errorObj) {
|
1920 | state.queue = [];
|
1921 | state.hasFaulted = true;
|
1922 | return thrower(res.e);
|
1923 | }
|
1924 | recurse(state);
|
1925 | }
|
1926 |
|
1927 | ScheduledObserver.prototype.ensureActive = function () {
|
1928 | var isOwner = false;
|
1929 | if (!this.hasFaulted && this.queue.length > 0) {
|
1930 | isOwner = !this.isAcquired;
|
1931 | this.isAcquired = true;
|
1932 | }
|
1933 | isOwner &&
|
1934 | this.disposable.setDisposable(this.scheduler.scheduleRecursive(this, scheduleMethod));
|
1935 | };
|
1936 |
|
1937 | ScheduledObserver.prototype.dispose = function () {
|
1938 | __super__.prototype.dispose.call(this);
|
1939 | this.disposable.dispose();
|
1940 | };
|
1941 |
|
1942 | return ScheduledObserver;
|
1943 | }(AbstractObserver));
|
1944 |
|
1945 | var ObserveOnObserver = (function (__super__) {
|
1946 | inherits(ObserveOnObserver, __super__);
|
1947 |
|
1948 | function ObserveOnObserver(scheduler, observer, cancel) {
|
1949 | __super__.call(this, scheduler, observer);
|
1950 | this._cancel = cancel;
|
1951 | }
|
1952 |
|
1953 | ObserveOnObserver.prototype.next = function (value) {
|
1954 | __super__.prototype.next.call(this, value);
|
1955 | this.ensureActive();
|
1956 | };
|
1957 |
|
1958 | ObserveOnObserver.prototype.error = function (e) {
|
1959 | __super__.prototype.error.call(this, e);
|
1960 | this.ensureActive();
|
1961 | };
|
1962 |
|
1963 | ObserveOnObserver.prototype.completed = function () {
|
1964 | __super__.prototype.completed.call(this);
|
1965 | this.ensureActive();
|
1966 | };
|
1967 |
|
1968 | ObserveOnObserver.prototype.dispose = function () {
|
1969 | __super__.prototype.dispose.call(this);
|
1970 | this._cancel && this._cancel.dispose();
|
1971 | this._cancel = null;
|
1972 | };
|
1973 |
|
1974 | return ObserveOnObserver;
|
1975 | })(ScheduledObserver);
|
1976 |
|
1977 | var observableProto;
|
1978 |
|
1979 | |
1980 |
|
1981 |
|
1982 | var Observable = Rx.Observable = (function () {
|
1983 |
|
1984 | function makeSubscribe(self, subscribe) {
|
1985 | return function (o) {
|
1986 | var oldOnError = o.onError;
|
1987 | o.onError = function (e) {
|
1988 | makeStackTraceLong(e, self);
|
1989 | oldOnError.call(o, e);
|
1990 | };
|
1991 |
|
1992 | return subscribe.call(self, o);
|
1993 | };
|
1994 | }
|
1995 |
|
1996 | function Observable() {
|
1997 | if (Rx.config.longStackSupport && hasStacks) {
|
1998 | var oldSubscribe = this._subscribe;
|
1999 | var e = tryCatch(thrower)(new Error()).e;
|
2000 | this.stack = e.stack.substring(e.stack.indexOf('\n') + 1);
|
2001 | this._subscribe = makeSubscribe(this, oldSubscribe);
|
2002 | }
|
2003 | }
|
2004 |
|
2005 | observableProto = Observable.prototype;
|
2006 |
|
2007 | |
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 | Observable.isObservable = function (o) {
|
2013 | return o && isFunction(o.subscribe);
|
2014 | };
|
2015 |
|
2016 | |
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 | observableProto.subscribe = observableProto.forEach = function (oOrOnNext, onError, onCompleted) {
|
2024 | return this._subscribe(typeof oOrOnNext === 'object' ?
|
2025 | oOrOnNext :
|
2026 | observerCreate(oOrOnNext, onError, onCompleted));
|
2027 | };
|
2028 |
|
2029 | |
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 | observableProto.subscribeOnNext = function (onNext, thisArg) {
|
2036 | return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
|
2037 | };
|
2038 |
|
2039 | |
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 | observableProto.subscribeOnError = function (onError, thisArg) {
|
2046 | return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
|
2047 | };
|
2048 |
|
2049 | |
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 | observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
|
2056 | return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
|
2057 | };
|
2058 |
|
2059 | return Observable;
|
2060 | })();
|
2061 |
|
2062 | var ObservableBase = Rx.ObservableBase = (function (__super__) {
|
2063 | inherits(ObservableBase, __super__);
|
2064 |
|
2065 | function fixSubscriber(subscriber) {
|
2066 | return subscriber && isFunction(subscriber.dispose) ? subscriber :
|
2067 | isFunction(subscriber) ? disposableCreate(subscriber) : disposableEmpty;
|
2068 | }
|
2069 |
|
2070 | function setDisposable(s, state) {
|
2071 | var ado = state[0], self = state[1];
|
2072 | var sub = tryCatch(self.subscribeCore).call(self, ado);
|
2073 | if (sub === errorObj && !ado.fail(errorObj.e)) { thrower(errorObj.e); }
|
2074 | ado.setDisposable(fixSubscriber(sub));
|
2075 | }
|
2076 |
|
2077 | function ObservableBase() {
|
2078 | __super__.call(this);
|
2079 | }
|
2080 |
|
2081 | ObservableBase.prototype._subscribe = function (o) {
|
2082 | var ado = new AutoDetachObserver(o), state = [ado, this];
|
2083 |
|
2084 | if (currentThreadScheduler.scheduleRequired()) {
|
2085 | currentThreadScheduler.schedule(state, setDisposable);
|
2086 | } else {
|
2087 | setDisposable(null, state);
|
2088 | }
|
2089 | return ado;
|
2090 | };
|
2091 |
|
2092 | ObservableBase.prototype.subscribeCore = notImplemented;
|
2093 |
|
2094 | return ObservableBase;
|
2095 | }(Observable));
|
2096 |
|
2097 | var FlatMapObservable = Rx.FlatMapObservable = (function(__super__) {
|
2098 |
|
2099 | inherits(FlatMapObservable, __super__);
|
2100 |
|
2101 | function FlatMapObservable(source, selector, resultSelector, thisArg) {
|
2102 | this.resultSelector = isFunction(resultSelector) ? resultSelector : null;
|
2103 | this.selector = bindCallback(isFunction(selector) ? selector : function() { return selector; }, thisArg, 3);
|
2104 | this.source = source;
|
2105 | __super__.call(this);
|
2106 | }
|
2107 |
|
2108 | FlatMapObservable.prototype.subscribeCore = function(o) {
|
2109 | return this.source.subscribe(new InnerObserver(o, this.selector, this.resultSelector, this));
|
2110 | };
|
2111 |
|
2112 | inherits(InnerObserver, AbstractObserver);
|
2113 | function InnerObserver(observer, selector, resultSelector, source) {
|
2114 | this.i = 0;
|
2115 | this.selector = selector;
|
2116 | this.resultSelector = resultSelector;
|
2117 | this.source = source;
|
2118 | this.o = observer;
|
2119 | AbstractObserver.call(this);
|
2120 | }
|
2121 |
|
2122 | InnerObserver.prototype._wrapResult = function(result, x, i) {
|
2123 | return this.resultSelector ?
|
2124 | result.map(function(y, i2) { return this.resultSelector(x, y, i, i2); }, this) :
|
2125 | result;
|
2126 | };
|
2127 |
|
2128 | InnerObserver.prototype.next = function(x) {
|
2129 | var i = this.i++;
|
2130 | var result = tryCatch(this.selector)(x, i, this.source);
|
2131 | if (result === errorObj) { return this.o.onError(result.e); }
|
2132 |
|
2133 | isPromise(result) && (result = observableFromPromise(result));
|
2134 | (isArrayLike(result) || isIterable(result)) && (result = Observable.from(result));
|
2135 | this.o.onNext(this._wrapResult(result, x, i));
|
2136 | };
|
2137 |
|
2138 | InnerObserver.prototype.error = function(e) { this.o.onError(e); };
|
2139 |
|
2140 | InnerObserver.prototype.completed = function() { this.o.onCompleted(); };
|
2141 |
|
2142 | return FlatMapObservable;
|
2143 |
|
2144 | }(ObservableBase));
|
2145 |
|
2146 | var Enumerable = Rx.internals.Enumerable = function () { };
|
2147 |
|
2148 | function IsDisposedDisposable(state) {
|
2149 | this._s = state;
|
2150 | this.isDisposed = false;
|
2151 | }
|
2152 |
|
2153 | IsDisposedDisposable.prototype.dispose = function () {
|
2154 | if (!this.isDisposed) {
|
2155 | this.isDisposed = true;
|
2156 | this._s.isDisposed = true;
|
2157 | }
|
2158 | };
|
2159 |
|
2160 | var ConcatEnumerableObservable = (function(__super__) {
|
2161 | inherits(ConcatEnumerableObservable, __super__);
|
2162 | function ConcatEnumerableObservable(sources) {
|
2163 | this.sources = sources;
|
2164 | __super__.call(this);
|
2165 | }
|
2166 |
|
2167 | function scheduleMethod(state, recurse) {
|
2168 | if (state.isDisposed) { return; }
|
2169 | var currentItem = tryCatch(state.e.next).call(state.e);
|
2170 | if (currentItem === errorObj) { return state.o.onError(currentItem.e); }
|
2171 | if (currentItem.done) { return state.o.onCompleted(); }
|
2172 |
|
2173 |
|
2174 | var currentValue = currentItem.value;
|
2175 | isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
2176 |
|
2177 | var d = new SingleAssignmentDisposable();
|
2178 | state.subscription.setDisposable(d);
|
2179 | d.setDisposable(currentValue.subscribe(new InnerObserver(state, recurse)));
|
2180 | }
|
2181 |
|
2182 | ConcatEnumerableObservable.prototype.subscribeCore = function (o) {
|
2183 | var subscription = new SerialDisposable();
|
2184 | var state = {
|
2185 | isDisposed: false,
|
2186 | o: o,
|
2187 | subscription: subscription,
|
2188 | e: this.sources[$iterator$]()
|
2189 | };
|
2190 |
|
2191 | var cancelable = currentThreadScheduler.scheduleRecursive(state, scheduleMethod);
|
2192 | return new NAryDisposable([subscription, cancelable, new IsDisposedDisposable(state)]);
|
2193 | };
|
2194 |
|
2195 | function InnerObserver(state, recurse) {
|
2196 | this._state = state;
|
2197 | this._recurse = recurse;
|
2198 | AbstractObserver.call(this);
|
2199 | }
|
2200 |
|
2201 | inherits(InnerObserver, AbstractObserver);
|
2202 |
|
2203 | InnerObserver.prototype.next = function (x) { this._state.o.onNext(x); };
|
2204 | InnerObserver.prototype.error = function (e) { this._state.o.onError(e); };
|
2205 | InnerObserver.prototype.completed = function () { this._recurse(this._state); };
|
2206 |
|
2207 | return ConcatEnumerableObservable;
|
2208 | }(ObservableBase));
|
2209 |
|
2210 | Enumerable.prototype.concat = function () {
|
2211 | return new ConcatEnumerableObservable(this);
|
2212 | };
|
2213 |
|
2214 | var CatchErrorObservable = (function(__super__) {
|
2215 | function CatchErrorObservable(sources) {
|
2216 | this.sources = sources;
|
2217 | __super__.call(this);
|
2218 | }
|
2219 |
|
2220 | inherits(CatchErrorObservable, __super__);
|
2221 |
|
2222 | function scheduleMethod(state, recurse) {
|
2223 | if (state.isDisposed) { return; }
|
2224 | var currentItem = tryCatch(state.e.next).call(state.e);
|
2225 | if (currentItem === errorObj) { return state.o.onError(currentItem.e); }
|
2226 | if (currentItem.done) { return state.lastError !== null ? state.o.onError(state.lastError) : state.o.onCompleted(); }
|
2227 |
|
2228 | var currentValue = currentItem.value;
|
2229 | isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
2230 |
|
2231 | var d = new SingleAssignmentDisposable();
|
2232 | state.subscription.setDisposable(d);
|
2233 | d.setDisposable(currentValue.subscribe(new InnerObserver(state, recurse)));
|
2234 | }
|
2235 |
|
2236 | CatchErrorObservable.prototype.subscribeCore = function (o) {
|
2237 | var subscription = new SerialDisposable();
|
2238 | var state = {
|
2239 | isDisposed: false,
|
2240 | e: this.sources[$iterator$](),
|
2241 | subscription: subscription,
|
2242 | lastError: null,
|
2243 | o: o
|
2244 | };
|
2245 |
|
2246 | var cancelable = currentThreadScheduler.scheduleRecursive(state, scheduleMethod);
|
2247 | return new NAryDisposable([subscription, cancelable, new IsDisposedDisposable(state)]);
|
2248 | };
|
2249 |
|
2250 | function InnerObserver(state, recurse) {
|
2251 | this._state = state;
|
2252 | this._recurse = recurse;
|
2253 | AbstractObserver.call(this);
|
2254 | }
|
2255 |
|
2256 | inherits(InnerObserver, AbstractObserver);
|
2257 |
|
2258 | InnerObserver.prototype.next = function (x) { this._state.o.onNext(x); };
|
2259 | InnerObserver.prototype.error = function (e) { this._state.lastError = e; this._recurse(this._state); };
|
2260 | InnerObserver.prototype.completed = function () { this._state.o.onCompleted(); };
|
2261 |
|
2262 | return CatchErrorObservable;
|
2263 | }(ObservableBase));
|
2264 |
|
2265 | Enumerable.prototype.catchError = function () {
|
2266 | return new CatchErrorObservable(this);
|
2267 | };
|
2268 |
|
2269 | Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
|
2270 | var sources = this;
|
2271 | return new AnonymousObservable(function (o) {
|
2272 | var exceptions = new Subject(),
|
2273 | notifier = new Subject(),
|
2274 | handled = notificationHandler(exceptions),
|
2275 | notificationDisposable = handled.subscribe(notifier);
|
2276 |
|
2277 | var e = sources[$iterator$]();
|
2278 |
|
2279 | var state = { isDisposed: false },
|
2280 | lastError,
|
2281 | subscription = new SerialDisposable();
|
2282 | var cancelable = currentThreadScheduler.scheduleRecursive(null, function (_, self) {
|
2283 | if (state.isDisposed) { return; }
|
2284 | var currentItem = tryCatch(e.next).call(e);
|
2285 | if (currentItem === errorObj) { return o.onError(currentItem.e); }
|
2286 |
|
2287 | if (currentItem.done) {
|
2288 | if (lastError) {
|
2289 | o.onError(lastError);
|
2290 | } else {
|
2291 | o.onCompleted();
|
2292 | }
|
2293 | return;
|
2294 | }
|
2295 |
|
2296 |
|
2297 | var currentValue = currentItem.value;
|
2298 | isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
2299 |
|
2300 | var outer = new SingleAssignmentDisposable();
|
2301 | var inner = new SingleAssignmentDisposable();
|
2302 | subscription.setDisposable(new BinaryDisposable(inner, outer));
|
2303 | outer.setDisposable(currentValue.subscribe(
|
2304 | function(x) { o.onNext(x); },
|
2305 | function (exn) {
|
2306 | inner.setDisposable(notifier.subscribe(self, function(ex) {
|
2307 | o.onError(ex);
|
2308 | }, function() {
|
2309 | o.onCompleted();
|
2310 | }));
|
2311 |
|
2312 | exceptions.onNext(exn);
|
2313 | },
|
2314 | function() { o.onCompleted(); }));
|
2315 | });
|
2316 |
|
2317 | return new NAryDisposable([notificationDisposable, subscription, cancelable, new IsDisposedDisposable(state)]);
|
2318 | });
|
2319 | };
|
2320 |
|
2321 | var RepeatEnumerable = (function (__super__) {
|
2322 | inherits(RepeatEnumerable, __super__);
|
2323 | function RepeatEnumerable(v, c) {
|
2324 | this.v = v;
|
2325 | this.c = c == null ? -1 : c;
|
2326 | }
|
2327 |
|
2328 | RepeatEnumerable.prototype[$iterator$] = function () {
|
2329 | return new RepeatEnumerator(this);
|
2330 | };
|
2331 |
|
2332 | function RepeatEnumerator(p) {
|
2333 | this.v = p.v;
|
2334 | this.l = p.c;
|
2335 | }
|
2336 |
|
2337 | RepeatEnumerator.prototype.next = function () {
|
2338 | if (this.l === 0) { return doneEnumerator; }
|
2339 | if (this.l > 0) { this.l--; }
|
2340 | return { done: false, value: this.v };
|
2341 | };
|
2342 |
|
2343 | return RepeatEnumerable;
|
2344 | }(Enumerable));
|
2345 |
|
2346 | var enumerableRepeat = Enumerable.repeat = function (value, repeatCount) {
|
2347 | return new RepeatEnumerable(value, repeatCount);
|
2348 | };
|
2349 |
|
2350 | var OfEnumerable = (function(__super__) {
|
2351 | inherits(OfEnumerable, __super__);
|
2352 | function OfEnumerable(s, fn, thisArg) {
|
2353 | this.s = s;
|
2354 | this.fn = fn ? bindCallback(fn, thisArg, 3) : null;
|
2355 | }
|
2356 | OfEnumerable.prototype[$iterator$] = function () {
|
2357 | return new OfEnumerator(this);
|
2358 | };
|
2359 |
|
2360 | function OfEnumerator(p) {
|
2361 | this.i = -1;
|
2362 | this.s = p.s;
|
2363 | this.l = this.s.length;
|
2364 | this.fn = p.fn;
|
2365 | }
|
2366 |
|
2367 | OfEnumerator.prototype.next = function () {
|
2368 | return ++this.i < this.l ?
|
2369 | { done: false, value: !this.fn ? this.s[this.i] : this.fn(this.s[this.i], this.i, this.s) } :
|
2370 | doneEnumerator;
|
2371 | };
|
2372 |
|
2373 | return OfEnumerable;
|
2374 | }(Enumerable));
|
2375 |
|
2376 | var enumerableOf = Enumerable.of = function (source, selector, thisArg) {
|
2377 | return new OfEnumerable(source, selector, thisArg);
|
2378 | };
|
2379 |
|
2380 | var ObserveOnObservable = (function (__super__) {
|
2381 | inherits(ObserveOnObservable, __super__);
|
2382 | function ObserveOnObservable(source, s) {
|
2383 | this.source = source;
|
2384 | this._s = s;
|
2385 | __super__.call(this);
|
2386 | }
|
2387 |
|
2388 | ObserveOnObservable.prototype.subscribeCore = function (o) {
|
2389 | return this.source.subscribe(new ObserveOnObserver(this._s, o));
|
2390 | };
|
2391 |
|
2392 | return ObserveOnObservable;
|
2393 | }(ObservableBase));
|
2394 |
|
2395 | |
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 | observableProto.observeOn = function (scheduler) {
|
2405 | return new ObserveOnObservable(this, scheduler);
|
2406 | };
|
2407 |
|
2408 | var SubscribeOnObservable = (function (__super__) {
|
2409 | inherits(SubscribeOnObservable, __super__);
|
2410 | function SubscribeOnObservable(source, s) {
|
2411 | this.source = source;
|
2412 | this._s = s;
|
2413 | __super__.call(this);
|
2414 | }
|
2415 |
|
2416 | function scheduleMethod(scheduler, state) {
|
2417 | var source = state[0], d = state[1], o = state[2];
|
2418 | d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(o)));
|
2419 | }
|
2420 |
|
2421 | SubscribeOnObservable.prototype.subscribeCore = function (o) {
|
2422 | var m = new SingleAssignmentDisposable(), d = new SerialDisposable();
|
2423 | d.setDisposable(m);
|
2424 | m.setDisposable(this._s.schedule([this.source, d, o], scheduleMethod));
|
2425 | return d;
|
2426 | };
|
2427 |
|
2428 | return SubscribeOnObservable;
|
2429 | }(ObservableBase));
|
2430 |
|
2431 | |
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 | observableProto.subscribeOn = function (scheduler) {
|
2442 | return new SubscribeOnObservable(this, scheduler);
|
2443 | };
|
2444 |
|
2445 | var FromPromiseObservable = (function(__super__) {
|
2446 | inherits(FromPromiseObservable, __super__);
|
2447 | function FromPromiseObservable(p, s) {
|
2448 | this._p = p;
|
2449 | this._s = s;
|
2450 | __super__.call(this);
|
2451 | }
|
2452 |
|
2453 | function scheduleNext(s, state) {
|
2454 | var o = state[0], data = state[1];
|
2455 | o.onNext(data);
|
2456 | o.onCompleted();
|
2457 | }
|
2458 |
|
2459 | function scheduleError(s, state) {
|
2460 | var o = state[0], err = state[1];
|
2461 | o.onError(err);
|
2462 | }
|
2463 |
|
2464 | FromPromiseObservable.prototype.subscribeCore = function(o) {
|
2465 | var sad = new SingleAssignmentDisposable(), self = this;
|
2466 |
|
2467 | this._p
|
2468 | .then(function (data) {
|
2469 | sad.setDisposable(self._s.schedule([o, data], scheduleNext));
|
2470 | }, function (err) {
|
2471 | sad.setDisposable(self._s.schedule([o, err], scheduleError));
|
2472 | });
|
2473 |
|
2474 | return sad;
|
2475 | };
|
2476 |
|
2477 | return FromPromiseObservable;
|
2478 | }(ObservableBase));
|
2479 |
|
2480 | |
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 | var observableFromPromise = Observable.fromPromise = function (promise, scheduler) {
|
2486 | scheduler || (scheduler = defaultScheduler);
|
2487 | return new FromPromiseObservable(promise, scheduler);
|
2488 | };
|
2489 |
|
2490 | |
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 | observableProto.toPromise = function (promiseCtor) {
|
2502 | promiseCtor || (promiseCtor = Rx.config.Promise);
|
2503 | if (!promiseCtor) { throw new NotSupportedError('Promise type not provided nor in Rx.config.Promise'); }
|
2504 | var source = this;
|
2505 | return new promiseCtor(function (resolve, reject) {
|
2506 |
|
2507 | var value;
|
2508 | source.subscribe(function (v) {
|
2509 | value = v;
|
2510 | }, reject, function () {
|
2511 | resolve(value);
|
2512 | });
|
2513 | });
|
2514 | };
|
2515 |
|
2516 | var ToArrayObservable = (function(__super__) {
|
2517 | inherits(ToArrayObservable, __super__);
|
2518 | function ToArrayObservable(source) {
|
2519 | this.source = source;
|
2520 | __super__.call(this);
|
2521 | }
|
2522 |
|
2523 | ToArrayObservable.prototype.subscribeCore = function(o) {
|
2524 | return this.source.subscribe(new InnerObserver(o));
|
2525 | };
|
2526 |
|
2527 | inherits(InnerObserver, AbstractObserver);
|
2528 | function InnerObserver(o) {
|
2529 | this.o = o;
|
2530 | this.a = [];
|
2531 | AbstractObserver.call(this);
|
2532 | }
|
2533 |
|
2534 | InnerObserver.prototype.next = function (x) { this.a.push(x); };
|
2535 | InnerObserver.prototype.error = function (e) { this.o.onError(e); };
|
2536 | InnerObserver.prototype.completed = function () { this.o.onNext(this.a); this.o.onCompleted(); };
|
2537 |
|
2538 | return ToArrayObservable;
|
2539 | }(ObservableBase));
|
2540 |
|
2541 | |
2542 |
|
2543 |
|
2544 |
|
2545 | observableProto.toArray = function () {
|
2546 | return new ToArrayObservable(this);
|
2547 | };
|
2548 |
|
2549 | |
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 | Observable.create = function (subscribe, parent) {
|
2559 | return new AnonymousObservable(subscribe, parent);
|
2560 | };
|
2561 |
|
2562 | var Defer = (function(__super__) {
|
2563 | inherits(Defer, __super__);
|
2564 | function Defer(factory) {
|
2565 | this._f = factory;
|
2566 | __super__.call(this);
|
2567 | }
|
2568 |
|
2569 | Defer.prototype.subscribeCore = function (o) {
|
2570 | var result = tryCatch(this._f)();
|
2571 | if (result === errorObj) { return observableThrow(result.e).subscribe(o);}
|
2572 | isPromise(result) && (result = observableFromPromise(result));
|
2573 | return result.subscribe(o);
|
2574 | };
|
2575 |
|
2576 | return Defer;
|
2577 | }(ObservableBase));
|
2578 |
|
2579 | |
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 | var observableDefer = Observable.defer = function (observableFactory) {
|
2588 | return new Defer(observableFactory);
|
2589 | };
|
2590 |
|
2591 | var EmptyObservable = (function(__super__) {
|
2592 | inherits(EmptyObservable, __super__);
|
2593 | function EmptyObservable(scheduler) {
|
2594 | this.scheduler = scheduler;
|
2595 | __super__.call(this);
|
2596 | }
|
2597 |
|
2598 | EmptyObservable.prototype.subscribeCore = function (observer) {
|
2599 | var sink = new EmptySink(observer, this.scheduler);
|
2600 | return sink.run();
|
2601 | };
|
2602 |
|
2603 | function EmptySink(observer, scheduler) {
|
2604 | this.observer = observer;
|
2605 | this.scheduler = scheduler;
|
2606 | }
|
2607 |
|
2608 | function scheduleItem(s, state) {
|
2609 | state.onCompleted();
|
2610 | return disposableEmpty;
|
2611 | }
|
2612 |
|
2613 | EmptySink.prototype.run = function () {
|
2614 | var state = this.observer;
|
2615 | return this.scheduler === immediateScheduler ?
|
2616 | scheduleItem(null, state) :
|
2617 | this.scheduler.schedule(state, scheduleItem);
|
2618 | };
|
2619 |
|
2620 | return EmptyObservable;
|
2621 | }(ObservableBase));
|
2622 |
|
2623 | var EMPTY_OBSERVABLE = new EmptyObservable(immediateScheduler);
|
2624 |
|
2625 | |
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 |
|
2631 |
|
2632 |
|
2633 |
|
2634 | var observableEmpty = Observable.empty = function (scheduler) {
|
2635 | isScheduler(scheduler) || (scheduler = immediateScheduler);
|
2636 | return scheduler === immediateScheduler ? EMPTY_OBSERVABLE : new EmptyObservable(scheduler);
|
2637 | };
|
2638 |
|
2639 | var FromObservable = (function(__super__) {
|
2640 | inherits(FromObservable, __super__);
|
2641 | function FromObservable(iterable, fn, scheduler) {
|
2642 | this._iterable = iterable;
|
2643 | this._fn = fn;
|
2644 | this._scheduler = scheduler;
|
2645 | __super__.call(this);
|
2646 | }
|
2647 |
|
2648 | function createScheduleMethod(o, it, fn) {
|
2649 | return function loopRecursive(i, recurse) {
|
2650 | var next = tryCatch(it.next).call(it);
|
2651 | if (next === errorObj) { return o.onError(next.e); }
|
2652 | if (next.done) { return o.onCompleted(); }
|
2653 |
|
2654 | var result = next.value;
|
2655 |
|
2656 | if (isFunction(fn)) {
|
2657 | result = tryCatch(fn)(result, i);
|
2658 | if (result === errorObj) { return o.onError(result.e); }
|
2659 | }
|
2660 |
|
2661 | o.onNext(result);
|
2662 | recurse(i + 1);
|
2663 | };
|
2664 | }
|
2665 |
|
2666 | FromObservable.prototype.subscribeCore = function (o) {
|
2667 | var list = Object(this._iterable),
|
2668 | it = getIterable(list);
|
2669 |
|
2670 | return this._scheduler.scheduleRecursive(0, createScheduleMethod(o, it, this._fn));
|
2671 | };
|
2672 |
|
2673 | return FromObservable;
|
2674 | }(ObservableBase));
|
2675 |
|
2676 | var maxSafeInteger = Math.pow(2, 53) - 1;
|
2677 |
|
2678 | function StringIterable(s) {
|
2679 | this._s = s;
|
2680 | }
|
2681 |
|
2682 | StringIterable.prototype[$iterator$] = function () {
|
2683 | return new StringIterator(this._s);
|
2684 | };
|
2685 |
|
2686 | function StringIterator(s) {
|
2687 | this._s = s;
|
2688 | this._l = s.length;
|
2689 | this._i = 0;
|
2690 | }
|
2691 |
|
2692 | StringIterator.prototype[$iterator$] = function () {
|
2693 | return this;
|
2694 | };
|
2695 |
|
2696 | StringIterator.prototype.next = function () {
|
2697 | return this._i < this._l ? { done: false, value: this._s.charAt(this._i++) } : doneEnumerator;
|
2698 | };
|
2699 |
|
2700 | function ArrayIterable(a) {
|
2701 | this._a = a;
|
2702 | }
|
2703 |
|
2704 | ArrayIterable.prototype[$iterator$] = function () {
|
2705 | return new ArrayIterator(this._a);
|
2706 | };
|
2707 |
|
2708 | function ArrayIterator(a) {
|
2709 | this._a = a;
|
2710 | this._l = toLength(a);
|
2711 | this._i = 0;
|
2712 | }
|
2713 |
|
2714 | ArrayIterator.prototype[$iterator$] = function () {
|
2715 | return this;
|
2716 | };
|
2717 |
|
2718 | ArrayIterator.prototype.next = function () {
|
2719 | return this._i < this._l ? { done: false, value: this._a[this._i++] } : doneEnumerator;
|
2720 | };
|
2721 |
|
2722 | function numberIsFinite(value) {
|
2723 | return typeof value === 'number' && root.isFinite(value);
|
2724 | }
|
2725 |
|
2726 | function isNan(n) {
|
2727 | return n !== n;
|
2728 | }
|
2729 |
|
2730 | function getIterable(o) {
|
2731 | var i = o[$iterator$], it;
|
2732 | if (!i && typeof o === 'string') {
|
2733 | it = new StringIterable(o);
|
2734 | return it[$iterator$]();
|
2735 | }
|
2736 | if (!i && o.length !== undefined) {
|
2737 | it = new ArrayIterable(o);
|
2738 | return it[$iterator$]();
|
2739 | }
|
2740 | if (!i) { throw new TypeError('Object is not iterable'); }
|
2741 | return o[$iterator$]();
|
2742 | }
|
2743 |
|
2744 | function sign(value) {
|
2745 | var number = +value;
|
2746 | if (number === 0) { return number; }
|
2747 | if (isNaN(number)) { return number; }
|
2748 | return number < 0 ? -1 : 1;
|
2749 | }
|
2750 |
|
2751 | function toLength(o) {
|
2752 | var len = +o.length;
|
2753 | if (isNaN(len)) { return 0; }
|
2754 | if (len === 0 || !numberIsFinite(len)) { return len; }
|
2755 | len = sign(len) * Math.floor(Math.abs(len));
|
2756 | if (len <= 0) { return 0; }
|
2757 | if (len > maxSafeInteger) { return maxSafeInteger; }
|
2758 | return len;
|
2759 | }
|
2760 |
|
2761 | |
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 | var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
|
2769 | if (iterable == null) {
|
2770 | throw new Error('iterable cannot be null.')
|
2771 | }
|
2772 | if (mapFn && !isFunction(mapFn)) {
|
2773 | throw new Error('mapFn when provided must be a function');
|
2774 | }
|
2775 | if (mapFn) {
|
2776 | var mapper = bindCallback(mapFn, thisArg, 2);
|
2777 | }
|
2778 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2779 | return new FromObservable(iterable, mapper, scheduler);
|
2780 | }
|
2781 |
|
2782 | var FromArrayObservable = (function(__super__) {
|
2783 | inherits(FromArrayObservable, __super__);
|
2784 | function FromArrayObservable(args, scheduler) {
|
2785 | this._args = args;
|
2786 | this._scheduler = scheduler;
|
2787 | __super__.call(this);
|
2788 | }
|
2789 |
|
2790 | function scheduleMethod(o, args) {
|
2791 | var len = args.length;
|
2792 | return function loopRecursive (i, recurse) {
|
2793 | if (i < len) {
|
2794 | o.onNext(args[i]);
|
2795 | recurse(i + 1);
|
2796 | } else {
|
2797 | o.onCompleted();
|
2798 | }
|
2799 | };
|
2800 | }
|
2801 |
|
2802 | FromArrayObservable.prototype.subscribeCore = function (o) {
|
2803 | return this._scheduler.scheduleRecursive(0, scheduleMethod(o, this._args));
|
2804 | };
|
2805 |
|
2806 | return FromArrayObservable;
|
2807 | }(ObservableBase));
|
2808 |
|
2809 | |
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 | var observableFromArray = Observable.fromArray = function (array, scheduler) {
|
2816 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2817 | return new FromArrayObservable(array, scheduler)
|
2818 | };
|
2819 |
|
2820 | var GenerateObservable = (function (__super__) {
|
2821 | inherits(GenerateObservable, __super__);
|
2822 | function GenerateObservable(state, cndFn, itrFn, resFn, s) {
|
2823 | this._state = state;
|
2824 | this._cndFn = cndFn;
|
2825 | this._itrFn = itrFn;
|
2826 | this._resFn = resFn;
|
2827 | this._s = s;
|
2828 | this._first = true;
|
2829 | __super__.call(this);
|
2830 | }
|
2831 |
|
2832 | function scheduleRecursive(self, recurse) {
|
2833 | if (self._first) {
|
2834 | self._first = false;
|
2835 | } else {
|
2836 | self._state = tryCatch(self._itrFn)(self._state);
|
2837 | if (self._state === errorObj) { return self._o.onError(self._state.e); }
|
2838 | }
|
2839 | var hasResult = tryCatch(self._cndFn)(self._state);
|
2840 | if (hasResult === errorObj) { return self._o.onError(hasResult.e); }
|
2841 | if (hasResult) {
|
2842 | var result = tryCatch(self._resFn)(self._state);
|
2843 | if (result === errorObj) { return self._o.onError(result.e); }
|
2844 | self._o.onNext(result);
|
2845 | recurse(self);
|
2846 | } else {
|
2847 | self._o.onCompleted();
|
2848 | }
|
2849 | }
|
2850 |
|
2851 | GenerateObservable.prototype.subscribeCore = function (o) {
|
2852 | this._o = o;
|
2853 | return this._s.scheduleRecursive(this, scheduleRecursive);
|
2854 | };
|
2855 |
|
2856 | return GenerateObservable;
|
2857 | }(ObservableBase));
|
2858 |
|
2859 | |
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 | Observable.generate = function (initialState, condition, iterate, resultSelector, scheduler) {
|
2873 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2874 | return new GenerateObservable(initialState, condition, iterate, resultSelector, scheduler);
|
2875 | };
|
2876 |
|
2877 | function observableOf (scheduler, array) {
|
2878 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
2879 | return new FromArrayObservable(array, scheduler);
|
2880 | }
|
2881 |
|
2882 | |
2883 |
|
2884 |
|
2885 |
|
2886 | Observable.of = function () {
|
2887 | var len = arguments.length, args = new Array(len);
|
2888 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
2889 | return new FromArrayObservable(args, currentThreadScheduler);
|
2890 | };
|
2891 |
|
2892 | |
2893 |
|
2894 |
|
2895 |
|
2896 |
|
2897 | Observable.ofWithScheduler = function (scheduler) {
|
2898 | var len = arguments.length, args = new Array(len - 1);
|
2899 | for(var i = 1; i < len; i++) { args[i - 1] = arguments[i]; }
|
2900 | return new FromArrayObservable(args, scheduler);
|
2901 | };
|
2902 |
|
2903 | |
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 | Observable.ofArrayChanges = function(array) {
|
2909 | if (!Array.isArray(array)) { throw new TypeError('Array.observe only accepts arrays.'); }
|
2910 | if (typeof Array.observe !== 'function' && typeof Array.unobserve !== 'function') { throw new TypeError('Array.observe is not supported on your platform') }
|
2911 | return new AnonymousObservable(function(observer) {
|
2912 | function observerFn(changes) {
|
2913 | for(var i = 0, len = changes.length; i < len; i++) {
|
2914 | observer.onNext(changes[i]);
|
2915 | }
|
2916 | }
|
2917 |
|
2918 | Array.observe(array, observerFn);
|
2919 |
|
2920 | return function () {
|
2921 | Array.unobserve(array, observerFn);
|
2922 | };
|
2923 | });
|
2924 | };
|
2925 |
|
2926 | |
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 | Observable.ofObjectChanges = function(obj) {
|
2932 | if (obj == null) { throw new TypeError('object must not be null or undefined.'); }
|
2933 | if (typeof Object.observe !== 'function' && typeof Object.unobserve !== 'function') { throw new TypeError('Object.observe is not supported on your platform') }
|
2934 | return new AnonymousObservable(function(observer) {
|
2935 | function observerFn(changes) {
|
2936 | for(var i = 0, len = changes.length; i < len; i++) {
|
2937 | observer.onNext(changes[i]);
|
2938 | }
|
2939 | }
|
2940 |
|
2941 | Object.observe(obj, observerFn);
|
2942 |
|
2943 | return function () {
|
2944 | Object.unobserve(obj, observerFn);
|
2945 | };
|
2946 | });
|
2947 | };
|
2948 |
|
2949 | var NeverObservable = (function(__super__) {
|
2950 | inherits(NeverObservable, __super__);
|
2951 | function NeverObservable() {
|
2952 | __super__.call(this);
|
2953 | }
|
2954 |
|
2955 | NeverObservable.prototype.subscribeCore = function (observer) {
|
2956 | return disposableEmpty;
|
2957 | };
|
2958 |
|
2959 | return NeverObservable;
|
2960 | }(ObservableBase));
|
2961 |
|
2962 | var NEVER_OBSERVABLE = new NeverObservable();
|
2963 |
|
2964 | |
2965 |
|
2966 |
|
2967 |
|
2968 | var observableNever = Observable.never = function () {
|
2969 | return NEVER_OBSERVABLE;
|
2970 | };
|
2971 |
|
2972 | var PairsObservable = (function(__super__) {
|
2973 | inherits(PairsObservable, __super__);
|
2974 | function PairsObservable(o, scheduler) {
|
2975 | this._o = o;
|
2976 | this._keys = Object.keys(o);
|
2977 | this._scheduler = scheduler;
|
2978 | __super__.call(this);
|
2979 | }
|
2980 |
|
2981 | function scheduleMethod(o, obj, keys) {
|
2982 | return function loopRecursive(i, recurse) {
|
2983 | if (i < keys.length) {
|
2984 | var key = keys[i];
|
2985 | o.onNext([key, obj[key]]);
|
2986 | recurse(i + 1);
|
2987 | } else {
|
2988 | o.onCompleted();
|
2989 | }
|
2990 | };
|
2991 | }
|
2992 |
|
2993 | PairsObservable.prototype.subscribeCore = function (o) {
|
2994 | return this._scheduler.scheduleRecursive(0, scheduleMethod(o, this._o, this._keys));
|
2995 | };
|
2996 |
|
2997 | return PairsObservable;
|
2998 | }(ObservableBase));
|
2999 |
|
3000 | |
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 | Observable.pairs = function (obj, scheduler) {
|
3007 | scheduler || (scheduler = currentThreadScheduler);
|
3008 | return new PairsObservable(obj, scheduler);
|
3009 | };
|
3010 |
|
3011 | var RangeObservable = (function(__super__) {
|
3012 | inherits(RangeObservable, __super__);
|
3013 | function RangeObservable(start, count, scheduler) {
|
3014 | this.start = start;
|
3015 | this.rangeCount = count;
|
3016 | this.scheduler = scheduler;
|
3017 | __super__.call(this);
|
3018 | }
|
3019 |
|
3020 | function loopRecursive(start, count, o) {
|
3021 | return function loop (i, recurse) {
|
3022 | if (i < count) {
|
3023 | o.onNext(start + i);
|
3024 | recurse(i + 1);
|
3025 | } else {
|
3026 | o.onCompleted();
|
3027 | }
|
3028 | };
|
3029 | }
|
3030 |
|
3031 | RangeObservable.prototype.subscribeCore = function (o) {
|
3032 | return this.scheduler.scheduleRecursive(
|
3033 | 0,
|
3034 | loopRecursive(this.start, this.rangeCount, o)
|
3035 | );
|
3036 | };
|
3037 |
|
3038 | return RangeObservable;
|
3039 | }(ObservableBase));
|
3040 |
|
3041 | |
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 | Observable.range = function (start, count, scheduler) {
|
3049 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
3050 | return new RangeObservable(start, count, scheduler);
|
3051 | };
|
3052 |
|
3053 | var RepeatObservable = (function(__super__) {
|
3054 | inherits(RepeatObservable, __super__);
|
3055 | function RepeatObservable(value, repeatCount, scheduler) {
|
3056 | this.value = value;
|
3057 | this.repeatCount = repeatCount == null ? -1 : repeatCount;
|
3058 | this.scheduler = scheduler;
|
3059 | __super__.call(this);
|
3060 | }
|
3061 |
|
3062 | RepeatObservable.prototype.subscribeCore = function (observer) {
|
3063 | var sink = new RepeatSink(observer, this);
|
3064 | return sink.run();
|
3065 | };
|
3066 |
|
3067 | return RepeatObservable;
|
3068 | }(ObservableBase));
|
3069 |
|
3070 | function RepeatSink(observer, parent) {
|
3071 | this.observer = observer;
|
3072 | this.parent = parent;
|
3073 | }
|
3074 |
|
3075 | RepeatSink.prototype.run = function () {
|
3076 | var observer = this.observer, value = this.parent.value;
|
3077 | function loopRecursive(i, recurse) {
|
3078 | if (i === -1 || i > 0) {
|
3079 | observer.onNext(value);
|
3080 | i > 0 && i--;
|
3081 | }
|
3082 | if (i === 0) { return observer.onCompleted(); }
|
3083 | recurse(i);
|
3084 | }
|
3085 |
|
3086 | return this.parent.scheduler.scheduleRecursive(this.parent.repeatCount, loopRecursive);
|
3087 | };
|
3088 |
|
3089 | |
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 | Observable.repeat = function (value, repeatCount, scheduler) {
|
3097 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
3098 | return new RepeatObservable(value, repeatCount, scheduler);
|
3099 | };
|
3100 |
|
3101 | var JustObservable = (function(__super__) {
|
3102 | inherits(JustObservable, __super__);
|
3103 | function JustObservable(value, scheduler) {
|
3104 | this._value = value;
|
3105 | this._scheduler = scheduler;
|
3106 | __super__.call(this);
|
3107 | }
|
3108 |
|
3109 | JustObservable.prototype.subscribeCore = function (o) {
|
3110 | var state = [this._value, o];
|
3111 | return this._scheduler === immediateScheduler ?
|
3112 | scheduleItem(null, state) :
|
3113 | this._scheduler.schedule(state, scheduleItem);
|
3114 | };
|
3115 |
|
3116 | function scheduleItem(s, state) {
|
3117 | var value = state[0], observer = state[1];
|
3118 | observer.onNext(value);
|
3119 | observer.onCompleted();
|
3120 | return disposableEmpty;
|
3121 | }
|
3122 |
|
3123 | return JustObservable;
|
3124 | }(ObservableBase));
|
3125 |
|
3126 | |
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 | var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
|
3134 | isScheduler(scheduler) || (scheduler = immediateScheduler);
|
3135 | return new JustObservable(value, scheduler);
|
3136 | };
|
3137 |
|
3138 | var ThrowObservable = (function(__super__) {
|
3139 | inherits(ThrowObservable, __super__);
|
3140 | function ThrowObservable(error, scheduler) {
|
3141 | this._error = error;
|
3142 | this._scheduler = scheduler;
|
3143 | __super__.call(this);
|
3144 | }
|
3145 |
|
3146 | ThrowObservable.prototype.subscribeCore = function (o) {
|
3147 | var state = [this._error, o];
|
3148 | return this._scheduler === immediateScheduler ?
|
3149 | scheduleItem(null, state) :
|
3150 | this._scheduler.schedule(state, scheduleItem);
|
3151 | };
|
3152 |
|
3153 | function scheduleItem(s, state) {
|
3154 | var e = state[0], o = state[1];
|
3155 | o.onError(e);
|
3156 | return disposableEmpty;
|
3157 | }
|
3158 |
|
3159 | return ThrowObservable;
|
3160 | }(ObservableBase));
|
3161 |
|
3162 | |
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 | var observableThrow = Observable['throw'] = function (error, scheduler) {
|
3170 | isScheduler(scheduler) || (scheduler = immediateScheduler);
|
3171 | return new ThrowObservable(error, scheduler);
|
3172 | };
|
3173 |
|
3174 | var UsingObservable = (function (__super__) {
|
3175 | inherits(UsingObservable, __super__);
|
3176 | function UsingObservable(resFn, obsFn) {
|
3177 | this._resFn = resFn;
|
3178 | this._obsFn = obsFn;
|
3179 | __super__.call(this);
|
3180 | }
|
3181 |
|
3182 | UsingObservable.prototype.subscribeCore = function (o) {
|
3183 | var disposable = disposableEmpty;
|
3184 | var resource = tryCatch(this._resFn)();
|
3185 | if (resource === errorObj) {
|
3186 | return new BinaryDisposable(observableThrow(resource.e).subscribe(o), disposable);
|
3187 | }
|
3188 | resource && (disposable = resource);
|
3189 | var source = tryCatch(this._obsFn)(resource);
|
3190 | if (source === errorObj) {
|
3191 | return new BinaryDisposable(observableThrow(source.e).subscribe(o), disposable);
|
3192 | }
|
3193 | return new BinaryDisposable(source.subscribe(o), disposable);
|
3194 | };
|
3195 |
|
3196 | return UsingObservable;
|
3197 | }(ObservableBase));
|
3198 |
|
3199 | |
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 | Observable.using = function (resourceFactory, observableFactory) {
|
3206 | return new UsingObservable(resourceFactory, observableFactory);
|
3207 | };
|
3208 |
|
3209 | |
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 | observableProto.amb = function (rightSource) {
|
3215 | var leftSource = this;
|
3216 | return new AnonymousObservable(function (observer) {
|
3217 | var choice,
|
3218 | leftChoice = 'L', rightChoice = 'R',
|
3219 | leftSubscription = new SingleAssignmentDisposable(),
|
3220 | rightSubscription = new SingleAssignmentDisposable();
|
3221 |
|
3222 | isPromise(rightSource) && (rightSource = observableFromPromise(rightSource));
|
3223 |
|
3224 | function choiceL() {
|
3225 | if (!choice) {
|
3226 | choice = leftChoice;
|
3227 | rightSubscription.dispose();
|
3228 | }
|
3229 | }
|
3230 |
|
3231 | function choiceR() {
|
3232 | if (!choice) {
|
3233 | choice = rightChoice;
|
3234 | leftSubscription.dispose();
|
3235 | }
|
3236 | }
|
3237 |
|
3238 | var leftSubscribe = observerCreate(
|
3239 | function (left) {
|
3240 | choiceL();
|
3241 | choice === leftChoice && observer.onNext(left);
|
3242 | },
|
3243 | function (e) {
|
3244 | choiceL();
|
3245 | choice === leftChoice && observer.onError(e);
|
3246 | },
|
3247 | function () {
|
3248 | choiceL();
|
3249 | choice === leftChoice && observer.onCompleted();
|
3250 | }
|
3251 | );
|
3252 | var rightSubscribe = observerCreate(
|
3253 | function (right) {
|
3254 | choiceR();
|
3255 | choice === rightChoice && observer.onNext(right);
|
3256 | },
|
3257 | function (e) {
|
3258 | choiceR();
|
3259 | choice === rightChoice && observer.onError(e);
|
3260 | },
|
3261 | function () {
|
3262 | choiceR();
|
3263 | choice === rightChoice && observer.onCompleted();
|
3264 | }
|
3265 | );
|
3266 |
|
3267 | leftSubscription.setDisposable(leftSource.subscribe(leftSubscribe));
|
3268 | rightSubscription.setDisposable(rightSource.subscribe(rightSubscribe));
|
3269 |
|
3270 | return new BinaryDisposable(leftSubscription, rightSubscription);
|
3271 | });
|
3272 | };
|
3273 |
|
3274 | function amb(p, c) { return p.amb(c); }
|
3275 |
|
3276 | |
3277 |
|
3278 |
|
3279 |
|
3280 | Observable.amb = function () {
|
3281 | var acc = observableNever(), items;
|
3282 | if (Array.isArray(arguments[0])) {
|
3283 | items = arguments[0];
|
3284 | } else {
|
3285 | var len = arguments.length;
|
3286 | items = new Array(items);
|
3287 | for(var i = 0; i < len; i++) { items[i] = arguments[i]; }
|
3288 | }
|
3289 | for (var i = 0, len = items.length; i < len; i++) {
|
3290 | acc = amb(acc, items[i]);
|
3291 | }
|
3292 | return acc;
|
3293 | };
|
3294 |
|
3295 | var CatchObservable = (function (__super__) {
|
3296 | inherits(CatchObservable, __super__);
|
3297 | function CatchObservable(source, fn) {
|
3298 | this.source = source;
|
3299 | this._fn = fn;
|
3300 | __super__.call(this);
|
3301 | }
|
3302 |
|
3303 | CatchObservable.prototype.subscribeCore = function (o) {
|
3304 | var d1 = new SingleAssignmentDisposable(), subscription = new SerialDisposable();
|
3305 | subscription.setDisposable(d1);
|
3306 | d1.setDisposable(this.source.subscribe(new CatchObserver(o, subscription, this._fn)));
|
3307 | return subscription;
|
3308 | };
|
3309 |
|
3310 | return CatchObservable;
|
3311 | }(ObservableBase));
|
3312 |
|
3313 | var CatchObserver = (function(__super__) {
|
3314 | inherits(CatchObserver, __super__);
|
3315 | function CatchObserver(o, s, fn) {
|
3316 | this._o = o;
|
3317 | this._s = s;
|
3318 | this._fn = fn;
|
3319 | __super__.call(this);
|
3320 | }
|
3321 |
|
3322 | CatchObserver.prototype.next = function (x) { this._o.onNext(x); };
|
3323 | CatchObserver.prototype.completed = function () { return this._o.onCompleted(); };
|
3324 | CatchObserver.prototype.error = function (e) {
|
3325 | var result = tryCatch(this._fn)(e);
|
3326 | if (result === errorObj) { return this._o.onError(result.e); }
|
3327 | isPromise(result) && (result = observableFromPromise(result));
|
3328 |
|
3329 | var d = new SingleAssignmentDisposable();
|
3330 | this._s.setDisposable(d);
|
3331 | d.setDisposable(result.subscribe(this._o));
|
3332 | };
|
3333 |
|
3334 | return CatchObserver;
|
3335 | }(AbstractObserver));
|
3336 |
|
3337 | |
3338 |
|
3339 |
|
3340 |
|
3341 |
|
3342 | observableProto['catch'] = function (handlerOrSecond) {
|
3343 | return isFunction(handlerOrSecond) ? new CatchObservable(this, handlerOrSecond) : observableCatch([this, handlerOrSecond]);
|
3344 | };
|
3345 |
|
3346 | |
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 | var observableCatch = Observable['catch'] = function () {
|
3352 | var items;
|
3353 | if (Array.isArray(arguments[0])) {
|
3354 | items = arguments[0];
|
3355 | } else {
|
3356 | var len = arguments.length;
|
3357 | items = new Array(len);
|
3358 | for(var i = 0; i < len; i++) { items[i] = arguments[i]; }
|
3359 | }
|
3360 | return enumerableOf(items).catchError();
|
3361 | };
|
3362 |
|
3363 | |
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 | observableProto.combineLatest = function () {
|
3373 | var len = arguments.length, args = new Array(len);
|
3374 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3375 | if (Array.isArray(args[0])) {
|
3376 | args[0].unshift(this);
|
3377 | } else {
|
3378 | args.unshift(this);
|
3379 | }
|
3380 | return combineLatest.apply(this, args);
|
3381 | };
|
3382 |
|
3383 | function falseFactory() { return false; }
|
3384 | function argumentsToArray() {
|
3385 | var len = arguments.length, args = new Array(len);
|
3386 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3387 | return args;
|
3388 | }
|
3389 |
|
3390 | var CombineLatestObservable = (function(__super__) {
|
3391 | inherits(CombineLatestObservable, __super__);
|
3392 | function CombineLatestObservable(params, cb) {
|
3393 | this._params = params;
|
3394 | this._cb = cb;
|
3395 | __super__.call(this);
|
3396 | }
|
3397 |
|
3398 | CombineLatestObservable.prototype.subscribeCore = function(observer) {
|
3399 | var len = this._params.length,
|
3400 | subscriptions = new Array(len);
|
3401 |
|
3402 | var state = {
|
3403 | hasValue: arrayInitialize(len, falseFactory),
|
3404 | hasValueAll: false,
|
3405 | isDone: arrayInitialize(len, falseFactory),
|
3406 | values: new Array(len)
|
3407 | };
|
3408 |
|
3409 | for (var i = 0; i < len; i++) {
|
3410 | var source = this._params[i], sad = new SingleAssignmentDisposable();
|
3411 | subscriptions[i] = sad;
|
3412 | isPromise(source) && (source = observableFromPromise(source));
|
3413 | sad.setDisposable(source.subscribe(new CombineLatestObserver(observer, i, this._cb, state)));
|
3414 | }
|
3415 |
|
3416 | return new NAryDisposable(subscriptions);
|
3417 | };
|
3418 |
|
3419 | return CombineLatestObservable;
|
3420 | }(ObservableBase));
|
3421 |
|
3422 | var CombineLatestObserver = (function (__super__) {
|
3423 | inherits(CombineLatestObserver, __super__);
|
3424 | function CombineLatestObserver(o, i, cb, state) {
|
3425 | this._o = o;
|
3426 | this._i = i;
|
3427 | this._cb = cb;
|
3428 | this._state = state;
|
3429 | __super__.call(this);
|
3430 | }
|
3431 |
|
3432 | function notTheSame(i) {
|
3433 | return function (x, j) {
|
3434 | return j !== i;
|
3435 | };
|
3436 | }
|
3437 |
|
3438 | CombineLatestObserver.prototype.next = function (x) {
|
3439 | this._state.values[this._i] = x;
|
3440 | this._state.hasValue[this._i] = true;
|
3441 | if (this._state.hasValueAll || (this._state.hasValueAll = this._state.hasValue.every(identity))) {
|
3442 | var res = tryCatch(this._cb).apply(null, this._state.values);
|
3443 | if (res === errorObj) { return this._o.onError(res.e); }
|
3444 | this._o.onNext(res);
|
3445 | } else if (this._state.isDone.filter(notTheSame(this._i)).every(identity)) {
|
3446 | this._o.onCompleted();
|
3447 | }
|
3448 | };
|
3449 |
|
3450 | CombineLatestObserver.prototype.error = function (e) {
|
3451 | this._o.onError(e);
|
3452 | };
|
3453 |
|
3454 | CombineLatestObserver.prototype.completed = function () {
|
3455 | this._state.isDone[this._i] = true;
|
3456 | this._state.isDone.every(identity) && this._o.onCompleted();
|
3457 | };
|
3458 |
|
3459 | return CombineLatestObserver;
|
3460 | }(AbstractObserver));
|
3461 |
|
3462 | |
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 | var combineLatest = Observable.combineLatest = function () {
|
3471 | var len = arguments.length, args = new Array(len);
|
3472 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3473 | var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
3474 | Array.isArray(args[0]) && (args = args[0]);
|
3475 | return new CombineLatestObservable(args, resultSelector);
|
3476 | };
|
3477 |
|
3478 | |
3479 |
|
3480 |
|
3481 |
|
3482 | observableProto.concat = function () {
|
3483 | for(var args = [], i = 0, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
|
3484 | args.unshift(this);
|
3485 | return observableConcat.apply(null, args);
|
3486 | };
|
3487 |
|
3488 | var ConcatObserver = (function(__super__) {
|
3489 | inherits(ConcatObserver, __super__);
|
3490 | function ConcatObserver(s, fn) {
|
3491 | this._s = s;
|
3492 | this._fn = fn;
|
3493 | __super__.call(this);
|
3494 | }
|
3495 |
|
3496 | ConcatObserver.prototype.next = function (x) { this._s.o.onNext(x); };
|
3497 | ConcatObserver.prototype.error = function (e) { this._s.o.onError(e); };
|
3498 | ConcatObserver.prototype.completed = function () { this._s.i++; this._fn(this._s); };
|
3499 |
|
3500 | return ConcatObserver;
|
3501 | }(AbstractObserver));
|
3502 |
|
3503 | var ConcatObservable = (function(__super__) {
|
3504 | inherits(ConcatObservable, __super__);
|
3505 | function ConcatObservable(sources) {
|
3506 | this._sources = sources;
|
3507 | __super__.call(this);
|
3508 | }
|
3509 |
|
3510 | function scheduleRecursive (state, recurse) {
|
3511 | if (state.disposable.isDisposed) { return; }
|
3512 | if (state.i === state.sources.length) { return state.o.onCompleted(); }
|
3513 |
|
3514 |
|
3515 | var currentValue = state.sources[state.i];
|
3516 | isPromise(currentValue) && (currentValue = observableFromPromise(currentValue));
|
3517 |
|
3518 | var d = new SingleAssignmentDisposable();
|
3519 | state.subscription.setDisposable(d);
|
3520 | d.setDisposable(currentValue.subscribe(new ConcatObserver(state, recurse)));
|
3521 | }
|
3522 |
|
3523 | ConcatObservable.prototype.subscribeCore = function(o) {
|
3524 | var subscription = new SerialDisposable();
|
3525 | var disposable = disposableCreate(noop);
|
3526 | var state = {
|
3527 | o: o,
|
3528 | i: 0,
|
3529 | subscription: subscription,
|
3530 | disposable: disposable,
|
3531 | sources: this._sources
|
3532 | };
|
3533 |
|
3534 | var cancelable = immediateScheduler.scheduleRecursive(state, scheduleRecursive);
|
3535 | return new NAryDisposable([subscription, disposable, cancelable]);
|
3536 | };
|
3537 |
|
3538 | return ConcatObservable;
|
3539 | }(ObservableBase));
|
3540 |
|
3541 | |
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | var observableConcat = Observable.concat = function () {
|
3547 | var args;
|
3548 | if (Array.isArray(arguments[0])) {
|
3549 | args = arguments[0];
|
3550 | } else {
|
3551 | args = new Array(arguments.length);
|
3552 | for(var i = 0, len = arguments.length; i < len; i++) { args[i] = arguments[i]; }
|
3553 | }
|
3554 | return new ConcatObservable(args);
|
3555 | };
|
3556 |
|
3557 | |
3558 |
|
3559 |
|
3560 |
|
3561 | observableProto.concatAll = function () {
|
3562 | return this.merge(1);
|
3563 | };
|
3564 |
|
3565 | var MergeObservable = (function (__super__) {
|
3566 | inherits(MergeObservable, __super__);
|
3567 |
|
3568 | function MergeObservable(source, maxConcurrent) {
|
3569 | this.source = source;
|
3570 | this.maxConcurrent = maxConcurrent;
|
3571 | __super__.call(this);
|
3572 | }
|
3573 |
|
3574 | MergeObservable.prototype.subscribeCore = function(observer) {
|
3575 | var g = new CompositeDisposable();
|
3576 | g.add(this.source.subscribe(new MergeObserver(observer, this.maxConcurrent, g)));
|
3577 | return g;
|
3578 | };
|
3579 |
|
3580 | return MergeObservable;
|
3581 |
|
3582 | }(ObservableBase));
|
3583 |
|
3584 | var MergeObserver = (function (__super__) {
|
3585 | function MergeObserver(o, max, g) {
|
3586 | this.o = o;
|
3587 | this.max = max;
|
3588 | this.g = g;
|
3589 | this.done = false;
|
3590 | this.q = [];
|
3591 | this.activeCount = 0;
|
3592 | __super__.call(this);
|
3593 | }
|
3594 |
|
3595 | inherits(MergeObserver, __super__);
|
3596 |
|
3597 | MergeObserver.prototype.handleSubscribe = function (xs) {
|
3598 | var sad = new SingleAssignmentDisposable();
|
3599 | this.g.add(sad);
|
3600 | isPromise(xs) && (xs = observableFromPromise(xs));
|
3601 | sad.setDisposable(xs.subscribe(new InnerObserver(this, sad)));
|
3602 | };
|
3603 |
|
3604 | MergeObserver.prototype.next = function (innerSource) {
|
3605 | if(this.activeCount < this.max) {
|
3606 | this.activeCount++;
|
3607 | this.handleSubscribe(innerSource);
|
3608 | } else {
|
3609 | this.q.push(innerSource);
|
3610 | }
|
3611 | };
|
3612 | MergeObserver.prototype.error = function (e) { this.o.onError(e); };
|
3613 | MergeObserver.prototype.completed = function () { this.done = true; this.activeCount === 0 && this.o.onCompleted(); };
|
3614 |
|
3615 | function InnerObserver(parent, sad) {
|
3616 | this.parent = parent;
|
3617 | this.sad = sad;
|
3618 | __super__.call(this);
|
3619 | }
|
3620 |
|
3621 | inherits(InnerObserver, __super__);
|
3622 |
|
3623 | InnerObserver.prototype.next = function (x) { this.parent.o.onNext(x); };
|
3624 | InnerObserver.prototype.error = function (e) { this.parent.o.onError(e); };
|
3625 | InnerObserver.prototype.completed = function () {
|
3626 | this.parent.g.remove(this.sad);
|
3627 | if (this.parent.q.length > 0) {
|
3628 | this.parent.handleSubscribe(this.parent.q.shift());
|
3629 | } else {
|
3630 | this.parent.activeCount--;
|
3631 | this.parent.done && this.parent.activeCount === 0 && this.parent.o.onCompleted();
|
3632 | }
|
3633 | };
|
3634 |
|
3635 | return MergeObserver;
|
3636 | }(AbstractObserver));
|
3637 |
|
3638 | |
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 | observableProto.merge = function (maxConcurrentOrOther) {
|
3645 | return typeof maxConcurrentOrOther !== 'number' ?
|
3646 | observableMerge(this, maxConcurrentOrOther) :
|
3647 | new MergeObservable(this, maxConcurrentOrOther);
|
3648 | };
|
3649 |
|
3650 | |
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 | var observableMerge = Observable.merge = function () {
|
3656 | var scheduler, sources = [], i, len = arguments.length;
|
3657 | if (!arguments[0]) {
|
3658 | scheduler = immediateScheduler;
|
3659 | for(i = 1; i < len; i++) { sources.push(arguments[i]); }
|
3660 | } else if (isScheduler(arguments[0])) {
|
3661 | scheduler = arguments[0];
|
3662 | for(i = 1; i < len; i++) { sources.push(arguments[i]); }
|
3663 | } else {
|
3664 | scheduler = immediateScheduler;
|
3665 | for(i = 0; i < len; i++) { sources.push(arguments[i]); }
|
3666 | }
|
3667 | if (Array.isArray(sources[0])) {
|
3668 | sources = sources[0];
|
3669 | }
|
3670 | return observableOf(scheduler, sources).mergeAll();
|
3671 | };
|
3672 |
|
3673 | var MergeAllObservable = (function (__super__) {
|
3674 | inherits(MergeAllObservable, __super__);
|
3675 |
|
3676 | function MergeAllObservable(source) {
|
3677 | this.source = source;
|
3678 | __super__.call(this);
|
3679 | }
|
3680 |
|
3681 | MergeAllObservable.prototype.subscribeCore = function (o) {
|
3682 | var g = new CompositeDisposable(), m = new SingleAssignmentDisposable();
|
3683 | g.add(m);
|
3684 | m.setDisposable(this.source.subscribe(new MergeAllObserver(o, g)));
|
3685 | return g;
|
3686 | };
|
3687 |
|
3688 | return MergeAllObservable;
|
3689 | }(ObservableBase));
|
3690 |
|
3691 | var MergeAllObserver = (function (__super__) {
|
3692 | function MergeAllObserver(o, g) {
|
3693 | this.o = o;
|
3694 | this.g = g;
|
3695 | this.done = false;
|
3696 | __super__.call(this);
|
3697 | }
|
3698 |
|
3699 | inherits(MergeAllObserver, __super__);
|
3700 |
|
3701 | MergeAllObserver.prototype.next = function(innerSource) {
|
3702 | var sad = new SingleAssignmentDisposable();
|
3703 | this.g.add(sad);
|
3704 | isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
3705 | sad.setDisposable(innerSource.subscribe(new InnerObserver(this, sad)));
|
3706 | };
|
3707 |
|
3708 | MergeAllObserver.prototype.error = function (e) {
|
3709 | this.o.onError(e);
|
3710 | };
|
3711 |
|
3712 | MergeAllObserver.prototype.completed = function () {
|
3713 | this.done = true;
|
3714 | this.g.length === 1 && this.o.onCompleted();
|
3715 | };
|
3716 |
|
3717 | function InnerObserver(parent, sad) {
|
3718 | this.parent = parent;
|
3719 | this.sad = sad;
|
3720 | __super__.call(this);
|
3721 | }
|
3722 |
|
3723 | inherits(InnerObserver, __super__);
|
3724 |
|
3725 | InnerObserver.prototype.next = function (x) {
|
3726 | this.parent.o.onNext(x);
|
3727 | };
|
3728 | InnerObserver.prototype.error = function (e) {
|
3729 | this.parent.o.onError(e);
|
3730 | };
|
3731 | InnerObserver.prototype.completed = function () {
|
3732 | this.parent.g.remove(this.sad);
|
3733 | this.parent.done && this.parent.g.length === 1 && this.parent.o.onCompleted();
|
3734 | };
|
3735 |
|
3736 | return MergeAllObserver;
|
3737 | }(AbstractObserver));
|
3738 |
|
3739 | |
3740 |
|
3741 |
|
3742 |
|
3743 | observableProto.mergeAll = function () {
|
3744 | return new MergeAllObservable(this);
|
3745 | };
|
3746 |
|
3747 | var CompositeError = Rx.CompositeError = function(errors) {
|
3748 | this.innerErrors = errors;
|
3749 | this.message = 'This contains multiple errors. Check the innerErrors';
|
3750 | Error.call(this);
|
3751 | };
|
3752 | CompositeError.prototype = Object.create(Error.prototype);
|
3753 | CompositeError.prototype.name = 'CompositeError';
|
3754 |
|
3755 | var MergeDelayErrorObservable = (function(__super__) {
|
3756 | inherits(MergeDelayErrorObservable, __super__);
|
3757 | function MergeDelayErrorObservable(source) {
|
3758 | this.source = source;
|
3759 | __super__.call(this);
|
3760 | }
|
3761 |
|
3762 | MergeDelayErrorObservable.prototype.subscribeCore = function (o) {
|
3763 | var group = new CompositeDisposable(),
|
3764 | m = new SingleAssignmentDisposable(),
|
3765 | state = { isStopped: false, errors: [], o: o };
|
3766 |
|
3767 | group.add(m);
|
3768 | m.setDisposable(this.source.subscribe(new MergeDelayErrorObserver(group, state)));
|
3769 |
|
3770 | return group;
|
3771 | };
|
3772 |
|
3773 | return MergeDelayErrorObservable;
|
3774 | }(ObservableBase));
|
3775 |
|
3776 | var MergeDelayErrorObserver = (function(__super__) {
|
3777 | inherits(MergeDelayErrorObserver, __super__);
|
3778 | function MergeDelayErrorObserver(group, state) {
|
3779 | this._group = group;
|
3780 | this._state = state;
|
3781 | __super__.call(this);
|
3782 | }
|
3783 |
|
3784 | function setCompletion(o, errors) {
|
3785 | if (errors.length === 0) {
|
3786 | o.onCompleted();
|
3787 | } else if (errors.length === 1) {
|
3788 | o.onError(errors[0]);
|
3789 | } else {
|
3790 | o.onError(new CompositeError(errors));
|
3791 | }
|
3792 | }
|
3793 |
|
3794 | MergeDelayErrorObserver.prototype.next = function (x) {
|
3795 | var inner = new SingleAssignmentDisposable();
|
3796 | this._group.add(inner);
|
3797 |
|
3798 |
|
3799 | isPromise(x) && (x = observableFromPromise(x));
|
3800 | inner.setDisposable(x.subscribe(new InnerObserver(inner, this._group, this._state)));
|
3801 | };
|
3802 |
|
3803 | MergeDelayErrorObserver.prototype.error = function (e) {
|
3804 | this._state.errors.push(e);
|
3805 | this._state.isStopped = true;
|
3806 | this._group.length === 1 && setCompletion(this._state.o, this._state.errors);
|
3807 | };
|
3808 |
|
3809 | MergeDelayErrorObserver.prototype.completed = function () {
|
3810 | this._state.isStopped = true;
|
3811 | this._group.length === 1 && setCompletion(this._state.o, this._state.errors);
|
3812 | };
|
3813 |
|
3814 | inherits(InnerObserver, __super__);
|
3815 | function InnerObserver(inner, group, state) {
|
3816 | this._inner = inner;
|
3817 | this._group = group;
|
3818 | this._state = state;
|
3819 | __super__.call(this);
|
3820 | }
|
3821 |
|
3822 | InnerObserver.prototype.next = function (x) { this._state.o.onNext(x); };
|
3823 | InnerObserver.prototype.error = function (e) {
|
3824 | this._state.errors.push(e);
|
3825 | this._group.remove(this._inner);
|
3826 | this._state.isStopped && this._group.length === 1 && setCompletion(this._state.o, this._state.errors);
|
3827 | };
|
3828 | InnerObserver.prototype.completed = function () {
|
3829 | this._group.remove(this._inner);
|
3830 | this._state.isStopped && this._group.length === 1 && setCompletion(this._state.o, this._state.errors);
|
3831 | };
|
3832 |
|
3833 | return MergeDelayErrorObserver;
|
3834 | }(AbstractObserver));
|
3835 |
|
3836 | |
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 | Observable.mergeDelayError = function() {
|
3848 | var args;
|
3849 | if (Array.isArray(arguments[0])) {
|
3850 | args = arguments[0];
|
3851 | } else {
|
3852 | var len = arguments.length;
|
3853 | args = new Array(len);
|
3854 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
3855 | }
|
3856 | var source = observableOf(null, args);
|
3857 | return new MergeDelayErrorObservable(source);
|
3858 | };
|
3859 |
|
3860 | |
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 | observableProto.onErrorResumeNext = function (second) {
|
3866 | if (!second) { throw new Error('Second observable is required'); }
|
3867 | return onErrorResumeNext([this, second]);
|
3868 | };
|
3869 |
|
3870 | var OnErrorResumeNextObservable = (function(__super__) {
|
3871 | inherits(OnErrorResumeNextObservable, __super__);
|
3872 | function OnErrorResumeNextObservable(sources) {
|
3873 | this.sources = sources;
|
3874 | __super__.call(this);
|
3875 | }
|
3876 |
|
3877 | function scheduleMethod(state, recurse) {
|
3878 | if (state.pos < state.sources.length) {
|
3879 | var current = state.sources[state.pos++];
|
3880 | isPromise(current) && (current = observableFromPromise(current));
|
3881 | var d = new SingleAssignmentDisposable();
|
3882 | state.subscription.setDisposable(d);
|
3883 | d.setDisposable(current.subscribe(new OnErrorResumeNextObserver(state, recurse)));
|
3884 | } else {
|
3885 | state.o.onCompleted();
|
3886 | }
|
3887 | }
|
3888 |
|
3889 | OnErrorResumeNextObservable.prototype.subscribeCore = function (o) {
|
3890 | var subscription = new SerialDisposable(),
|
3891 | state = {pos: 0, subscription: subscription, o: o, sources: this.sources },
|
3892 | cancellable = immediateScheduler.scheduleRecursive(state, scheduleMethod);
|
3893 |
|
3894 | return new BinaryDisposable(subscription, cancellable);
|
3895 | };
|
3896 |
|
3897 | return OnErrorResumeNextObservable;
|
3898 | }(ObservableBase));
|
3899 |
|
3900 | var OnErrorResumeNextObserver = (function(__super__) {
|
3901 | inherits(OnErrorResumeNextObserver, __super__);
|
3902 | function OnErrorResumeNextObserver(state, recurse) {
|
3903 | this._state = state;
|
3904 | this._recurse = recurse;
|
3905 | __super__.call(this);
|
3906 | }
|
3907 |
|
3908 | OnErrorResumeNextObserver.prototype.next = function (x) { this._state.o.onNext(x); };
|
3909 | OnErrorResumeNextObserver.prototype.error = function () { this._recurse(this._state); };
|
3910 | OnErrorResumeNextObserver.prototype.completed = function () { this._recurse(this._state); };
|
3911 |
|
3912 | return OnErrorResumeNextObserver;
|
3913 | }(AbstractObserver));
|
3914 |
|
3915 | |
3916 |
|
3917 |
|
3918 |
|
3919 | var onErrorResumeNext = Observable.onErrorResumeNext = function () {
|
3920 | var sources = [];
|
3921 | if (Array.isArray(arguments[0])) {
|
3922 | sources = arguments[0];
|
3923 | } else {
|
3924 | var len = arguments.length;
|
3925 | sources = new Array(len);
|
3926 | for(var i = 0; i < len; i++) { sources[i] = arguments[i]; }
|
3927 | }
|
3928 | return new OnErrorResumeNextObservable(sources);
|
3929 | };
|
3930 |
|
3931 | var SkipUntilObservable = (function(__super__) {
|
3932 | inherits(SkipUntilObservable, __super__);
|
3933 |
|
3934 | function SkipUntilObservable(source, other) {
|
3935 | this._s = source;
|
3936 | this._o = isPromise(other) ? observableFromPromise(other) : other;
|
3937 | this._open = false;
|
3938 | __super__.call(this);
|
3939 | }
|
3940 |
|
3941 | SkipUntilObservable.prototype.subscribeCore = function(o) {
|
3942 | var leftSubscription = new SingleAssignmentDisposable();
|
3943 | leftSubscription.setDisposable(this._s.subscribe(new SkipUntilSourceObserver(o, this)));
|
3944 |
|
3945 | isPromise(this._o) && (this._o = observableFromPromise(this._o));
|
3946 |
|
3947 | var rightSubscription = new SingleAssignmentDisposable();
|
3948 | rightSubscription.setDisposable(this._o.subscribe(new SkipUntilOtherObserver(o, this, rightSubscription)));
|
3949 |
|
3950 | return new BinaryDisposable(leftSubscription, rightSubscription);
|
3951 | };
|
3952 |
|
3953 | return SkipUntilObservable;
|
3954 | }(ObservableBase));
|
3955 |
|
3956 | var SkipUntilSourceObserver = (function(__super__) {
|
3957 | inherits(SkipUntilSourceObserver, __super__);
|
3958 | function SkipUntilSourceObserver(o, p) {
|
3959 | this._o = o;
|
3960 | this._p = p;
|
3961 | __super__.call(this);
|
3962 | }
|
3963 |
|
3964 | SkipUntilSourceObserver.prototype.next = function (x) {
|
3965 | this._p._open && this._o.onNext(x);
|
3966 | };
|
3967 |
|
3968 | SkipUntilSourceObserver.prototype.error = function (err) {
|
3969 | this._o.onError(err);
|
3970 | };
|
3971 |
|
3972 | SkipUntilSourceObserver.prototype.onCompleted = function () {
|
3973 | this._p._open && this._o.onCompleted();
|
3974 | };
|
3975 |
|
3976 | return SkipUntilSourceObserver;
|
3977 | }(AbstractObserver));
|
3978 |
|
3979 | var SkipUntilOtherObserver = (function(__super__) {
|
3980 | inherits(SkipUntilOtherObserver, __super__);
|
3981 | function SkipUntilOtherObserver(o, p, r) {
|
3982 | this._o = o;
|
3983 | this._p = p;
|
3984 | this._r = r;
|
3985 | __super__.call(this);
|
3986 | }
|
3987 |
|
3988 | SkipUntilOtherObserver.prototype.next = function () {
|
3989 | this._p._open = true;
|
3990 | this._r.dispose();
|
3991 | };
|
3992 |
|
3993 | SkipUntilOtherObserver.prototype.error = function (err) {
|
3994 | this._o.onError(err);
|
3995 | };
|
3996 |
|
3997 | SkipUntilOtherObserver.prototype.onCompleted = function () {
|
3998 | this._r.dispose();
|
3999 | };
|
4000 |
|
4001 | return SkipUntilOtherObserver;
|
4002 | }(AbstractObserver));
|
4003 |
|
4004 | |
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 | observableProto.skipUntil = function (other) {
|
4010 | return new SkipUntilObservable(this, other);
|
4011 | };
|
4012 |
|
4013 | var SwitchObservable = (function(__super__) {
|
4014 | inherits(SwitchObservable, __super__);
|
4015 | function SwitchObservable(source) {
|
4016 | this.source = source;
|
4017 | __super__.call(this);
|
4018 | }
|
4019 |
|
4020 | SwitchObservable.prototype.subscribeCore = function (o) {
|
4021 | var inner = new SerialDisposable(), s = this.source.subscribe(new SwitchObserver(o, inner));
|
4022 | return new BinaryDisposable(s, inner);
|
4023 | };
|
4024 |
|
4025 | inherits(SwitchObserver, AbstractObserver);
|
4026 | function SwitchObserver(o, inner) {
|
4027 | this.o = o;
|
4028 | this.inner = inner;
|
4029 | this.stopped = false;
|
4030 | this.latest = 0;
|
4031 | this.hasLatest = false;
|
4032 | AbstractObserver.call(this);
|
4033 | }
|
4034 |
|
4035 | SwitchObserver.prototype.next = function (innerSource) {
|
4036 | var d = new SingleAssignmentDisposable(), id = ++this.latest;
|
4037 | this.hasLatest = true;
|
4038 | this.inner.setDisposable(d);
|
4039 | isPromise(innerSource) && (innerSource = observableFromPromise(innerSource));
|
4040 | d.setDisposable(innerSource.subscribe(new InnerObserver(this, id)));
|
4041 | };
|
4042 |
|
4043 | SwitchObserver.prototype.error = function (e) {
|
4044 | this.o.onError(e);
|
4045 | };
|
4046 |
|
4047 | SwitchObserver.prototype.completed = function () {
|
4048 | this.stopped = true;
|
4049 | !this.hasLatest && this.o.onCompleted();
|
4050 | };
|
4051 |
|
4052 | inherits(InnerObserver, AbstractObserver);
|
4053 | function InnerObserver(parent, id) {
|
4054 | this.parent = parent;
|
4055 | this.id = id;
|
4056 | AbstractObserver.call(this);
|
4057 | }
|
4058 | InnerObserver.prototype.next = function (x) {
|
4059 | this.parent.latest === this.id && this.parent.o.onNext(x);
|
4060 | };
|
4061 |
|
4062 | InnerObserver.prototype.error = function (e) {
|
4063 | this.parent.latest === this.id && this.parent.o.onError(e);
|
4064 | };
|
4065 |
|
4066 | InnerObserver.prototype.completed = function () {
|
4067 | if (this.parent.latest === this.id) {
|
4068 | this.parent.hasLatest = false;
|
4069 | this.parent.stopped && this.parent.o.onCompleted();
|
4070 | }
|
4071 | };
|
4072 |
|
4073 | return SwitchObservable;
|
4074 | }(ObservableBase));
|
4075 |
|
4076 | |
4077 |
|
4078 |
|
4079 |
|
4080 | observableProto['switch'] = observableProto.switchLatest = function () {
|
4081 | return new SwitchObservable(this);
|
4082 | };
|
4083 |
|
4084 | var TakeUntilObservable = (function(__super__) {
|
4085 | inherits(TakeUntilObservable, __super__);
|
4086 |
|
4087 | function TakeUntilObservable(source, other) {
|
4088 | this.source = source;
|
4089 | this.other = isPromise(other) ? observableFromPromise(other) : other;
|
4090 | __super__.call(this);
|
4091 | }
|
4092 |
|
4093 | TakeUntilObservable.prototype.subscribeCore = function(o) {
|
4094 | return new BinaryDisposable(
|
4095 | this.source.subscribe(o),
|
4096 | this.other.subscribe(new TakeUntilObserver(o))
|
4097 | );
|
4098 | };
|
4099 |
|
4100 | return TakeUntilObservable;
|
4101 | }(ObservableBase));
|
4102 |
|
4103 | var TakeUntilObserver = (function(__super__) {
|
4104 | inherits(TakeUntilObserver, __super__);
|
4105 | function TakeUntilObserver(o) {
|
4106 | this._o = o;
|
4107 | __super__.call(this);
|
4108 | }
|
4109 |
|
4110 | TakeUntilObserver.prototype.next = function () {
|
4111 | this._o.onCompleted();
|
4112 | };
|
4113 |
|
4114 | TakeUntilObserver.prototype.error = function (err) {
|
4115 | this._o.onError(err);
|
4116 | };
|
4117 |
|
4118 | TakeUntilObserver.prototype.onCompleted = noop;
|
4119 |
|
4120 | return TakeUntilObserver;
|
4121 | }(AbstractObserver));
|
4122 |
|
4123 | |
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 | observableProto.takeUntil = function (other) {
|
4129 | return new TakeUntilObservable(this, other);
|
4130 | };
|
4131 |
|
4132 | function falseFactory() { return false; }
|
4133 | function argumentsToArray() {
|
4134 | var len = arguments.length, args = new Array(len);
|
4135 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4136 | return args;
|
4137 | }
|
4138 |
|
4139 | var WithLatestFromObservable = (function(__super__) {
|
4140 | inherits(WithLatestFromObservable, __super__);
|
4141 | function WithLatestFromObservable(source, sources, resultSelector) {
|
4142 | this._s = source;
|
4143 | this._ss = sources;
|
4144 | this._cb = resultSelector;
|
4145 | __super__.call(this);
|
4146 | }
|
4147 |
|
4148 | WithLatestFromObservable.prototype.subscribeCore = function (o) {
|
4149 | var len = this._ss.length;
|
4150 | var state = {
|
4151 | hasValue: arrayInitialize(len, falseFactory),
|
4152 | hasValueAll: false,
|
4153 | values: new Array(len)
|
4154 | };
|
4155 |
|
4156 | var n = this._ss.length, subscriptions = new Array(n + 1);
|
4157 | for (var i = 0; i < n; i++) {
|
4158 | var other = this._ss[i], sad = new SingleAssignmentDisposable();
|
4159 | isPromise(other) && (other = observableFromPromise(other));
|
4160 | sad.setDisposable(other.subscribe(new WithLatestFromOtherObserver(o, i, state)));
|
4161 | subscriptions[i] = sad;
|
4162 | }
|
4163 |
|
4164 | var outerSad = new SingleAssignmentDisposable();
|
4165 | outerSad.setDisposable(this._s.subscribe(new WithLatestFromSourceObserver(o, this._cb, state)));
|
4166 | subscriptions[n] = outerSad;
|
4167 |
|
4168 | return new NAryDisposable(subscriptions);
|
4169 | };
|
4170 |
|
4171 | return WithLatestFromObservable;
|
4172 | }(ObservableBase));
|
4173 |
|
4174 | var WithLatestFromOtherObserver = (function (__super__) {
|
4175 | inherits(WithLatestFromOtherObserver, __super__);
|
4176 | function WithLatestFromOtherObserver(o, i, state) {
|
4177 | this._o = o;
|
4178 | this._i = i;
|
4179 | this._state = state;
|
4180 | __super__.call(this);
|
4181 | }
|
4182 |
|
4183 | WithLatestFromOtherObserver.prototype.next = function (x) {
|
4184 | this._state.values[this._i] = x;
|
4185 | this._state.hasValue[this._i] = true;
|
4186 | this._state.hasValueAll = this._state.hasValue.every(identity);
|
4187 | };
|
4188 |
|
4189 | WithLatestFromOtherObserver.prototype.error = function (e) {
|
4190 | this._o.onError(e);
|
4191 | };
|
4192 |
|
4193 | WithLatestFromOtherObserver.prototype.completed = noop;
|
4194 |
|
4195 | return WithLatestFromOtherObserver;
|
4196 | }(AbstractObserver));
|
4197 |
|
4198 | var WithLatestFromSourceObserver = (function (__super__) {
|
4199 | inherits(WithLatestFromSourceObserver, __super__);
|
4200 | function WithLatestFromSourceObserver(o, cb, state) {
|
4201 | this._o = o;
|
4202 | this._cb = cb;
|
4203 | this._state = state;
|
4204 | __super__.call(this);
|
4205 | }
|
4206 |
|
4207 | WithLatestFromSourceObserver.prototype.next = function (x) {
|
4208 | var allValues = [x].concat(this._state.values);
|
4209 | if (!this._state.hasValueAll) { return; }
|
4210 | var res = tryCatch(this._cb).apply(null, allValues);
|
4211 | if (res === errorObj) { return this._o.onError(res.e); }
|
4212 | this._o.onNext(res);
|
4213 | };
|
4214 |
|
4215 | WithLatestFromSourceObserver.prototype.error = function (e) {
|
4216 | this._o.onError(e);
|
4217 | };
|
4218 |
|
4219 | WithLatestFromSourceObserver.prototype.completed = function () {
|
4220 | this._o.onCompleted();
|
4221 | };
|
4222 |
|
4223 | return WithLatestFromSourceObserver;
|
4224 | }(AbstractObserver));
|
4225 |
|
4226 | |
4227 |
|
4228 |
|
4229 |
|
4230 | observableProto.withLatestFrom = function () {
|
4231 | if (arguments.length === 0) { throw new Error('invalid arguments'); }
|
4232 |
|
4233 | var len = arguments.length, args = new Array(len);
|
4234 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4235 | var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
4236 | Array.isArray(args[0]) && (args = args[0]);
|
4237 |
|
4238 | return new WithLatestFromObservable(this, args, resultSelector);
|
4239 | };
|
4240 |
|
4241 | function falseFactory() { return false; }
|
4242 | function emptyArrayFactory() { return []; }
|
4243 |
|
4244 | var ZipObservable = (function(__super__) {
|
4245 | inherits(ZipObservable, __super__);
|
4246 | function ZipObservable(sources, resultSelector) {
|
4247 | this._s = sources;
|
4248 | this._cb = resultSelector;
|
4249 | __super__.call(this);
|
4250 | }
|
4251 |
|
4252 | ZipObservable.prototype.subscribeCore = function(observer) {
|
4253 | var n = this._s.length,
|
4254 | subscriptions = new Array(n),
|
4255 | done = arrayInitialize(n, falseFactory),
|
4256 | q = arrayInitialize(n, emptyArrayFactory);
|
4257 |
|
4258 | for (var i = 0; i < n; i++) {
|
4259 | var source = this._s[i], sad = new SingleAssignmentDisposable();
|
4260 | subscriptions[i] = sad;
|
4261 | isPromise(source) && (source = observableFromPromise(source));
|
4262 | sad.setDisposable(source.subscribe(new ZipObserver(observer, i, this, q, done)));
|
4263 | }
|
4264 |
|
4265 | return new NAryDisposable(subscriptions);
|
4266 | };
|
4267 |
|
4268 | return ZipObservable;
|
4269 | }(ObservableBase));
|
4270 |
|
4271 | var ZipObserver = (function (__super__) {
|
4272 | inherits(ZipObserver, __super__);
|
4273 | function ZipObserver(o, i, p, q, d) {
|
4274 | this._o = o;
|
4275 | this._i = i;
|
4276 | this._p = p;
|
4277 | this._q = q;
|
4278 | this._d = d;
|
4279 | __super__.call(this);
|
4280 | }
|
4281 |
|
4282 | function notEmpty(x) { return x.length > 0; }
|
4283 | function shiftEach(x) { return x.shift(); }
|
4284 | function notTheSame(i) {
|
4285 | return function (x, j) {
|
4286 | return j !== i;
|
4287 | };
|
4288 | }
|
4289 |
|
4290 | ZipObserver.prototype.next = function (x) {
|
4291 | this._q[this._i].push(x);
|
4292 | if (this._q.every(notEmpty)) {
|
4293 | var queuedValues = this._q.map(shiftEach);
|
4294 | var res = tryCatch(this._p._cb).apply(null, queuedValues);
|
4295 | if (res === errorObj) { return this._o.onError(res.e); }
|
4296 | this._o.onNext(res);
|
4297 | } else if (this._d.filter(notTheSame(this._i)).every(identity)) {
|
4298 | this._o.onCompleted();
|
4299 | }
|
4300 | };
|
4301 |
|
4302 | ZipObserver.prototype.error = function (e) {
|
4303 | this._o.onError(e);
|
4304 | };
|
4305 |
|
4306 | ZipObserver.prototype.completed = function () {
|
4307 | this._d[this._i] = true;
|
4308 | this._d.every(identity) && this._o.onCompleted();
|
4309 | };
|
4310 |
|
4311 | return ZipObserver;
|
4312 | }(AbstractObserver));
|
4313 |
|
4314 | |
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 | observableProto.zip = function () {
|
4320 | if (arguments.length === 0) { throw new Error('invalid arguments'); }
|
4321 |
|
4322 | var len = arguments.length, args = new Array(len);
|
4323 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4324 | var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
4325 | Array.isArray(args[0]) && (args = args[0]);
|
4326 |
|
4327 | var parent = this;
|
4328 | args.unshift(parent);
|
4329 |
|
4330 | return new ZipObservable(args, resultSelector);
|
4331 | };
|
4332 |
|
4333 | |
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 | Observable.zip = function () {
|
4340 | var len = arguments.length, args = new Array(len);
|
4341 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4342 | if (Array.isArray(args[0])) {
|
4343 | args = isFunction(args[1]) ? args[0].concat(args[1]) : args[0];
|
4344 | }
|
4345 | var first = args.shift();
|
4346 | return first.zip.apply(first, args);
|
4347 | };
|
4348 |
|
4349 | function falseFactory() { return false; }
|
4350 | function emptyArrayFactory() { return []; }
|
4351 | function argumentsToArray() {
|
4352 | var len = arguments.length, args = new Array(len);
|
4353 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4354 | return args;
|
4355 | }
|
4356 |
|
4357 | var ZipIterableObservable = (function(__super__) {
|
4358 | inherits(ZipIterableObservable, __super__);
|
4359 | function ZipIterableObservable(sources, cb) {
|
4360 | this.sources = sources;
|
4361 | this._cb = cb;
|
4362 | __super__.call(this);
|
4363 | }
|
4364 |
|
4365 | ZipIterableObservable.prototype.subscribeCore = function (o) {
|
4366 | var sources = this.sources, len = sources.length, subscriptions = new Array(len);
|
4367 |
|
4368 | var state = {
|
4369 | q: arrayInitialize(len, emptyArrayFactory),
|
4370 | done: arrayInitialize(len, falseFactory),
|
4371 | cb: this._cb,
|
4372 | o: o
|
4373 | };
|
4374 |
|
4375 | for (var i = 0; i < len; i++) {
|
4376 | (function (i) {
|
4377 | var source = sources[i], sad = new SingleAssignmentDisposable();
|
4378 | (isArrayLike(source) || isIterable(source)) && (source = observableFrom(source));
|
4379 |
|
4380 | subscriptions[i] = sad;
|
4381 | sad.setDisposable(source.subscribe(new ZipIterableObserver(state, i)));
|
4382 | }(i));
|
4383 | }
|
4384 |
|
4385 | return new NAryDisposable(subscriptions);
|
4386 | };
|
4387 |
|
4388 | return ZipIterableObservable;
|
4389 | }(ObservableBase));
|
4390 |
|
4391 | var ZipIterableObserver = (function (__super__) {
|
4392 | inherits(ZipIterableObserver, __super__);
|
4393 | function ZipIterableObserver(s, i) {
|
4394 | this._s = s;
|
4395 | this._i = i;
|
4396 | __super__.call(this);
|
4397 | }
|
4398 |
|
4399 | function notEmpty(x) { return x.length > 0; }
|
4400 | function shiftEach(x) { return x.shift(); }
|
4401 | function notTheSame(i) {
|
4402 | return function (x, j) {
|
4403 | return j !== i;
|
4404 | };
|
4405 | }
|
4406 |
|
4407 | ZipIterableObserver.prototype.next = function (x) {
|
4408 | this._s.q[this._i].push(x);
|
4409 | if (this._s.q.every(notEmpty)) {
|
4410 | var queuedValues = this._s.q.map(shiftEach),
|
4411 | res = tryCatch(this._s.cb).apply(null, queuedValues);
|
4412 | if (res === errorObj) { return this._s.o.onError(res.e); }
|
4413 | this._s.o.onNext(res);
|
4414 | } else if (this._s.done.filter(notTheSame(this._i)).every(identity)) {
|
4415 | this._s.o.onCompleted();
|
4416 | }
|
4417 | };
|
4418 |
|
4419 | ZipIterableObserver.prototype.error = function (e) { this._s.o.onError(e); };
|
4420 |
|
4421 | ZipIterableObserver.prototype.completed = function () {
|
4422 | this._s.done[this._i] = true;
|
4423 | this._s.done.every(identity) && this._s.o.onCompleted();
|
4424 | };
|
4425 |
|
4426 | return ZipIterableObserver;
|
4427 | }(AbstractObserver));
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 | observableProto.zipIterable = function () {
|
4435 | if (arguments.length === 0) { throw new Error('invalid arguments'); }
|
4436 |
|
4437 | var len = arguments.length, args = new Array(len);
|
4438 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
4439 | var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
4440 |
|
4441 | var parent = this;
|
4442 | args.unshift(parent);
|
4443 | return new ZipIterableObservable(args, resultSelector);
|
4444 | };
|
4445 |
|
4446 | function asObservable(source) {
|
4447 | return function subscribe(o) { return source.subscribe(o); };
|
4448 | }
|
4449 |
|
4450 | |
4451 |
|
4452 |
|
4453 |
|
4454 | observableProto.asObservable = function () {
|
4455 | return new AnonymousObservable(asObservable(this), this);
|
4456 | };
|
4457 |
|
4458 | function toArray(x) { return x.toArray(); }
|
4459 | function notEmpty(x) { return x.length > 0; }
|
4460 |
|
4461 | |
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 | observableProto.bufferWithCount = function (count, skip) {
|
4468 | typeof skip !== 'number' && (skip = count);
|
4469 | return this.windowWithCount(count, skip)
|
4470 | .flatMap(toArray)
|
4471 | .filter(notEmpty);
|
4472 | };
|
4473 |
|
4474 | var DematerializeObservable = (function (__super__) {
|
4475 | inherits(DematerializeObservable, __super__);
|
4476 | function DematerializeObservable(source) {
|
4477 | this.source = source;
|
4478 | __super__.call(this);
|
4479 | }
|
4480 |
|
4481 | DematerializeObservable.prototype.subscribeCore = function (o) {
|
4482 | return this.source.subscribe(new DematerializeObserver(o));
|
4483 | };
|
4484 |
|
4485 | return DematerializeObservable;
|
4486 | }(ObservableBase));
|
4487 |
|
4488 | var DematerializeObserver = (function (__super__) {
|
4489 | inherits(DematerializeObserver, __super__);
|
4490 |
|
4491 | function DematerializeObserver(o) {
|
4492 | this._o = o;
|
4493 | __super__.call(this);
|
4494 | }
|
4495 |
|
4496 | DematerializeObserver.prototype.next = function (x) { x.accept(this._o); };
|
4497 | DematerializeObserver.prototype.error = function (e) { this._o.onError(e); };
|
4498 | DematerializeObserver.prototype.completed = function () { this._o.onCompleted(); };
|
4499 |
|
4500 | return DematerializeObserver;
|
4501 | }(AbstractObserver));
|
4502 |
|
4503 | |
4504 |
|
4505 |
|
4506 |
|
4507 | observableProto.dematerialize = function () {
|
4508 | return new DematerializeObservable(this);
|
4509 | };
|
4510 |
|
4511 | var DistinctUntilChangedObservable = (function(__super__) {
|
4512 | inherits(DistinctUntilChangedObservable, __super__);
|
4513 | function DistinctUntilChangedObservable(source, keyFn, comparer) {
|
4514 | this.source = source;
|
4515 | this.keyFn = keyFn;
|
4516 | this.comparer = comparer;
|
4517 | __super__.call(this);
|
4518 | }
|
4519 |
|
4520 | DistinctUntilChangedObservable.prototype.subscribeCore = function (o) {
|
4521 | return this.source.subscribe(new DistinctUntilChangedObserver(o, this.keyFn, this.comparer));
|
4522 | };
|
4523 |
|
4524 | return DistinctUntilChangedObservable;
|
4525 | }(ObservableBase));
|
4526 |
|
4527 | var DistinctUntilChangedObserver = (function(__super__) {
|
4528 | inherits(DistinctUntilChangedObserver, __super__);
|
4529 | function DistinctUntilChangedObserver(o, keyFn, comparer) {
|
4530 | this.o = o;
|
4531 | this.keyFn = keyFn;
|
4532 | this.comparer = comparer;
|
4533 | this.hasCurrentKey = false;
|
4534 | this.currentKey = null;
|
4535 | __super__.call(this);
|
4536 | }
|
4537 |
|
4538 | DistinctUntilChangedObserver.prototype.next = function (x) {
|
4539 | var key = x, comparerEquals;
|
4540 | if (isFunction(this.keyFn)) {
|
4541 | key = tryCatch(this.keyFn)(x);
|
4542 | if (key === errorObj) { return this.o.onError(key.e); }
|
4543 | }
|
4544 | if (this.hasCurrentKey) {
|
4545 | comparerEquals = tryCatch(this.comparer)(this.currentKey, key);
|
4546 | if (comparerEquals === errorObj) { return this.o.onError(comparerEquals.e); }
|
4547 | }
|
4548 | if (!this.hasCurrentKey || !comparerEquals) {
|
4549 | this.hasCurrentKey = true;
|
4550 | this.currentKey = key;
|
4551 | this.o.onNext(x);
|
4552 | }
|
4553 | };
|
4554 | DistinctUntilChangedObserver.prototype.error = function(e) {
|
4555 | this.o.onError(e);
|
4556 | };
|
4557 | DistinctUntilChangedObserver.prototype.completed = function () {
|
4558 | this.o.onCompleted();
|
4559 | };
|
4560 |
|
4561 | return DistinctUntilChangedObserver;
|
4562 | }(AbstractObserver));
|
4563 |
|
4564 | |
4565 |
|
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 | observableProto.distinctUntilChanged = function (keyFn, comparer) {
|
4571 | comparer || (comparer = defaultComparer);
|
4572 | return new DistinctUntilChangedObservable(this, keyFn, comparer);
|
4573 | };
|
4574 |
|
4575 | var TapObservable = (function(__super__) {
|
4576 | inherits(TapObservable,__super__);
|
4577 | function TapObservable(source, observerOrOnNext, onError, onCompleted) {
|
4578 | this.source = source;
|
4579 | this._oN = observerOrOnNext;
|
4580 | this._oE = onError;
|
4581 | this._oC = onCompleted;
|
4582 | __super__.call(this);
|
4583 | }
|
4584 |
|
4585 | TapObservable.prototype.subscribeCore = function(o) {
|
4586 | return this.source.subscribe(new InnerObserver(o, this));
|
4587 | };
|
4588 |
|
4589 | inherits(InnerObserver, AbstractObserver);
|
4590 | function InnerObserver(o, p) {
|
4591 | this.o = o;
|
4592 | this.t = !p._oN || isFunction(p._oN) ?
|
4593 | observerCreate(p._oN || noop, p._oE || noop, p._oC || noop) :
|
4594 | p._oN;
|
4595 | this.isStopped = false;
|
4596 | AbstractObserver.call(this);
|
4597 | }
|
4598 | InnerObserver.prototype.next = function(x) {
|
4599 | var res = tryCatch(this.t.onNext).call(this.t, x);
|
4600 | if (res === errorObj) { this.o.onError(res.e); }
|
4601 | this.o.onNext(x);
|
4602 | };
|
4603 | InnerObserver.prototype.error = function(err) {
|
4604 | var res = tryCatch(this.t.onError).call(this.t, err);
|
4605 | if (res === errorObj) { return this.o.onError(res.e); }
|
4606 | this.o.onError(err);
|
4607 | };
|
4608 | InnerObserver.prototype.completed = function() {
|
4609 | var res = tryCatch(this.t.onCompleted).call(this.t);
|
4610 | if (res === errorObj) { return this.o.onError(res.e); }
|
4611 | this.o.onCompleted();
|
4612 | };
|
4613 |
|
4614 | return TapObservable;
|
4615 | }(ObservableBase));
|
4616 |
|
4617 | |
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 | observableProto['do'] = observableProto.tap = observableProto.doAction = function (observerOrOnNext, onError, onCompleted) {
|
4626 | return new TapObservable(this, observerOrOnNext, onError, onCompleted);
|
4627 | };
|
4628 |
|
4629 | |
4630 |
|
4631 |
|
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 | observableProto.doOnNext = observableProto.tapOnNext = function (onNext, thisArg) {
|
4637 | return this.tap(typeof thisArg !== 'undefined' ? function (x) { onNext.call(thisArg, x); } : onNext);
|
4638 | };
|
4639 |
|
4640 | |
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 | observableProto.doOnError = observableProto.tapOnError = function (onError, thisArg) {
|
4648 | return this.tap(noop, typeof thisArg !== 'undefined' ? function (e) { onError.call(thisArg, e); } : onError);
|
4649 | };
|
4650 |
|
4651 | |
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 | observableProto.doOnCompleted = observableProto.tapOnCompleted = function (onCompleted, thisArg) {
|
4659 | return this.tap(noop, null, typeof thisArg !== 'undefined' ? function () { onCompleted.call(thisArg); } : onCompleted);
|
4660 | };
|
4661 |
|
4662 | var FinallyObservable = (function (__super__) {
|
4663 | inherits(FinallyObservable, __super__);
|
4664 | function FinallyObservable(source, fn, thisArg) {
|
4665 | this.source = source;
|
4666 | this._fn = bindCallback(fn, thisArg, 0);
|
4667 | __super__.call(this);
|
4668 | }
|
4669 |
|
4670 | FinallyObservable.prototype.subscribeCore = function (o) {
|
4671 | var d = tryCatch(this.source.subscribe).call(this.source, o);
|
4672 | if (d === errorObj) {
|
4673 | this._fn();
|
4674 | thrower(d.e);
|
4675 | }
|
4676 |
|
4677 | return new FinallyDisposable(d, this._fn);
|
4678 | };
|
4679 |
|
4680 | function FinallyDisposable(s, fn) {
|
4681 | this.isDisposed = false;
|
4682 | this._s = s;
|
4683 | this._fn = fn;
|
4684 | }
|
4685 | FinallyDisposable.prototype.dispose = function () {
|
4686 | if (!this.isDisposed) {
|
4687 | var res = tryCatch(this._s.dispose).call(this._s);
|
4688 | this._fn();
|
4689 | res === errorObj && thrower(res.e);
|
4690 | }
|
4691 | };
|
4692 |
|
4693 | return FinallyObservable;
|
4694 |
|
4695 | }(ObservableBase));
|
4696 |
|
4697 | |
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 | observableProto['finally'] = function (action, thisArg) {
|
4703 | return new FinallyObservable(this, action, thisArg);
|
4704 | };
|
4705 |
|
4706 | var IgnoreElementsObservable = (function(__super__) {
|
4707 | inherits(IgnoreElementsObservable, __super__);
|
4708 |
|
4709 | function IgnoreElementsObservable(source) {
|
4710 | this.source = source;
|
4711 | __super__.call(this);
|
4712 | }
|
4713 |
|
4714 | IgnoreElementsObservable.prototype.subscribeCore = function (o) {
|
4715 | return this.source.subscribe(new InnerObserver(o));
|
4716 | };
|
4717 |
|
4718 | function InnerObserver(o) {
|
4719 | this.o = o;
|
4720 | this.isStopped = false;
|
4721 | }
|
4722 | InnerObserver.prototype.onNext = noop;
|
4723 | InnerObserver.prototype.onError = function (err) {
|
4724 | if(!this.isStopped) {
|
4725 | this.isStopped = true;
|
4726 | this.o.onError(err);
|
4727 | }
|
4728 | };
|
4729 | InnerObserver.prototype.onCompleted = function () {
|
4730 | if(!this.isStopped) {
|
4731 | this.isStopped = true;
|
4732 | this.o.onCompleted();
|
4733 | }
|
4734 | };
|
4735 | InnerObserver.prototype.dispose = function() { this.isStopped = true; };
|
4736 | InnerObserver.prototype.fail = function (e) {
|
4737 | if (!this.isStopped) {
|
4738 | this.isStopped = true;
|
4739 | this.observer.onError(e);
|
4740 | return true;
|
4741 | }
|
4742 |
|
4743 | return false;
|
4744 | };
|
4745 |
|
4746 | return IgnoreElementsObservable;
|
4747 | }(ObservableBase));
|
4748 |
|
4749 | |
4750 |
|
4751 |
|
4752 |
|
4753 | observableProto.ignoreElements = function () {
|
4754 | return new IgnoreElementsObservable(this);
|
4755 | };
|
4756 |
|
4757 | var MaterializeObservable = (function (__super__) {
|
4758 | inherits(MaterializeObservable, __super__);
|
4759 | function MaterializeObservable(source, fn) {
|
4760 | this.source = source;
|
4761 | __super__.call(this);
|
4762 | }
|
4763 |
|
4764 | MaterializeObservable.prototype.subscribeCore = function (o) {
|
4765 | return this.source.subscribe(new MaterializeObserver(o));
|
4766 | };
|
4767 |
|
4768 | return MaterializeObservable;
|
4769 | }(ObservableBase));
|
4770 |
|
4771 | var MaterializeObserver = (function (__super__) {
|
4772 | inherits(MaterializeObserver, __super__);
|
4773 |
|
4774 | function MaterializeObserver(o) {
|
4775 | this._o = o;
|
4776 | __super__.call(this);
|
4777 | }
|
4778 |
|
4779 | MaterializeObserver.prototype.next = function (x) { this._o.onNext(notificationCreateOnNext(x)) };
|
4780 | MaterializeObserver.prototype.error = function (e) { this._o.onNext(notificationCreateOnError(e)); this._o.onCompleted(); };
|
4781 | MaterializeObserver.prototype.completed = function () { this._o.onNext(notificationCreateOnCompleted()); this._o.onCompleted(); };
|
4782 |
|
4783 | return MaterializeObserver;
|
4784 | }(AbstractObserver));
|
4785 |
|
4786 | |
4787 |
|
4788 |
|
4789 |
|
4790 | observableProto.materialize = function () {
|
4791 | return new MaterializeObservable(this);
|
4792 | };
|
4793 |
|
4794 | |
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 | observableProto.repeat = function (repeatCount) {
|
4800 | return enumerableRepeat(this, repeatCount).concat();
|
4801 | };
|
4802 |
|
4803 | |
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 |
|
4810 |
|
4811 |
|
4812 |
|
4813 | observableProto.retry = function (retryCount) {
|
4814 | return enumerableRepeat(this, retryCount).catchError();
|
4815 | };
|
4816 |
|
4817 | |
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 | observableProto.retryWhen = function (notifier) {
|
4828 | return enumerableRepeat(this).catchErrorWhen(notifier);
|
4829 | };
|
4830 | var ScanObservable = (function(__super__) {
|
4831 | inherits(ScanObservable, __super__);
|
4832 | function ScanObservable(source, accumulator, hasSeed, seed) {
|
4833 | this.source = source;
|
4834 | this.accumulator = accumulator;
|
4835 | this.hasSeed = hasSeed;
|
4836 | this.seed = seed;
|
4837 | __super__.call(this);
|
4838 | }
|
4839 |
|
4840 | ScanObservable.prototype.subscribeCore = function(o) {
|
4841 | return this.source.subscribe(new ScanObserver(o,this));
|
4842 | };
|
4843 |
|
4844 | return ScanObservable;
|
4845 | }(ObservableBase));
|
4846 |
|
4847 | var ScanObserver = (function (__super__) {
|
4848 | inherits(ScanObserver, __super__);
|
4849 | function ScanObserver(o, parent) {
|
4850 | this._o = o;
|
4851 | this._p = parent;
|
4852 | this._fn = parent.accumulator;
|
4853 | this._hs = parent.hasSeed;
|
4854 | this._s = parent.seed;
|
4855 | this._ha = false;
|
4856 | this._a = null;
|
4857 | this._hv = false;
|
4858 | this._i = 0;
|
4859 | __super__.call(this);
|
4860 | }
|
4861 |
|
4862 | ScanObserver.prototype.next = function (x) {
|
4863 | !this._hv && (this._hv = true);
|
4864 | if (this._ha) {
|
4865 | this._a = tryCatch(this._fn)(this._a, x, this._i, this._p);
|
4866 | } else {
|
4867 | this._a = this._hs ? tryCatch(this._fn)(this._s, x, this._i, this._p) : x;
|
4868 | this._ha = true;
|
4869 | }
|
4870 | if (this._a === errorObj) { return this._o.onError(this._a.e); }
|
4871 | this._o.onNext(this._a);
|
4872 | this._i++;
|
4873 | };
|
4874 |
|
4875 | ScanObserver.prototype.error = function (e) {
|
4876 | this._o.onError(e);
|
4877 | };
|
4878 |
|
4879 | ScanObserver.prototype.completed = function () {
|
4880 | !this._hv && this._hs && this._o.onNext(this._s);
|
4881 | this._o.onCompleted();
|
4882 | };
|
4883 |
|
4884 | return ScanObserver;
|
4885 | }(AbstractObserver));
|
4886 |
|
4887 | |
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 | observableProto.scan = function () {
|
4895 | var hasSeed = false, seed, accumulator = arguments[0];
|
4896 | if (arguments.length === 2) {
|
4897 | hasSeed = true;
|
4898 | seed = arguments[1];
|
4899 | }
|
4900 | return new ScanObservable(this, accumulator, hasSeed, seed);
|
4901 | };
|
4902 |
|
4903 | var SkipLastObservable = (function (__super__) {
|
4904 | inherits(SkipLastObservable, __super__);
|
4905 | function SkipLastObservable(source, c) {
|
4906 | this.source = source;
|
4907 | this._c = c;
|
4908 | __super__.call(this);
|
4909 | }
|
4910 |
|
4911 | SkipLastObservable.prototype.subscribeCore = function (o) {
|
4912 | return this.source.subscribe(new SkipLastObserver(o, this._c));
|
4913 | };
|
4914 |
|
4915 | return SkipLastObservable;
|
4916 | }(ObservableBase));
|
4917 |
|
4918 | var SkipLastObserver = (function (__super__) {
|
4919 | inherits(SkipLastObserver, __super__);
|
4920 | function SkipLastObserver(o, c) {
|
4921 | this._o = o;
|
4922 | this._c = c;
|
4923 | this._q = [];
|
4924 | __super__.call(this);
|
4925 | }
|
4926 |
|
4927 | SkipLastObserver.prototype.next = function (x) {
|
4928 | this._q.push(x);
|
4929 | this._q.length > this._c && this._o.onNext(this._q.shift());
|
4930 | };
|
4931 |
|
4932 | SkipLastObserver.prototype.error = function (e) {
|
4933 | this._o.onError(e);
|
4934 | };
|
4935 |
|
4936 | SkipLastObserver.prototype.completed = function () {
|
4937 | this._o.onCompleted();
|
4938 | };
|
4939 |
|
4940 | return SkipLastObserver;
|
4941 | }(AbstractObserver));
|
4942 |
|
4943 | |
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 | observableProto.skipLast = function (count) {
|
4952 | if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
4953 | return new SkipLastObservable(this, count);
|
4954 | };
|
4955 |
|
4956 | |
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 | observableProto.startWith = function () {
|
4965 | var values, scheduler, start = 0;
|
4966 | if (!!arguments.length && isScheduler(arguments[0])) {
|
4967 | scheduler = arguments[0];
|
4968 | start = 1;
|
4969 | } else {
|
4970 | scheduler = immediateScheduler;
|
4971 | }
|
4972 | for(var args = [], i = start, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
|
4973 | return enumerableOf([observableFromArray(args, scheduler), this]).concat();
|
4974 | };
|
4975 |
|
4976 | var TakeLastObserver = (function (__super__) {
|
4977 | inherits(TakeLastObserver, __super__);
|
4978 | function TakeLastObserver(o, c) {
|
4979 | this._o = o;
|
4980 | this._c = c;
|
4981 | this._q = [];
|
4982 | __super__.call(this);
|
4983 | }
|
4984 |
|
4985 | TakeLastObserver.prototype.next = function (x) {
|
4986 | this._q.push(x);
|
4987 | this._q.length > this._c && this._q.shift();
|
4988 | };
|
4989 |
|
4990 | TakeLastObserver.prototype.error = function (e) {
|
4991 | this._o.onError(e);
|
4992 | };
|
4993 |
|
4994 | TakeLastObserver.prototype.completed = function () {
|
4995 | while (this._q.length > 0) { this._o.onNext(this._q.shift()); }
|
4996 | this._o.onCompleted();
|
4997 | };
|
4998 |
|
4999 | return TakeLastObserver;
|
5000 | }(AbstractObserver));
|
5001 |
|
5002 | |
5003 |
|
5004 |
|
5005 |
|
5006 |
|
5007 |
|
5008 |
|
5009 |
|
5010 | observableProto.takeLast = function (count) {
|
5011 | if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
5012 | var source = this;
|
5013 | return new AnonymousObservable(function (o) {
|
5014 | return source.subscribe(new TakeLastObserver(o, count));
|
5015 | }, source);
|
5016 | };
|
5017 |
|
5018 | var TakeLastBufferObserver = (function (__super__) {
|
5019 | inherits(TakeLastBufferObserver, __super__);
|
5020 | function TakeLastBufferObserver(o, c) {
|
5021 | this._o = o;
|
5022 | this._c = c;
|
5023 | this._q = [];
|
5024 | __super__.call(this);
|
5025 | }
|
5026 |
|
5027 | TakeLastBufferObserver.prototype.next = function (x) {
|
5028 | this._q.push(x);
|
5029 | this._q.length > this._c && this._q.shift();
|
5030 | };
|
5031 |
|
5032 | TakeLastBufferObserver.prototype.error = function (e) {
|
5033 | this._o.onError(e);
|
5034 | };
|
5035 |
|
5036 | TakeLastBufferObserver.prototype.completed = function () {
|
5037 | this._o.onNext(this._q);
|
5038 | this._o.onCompleted();
|
5039 | };
|
5040 |
|
5041 | return TakeLastBufferObserver;
|
5042 | }(AbstractObserver));
|
5043 |
|
5044 | |
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 | observableProto.takeLastBuffer = function (count) {
|
5054 | if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
5055 | var source = this;
|
5056 | return new AnonymousObservable(function (o) {
|
5057 | return source.subscribe(new TakeLastBufferObserver(o, count));
|
5058 | }, source);
|
5059 | };
|
5060 |
|
5061 | |
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 | observableProto.windowWithCount = function (count, skip) {
|
5068 | var source = this;
|
5069 | +count || (count = 0);
|
5070 | Math.abs(count) === Infinity && (count = 0);
|
5071 | if (count <= 0) { throw new ArgumentOutOfRangeError(); }
|
5072 | skip == null && (skip = count);
|
5073 | +skip || (skip = 0);
|
5074 | Math.abs(skip) === Infinity && (skip = 0);
|
5075 |
|
5076 | if (skip <= 0) { throw new ArgumentOutOfRangeError(); }
|
5077 | return new AnonymousObservable(function (observer) {
|
5078 | var m = new SingleAssignmentDisposable(),
|
5079 | refCountDisposable = new RefCountDisposable(m),
|
5080 | n = 0,
|
5081 | q = [];
|
5082 |
|
5083 | function createWindow () {
|
5084 | var s = new Subject();
|
5085 | q.push(s);
|
5086 | observer.onNext(addRef(s, refCountDisposable));
|
5087 | }
|
5088 |
|
5089 | createWindow();
|
5090 |
|
5091 | m.setDisposable(source.subscribe(
|
5092 | function (x) {
|
5093 | for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
|
5094 | var c = n - count + 1;
|
5095 | c >= 0 && c % skip === 0 && q.shift().onCompleted();
|
5096 | ++n % skip === 0 && createWindow();
|
5097 | },
|
5098 | function (e) {
|
5099 | while (q.length > 0) { q.shift().onError(e); }
|
5100 | observer.onError(e);
|
5101 | },
|
5102 | function () {
|
5103 | while (q.length > 0) { q.shift().onCompleted(); }
|
5104 | observer.onCompleted();
|
5105 | }
|
5106 | ));
|
5107 | return refCountDisposable;
|
5108 | }, source);
|
5109 | };
|
5110 |
|
5111 | function concatMap(source, selector, thisArg) {
|
5112 | var selectorFunc = bindCallback(selector, thisArg, 3);
|
5113 | return source.map(function (x, i) {
|
5114 | var result = selectorFunc(x, i, source);
|
5115 | isPromise(result) && (result = observableFromPromise(result));
|
5116 | (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
|
5117 | return result;
|
5118 | }).concatAll();
|
5119 | }
|
5120 |
|
5121 | |
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 |
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 |
|
5140 | observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
|
5141 | if (isFunction(selector) && isFunction(resultSelector)) {
|
5142 | return this.concatMap(function (x, i) {
|
5143 | var selectorResult = selector(x, i);
|
5144 | isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
|
5145 | (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
|
5146 |
|
5147 | return selectorResult.map(function (y, i2) {
|
5148 | return resultSelector(x, y, i, i2);
|
5149 | });
|
5150 | });
|
5151 | }
|
5152 | return isFunction(selector) ?
|
5153 | concatMap(this, selector, thisArg) :
|
5154 | concatMap(this, function () { return selector; });
|
5155 | };
|
5156 |
|
5157 | |
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 |
|
5165 | observableProto.concatMapObserver = observableProto.selectConcatObserver = function(onNext, onError, onCompleted, thisArg) {
|
5166 | var source = this,
|
5167 | onNextFunc = bindCallback(onNext, thisArg, 2),
|
5168 | onErrorFunc = bindCallback(onError, thisArg, 1),
|
5169 | onCompletedFunc = bindCallback(onCompleted, thisArg, 0);
|
5170 | return new AnonymousObservable(function (observer) {
|
5171 | var index = 0;
|
5172 | return source.subscribe(
|
5173 | function (x) {
|
5174 | var result;
|
5175 | try {
|
5176 | result = onNextFunc(x, index++);
|
5177 | } catch (e) {
|
5178 | observer.onError(e);
|
5179 | return;
|
5180 | }
|
5181 | isPromise(result) && (result = observableFromPromise(result));
|
5182 | observer.onNext(result);
|
5183 | },
|
5184 | function (err) {
|
5185 | var result;
|
5186 | try {
|
5187 | result = onErrorFunc(err);
|
5188 | } catch (e) {
|
5189 | observer.onError(e);
|
5190 | return;
|
5191 | }
|
5192 | isPromise(result) && (result = observableFromPromise(result));
|
5193 | observer.onNext(result);
|
5194 | observer.onCompleted();
|
5195 | },
|
5196 | function () {
|
5197 | var result;
|
5198 | try {
|
5199 | result = onCompletedFunc();
|
5200 | } catch (e) {
|
5201 | observer.onError(e);
|
5202 | return;
|
5203 | }
|
5204 | isPromise(result) && (result = observableFromPromise(result));
|
5205 | observer.onNext(result);
|
5206 | observer.onCompleted();
|
5207 | });
|
5208 | }, this).concatAll();
|
5209 | };
|
5210 |
|
5211 | var DefaultIfEmptyObserver = (function (__super__) {
|
5212 | inherits(DefaultIfEmptyObserver, __super__);
|
5213 | function DefaultIfEmptyObserver(o, d) {
|
5214 | this._o = o;
|
5215 | this._d = d;
|
5216 | this._f = false;
|
5217 | __super__.call(this);
|
5218 | }
|
5219 |
|
5220 | DefaultIfEmptyObserver.prototype.next = function (x) {
|
5221 | this._f = true;
|
5222 | this._o.onNext(x);
|
5223 | };
|
5224 |
|
5225 | DefaultIfEmptyObserver.prototype.error = function (e) {
|
5226 | this._o.onError(e);
|
5227 | };
|
5228 |
|
5229 | DefaultIfEmptyObserver.prototype.completed = function () {
|
5230 | !this._f && this._o.onNext(this._d);
|
5231 | this._o.onCompleted();
|
5232 | };
|
5233 |
|
5234 | return DefaultIfEmptyObserver;
|
5235 | }(AbstractObserver));
|
5236 |
|
5237 | |
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 | observableProto.defaultIfEmpty = function (defaultValue) {
|
5248 | var source = this;
|
5249 | defaultValue === undefined && (defaultValue = null);
|
5250 | return new AnonymousObservable(function (o) {
|
5251 | return source.subscribe(new DefaultIfEmptyObserver(o, defaultValue));
|
5252 | }, source);
|
5253 | };
|
5254 |
|
5255 |
|
5256 | function arrayIndexOfComparer(array, item, comparer) {
|
5257 | for (var i = 0, len = array.length; i < len; i++) {
|
5258 | if (comparer(array[i], item)) { return i; }
|
5259 | }
|
5260 | return -1;
|
5261 | }
|
5262 |
|
5263 | function HashSet(comparer) {
|
5264 | this.comparer = comparer;
|
5265 | this.set = [];
|
5266 | }
|
5267 | HashSet.prototype.push = function(value) {
|
5268 | var retValue = arrayIndexOfComparer(this.set, value, this.comparer) === -1;
|
5269 | retValue && this.set.push(value);
|
5270 | return retValue;
|
5271 | };
|
5272 |
|
5273 | var DistinctObservable = (function (__super__) {
|
5274 | inherits(DistinctObservable, __super__);
|
5275 | function DistinctObservable(source, keyFn, cmpFn) {
|
5276 | this.source = source;
|
5277 | this._keyFn = keyFn;
|
5278 | this._cmpFn = cmpFn;
|
5279 | __super__.call(this);
|
5280 | }
|
5281 |
|
5282 | DistinctObservable.prototype.subscribeCore = function (o) {
|
5283 | return this.source.subscribe(new DistinctObserver(o, this._keyFn, this._cmpFn));
|
5284 | };
|
5285 |
|
5286 | return DistinctObservable;
|
5287 | }(ObservableBase));
|
5288 |
|
5289 | var DistinctObserver = (function (__super__) {
|
5290 | inherits(DistinctObserver, __super__);
|
5291 | function DistinctObserver(o, keyFn, cmpFn) {
|
5292 | this._o = o;
|
5293 | this._keyFn = keyFn;
|
5294 | this._h = new HashSet(cmpFn);
|
5295 | __super__.call(this);
|
5296 | }
|
5297 |
|
5298 | DistinctObserver.prototype.next = function (x) {
|
5299 | var key = x;
|
5300 | if (isFunction(this._keyFn)) {
|
5301 | key = tryCatch(this._keyFn)(x);
|
5302 | if (key === errorObj) { return this._o.onError(key.e); }
|
5303 | }
|
5304 | this._h.push(key) && this._o.onNext(x);
|
5305 | };
|
5306 |
|
5307 | DistinctObserver.prototype.error = function (e) { this._o.onError(e); };
|
5308 | DistinctObserver.prototype.completed = function () { this._o.onCompleted(); };
|
5309 |
|
5310 | return DistinctObserver;
|
5311 | }(AbstractObserver));
|
5312 |
|
5313 | |
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 |
|
5322 |
|
5323 |
|
5324 |
|
5325 | observableProto.distinct = function (keySelector, comparer) {
|
5326 | comparer || (comparer = defaultComparer);
|
5327 | return new DistinctObservable(this, keySelector, comparer);
|
5328 | };
|
5329 |
|
5330 | |
5331 |
|
5332 |
|
5333 |
|
5334 |
|
5335 |
|
5336 |
|
5337 |
|
5338 |
|
5339 |
|
5340 |
|
5341 | observableProto.groupBy = function (keySelector, elementSelector) {
|
5342 | return this.groupByUntil(keySelector, elementSelector, observableNever);
|
5343 | };
|
5344 |
|
5345 | |
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 |
|
5361 | observableProto.groupByUntil = function (keySelector, elementSelector, durationSelector) {
|
5362 | var source = this;
|
5363 | return new AnonymousObservable(function (o) {
|
5364 | var map = new Map(),
|
5365 | groupDisposable = new CompositeDisposable(),
|
5366 | refCountDisposable = new RefCountDisposable(groupDisposable),
|
5367 | handleError = function (e) { return function (item) { item.onError(e); }; };
|
5368 |
|
5369 | groupDisposable.add(
|
5370 | source.subscribe(function (x) {
|
5371 | var key = tryCatch(keySelector)(x);
|
5372 | if (key === errorObj) {
|
5373 | map.forEach(handleError(key.e));
|
5374 | return o.onError(key.e);
|
5375 | }
|
5376 |
|
5377 | var fireNewMapEntry = false, writer = map.get(key);
|
5378 | if (writer === undefined) {
|
5379 | writer = new Subject();
|
5380 | map.set(key, writer);
|
5381 | fireNewMapEntry = true;
|
5382 | }
|
5383 |
|
5384 | if (fireNewMapEntry) {
|
5385 | var group = new GroupedObservable(key, writer, refCountDisposable),
|
5386 | durationGroup = new GroupedObservable(key, writer);
|
5387 | var duration = tryCatch(durationSelector)(durationGroup);
|
5388 | if (duration === errorObj) {
|
5389 | map.forEach(handleError(duration.e));
|
5390 | return o.onError(duration.e);
|
5391 | }
|
5392 |
|
5393 | o.onNext(group);
|
5394 |
|
5395 | var md = new SingleAssignmentDisposable();
|
5396 | groupDisposable.add(md);
|
5397 |
|
5398 | md.setDisposable(duration.take(1).subscribe(
|
5399 | noop,
|
5400 | function (e) {
|
5401 | map.forEach(handleError(e));
|
5402 | o.onError(e);
|
5403 | },
|
5404 | function () {
|
5405 | if (map['delete'](key)) { writer.onCompleted(); }
|
5406 | groupDisposable.remove(md);
|
5407 | }));
|
5408 | }
|
5409 |
|
5410 | var element = x;
|
5411 | if (isFunction(elementSelector)) {
|
5412 | element = tryCatch(elementSelector)(x);
|
5413 | if (element === errorObj) {
|
5414 | map.forEach(handleError(element.e));
|
5415 | return o.onError(element.e);
|
5416 | }
|
5417 | }
|
5418 |
|
5419 | writer.onNext(element);
|
5420 | }, function (e) {
|
5421 | map.forEach(handleError(e));
|
5422 | o.onError(e);
|
5423 | }, function () {
|
5424 | map.forEach(function (item) { item.onCompleted(); });
|
5425 | o.onCompleted();
|
5426 | }));
|
5427 |
|
5428 | return refCountDisposable;
|
5429 | }, source);
|
5430 | };
|
5431 |
|
5432 | var MapObservable = (function (__super__) {
|
5433 | inherits(MapObservable, __super__);
|
5434 |
|
5435 | function MapObservable(source, selector, thisArg) {
|
5436 | this.source = source;
|
5437 | this.selector = bindCallback(selector, thisArg, 3);
|
5438 | __super__.call(this);
|
5439 | }
|
5440 |
|
5441 | function innerMap(selector, self) {
|
5442 | return function (x, i, o) { return selector.call(this, self.selector(x, i, o), i, o); };
|
5443 | }
|
5444 |
|
5445 | MapObservable.prototype.internalMap = function (selector, thisArg) {
|
5446 | return new MapObservable(this.source, innerMap(selector, this), thisArg);
|
5447 | };
|
5448 |
|
5449 | MapObservable.prototype.subscribeCore = function (o) {
|
5450 | return this.source.subscribe(new InnerObserver(o, this.selector, this));
|
5451 | };
|
5452 |
|
5453 | inherits(InnerObserver, AbstractObserver);
|
5454 | function InnerObserver(o, selector, source) {
|
5455 | this.o = o;
|
5456 | this.selector = selector;
|
5457 | this.source = source;
|
5458 | this.i = 0;
|
5459 | AbstractObserver.call(this);
|
5460 | }
|
5461 |
|
5462 | InnerObserver.prototype.next = function(x) {
|
5463 | var result = tryCatch(this.selector)(x, this.i++, this.source);
|
5464 | if (result === errorObj) { return this.o.onError(result.e); }
|
5465 | this.o.onNext(result);
|
5466 | };
|
5467 |
|
5468 | InnerObserver.prototype.error = function (e) {
|
5469 | this.o.onError(e);
|
5470 | };
|
5471 |
|
5472 | InnerObserver.prototype.completed = function () {
|
5473 | this.o.onCompleted();
|
5474 | };
|
5475 |
|
5476 | return MapObservable;
|
5477 |
|
5478 | }(ObservableBase));
|
5479 |
|
5480 | |
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 | observableProto.map = observableProto.select = function (selector, thisArg) {
|
5487 | var selectorFn = typeof selector === 'function' ? selector : function () { return selector; };
|
5488 | return this instanceof MapObservable ?
|
5489 | this.internalMap(selectorFn, thisArg) :
|
5490 | new MapObservable(this, selectorFn, thisArg);
|
5491 | };
|
5492 |
|
5493 | function plucker(args, len) {
|
5494 | return function mapper(x) {
|
5495 | var currentProp = x;
|
5496 | for (var i = 0; i < len; i++) {
|
5497 | var p = currentProp[args[i]];
|
5498 | if (typeof p !== 'undefined') {
|
5499 | currentProp = p;
|
5500 | } else {
|
5501 | return undefined;
|
5502 | }
|
5503 | }
|
5504 | return currentProp;
|
5505 | }
|
5506 | }
|
5507 |
|
5508 | |
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 | observableProto.pluck = function () {
|
5515 | var len = arguments.length, args = new Array(len);
|
5516 | if (len === 0) { throw new Error('List of properties cannot be empty.'); }
|
5517 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
5518 | return this.map(plucker(args, len));
|
5519 | };
|
5520 |
|
5521 | observableProto.flatMap = observableProto.selectMany = function(selector, resultSelector, thisArg) {
|
5522 | return new FlatMapObservable(this, selector, resultSelector, thisArg).mergeAll();
|
5523 | };
|
5524 |
|
5525 | |
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 | observableProto.flatMapObserver = observableProto.selectManyObserver = function (onNext, onError, onCompleted, thisArg) {
|
5534 | var source = this;
|
5535 | return new AnonymousObservable(function (observer) {
|
5536 | var index = 0;
|
5537 |
|
5538 | return source.subscribe(
|
5539 | function (x) {
|
5540 | var result;
|
5541 | try {
|
5542 | result = onNext.call(thisArg, x, index++);
|
5543 | } catch (e) {
|
5544 | observer.onError(e);
|
5545 | return;
|
5546 | }
|
5547 | isPromise(result) && (result = observableFromPromise(result));
|
5548 | observer.onNext(result);
|
5549 | },
|
5550 | function (err) {
|
5551 | var result;
|
5552 | try {
|
5553 | result = onError.call(thisArg, err);
|
5554 | } catch (e) {
|
5555 | observer.onError(e);
|
5556 | return;
|
5557 | }
|
5558 | isPromise(result) && (result = observableFromPromise(result));
|
5559 | observer.onNext(result);
|
5560 | observer.onCompleted();
|
5561 | },
|
5562 | function () {
|
5563 | var result;
|
5564 | try {
|
5565 | result = onCompleted.call(thisArg);
|
5566 | } catch (e) {
|
5567 | observer.onError(e);
|
5568 | return;
|
5569 | }
|
5570 | isPromise(result) && (result = observableFromPromise(result));
|
5571 | observer.onNext(result);
|
5572 | observer.onCompleted();
|
5573 | });
|
5574 | }, source).mergeAll();
|
5575 | };
|
5576 |
|
5577 | Rx.Observable.prototype.flatMapLatest = function(selector, resultSelector, thisArg) {
|
5578 | return new FlatMapObservable(this, selector, resultSelector, thisArg).switchLatest();
|
5579 | };
|
5580 | var SkipObservable = (function(__super__) {
|
5581 | inherits(SkipObservable, __super__);
|
5582 | function SkipObservable(source, count) {
|
5583 | this.source = source;
|
5584 | this._count = count;
|
5585 | __super__.call(this);
|
5586 | }
|
5587 |
|
5588 | SkipObservable.prototype.subscribeCore = function (o) {
|
5589 | return this.source.subscribe(new SkipObserver(o, this._count));
|
5590 | };
|
5591 |
|
5592 | function SkipObserver(o, c) {
|
5593 | this._o = o;
|
5594 | this._r = c;
|
5595 | AbstractObserver.call(this);
|
5596 | }
|
5597 |
|
5598 | inherits(SkipObserver, AbstractObserver);
|
5599 |
|
5600 | SkipObserver.prototype.next = function (x) {
|
5601 | if (this._r <= 0) {
|
5602 | this._o.onNext(x);
|
5603 | } else {
|
5604 | this._r--;
|
5605 | }
|
5606 | };
|
5607 | SkipObserver.prototype.error = function(e) { this._o.onError(e); };
|
5608 | SkipObserver.prototype.completed = function() { this._o.onCompleted(); };
|
5609 |
|
5610 | return SkipObservable;
|
5611 | }(ObservableBase));
|
5612 |
|
5613 | |
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 | observableProto.skip = function (count) {
|
5619 | if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
5620 | return new SkipObservable(this, count);
|
5621 | };
|
5622 |
|
5623 | var SkipWhileObservable = (function (__super__) {
|
5624 | inherits(SkipWhileObservable, __super__);
|
5625 | function SkipWhileObservable(source, fn) {
|
5626 | this.source = source;
|
5627 | this._fn = fn;
|
5628 | __super__.call(this);
|
5629 | }
|
5630 |
|
5631 | SkipWhileObservable.prototype.subscribeCore = function (o) {
|
5632 | return this.source.subscribe(new SkipWhileObserver(o, this));
|
5633 | };
|
5634 |
|
5635 | return SkipWhileObservable;
|
5636 | }(ObservableBase));
|
5637 |
|
5638 | var SkipWhileObserver = (function (__super__) {
|
5639 | inherits(SkipWhileObserver, __super__);
|
5640 |
|
5641 | function SkipWhileObserver(o, p) {
|
5642 | this._o = o;
|
5643 | this._p = p;
|
5644 | this._i = 0;
|
5645 | this._r = false;
|
5646 | __super__.call(this);
|
5647 | }
|
5648 |
|
5649 | SkipWhileObserver.prototype.next = function (x) {
|
5650 | if (!this._r) {
|
5651 | var res = tryCatch(this._p._fn)(x, this._i++, this._p);
|
5652 | if (res === errorObj) { return this._o.onError(res.e); }
|
5653 | this._r = !res;
|
5654 | }
|
5655 | this._r && this._o.onNext(x);
|
5656 | };
|
5657 | SkipWhileObserver.prototype.error = function (e) { this._o.onError(e); };
|
5658 | SkipWhileObserver.prototype.completed = function () { this._o.onCompleted(); };
|
5659 |
|
5660 | return SkipWhileObserver;
|
5661 | }(AbstractObserver));
|
5662 |
|
5663 | |
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 | observableProto.skipWhile = function (predicate, thisArg) {
|
5674 | var fn = bindCallback(predicate, thisArg, 3);
|
5675 | return new SkipWhileObservable(this, fn);
|
5676 | };
|
5677 |
|
5678 | var TakeObservable = (function(__super__) {
|
5679 | inherits(TakeObservable, __super__);
|
5680 | function TakeObservable(source, count) {
|
5681 | this.source = source;
|
5682 | this._count = count;
|
5683 | __super__.call(this);
|
5684 | }
|
5685 |
|
5686 | TakeObservable.prototype.subscribeCore = function (o) {
|
5687 | return this.source.subscribe(new TakeObserver(o, this._count));
|
5688 | };
|
5689 |
|
5690 | function TakeObserver(o, c) {
|
5691 | this._o = o;
|
5692 | this._c = c;
|
5693 | this._r = c;
|
5694 | AbstractObserver.call(this);
|
5695 | }
|
5696 |
|
5697 | inherits(TakeObserver, AbstractObserver);
|
5698 |
|
5699 | TakeObserver.prototype.next = function (x) {
|
5700 | if (this._r-- > 0) {
|
5701 | this._o.onNext(x);
|
5702 | this._r <= 0 && this._o.onCompleted();
|
5703 | }
|
5704 | };
|
5705 |
|
5706 | TakeObserver.prototype.error = function (e) { this._o.onError(e); };
|
5707 | TakeObserver.prototype.completed = function () { this._o.onCompleted(); };
|
5708 |
|
5709 | return TakeObservable;
|
5710 | }(ObservableBase));
|
5711 |
|
5712 | |
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 | observableProto.take = function (count, scheduler) {
|
5719 | if (count < 0) { throw new ArgumentOutOfRangeError(); }
|
5720 | if (count === 0) { return observableEmpty(scheduler); }
|
5721 | return new TakeObservable(this, count);
|
5722 | };
|
5723 |
|
5724 | var TakeWhileObservable = (function (__super__) {
|
5725 | inherits(TakeWhileObservable, __super__);
|
5726 | function TakeWhileObservable(source, fn) {
|
5727 | this.source = source;
|
5728 | this._fn = fn;
|
5729 | __super__.call(this);
|
5730 | }
|
5731 |
|
5732 | TakeWhileObservable.prototype.subscribeCore = function (o) {
|
5733 | return this.source.subscribe(new TakeWhileObserver(o, this));
|
5734 | };
|
5735 |
|
5736 | return TakeWhileObservable;
|
5737 | }(ObservableBase));
|
5738 |
|
5739 | var TakeWhileObserver = (function (__super__) {
|
5740 | inherits(TakeWhileObserver, __super__);
|
5741 |
|
5742 | function TakeWhileObserver(o, p) {
|
5743 | this._o = o;
|
5744 | this._p = p;
|
5745 | this._i = 0;
|
5746 | this._r = true;
|
5747 | __super__.call(this);
|
5748 | }
|
5749 |
|
5750 | TakeWhileObserver.prototype.next = function (x) {
|
5751 | if (this._r) {
|
5752 | this._r = tryCatch(this._p._fn)(x, this._i++, this._p);
|
5753 | if (this._r === errorObj) { return this._o.onError(this._r.e); }
|
5754 | }
|
5755 | if (this._r) {
|
5756 | this._o.onNext(x);
|
5757 | } else {
|
5758 | this._o.onCompleted();
|
5759 | }
|
5760 | };
|
5761 | TakeWhileObserver.prototype.error = function (e) { this._o.onError(e); };
|
5762 | TakeWhileObserver.prototype.completed = function () { this._o.onCompleted(); };
|
5763 |
|
5764 | return TakeWhileObserver;
|
5765 | }(AbstractObserver));
|
5766 |
|
5767 | |
5768 |
|
5769 |
|
5770 |
|
5771 |
|
5772 |
|
5773 |
|
5774 | observableProto.takeWhile = function (predicate, thisArg) {
|
5775 | var fn = bindCallback(predicate, thisArg, 3);
|
5776 | return new TakeWhileObservable(this, fn);
|
5777 | };
|
5778 |
|
5779 | var FilterObservable = (function (__super__) {
|
5780 | inherits(FilterObservable, __super__);
|
5781 |
|
5782 | function FilterObservable(source, predicate, thisArg) {
|
5783 | this.source = source;
|
5784 | this.predicate = bindCallback(predicate, thisArg, 3);
|
5785 | __super__.call(this);
|
5786 | }
|
5787 |
|
5788 | FilterObservable.prototype.subscribeCore = function (o) {
|
5789 | return this.source.subscribe(new InnerObserver(o, this.predicate, this));
|
5790 | };
|
5791 |
|
5792 | function innerPredicate(predicate, self) {
|
5793 | return function(x, i, o) { return self.predicate(x, i, o) && predicate.call(this, x, i, o); }
|
5794 | }
|
5795 |
|
5796 | FilterObservable.prototype.internalFilter = function(predicate, thisArg) {
|
5797 | return new FilterObservable(this.source, innerPredicate(predicate, this), thisArg);
|
5798 | };
|
5799 |
|
5800 | inherits(InnerObserver, AbstractObserver);
|
5801 | function InnerObserver(o, predicate, source) {
|
5802 | this.o = o;
|
5803 | this.predicate = predicate;
|
5804 | this.source = source;
|
5805 | this.i = 0;
|
5806 | AbstractObserver.call(this);
|
5807 | }
|
5808 |
|
5809 | InnerObserver.prototype.next = function(x) {
|
5810 | var shouldYield = tryCatch(this.predicate)(x, this.i++, this.source);
|
5811 | if (shouldYield === errorObj) {
|
5812 | return this.o.onError(shouldYield.e);
|
5813 | }
|
5814 | shouldYield && this.o.onNext(x);
|
5815 | };
|
5816 |
|
5817 | InnerObserver.prototype.error = function (e) {
|
5818 | this.o.onError(e);
|
5819 | };
|
5820 |
|
5821 | InnerObserver.prototype.completed = function () {
|
5822 | this.o.onCompleted();
|
5823 | };
|
5824 |
|
5825 | return FilterObservable;
|
5826 |
|
5827 | }(ObservableBase));
|
5828 |
|
5829 | |
5830 |
|
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 | observableProto.filter = observableProto.where = function (predicate, thisArg) {
|
5836 | return this instanceof FilterObservable ? this.internalFilter(predicate, thisArg) :
|
5837 | new FilterObservable(this, predicate, thisArg);
|
5838 | };
|
5839 |
|
5840 | var ExtremaByObservable = (function (__super__) {
|
5841 | inherits(ExtremaByObservable, __super__);
|
5842 | function ExtremaByObservable(source, k, c) {
|
5843 | this.source = source;
|
5844 | this._k = k;
|
5845 | this._c = c;
|
5846 | __super__.call(this);
|
5847 | }
|
5848 |
|
5849 | ExtremaByObservable.prototype.subscribeCore = function (o) {
|
5850 | return this.source.subscribe(new ExtremaByObserver(o, this._k, this._c));
|
5851 | };
|
5852 |
|
5853 | return ExtremaByObservable;
|
5854 | }(ObservableBase));
|
5855 |
|
5856 | var ExtremaByObserver = (function (__super__) {
|
5857 | inherits(ExtremaByObserver, __super__);
|
5858 | function ExtremaByObserver(o, k, c) {
|
5859 | this._o = o;
|
5860 | this._k = k;
|
5861 | this._c = c;
|
5862 | this._v = null;
|
5863 | this._hv = false;
|
5864 | this._l = [];
|
5865 | __super__.call(this);
|
5866 | }
|
5867 |
|
5868 | ExtremaByObserver.prototype.next = function (x) {
|
5869 | var key = tryCatch(this._k)(x);
|
5870 | if (key === errorObj) { return this._o.onError(key.e); }
|
5871 | var comparison = 0;
|
5872 | if (!this._hv) {
|
5873 | this._hv = true;
|
5874 | this._v = key;
|
5875 | } else {
|
5876 | comparison = tryCatch(this._c)(key, this._v);
|
5877 | if (comparison === errorObj) { return this._o.onError(comparison.e); }
|
5878 | }
|
5879 | if (comparison > 0) {
|
5880 | this._v = key;
|
5881 | this._l = [];
|
5882 | }
|
5883 | if (comparison >= 0) { this._l.push(x); }
|
5884 | };
|
5885 |
|
5886 | ExtremaByObserver.prototype.error = function (e) {
|
5887 | this._o.onError(e);
|
5888 | };
|
5889 |
|
5890 | ExtremaByObserver.prototype.completed = function () {
|
5891 | this._o.onNext(this._l);
|
5892 | this._o.onCompleted();
|
5893 | };
|
5894 |
|
5895 | return ExtremaByObserver;
|
5896 | }(AbstractObserver));
|
5897 |
|
5898 | function firstOnly(x) {
|
5899 | if (x.length === 0) { throw new EmptyError(); }
|
5900 | return x[0];
|
5901 | }
|
5902 |
|
5903 | var ReduceObservable = (function(__super__) {
|
5904 | inherits(ReduceObservable, __super__);
|
5905 | function ReduceObservable(source, accumulator, hasSeed, seed) {
|
5906 | this.source = source;
|
5907 | this.accumulator = accumulator;
|
5908 | this.hasSeed = hasSeed;
|
5909 | this.seed = seed;
|
5910 | __super__.call(this);
|
5911 | }
|
5912 |
|
5913 | ReduceObservable.prototype.subscribeCore = function(observer) {
|
5914 | return this.source.subscribe(new ReduceObserver(observer,this));
|
5915 | };
|
5916 |
|
5917 | return ReduceObservable;
|
5918 | }(ObservableBase));
|
5919 |
|
5920 | var ReduceObserver = (function (__super__) {
|
5921 | inherits(ReduceObserver, __super__);
|
5922 | function ReduceObserver(o, parent) {
|
5923 | this._o = o;
|
5924 | this._p = parent;
|
5925 | this._fn = parent.accumulator;
|
5926 | this._hs = parent.hasSeed;
|
5927 | this._s = parent.seed;
|
5928 | this._ha = false;
|
5929 | this._a = null;
|
5930 | this._hv = false;
|
5931 | this._i = 0;
|
5932 | __super__.call(this);
|
5933 | }
|
5934 |
|
5935 | ReduceObserver.prototype.next = function (x) {
|
5936 | !this._hv && (this._hv = true);
|
5937 | if (this._ha) {
|
5938 | this._a = tryCatch(this._fn)(this._a, x, this._i, this._p);
|
5939 | } else {
|
5940 | this._a = this._hs ? tryCatch(this._fn)(this._s, x, this._i, this._p) : x;
|
5941 | this._ha = true;
|
5942 | }
|
5943 | if (this._a === errorObj) { return this._o.onError(this._a.e); }
|
5944 | this._i++;
|
5945 | };
|
5946 |
|
5947 | ReduceObserver.prototype.error = function (e) {
|
5948 | this._o.onError(e);
|
5949 | };
|
5950 |
|
5951 | ReduceObserver.prototype.completed = function () {
|
5952 | this._hv && this._o.onNext(this._a);
|
5953 | !this._hv && this._hs && this._o.onNext(this._s);
|
5954 | !this._hv && !this._hs && this._o.onError(new EmptyError());
|
5955 | this._o.onCompleted();
|
5956 | };
|
5957 |
|
5958 | return ReduceObserver;
|
5959 | }(AbstractObserver));
|
5960 |
|
5961 | |
5962 |
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 | observableProto.reduce = function () {
|
5969 | var hasSeed = false, seed, accumulator = arguments[0];
|
5970 | if (arguments.length === 2) {
|
5971 | hasSeed = true;
|
5972 | seed = arguments[1];
|
5973 | }
|
5974 | return new ReduceObservable(this, accumulator, hasSeed, seed);
|
5975 | };
|
5976 |
|
5977 | var SomeObservable = (function (__super__) {
|
5978 | inherits(SomeObservable, __super__);
|
5979 | function SomeObservable(source, fn) {
|
5980 | this.source = source;
|
5981 | this._fn = fn;
|
5982 | __super__.call(this);
|
5983 | }
|
5984 |
|
5985 | SomeObservable.prototype.subscribeCore = function (o) {
|
5986 | return this.source.subscribe(new SomeObserver(o, this._fn, this.source));
|
5987 | };
|
5988 |
|
5989 | return SomeObservable;
|
5990 | }(ObservableBase));
|
5991 |
|
5992 | var SomeObserver = (function (__super__) {
|
5993 | inherits(SomeObserver, __super__);
|
5994 |
|
5995 | function SomeObserver(o, fn, s) {
|
5996 | this._o = o;
|
5997 | this._fn = fn;
|
5998 | this._s = s;
|
5999 | this._i = 0;
|
6000 | __super__.call(this);
|
6001 | }
|
6002 |
|
6003 | SomeObserver.prototype.next = function (x) {
|
6004 | var result = tryCatch(this._fn)(x, this._i++, this._s);
|
6005 | if (result === errorObj) { return this._o.onError(result.e); }
|
6006 | if (Boolean(result)) {
|
6007 | this._o.onNext(true);
|
6008 | this._o.onCompleted();
|
6009 | }
|
6010 | };
|
6011 | SomeObserver.prototype.error = function (e) { this._o.onError(e); };
|
6012 | SomeObserver.prototype.completed = function () {
|
6013 | this._o.onNext(false);
|
6014 | this._o.onCompleted();
|
6015 | };
|
6016 |
|
6017 | return SomeObserver;
|
6018 | }(AbstractObserver));
|
6019 |
|
6020 | |
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 | observableProto.some = function (predicate, thisArg) {
|
6026 | var fn = bindCallback(predicate, thisArg, 3);
|
6027 | return new SomeObservable(this, fn);
|
6028 | };
|
6029 |
|
6030 | var IsEmptyObservable = (function (__super__) {
|
6031 | inherits(IsEmptyObservable, __super__);
|
6032 | function IsEmptyObservable(source) {
|
6033 | this.source = source;
|
6034 | __super__.call(this);
|
6035 | }
|
6036 |
|
6037 | IsEmptyObservable.prototype.subscribeCore = function (o) {
|
6038 | return this.source.subscribe(new IsEmptyObserver(o));
|
6039 | };
|
6040 |
|
6041 | return IsEmptyObservable;
|
6042 | }(ObservableBase));
|
6043 |
|
6044 | var IsEmptyObserver = (function(__super__) {
|
6045 | inherits(IsEmptyObserver, __super__);
|
6046 | function IsEmptyObserver(o) {
|
6047 | this._o = o;
|
6048 | __super__.call(this);
|
6049 | }
|
6050 |
|
6051 | IsEmptyObserver.prototype.next = function () {
|
6052 | this._o.onNext(false);
|
6053 | this._o.onCompleted();
|
6054 | };
|
6055 | IsEmptyObserver.prototype.error = function (e) { this._o.onError(e); };
|
6056 | IsEmptyObserver.prototype.completed = function () {
|
6057 | this._o.onNext(true);
|
6058 | this._o.onCompleted();
|
6059 | };
|
6060 |
|
6061 | return IsEmptyObserver;
|
6062 | }(AbstractObserver));
|
6063 |
|
6064 | |
6065 |
|
6066 |
|
6067 |
|
6068 | observableProto.isEmpty = function () {
|
6069 | return new IsEmptyObservable(this);
|
6070 | };
|
6071 |
|
6072 | var EveryObservable = (function (__super__) {
|
6073 | inherits(EveryObservable, __super__);
|
6074 | function EveryObservable(source, fn) {
|
6075 | this.source = source;
|
6076 | this._fn = fn;
|
6077 | __super__.call(this);
|
6078 | }
|
6079 |
|
6080 | EveryObservable.prototype.subscribeCore = function (o) {
|
6081 | return this.source.subscribe(new EveryObserver(o, this._fn, this.source));
|
6082 | };
|
6083 |
|
6084 | return EveryObservable;
|
6085 | }(ObservableBase));
|
6086 |
|
6087 | var EveryObserver = (function (__super__) {
|
6088 | inherits(EveryObserver, __super__);
|
6089 |
|
6090 | function EveryObserver(o, fn, s) {
|
6091 | this._o = o;
|
6092 | this._fn = fn;
|
6093 | this._s = s;
|
6094 | this._i = 0;
|
6095 | __super__.call(this);
|
6096 | }
|
6097 |
|
6098 | EveryObserver.prototype.next = function (x) {
|
6099 | var result = tryCatch(this._fn)(x, this._i++, this._s);
|
6100 | if (result === errorObj) { return this._o.onError(result.e); }
|
6101 | if (!Boolean(result)) {
|
6102 | this._o.onNext(false);
|
6103 | this._o.onCompleted();
|
6104 | }
|
6105 | };
|
6106 | EveryObserver.prototype.error = function (e) { this._o.onError(e); };
|
6107 | EveryObserver.prototype.completed = function () {
|
6108 | this._o.onNext(true);
|
6109 | this._o.onCompleted();
|
6110 | };
|
6111 |
|
6112 | return EveryObserver;
|
6113 | }(AbstractObserver));
|
6114 |
|
6115 | |
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 | observableProto.every = function (predicate, thisArg) {
|
6122 | var fn = bindCallback(predicate, thisArg, 3);
|
6123 | return new EveryObservable(this, fn);
|
6124 | };
|
6125 |
|
6126 | var IncludesObservable = (function (__super__) {
|
6127 | inherits(IncludesObservable, __super__);
|
6128 | function IncludesObservable(source, elem, idx) {
|
6129 | var n = +idx || 0;
|
6130 | Math.abs(n) === Infinity && (n = 0);
|
6131 |
|
6132 | this.source = source;
|
6133 | this._elem = elem;
|
6134 | this._n = n;
|
6135 | __super__.call(this);
|
6136 | }
|
6137 |
|
6138 | IncludesObservable.prototype.subscribeCore = function (o) {
|
6139 | if (this._n < 0) {
|
6140 | o.onNext(false);
|
6141 | o.onCompleted();
|
6142 | return disposableEmpty;
|
6143 | }
|
6144 |
|
6145 | return this.source.subscribe(new IncludesObserver(o, this._elem, this._n));
|
6146 | };
|
6147 |
|
6148 | return IncludesObservable;
|
6149 | }(ObservableBase));
|
6150 |
|
6151 | var IncludesObserver = (function (__super__) {
|
6152 | inherits(IncludesObserver, __super__);
|
6153 | function IncludesObserver(o, elem, n) {
|
6154 | this._o = o;
|
6155 | this._elem = elem;
|
6156 | this._n = n;
|
6157 | this._i = 0;
|
6158 | __super__.call(this);
|
6159 | }
|
6160 |
|
6161 | function comparer(a, b) {
|
6162 | return (a === 0 && b === 0) || (a === b || (isNaN(a) && isNaN(b)));
|
6163 | }
|
6164 |
|
6165 | IncludesObserver.prototype.next = function (x) {
|
6166 | if (this._i++ >= this._n && comparer(x, this._elem)) {
|
6167 | this._o.onNext(true);
|
6168 | this._o.onCompleted();
|
6169 | }
|
6170 | };
|
6171 | IncludesObserver.prototype.error = function (e) { this._o.onError(e); };
|
6172 | IncludesObserver.prototype.completed = function () { this._o.onNext(false); this._o.onCompleted(); };
|
6173 |
|
6174 | return IncludesObserver;
|
6175 | }(AbstractObserver));
|
6176 |
|
6177 | |
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 | observableProto.includes = function (searchElement, fromIndex) {
|
6184 | return new IncludesObservable(this, searchElement, fromIndex);
|
6185 | };
|
6186 |
|
6187 | var CountObservable = (function (__super__) {
|
6188 | inherits(CountObservable, __super__);
|
6189 | function CountObservable(source, fn) {
|
6190 | this.source = source;
|
6191 | this._fn = fn;
|
6192 | __super__.call(this);
|
6193 | }
|
6194 |
|
6195 | CountObservable.prototype.subscribeCore = function (o) {
|
6196 | return this.source.subscribe(new CountObserver(o, this._fn, this.source));
|
6197 | };
|
6198 |
|
6199 | return CountObservable;
|
6200 | }(ObservableBase));
|
6201 |
|
6202 | var CountObserver = (function (__super__) {
|
6203 | inherits(CountObserver, __super__);
|
6204 |
|
6205 | function CountObserver(o, fn, s) {
|
6206 | this._o = o;
|
6207 | this._fn = fn;
|
6208 | this._s = s;
|
6209 | this._i = 0;
|
6210 | this._c = 0;
|
6211 | __super__.call(this);
|
6212 | }
|
6213 |
|
6214 | CountObserver.prototype.next = function (x) {
|
6215 | if (this._fn) {
|
6216 | var result = tryCatch(this._fn)(x, this._i++, this._s);
|
6217 | if (result === errorObj) { return this._o.onError(result.e); }
|
6218 | Boolean(result) && (this._c++);
|
6219 | } else {
|
6220 | this._c++;
|
6221 | }
|
6222 | };
|
6223 | CountObserver.prototype.error = function (e) { this._o.onError(e); };
|
6224 | CountObserver.prototype.completed = function () {
|
6225 | this._o.onNext(this._c);
|
6226 | this._o.onCompleted();
|
6227 | };
|
6228 |
|
6229 | return CountObserver;
|
6230 | }(AbstractObserver));
|
6231 |
|
6232 | |
6233 |
|
6234 |
|
6235 |
|
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 | observableProto.count = function (predicate, thisArg) {
|
6242 | var fn = bindCallback(predicate, thisArg, 3);
|
6243 | return new CountObservable(this, fn);
|
6244 | };
|
6245 |
|
6246 | var IndexOfObservable = (function (__super__) {
|
6247 | inherits(IndexOfObservable, __super__);
|
6248 | function IndexOfObservable(source, e, n) {
|
6249 | this.source = source;
|
6250 | this._e = e;
|
6251 | this._n = n;
|
6252 | __super__.call(this);
|
6253 | }
|
6254 |
|
6255 | IndexOfObservable.prototype.subscribeCore = function (o) {
|
6256 | if (this._n < 0) {
|
6257 | o.onNext(-1);
|
6258 | o.onCompleted();
|
6259 | return disposableEmpty;
|
6260 | }
|
6261 |
|
6262 | return this.source.subscribe(new IndexOfObserver(o, this._e, this._n));
|
6263 | };
|
6264 |
|
6265 | return IndexOfObservable;
|
6266 | }(ObservableBase));
|
6267 |
|
6268 | var IndexOfObserver = (function (__super__) {
|
6269 | inherits(IndexOfObserver, __super__);
|
6270 | function IndexOfObserver(o, e, n) {
|
6271 | this._o = o;
|
6272 | this._e = e;
|
6273 | this._n = n;
|
6274 | this._i = 0;
|
6275 | __super__.call(this);
|
6276 | }
|
6277 |
|
6278 | IndexOfObserver.prototype.next = function (x) {
|
6279 | if (this._i >= this._n && x === this._e) {
|
6280 | this._o.onNext(this._i);
|
6281 | this._o.onCompleted();
|
6282 | }
|
6283 | this._i++;
|
6284 | };
|
6285 | IndexOfObserver.prototype.error = function (e) { this._o.onError(e); };
|
6286 | IndexOfObserver.prototype.completed = function () { this._o.onNext(-1); this._o.onCompleted(); };
|
6287 |
|
6288 | return IndexOfObserver;
|
6289 | }(AbstractObserver));
|
6290 |
|
6291 | |
6292 |
|
6293 |
|
6294 |
|
6295 |
|
6296 |
|
6297 | observableProto.indexOf = function(searchElement, fromIndex) {
|
6298 | var n = +fromIndex || 0;
|
6299 | Math.abs(n) === Infinity && (n = 0);
|
6300 | return new IndexOfObservable(this, searchElement, n);
|
6301 | };
|
6302 |
|
6303 | var SumObservable = (function (__super__) {
|
6304 | inherits(SumObservable, __super__);
|
6305 | function SumObservable(source, fn) {
|
6306 | this.source = source;
|
6307 | this._fn = fn;
|
6308 | __super__.call(this);
|
6309 | }
|
6310 |
|
6311 | SumObservable.prototype.subscribeCore = function (o) {
|
6312 | return this.source.subscribe(new SumObserver(o, this._fn, this.source));
|
6313 | };
|
6314 |
|
6315 | return SumObservable;
|
6316 | }(ObservableBase));
|
6317 |
|
6318 | var SumObserver = (function (__super__) {
|
6319 | inherits(SumObserver, __super__);
|
6320 |
|
6321 | function SumObserver(o, fn, s) {
|
6322 | this._o = o;
|
6323 | this._fn = fn;
|
6324 | this._s = s;
|
6325 | this._i = 0;
|
6326 | this._c = 0;
|
6327 | __super__.call(this);
|
6328 | }
|
6329 |
|
6330 | SumObserver.prototype.next = function (x) {
|
6331 | if (this._fn) {
|
6332 | var result = tryCatch(this._fn)(x, this._i++, this._s);
|
6333 | if (result === errorObj) { return this._o.onError(result.e); }
|
6334 | this._c += result;
|
6335 | } else {
|
6336 | this._c += x;
|
6337 | }
|
6338 | };
|
6339 | SumObserver.prototype.error = function (e) { this._o.onError(e); };
|
6340 | SumObserver.prototype.completed = function () {
|
6341 | this._o.onNext(this._c);
|
6342 | this._o.onCompleted();
|
6343 | };
|
6344 |
|
6345 | return SumObserver;
|
6346 | }(AbstractObserver));
|
6347 |
|
6348 | |
6349 |
|
6350 |
|
6351 |
|
6352 |
|
6353 |
|
6354 | observableProto.sum = function (keySelector, thisArg) {
|
6355 | var fn = bindCallback(keySelector, thisArg, 3);
|
6356 | return new SumObservable(this, fn);
|
6357 | };
|
6358 |
|
6359 | |
6360 |
|
6361 |
|
6362 |
|
6363 |
|
6364 |
|
6365 |
|
6366 |
|
6367 |
|
6368 | observableProto.minBy = function (keySelector, comparer) {
|
6369 | comparer || (comparer = defaultSubComparer);
|
6370 | return new ExtremaByObservable(this, keySelector, function (x, y) { return comparer(x, y) * -1; });
|
6371 | };
|
6372 |
|
6373 | |
6374 |
|
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 | observableProto.min = function (comparer) {
|
6382 | return this.minBy(identity, comparer).map(function (x) { return firstOnly(x); });
|
6383 | };
|
6384 |
|
6385 | |
6386 |
|
6387 |
|
6388 |
|
6389 |
|
6390 |
|
6391 |
|
6392 |
|
6393 |
|
6394 | observableProto.maxBy = function (keySelector, comparer) {
|
6395 | comparer || (comparer = defaultSubComparer);
|
6396 | return new ExtremaByObservable(this, keySelector, comparer);
|
6397 | };
|
6398 |
|
6399 | |
6400 |
|
6401 |
|
6402 |
|
6403 |
|
6404 |
|
6405 |
|
6406 |
|
6407 | observableProto.max = function (comparer) {
|
6408 | return this.maxBy(identity, comparer).map(function (x) { return firstOnly(x); });
|
6409 | };
|
6410 |
|
6411 | var AverageObservable = (function (__super__) {
|
6412 | inherits(AverageObservable, __super__);
|
6413 | function AverageObservable(source, fn) {
|
6414 | this.source = source;
|
6415 | this._fn = fn;
|
6416 | __super__.call(this);
|
6417 | }
|
6418 |
|
6419 | AverageObservable.prototype.subscribeCore = function (o) {
|
6420 | return this.source.subscribe(new AverageObserver(o, this._fn, this.source));
|
6421 | };
|
6422 |
|
6423 | return AverageObservable;
|
6424 | }(ObservableBase));
|
6425 |
|
6426 | var AverageObserver = (function(__super__) {
|
6427 | inherits(AverageObserver, __super__);
|
6428 | function AverageObserver(o, fn, s) {
|
6429 | this._o = o;
|
6430 | this._fn = fn;
|
6431 | this._s = s;
|
6432 | this._c = 0;
|
6433 | this._t = 0;
|
6434 | __super__.call(this);
|
6435 | }
|
6436 |
|
6437 | AverageObserver.prototype.next = function (x) {
|
6438 | if(this._fn) {
|
6439 | var r = tryCatch(this._fn)(x, this._c++, this._s);
|
6440 | if (r === errorObj) { return this._o.onError(r.e); }
|
6441 | this._t += r;
|
6442 | } else {
|
6443 | this._c++;
|
6444 | this._t += x;
|
6445 | }
|
6446 | };
|
6447 | AverageObserver.prototype.error = function (e) { this._o.onError(e); };
|
6448 | AverageObserver.prototype.completed = function () {
|
6449 | if (this._c === 0) { return this._o.onError(new EmptyError()); }
|
6450 | this._o.onNext(this._t / this._c);
|
6451 | this._o.onCompleted();
|
6452 | };
|
6453 |
|
6454 | return AverageObserver;
|
6455 | }(AbstractObserver));
|
6456 |
|
6457 | |
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 | observableProto.average = function (keySelector, thisArg) {
|
6464 | var source = this, fn;
|
6465 | if (isFunction(keySelector)) {
|
6466 | fn = bindCallback(keySelector, thisArg, 3);
|
6467 | }
|
6468 | return new AverageObservable(source, fn);
|
6469 | };
|
6470 |
|
6471 | |
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 |
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 | observableProto.sequenceEqual = function (second, comparer) {
|
6484 | var first = this;
|
6485 | comparer || (comparer = defaultComparer);
|
6486 | return new AnonymousObservable(function (o) {
|
6487 | var donel = false, doner = false, ql = [], qr = [];
|
6488 | var subscription1 = first.subscribe(function (x) {
|
6489 | if (qr.length > 0) {
|
6490 | var v = qr.shift();
|
6491 | var equal = tryCatch(comparer)(v, x);
|
6492 | if (equal === errorObj) { return o.onError(equal.e); }
|
6493 | if (!equal) {
|
6494 | o.onNext(false);
|
6495 | o.onCompleted();
|
6496 | }
|
6497 | } else if (doner) {
|
6498 | o.onNext(false);
|
6499 | o.onCompleted();
|
6500 | } else {
|
6501 | ql.push(x);
|
6502 | }
|
6503 | }, function(e) { o.onError(e); }, function () {
|
6504 | donel = true;
|
6505 | if (ql.length === 0) {
|
6506 | if (qr.length > 0) {
|
6507 | o.onNext(false);
|
6508 | o.onCompleted();
|
6509 | } else if (doner) {
|
6510 | o.onNext(true);
|
6511 | o.onCompleted();
|
6512 | }
|
6513 | }
|
6514 | });
|
6515 |
|
6516 | (isArrayLike(second) || isIterable(second)) && (second = observableFrom(second));
|
6517 | isPromise(second) && (second = observableFromPromise(second));
|
6518 | var subscription2 = second.subscribe(function (x) {
|
6519 | if (ql.length > 0) {
|
6520 | var v = ql.shift();
|
6521 | var equal = tryCatch(comparer)(v, x);
|
6522 | if (equal === errorObj) { return o.onError(equal.e); }
|
6523 | if (!equal) {
|
6524 | o.onNext(false);
|
6525 | o.onCompleted();
|
6526 | }
|
6527 | } else if (donel) {
|
6528 | o.onNext(false);
|
6529 | o.onCompleted();
|
6530 | } else {
|
6531 | qr.push(x);
|
6532 | }
|
6533 | }, function(e) { o.onError(e); }, function () {
|
6534 | doner = true;
|
6535 | if (qr.length === 0) {
|
6536 | if (ql.length > 0) {
|
6537 | o.onNext(false);
|
6538 | o.onCompleted();
|
6539 | } else if (donel) {
|
6540 | o.onNext(true);
|
6541 | o.onCompleted();
|
6542 | }
|
6543 | }
|
6544 | });
|
6545 | return new BinaryDisposable(subscription1, subscription2);
|
6546 | }, first);
|
6547 | };
|
6548 |
|
6549 | var ElementAtObservable = (function (__super__) {
|
6550 | inherits(ElementAtObservable, __super__);
|
6551 | function ElementAtObservable(source, i, d) {
|
6552 | this.source = source;
|
6553 | this._i = i;
|
6554 | this._d = d;
|
6555 | __super__.call(this);
|
6556 | }
|
6557 |
|
6558 | ElementAtObservable.prototype.subscribeCore = function (o) {
|
6559 | return this.source.subscribe(new ElementAtObserver(o, this._i, this._d));
|
6560 | };
|
6561 |
|
6562 | return ElementAtObservable;
|
6563 | }(ObservableBase));
|
6564 |
|
6565 | var ElementAtObserver = (function (__super__) {
|
6566 | inherits(ElementAtObserver, __super__);
|
6567 |
|
6568 | function ElementAtObserver(o, i, d) {
|
6569 | this._o = o;
|
6570 | this._i = i;
|
6571 | this._d = d;
|
6572 | __super__.call(this);
|
6573 | }
|
6574 |
|
6575 | ElementAtObserver.prototype.next = function (x) {
|
6576 | if (this._i-- === 0) {
|
6577 | this._o.onNext(x);
|
6578 | this._o.onCompleted();
|
6579 | }
|
6580 | };
|
6581 | ElementAtObserver.prototype.error = function (e) { this._o.onError(e); };
|
6582 | ElementAtObserver.prototype.completed = function () {
|
6583 | if (this._d === undefined) {
|
6584 | this._o.onError(new ArgumentOutOfRangeError());
|
6585 | } else {
|
6586 | this._o.onNext(this._d);
|
6587 | this._o.onCompleted();
|
6588 | }
|
6589 | };
|
6590 |
|
6591 | return ElementAtObserver;
|
6592 | }(AbstractObserver));
|
6593 |
|
6594 | |
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 | observableProto.elementAt = function (index, defaultValue) {
|
6601 | if (index < 0) { throw new ArgumentOutOfRangeError(); }
|
6602 | return new ElementAtObservable(this, index, defaultValue);
|
6603 | };
|
6604 |
|
6605 | var SingleObserver = (function(__super__) {
|
6606 | inherits(SingleObserver, __super__);
|
6607 | function SingleObserver(o, obj, s) {
|
6608 | this._o = o;
|
6609 | this._obj = obj;
|
6610 | this._s = s;
|
6611 | this._i = 0;
|
6612 | this._hv = false;
|
6613 | this._v = null;
|
6614 | __super__.call(this);
|
6615 | }
|
6616 |
|
6617 | SingleObserver.prototype.next = function (x) {
|
6618 | var shouldYield = false;
|
6619 | if (this._obj.predicate) {
|
6620 | var res = tryCatch(this._obj.predicate)(x, this._i++, this._s);
|
6621 | if (res === errorObj) { return this._o.onError(res.e); }
|
6622 | Boolean(res) && (shouldYield = true);
|
6623 | } else if (!this._obj.predicate) {
|
6624 | shouldYield = true;
|
6625 | }
|
6626 | if (shouldYield) {
|
6627 | if (this._hv) {
|
6628 | return this._o.onError(new Error('Sequence contains more than one matching element'));
|
6629 | }
|
6630 | this._hv = true;
|
6631 | this._v = x;
|
6632 | }
|
6633 | };
|
6634 | SingleObserver.prototype.error = function (e) { this._o.onError(e); };
|
6635 | SingleObserver.prototype.completed = function () {
|
6636 | if (this._hv) {
|
6637 | this._o.onNext(this._v);
|
6638 | this._o.onCompleted();
|
6639 | }
|
6640 | else if (this._obj.defaultValue === undefined) {
|
6641 | this._o.onError(new EmptyError());
|
6642 | } else {
|
6643 | this._o.onNext(this._obj.defaultValue);
|
6644 | this._o.onCompleted();
|
6645 | }
|
6646 | };
|
6647 |
|
6648 | return SingleObserver;
|
6649 | }(AbstractObserver));
|
6650 |
|
6651 |
|
6652 | |
6653 |
|
6654 |
|
6655 |
|
6656 | observableProto.single = function (predicate, thisArg) {
|
6657 | var obj = {}, source = this;
|
6658 | if (typeof arguments[0] === 'object') {
|
6659 | obj = arguments[0];
|
6660 | } else {
|
6661 | obj = {
|
6662 | predicate: arguments[0],
|
6663 | thisArg: arguments[1],
|
6664 | defaultValue: arguments[2]
|
6665 | };
|
6666 | }
|
6667 | if (isFunction (obj.predicate)) {
|
6668 | var fn = obj.predicate;
|
6669 | obj.predicate = bindCallback(fn, obj.thisArg, 3);
|
6670 | }
|
6671 | return new AnonymousObservable(function (o) {
|
6672 | return source.subscribe(new SingleObserver(o, obj, source));
|
6673 | }, source);
|
6674 | };
|
6675 |
|
6676 | var FirstObservable = (function (__super__) {
|
6677 | inherits(FirstObservable, __super__);
|
6678 | function FirstObservable(source, obj) {
|
6679 | this.source = source;
|
6680 | this._obj = obj;
|
6681 | __super__.call(this);
|
6682 | }
|
6683 |
|
6684 | FirstObservable.prototype.subscribeCore = function (o) {
|
6685 | return this.source.subscribe(new FirstObserver(o, this._obj, this.source));
|
6686 | };
|
6687 |
|
6688 | return FirstObservable;
|
6689 | }(ObservableBase));
|
6690 |
|
6691 | var FirstObserver = (function(__super__) {
|
6692 | inherits(FirstObserver, __super__);
|
6693 | function FirstObserver(o, obj, s) {
|
6694 | this._o = o;
|
6695 | this._obj = obj;
|
6696 | this._s = s;
|
6697 | this._i = 0;
|
6698 | __super__.call(this);
|
6699 | }
|
6700 |
|
6701 | FirstObserver.prototype.next = function (x) {
|
6702 | if (this._obj.predicate) {
|
6703 | var res = tryCatch(this._obj.predicate)(x, this._i++, this._s);
|
6704 | if (res === errorObj) { return this._o.onError(res.e); }
|
6705 | if (Boolean(res)) {
|
6706 | this._o.onNext(x);
|
6707 | this._o.onCompleted();
|
6708 | }
|
6709 | } else if (!this._obj.predicate) {
|
6710 | this._o.onNext(x);
|
6711 | this._o.onCompleted();
|
6712 | }
|
6713 | };
|
6714 | FirstObserver.prototype.error = function (e) { this._o.onError(e); };
|
6715 | FirstObserver.prototype.completed = function () {
|
6716 | if (this._obj.defaultValue === undefined) {
|
6717 | this._o.onError(new EmptyError());
|
6718 | } else {
|
6719 | this._o.onNext(this._obj.defaultValue);
|
6720 | this._o.onCompleted();
|
6721 | }
|
6722 | };
|
6723 |
|
6724 | return FirstObserver;
|
6725 | }(AbstractObserver));
|
6726 |
|
6727 | |
6728 |
|
6729 |
|
6730 |
|
6731 | observableProto.first = function () {
|
6732 | var obj = {}, source = this;
|
6733 | if (typeof arguments[0] === 'object') {
|
6734 | obj = arguments[0];
|
6735 | } else {
|
6736 | obj = {
|
6737 | predicate: arguments[0],
|
6738 | thisArg: arguments[1],
|
6739 | defaultValue: arguments[2]
|
6740 | };
|
6741 | }
|
6742 | if (isFunction (obj.predicate)) {
|
6743 | var fn = obj.predicate;
|
6744 | obj.predicate = bindCallback(fn, obj.thisArg, 3);
|
6745 | }
|
6746 | return new FirstObservable(this, obj);
|
6747 | };
|
6748 |
|
6749 | var LastObservable = (function (__super__) {
|
6750 | inherits(LastObservable, __super__);
|
6751 | function LastObservable(source, obj) {
|
6752 | this.source = source;
|
6753 | this._obj = obj;
|
6754 | __super__.call(this);
|
6755 | }
|
6756 |
|
6757 | LastObservable.prototype.subscribeCore = function (o) {
|
6758 | return this.source.subscribe(new LastObserver(o, this._obj, this.source));
|
6759 | };
|
6760 |
|
6761 | return LastObservable;
|
6762 | }(ObservableBase));
|
6763 |
|
6764 | var LastObserver = (function(__super__) {
|
6765 | inherits(LastObserver, __super__);
|
6766 | function LastObserver(o, obj, s) {
|
6767 | this._o = o;
|
6768 | this._obj = obj;
|
6769 | this._s = s;
|
6770 | this._i = 0;
|
6771 | this._hv = false;
|
6772 | this._v = null;
|
6773 | __super__.call(this);
|
6774 | }
|
6775 |
|
6776 | LastObserver.prototype.next = function (x) {
|
6777 | var shouldYield = false;
|
6778 | if (this._obj.predicate) {
|
6779 | var res = tryCatch(this._obj.predicate)(x, this._i++, this._s);
|
6780 | if (res === errorObj) { return this._o.onError(res.e); }
|
6781 | Boolean(res) && (shouldYield = true);
|
6782 | } else if (!this._obj.predicate) {
|
6783 | shouldYield = true;
|
6784 | }
|
6785 | if (shouldYield) {
|
6786 | this._hv = true;
|
6787 | this._v = x;
|
6788 | }
|
6789 | };
|
6790 | LastObserver.prototype.error = function (e) { this._o.onError(e); };
|
6791 | LastObserver.prototype.completed = function () {
|
6792 | if (this._hv) {
|
6793 | this._o.onNext(this._v);
|
6794 | this._o.onCompleted();
|
6795 | }
|
6796 | else if (this._obj.defaultValue === undefined) {
|
6797 | this._o.onError(new EmptyError());
|
6798 | } else {
|
6799 | this._o.onNext(this._obj.defaultValue);
|
6800 | this._o.onCompleted();
|
6801 | }
|
6802 | };
|
6803 |
|
6804 | return LastObserver;
|
6805 | }(AbstractObserver));
|
6806 |
|
6807 | |
6808 |
|
6809 |
|
6810 |
|
6811 | observableProto.last = function () {
|
6812 | var obj = {}, source = this;
|
6813 | if (typeof arguments[0] === 'object') {
|
6814 | obj = arguments[0];
|
6815 | } else {
|
6816 | obj = {
|
6817 | predicate: arguments[0],
|
6818 | thisArg: arguments[1],
|
6819 | defaultValue: arguments[2]
|
6820 | };
|
6821 | }
|
6822 | if (isFunction (obj.predicate)) {
|
6823 | var fn = obj.predicate;
|
6824 | obj.predicate = bindCallback(fn, obj.thisArg, 3);
|
6825 | }
|
6826 | return new LastObservable(this, obj);
|
6827 | };
|
6828 |
|
6829 | var FindValueObserver = (function(__super__) {
|
6830 | inherits(FindValueObserver, __super__);
|
6831 | function FindValueObserver(observer, source, callback, yieldIndex) {
|
6832 | this._o = observer;
|
6833 | this._s = source;
|
6834 | this._cb = callback;
|
6835 | this._y = yieldIndex;
|
6836 | this._i = 0;
|
6837 | __super__.call(this);
|
6838 | }
|
6839 |
|
6840 | FindValueObserver.prototype.next = function (x) {
|
6841 | var shouldRun = tryCatch(this._cb)(x, this._i, this._s);
|
6842 | if (shouldRun === errorObj) { return this._o.onError(shouldRun.e); }
|
6843 | if (shouldRun) {
|
6844 | this._o.onNext(this._y ? this._i : x);
|
6845 | this._o.onCompleted();
|
6846 | } else {
|
6847 | this._i++;
|
6848 | }
|
6849 | };
|
6850 |
|
6851 | FindValueObserver.prototype.error = function (e) {
|
6852 | this._o.onError(e);
|
6853 | };
|
6854 |
|
6855 | FindValueObserver.prototype.completed = function () {
|
6856 | this._y && this._o.onNext(-1);
|
6857 | this._o.onCompleted();
|
6858 | };
|
6859 |
|
6860 | return FindValueObserver;
|
6861 | }(AbstractObserver));
|
6862 |
|
6863 | function findValue (source, predicate, thisArg, yieldIndex) {
|
6864 | var callback = bindCallback(predicate, thisArg, 3);
|
6865 | return new AnonymousObservable(function (o) {
|
6866 | return source.subscribe(new FindValueObserver(o, source, callback, yieldIndex));
|
6867 | }, source);
|
6868 | }
|
6869 |
|
6870 | |
6871 |
|
6872 |
|
6873 |
|
6874 |
|
6875 |
|
6876 | observableProto.find = function (predicate, thisArg) {
|
6877 | return findValue(this, predicate, thisArg, false);
|
6878 | };
|
6879 |
|
6880 | |
6881 |
|
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 | observableProto.findIndex = function (predicate, thisArg) {
|
6888 | return findValue(this, predicate, thisArg, true);
|
6889 | };
|
6890 |
|
6891 | var ToSetObservable = (function (__super__) {
|
6892 | inherits(ToSetObservable, __super__);
|
6893 | function ToSetObservable(source) {
|
6894 | this.source = source;
|
6895 | __super__.call(this);
|
6896 | }
|
6897 |
|
6898 | ToSetObservable.prototype.subscribeCore = function (o) {
|
6899 | return this.source.subscribe(new ToSetObserver(o));
|
6900 | };
|
6901 |
|
6902 | return ToSetObservable;
|
6903 | }(ObservableBase));
|
6904 |
|
6905 | var ToSetObserver = (function (__super__) {
|
6906 | inherits(ToSetObserver, __super__);
|
6907 | function ToSetObserver(o) {
|
6908 | this._o = o;
|
6909 | this._s = new root.Set();
|
6910 | __super__.call(this);
|
6911 | }
|
6912 |
|
6913 | ToSetObserver.prototype.next = function (x) {
|
6914 | this._s.add(x);
|
6915 | };
|
6916 |
|
6917 | ToSetObserver.prototype.error = function (e) {
|
6918 | this._o.onError(e);
|
6919 | };
|
6920 |
|
6921 | ToSetObserver.prototype.completed = function () {
|
6922 | this._o.onNext(this._s);
|
6923 | this._o.onCompleted();
|
6924 | };
|
6925 |
|
6926 | return ToSetObserver;
|
6927 | }(AbstractObserver));
|
6928 |
|
6929 | |
6930 |
|
6931 |
|
6932 |
|
6933 | observableProto.toSet = function () {
|
6934 | if (typeof root.Set === 'undefined') { throw new TypeError(); }
|
6935 | return new ToSetObservable(this);
|
6936 | };
|
6937 |
|
6938 | var ToMapObservable = (function (__super__) {
|
6939 | inherits(ToMapObservable, __super__);
|
6940 | function ToMapObservable(source, k, e) {
|
6941 | this.source = source;
|
6942 | this._k = k;
|
6943 | this._e = e;
|
6944 | __super__.call(this);
|
6945 | }
|
6946 |
|
6947 | ToMapObservable.prototype.subscribeCore = function (o) {
|
6948 | return this.source.subscribe(new ToMapObserver(o, this._k, this._e));
|
6949 | };
|
6950 |
|
6951 | return ToMapObservable;
|
6952 | }(ObservableBase));
|
6953 |
|
6954 | var ToMapObserver = (function (__super__) {
|
6955 | inherits(ToMapObserver, __super__);
|
6956 | function ToMapObserver(o, k, e) {
|
6957 | this._o = o;
|
6958 | this._k = k;
|
6959 | this._e = e;
|
6960 | this._m = new root.Map();
|
6961 | __super__.call(this);
|
6962 | }
|
6963 |
|
6964 | ToMapObserver.prototype.next = function (x) {
|
6965 | var key = tryCatch(this._k)(x);
|
6966 | if (key === errorObj) { return this._o.onError(key.e); }
|
6967 | var elem = x;
|
6968 | if (this._e) {
|
6969 | elem = tryCatch(this._e)(x);
|
6970 | if (elem === errorObj) { return this._o.onError(elem.e); }
|
6971 | }
|
6972 |
|
6973 | this._m.set(key, elem);
|
6974 | };
|
6975 |
|
6976 | ToMapObserver.prototype.error = function (e) {
|
6977 | this._o.onError(e);
|
6978 | };
|
6979 |
|
6980 | ToMapObserver.prototype.completed = function () {
|
6981 | this._o.onNext(this._m);
|
6982 | this._o.onCompleted();
|
6983 | };
|
6984 |
|
6985 | return ToMapObserver;
|
6986 | }(AbstractObserver));
|
6987 |
|
6988 | |
6989 |
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 | observableProto.toMap = function (keySelector, elementSelector) {
|
6995 | if (typeof root.Map === 'undefined') { throw new TypeError(); }
|
6996 | return new ToMapObservable(this, keySelector, elementSelector);
|
6997 | };
|
6998 |
|
6999 | var SliceObservable = (function (__super__) {
|
7000 | inherits(SliceObservable, __super__);
|
7001 | function SliceObservable(source, b, e) {
|
7002 | this.source = source;
|
7003 | this._b = b;
|
7004 | this._e = e;
|
7005 | __super__.call(this);
|
7006 | }
|
7007 |
|
7008 | SliceObservable.prototype.subscribeCore = function (o) {
|
7009 | return this.source.subscribe(new SliceObserver(o, this._b, this._e));
|
7010 | };
|
7011 |
|
7012 | return SliceObservable;
|
7013 | }(ObservableBase));
|
7014 |
|
7015 | var SliceObserver = (function (__super__) {
|
7016 | inherits(SliceObserver, __super__);
|
7017 |
|
7018 | function SliceObserver(o, b, e) {
|
7019 | this._o = o;
|
7020 | this._b = b;
|
7021 | this._e = e;
|
7022 | this._i = 0;
|
7023 | __super__.call(this);
|
7024 | }
|
7025 |
|
7026 | SliceObserver.prototype.next = function (x) {
|
7027 | if (this._i >= this._b) {
|
7028 | if (this._e === this._i) {
|
7029 | this._o.onCompleted();
|
7030 | } else {
|
7031 | this._o.onNext(x);
|
7032 | }
|
7033 | }
|
7034 | this._i++;
|
7035 | };
|
7036 | SliceObserver.prototype.error = function (e) { this._o.onError(e); };
|
7037 | SliceObserver.prototype.completed = function () { this._o.onCompleted(); };
|
7038 |
|
7039 | return SliceObserver;
|
7040 | }(AbstractObserver));
|
7041 |
|
7042 | |
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 |
|
7049 |
|
7050 | observableProto.slice = function (begin, end) {
|
7051 | var start = begin || 0;
|
7052 | if (start < 0) { throw new Rx.ArgumentOutOfRangeError(); }
|
7053 | if (typeof end === 'number' && end < start) {
|
7054 | throw new Rx.ArgumentOutOfRangeError();
|
7055 | }
|
7056 | return new SliceObservable(this, start, end);
|
7057 | };
|
7058 |
|
7059 | var LastIndexOfObservable = (function (__super__) {
|
7060 | inherits(LastIndexOfObservable, __super__);
|
7061 | function LastIndexOfObservable(source, e, n) {
|
7062 | this.source = source;
|
7063 | this._e = e;
|
7064 | this._n = n;
|
7065 | __super__.call(this);
|
7066 | }
|
7067 |
|
7068 | LastIndexOfObservable.prototype.subscribeCore = function (o) {
|
7069 | if (this._n < 0) {
|
7070 | o.onNext(-1);
|
7071 | o.onCompleted();
|
7072 | return disposableEmpty;
|
7073 | }
|
7074 |
|
7075 | return this.source.subscribe(new LastIndexOfObserver(o, this._e, this._n));
|
7076 | };
|
7077 |
|
7078 | return LastIndexOfObservable;
|
7079 | }(ObservableBase));
|
7080 |
|
7081 | var LastIndexOfObserver = (function (__super__) {
|
7082 | inherits(LastIndexOfObserver, __super__);
|
7083 | function LastIndexOfObserver(o, e, n) {
|
7084 | this._o = o;
|
7085 | this._e = e;
|
7086 | this._n = n;
|
7087 | this._v = 0;
|
7088 | this._hv = false;
|
7089 | this._i = 0;
|
7090 | __super__.call(this);
|
7091 | }
|
7092 |
|
7093 | LastIndexOfObserver.prototype.next = function (x) {
|
7094 | if (this._i >= this._n && x === this._e) {
|
7095 | this._hv = true;
|
7096 | this._v = this._i;
|
7097 | }
|
7098 | this._i++;
|
7099 | };
|
7100 | LastIndexOfObserver.prototype.error = function (e) { this._o.onError(e); };
|
7101 | LastIndexOfObserver.prototype.completed = function () {
|
7102 | if (this._hv) {
|
7103 | this._o.onNext(this._v);
|
7104 | } else {
|
7105 | this._o.onNext(-1);
|
7106 | }
|
7107 | this._o.onCompleted();
|
7108 | };
|
7109 |
|
7110 | return LastIndexOfObserver;
|
7111 | }(AbstractObserver));
|
7112 |
|
7113 | |
7114 |
|
7115 |
|
7116 |
|
7117 |
|
7118 |
|
7119 | observableProto.lastIndexOf = function(searchElement, fromIndex) {
|
7120 | var n = +fromIndex || 0;
|
7121 | Math.abs(n) === Infinity && (n = 0);
|
7122 | return new LastIndexOfObservable(this, searchElement, n);
|
7123 | };
|
7124 |
|
7125 | Observable.wrap = function (fn) {
|
7126 | function createObservable() {
|
7127 | return Observable.spawn.call(this, fn.apply(this, arguments));
|
7128 | }
|
7129 |
|
7130 | createObservable.__generatorFunction__ = fn;
|
7131 | return createObservable;
|
7132 | };
|
7133 |
|
7134 | var spawn = Observable.spawn = function () {
|
7135 | var gen = arguments[0], self = this, args = [];
|
7136 | for (var i = 1, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
|
7137 |
|
7138 | return new AnonymousObservable(function (o) {
|
7139 | var g = new CompositeDisposable();
|
7140 |
|
7141 | if (isFunction(gen)) { gen = gen.apply(self, args); }
|
7142 | if (!gen || !isFunction(gen.next)) {
|
7143 | o.onNext(gen);
|
7144 | return o.onCompleted();
|
7145 | }
|
7146 |
|
7147 | function processGenerator(res) {
|
7148 | var ret = tryCatch(gen.next).call(gen, res);
|
7149 | if (ret === errorObj) { return o.onError(ret.e); }
|
7150 | next(ret);
|
7151 | }
|
7152 |
|
7153 | processGenerator();
|
7154 |
|
7155 | function onError(err) {
|
7156 | var ret = tryCatch(gen.next).call(gen, err);
|
7157 | if (ret === errorObj) { return o.onError(ret.e); }
|
7158 | next(ret);
|
7159 | }
|
7160 |
|
7161 | function next(ret) {
|
7162 | if (ret.done) {
|
7163 | o.onNext(ret.value);
|
7164 | o.onCompleted();
|
7165 | return;
|
7166 | }
|
7167 | var obs = toObservable.call(self, ret.value);
|
7168 | var value = null;
|
7169 | var hasValue = false;
|
7170 | if (Observable.isObservable(obs)) {
|
7171 | g.add(obs.subscribe(function(val) {
|
7172 | hasValue = true;
|
7173 | value = val;
|
7174 | }, onError, function() {
|
7175 | hasValue && processGenerator(value);
|
7176 | }));
|
7177 | } else {
|
7178 | onError(new TypeError('type not supported'));
|
7179 | }
|
7180 | }
|
7181 |
|
7182 | return g;
|
7183 | });
|
7184 | };
|
7185 |
|
7186 | function toObservable(obj) {
|
7187 | if (!obj) { return obj; }
|
7188 | if (Observable.isObservable(obj)) { return obj; }
|
7189 | if (isPromise(obj)) { return Observable.fromPromise(obj); }
|
7190 | if (isGeneratorFunction(obj) || isGenerator(obj)) { return spawn.call(this, obj); }
|
7191 | if (isFunction(obj)) { return thunkToObservable.call(this, obj); }
|
7192 | if (isArrayLike(obj) || isIterable(obj)) { return arrayToObservable.call(this, obj); }
|
7193 | if (isObject(obj)) {return objectToObservable.call(this, obj);}
|
7194 | return obj;
|
7195 | }
|
7196 |
|
7197 | function arrayToObservable (obj) {
|
7198 | return Observable.from(obj).concatMap(function(o) {
|
7199 | if(Observable.isObservable(o) || isObject(o)) {
|
7200 | return toObservable.call(null, o);
|
7201 | } else {
|
7202 | return Rx.Observable.just(o);
|
7203 | }
|
7204 | }).toArray();
|
7205 | }
|
7206 |
|
7207 | function objectToObservable (obj) {
|
7208 | var results = new obj.constructor(), keys = Object.keys(obj), observables = [];
|
7209 | for (var i = 0, len = keys.length; i < len; i++) {
|
7210 | var key = keys[i];
|
7211 | var observable = toObservable.call(this, obj[key]);
|
7212 |
|
7213 | if(observable && Observable.isObservable(observable)) {
|
7214 | defer(observable, key);
|
7215 | } else {
|
7216 | results[key] = obj[key];
|
7217 | }
|
7218 | }
|
7219 |
|
7220 | return Observable.forkJoin.apply(Observable, observables).map(function() {
|
7221 | return results;
|
7222 | });
|
7223 |
|
7224 |
|
7225 | function defer (observable, key) {
|
7226 | results[key] = undefined;
|
7227 | observables.push(observable.map(function (next) {
|
7228 | results[key] = next;
|
7229 | }));
|
7230 | }
|
7231 | }
|
7232 |
|
7233 | function thunkToObservable(fn) {
|
7234 | var self = this;
|
7235 | return new AnonymousObservable(function (o) {
|
7236 | fn.call(self, function () {
|
7237 | var err = arguments[0], res = arguments[1];
|
7238 | if (err) { return o.onError(err); }
|
7239 | if (arguments.length > 2) {
|
7240 | var args = [];
|
7241 | for (var i = 1, len = arguments.length; i < len; i++) { args.push(arguments[i]); }
|
7242 | res = args;
|
7243 | }
|
7244 | o.onNext(res);
|
7245 | o.onCompleted();
|
7246 | });
|
7247 | });
|
7248 | }
|
7249 |
|
7250 | function isGenerator(obj) {
|
7251 | return isFunction (obj.next) && isFunction (obj['throw']);
|
7252 | }
|
7253 |
|
7254 | function isGeneratorFunction(obj) {
|
7255 | var ctor = obj.constructor;
|
7256 | if (!ctor) { return false; }
|
7257 | if (ctor.name === 'GeneratorFunction' || ctor.displayName === 'GeneratorFunction') { return true; }
|
7258 | return isGenerator(ctor.prototype);
|
7259 | }
|
7260 |
|
7261 | function isObject(val) {
|
7262 | return Object == val.constructor;
|
7263 | }
|
7264 |
|
7265 | |
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 |
|
7275 |
|
7276 |
|
7277 |
|
7278 |
|
7279 |
|
7280 |
|
7281 |
|
7282 | Observable.start = function (func, context, scheduler) {
|
7283 | return observableToAsync(func, context, scheduler)();
|
7284 | };
|
7285 |
|
7286 | |
7287 |
|
7288 |
|
7289 |
|
7290 |
|
7291 |
|
7292 |
|
7293 | var observableToAsync = Observable.toAsync = function (func, context, scheduler) {
|
7294 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
7295 | return function () {
|
7296 | var args = arguments,
|
7297 | subject = new AsyncSubject();
|
7298 |
|
7299 | scheduler.schedule(null, function () {
|
7300 | var result;
|
7301 | try {
|
7302 | result = func.apply(context, args);
|
7303 | } catch (e) {
|
7304 | subject.onError(e);
|
7305 | return;
|
7306 | }
|
7307 | subject.onNext(result);
|
7308 | subject.onCompleted();
|
7309 | });
|
7310 | return subject.asObservable();
|
7311 | };
|
7312 | };
|
7313 |
|
7314 | function createCbObservable(fn, ctx, selector, args) {
|
7315 | var o = new AsyncSubject();
|
7316 |
|
7317 | args.push(createCbHandler(o, ctx, selector));
|
7318 | fn.apply(ctx, args);
|
7319 |
|
7320 | return o.asObservable();
|
7321 | }
|
7322 |
|
7323 | function createCbHandler(o, ctx, selector) {
|
7324 | return function handler () {
|
7325 | var len = arguments.length, results = new Array(len);
|
7326 | for(var i = 0; i < len; i++) { results[i] = arguments[i]; }
|
7327 |
|
7328 | if (isFunction(selector)) {
|
7329 | results = tryCatch(selector).apply(ctx, results);
|
7330 | if (results === errorObj) { return o.onError(results.e); }
|
7331 | o.onNext(results);
|
7332 | } else {
|
7333 | if (results.length <= 1) {
|
7334 | o.onNext(results[0]);
|
7335 | } else {
|
7336 | o.onNext(results);
|
7337 | }
|
7338 | }
|
7339 |
|
7340 | o.onCompleted();
|
7341 | };
|
7342 | }
|
7343 |
|
7344 |
|
7345 |
|
7346 |
|
7347 |
|
7348 |
|
7349 |
|
7350 |
|
7351 |
|
7352 | Observable.fromCallback = function (fn, ctx, selector) {
|
7353 | return function () {
|
7354 | typeof ctx === 'undefined' && (ctx = this);
|
7355 |
|
7356 | var len = arguments.length, args = new Array(len)
|
7357 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
7358 | return createCbObservable(fn, ctx, selector, args);
|
7359 | };
|
7360 | };
|
7361 |
|
7362 | function createNodeObservable(fn, ctx, selector, args) {
|
7363 | var o = new AsyncSubject();
|
7364 |
|
7365 | args.push(createNodeHandler(o, ctx, selector));
|
7366 | fn.apply(ctx, args);
|
7367 |
|
7368 | return o.asObservable();
|
7369 | }
|
7370 |
|
7371 | function createNodeHandler(o, ctx, selector) {
|
7372 | return function handler () {
|
7373 | var err = arguments[0];
|
7374 | if (err) { return o.onError(err); }
|
7375 |
|
7376 | var len = arguments.length, results = [];
|
7377 | for(var i = 1; i < len; i++) { results[i - 1] = arguments[i]; }
|
7378 |
|
7379 | if (isFunction(selector)) {
|
7380 | var results = tryCatch(selector).apply(ctx, results);
|
7381 | if (results === errorObj) { return o.onError(results.e); }
|
7382 | o.onNext(results);
|
7383 | } else {
|
7384 | if (results.length <= 1) {
|
7385 | o.onNext(results[0]);
|
7386 | } else {
|
7387 | o.onNext(results);
|
7388 | }
|
7389 | }
|
7390 |
|
7391 | o.onCompleted();
|
7392 | };
|
7393 | }
|
7394 |
|
7395 |
|
7396 |
|
7397 |
|
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 | Observable.fromNodeCallback = function (fn, ctx, selector) {
|
7403 | return function () {
|
7404 | typeof ctx === 'undefined' && (ctx = this);
|
7405 | var len = arguments.length, args = new Array(len);
|
7406 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
7407 | return createNodeObservable(fn, ctx, selector, args);
|
7408 | };
|
7409 | };
|
7410 |
|
7411 | function isNodeList(el) {
|
7412 | if (root.StaticNodeList) {
|
7413 |
|
7414 |
|
7415 | return el instanceof root.StaticNodeList || el instanceof root.NodeList;
|
7416 | } else {
|
7417 | return Object.prototype.toString.call(el) === '[object NodeList]';
|
7418 | }
|
7419 | }
|
7420 |
|
7421 | function ListenDisposable(e, n, fn) {
|
7422 | this._e = e;
|
7423 | this._n = n;
|
7424 | this._fn = fn;
|
7425 | this._e.addEventListener(this._n, this._fn, false);
|
7426 | this.isDisposed = false;
|
7427 | }
|
7428 | ListenDisposable.prototype.dispose = function () {
|
7429 | if (!this.isDisposed) {
|
7430 | this._e.removeEventListener(this._n, this._fn, false);
|
7431 | this.isDisposed = true;
|
7432 | }
|
7433 | };
|
7434 |
|
7435 | function createEventListener (el, eventName, handler) {
|
7436 | var disposables = new CompositeDisposable();
|
7437 |
|
7438 |
|
7439 | var elemToString = Object.prototype.toString.call(el);
|
7440 | if (isNodeList(el) || elemToString === '[object HTMLCollection]') {
|
7441 | for (var i = 0, len = el.length; i < len; i++) {
|
7442 | disposables.add(createEventListener(el.item(i), eventName, handler));
|
7443 | }
|
7444 | } else if (el) {
|
7445 | disposables.add(new ListenDisposable(el, eventName, handler));
|
7446 | }
|
7447 |
|
7448 | return disposables;
|
7449 | }
|
7450 |
|
7451 | |
7452 |
|
7453 |
|
7454 | Rx.config.useNativeEvents = false;
|
7455 |
|
7456 | var EventObservable = (function(__super__) {
|
7457 | inherits(EventObservable, __super__);
|
7458 | function EventObservable(el, name, fn) {
|
7459 | this._el = el;
|
7460 | this._n = name;
|
7461 | this._fn = fn;
|
7462 | __super__.call(this);
|
7463 | }
|
7464 |
|
7465 | function createHandler(o, fn) {
|
7466 | return function handler () {
|
7467 | var results = arguments[0];
|
7468 | if (isFunction(fn)) {
|
7469 | results = tryCatch(fn).apply(null, arguments);
|
7470 | if (results === errorObj) { return o.onError(results.e); }
|
7471 | }
|
7472 | o.onNext(results);
|
7473 | };
|
7474 | }
|
7475 |
|
7476 | EventObservable.prototype.subscribeCore = function (o) {
|
7477 | return createEventListener(
|
7478 | this._el,
|
7479 | this._n,
|
7480 | createHandler(o, this._fn));
|
7481 | };
|
7482 |
|
7483 | return EventObservable;
|
7484 | }(ObservableBase));
|
7485 |
|
7486 | |
7487 |
|
7488 |
|
7489 |
|
7490 |
|
7491 |
|
7492 |
|
7493 | Observable.fromEvent = function (element, eventName, selector) {
|
7494 |
|
7495 | if (element.addListener) {
|
7496 | return fromEventPattern(
|
7497 | function (h) { element.addListener(eventName, h); },
|
7498 | function (h) { element.removeListener(eventName, h); },
|
7499 | selector);
|
7500 | }
|
7501 |
|
7502 |
|
7503 | if (!Rx.config.useNativeEvents) {
|
7504 |
|
7505 | if (typeof element.on === 'function' && typeof element.off === 'function') {
|
7506 | return fromEventPattern(
|
7507 | function (h) { element.on(eventName, h); },
|
7508 | function (h) { element.off(eventName, h); },
|
7509 | selector);
|
7510 | }
|
7511 | }
|
7512 |
|
7513 | return new EventObservable(element, eventName, selector).publish().refCount();
|
7514 | };
|
7515 |
|
7516 | var EventPatternObservable = (function(__super__) {
|
7517 | inherits(EventPatternObservable, __super__);
|
7518 | function EventPatternObservable(add, del, fn) {
|
7519 | this._add = add;
|
7520 | this._del = del;
|
7521 | this._fn = fn;
|
7522 | __super__.call(this);
|
7523 | }
|
7524 |
|
7525 | function createHandler(o, fn) {
|
7526 | return function handler () {
|
7527 | var results = arguments[0];
|
7528 | if (isFunction(fn)) {
|
7529 | results = tryCatch(fn).apply(null, arguments);
|
7530 | if (results === errorObj) { return o.onError(results.e); }
|
7531 | }
|
7532 | o.onNext(results);
|
7533 | };
|
7534 | }
|
7535 |
|
7536 | EventPatternObservable.prototype.subscribeCore = function (o) {
|
7537 | var fn = createHandler(o, this._fn);
|
7538 | var returnValue = this._add(fn);
|
7539 | return new EventPatternDisposable(this._del, fn, returnValue);
|
7540 | };
|
7541 |
|
7542 | function EventPatternDisposable(del, fn, ret) {
|
7543 | this._del = del;
|
7544 | this._fn = fn;
|
7545 | this._ret = ret;
|
7546 | this.isDisposed = false;
|
7547 | }
|
7548 |
|
7549 | EventPatternDisposable.prototype.dispose = function () {
|
7550 | if(!this.isDisposed) {
|
7551 | isFunction(this._del) && this._del(this._fn, this._ret);
|
7552 | }
|
7553 | };
|
7554 |
|
7555 | return EventPatternObservable;
|
7556 | }(ObservableBase));
|
7557 |
|
7558 | |
7559 |
|
7560 |
|
7561 |
|
7562 |
|
7563 |
|
7564 |
|
7565 | var fromEventPattern = Observable.fromEventPattern = function (addHandler, removeHandler, selector) {
|
7566 | return new EventPatternObservable(addHandler, removeHandler, selector).publish().refCount();
|
7567 | };
|
7568 |
|
7569 | |
7570 |
|
7571 |
|
7572 |
|
7573 |
|
7574 | Observable.startAsync = function (functionAsync) {
|
7575 | var promise = tryCatch(functionAsync)();
|
7576 | if (promise === errorObj) { return observableThrow(promise.e); }
|
7577 | return observableFromPromise(promise);
|
7578 | };
|
7579 |
|
7580 | var PausableObservable = (function (__super__) {
|
7581 | inherits(PausableObservable, __super__);
|
7582 | function PausableObservable(source, pauser) {
|
7583 | this.source = source;
|
7584 | this.controller = new Subject();
|
7585 |
|
7586 | if (pauser && pauser.subscribe) {
|
7587 | this.pauser = this.controller.merge(pauser);
|
7588 | } else {
|
7589 | this.pauser = this.controller;
|
7590 | }
|
7591 |
|
7592 | __super__.call(this);
|
7593 | }
|
7594 |
|
7595 | PausableObservable.prototype._subscribe = function (o) {
|
7596 | var conn = this.source.publish(),
|
7597 | subscription = conn.subscribe(o),
|
7598 | connection = disposableEmpty;
|
7599 |
|
7600 | var pausable = this.pauser.distinctUntilChanged().subscribe(function (b) {
|
7601 | if (b) {
|
7602 | connection = conn.connect();
|
7603 | } else {
|
7604 | connection.dispose();
|
7605 | connection = disposableEmpty;
|
7606 | }
|
7607 | });
|
7608 |
|
7609 | return new NAryDisposable([subscription, connection, pausable]);
|
7610 | };
|
7611 |
|
7612 | PausableObservable.prototype.pause = function () {
|
7613 | this.controller.onNext(false);
|
7614 | };
|
7615 |
|
7616 | PausableObservable.prototype.resume = function () {
|
7617 | this.controller.onNext(true);
|
7618 | };
|
7619 |
|
7620 | return PausableObservable;
|
7621 |
|
7622 | }(Observable));
|
7623 |
|
7624 | |
7625 |
|
7626 |
|
7627 |
|
7628 |
|
7629 |
|
7630 |
|
7631 |
|
7632 | observableProto.pausable = function (pauser) {
|
7633 | return new PausableObservable(this, pauser);
|
7634 | };
|
7635 |
|
7636 | function combineLatestSource(source, subject, resultSelector) {
|
7637 | return new AnonymousObservable(function (o) {
|
7638 | var hasValue = [false, false],
|
7639 | hasValueAll = false,
|
7640 | isDone = false,
|
7641 | values = new Array(2),
|
7642 | err;
|
7643 |
|
7644 | function next(x, i) {
|
7645 | values[i] = x;
|
7646 | hasValue[i] = true;
|
7647 | if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
|
7648 | if (err) { return o.onError(err); }
|
7649 | var res = tryCatch(resultSelector).apply(null, values);
|
7650 | if (res === errorObj) { return o.onError(res.e); }
|
7651 | o.onNext(res);
|
7652 | }
|
7653 | isDone && values[1] && o.onCompleted();
|
7654 | }
|
7655 |
|
7656 | return new BinaryDisposable(
|
7657 | source.subscribe(
|
7658 | function (x) {
|
7659 | next(x, 0);
|
7660 | },
|
7661 | function (e) {
|
7662 | if (values[1]) {
|
7663 | o.onError(e);
|
7664 | } else {
|
7665 | err = e;
|
7666 | }
|
7667 | },
|
7668 | function () {
|
7669 | isDone = true;
|
7670 | values[1] && o.onCompleted();
|
7671 | }),
|
7672 | subject.subscribe(
|
7673 | function (x) {
|
7674 | next(x, 1);
|
7675 | },
|
7676 | function (e) { o.onError(e); },
|
7677 | function () {
|
7678 | isDone = true;
|
7679 | next(true, 1);
|
7680 | })
|
7681 | );
|
7682 | }, source);
|
7683 | }
|
7684 |
|
7685 | var PausableBufferedObservable = (function (__super__) {
|
7686 | inherits(PausableBufferedObservable, __super__);
|
7687 | function PausableBufferedObservable(source, pauser) {
|
7688 | this.source = source;
|
7689 | this.controller = new Subject();
|
7690 |
|
7691 | if (pauser && pauser.subscribe) {
|
7692 | this.pauser = this.controller.merge(pauser);
|
7693 | } else {
|
7694 | this.pauser = this.controller;
|
7695 | }
|
7696 |
|
7697 | __super__.call(this);
|
7698 | }
|
7699 |
|
7700 | PausableBufferedObservable.prototype._subscribe = function (o) {
|
7701 | var q = [], previousShouldFire;
|
7702 |
|
7703 | function drainQueue() { while (q.length > 0) { o.onNext(q.shift()); } }
|
7704 |
|
7705 | var subscription =
|
7706 | combineLatestSource(
|
7707 | this.source,
|
7708 | this.pauser.startWith(false).distinctUntilChanged(),
|
7709 | function (data, shouldFire) {
|
7710 | return { data: data, shouldFire: shouldFire };
|
7711 | })
|
7712 | .subscribe(
|
7713 | function (results) {
|
7714 | if (previousShouldFire !== undefined && results.shouldFire !== previousShouldFire) {
|
7715 | previousShouldFire = results.shouldFire;
|
7716 |
|
7717 | if (results.shouldFire) { drainQueue(); }
|
7718 | } else {
|
7719 | previousShouldFire = results.shouldFire;
|
7720 |
|
7721 | if (results.shouldFire) {
|
7722 | o.onNext(results.data);
|
7723 | } else {
|
7724 | q.push(results.data);
|
7725 | }
|
7726 | }
|
7727 | },
|
7728 | function (err) {
|
7729 | drainQueue();
|
7730 | o.onError(err);
|
7731 | },
|
7732 | function () {
|
7733 | drainQueue();
|
7734 | o.onCompleted();
|
7735 | }
|
7736 | );
|
7737 | return subscription;
|
7738 | };
|
7739 |
|
7740 | PausableBufferedObservable.prototype.pause = function () {
|
7741 | this.controller.onNext(false);
|
7742 | };
|
7743 |
|
7744 | PausableBufferedObservable.prototype.resume = function () {
|
7745 | this.controller.onNext(true);
|
7746 | };
|
7747 |
|
7748 | return PausableBufferedObservable;
|
7749 |
|
7750 | }(Observable));
|
7751 |
|
7752 | |
7753 |
|
7754 |
|
7755 |
|
7756 |
|
7757 |
|
7758 |
|
7759 |
|
7760 |
|
7761 | observableProto.pausableBuffered = function (pauser) {
|
7762 | return new PausableBufferedObservable(this, pauser);
|
7763 | };
|
7764 |
|
7765 | var ControlledObservable = (function (__super__) {
|
7766 | inherits(ControlledObservable, __super__);
|
7767 | function ControlledObservable (source, enableQueue, scheduler) {
|
7768 | __super__.call(this);
|
7769 | this.subject = new ControlledSubject(enableQueue, scheduler);
|
7770 | this.source = source.multicast(this.subject).refCount();
|
7771 | }
|
7772 |
|
7773 | ControlledObservable.prototype._subscribe = function (o) {
|
7774 | return this.source.subscribe(o);
|
7775 | };
|
7776 |
|
7777 | ControlledObservable.prototype.request = function (numberOfItems) {
|
7778 | return this.subject.request(numberOfItems == null ? -1 : numberOfItems);
|
7779 | };
|
7780 |
|
7781 | return ControlledObservable;
|
7782 |
|
7783 | }(Observable));
|
7784 |
|
7785 | var ControlledSubject = (function (__super__) {
|
7786 | inherits(ControlledSubject, __super__);
|
7787 | function ControlledSubject(enableQueue, scheduler) {
|
7788 | enableQueue == null && (enableQueue = true);
|
7789 |
|
7790 | __super__.call(this);
|
7791 | this.subject = new Subject();
|
7792 | this.enableQueue = enableQueue;
|
7793 | this.queue = enableQueue ? [] : null;
|
7794 | this.requestedCount = 0;
|
7795 | this.requestedDisposable = null;
|
7796 | this.error = null;
|
7797 | this.hasFailed = false;
|
7798 | this.hasCompleted = false;
|
7799 | this.scheduler = scheduler || currentThreadScheduler;
|
7800 | }
|
7801 |
|
7802 | addProperties(ControlledSubject.prototype, Observer, {
|
7803 | _subscribe: function (o) {
|
7804 | return this.subject.subscribe(o);
|
7805 | },
|
7806 | onCompleted: function () {
|
7807 | this.hasCompleted = true;
|
7808 | if (!this.enableQueue || this.queue.length === 0) {
|
7809 | this.subject.onCompleted();
|
7810 | this.disposeCurrentRequest();
|
7811 | } else {
|
7812 | this.queue.push(Notification.createOnCompleted());
|
7813 | }
|
7814 | },
|
7815 | onError: function (error) {
|
7816 | this.hasFailed = true;
|
7817 | this.error = error;
|
7818 | if (!this.enableQueue || this.queue.length === 0) {
|
7819 | this.subject.onError(error);
|
7820 | this.disposeCurrentRequest();
|
7821 | } else {
|
7822 | this.queue.push(Notification.createOnError(error));
|
7823 | }
|
7824 | },
|
7825 | onNext: function (value) {
|
7826 | if (this.requestedCount <= 0) {
|
7827 | this.enableQueue && this.queue.push(Notification.createOnNext(value));
|
7828 | } else {
|
7829 | (this.requestedCount-- === 0) && this.disposeCurrentRequest();
|
7830 | this.subject.onNext(value);
|
7831 | }
|
7832 | },
|
7833 | _processRequest: function (numberOfItems) {
|
7834 | if (this.enableQueue) {
|
7835 | while (this.queue.length > 0 && (numberOfItems > 0 || this.queue[0].kind !== 'N')) {
|
7836 | var first = this.queue.shift();
|
7837 | first.accept(this.subject);
|
7838 | if (first.kind === 'N') {
|
7839 | numberOfItems--;
|
7840 | } else {
|
7841 | this.disposeCurrentRequest();
|
7842 | this.queue = [];
|
7843 | }
|
7844 | }
|
7845 | }
|
7846 |
|
7847 | return numberOfItems;
|
7848 | },
|
7849 | request: function (number) {
|
7850 | this.disposeCurrentRequest();
|
7851 | var self = this;
|
7852 |
|
7853 | this.requestedDisposable = this.scheduler.schedule(number,
|
7854 | function(s, i) {
|
7855 | var remaining = self._processRequest(i);
|
7856 | var stopped = self.hasCompleted || self.hasFailed;
|
7857 | if (!stopped && remaining > 0) {
|
7858 | self.requestedCount = remaining;
|
7859 |
|
7860 | return disposableCreate(function () {
|
7861 | self.requestedCount = 0;
|
7862 | });
|
7863 |
|
7864 |
|
7865 |
|
7866 | }
|
7867 | });
|
7868 |
|
7869 | return this.requestedDisposable;
|
7870 | },
|
7871 | disposeCurrentRequest: function () {
|
7872 | if (this.requestedDisposable) {
|
7873 | this.requestedDisposable.dispose();
|
7874 | this.requestedDisposable = null;
|
7875 | }
|
7876 | }
|
7877 | });
|
7878 |
|
7879 | return ControlledSubject;
|
7880 | }(Observable));
|
7881 |
|
7882 | |
7883 |
|
7884 |
|
7885 |
|
7886 |
|
7887 |
|
7888 |
|
7889 |
|
7890 |
|
7891 | observableProto.controlled = function (enableQueue, scheduler) {
|
7892 |
|
7893 | if (enableQueue && isScheduler(enableQueue)) {
|
7894 | scheduler = enableQueue;
|
7895 | enableQueue = true;
|
7896 | }
|
7897 |
|
7898 | if (enableQueue == null) { enableQueue = true; }
|
7899 | return new ControlledObservable(this, enableQueue, scheduler);
|
7900 | };
|
7901 |
|
7902 | var StopAndWaitObservable = (function (__super__) {
|
7903 | inherits(StopAndWaitObservable, __super__);
|
7904 | function StopAndWaitObservable (source) {
|
7905 | __super__.call(this);
|
7906 | this.source = source;
|
7907 | }
|
7908 |
|
7909 | function scheduleMethod(s, self) {
|
7910 | self.source.request(1);
|
7911 | }
|
7912 |
|
7913 | StopAndWaitObservable.prototype._subscribe = function (o) {
|
7914 | this.subscription = this.source.subscribe(new StopAndWaitObserver(o, this, this.subscription));
|
7915 | return new BinaryDisposable(
|
7916 | this.subscription,
|
7917 | defaultScheduler.schedule(this, scheduleMethod)
|
7918 | );
|
7919 | };
|
7920 |
|
7921 | var StopAndWaitObserver = (function (__sub__) {
|
7922 | inherits(StopAndWaitObserver, __sub__);
|
7923 | function StopAndWaitObserver (observer, observable, cancel) {
|
7924 | __sub__.call(this);
|
7925 | this.observer = observer;
|
7926 | this.observable = observable;
|
7927 | this.cancel = cancel;
|
7928 | this.scheduleDisposable = null;
|
7929 | }
|
7930 |
|
7931 | StopAndWaitObserver.prototype.completed = function () {
|
7932 | this.observer.onCompleted();
|
7933 | this.dispose();
|
7934 | };
|
7935 |
|
7936 | StopAndWaitObserver.prototype.error = function (error) {
|
7937 | this.observer.onError(error);
|
7938 | this.dispose();
|
7939 | };
|
7940 |
|
7941 | function innerScheduleMethod(s, self) {
|
7942 | self.observable.source.request(1);
|
7943 | }
|
7944 |
|
7945 | StopAndWaitObserver.prototype.next = function (value) {
|
7946 | this.observer.onNext(value);
|
7947 | this.scheduleDisposable = defaultScheduler.schedule(this, innerScheduleMethod);
|
7948 | };
|
7949 |
|
7950 | StopAndWaitObservable.dispose = function () {
|
7951 | this.observer = null;
|
7952 | if (this.cancel) {
|
7953 | this.cancel.dispose();
|
7954 | this.cancel = null;
|
7955 | }
|
7956 | if (this.scheduleDisposable) {
|
7957 | this.scheduleDisposable.dispose();
|
7958 | this.scheduleDisposable = null;
|
7959 | }
|
7960 | __sub__.prototype.dispose.call(this);
|
7961 | };
|
7962 |
|
7963 | return StopAndWaitObserver;
|
7964 | }(AbstractObserver));
|
7965 |
|
7966 | return StopAndWaitObservable;
|
7967 | }(Observable));
|
7968 |
|
7969 |
|
7970 | |
7971 |
|
7972 |
|
7973 |
|
7974 | ControlledObservable.prototype.stopAndWait = function () {
|
7975 | return new StopAndWaitObservable(this);
|
7976 | };
|
7977 |
|
7978 | var WindowedObservable = (function (__super__) {
|
7979 | inherits(WindowedObservable, __super__);
|
7980 | function WindowedObservable(source, windowSize) {
|
7981 | __super__.call(this);
|
7982 | this.source = source;
|
7983 | this.windowSize = windowSize;
|
7984 | }
|
7985 |
|
7986 | function scheduleMethod(s, self) {
|
7987 | self.source.request(self.windowSize);
|
7988 | }
|
7989 |
|
7990 | WindowedObservable.prototype._subscribe = function (o) {
|
7991 | this.subscription = this.source.subscribe(new WindowedObserver(o, this, this.subscription));
|
7992 | return new BinaryDisposable(
|
7993 | this.subscription,
|
7994 | defaultScheduler.schedule(this, scheduleMethod)
|
7995 | );
|
7996 | };
|
7997 |
|
7998 | var WindowedObserver = (function (__sub__) {
|
7999 | inherits(WindowedObserver, __sub__);
|
8000 | function WindowedObserver(observer, observable, cancel) {
|
8001 | this.observer = observer;
|
8002 | this.observable = observable;
|
8003 | this.cancel = cancel;
|
8004 | this.received = 0;
|
8005 | this.scheduleDisposable = null;
|
8006 | __sub__.call(this);
|
8007 | }
|
8008 |
|
8009 | WindowedObserver.prototype.completed = function () {
|
8010 | this.observer.onCompleted();
|
8011 | this.dispose();
|
8012 | };
|
8013 |
|
8014 | WindowedObserver.prototype.error = function (error) {
|
8015 | this.observer.onError(error);
|
8016 | this.dispose();
|
8017 | };
|
8018 |
|
8019 | function innerScheduleMethod(s, self) {
|
8020 | self.observable.source.request(self.observable.windowSize);
|
8021 | }
|
8022 |
|
8023 | WindowedObserver.prototype.next = function (value) {
|
8024 | this.observer.onNext(value);
|
8025 | this.received = ++this.received % this.observable.windowSize;
|
8026 | this.received === 0 && (this.scheduleDisposable = defaultScheduler.schedule(this, innerScheduleMethod));
|
8027 | };
|
8028 |
|
8029 | WindowedObserver.prototype.dispose = function () {
|
8030 | this.observer = null;
|
8031 | if (this.cancel) {
|
8032 | this.cancel.dispose();
|
8033 | this.cancel = null;
|
8034 | }
|
8035 | if (this.scheduleDisposable) {
|
8036 | this.scheduleDisposable.dispose();
|
8037 | this.scheduleDisposable = null;
|
8038 | }
|
8039 | __sub__.prototype.dispose.call(this);
|
8040 | };
|
8041 |
|
8042 | return WindowedObserver;
|
8043 | }(AbstractObserver));
|
8044 |
|
8045 | return WindowedObservable;
|
8046 | }(Observable));
|
8047 |
|
8048 | |
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 | ControlledObservable.prototype.windowed = function (windowSize) {
|
8054 | return new WindowedObservable(this, windowSize);
|
8055 | };
|
8056 |
|
8057 | |
8058 |
|
8059 |
|
8060 |
|
8061 |
|
8062 | observableProto.pipe = function (dest) {
|
8063 | var source = this.pausableBuffered();
|
8064 |
|
8065 | function onDrain() {
|
8066 | source.resume();
|
8067 | }
|
8068 |
|
8069 | dest.addListener('drain', onDrain);
|
8070 |
|
8071 | source.subscribe(
|
8072 | function (x) {
|
8073 | !dest.write(String(x)) && source.pause();
|
8074 | },
|
8075 | function (err) {
|
8076 | dest.emit('error', err);
|
8077 | },
|
8078 | function () {
|
8079 |
|
8080 | !dest._isStdio && dest.end();
|
8081 | dest.removeListener('drain', onDrain);
|
8082 | });
|
8083 |
|
8084 | source.resume();
|
8085 |
|
8086 | return dest;
|
8087 | };
|
8088 |
|
8089 | var MulticastObservable = (function (__super__) {
|
8090 | inherits(MulticastObservable, __super__);
|
8091 | function MulticastObservable(source, fn1, fn2) {
|
8092 | this.source = source;
|
8093 | this._fn1 = fn1;
|
8094 | this._fn2 = fn2;
|
8095 | __super__.call(this);
|
8096 | }
|
8097 |
|
8098 | MulticastObservable.prototype.subscribeCore = function (o) {
|
8099 | var connectable = this.source.multicast(this._fn1());
|
8100 | return new BinaryDisposable(this._fn2(connectable).subscribe(o), connectable.connect());
|
8101 | };
|
8102 |
|
8103 | return MulticastObservable;
|
8104 | }(ObservableBase));
|
8105 |
|
8106 | |
8107 |
|
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 |
|
8113 |
|
8114 |
|
8115 |
|
8116 |
|
8117 |
|
8118 |
|
8119 |
|
8120 |
|
8121 |
|
8122 |
|
8123 | observableProto.multicast = function (subjectOrSubjectSelector, selector) {
|
8124 | return isFunction(subjectOrSubjectSelector) ?
|
8125 | new MulticastObservable(this, subjectOrSubjectSelector, selector) :
|
8126 | new ConnectableObservable(this, subjectOrSubjectSelector);
|
8127 | };
|
8128 |
|
8129 | |
8130 |
|
8131 |
|
8132 |
|
8133 |
|
8134 |
|
8135 |
|
8136 |
|
8137 |
|
8138 |
|
8139 |
|
8140 | observableProto.publish = function (selector) {
|
8141 | return selector && isFunction(selector) ?
|
8142 | this.multicast(function () { return new Subject(); }, selector) :
|
8143 | this.multicast(new Subject());
|
8144 | };
|
8145 |
|
8146 | |
8147 |
|
8148 |
|
8149 |
|
8150 |
|
8151 | observableProto.share = function () {
|
8152 | return this.publish().refCount();
|
8153 | };
|
8154 |
|
8155 | |
8156 |
|
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 |
|
8164 |
|
8165 |
|
8166 | observableProto.publishLast = function (selector) {
|
8167 | return selector && isFunction(selector) ?
|
8168 | this.multicast(function () { return new AsyncSubject(); }, selector) :
|
8169 | this.multicast(new AsyncSubject());
|
8170 | };
|
8171 |
|
8172 | |
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 |
|
8180 |
|
8181 |
|
8182 |
|
8183 |
|
8184 | observableProto.publishValue = function (initialValueOrSelector, initialValue) {
|
8185 | return arguments.length === 2 ?
|
8186 | this.multicast(function () {
|
8187 | return new BehaviorSubject(initialValue);
|
8188 | }, initialValueOrSelector) :
|
8189 | this.multicast(new BehaviorSubject(initialValueOrSelector));
|
8190 | };
|
8191 |
|
8192 | |
8193 |
|
8194 |
|
8195 |
|
8196 |
|
8197 |
|
8198 | observableProto.shareValue = function (initialValue) {
|
8199 | return this.publishValue(initialValue).refCount();
|
8200 | };
|
8201 |
|
8202 | |
8203 |
|
8204 |
|
8205 |
|
8206 |
|
8207 |
|
8208 |
|
8209 |
|
8210 |
|
8211 |
|
8212 |
|
8213 |
|
8214 |
|
8215 |
|
8216 |
|
8217 |
|
8218 | observableProto.replay = function (selector, bufferSize, windowSize, scheduler) {
|
8219 | return selector && isFunction(selector) ?
|
8220 | this.multicast(function () { return new ReplaySubject(bufferSize, windowSize, scheduler); }, selector) :
|
8221 | this.multicast(new ReplaySubject(bufferSize, windowSize, scheduler));
|
8222 | };
|
8223 |
|
8224 | |
8225 |
|
8226 |
|
8227 |
|
8228 |
|
8229 |
|
8230 |
|
8231 |
|
8232 |
|
8233 |
|
8234 |
|
8235 |
|
8236 |
|
8237 |
|
8238 |
|
8239 | observableProto.shareReplay = function (bufferSize, windowSize, scheduler) {
|
8240 | return this.replay(null, bufferSize, windowSize, scheduler).refCount();
|
8241 | };
|
8242 |
|
8243 | var InnerSubscription = function (s, o) {
|
8244 | this._s = s;
|
8245 | this._o = o;
|
8246 | };
|
8247 |
|
8248 | InnerSubscription.prototype.dispose = function () {
|
8249 | if (!this._s.isDisposed && this._o !== null) {
|
8250 | var idx = this._s.observers.indexOf(this._o);
|
8251 | this._s.observers.splice(idx, 1);
|
8252 | this._o = null;
|
8253 | }
|
8254 | };
|
8255 |
|
8256 | var RefCountObservable = (function (__super__) {
|
8257 | inherits(RefCountObservable, __super__);
|
8258 | function RefCountObservable(source) {
|
8259 | this.source = source;
|
8260 | this._count = 0;
|
8261 | this._connectableSubscription = null;
|
8262 | __super__.call(this);
|
8263 | }
|
8264 |
|
8265 | RefCountObservable.prototype.subscribeCore = function (o) {
|
8266 | var subscription = this.source.subscribe(o);
|
8267 | ++this._count === 1 && (this._connectableSubscription = this.source.connect());
|
8268 | return new RefCountDisposable(this, subscription);
|
8269 | };
|
8270 |
|
8271 | function RefCountDisposable(p, s) {
|
8272 | this._p = p;
|
8273 | this._s = s;
|
8274 | this.isDisposed = false;
|
8275 | }
|
8276 |
|
8277 | RefCountDisposable.prototype.dispose = function () {
|
8278 | if (!this.isDisposed) {
|
8279 | this.isDisposed = true;
|
8280 | this._s.dispose();
|
8281 | --this._p._count === 0 && this._p._connectableSubscription.dispose();
|
8282 | }
|
8283 | };
|
8284 |
|
8285 | return RefCountObservable;
|
8286 | }(ObservableBase));
|
8287 |
|
8288 | var ConnectableObservable = Rx.ConnectableObservable = (function (__super__) {
|
8289 | inherits(ConnectableObservable, __super__);
|
8290 | function ConnectableObservable(source, subject) {
|
8291 | this.source = source;
|
8292 | this._connection = null;
|
8293 | this._source = source.asObservable();
|
8294 | this._subject = subject;
|
8295 | __super__.call(this);
|
8296 | }
|
8297 |
|
8298 | function ConnectDisposable(parent, subscription) {
|
8299 | this._p = parent;
|
8300 | this._s = subscription;
|
8301 | }
|
8302 |
|
8303 | ConnectDisposable.prototype.dispose = function () {
|
8304 | if (this._s) {
|
8305 | this._s.dispose();
|
8306 | this._s = null;
|
8307 | this._p._connection = null;
|
8308 | }
|
8309 | };
|
8310 |
|
8311 | ConnectableObservable.prototype.connect = function () {
|
8312 | if (!this._connection) {
|
8313 | var subscription = this._source.subscribe(this._subject);
|
8314 | this._connection = new ConnectDisposable(this, subscription);
|
8315 | }
|
8316 | return this._connection;
|
8317 | };
|
8318 |
|
8319 | ConnectableObservable.prototype._subscribe = function (o) {
|
8320 | return this._subject.subscribe(o);
|
8321 | };
|
8322 |
|
8323 | ConnectableObservable.prototype.refCount = function () {
|
8324 | return new RefCountObservable(this);
|
8325 | };
|
8326 |
|
8327 | return ConnectableObservable;
|
8328 | }(Observable));
|
8329 |
|
8330 | |
8331 |
|
8332 |
|
8333 |
|
8334 |
|
8335 | observableProto.singleInstance = function() {
|
8336 | var source = this, hasObservable = false, observable;
|
8337 |
|
8338 | function getObservable() {
|
8339 | if (!hasObservable) {
|
8340 | hasObservable = true;
|
8341 | observable = source['finally'](function() { hasObservable = false; }).publish().refCount();
|
8342 | }
|
8343 | return observable;
|
8344 | }
|
8345 |
|
8346 | return new AnonymousObservable(function(o) {
|
8347 | return getObservable().subscribe(o);
|
8348 | });
|
8349 | };
|
8350 |
|
8351 | |
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 |
|
8357 |
|
8358 |
|
8359 |
|
8360 | observableProto.join = function (right, leftDurationSelector, rightDurationSelector, resultSelector) {
|
8361 | var left = this;
|
8362 | return new AnonymousObservable(function (o) {
|
8363 | var group = new CompositeDisposable();
|
8364 | var leftDone = false, rightDone = false;
|
8365 | var leftId = 0, rightId = 0;
|
8366 | var leftMap = new Map(), rightMap = new Map();
|
8367 | var handleError = function (e) { o.onError(e); };
|
8368 |
|
8369 | group.add(left.subscribe(
|
8370 | function (value) {
|
8371 | var id = leftId++, md = new SingleAssignmentDisposable();
|
8372 |
|
8373 | leftMap.set(id, value);
|
8374 | group.add(md);
|
8375 |
|
8376 | var duration = tryCatch(leftDurationSelector)(value);
|
8377 | if (duration === errorObj) { return o.onError(duration.e); }
|
8378 |
|
8379 | md.setDisposable(duration.take(1).subscribe(
|
8380 | noop,
|
8381 | handleError,
|
8382 | function () {
|
8383 | leftMap['delete'](id) && leftMap.size === 0 && leftDone && o.onCompleted();
|
8384 | group.remove(md);
|
8385 | }));
|
8386 |
|
8387 | rightMap.forEach(function (v) {
|
8388 | var result = tryCatch(resultSelector)(value, v);
|
8389 | if (result === errorObj) { return o.onError(result.e); }
|
8390 | o.onNext(result);
|
8391 | });
|
8392 | },
|
8393 | handleError,
|
8394 | function () {
|
8395 | leftDone = true;
|
8396 | (rightDone || leftMap.size === 0) && o.onCompleted();
|
8397 | })
|
8398 | );
|
8399 |
|
8400 | group.add(right.subscribe(
|
8401 | function (value) {
|
8402 | var id = rightId++, md = new SingleAssignmentDisposable();
|
8403 |
|
8404 | rightMap.set(id, value);
|
8405 | group.add(md);
|
8406 |
|
8407 | var duration = tryCatch(rightDurationSelector)(value);
|
8408 | if (duration === errorObj) { return o.onError(duration.e); }
|
8409 |
|
8410 | md.setDisposable(duration.take(1).subscribe(
|
8411 | noop,
|
8412 | handleError,
|
8413 | function () {
|
8414 | rightMap['delete'](id) && rightMap.size === 0 && rightDone && o.onCompleted();
|
8415 | group.remove(md);
|
8416 | }));
|
8417 |
|
8418 | leftMap.forEach(function (v) {
|
8419 | var result = tryCatch(resultSelector)(v, value);
|
8420 | if (result === errorObj) { return o.onError(result.e); }
|
8421 | o.onNext(result);
|
8422 | });
|
8423 | },
|
8424 | handleError,
|
8425 | function () {
|
8426 | rightDone = true;
|
8427 | (leftDone || rightMap.size === 0) && o.onCompleted();
|
8428 | })
|
8429 | );
|
8430 | return group;
|
8431 | }, left);
|
8432 | };
|
8433 |
|
8434 | |
8435 |
|
8436 |
|
8437 |
|
8438 |
|
8439 |
|
8440 |
|
8441 |
|
8442 |
|
8443 | observableProto.groupJoin = function (right, leftDurationSelector, rightDurationSelector, resultSelector) {
|
8444 | var left = this;
|
8445 | return new AnonymousObservable(function (o) {
|
8446 | var group = new CompositeDisposable();
|
8447 | var r = new RefCountDisposable(group);
|
8448 | var leftMap = new Map(), rightMap = new Map();
|
8449 | var leftId = 0, rightId = 0;
|
8450 | var handleError = function (e) { return function (v) { v.onError(e); }; };
|
8451 |
|
8452 | function handleError(e) { };
|
8453 |
|
8454 | group.add(left.subscribe(
|
8455 | function (value) {
|
8456 | var s = new Subject();
|
8457 | var id = leftId++;
|
8458 | leftMap.set(id, s);
|
8459 |
|
8460 | var result = tryCatch(resultSelector)(value, addRef(s, r));
|
8461 | if (result === errorObj) {
|
8462 | leftMap.forEach(handleError(result.e));
|
8463 | return o.onError(result.e);
|
8464 | }
|
8465 | o.onNext(result);
|
8466 |
|
8467 | rightMap.forEach(function (v) { s.onNext(v); });
|
8468 |
|
8469 | var md = new SingleAssignmentDisposable();
|
8470 | group.add(md);
|
8471 |
|
8472 | var duration = tryCatch(leftDurationSelector)(value);
|
8473 | if (duration === errorObj) {
|
8474 | leftMap.forEach(handleError(duration.e));
|
8475 | return o.onError(duration.e);
|
8476 | }
|
8477 |
|
8478 | md.setDisposable(duration.take(1).subscribe(
|
8479 | noop,
|
8480 | function (e) {
|
8481 | leftMap.forEach(handleError(e));
|
8482 | o.onError(e);
|
8483 | },
|
8484 | function () {
|
8485 | leftMap['delete'](id) && s.onCompleted();
|
8486 | group.remove(md);
|
8487 | }));
|
8488 | },
|
8489 | function (e) {
|
8490 | leftMap.forEach(handleError(e));
|
8491 | o.onError(e);
|
8492 | },
|
8493 | function () { o.onCompleted(); })
|
8494 | );
|
8495 |
|
8496 | group.add(right.subscribe(
|
8497 | function (value) {
|
8498 | var id = rightId++;
|
8499 | rightMap.set(id, value);
|
8500 |
|
8501 | var md = new SingleAssignmentDisposable();
|
8502 | group.add(md);
|
8503 |
|
8504 | var duration = tryCatch(rightDurationSelector)(value);
|
8505 | if (duration === errorObj) {
|
8506 | leftMap.forEach(handleError(duration.e));
|
8507 | return o.onError(duration.e);
|
8508 | }
|
8509 |
|
8510 | md.setDisposable(duration.take(1).subscribe(
|
8511 | noop,
|
8512 | function (e) {
|
8513 | leftMap.forEach(handleError(e));
|
8514 | o.onError(e);
|
8515 | },
|
8516 | function () {
|
8517 | rightMap['delete'](id);
|
8518 | group.remove(md);
|
8519 | }));
|
8520 |
|
8521 | leftMap.forEach(function (v) { v.onNext(value); });
|
8522 | },
|
8523 | function (e) {
|
8524 | leftMap.forEach(handleError(e));
|
8525 | o.onError(e);
|
8526 | })
|
8527 | );
|
8528 |
|
8529 | return r;
|
8530 | }, left);
|
8531 | };
|
8532 |
|
8533 | function toArray(x) { return x.toArray(); }
|
8534 |
|
8535 | |
8536 |
|
8537 |
|
8538 |
|
8539 |
|
8540 |
|
8541 | observableProto.buffer = function () {
|
8542 | return this.window.apply(this, arguments)
|
8543 | .flatMap(toArray);
|
8544 | };
|
8545 |
|
8546 | |
8547 |
|
8548 |
|
8549 |
|
8550 |
|
8551 |
|
8552 |
|
8553 | observableProto.window = function (windowOpeningsOrClosingSelector, windowClosingSelector) {
|
8554 | if (arguments.length === 1 && typeof arguments[0] !== 'function') {
|
8555 | return observableWindowWithBoundaries.call(this, windowOpeningsOrClosingSelector);
|
8556 | }
|
8557 | return typeof windowOpeningsOrClosingSelector === 'function' ?
|
8558 | observableWindowWithClosingSelector.call(this, windowOpeningsOrClosingSelector) :
|
8559 | observableWindowWithOpenings.call(this, windowOpeningsOrClosingSelector, windowClosingSelector);
|
8560 | };
|
8561 |
|
8562 | function observableWindowWithOpenings(windowOpenings, windowClosingSelector) {
|
8563 | return windowOpenings.groupJoin(this, windowClosingSelector, observableEmpty, function (_, win) {
|
8564 | return win;
|
8565 | });
|
8566 | }
|
8567 |
|
8568 | function observableWindowWithBoundaries(windowBoundaries) {
|
8569 | var source = this;
|
8570 | return new AnonymousObservable(function (observer) {
|
8571 | var win = new Subject(),
|
8572 | d = new CompositeDisposable(),
|
8573 | r = new RefCountDisposable(d);
|
8574 |
|
8575 | observer.onNext(addRef(win, r));
|
8576 |
|
8577 | d.add(source.subscribe(function (x) {
|
8578 | win.onNext(x);
|
8579 | }, function (err) {
|
8580 | win.onError(err);
|
8581 | observer.onError(err);
|
8582 | }, function () {
|
8583 | win.onCompleted();
|
8584 | observer.onCompleted();
|
8585 | }));
|
8586 |
|
8587 | isPromise(windowBoundaries) && (windowBoundaries = observableFromPromise(windowBoundaries));
|
8588 |
|
8589 | d.add(windowBoundaries.subscribe(function (w) {
|
8590 | win.onCompleted();
|
8591 | win = new Subject();
|
8592 | observer.onNext(addRef(win, r));
|
8593 | }, function (err) {
|
8594 | win.onError(err);
|
8595 | observer.onError(err);
|
8596 | }, function () {
|
8597 | win.onCompleted();
|
8598 | observer.onCompleted();
|
8599 | }));
|
8600 |
|
8601 | return r;
|
8602 | }, source);
|
8603 | }
|
8604 |
|
8605 | function observableWindowWithClosingSelector(windowClosingSelector) {
|
8606 | var source = this;
|
8607 | return new AnonymousObservable(function (observer) {
|
8608 | var m = new SerialDisposable(),
|
8609 | d = new CompositeDisposable(m),
|
8610 | r = new RefCountDisposable(d),
|
8611 | win = new Subject();
|
8612 | observer.onNext(addRef(win, r));
|
8613 | d.add(source.subscribe(function (x) {
|
8614 | win.onNext(x);
|
8615 | }, function (err) {
|
8616 | win.onError(err);
|
8617 | observer.onError(err);
|
8618 | }, function () {
|
8619 | win.onCompleted();
|
8620 | observer.onCompleted();
|
8621 | }));
|
8622 |
|
8623 | function createWindowClose () {
|
8624 | var windowClose;
|
8625 | try {
|
8626 | windowClose = windowClosingSelector();
|
8627 | } catch (e) {
|
8628 | observer.onError(e);
|
8629 | return;
|
8630 | }
|
8631 |
|
8632 | isPromise(windowClose) && (windowClose = observableFromPromise(windowClose));
|
8633 |
|
8634 | var m1 = new SingleAssignmentDisposable();
|
8635 | m.setDisposable(m1);
|
8636 | m1.setDisposable(windowClose.take(1).subscribe(noop, function (err) {
|
8637 | win.onError(err);
|
8638 | observer.onError(err);
|
8639 | }, function () {
|
8640 | win.onCompleted();
|
8641 | win = new Subject();
|
8642 | observer.onNext(addRef(win, r));
|
8643 | createWindowClose();
|
8644 | }));
|
8645 | }
|
8646 |
|
8647 | createWindowClose();
|
8648 | return r;
|
8649 | }, source);
|
8650 | }
|
8651 |
|
8652 | var PairwiseObservable = (function (__super__) {
|
8653 | inherits(PairwiseObservable, __super__);
|
8654 | function PairwiseObservable(source) {
|
8655 | this.source = source;
|
8656 | __super__.call(this);
|
8657 | }
|
8658 |
|
8659 | PairwiseObservable.prototype.subscribeCore = function (o) {
|
8660 | return this.source.subscribe(new PairwiseObserver(o));
|
8661 | };
|
8662 |
|
8663 | return PairwiseObservable;
|
8664 | }(ObservableBase));
|
8665 |
|
8666 | var PairwiseObserver = (function(__super__) {
|
8667 | inherits(PairwiseObserver, __super__);
|
8668 | function PairwiseObserver(o) {
|
8669 | this._o = o;
|
8670 | this._p = null;
|
8671 | this._hp = false;
|
8672 | }
|
8673 |
|
8674 | PairwiseObserver.prototype.next = function (x) {
|
8675 | if (this._hp) {
|
8676 | this._o.onNext([this._p, x]);
|
8677 | } else {
|
8678 | this._hp = true;
|
8679 | }
|
8680 | this._p = x;
|
8681 | };
|
8682 | PairwiseObserver.prototype.error = function (err) { this._o.onError(err); };
|
8683 | PairwiseObserver.prototype.completed = function () { this._o.onCompleted(); };
|
8684 |
|
8685 | return PairwiseObserver;
|
8686 | }(AbstractObserver));
|
8687 |
|
8688 | |
8689 |
|
8690 |
|
8691 |
|
8692 |
|
8693 |
|
8694 | observableProto.pairwise = function () {
|
8695 | return new PairwiseObservable(this);
|
8696 | };
|
8697 |
|
8698 | |
8699 |
|
8700 |
|
8701 |
|
8702 |
|
8703 |
|
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 | observableProto.partition = function(predicate, thisArg) {
|
8712 | var fn = bindCallback(predicate, thisArg, 3);
|
8713 | return [
|
8714 | this.filter(predicate, thisArg),
|
8715 | this.filter(function (x, i, o) { return !fn(x, i, o); })
|
8716 | ];
|
8717 | };
|
8718 |
|
8719 | var WhileEnumerable = (function(__super__) {
|
8720 | inherits(WhileEnumerable, __super__);
|
8721 | function WhileEnumerable(c, s) {
|
8722 | this.c = c;
|
8723 | this.s = s;
|
8724 | }
|
8725 | WhileEnumerable.prototype[$iterator$] = function () {
|
8726 | var self = this;
|
8727 | return {
|
8728 | next: function () {
|
8729 | return self.c() ?
|
8730 | { done: false, value: self.s } :
|
8731 | { done: true, value: void 0 };
|
8732 | }
|
8733 | };
|
8734 | };
|
8735 | return WhileEnumerable;
|
8736 | }(Enumerable));
|
8737 |
|
8738 | function enumerableWhile(condition, source) {
|
8739 | return new WhileEnumerable(condition, source);
|
8740 | }
|
8741 |
|
8742 | |
8743 |
|
8744 |
|
8745 |
|
8746 |
|
8747 |
|
8748 |
|
8749 | observableProto.letBind = observableProto['let'] = function (func) {
|
8750 | return func(this);
|
8751 | };
|
8752 |
|
8753 | |
8754 |
|
8755 |
|
8756 |
|
8757 |
|
8758 |
|
8759 |
|
8760 |
|
8761 |
|
8762 |
|
8763 |
|
8764 |
|
8765 | Observable['if'] = function (condition, thenSource, elseSourceOrScheduler) {
|
8766 | return observableDefer(function () {
|
8767 | elseSourceOrScheduler || (elseSourceOrScheduler = observableEmpty());
|
8768 |
|
8769 | isPromise(thenSource) && (thenSource = observableFromPromise(thenSource));
|
8770 | isPromise(elseSourceOrScheduler) && (elseSourceOrScheduler = observableFromPromise(elseSourceOrScheduler));
|
8771 |
|
8772 |
|
8773 | typeof elseSourceOrScheduler.now === 'function' && (elseSourceOrScheduler = observableEmpty(elseSourceOrScheduler));
|
8774 | return condition() ? thenSource : elseSourceOrScheduler;
|
8775 | });
|
8776 | };
|
8777 |
|
8778 | |
8779 |
|
8780 |
|
8781 |
|
8782 |
|
8783 |
|
8784 |
|
8785 | Observable['for'] = Observable.forIn = function (sources, resultSelector, thisArg) {
|
8786 | return enumerableOf(sources, resultSelector, thisArg).concat();
|
8787 | };
|
8788 |
|
8789 | |
8790 |
|
8791 |
|
8792 |
|
8793 |
|
8794 |
|
8795 |
|
8796 |
|
8797 | var observableWhileDo = Observable['while'] = Observable.whileDo = function (condition, source) {
|
8798 | isPromise(source) && (source = observableFromPromise(source));
|
8799 | return enumerableWhile(condition, source).concat();
|
8800 | };
|
8801 |
|
8802 | |
8803 |
|
8804 |
|
8805 |
|
8806 |
|
8807 |
|
8808 |
|
8809 | observableProto.doWhile = function (condition) {
|
8810 | return observableConcat([this, observableWhileDo(condition, this)]);
|
8811 | };
|
8812 |
|
8813 | |
8814 |
|
8815 |
|
8816 |
|
8817 |
|
8818 |
|
8819 |
|
8820 |
|
8821 | Observable['case'] = function (selector, sources, defaultSourceOrScheduler) {
|
8822 | return observableDefer(function () {
|
8823 | isPromise(defaultSourceOrScheduler) && (defaultSourceOrScheduler = observableFromPromise(defaultSourceOrScheduler));
|
8824 | defaultSourceOrScheduler || (defaultSourceOrScheduler = observableEmpty());
|
8825 |
|
8826 | isScheduler(defaultSourceOrScheduler) && (defaultSourceOrScheduler = observableEmpty(defaultSourceOrScheduler));
|
8827 |
|
8828 | var result = sources[selector()];
|
8829 | isPromise(result) && (result = observableFromPromise(result));
|
8830 |
|
8831 | return result || defaultSourceOrScheduler;
|
8832 | });
|
8833 | };
|
8834 |
|
8835 | var ExpandObservable = (function(__super__) {
|
8836 | inherits(ExpandObservable, __super__);
|
8837 | function ExpandObservable(source, fn, scheduler) {
|
8838 | this.source = source;
|
8839 | this._fn = fn;
|
8840 | this._scheduler = scheduler;
|
8841 | __super__.call(this);
|
8842 | }
|
8843 |
|
8844 | function scheduleRecursive(args, recurse) {
|
8845 | var state = args[0], self = args[1];
|
8846 | var work;
|
8847 | if (state.q.length > 0) {
|
8848 | work = state.q.shift();
|
8849 | } else {
|
8850 | state.isAcquired = false;
|
8851 | return;
|
8852 | }
|
8853 | var m1 = new SingleAssignmentDisposable();
|
8854 | state.d.add(m1);
|
8855 | m1.setDisposable(work.subscribe(new ExpandObserver(state, self, m1)));
|
8856 | recurse([state, self]);
|
8857 | }
|
8858 |
|
8859 | ExpandObservable.prototype._ensureActive = function (state) {
|
8860 | var isOwner = false;
|
8861 | if (state.q.length > 0) {
|
8862 | isOwner = !state.isAcquired;
|
8863 | state.isAcquired = true;
|
8864 | }
|
8865 | isOwner && state.m.setDisposable(this._scheduler.scheduleRecursive([state, this], scheduleRecursive));
|
8866 | };
|
8867 |
|
8868 | ExpandObservable.prototype.subscribeCore = function (o) {
|
8869 | var m = new SerialDisposable(),
|
8870 | d = new CompositeDisposable(m),
|
8871 | state = {
|
8872 | q: [],
|
8873 | m: m,
|
8874 | d: d,
|
8875 | activeCount: 0,
|
8876 | isAcquired: false,
|
8877 | o: o
|
8878 | };
|
8879 |
|
8880 | state.q.push(this.source);
|
8881 | state.activeCount++;
|
8882 | this._ensureActive(state);
|
8883 | return d;
|
8884 | };
|
8885 |
|
8886 | return ExpandObservable;
|
8887 | }(ObservableBase));
|
8888 |
|
8889 | var ExpandObserver = (function(__super__) {
|
8890 | inherits(ExpandObserver, __super__);
|
8891 | function ExpandObserver(state, parent, m1) {
|
8892 | this._s = state;
|
8893 | this._p = parent;
|
8894 | this._m1 = m1;
|
8895 | __super__.call(this);
|
8896 | }
|
8897 |
|
8898 | ExpandObserver.prototype.next = function (x) {
|
8899 | this._s.o.onNext(x);
|
8900 | var result = tryCatch(this._p._fn)(x);
|
8901 | if (result === errorObj) { return this._s.o.onError(result.e); }
|
8902 | this._s.q.push(result);
|
8903 | this._s.activeCount++;
|
8904 | this._p._ensureActive(this._s);
|
8905 | };
|
8906 |
|
8907 | ExpandObserver.prototype.error = function (e) {
|
8908 | this._s.o.onError(e);
|
8909 | };
|
8910 |
|
8911 | ExpandObserver.prototype.completed = function () {
|
8912 | this._s.d.remove(this._m1);
|
8913 | this._s.activeCount--;
|
8914 | this._s.activeCount === 0 && this._s.o.onCompleted();
|
8915 | };
|
8916 |
|
8917 | return ExpandObserver;
|
8918 | }(AbstractObserver));
|
8919 |
|
8920 | |
8921 |
|
8922 |
|
8923 |
|
8924 |
|
8925 |
|
8926 |
|
8927 | observableProto.expand = function (selector, scheduler) {
|
8928 | isScheduler(scheduler) || (scheduler = currentThreadScheduler);
|
8929 | return new ExpandObservable(this, selector, scheduler);
|
8930 | };
|
8931 |
|
8932 | function argumentsToArray() {
|
8933 | var len = arguments.length, args = new Array(len);
|
8934 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
8935 | return args;
|
8936 | }
|
8937 |
|
8938 | var ForkJoinObservable = (function (__super__) {
|
8939 | inherits(ForkJoinObservable, __super__);
|
8940 | function ForkJoinObservable(sources, cb) {
|
8941 | this._sources = sources;
|
8942 | this._cb = cb;
|
8943 | __super__.call(this);
|
8944 | }
|
8945 |
|
8946 | ForkJoinObservable.prototype.subscribeCore = function (o) {
|
8947 | if (this._sources.length === 0) {
|
8948 | o.onCompleted();
|
8949 | return disposableEmpty;
|
8950 | }
|
8951 |
|
8952 | var count = this._sources.length;
|
8953 | var state = {
|
8954 | finished: false,
|
8955 | hasResults: new Array(count),
|
8956 | hasCompleted: new Array(count),
|
8957 | results: new Array(count)
|
8958 | };
|
8959 |
|
8960 | var subscriptions = new CompositeDisposable();
|
8961 | for (var i = 0, len = this._sources.length; i < len; i++) {
|
8962 | var source = this._sources[i];
|
8963 | isPromise(source) && (source = observableFromPromise(source));
|
8964 | subscriptions.add(source.subscribe(new ForkJoinObserver(o, state, i, this._cb, subscriptions)));
|
8965 | }
|
8966 |
|
8967 | return subscriptions;
|
8968 | };
|
8969 |
|
8970 | return ForkJoinObservable;
|
8971 | }(ObservableBase));
|
8972 |
|
8973 | var ForkJoinObserver = (function(__super__) {
|
8974 | inherits(ForkJoinObserver, __super__);
|
8975 | function ForkJoinObserver(o, s, i, cb, subs) {
|
8976 | this._o = o;
|
8977 | this._s = s;
|
8978 | this._i = i;
|
8979 | this._cb = cb;
|
8980 | this._subs = subs;
|
8981 | __super__.call(this);
|
8982 | }
|
8983 |
|
8984 | ForkJoinObserver.prototype.next = function (x) {
|
8985 | if (!this._s.finished) {
|
8986 | this._s.hasResults[this._i] = true;
|
8987 | this._s.results[this._i] = x;
|
8988 | }
|
8989 | };
|
8990 |
|
8991 | ForkJoinObserver.prototype.error = function (e) {
|
8992 | this._s.finished = true;
|
8993 | this._o.onError(e);
|
8994 | this._subs.dispose();
|
8995 | };
|
8996 |
|
8997 | ForkJoinObserver.prototype.completed = function () {
|
8998 | if (!this._s.finished) {
|
8999 | if (!this._s.hasResults[this._i]) {
|
9000 | return this._o.onCompleted();
|
9001 | }
|
9002 | this._s.hasCompleted[this._i] = true;
|
9003 | for (var i = 0; i < this._s.results.length; i++) {
|
9004 | if (!this._s.hasCompleted[i]) { return; }
|
9005 | }
|
9006 | this._s.finished = true;
|
9007 |
|
9008 | var res = tryCatch(this._cb).apply(null, this._s.results);
|
9009 | if (res === errorObj) { return this._o.onError(res.e); }
|
9010 |
|
9011 | this._o.onNext(res);
|
9012 | this._o.onCompleted();
|
9013 | }
|
9014 | };
|
9015 |
|
9016 | return ForkJoinObserver;
|
9017 | }(AbstractObserver));
|
9018 |
|
9019 | |
9020 |
|
9021 |
|
9022 |
|
9023 |
|
9024 |
|
9025 |
|
9026 |
|
9027 | Observable.forkJoin = function () {
|
9028 | var len = arguments.length, args = new Array(len);
|
9029 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
9030 | var resultSelector = isFunction(args[len - 1]) ? args.pop() : argumentsToArray;
|
9031 | Array.isArray(args[0]) && (args = args[0]);
|
9032 | return new ForkJoinObservable(args, resultSelector);
|
9033 | };
|
9034 |
|
9035 | |
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 |
|
9041 | observableProto.forkJoin = function () {
|
9042 | var len = arguments.length, args = new Array(len);
|
9043 | for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
9044 | if (Array.isArray(args[0])) {
|
9045 | args[0].unshift(this);
|
9046 | } else {
|
9047 | args.unshift(this);
|
9048 | }
|
9049 | return Observable.forkJoin.apply(null, args);
|
9050 | };
|
9051 |
|
9052 | |
9053 |
|
9054 |
|
9055 |
|
9056 |
|
9057 |
|
9058 | observableProto.manySelect = observableProto.extend = function (selector, scheduler) {
|
9059 | isScheduler(scheduler) || (scheduler = Rx.Scheduler.immediate);
|
9060 | var source = this;
|
9061 | return observableDefer(function () {
|
9062 | var chain;
|
9063 |
|
9064 | return source
|
9065 | .map(function (x) {
|
9066 | var curr = new ChainObservable(x);
|
9067 |
|
9068 | chain && chain.onNext(x);
|
9069 | chain = curr;
|
9070 |
|
9071 | return curr;
|
9072 | })
|
9073 | .tap(
|
9074 | noop,
|
9075 | function (e) { chain && chain.onError(e); },
|
9076 | function () { chain && chain.onCompleted(); }
|
9077 | )
|
9078 | .observeOn(scheduler)
|
9079 | .map(selector);
|
9080 | }, source);
|
9081 | };
|
9082 |
|
9083 | var ChainObservable = (function (__super__) {
|
9084 | inherits(ChainObservable, __super__);
|
9085 | function ChainObservable(head) {
|
9086 | __super__.call(this);
|
9087 | this.head = head;
|
9088 | this.tail = new AsyncSubject();
|
9089 | }
|
9090 |
|
9091 | addProperties(ChainObservable.prototype, Observer, {
|
9092 | _subscribe: function (o) {
|
9093 | var g = new CompositeDisposable();
|
9094 | g.add(currentThreadScheduler.schedule(this, function (_, self) {
|
9095 | o.onNext(self.head);
|
9096 | g.add(self.tail.mergeAll().subscribe(o));
|
9097 | }));
|
9098 |
|
9099 | return g;
|
9100 | },
|
9101 | onCompleted: function () {
|
9102 | this.onNext(Observable.empty());
|
9103 | },
|
9104 | onError: function (e) {
|
9105 | this.onNext(Observable['throw'](e));
|
9106 | },
|
9107 | onNext: function (v) {
|
9108 | this.tail.onNext(v);
|
9109 | this.tail.onCompleted();
|
9110 | }
|
9111 | });
|
9112 |
|
9113 | return ChainObservable;
|
9114 |
|
9115 | }(Observable));
|
9116 |
|
9117 | var Map = root.Map || (function () {
|
9118 | function Map() {
|
9119 | this.size = 0;
|
9120 | this._values = [];
|
9121 | this._keys = [];
|
9122 | }
|
9123 |
|
9124 | Map.prototype['delete'] = function (key) {
|
9125 | var i = this._keys.indexOf(key);
|
9126 | if (i === -1) { return false; }
|
9127 | this._values.splice(i, 1);
|
9128 | this._keys.splice(i, 1);
|
9129 | this.size--;
|
9130 | return true;
|
9131 | };
|
9132 |
|
9133 | Map.prototype.get = function (key) {
|
9134 | var i = this._keys.indexOf(key);
|
9135 | return i === -1 ? undefined : this._values[i];
|
9136 | };
|
9137 |
|
9138 | Map.prototype.set = function (key, value) {
|
9139 | var i = this._keys.indexOf(key);
|
9140 | if (i === -1) {
|
9141 | this._keys.push(key);
|
9142 | this._values.push(value);
|
9143 | this.size++;
|
9144 | } else {
|
9145 | this._values[i] = value;
|
9146 | }
|
9147 | return this;
|
9148 | };
|
9149 |
|
9150 | Map.prototype.forEach = function (cb, thisArg) {
|
9151 | for (var i = 0; i < this.size; i++) {
|
9152 | cb.call(thisArg, this._values[i], this._keys[i]);
|
9153 | }
|
9154 | };
|
9155 |
|
9156 | return Map;
|
9157 | }());
|
9158 |
|
9159 | |
9160 |
|
9161 |
|
9162 |
|
9163 | function Pattern(patterns) {
|
9164 | this.patterns = patterns;
|
9165 | }
|
9166 |
|
9167 | |
9168 |
|
9169 |
|
9170 |
|
9171 |
|
9172 | Pattern.prototype.and = function (other) {
|
9173 | return new Pattern(this.patterns.concat(other));
|
9174 | };
|
9175 |
|
9176 | |
9177 |
|
9178 |
|
9179 |
|
9180 |
|
9181 | Pattern.prototype.thenDo = function (selector) {
|
9182 | return new Plan(this, selector);
|
9183 | };
|
9184 |
|
9185 | function Plan(expression, selector) {
|
9186 | this.expression = expression;
|
9187 | this.selector = selector;
|
9188 | }
|
9189 |
|
9190 | function handleOnError(o) { return function (e) { o.onError(e); }; }
|
9191 | function handleOnNext(self, observer) {
|
9192 | return function onNext () {
|
9193 | var result = tryCatch(self.selector).apply(self, arguments);
|
9194 | if (result === errorObj) { return observer.onError(result.e); }
|
9195 | observer.onNext(result);
|
9196 | };
|
9197 | }
|
9198 |
|
9199 | Plan.prototype.activate = function (externalSubscriptions, observer, deactivate) {
|
9200 | var joinObservers = [], errHandler = handleOnError(observer);
|
9201 | for (var i = 0, len = this.expression.patterns.length; i < len; i++) {
|
9202 | joinObservers.push(planCreateObserver(externalSubscriptions, this.expression.patterns[i], errHandler));
|
9203 | }
|
9204 | var activePlan = new ActivePlan(joinObservers, handleOnNext(this, observer), function () {
|
9205 | for (var j = 0, jlen = joinObservers.length; j < jlen; j++) {
|
9206 | joinObservers[j].removeActivePlan(activePlan);
|
9207 | }
|
9208 | deactivate(activePlan);
|
9209 | });
|
9210 | for (i = 0, len = joinObservers.length; i < len; i++) {
|
9211 | joinObservers[i].addActivePlan(activePlan);
|
9212 | }
|
9213 | return activePlan;
|
9214 | };
|
9215 |
|
9216 | function planCreateObserver(externalSubscriptions, observable, onError) {
|
9217 | var entry = externalSubscriptions.get(observable);
|
9218 | if (!entry) {
|
9219 | var observer = new JoinObserver(observable, onError);
|
9220 | externalSubscriptions.set(observable, observer);
|
9221 | return observer;
|
9222 | }
|
9223 | return entry;
|
9224 | }
|
9225 |
|
9226 | function ActivePlan(joinObserverArray, onNext, onCompleted) {
|
9227 | this.joinObserverArray = joinObserverArray;
|
9228 | this.onNext = onNext;
|
9229 | this.onCompleted = onCompleted;
|
9230 | this.joinObservers = new Map();
|
9231 | for (var i = 0, len = this.joinObserverArray.length; i < len; i++) {
|
9232 | var joinObserver = this.joinObserverArray[i];
|
9233 | this.joinObservers.set(joinObserver, joinObserver);
|
9234 | }
|
9235 | }
|
9236 |
|
9237 | ActivePlan.prototype.dequeue = function () {
|
9238 | this.joinObservers.forEach(function (v) { v.queue.shift(); });
|
9239 | };
|
9240 |
|
9241 | ActivePlan.prototype.match = function () {
|
9242 | var i, len, hasValues = true;
|
9243 | for (i = 0, len = this.joinObserverArray.length; i < len; i++) {
|
9244 | if (this.joinObserverArray[i].queue.length === 0) {
|
9245 | hasValues = false;
|
9246 | break;
|
9247 | }
|
9248 | }
|
9249 | if (hasValues) {
|
9250 | var firstValues = [],
|
9251 | isCompleted = false;
|
9252 | for (i = 0, len = this.joinObserverArray.length; i < len; i++) {
|
9253 | firstValues.push(this.joinObserverArray[i].queue[0]);
|
9254 | this.joinObserverArray[i].queue[0].kind === 'C' && (isCompleted = true);
|
9255 | }
|
9256 | if (isCompleted) {
|
9257 | this.onCompleted();
|
9258 | } else {
|
9259 | this.dequeue();
|
9260 | var values = [];
|
9261 | for (i = 0, len = firstValues.length; i < firstValues.length; i++) {
|
9262 | values.push(firstValues[i].value);
|
9263 | }
|
9264 | this.onNext.apply(this, values);
|
9265 | }
|
9266 | }
|
9267 | };
|
9268 |
|
9269 | var JoinObserver = (function (__super__) {
|
9270 | inherits(JoinObserver, __super__);
|
9271 |
|
9272 | function JoinObserver(source, onError) {
|
9273 | __super__.call(this);
|
9274 | this.source = source;
|
9275 | this.onError = onError;
|
9276 | this.queue = [];
|
9277 | this.activePlans = [];
|
9278 | this.subscription = new SingleAssignmentDisposable();
|
9279 | this.isDisposed = false;
|
9280 | }
|
9281 |
|
9282 | var JoinObserverPrototype = JoinObserver.prototype;
|
9283 |
|
9284 | JoinObserverPrototype.next = function (notification) {
|
9285 | if (!this.isDisposed) {
|
9286 | if (notification.kind === 'E') {
|
9287 | return this.onError(notification.error);
|
9288 | }
|
9289 | this.queue.push(notification);
|
9290 | var activePlans = this.activePlans.slice(0);
|
9291 | for (var i = 0, len = activePlans.length; i < len; i++) {
|
9292 | activePlans[i].match();
|
9293 | }
|
9294 | }
|
9295 | };
|
9296 |
|
9297 | JoinObserverPrototype.error = noop;
|
9298 | JoinObserverPrototype.completed = noop;
|
9299 |
|
9300 | JoinObserverPrototype.addActivePlan = function (activePlan) {
|
9301 | this.activePlans.push(activePlan);
|
9302 | };
|
9303 |
|
9304 | JoinObserverPrototype.subscribe = function () {
|
9305 | this.subscription.setDisposable(this.source.materialize().subscribe(this));
|
9306 | };
|
9307 |
|
9308 | JoinObserverPrototype.removeActivePlan = function (activePlan) {
|
9309 | this.activePlans.splice(this.activePlans.indexOf(activePlan), 1);
|
9310 | this.activePlans.length === 0 && this.dispose();
|
9311 | };
|
9312 |
|
9313 | JoinObserverPrototype.dispose = function () {
|
9314 | __super__.prototype.dispose.call(this);
|
9315 | if (!this.isDisposed) {
|
9316 | this.isDisposed = true;
|
9317 | this.subscription.dispose();
|
9318 | }
|
9319 | };
|
9320 |
|
9321 | return JoinObserver;
|
9322 | } (AbstractObserver));
|
9323 |
|
9324 | |
9325 |
|
9326 |
|
9327 |
|
9328 |
|
9329 |
|
9330 | observableProto.and = function (right) {
|
9331 | return new Pattern([this, right]);
|
9332 | };
|
9333 |
|
9334 | |
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 | observableProto.thenDo = function (selector) {
|
9341 | return new Pattern([this]).thenDo(selector);
|
9342 | };
|
9343 |
|
9344 | |
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 |
|
9350 | Observable.when = function () {
|
9351 | var len = arguments.length, plans;
|
9352 | if (Array.isArray(arguments[0])) {
|
9353 | plans = arguments[0];
|
9354 | } else {
|
9355 | plans = new Array(len);
|
9356 | for(var i = 0; i < len; i++) { plans[i] = arguments[i]; }
|
9357 | }
|
9358 | return new AnonymousObservable(function (o) {
|
9359 | var activePlans = [],
|
9360 | externalSubscriptions = new Map();
|
9361 | var outObserver = observerCreate(
|
9362 | function (x) { o.onNext(x); },
|
9363 | function (err) {
|
9364 | externalSubscriptions.forEach(function (v) { v.onError(err); });
|
9365 | o.onError(err);
|
9366 | },
|
9367 | function (x) { o.onCompleted(); }
|
9368 | );
|
9369 | try {
|
9370 | for (var i = 0, len = plans.length; i < len; i++) {
|
9371 | activePlans.push(plans[i].activate(externalSubscriptions, outObserver, function (activePlan) {
|
9372 | var idx = activePlans.indexOf(activePlan);
|
9373 | activePlans.splice(idx, 1);
|
9374 | activePlans.length === 0 && o.onCompleted();
|
9375 | }));
|
9376 | }
|
9377 | } catch (e) {
|
9378 | observableThrow(e).subscribe(o);
|
9379 | }
|
9380 | var group = new CompositeDisposable();
|
9381 | externalSubscriptions.forEach(function (joinObserver) {
|
9382 | joinObserver.subscribe();
|
9383 | group.add(joinObserver);
|
9384 | });
|
9385 |
|
9386 | return group;
|
9387 | });
|
9388 | };
|
9389 |
|
9390 | var TimerObservable = (function(__super__) {
|
9391 | inherits(TimerObservable, __super__);
|
9392 | function TimerObservable(dt, s) {
|
9393 | this._dt = dt;
|
9394 | this._s = s;
|
9395 | __super__.call(this);
|
9396 | }
|
9397 |
|
9398 | TimerObservable.prototype.subscribeCore = function (o) {
|
9399 | return this._s.scheduleFuture(o, this._dt, scheduleMethod);
|
9400 | };
|
9401 |
|
9402 | function scheduleMethod(s, o) {
|
9403 | o.onNext(0);
|
9404 | o.onCompleted();
|
9405 | }
|
9406 |
|
9407 | return TimerObservable;
|
9408 | }(ObservableBase));
|
9409 |
|
9410 | function _observableTimer(dueTime, scheduler) {
|
9411 | return new TimerObservable(dueTime, scheduler);
|
9412 | }
|
9413 |
|
9414 | function observableTimerDateAndPeriod(dueTime, period, scheduler) {
|
9415 | return new AnonymousObservable(function (observer) {
|
9416 | var d = dueTime, p = normalizeTime(period);
|
9417 | return scheduler.scheduleRecursiveFuture(0, d, function (count, self) {
|
9418 | if (p > 0) {
|
9419 | var now = scheduler.now();
|
9420 | d = new Date(d.getTime() + p);
|
9421 | d.getTime() <= now && (d = new Date(now + p));
|
9422 | }
|
9423 | observer.onNext(count);
|
9424 | self(count + 1, new Date(d));
|
9425 | });
|
9426 | });
|
9427 | }
|
9428 |
|
9429 | function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
9430 | return dueTime === period ?
|
9431 | new AnonymousObservable(function (observer) {
|
9432 | return scheduler.schedulePeriodic(0, period, function (count) {
|
9433 | observer.onNext(count);
|
9434 | return count + 1;
|
9435 | });
|
9436 | }) :
|
9437 | observableDefer(function () {
|
9438 | return observableTimerDateAndPeriod(new Date(scheduler.now() + dueTime), period, scheduler);
|
9439 | });
|
9440 | }
|
9441 |
|
9442 | |
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 | var observableinterval = Observable.interval = function (period, scheduler) {
|
9454 | return observableTimerTimeSpanAndPeriod(period, period, isScheduler(scheduler) ? scheduler : defaultScheduler);
|
9455 | };
|
9456 |
|
9457 | |
9458 |
|
9459 |
|
9460 |
|
9461 |
|
9462 |
|
9463 |
|
9464 | var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
9465 | var period;
|
9466 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
9467 | if (periodOrScheduler != null && typeof periodOrScheduler === 'number') {
|
9468 | period = periodOrScheduler;
|
9469 | } else if (isScheduler(periodOrScheduler)) {
|
9470 | scheduler = periodOrScheduler;
|
9471 | }
|
9472 | if ((dueTime instanceof Date || typeof dueTime === 'number') && period === undefined) {
|
9473 | return _observableTimer(dueTime, scheduler);
|
9474 | }
|
9475 | if (dueTime instanceof Date && period !== undefined) {
|
9476 | return observableTimerDateAndPeriod(dueTime.getTime(), periodOrScheduler, scheduler);
|
9477 | }
|
9478 | return observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
|
9479 | };
|
9480 |
|
9481 | function observableDelayRelative(source, dueTime, scheduler) {
|
9482 | return new AnonymousObservable(function (o) {
|
9483 | var active = false,
|
9484 | cancelable = new SerialDisposable(),
|
9485 | exception = null,
|
9486 | q = [],
|
9487 | running = false,
|
9488 | subscription;
|
9489 | subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
9490 | var d, shouldRun;
|
9491 | if (notification.value.kind === 'E') {
|
9492 | q = [];
|
9493 | q.push(notification);
|
9494 | exception = notification.value.error;
|
9495 | shouldRun = !running;
|
9496 | } else {
|
9497 | q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
9498 | shouldRun = !active;
|
9499 | active = true;
|
9500 | }
|
9501 | if (shouldRun) {
|
9502 | if (exception !== null) {
|
9503 | o.onError(exception);
|
9504 | } else {
|
9505 | d = new SingleAssignmentDisposable();
|
9506 | cancelable.setDisposable(d);
|
9507 | d.setDisposable(scheduler.scheduleRecursiveFuture(null, dueTime, function (_, self) {
|
9508 | var e, recurseDueTime, result, shouldRecurse;
|
9509 | if (exception !== null) {
|
9510 | return;
|
9511 | }
|
9512 | running = true;
|
9513 | do {
|
9514 | result = null;
|
9515 | if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
9516 | result = q.shift().value;
|
9517 | }
|
9518 | if (result !== null) {
|
9519 | result.accept(o);
|
9520 | }
|
9521 | } while (result !== null);
|
9522 | shouldRecurse = false;
|
9523 | recurseDueTime = 0;
|
9524 | if (q.length > 0) {
|
9525 | shouldRecurse = true;
|
9526 | recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
9527 | } else {
|
9528 | active = false;
|
9529 | }
|
9530 | e = exception;
|
9531 | running = false;
|
9532 | if (e !== null) {
|
9533 | o.onError(e);
|
9534 | } else if (shouldRecurse) {
|
9535 | self(null, recurseDueTime);
|
9536 | }
|
9537 | }));
|
9538 | }
|
9539 | }
|
9540 | });
|
9541 | return new BinaryDisposable(subscription, cancelable);
|
9542 | }, source);
|
9543 | }
|
9544 |
|
9545 | function observableDelayAbsolute(source, dueTime, scheduler) {
|
9546 | return observableDefer(function () {
|
9547 | return observableDelayRelative(source, dueTime - scheduler.now(), scheduler);
|
9548 | });
|
9549 | }
|
9550 |
|
9551 | function delayWithSelector(source, subscriptionDelay, delayDurationSelector) {
|
9552 | var subDelay, selector;
|
9553 | if (isFunction(subscriptionDelay)) {
|
9554 | selector = subscriptionDelay;
|
9555 | } else {
|
9556 | subDelay = subscriptionDelay;
|
9557 | selector = delayDurationSelector;
|
9558 | }
|
9559 | return new AnonymousObservable(function (o) {
|
9560 | var delays = new CompositeDisposable(), atEnd = false, subscription = new SerialDisposable();
|
9561 |
|
9562 | function start() {
|
9563 | subscription.setDisposable(source.subscribe(
|
9564 | function (x) {
|
9565 | var delay = tryCatch(selector)(x);
|
9566 | if (delay === errorObj) { return o.onError(delay.e); }
|
9567 | var d = new SingleAssignmentDisposable();
|
9568 | delays.add(d);
|
9569 | d.setDisposable(delay.subscribe(
|
9570 | function () {
|
9571 | o.onNext(x);
|
9572 | delays.remove(d);
|
9573 | done();
|
9574 | },
|
9575 | function (e) { o.onError(e); },
|
9576 | function () {
|
9577 | o.onNext(x);
|
9578 | delays.remove(d);
|
9579 | done();
|
9580 | }
|
9581 | ));
|
9582 | },
|
9583 | function (e) { o.onError(e); },
|
9584 | function () {
|
9585 | atEnd = true;
|
9586 | subscription.dispose();
|
9587 | done();
|
9588 | }
|
9589 | ));
|
9590 | }
|
9591 |
|
9592 | function done () {
|
9593 | atEnd && delays.length === 0 && o.onCompleted();
|
9594 | }
|
9595 |
|
9596 | if (!subDelay) {
|
9597 | start();
|
9598 | } else {
|
9599 | subscription.setDisposable(subDelay.subscribe(start, function (e) { o.onError(e); }, start));
|
9600 | }
|
9601 |
|
9602 | return new BinaryDisposable(subscription, delays);
|
9603 | }, this);
|
9604 | }
|
9605 |
|
9606 | |
9607 |
|
9608 |
|
9609 |
|
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 | observableProto.delay = function () {
|
9615 | var firstArg = arguments[0];
|
9616 | if (typeof firstArg === 'number' || firstArg instanceof Date) {
|
9617 | var dueTime = firstArg, scheduler = arguments[1];
|
9618 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
9619 | return dueTime instanceof Date ?
|
9620 | observableDelayAbsolute(this, dueTime, scheduler) :
|
9621 | observableDelayRelative(this, dueTime, scheduler);
|
9622 | } else if (Observable.isObservable(firstArg) || isFunction(firstArg)) {
|
9623 | return delayWithSelector(this, firstArg, arguments[1]);
|
9624 | } else {
|
9625 | throw new Error('Invalid arguments');
|
9626 | }
|
9627 | };
|
9628 |
|
9629 | var DebounceObservable = (function (__super__) {
|
9630 | inherits(DebounceObservable, __super__);
|
9631 | function DebounceObservable(source, dt, s) {
|
9632 | isScheduler(s) || (s = defaultScheduler);
|
9633 | this.source = source;
|
9634 | this._dt = dt;
|
9635 | this._s = s;
|
9636 | __super__.call(this);
|
9637 | }
|
9638 |
|
9639 | DebounceObservable.prototype.subscribeCore = function (o) {
|
9640 | var cancelable = new SerialDisposable();
|
9641 | return new BinaryDisposable(
|
9642 | this.source.subscribe(new DebounceObserver(o, this.source, this._dt, this._s, cancelable)),
|
9643 | cancelable);
|
9644 | };
|
9645 |
|
9646 | return DebounceObservable;
|
9647 | }(ObservableBase));
|
9648 |
|
9649 | var DebounceObserver = (function (__super__) {
|
9650 | inherits(DebounceObserver, __super__);
|
9651 | function DebounceObserver(observer, source, dueTime, scheduler, cancelable) {
|
9652 | this._o = observer;
|
9653 | this._s = source;
|
9654 | this._d = dueTime;
|
9655 | this._scheduler = scheduler;
|
9656 | this._c = cancelable;
|
9657 | this._v = null;
|
9658 | this._hv = false;
|
9659 | this._id = 0;
|
9660 | __super__.call(this);
|
9661 | }
|
9662 |
|
9663 | DebounceObserver.prototype.next = function (x) {
|
9664 | this._hv = true;
|
9665 | this._v = x;
|
9666 | var currentId = ++this._id, d = new SingleAssignmentDisposable();
|
9667 | this._c.setDisposable(d);
|
9668 | d.setDisposable(this._scheduler.scheduleFuture(this, this._d, function (_, self) {
|
9669 | self._hv && self._id === currentId && self._o.onNext(x);
|
9670 | self._hv = false;
|
9671 | }));
|
9672 | };
|
9673 |
|
9674 | DebounceObserver.prototype.error = function (e) {
|
9675 | this._c.dispose();
|
9676 | this._o.onError(e);
|
9677 | this._hv = false;
|
9678 | this._id++;
|
9679 | };
|
9680 |
|
9681 | DebounceObserver.prototype.completed = function () {
|
9682 | this._c.dispose();
|
9683 | this._hv && this._o.onNext(this._v);
|
9684 | this._o.onCompleted();
|
9685 | this._hv = false;
|
9686 | this._id++;
|
9687 | };
|
9688 |
|
9689 | return DebounceObserver;
|
9690 | }(AbstractObserver));
|
9691 |
|
9692 | function debounceWithSelector(source, durationSelector) {
|
9693 | return new AnonymousObservable(function (o) {
|
9694 | var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
|
9695 | var subscription = source.subscribe(
|
9696 | function (x) {
|
9697 | var throttle = tryCatch(durationSelector)(x);
|
9698 | if (throttle === errorObj) { return o.onError(throttle.e); }
|
9699 |
|
9700 | isPromise(throttle) && (throttle = observableFromPromise(throttle));
|
9701 |
|
9702 | hasValue = true;
|
9703 | value = x;
|
9704 | id++;
|
9705 | var currentid = id, d = new SingleAssignmentDisposable();
|
9706 | cancelable.setDisposable(d);
|
9707 | d.setDisposable(throttle.subscribe(
|
9708 | function () {
|
9709 | hasValue && id === currentid && o.onNext(value);
|
9710 | hasValue = false;
|
9711 | d.dispose();
|
9712 | },
|
9713 | function (e) { o.onError(e); },
|
9714 | function () {
|
9715 | hasValue && id === currentid && o.onNext(value);
|
9716 | hasValue = false;
|
9717 | d.dispose();
|
9718 | }
|
9719 | ));
|
9720 | },
|
9721 | function (e) {
|
9722 | cancelable.dispose();
|
9723 | o.onError(e);
|
9724 | hasValue = false;
|
9725 | id++;
|
9726 | },
|
9727 | function () {
|
9728 | cancelable.dispose();
|
9729 | hasValue && o.onNext(value);
|
9730 | o.onCompleted();
|
9731 | hasValue = false;
|
9732 | id++;
|
9733 | }
|
9734 | );
|
9735 | return new BinaryDisposable(subscription, cancelable);
|
9736 | }, source);
|
9737 | }
|
9738 |
|
9739 | observableProto.debounce = function () {
|
9740 | if (isFunction (arguments[0])) {
|
9741 | return debounceWithSelector(this, arguments[0]);
|
9742 | } else if (typeof arguments[0] === 'number') {
|
9743 | return new DebounceObservable(this, arguments[0], arguments[1]);
|
9744 | } else {
|
9745 | throw new Error('Invalid arguments');
|
9746 | }
|
9747 | };
|
9748 |
|
9749 | |
9750 |
|
9751 |
|
9752 |
|
9753 |
|
9754 |
|
9755 |
|
9756 | observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
9757 | var source = this, timeShift;
|
9758 | timeShiftOrScheduler == null && (timeShift = timeSpan);
|
9759 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
9760 | if (typeof timeShiftOrScheduler === 'number') {
|
9761 | timeShift = timeShiftOrScheduler;
|
9762 | } else if (isScheduler(timeShiftOrScheduler)) {
|
9763 | timeShift = timeSpan;
|
9764 | scheduler = timeShiftOrScheduler;
|
9765 | }
|
9766 | return new AnonymousObservable(function (observer) {
|
9767 | var groupDisposable,
|
9768 | nextShift = timeShift,
|
9769 | nextSpan = timeSpan,
|
9770 | q = [],
|
9771 | refCountDisposable,
|
9772 | timerD = new SerialDisposable(),
|
9773 | totalTime = 0;
|
9774 | groupDisposable = new CompositeDisposable(timerD),
|
9775 | refCountDisposable = new RefCountDisposable(groupDisposable);
|
9776 |
|
9777 | function createTimer () {
|
9778 | var m = new SingleAssignmentDisposable(),
|
9779 | isSpan = false,
|
9780 | isShift = false;
|
9781 | timerD.setDisposable(m);
|
9782 | if (nextSpan === nextShift) {
|
9783 | isSpan = true;
|
9784 | isShift = true;
|
9785 | } else if (nextSpan < nextShift) {
|
9786 | isSpan = true;
|
9787 | } else {
|
9788 | isShift = true;
|
9789 | }
|
9790 | var newTotalTime = isSpan ? nextSpan : nextShift,
|
9791 | ts = newTotalTime - totalTime;
|
9792 | totalTime = newTotalTime;
|
9793 | if (isSpan) {
|
9794 | nextSpan += timeShift;
|
9795 | }
|
9796 | if (isShift) {
|
9797 | nextShift += timeShift;
|
9798 | }
|
9799 | m.setDisposable(scheduler.scheduleFuture(null, ts, function () {
|
9800 | if (isShift) {
|
9801 | var s = new Subject();
|
9802 | q.push(s);
|
9803 | observer.onNext(addRef(s, refCountDisposable));
|
9804 | }
|
9805 | isSpan && q.shift().onCompleted();
|
9806 | createTimer();
|
9807 | }));
|
9808 | };
|
9809 | q.push(new Subject());
|
9810 | observer.onNext(addRef(q[0], refCountDisposable));
|
9811 | createTimer();
|
9812 | groupDisposable.add(source.subscribe(
|
9813 | function (x) {
|
9814 | for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
|
9815 | },
|
9816 | function (e) {
|
9817 | for (var i = 0, len = q.length; i < len; i++) { q[i].onError(e); }
|
9818 | observer.onError(e);
|
9819 | },
|
9820 | function () {
|
9821 | for (var i = 0, len = q.length; i < len; i++) { q[i].onCompleted(); }
|
9822 | observer.onCompleted();
|
9823 | }
|
9824 | ));
|
9825 | return refCountDisposable;
|
9826 | }, source);
|
9827 | };
|
9828 |
|
9829 | |
9830 |
|
9831 |
|
9832 |
|
9833 |
|
9834 |
|
9835 |
|
9836 | observableProto.windowWithTimeOrCount = function (timeSpan, count, scheduler) {
|
9837 | var source = this;
|
9838 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
9839 | return new AnonymousObservable(function (observer) {
|
9840 | var timerD = new SerialDisposable(),
|
9841 | groupDisposable = new CompositeDisposable(timerD),
|
9842 | refCountDisposable = new RefCountDisposable(groupDisposable),
|
9843 | n = 0,
|
9844 | windowId = 0,
|
9845 | s = new Subject();
|
9846 |
|
9847 | function createTimer(id) {
|
9848 | var m = new SingleAssignmentDisposable();
|
9849 | timerD.setDisposable(m);
|
9850 | m.setDisposable(scheduler.scheduleFuture(null, timeSpan, function () {
|
9851 | if (id !== windowId) { return; }
|
9852 | n = 0;
|
9853 | var newId = ++windowId;
|
9854 | s.onCompleted();
|
9855 | s = new Subject();
|
9856 | observer.onNext(addRef(s, refCountDisposable));
|
9857 | createTimer(newId);
|
9858 | }));
|
9859 | }
|
9860 |
|
9861 | observer.onNext(addRef(s, refCountDisposable));
|
9862 | createTimer(0);
|
9863 |
|
9864 | groupDisposable.add(source.subscribe(
|
9865 | function (x) {
|
9866 | var newId = 0, newWindow = false;
|
9867 | s.onNext(x);
|
9868 | if (++n === count) {
|
9869 | newWindow = true;
|
9870 | n = 0;
|
9871 | newId = ++windowId;
|
9872 | s.onCompleted();
|
9873 | s = new Subject();
|
9874 | observer.onNext(addRef(s, refCountDisposable));
|
9875 | }
|
9876 | newWindow && createTimer(newId);
|
9877 | },
|
9878 | function (e) {
|
9879 | s.onError(e);
|
9880 | observer.onError(e);
|
9881 | }, function () {
|
9882 | s.onCompleted();
|
9883 | observer.onCompleted();
|
9884 | }
|
9885 | ));
|
9886 | return refCountDisposable;
|
9887 | }, source);
|
9888 | };
|
9889 |
|
9890 | function toArray(x) { return x.toArray(); }
|
9891 |
|
9892 | |
9893 |
|
9894 |
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 | observableProto.bufferWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
9900 | return this.windowWithTime(timeSpan, timeShiftOrScheduler, scheduler).flatMap(toArray);
|
9901 | };
|
9902 |
|
9903 | function toArray(x) { return x.toArray(); }
|
9904 |
|
9905 | |
9906 |
|
9907 |
|
9908 |
|
9909 |
|
9910 |
|
9911 |
|
9912 | observableProto.bufferWithTimeOrCount = function (timeSpan, count, scheduler) {
|
9913 | return this.windowWithTimeOrCount(timeSpan, count, scheduler).flatMap(toArray);
|
9914 | };
|
9915 |
|
9916 | var TimeIntervalObservable = (function (__super__) {
|
9917 | inherits(TimeIntervalObservable, __super__);
|
9918 | function TimeIntervalObservable(source, s) {
|
9919 | this.source = source;
|
9920 | this._s = s;
|
9921 | __super__.call(this);
|
9922 | }
|
9923 |
|
9924 | TimeIntervalObservable.prototype.subscribeCore = function (o) {
|
9925 | return this.source.subscribe(new TimeIntervalObserver(o, this._s));
|
9926 | };
|
9927 |
|
9928 | return TimeIntervalObservable;
|
9929 | }(ObservableBase));
|
9930 |
|
9931 | var TimeIntervalObserver = (function (__super__) {
|
9932 | inherits(TimeIntervalObserver, __super__);
|
9933 |
|
9934 | function TimeIntervalObserver(o, s) {
|
9935 | this._o = o;
|
9936 | this._s = s;
|
9937 | this._l = s.now();
|
9938 | __super__.call(this);
|
9939 | }
|
9940 |
|
9941 | TimeIntervalObserver.prototype.next = function (x) {
|
9942 | var now = this._s.now(), span = now - this._l;
|
9943 | this._l = now;
|
9944 | this._o.onNext({ value: x, interval: span });
|
9945 | };
|
9946 | TimeIntervalObserver.prototype.error = function (e) { this._o.onError(e); };
|
9947 | TimeIntervalObserver.prototype.completed = function () { this._o.onCompleted(); };
|
9948 |
|
9949 | return TimeIntervalObserver;
|
9950 | }(AbstractObserver));
|
9951 |
|
9952 | |
9953 |
|
9954 |
|
9955 |
|
9956 |
|
9957 |
|
9958 |
|
9959 |
|
9960 |
|
9961 |
|
9962 | observableProto.timeInterval = function (scheduler) {
|
9963 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
9964 | return new TimeIntervalObservable(this, scheduler);
|
9965 | };
|
9966 |
|
9967 | var TimestampObservable = (function (__super__) {
|
9968 | inherits(TimestampObservable, __super__);
|
9969 | function TimestampObservable(source, s) {
|
9970 | this.source = source;
|
9971 | this._s = s;
|
9972 | __super__.call(this);
|
9973 | }
|
9974 |
|
9975 | TimestampObservable.prototype.subscribeCore = function (o) {
|
9976 | return this.source.subscribe(new TimestampObserver(o, this._s));
|
9977 | };
|
9978 |
|
9979 | return TimestampObservable;
|
9980 | }(ObservableBase));
|
9981 |
|
9982 | var TimestampObserver = (function (__super__) {
|
9983 | inherits(TimestampObserver, __super__);
|
9984 | function TimestampObserver(o, s) {
|
9985 | this._o = o;
|
9986 | this._s = s;
|
9987 | __super__.call(this);
|
9988 | }
|
9989 |
|
9990 | TimestampObserver.prototype.next = function (x) {
|
9991 | this._o.onNext({ value: x, timestamp: this._s.now() });
|
9992 | };
|
9993 |
|
9994 | TimestampObserver.prototype.error = function (e) {
|
9995 | this._o.onError(e);
|
9996 | };
|
9997 |
|
9998 | TimestampObserver.prototype.completed = function () {
|
9999 | this._o.onCompleted();
|
10000 | };
|
10001 |
|
10002 | return TimestampObserver;
|
10003 | }(AbstractObserver));
|
10004 |
|
10005 | |
10006 |
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 |
|
10014 |
|
10015 | observableProto.timestamp = function (scheduler) {
|
10016 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10017 | return new TimestampObservable(this, scheduler);
|
10018 | };
|
10019 |
|
10020 | function sampleObservable(source, sampler) {
|
10021 | return new AnonymousObservable(function (o) {
|
10022 | var atEnd = false, value, hasValue = false;
|
10023 |
|
10024 | function sampleSubscribe() {
|
10025 | if (hasValue) {
|
10026 | hasValue = false;
|
10027 | o.onNext(value);
|
10028 | }
|
10029 | atEnd && o.onCompleted();
|
10030 | }
|
10031 |
|
10032 | var sourceSubscription = new SingleAssignmentDisposable();
|
10033 | sourceSubscription.setDisposable(source.subscribe(
|
10034 | function (newValue) {
|
10035 | hasValue = true;
|
10036 | value = newValue;
|
10037 | },
|
10038 | function (e) { o.onError(e); },
|
10039 | function () {
|
10040 | atEnd = true;
|
10041 | sourceSubscription.dispose();
|
10042 | }
|
10043 | ));
|
10044 |
|
10045 | return new BinaryDisposable(
|
10046 | sourceSubscription,
|
10047 | sampler.subscribe(sampleSubscribe, function (e) { o.onError(e); }, sampleSubscribe)
|
10048 | );
|
10049 | }, source);
|
10050 | }
|
10051 |
|
10052 | |
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 |
|
10060 |
|
10061 |
|
10062 |
|
10063 |
|
10064 | observableProto.sample = observableProto.throttleLatest = function (intervalOrSampler, scheduler) {
|
10065 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10066 | return typeof intervalOrSampler === 'number' ?
|
10067 | sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
|
10068 | sampleObservable(this, intervalOrSampler);
|
10069 | };
|
10070 |
|
10071 | var TimeoutError = Rx.TimeoutError = function(message) {
|
10072 | this.message = message || 'Timeout has occurred';
|
10073 | this.name = 'TimeoutError';
|
10074 | Error.call(this);
|
10075 | };
|
10076 | TimeoutError.prototype = Object.create(Error.prototype);
|
10077 |
|
10078 | function timeoutWithSelector(source, firstTimeout, timeoutDurationSelector, other) {
|
10079 | if (isFunction(firstTimeout)) {
|
10080 | other = timeoutDurationSelector;
|
10081 | timeoutDurationSelector = firstTimeout;
|
10082 | firstTimeout = observableNever();
|
10083 | }
|
10084 | Observable.isObservable(other) || (other = observableThrow(new TimeoutError()));
|
10085 | return new AnonymousObservable(function (o) {
|
10086 | var subscription = new SerialDisposable(),
|
10087 | timer = new SerialDisposable(),
|
10088 | original = new SingleAssignmentDisposable();
|
10089 |
|
10090 | subscription.setDisposable(original);
|
10091 |
|
10092 | var id = 0, switched = false;
|
10093 |
|
10094 | function setTimer(timeout) {
|
10095 | var myId = id, d = new SingleAssignmentDisposable();
|
10096 |
|
10097 | function timerWins() {
|
10098 | switched = (myId === id);
|
10099 | return switched;
|
10100 | }
|
10101 |
|
10102 | timer.setDisposable(d);
|
10103 | d.setDisposable(timeout.subscribe(function () {
|
10104 | timerWins() && subscription.setDisposable(other.subscribe(o));
|
10105 | d.dispose();
|
10106 | }, function (e) {
|
10107 | timerWins() && o.onError(e);
|
10108 | }, function () {
|
10109 | timerWins() && subscription.setDisposable(other.subscribe(o));
|
10110 | }));
|
10111 | };
|
10112 |
|
10113 | setTimer(firstTimeout);
|
10114 |
|
10115 | function oWins() {
|
10116 | var res = !switched;
|
10117 | if (res) { id++; }
|
10118 | return res;
|
10119 | }
|
10120 |
|
10121 | original.setDisposable(source.subscribe(function (x) {
|
10122 | if (oWins()) {
|
10123 | o.onNext(x);
|
10124 | var timeout = tryCatch(timeoutDurationSelector)(x);
|
10125 | if (timeout === errorObj) { return o.onError(timeout.e); }
|
10126 | setTimer(isPromise(timeout) ? observableFromPromise(timeout) : timeout);
|
10127 | }
|
10128 | }, function (e) {
|
10129 | oWins() && o.onError(e);
|
10130 | }, function () {
|
10131 | oWins() && o.onCompleted();
|
10132 | }));
|
10133 | return new BinaryDisposable(subscription, timer);
|
10134 | }, source);
|
10135 | }
|
10136 |
|
10137 | function timeout(source, dueTime, other, scheduler) {
|
10138 | if (isScheduler(other)) {
|
10139 | scheduler = other;
|
10140 | other = observableThrow(new TimeoutError());
|
10141 | }
|
10142 | if (other instanceof Error) { other = observableThrow(other); }
|
10143 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10144 | Observable.isObservable(other) || (other = observableThrow(new TimeoutError()));
|
10145 | return new AnonymousObservable(function (o) {
|
10146 | var id = 0,
|
10147 | original = new SingleAssignmentDisposable(),
|
10148 | subscription = new SerialDisposable(),
|
10149 | switched = false,
|
10150 | timer = new SerialDisposable();
|
10151 |
|
10152 | subscription.setDisposable(original);
|
10153 |
|
10154 | function createTimer() {
|
10155 | var myId = id;
|
10156 | timer.setDisposable(scheduler.scheduleFuture(null, dueTime, function () {
|
10157 | switched = id === myId;
|
10158 | if (switched) {
|
10159 | isPromise(other) && (other = observableFromPromise(other));
|
10160 | subscription.setDisposable(other.subscribe(o));
|
10161 | }
|
10162 | }));
|
10163 | }
|
10164 |
|
10165 | createTimer();
|
10166 |
|
10167 | original.setDisposable(source.subscribe(function (x) {
|
10168 | if (!switched) {
|
10169 | id++;
|
10170 | o.onNext(x);
|
10171 | createTimer();
|
10172 | }
|
10173 | }, function (e) {
|
10174 | if (!switched) {
|
10175 | id++;
|
10176 | o.onError(e);
|
10177 | }
|
10178 | }, function () {
|
10179 | if (!switched) {
|
10180 | id++;
|
10181 | o.onCompleted();
|
10182 | }
|
10183 | }));
|
10184 | return new BinaryDisposable(subscription, timer);
|
10185 | }, source);
|
10186 | }
|
10187 |
|
10188 | observableProto.timeout = function () {
|
10189 | var firstArg = arguments[0];
|
10190 | if (firstArg instanceof Date || typeof firstArg === 'number') {
|
10191 | return timeout(this, firstArg, arguments[1], arguments[2]);
|
10192 | } else if (Observable.isObservable(firstArg) || isFunction(firstArg)) {
|
10193 | return timeoutWithSelector(this, firstArg, arguments[1], arguments[2]);
|
10194 | } else {
|
10195 | throw new Error('Invalid arguments');
|
10196 | }
|
10197 | };
|
10198 |
|
10199 | var GenerateAbsoluteObservable = (function (__super__) {
|
10200 | inherits(GenerateAbsoluteObservable, __super__);
|
10201 | function GenerateAbsoluteObservable(state, cndFn, itrFn, resFn, timeFn, s) {
|
10202 | this._state = state;
|
10203 | this._cndFn = cndFn;
|
10204 | this._itrFn = itrFn;
|
10205 | this._resFn = resFn;
|
10206 | this._timeFn = timeFn;
|
10207 | this._s = s;
|
10208 | this._first = true;
|
10209 | this._hasResult = false;
|
10210 | __super__.call(this);
|
10211 | }
|
10212 |
|
10213 | function scheduleRecursive(self, recurse) {
|
10214 | self._hasResult && self._o.onNext(self._state);
|
10215 |
|
10216 | if (self._first) {
|
10217 | self._first = false;
|
10218 | } else {
|
10219 | self._state = tryCatch(self._itrFn)(self._state);
|
10220 | if (self._state === errorObj) { return self._o.onError(self._state.e); }
|
10221 | }
|
10222 | self._hasResult = tryCatch(self._cndFn)(self._state);
|
10223 | if (self._hasResult === errorObj) { return self._o.onError(self._hasResult.e); }
|
10224 | if (self._hasResult) {
|
10225 | var result = tryCatch(self._resFn)(self._state);
|
10226 | if (result === errorObj) { return self._o.onError(result.e); }
|
10227 | var time = tryCatch(self._timeFn)(self._state);
|
10228 | if (time === errorObj) { return self._o.onError(time.e); }
|
10229 | recurse(self, time);
|
10230 | } else {
|
10231 | self._o.onCompleted();
|
10232 | }
|
10233 | }
|
10234 |
|
10235 | GenerateAbsoluteObservable.prototype.subscribeCore = function (o) {
|
10236 | this._o = o;
|
10237 | return this._s.scheduleRecursiveFuture(this, new Date(this._s.now()), scheduleRecursive);
|
10238 | };
|
10239 |
|
10240 | return GenerateAbsoluteObservable;
|
10241 | }(ObservableBase));
|
10242 |
|
10243 | |
10244 |
|
10245 |
|
10246 |
|
10247 |
|
10248 |
|
10249 |
|
10250 |
|
10251 |
|
10252 |
|
10253 |
|
10254 |
|
10255 |
|
10256 |
|
10257 |
|
10258 |
|
10259 |
|
10260 |
|
10261 |
|
10262 | Observable.generateWithAbsoluteTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
10263 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10264 | return new GenerateAbsoluteObservable(initialState, condition, iterate, resultSelector, timeSelector, scheduler);
|
10265 | };
|
10266 |
|
10267 | var GenerateRelativeObservable = (function (__super__) {
|
10268 | inherits(GenerateRelativeObservable, __super__);
|
10269 | function GenerateRelativeObservable(state, cndFn, itrFn, resFn, timeFn, s) {
|
10270 | this._state = state;
|
10271 | this._cndFn = cndFn;
|
10272 | this._itrFn = itrFn;
|
10273 | this._resFn = resFn;
|
10274 | this._timeFn = timeFn;
|
10275 | this._s = s;
|
10276 | this._first = true;
|
10277 | this._hasResult = false;
|
10278 | __super__.call(this);
|
10279 | }
|
10280 |
|
10281 | function scheduleRecursive(self, recurse) {
|
10282 | self._hasResult && self._o.onNext(self._state);
|
10283 |
|
10284 | if (self._first) {
|
10285 | self._first = false;
|
10286 | } else {
|
10287 | self._state = tryCatch(self._itrFn)(self._state);
|
10288 | if (self._state === errorObj) { return self._o.onError(self._state.e); }
|
10289 | }
|
10290 | self._hasResult = tryCatch(self._cndFn)(self._state);
|
10291 | if (self._hasResult === errorObj) { return self._o.onError(self._hasResult.e); }
|
10292 | if (self._hasResult) {
|
10293 | var result = tryCatch(self._resFn)(self._state);
|
10294 | if (result === errorObj) { return self._o.onError(result.e); }
|
10295 | var time = tryCatch(self._timeFn)(self._state);
|
10296 | if (time === errorObj) { return self._o.onError(time.e); }
|
10297 | recurse(self, time);
|
10298 | } else {
|
10299 | self._o.onCompleted();
|
10300 | }
|
10301 | }
|
10302 |
|
10303 | GenerateRelativeObservable.prototype.subscribeCore = function (o) {
|
10304 | this._o = o;
|
10305 | return this._s.scheduleRecursiveFuture(this, 0, scheduleRecursive);
|
10306 | };
|
10307 |
|
10308 | return GenerateRelativeObservable;
|
10309 | }(ObservableBase));
|
10310 |
|
10311 | |
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 |
|
10319 |
|
10320 |
|
10321 |
|
10322 |
|
10323 |
|
10324 |
|
10325 |
|
10326 |
|
10327 |
|
10328 |
|
10329 |
|
10330 | Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
10331 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10332 | return new GenerateRelativeObservable(initialState, condition, iterate, resultSelector, timeSelector, scheduler);
|
10333 | };
|
10334 |
|
10335 | var DelaySubscription = (function(__super__) {
|
10336 | inherits(DelaySubscription, __super__);
|
10337 | function DelaySubscription(source, dt, s) {
|
10338 | this.source = source;
|
10339 | this._dt = dt;
|
10340 | this._s = s;
|
10341 | __super__.call(this);
|
10342 | }
|
10343 |
|
10344 | DelaySubscription.prototype.subscribeCore = function (o) {
|
10345 | var d = new SerialDisposable();
|
10346 |
|
10347 | d.setDisposable(this._s.scheduleFuture([this.source, o, d], this._dt, scheduleMethod));
|
10348 |
|
10349 | return d;
|
10350 | };
|
10351 |
|
10352 | function scheduleMethod(s, state) {
|
10353 | var source = state[0], o = state[1], d = state[2];
|
10354 | d.setDisposable(source.subscribe(o));
|
10355 | }
|
10356 |
|
10357 | return DelaySubscription;
|
10358 | }(ObservableBase));
|
10359 |
|
10360 | |
10361 |
|
10362 |
|
10363 |
|
10364 |
|
10365 |
|
10366 |
|
10367 |
|
10368 |
|
10369 |
|
10370 |
|
10371 | observableProto.delaySubscription = function (dueTime, scheduler) {
|
10372 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10373 | return new DelaySubscription(this, dueTime, scheduler);
|
10374 | };
|
10375 |
|
10376 | var SkipLastWithTimeObservable = (function (__super__) {
|
10377 | inherits(SkipLastWithTimeObservable, __super__);
|
10378 | function SkipLastWithTimeObservable(source, d, s) {
|
10379 | this.source = source;
|
10380 | this._d = d;
|
10381 | this._s = s;
|
10382 | __super__.call(this);
|
10383 | }
|
10384 |
|
10385 | SkipLastWithTimeObservable.prototype.subscribeCore = function (o) {
|
10386 | return this.source.subscribe(new SkipLastWithTimeObserver(o, this));
|
10387 | };
|
10388 |
|
10389 | return SkipLastWithTimeObservable;
|
10390 | }(ObservableBase));
|
10391 |
|
10392 | var SkipLastWithTimeObserver = (function (__super__) {
|
10393 | inherits(SkipLastWithTimeObserver, __super__);
|
10394 |
|
10395 | function SkipLastWithTimeObserver(o, p) {
|
10396 | this._o = o;
|
10397 | this._s = p._s;
|
10398 | this._d = p._d;
|
10399 | this._q = [];
|
10400 | __super__.call(this);
|
10401 | }
|
10402 |
|
10403 | SkipLastWithTimeObserver.prototype.next = function (x) {
|
10404 | var now = this._s.now();
|
10405 | this._q.push({ interval: now, value: x });
|
10406 | while (this._q.length > 0 && now - this._q[0].interval >= this._d) {
|
10407 | this._o.onNext(this._q.shift().value);
|
10408 | }
|
10409 | };
|
10410 | SkipLastWithTimeObserver.prototype.error = function (e) { this._o.onError(e); };
|
10411 | SkipLastWithTimeObserver.prototype.completed = function () {
|
10412 | var now = this._s.now();
|
10413 | while (this._q.length > 0 && now - this._q[0].interval >= this._d) {
|
10414 | this._o.onNext(this._q.shift().value);
|
10415 | }
|
10416 | this._o.onCompleted();
|
10417 | };
|
10418 |
|
10419 | return SkipLastWithTimeObserver;
|
10420 | }(AbstractObserver));
|
10421 |
|
10422 | |
10423 |
|
10424 |
|
10425 |
|
10426 |
|
10427 |
|
10428 |
|
10429 |
|
10430 |
|
10431 |
|
10432 | observableProto.skipLastWithTime = function (duration, scheduler) {
|
10433 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10434 | return new SkipLastWithTimeObservable(this, duration, scheduler);
|
10435 | };
|
10436 |
|
10437 | var TakeLastWithTimeObservable = (function (__super__) {
|
10438 | inherits(TakeLastWithTimeObservable, __super__);
|
10439 | function TakeLastWithTimeObservable(source, d, s) {
|
10440 | this.source = source;
|
10441 | this._d = d;
|
10442 | this._s = s;
|
10443 | __super__.call(this);
|
10444 | }
|
10445 |
|
10446 | TakeLastWithTimeObservable.prototype.subscribeCore = function (o) {
|
10447 | return this.source.subscribe(new TakeLastWithTimeObserver(o, this._d, this._s));
|
10448 | };
|
10449 |
|
10450 | return TakeLastWithTimeObservable;
|
10451 | }(ObservableBase));
|
10452 |
|
10453 | var TakeLastWithTimeObserver = (function (__super__) {
|
10454 | inherits(TakeLastWithTimeObserver, __super__);
|
10455 |
|
10456 | function TakeLastWithTimeObserver(o, d, s) {
|
10457 | this._o = o;
|
10458 | this._d = d;
|
10459 | this._s = s;
|
10460 | this._q = [];
|
10461 | __super__.call(this);
|
10462 | }
|
10463 |
|
10464 | TakeLastWithTimeObserver.prototype.next = function (x) {
|
10465 | var now = this._s.now();
|
10466 | this._q.push({ interval: now, value: x });
|
10467 | while (this._q.length > 0 && now - this._q[0].interval >= this._d) {
|
10468 | this._q.shift();
|
10469 | }
|
10470 | };
|
10471 | TakeLastWithTimeObserver.prototype.error = function (e) { this._o.onError(e); };
|
10472 | TakeLastWithTimeObserver.prototype.completed = function () {
|
10473 | var now = this._s.now();
|
10474 | while (this._q.length > 0) {
|
10475 | var next = this._q.shift();
|
10476 | if (now - next.interval <= this._d) { this._o.onNext(next.value); }
|
10477 | }
|
10478 | this._o.onCompleted();
|
10479 | };
|
10480 |
|
10481 | return TakeLastWithTimeObserver;
|
10482 | }(AbstractObserver));
|
10483 |
|
10484 | |
10485 |
|
10486 |
|
10487 |
|
10488 |
|
10489 |
|
10490 |
|
10491 |
|
10492 |
|
10493 |
|
10494 | observableProto.takeLastWithTime = function (duration, scheduler) {
|
10495 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10496 | return new TakeLastWithTimeObservable(this, duration, scheduler);
|
10497 | };
|
10498 |
|
10499 | |
10500 |
|
10501 |
|
10502 |
|
10503 |
|
10504 |
|
10505 |
|
10506 |
|
10507 |
|
10508 |
|
10509 | observableProto.takeLastBufferWithTime = function (duration, scheduler) {
|
10510 | var source = this;
|
10511 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10512 | return new AnonymousObservable(function (o) {
|
10513 | var q = [];
|
10514 | return source.subscribe(function (x) {
|
10515 | var now = scheduler.now();
|
10516 | q.push({ interval: now, value: x });
|
10517 | while (q.length > 0 && now - q[0].interval >= duration) {
|
10518 | q.shift();
|
10519 | }
|
10520 | }, function (e) { o.onError(e); }, function () {
|
10521 | var now = scheduler.now(), res = [];
|
10522 | while (q.length > 0) {
|
10523 | var next = q.shift();
|
10524 | now - next.interval <= duration && res.push(next.value);
|
10525 | }
|
10526 | o.onNext(res);
|
10527 | o.onCompleted();
|
10528 | });
|
10529 | }, source);
|
10530 | };
|
10531 |
|
10532 | var TakeWithTimeObservable = (function (__super__) {
|
10533 | inherits(TakeWithTimeObservable, __super__);
|
10534 | function TakeWithTimeObservable(source, d, s) {
|
10535 | this.source = source;
|
10536 | this._d = d;
|
10537 | this._s = s;
|
10538 | __super__.call(this);
|
10539 | }
|
10540 |
|
10541 | function scheduleMethod(s, o) {
|
10542 | o.onCompleted();
|
10543 | }
|
10544 |
|
10545 | TakeWithTimeObservable.prototype.subscribeCore = function (o) {
|
10546 | return new BinaryDisposable(
|
10547 | this._s.scheduleFuture(o, this._d, scheduleMethod),
|
10548 | this.source.subscribe(o)
|
10549 | );
|
10550 | };
|
10551 |
|
10552 | return TakeWithTimeObservable;
|
10553 | }(ObservableBase));
|
10554 |
|
10555 | |
10556 |
|
10557 |
|
10558 |
|
10559 |
|
10560 |
|
10561 |
|
10562 |
|
10563 |
|
10564 |
|
10565 |
|
10566 |
|
10567 |
|
10568 | observableProto.takeWithTime = function (duration, scheduler) {
|
10569 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10570 | return new TakeWithTimeObservable(this, duration, scheduler);
|
10571 | };
|
10572 |
|
10573 | var SkipWithTimeObservable = (function (__super__) {
|
10574 | inherits(SkipWithTimeObservable, __super__);
|
10575 | function SkipWithTimeObservable(source, d, s) {
|
10576 | this.source = source;
|
10577 | this._d = d;
|
10578 | this._s = s;
|
10579 | this._open = false;
|
10580 | __super__.call(this);
|
10581 | }
|
10582 |
|
10583 | function scheduleMethod(s, self) {
|
10584 | self._open = true;
|
10585 | }
|
10586 |
|
10587 | SkipWithTimeObservable.prototype.subscribeCore = function (o) {
|
10588 | return new BinaryDisposable(
|
10589 | this._s.scheduleFuture(this, this._d, scheduleMethod),
|
10590 | this.source.subscribe(new SkipWithTimeObserver(o, this))
|
10591 | );
|
10592 | };
|
10593 |
|
10594 | return SkipWithTimeObservable;
|
10595 | }(ObservableBase));
|
10596 |
|
10597 | var SkipWithTimeObserver = (function (__super__) {
|
10598 | inherits(SkipWithTimeObserver, __super__);
|
10599 |
|
10600 | function SkipWithTimeObserver(o, p) {
|
10601 | this._o = o;
|
10602 | this._p = p;
|
10603 | __super__.call(this);
|
10604 | }
|
10605 |
|
10606 | SkipWithTimeObserver.prototype.next = function (x) { this._p._open && this._o.onNext(x); };
|
10607 | SkipWithTimeObserver.prototype.error = function (e) { this._o.onError(e); };
|
10608 | SkipWithTimeObserver.prototype.completed = function () { this._o.onCompleted(); };
|
10609 |
|
10610 | return SkipWithTimeObserver;
|
10611 | }(AbstractObserver));
|
10612 |
|
10613 | |
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 |
|
10622 |
|
10623 |
|
10624 |
|
10625 | observableProto.skipWithTime = function (duration, scheduler) {
|
10626 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10627 | return new SkipWithTimeObservable(this, duration, scheduler);
|
10628 | };
|
10629 |
|
10630 | var SkipUntilWithTimeObservable = (function (__super__) {
|
10631 | inherits(SkipUntilWithTimeObservable, __super__);
|
10632 | function SkipUntilWithTimeObservable(source, startTime, scheduler) {
|
10633 | this.source = source;
|
10634 | this._st = startTime;
|
10635 | this._s = scheduler;
|
10636 | __super__.call(this);
|
10637 | }
|
10638 |
|
10639 | function scheduleMethod(s, state) {
|
10640 | state._open = true;
|
10641 | }
|
10642 |
|
10643 | SkipUntilWithTimeObservable.prototype.subscribeCore = function (o) {
|
10644 | this._open = false;
|
10645 | return new BinaryDisposable(
|
10646 | this._s.scheduleFuture(this, this._st, scheduleMethod),
|
10647 | this.source.subscribe(new SkipUntilWithTimeObserver(o, this))
|
10648 | );
|
10649 | };
|
10650 |
|
10651 | return SkipUntilWithTimeObservable;
|
10652 | }(ObservableBase));
|
10653 |
|
10654 | var SkipUntilWithTimeObserver = (function (__super__) {
|
10655 | inherits(SkipUntilWithTimeObserver, __super__);
|
10656 |
|
10657 | function SkipUntilWithTimeObserver(o, p) {
|
10658 | this._o = o;
|
10659 | this._p = p;
|
10660 | __super__.call(this);
|
10661 | }
|
10662 |
|
10663 | SkipUntilWithTimeObserver.prototype.next = function (x) { this._p._open && this._o.onNext(x); };
|
10664 | SkipUntilWithTimeObserver.prototype.error = function (e) { this._o.onError(e); };
|
10665 | SkipUntilWithTimeObserver.prototype.completed = function () { this._o.onCompleted(); };
|
10666 |
|
10667 | return SkipUntilWithTimeObserver;
|
10668 | }(AbstractObserver));
|
10669 |
|
10670 |
|
10671 | |
10672 |
|
10673 |
|
10674 |
|
10675 |
|
10676 |
|
10677 |
|
10678 |
|
10679 |
|
10680 |
|
10681 |
|
10682 | observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
10683 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10684 | return new SkipUntilWithTimeObservable(this, startTime, scheduler);
|
10685 | };
|
10686 |
|
10687 | |
10688 |
|
10689 |
|
10690 |
|
10691 |
|
10692 |
|
10693 | observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
10694 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10695 | var source = this;
|
10696 | return new AnonymousObservable(function (o) {
|
10697 | return new BinaryDisposable(
|
10698 | scheduler.scheduleFuture(o, endTime, function (_, o) { o.onCompleted(); }),
|
10699 | source.subscribe(o));
|
10700 | }, source);
|
10701 | };
|
10702 |
|
10703 | |
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 |
|
10709 | observableProto.throttle = function (windowDuration, scheduler) {
|
10710 | isScheduler(scheduler) || (scheduler = defaultScheduler);
|
10711 | var duration = +windowDuration || 0;
|
10712 | if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
|
10713 | var source = this;
|
10714 | return new AnonymousObservable(function (o) {
|
10715 | var lastOnNext = 0;
|
10716 | return source.subscribe(
|
10717 | function (x) {
|
10718 | var now = scheduler.now();
|
10719 | if (lastOnNext === 0 || now - lastOnNext >= duration) {
|
10720 | lastOnNext = now;
|
10721 | o.onNext(x);
|
10722 | }
|
10723 | },function (e) { o.onError(e); }, function () { o.onCompleted(); }
|
10724 | );
|
10725 | }, source);
|
10726 | };
|
10727 |
|
10728 | var TransduceObserver = (function (__super__) {
|
10729 | inherits(TransduceObserver, __super__);
|
10730 | function TransduceObserver(o, xform) {
|
10731 | this._o = o;
|
10732 | this._xform = xform;
|
10733 | __super__.call(this);
|
10734 | }
|
10735 |
|
10736 | TransduceObserver.prototype.next = function (x) {
|
10737 | var res = tryCatch(this._xform['@@transducer/step']).call(this._xform, this._o, x);
|
10738 | if (res === errorObj) { this._o.onError(res.e); }
|
10739 | };
|
10740 |
|
10741 | TransduceObserver.prototype.error = function (e) { this._o.onError(e); };
|
10742 |
|
10743 | TransduceObserver.prototype.completed = function () {
|
10744 | this._xform['@@transducer/result'](this._o);
|
10745 | };
|
10746 |
|
10747 | return TransduceObserver;
|
10748 | }(AbstractObserver));
|
10749 |
|
10750 | function transformForObserver(o) {
|
10751 | return {
|
10752 | '@@transducer/init': function() {
|
10753 | return o;
|
10754 | },
|
10755 | '@@transducer/step': function(obs, input) {
|
10756 | return obs.onNext(input);
|
10757 | },
|
10758 | '@@transducer/result': function(obs) {
|
10759 | return obs.onCompleted();
|
10760 | }
|
10761 | };
|
10762 | }
|
10763 |
|
10764 | |
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 | observableProto.transduce = function(transducer) {
|
10770 | var source = this;
|
10771 | return new AnonymousObservable(function(o) {
|
10772 | var xform = transducer(transformForObserver(o));
|
10773 | return source.subscribe(new TransduceObserver(o, xform));
|
10774 | }, source);
|
10775 | };
|
10776 |
|
10777 | var SwitchFirstObservable = (function (__super__) {
|
10778 | inherits(SwitchFirstObservable, __super__);
|
10779 | function SwitchFirstObservable(source) {
|
10780 | this.source = source;
|
10781 | __super__.call(this);
|
10782 | }
|
10783 |
|
10784 | SwitchFirstObservable.prototype.subscribeCore = function (o) {
|
10785 | var m = new SingleAssignmentDisposable(),
|
10786 | g = new CompositeDisposable(),
|
10787 | state = {
|
10788 | hasCurrent: false,
|
10789 | isStopped: false,
|
10790 | o: o,
|
10791 | g: g
|
10792 | };
|
10793 |
|
10794 | g.add(m);
|
10795 | m.setDisposable(this.source.subscribe(new SwitchFirstObserver(state)));
|
10796 | return g;
|
10797 | };
|
10798 |
|
10799 | return SwitchFirstObservable;
|
10800 | }(ObservableBase));
|
10801 |
|
10802 | var SwitchFirstObserver = (function(__super__) {
|
10803 | inherits(SwitchFirstObserver, __super__);
|
10804 | function SwitchFirstObserver(state) {
|
10805 | this._s = state;
|
10806 | __super__.call(this);
|
10807 | }
|
10808 |
|
10809 | SwitchFirstObserver.prototype.next = function (x) {
|
10810 | if (!this._s.hasCurrent) {
|
10811 | this._s.hasCurrent = true;
|
10812 | isPromise(x) && (x = observableFromPromise(x));
|
10813 | var inner = new SingleAssignmentDisposable();
|
10814 | this._s.g.add(inner);
|
10815 | inner.setDisposable(x.subscribe(new InnerObserver(this._s, inner)));
|
10816 | }
|
10817 | };
|
10818 |
|
10819 | SwitchFirstObserver.prototype.error = function (e) {
|
10820 | this._s.o.onError(e);
|
10821 | };
|
10822 |
|
10823 | SwitchFirstObserver.prototype.completed = function () {
|
10824 | this._s.isStopped = true;
|
10825 | !this._s.hasCurrent && this._s.g.length === 1 && this._s.o.onCompleted();
|
10826 | };
|
10827 |
|
10828 | inherits(InnerObserver, __super__);
|
10829 | function InnerObserver(state, inner) {
|
10830 | this._s = state;
|
10831 | this._i = inner;
|
10832 | __super__.call(this);
|
10833 | }
|
10834 |
|
10835 | InnerObserver.prototype.next = function (x) { this._s.o.onNext(x); };
|
10836 | InnerObserver.prototype.error = function (e) { this._s.o.onError(e); };
|
10837 | InnerObserver.prototype.completed = function () {
|
10838 | this._s.g.remove(this._i);
|
10839 | this._s.hasCurrent = false;
|
10840 | this._s.isStopped && this._s.g.length === 1 && this._s.o.onCompleted();
|
10841 | };
|
10842 |
|
10843 | return SwitchFirstObserver;
|
10844 | }(AbstractObserver));
|
10845 |
|
10846 | |
10847 |
|
10848 |
|
10849 |
|
10850 |
|
10851 | observableProto.switchFirst = function () {
|
10852 | return new SwitchFirstObservable(this);
|
10853 | };
|
10854 |
|
10855 | observableProto.flatMapFirst = observableProto.selectManyFirst = function(selector, resultSelector, thisArg) {
|
10856 | return new FlatMapObservable(this, selector, resultSelector, thisArg).switchFirst();
|
10857 | };
|
10858 |
|
10859 | Rx.Observable.prototype.flatMapWithMaxConcurrent = function(limit, selector, resultSelector, thisArg) {
|
10860 | return new FlatMapObservable(this, selector, resultSelector, thisArg).merge(limit);
|
10861 | };
|
10862 |
|
10863 | var VirtualTimeScheduler = Rx.VirtualTimeScheduler = (function (__super__) {
|
10864 | inherits(VirtualTimeScheduler, __super__);
|
10865 |
|
10866 | |
10867 |
|
10868 |
|
10869 |
|
10870 |
|
10871 |
|
10872 |
|
10873 | function VirtualTimeScheduler(initialClock, comparer) {
|
10874 | this.clock = initialClock;
|
10875 | this.comparer = comparer;
|
10876 | this.isEnabled = false;
|
10877 | this.queue = new PriorityQueue(1024);
|
10878 | __super__.call(this);
|
10879 | }
|
10880 |
|
10881 | var VirtualTimeSchedulerPrototype = VirtualTimeScheduler.prototype;
|
10882 |
|
10883 | VirtualTimeSchedulerPrototype.now = function () {
|
10884 | return this.toAbsoluteTime(this.clock);
|
10885 | };
|
10886 |
|
10887 | VirtualTimeSchedulerPrototype.schedule = function (state, action) {
|
10888 | return this.scheduleAbsolute(state, this.clock, action);
|
10889 | };
|
10890 |
|
10891 | VirtualTimeSchedulerPrototype.scheduleFuture = function (state, dueTime, action) {
|
10892 | var dt = dueTime instanceof Date ?
|
10893 | this.toRelativeTime(dueTime - this.now()) :
|
10894 | this.toRelativeTime(dueTime);
|
10895 |
|
10896 | return this.scheduleRelative(state, dt, action);
|
10897 | };
|
10898 |
|
10899 | |
10900 |
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 | VirtualTimeSchedulerPrototype.add = notImplemented;
|
10906 |
|
10907 | |
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 | VirtualTimeSchedulerPrototype.toAbsoluteTime = notImplemented;
|
10913 |
|
10914 | |
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 | VirtualTimeSchedulerPrototype.toRelativeTime = notImplemented;
|
10920 |
|
10921 | |
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 |
|
10928 | VirtualTimeSchedulerPrototype.schedulePeriodic = function (state, period, action) {
|
10929 | var s = new SchedulePeriodicRecursive(this, state, period, action);
|
10930 | return s.start();
|
10931 | };
|
10932 |
|
10933 | |
10934 |
|
10935 |
|
10936 |
|
10937 |
|
10938 |
|
10939 |
|
10940 | VirtualTimeSchedulerPrototype.scheduleRelative = function (state, dueTime, action) {
|
10941 | var runAt = this.add(this.clock, dueTime);
|
10942 | return this.scheduleAbsolute(state, runAt, action);
|
10943 | };
|
10944 |
|
10945 | |
10946 |
|
10947 |
|
10948 | VirtualTimeSchedulerPrototype.start = function () {
|
10949 | if (!this.isEnabled) {
|
10950 | this.isEnabled = true;
|
10951 | do {
|
10952 | var next = this.getNext();
|
10953 | if (next !== null) {
|
10954 | this.comparer(next.dueTime, this.clock) > 0 && (this.clock = next.dueTime);
|
10955 | next.invoke();
|
10956 | } else {
|
10957 | this.isEnabled = false;
|
10958 | }
|
10959 | } while (this.isEnabled);
|
10960 | }
|
10961 | };
|
10962 |
|
10963 | |
10964 |
|
10965 |
|
10966 | VirtualTimeSchedulerPrototype.stop = function () {
|
10967 | this.isEnabled = false;
|
10968 | };
|
10969 |
|
10970 | |
10971 |
|
10972 |
|
10973 |
|
10974 | VirtualTimeSchedulerPrototype.advanceTo = function (time) {
|
10975 | var dueToClock = this.comparer(this.clock, time);
|
10976 | if (this.comparer(this.clock, time) > 0) { throw new ArgumentOutOfRangeError(); }
|
10977 | if (dueToClock === 0) { return; }
|
10978 | if (!this.isEnabled) {
|
10979 | this.isEnabled = true;
|
10980 | do {
|
10981 | var next = this.getNext();
|
10982 | if (next !== null && this.comparer(next.dueTime, time) <= 0) {
|
10983 | this.comparer(next.dueTime, this.clock) > 0 && (this.clock = next.dueTime);
|
10984 | next.invoke();
|
10985 | } else {
|
10986 | this.isEnabled = false;
|
10987 | }
|
10988 | } while (this.isEnabled);
|
10989 | this.clock = time;
|
10990 | }
|
10991 | };
|
10992 |
|
10993 | |
10994 |
|
10995 |
|
10996 |
|
10997 | VirtualTimeSchedulerPrototype.advanceBy = function (time) {
|
10998 | var dt = this.add(this.clock, time),
|
10999 | dueToClock = this.comparer(this.clock, dt);
|
11000 | if (dueToClock > 0) { throw new ArgumentOutOfRangeError(); }
|
11001 | if (dueToClock === 0) { return; }
|
11002 |
|
11003 | this.advanceTo(dt);
|
11004 | };
|
11005 |
|
11006 | |
11007 |
|
11008 |
|
11009 |
|
11010 | VirtualTimeSchedulerPrototype.sleep = function (time) {
|
11011 | var dt = this.add(this.clock, time);
|
11012 | if (this.comparer(this.clock, dt) >= 0) { throw new ArgumentOutOfRangeError(); }
|
11013 |
|
11014 | this.clock = dt;
|
11015 | };
|
11016 |
|
11017 | |
11018 |
|
11019 |
|
11020 |
|
11021 | VirtualTimeSchedulerPrototype.getNext = function () {
|
11022 | while (this.queue.length > 0) {
|
11023 | var next = this.queue.peek();
|
11024 | if (next.isCancelled()) {
|
11025 | this.queue.dequeue();
|
11026 | } else {
|
11027 | return next;
|
11028 | }
|
11029 | }
|
11030 | return null;
|
11031 | };
|
11032 |
|
11033 | |
11034 |
|
11035 |
|
11036 |
|
11037 |
|
11038 |
|
11039 |
|
11040 | VirtualTimeSchedulerPrototype.scheduleAbsolute = function (state, dueTime, action) {
|
11041 | var self = this;
|
11042 |
|
11043 | function run(scheduler, state1) {
|
11044 | self.queue.remove(si);
|
11045 | return action(scheduler, state1);
|
11046 | }
|
11047 |
|
11048 | var si = new ScheduledItem(this, state, run, dueTime, this.comparer);
|
11049 | this.queue.enqueue(si);
|
11050 |
|
11051 | return si.disposable;
|
11052 | };
|
11053 |
|
11054 | return VirtualTimeScheduler;
|
11055 | }(Scheduler));
|
11056 |
|
11057 |
|
11058 | Rx.HistoricalScheduler = (function (__super__) {
|
11059 | inherits(HistoricalScheduler, __super__);
|
11060 |
|
11061 | |
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 | function HistoricalScheduler(initialClock, comparer) {
|
11068 | var clock = initialClock == null ? 0 : initialClock;
|
11069 | var cmp = comparer || defaultSubComparer;
|
11070 | __super__.call(this, clock, cmp);
|
11071 | }
|
11072 |
|
11073 | var HistoricalSchedulerProto = HistoricalScheduler.prototype;
|
11074 |
|
11075 | |
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 | HistoricalSchedulerProto.add = function (absolute, relative) {
|
11082 | return absolute + relative;
|
11083 | };
|
11084 |
|
11085 | HistoricalSchedulerProto.toAbsoluteTime = function (absolute) {
|
11086 | return new Date(absolute).getTime();
|
11087 | };
|
11088 |
|
11089 | |
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 |
|
11095 | HistoricalSchedulerProto.toRelativeTime = function (timeSpan) {
|
11096 | return timeSpan;
|
11097 | };
|
11098 |
|
11099 | return HistoricalScheduler;
|
11100 | }(Rx.VirtualTimeScheduler));
|
11101 |
|
11102 | function OnNextPredicate(predicate) {
|
11103 | this.predicate = predicate;
|
11104 | }
|
11105 |
|
11106 | OnNextPredicate.prototype.equals = function (other) {
|
11107 | if (other === this) { return true; }
|
11108 | if (other == null) { return false; }
|
11109 | if (other.kind !== 'N') { return false; }
|
11110 | return this.predicate(other.value);
|
11111 | };
|
11112 |
|
11113 | function OnErrorPredicate(predicate) {
|
11114 | this.predicate = predicate;
|
11115 | }
|
11116 |
|
11117 | OnErrorPredicate.prototype.equals = function (other) {
|
11118 | if (other === this) { return true; }
|
11119 | if (other == null) { return false; }
|
11120 | if (other.kind !== 'E') { return false; }
|
11121 | return this.predicate(other.error);
|
11122 | };
|
11123 |
|
11124 | var ReactiveTest = Rx.ReactiveTest = {
|
11125 |
|
11126 | created: 100,
|
11127 |
|
11128 | subscribed: 200,
|
11129 |
|
11130 | disposed: 1000,
|
11131 |
|
11132 | |
11133 |
|
11134 |
|
11135 |
|
11136 |
|
11137 |
|
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 | onNext: function (ticks, value) {
|
11143 | return typeof value === 'function' ?
|
11144 | new Recorded(ticks, new OnNextPredicate(value)) :
|
11145 | new Recorded(ticks, Notification.createOnNext(value));
|
11146 | },
|
11147 | |
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 |
|
11157 | onError: function (ticks, error) {
|
11158 | return typeof error === 'function' ?
|
11159 | new Recorded(ticks, new OnErrorPredicate(error)) :
|
11160 | new Recorded(ticks, Notification.createOnError(error));
|
11161 | },
|
11162 | |
11163 |
|
11164 |
|
11165 |
|
11166 |
|
11167 |
|
11168 | onCompleted: function (ticks) {
|
11169 | return new Recorded(ticks, Notification.createOnCompleted());
|
11170 | },
|
11171 | |
11172 |
|
11173 |
|
11174 |
|
11175 |
|
11176 |
|
11177 |
|
11178 | subscribe: function (start, end) {
|
11179 | return new Subscription(start, end);
|
11180 | }
|
11181 | };
|
11182 |
|
11183 | |
11184 |
|
11185 |
|
11186 |
|
11187 |
|
11188 |
|
11189 |
|
11190 |
|
11191 | var Recorded = Rx.Recorded = function (time, value, comparer) {
|
11192 | this.time = time;
|
11193 | this.value = value;
|
11194 | this.comparer = comparer || defaultComparer;
|
11195 | };
|
11196 |
|
11197 | |
11198 |
|
11199 |
|
11200 |
|
11201 |
|
11202 |
|
11203 | Recorded.prototype.equals = function (other) {
|
11204 | return this.time === other.time && this.comparer(this.value, other.value);
|
11205 | };
|
11206 |
|
11207 | |
11208 |
|
11209 |
|
11210 |
|
11211 |
|
11212 | Recorded.prototype.toString = function () {
|
11213 | return this.value.toString() + '@' + this.time;
|
11214 | };
|
11215 |
|
11216 | |
11217 |
|
11218 |
|
11219 |
|
11220 |
|
11221 |
|
11222 |
|
11223 | var Subscription = Rx.Subscription = function (start, end) {
|
11224 | this.subscribe = start;
|
11225 | this.unsubscribe = end || Number.MAX_VALUE;
|
11226 | };
|
11227 |
|
11228 | |
11229 |
|
11230 |
|
11231 |
|
11232 |
|
11233 | Subscription.prototype.equals = function (other) {
|
11234 | return this.subscribe === other.subscribe && this.unsubscribe === other.unsubscribe;
|
11235 | };
|
11236 |
|
11237 | |
11238 |
|
11239 |
|
11240 |
|
11241 | Subscription.prototype.toString = function () {
|
11242 | return '(' + this.subscribe + ', ' + (this.unsubscribe === Number.MAX_VALUE ? 'Infinite' : this.unsubscribe) + ')';
|
11243 | };
|
11244 |
|
11245 | var MockDisposable = Rx.MockDisposable = function (scheduler) {
|
11246 | this.scheduler = scheduler;
|
11247 | this.disposes = [];
|
11248 | this.disposes.push(this.scheduler.clock);
|
11249 | };
|
11250 |
|
11251 | MockDisposable.prototype.dispose = function () {
|
11252 | this.disposes.push(this.scheduler.clock);
|
11253 | };
|
11254 |
|
11255 | var MockObserver = (function (__super__) {
|
11256 | inherits(MockObserver, __super__);
|
11257 |
|
11258 | function MockObserver(scheduler) {
|
11259 | __super__.call(this);
|
11260 | this.scheduler = scheduler;
|
11261 | this.messages = [];
|
11262 | }
|
11263 |
|
11264 | var MockObserverPrototype = MockObserver.prototype;
|
11265 |
|
11266 | MockObserverPrototype.onNext = function (value) {
|
11267 | this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnNext(value)));
|
11268 | };
|
11269 |
|
11270 | MockObserverPrototype.onError = function (e) {
|
11271 | this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnError(e)));
|
11272 | };
|
11273 |
|
11274 | MockObserverPrototype.onCompleted = function () {
|
11275 | this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnCompleted()));
|
11276 | };
|
11277 |
|
11278 | return MockObserver;
|
11279 | })(Observer);
|
11280 |
|
11281 | function MockPromise(scheduler, messages) {
|
11282 | var self = this;
|
11283 | this.scheduler = scheduler;
|
11284 | this.messages = messages;
|
11285 | this.subscriptions = [];
|
11286 | this.observers = [];
|
11287 | for (var i = 0, len = this.messages.length; i < len; i++) {
|
11288 | var message = this.messages[i],
|
11289 | notification = message.value;
|
11290 | (function (innerNotification) {
|
11291 | scheduler.scheduleAbsolute(null, message.time, function () {
|
11292 | var obs = self.observers.slice(0);
|
11293 |
|
11294 | for (var j = 0, jLen = obs.length; j < jLen; j++) {
|
11295 | innerNotification.accept(obs[j]);
|
11296 | }
|
11297 | return disposableEmpty;
|
11298 | });
|
11299 | })(notification);
|
11300 | }
|
11301 | }
|
11302 |
|
11303 | MockPromise.prototype.then = function (onResolved, onRejected) {
|
11304 | var self = this;
|
11305 |
|
11306 | this.subscriptions.push(new Subscription(this.scheduler.clock));
|
11307 | var index = this.subscriptions.length - 1;
|
11308 |
|
11309 | var newPromise;
|
11310 |
|
11311 | var observer = Rx.Observer.create(
|
11312 | function (x) {
|
11313 | var retValue = onResolved(x);
|
11314 | if (retValue && typeof retValue.then === 'function') {
|
11315 | newPromise = retValue;
|
11316 | } else {
|
11317 | var ticks = self.scheduler.clock;
|
11318 | newPromise = new MockPromise(self.scheduler, [Rx.ReactiveTest.onNext(ticks, undefined), Rx.ReactiveTest.onCompleted(ticks)]);
|
11319 | }
|
11320 | var idx = self.observers.indexOf(observer);
|
11321 | self.observers.splice(idx, 1);
|
11322 | self.subscriptions[index] = new Subscription(self.subscriptions[index].subscribe, self.scheduler.clock);
|
11323 | },
|
11324 | function (err) {
|
11325 | onRejected(err);
|
11326 | var idx = self.observers.indexOf(observer);
|
11327 | self.observers.splice(idx, 1);
|
11328 | self.subscriptions[index] = new Subscription(self.subscriptions[index].subscribe, self.scheduler.clock);
|
11329 | }
|
11330 | );
|
11331 | this.observers.push(observer);
|
11332 |
|
11333 | return newPromise || new MockPromise(this.scheduler, this.messages);
|
11334 | };
|
11335 |
|
11336 | var HotObservable = (function (__super__) {
|
11337 | inherits(HotObservable, __super__);
|
11338 |
|
11339 | function HotObservable(scheduler, messages) {
|
11340 | __super__.call(this);
|
11341 | var message, notification, observable = this;
|
11342 | this.scheduler = scheduler;
|
11343 | this.messages = messages;
|
11344 | this.subscriptions = [];
|
11345 | this.observers = [];
|
11346 | for (var i = 0, len = this.messages.length; i < len; i++) {
|
11347 | message = this.messages[i];
|
11348 | notification = message.value;
|
11349 | (function (innerNotification) {
|
11350 | scheduler.scheduleAbsolute(null, message.time, function () {
|
11351 | var obs = observable.observers.slice(0);
|
11352 |
|
11353 | for (var j = 0, jLen = obs.length; j < jLen; j++) {
|
11354 | innerNotification.accept(obs[j]);
|
11355 | }
|
11356 | return disposableEmpty;
|
11357 | });
|
11358 | })(notification);
|
11359 | }
|
11360 | }
|
11361 |
|
11362 | HotObservable.prototype._subscribe = function (o) {
|
11363 | var observable = this;
|
11364 | this.observers.push(o);
|
11365 | this.subscriptions.push(new Subscription(this.scheduler.clock));
|
11366 | var index = this.subscriptions.length - 1;
|
11367 | return disposableCreate(function () {
|
11368 | var idx = observable.observers.indexOf(o);
|
11369 | observable.observers.splice(idx, 1);
|
11370 | observable.subscriptions[index] = new Subscription(observable.subscriptions[index].subscribe, observable.scheduler.clock);
|
11371 | });
|
11372 | };
|
11373 |
|
11374 | return HotObservable;
|
11375 | })(Observable);
|
11376 |
|
11377 | var ColdObservable = (function (__super__) {
|
11378 | inherits(ColdObservable, __super__);
|
11379 |
|
11380 | function ColdObservable(scheduler, messages) {
|
11381 | __super__.call(this);
|
11382 | this.scheduler = scheduler;
|
11383 | this.messages = messages;
|
11384 | this.subscriptions = [];
|
11385 | }
|
11386 |
|
11387 | ColdObservable.prototype._subscribe = function (o) {
|
11388 | var message, notification, observable = this;
|
11389 | this.subscriptions.push(new Subscription(this.scheduler.clock));
|
11390 | var index = this.subscriptions.length - 1;
|
11391 | var d = new CompositeDisposable();
|
11392 | for (var i = 0, len = this.messages.length; i < len; i++) {
|
11393 | message = this.messages[i];
|
11394 | notification = message.value;
|
11395 | (function (innerNotification) {
|
11396 | d.add(observable.scheduler.scheduleRelative(null, message.time, function () {
|
11397 | innerNotification.accept(o);
|
11398 | return disposableEmpty;
|
11399 | }));
|
11400 | })(notification);
|
11401 | }
|
11402 | return disposableCreate(function () {
|
11403 | observable.subscriptions[index] = new Subscription(observable.subscriptions[index].subscribe, observable.scheduler.clock);
|
11404 | d.dispose();
|
11405 | });
|
11406 | };
|
11407 |
|
11408 | return ColdObservable;
|
11409 | })(Observable);
|
11410 |
|
11411 |
|
11412 | Rx.TestScheduler = (function (__super__) {
|
11413 | inherits(TestScheduler, __super__);
|
11414 |
|
11415 | function baseComparer(x, y) {
|
11416 | return x > y ? 1 : (x < y ? -1 : 0);
|
11417 | }
|
11418 |
|
11419 | function TestScheduler() {
|
11420 | __super__.call(this, 0, baseComparer);
|
11421 | }
|
11422 |
|
11423 | |
11424 |
|
11425 |
|
11426 |
|
11427 |
|
11428 |
|
11429 |
|
11430 |
|
11431 | TestScheduler.prototype.scheduleAbsolute = function (state, dueTime, action) {
|
11432 | dueTime <= this.clock && (dueTime = this.clock + 1);
|
11433 | return __super__.prototype.scheduleAbsolute.call(this, state, dueTime, action);
|
11434 | };
|
11435 | |
11436 |
|
11437 |
|
11438 |
|
11439 |
|
11440 |
|
11441 |
|
11442 | TestScheduler.prototype.add = function (absolute, relative) {
|
11443 | return absolute + relative;
|
11444 | };
|
11445 | |
11446 |
|
11447 |
|
11448 |
|
11449 |
|
11450 |
|
11451 | TestScheduler.prototype.toAbsoluteTime = function (absolute) {
|
11452 | return new Date(absolute).getTime();
|
11453 | };
|
11454 | |
11455 |
|
11456 |
|
11457 |
|
11458 |
|
11459 |
|
11460 | TestScheduler.prototype.toRelativeTime = function (timeSpan) {
|
11461 | return timeSpan;
|
11462 | };
|
11463 | |
11464 |
|
11465 |
|
11466 |
|
11467 |
|
11468 |
|
11469 |
|
11470 |
|
11471 |
|
11472 | TestScheduler.prototype.startScheduler = function (createFn, settings) {
|
11473 | settings || (settings = {});
|
11474 | settings.created == null && (settings.created = ReactiveTest.created);
|
11475 | settings.subscribed == null && (settings.subscribed = ReactiveTest.subscribed);
|
11476 | settings.disposed == null && (settings.disposed = ReactiveTest.disposed);
|
11477 |
|
11478 | var observer = this.createObserver(), source, subscription;
|
11479 |
|
11480 | this.scheduleAbsolute(null, settings.created, function () {
|
11481 | source = createFn();
|
11482 | return disposableEmpty;
|
11483 | });
|
11484 |
|
11485 | this.scheduleAbsolute(null, settings.subscribed, function () {
|
11486 | subscription = source.subscribe(observer);
|
11487 | return disposableEmpty;
|
11488 | });
|
11489 |
|
11490 | this.scheduleAbsolute(null, settings.disposed, function () {
|
11491 | subscription.dispose();
|
11492 | return disposableEmpty;
|
11493 | });
|
11494 |
|
11495 | this.start();
|
11496 |
|
11497 | return observer;
|
11498 | };
|
11499 |
|
11500 | |
11501 |
|
11502 |
|
11503 |
|
11504 |
|
11505 | TestScheduler.prototype.createHotObservable = function () {
|
11506 | var len = arguments.length, args;
|
11507 | if (Array.isArray(arguments[0])) {
|
11508 | args = arguments[0];
|
11509 | } else {
|
11510 | args = new Array(len);
|
11511 | for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
11512 | }
|
11513 | return new HotObservable(this, args);
|
11514 | };
|
11515 |
|
11516 | |
11517 |
|
11518 |
|
11519 |
|
11520 |
|
11521 | TestScheduler.prototype.createColdObservable = function () {
|
11522 | var len = arguments.length, args;
|
11523 | if (Array.isArray(arguments[0])) {
|
11524 | args = arguments[0];
|
11525 | } else {
|
11526 | args = new Array(len);
|
11527 | for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
|
11528 | }
|
11529 | return new ColdObservable(this, args);
|
11530 | };
|
11531 |
|
11532 | |
11533 |
|
11534 |
|
11535 |
|
11536 |
|
11537 |
|
11538 | TestScheduler.prototype.createResolvedPromise = function (ticks, value) {
|
11539 | return new MockPromise(this, [Rx.ReactiveTest.onNext(ticks, value), Rx.ReactiveTest.onCompleted(ticks)]);
|
11540 | };
|
11541 |
|
11542 | |
11543 |
|
11544 |
|
11545 |
|
11546 |
|
11547 |
|
11548 | TestScheduler.prototype.createRejectedPromise = function (ticks, reason) {
|
11549 | return new MockPromise(this, [Rx.ReactiveTest.onError(ticks, reason)]);
|
11550 | };
|
11551 |
|
11552 | |
11553 |
|
11554 |
|
11555 |
|
11556 | TestScheduler.prototype.createObserver = function () {
|
11557 | return new MockObserver(this);
|
11558 | };
|
11559 |
|
11560 | return TestScheduler;
|
11561 | })(VirtualTimeScheduler);
|
11562 |
|
11563 | var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
|
11564 | inherits(AnonymousObservable, __super__);
|
11565 |
|
11566 |
|
11567 | function fixSubscriber(subscriber) {
|
11568 | return subscriber && isFunction(subscriber.dispose) ? subscriber :
|
11569 | isFunction(subscriber) ? disposableCreate(subscriber) : disposableEmpty;
|
11570 | }
|
11571 |
|
11572 | function setDisposable(s, state) {
|
11573 | var ado = state[0], self = state[1];
|
11574 | var sub = tryCatch(self.__subscribe).call(self, ado);
|
11575 | if (sub === errorObj && !ado.fail(errorObj.e)) { thrower(errorObj.e); }
|
11576 | ado.setDisposable(fixSubscriber(sub));
|
11577 | }
|
11578 |
|
11579 | function AnonymousObservable(subscribe, parent) {
|
11580 | this.source = parent;
|
11581 | this.__subscribe = subscribe;
|
11582 | __super__.call(this);
|
11583 | }
|
11584 |
|
11585 | AnonymousObservable.prototype._subscribe = function (o) {
|
11586 | var ado = new AutoDetachObserver(o), state = [ado, this];
|
11587 |
|
11588 | if (currentThreadScheduler.scheduleRequired()) {
|
11589 | currentThreadScheduler.schedule(state, setDisposable);
|
11590 | } else {
|
11591 | setDisposable(null, state);
|
11592 | }
|
11593 | return ado;
|
11594 | };
|
11595 |
|
11596 | return AnonymousObservable;
|
11597 |
|
11598 | }(Observable));
|
11599 |
|
11600 | var AutoDetachObserver = (function (__super__) {
|
11601 | inherits(AutoDetachObserver, __super__);
|
11602 |
|
11603 | function AutoDetachObserver(observer) {
|
11604 | __super__.call(this);
|
11605 | this.observer = observer;
|
11606 | this.m = new SingleAssignmentDisposable();
|
11607 | }
|
11608 |
|
11609 | var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
|
11610 |
|
11611 | AutoDetachObserverPrototype.next = function (value) {
|
11612 | var result = tryCatch(this.observer.onNext).call(this.observer, value);
|
11613 | if (result === errorObj) {
|
11614 | this.dispose();
|
11615 | thrower(result.e);
|
11616 | }
|
11617 | };
|
11618 |
|
11619 | AutoDetachObserverPrototype.error = function (err) {
|
11620 | var result = tryCatch(this.observer.onError).call(this.observer, err);
|
11621 | this.dispose();
|
11622 | result === errorObj && thrower(result.e);
|
11623 | };
|
11624 |
|
11625 | AutoDetachObserverPrototype.completed = function () {
|
11626 | var result = tryCatch(this.observer.onCompleted).call(this.observer);
|
11627 | this.dispose();
|
11628 | result === errorObj && thrower(result.e);
|
11629 | };
|
11630 |
|
11631 | AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
|
11632 | AutoDetachObserverPrototype.getDisposable = function () { return this.m.getDisposable(); };
|
11633 |
|
11634 | AutoDetachObserverPrototype.dispose = function () {
|
11635 | __super__.prototype.dispose.call(this);
|
11636 | this.m.dispose();
|
11637 | };
|
11638 |
|
11639 | return AutoDetachObserver;
|
11640 | }(AbstractObserver));
|
11641 |
|
11642 | var UnderlyingObservable = (function (__super__) {
|
11643 | inherits(UnderlyingObservable, __super__);
|
11644 | function UnderlyingObservable(m, u) {
|
11645 | this._m = m;
|
11646 | this._u = u;
|
11647 | __super__.call(this);
|
11648 | }
|
11649 |
|
11650 | UnderlyingObservable.prototype.subscribeCore = function (o) {
|
11651 | return new BinaryDisposable(this._m.getDisposable(), this._u.subscribe(o));
|
11652 | };
|
11653 |
|
11654 | return UnderlyingObservable;
|
11655 | }(ObservableBase));
|
11656 |
|
11657 | var GroupedObservable = (function (__super__) {
|
11658 | inherits(GroupedObservable, __super__);
|
11659 | function GroupedObservable(key, underlyingObservable, mergedDisposable) {
|
11660 | __super__.call(this);
|
11661 | this.key = key;
|
11662 | this.underlyingObservable = !mergedDisposable ?
|
11663 | underlyingObservable :
|
11664 | new UnderlyingObservable(mergedDisposable, underlyingObservable);
|
11665 | }
|
11666 |
|
11667 | GroupedObservable.prototype._subscribe = function (o) {
|
11668 | return this.underlyingObservable.subscribe(o);
|
11669 | };
|
11670 |
|
11671 | return GroupedObservable;
|
11672 | }(Observable));
|
11673 |
|
11674 | |
11675 |
|
11676 |
|
11677 |
|
11678 | var Subject = Rx.Subject = (function (__super__) {
|
11679 | inherits(Subject, __super__);
|
11680 | function Subject() {
|
11681 | __super__.call(this);
|
11682 | this.isDisposed = false;
|
11683 | this.isStopped = false;
|
11684 | this.observers = [];
|
11685 | this.hasError = false;
|
11686 | }
|
11687 |
|
11688 | addProperties(Subject.prototype, Observer.prototype, {
|
11689 | _subscribe: function (o) {
|
11690 | checkDisposed(this);
|
11691 | if (!this.isStopped) {
|
11692 | this.observers.push(o);
|
11693 | return new InnerSubscription(this, o);
|
11694 | }
|
11695 | if (this.hasError) {
|
11696 | o.onError(this.error);
|
11697 | return disposableEmpty;
|
11698 | }
|
11699 | o.onCompleted();
|
11700 | return disposableEmpty;
|
11701 | },
|
11702 | |
11703 |
|
11704 |
|
11705 |
|
11706 | hasObservers: function () { return this.observers.length > 0; },
|
11707 | |
11708 |
|
11709 |
|
11710 | onCompleted: function () {
|
11711 | checkDisposed(this);
|
11712 | if (!this.isStopped) {
|
11713 | this.isStopped = true;
|
11714 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11715 | os[i].onCompleted();
|
11716 | }
|
11717 |
|
11718 | this.observers.length = 0;
|
11719 | }
|
11720 | },
|
11721 | |
11722 |
|
11723 |
|
11724 |
|
11725 | onError: function (error) {
|
11726 | checkDisposed(this);
|
11727 | if (!this.isStopped) {
|
11728 | this.isStopped = true;
|
11729 | this.error = error;
|
11730 | this.hasError = true;
|
11731 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11732 | os[i].onError(error);
|
11733 | }
|
11734 |
|
11735 | this.observers.length = 0;
|
11736 | }
|
11737 | },
|
11738 | |
11739 |
|
11740 |
|
11741 |
|
11742 | onNext: function (value) {
|
11743 | checkDisposed(this);
|
11744 | if (!this.isStopped) {
|
11745 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11746 | os[i].onNext(value);
|
11747 | }
|
11748 | }
|
11749 | },
|
11750 | |
11751 |
|
11752 |
|
11753 | dispose: function () {
|
11754 | this.isDisposed = true;
|
11755 | this.observers = null;
|
11756 | }
|
11757 | });
|
11758 |
|
11759 | |
11760 |
|
11761 |
|
11762 |
|
11763 |
|
11764 |
|
11765 | Subject.create = function (observer, observable) {
|
11766 | return new AnonymousSubject(observer, observable);
|
11767 | };
|
11768 |
|
11769 | return Subject;
|
11770 | }(Observable));
|
11771 |
|
11772 | |
11773 |
|
11774 |
|
11775 |
|
11776 | var AsyncSubject = Rx.AsyncSubject = (function (__super__) {
|
11777 | inherits(AsyncSubject, __super__);
|
11778 |
|
11779 | |
11780 |
|
11781 |
|
11782 |
|
11783 | function AsyncSubject() {
|
11784 | __super__.call(this);
|
11785 | this.isDisposed = false;
|
11786 | this.isStopped = false;
|
11787 | this.hasValue = false;
|
11788 | this.observers = [];
|
11789 | this.hasError = false;
|
11790 | }
|
11791 |
|
11792 | addProperties(AsyncSubject.prototype, Observer.prototype, {
|
11793 | _subscribe: function (o) {
|
11794 | checkDisposed(this);
|
11795 |
|
11796 | if (!this.isStopped) {
|
11797 | this.observers.push(o);
|
11798 | return new InnerSubscription(this, o);
|
11799 | }
|
11800 |
|
11801 | if (this.hasError) {
|
11802 | o.onError(this.error);
|
11803 | } else if (this.hasValue) {
|
11804 | o.onNext(this.value);
|
11805 | o.onCompleted();
|
11806 | } else {
|
11807 | o.onCompleted();
|
11808 | }
|
11809 |
|
11810 | return disposableEmpty;
|
11811 | },
|
11812 | |
11813 |
|
11814 |
|
11815 |
|
11816 | hasObservers: function () {
|
11817 | checkDisposed(this);
|
11818 | return this.observers.length > 0;
|
11819 | },
|
11820 | |
11821 |
|
11822 |
|
11823 | onCompleted: function () {
|
11824 | var i, len;
|
11825 | checkDisposed(this);
|
11826 | if (!this.isStopped) {
|
11827 | this.isStopped = true;
|
11828 | var os = cloneArray(this.observers), len = os.length;
|
11829 |
|
11830 | if (this.hasValue) {
|
11831 | for (i = 0; i < len; i++) {
|
11832 | var o = os[i];
|
11833 | o.onNext(this.value);
|
11834 | o.onCompleted();
|
11835 | }
|
11836 | } else {
|
11837 | for (i = 0; i < len; i++) {
|
11838 | os[i].onCompleted();
|
11839 | }
|
11840 | }
|
11841 |
|
11842 | this.observers.length = 0;
|
11843 | }
|
11844 | },
|
11845 | |
11846 |
|
11847 |
|
11848 |
|
11849 | onError: function (error) {
|
11850 | checkDisposed(this);
|
11851 | if (!this.isStopped) {
|
11852 | this.isStopped = true;
|
11853 | this.hasError = true;
|
11854 | this.error = error;
|
11855 |
|
11856 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11857 | os[i].onError(error);
|
11858 | }
|
11859 |
|
11860 | this.observers.length = 0;
|
11861 | }
|
11862 | },
|
11863 | |
11864 |
|
11865 |
|
11866 |
|
11867 | onNext: function (value) {
|
11868 | checkDisposed(this);
|
11869 | if (this.isStopped) { return; }
|
11870 | this.value = value;
|
11871 | this.hasValue = true;
|
11872 | },
|
11873 | |
11874 |
|
11875 |
|
11876 | dispose: function () {
|
11877 | this.isDisposed = true;
|
11878 | this.observers = null;
|
11879 | this.error = null;
|
11880 | this.value = null;
|
11881 | }
|
11882 | });
|
11883 |
|
11884 | return AsyncSubject;
|
11885 | }(Observable));
|
11886 |
|
11887 | |
11888 |
|
11889 |
|
11890 |
|
11891 | var BehaviorSubject = Rx.BehaviorSubject = (function (__super__) {
|
11892 | inherits(BehaviorSubject, __super__);
|
11893 | function BehaviorSubject(value) {
|
11894 | __super__.call(this);
|
11895 | this.value = value;
|
11896 | this.observers = [];
|
11897 | this.isDisposed = false;
|
11898 | this.isStopped = false;
|
11899 | this.hasError = false;
|
11900 | }
|
11901 |
|
11902 | addProperties(BehaviorSubject.prototype, Observer.prototype, {
|
11903 | _subscribe: function (o) {
|
11904 | checkDisposed(this);
|
11905 | if (!this.isStopped) {
|
11906 | this.observers.push(o);
|
11907 | o.onNext(this.value);
|
11908 | return new InnerSubscription(this, o);
|
11909 | }
|
11910 | if (this.hasError) {
|
11911 | o.onError(this.error);
|
11912 | } else {
|
11913 | o.onCompleted();
|
11914 | }
|
11915 | return disposableEmpty;
|
11916 | },
|
11917 | |
11918 |
|
11919 |
|
11920 |
|
11921 |
|
11922 |
|
11923 |
|
11924 | getValue: function () {
|
11925 | checkDisposed(this);
|
11926 | if (this.hasError) { thrower(this.error); }
|
11927 | return this.value;
|
11928 | },
|
11929 | |
11930 |
|
11931 |
|
11932 |
|
11933 | hasObservers: function () { return this.observers.length > 0; },
|
11934 | |
11935 |
|
11936 |
|
11937 | onCompleted: function () {
|
11938 | checkDisposed(this);
|
11939 | if (this.isStopped) { return; }
|
11940 | this.isStopped = true;
|
11941 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11942 | os[i].onCompleted();
|
11943 | }
|
11944 |
|
11945 | this.observers.length = 0;
|
11946 | },
|
11947 | |
11948 |
|
11949 |
|
11950 |
|
11951 | onError: function (error) {
|
11952 | checkDisposed(this);
|
11953 | if (this.isStopped) { return; }
|
11954 | this.isStopped = true;
|
11955 | this.hasError = true;
|
11956 | this.error = error;
|
11957 |
|
11958 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11959 | os[i].onError(error);
|
11960 | }
|
11961 |
|
11962 | this.observers.length = 0;
|
11963 | },
|
11964 | |
11965 |
|
11966 |
|
11967 |
|
11968 | onNext: function (value) {
|
11969 | checkDisposed(this);
|
11970 | if (this.isStopped) { return; }
|
11971 | this.value = value;
|
11972 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
11973 | os[i].onNext(value);
|
11974 | }
|
11975 | },
|
11976 | |
11977 |
|
11978 |
|
11979 | dispose: function () {
|
11980 | this.isDisposed = true;
|
11981 | this.observers = null;
|
11982 | this.value = null;
|
11983 | this.error = null;
|
11984 | }
|
11985 | });
|
11986 |
|
11987 | return BehaviorSubject;
|
11988 | }(Observable));
|
11989 |
|
11990 | |
11991 |
|
11992 |
|
11993 |
|
11994 | var ReplaySubject = Rx.ReplaySubject = (function (__super__) {
|
11995 |
|
11996 | var maxSafeInteger = Math.pow(2, 53) - 1;
|
11997 |
|
11998 | function createRemovableDisposable(subject, observer) {
|
11999 | return disposableCreate(function () {
|
12000 | observer.dispose();
|
12001 | !subject.isDisposed && subject.observers.splice(subject.observers.indexOf(observer), 1);
|
12002 | });
|
12003 | }
|
12004 |
|
12005 | inherits(ReplaySubject, __super__);
|
12006 |
|
12007 | |
12008 |
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 | function ReplaySubject(bufferSize, windowSize, scheduler) {
|
12014 | this.bufferSize = bufferSize == null ? maxSafeInteger : bufferSize;
|
12015 | this.windowSize = windowSize == null ? maxSafeInteger : windowSize;
|
12016 | this.scheduler = scheduler || currentThreadScheduler;
|
12017 | this.q = [];
|
12018 | this.observers = [];
|
12019 | this.isStopped = false;
|
12020 | this.isDisposed = false;
|
12021 | this.hasError = false;
|
12022 | this.error = null;
|
12023 | __super__.call(this);
|
12024 | }
|
12025 |
|
12026 | addProperties(ReplaySubject.prototype, Observer.prototype, {
|
12027 | _subscribe: function (o) {
|
12028 | checkDisposed(this);
|
12029 | var so = new ScheduledObserver(this.scheduler, o), subscription = createRemovableDisposable(this, so);
|
12030 |
|
12031 | this._trim(this.scheduler.now());
|
12032 | this.observers.push(so);
|
12033 |
|
12034 | for (var i = 0, len = this.q.length; i < len; i++) {
|
12035 | so.onNext(this.q[i].value);
|
12036 | }
|
12037 |
|
12038 | if (this.hasError) {
|
12039 | so.onError(this.error);
|
12040 | } else if (this.isStopped) {
|
12041 | so.onCompleted();
|
12042 | }
|
12043 |
|
12044 | so.ensureActive();
|
12045 | return subscription;
|
12046 | },
|
12047 | |
12048 |
|
12049 |
|
12050 |
|
12051 | hasObservers: function () {
|
12052 | return this.observers.length > 0;
|
12053 | },
|
12054 | _trim: function (now) {
|
12055 | while (this.q.length > this.bufferSize) {
|
12056 | this.q.shift();
|
12057 | }
|
12058 | while (this.q.length > 0 && (now - this.q[0].interval) > this.windowSize) {
|
12059 | this.q.shift();
|
12060 | }
|
12061 | },
|
12062 | |
12063 |
|
12064 |
|
12065 |
|
12066 | onNext: function (value) {
|
12067 | checkDisposed(this);
|
12068 | if (this.isStopped) { return; }
|
12069 | var now = this.scheduler.now();
|
12070 | this.q.push({ interval: now, value: value });
|
12071 | this._trim(now);
|
12072 |
|
12073 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
12074 | var observer = os[i];
|
12075 | observer.onNext(value);
|
12076 | observer.ensureActive();
|
12077 | }
|
12078 | },
|
12079 | |
12080 |
|
12081 |
|
12082 |
|
12083 | onError: function (error) {
|
12084 | checkDisposed(this);
|
12085 | if (this.isStopped) { return; }
|
12086 | this.isStopped = true;
|
12087 | this.error = error;
|
12088 | this.hasError = true;
|
12089 | var now = this.scheduler.now();
|
12090 | this._trim(now);
|
12091 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
12092 | var observer = os[i];
|
12093 | observer.onError(error);
|
12094 | observer.ensureActive();
|
12095 | }
|
12096 | this.observers.length = 0;
|
12097 | },
|
12098 | |
12099 |
|
12100 |
|
12101 | onCompleted: function () {
|
12102 | checkDisposed(this);
|
12103 | if (this.isStopped) { return; }
|
12104 | this.isStopped = true;
|
12105 | var now = this.scheduler.now();
|
12106 | this._trim(now);
|
12107 | for (var i = 0, os = cloneArray(this.observers), len = os.length; i < len; i++) {
|
12108 | var observer = os[i];
|
12109 | observer.onCompleted();
|
12110 | observer.ensureActive();
|
12111 | }
|
12112 | this.observers.length = 0;
|
12113 | },
|
12114 | |
12115 |
|
12116 |
|
12117 | dispose: function () {
|
12118 | this.isDisposed = true;
|
12119 | this.observers = null;
|
12120 | }
|
12121 | });
|
12122 |
|
12123 | return ReplaySubject;
|
12124 | }(Observable));
|
12125 |
|
12126 | var AnonymousSubject = Rx.AnonymousSubject = (function (__super__) {
|
12127 | inherits(AnonymousSubject, __super__);
|
12128 | function AnonymousSubject(observer, observable) {
|
12129 | this.observer = observer;
|
12130 | this.observable = observable;
|
12131 | __super__.call(this);
|
12132 | }
|
12133 |
|
12134 | addProperties(AnonymousSubject.prototype, Observer.prototype, {
|
12135 | _subscribe: function (o) {
|
12136 | return this.observable.subscribe(o);
|
12137 | },
|
12138 | onCompleted: function () {
|
12139 | this.observer.onCompleted();
|
12140 | },
|
12141 | onError: function (error) {
|
12142 | this.observer.onError(error);
|
12143 | },
|
12144 | onNext: function (value) {
|
12145 | this.observer.onNext(value);
|
12146 | }
|
12147 | });
|
12148 |
|
12149 | return AnonymousSubject;
|
12150 | }(Observable));
|
12151 |
|
12152 | |
12153 |
|
12154 |
|
12155 | Rx.Pauser = (function (__super__) {
|
12156 | inherits(Pauser, __super__);
|
12157 | function Pauser() {
|
12158 | __super__.call(this);
|
12159 | }
|
12160 |
|
12161 | |
12162 |
|
12163 |
|
12164 | Pauser.prototype.pause = function () { this.onNext(false); };
|
12165 |
|
12166 | |
12167 |
|
12168 |
|
12169 | Pauser.prototype.resume = function () { this.onNext(true); };
|
12170 |
|
12171 | return Pauser;
|
12172 | }(Subject));
|
12173 |
|
12174 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
12175 | root.Rx = Rx;
|
12176 |
|
12177 | define(function() {
|
12178 | return Rx;
|
12179 | });
|
12180 | } else if (freeExports && freeModule) {
|
12181 |
|
12182 | if (moduleExports) {
|
12183 | (freeModule.exports = Rx).Rx = Rx;
|
12184 | } else {
|
12185 | freeExports.Rx = Rx;
|
12186 | }
|
12187 | } else {
|
12188 |
|
12189 | root.Rx = Rx;
|
12190 | }
|
12191 |
|
12192 |
|
12193 | var rEndingLine = captureLine();
|
12194 |
|
12195 | }.call(this));
|