-
Notifications
You must be signed in to change notification settings - Fork 2
/
rx.patch
643 lines (616 loc) · 19.7 KB
/
rx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
--- rx-for-patch.js 2015-08-19 09:51:02.000000000 +0200
+++ rx-lite.js 2015-08-19 09:53:42.000000000 +0200
@@ -1,21 +1,8 @@
+// v3.0.1
+//
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-;(function (undefined) {
-
-var objectTypes = {
- 'function': true,
- 'object': true
-};
-
-var
- freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports,
- freeSelf = objectTypes[typeof self] && self.Object && self,
- freeWindow = objectTypes[typeof window] && window && window.Object && window,
- freeModule = objectTypes[typeof module] && module && !module.nodeType && module,
- moduleExports = freeModule && freeModule.exports === freeExports && freeExports,
- freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
-
-var root = root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
+var root = window;
var Rx = {
internals: {},
@@ -34,21 +21,9 @@
defaultKeySerializer = Rx.helpers.defaultKeySerializer = function (x) { return x.toString(); },
defaultError = Rx.helpers.defaultError = function (err) { throw err; },
isPromise = Rx.helpers.isPromise = function (p) { return !!p && typeof p.subscribe !== 'function' && typeof p.then === 'function'; },
- isFunction = Rx.helpers.isFunction = (function () {
-
- var isFn = function (value) {
- return typeof value == 'function' || false;
- }
-
- // fallback for older versions of Chrome and Safari
- if (isFn(/x/)) {
- isFn = function(value) {
- return typeof value == 'function' && toString.call(value) == '[object Function]';
- };
- }
-
- return isFn;
- }());
+ isFunction = Rx.helpers.isFunction = function (value) {
+ return typeof value == 'function' || false;
+ };
function cloneArray(arr) {
var len = arr.length, a = new Array(len);
@@ -75,97 +50,6 @@
throw e;
}
-Rx.config.longStackSupport = false;
-var hasStacks = false, stacks = tryCatch(function () { throw new Error(); })();
-hasStacks = !!stacks.e && !!stacks.e.stack;
-
-// All code after this point will be filtered from stack traces reported by RxJS
-var rStartingLine = captureLine(), rFileName;
-
-var STACK_JUMP_SEPARATOR = 'From previous event:';
-
-function makeStackTraceLong(error, observable) {
- // If possible, transform the error stack trace by removing Node and RxJS
- // cruft, then concatenating with the stack trace of `observable`.
- if (hasStacks &&
- observable.stack &&
- typeof error === 'object' &&
- error !== null &&
- error.stack &&
- error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
- ) {
- var stacks = [];
- for (var o = observable; !!o; o = o.source) {
- if (o.stack) {
- stacks.unshift(o.stack);
- }
- }
- stacks.unshift(error.stack);
-
- var concatedStacks = stacks.join('\n' + STACK_JUMP_SEPARATOR + '\n');
- error.stack = filterStackString(concatedStacks);
- }
-}
-
-function filterStackString(stackString) {
- var lines = stackString.split('\n'), desiredLines = [];
- for (var i = 0, len = lines.length; i < len; i++) {
- var line = lines[i];
-
- if (!isInternalFrame(line) && !isNodeFrame(line) && line) {
- desiredLines.push(line);
- }
- }
- return desiredLines.join('\n');
-}
-
-function isInternalFrame(stackLine) {
- var fileNameAndLineNumber = getFileNameAndLineNumber(stackLine);
- if (!fileNameAndLineNumber) {
- return false;
- }
- var fileName = fileNameAndLineNumber[0], lineNumber = fileNameAndLineNumber[1];
-
- return fileName === rFileName &&
- lineNumber >= rStartingLine &&
- lineNumber <= rEndingLine;
-}
-
-function isNodeFrame(stackLine) {
- return stackLine.indexOf('(module.js:') !== -1 ||
- stackLine.indexOf('(node.js:') !== -1;
-}
-
-function captureLine() {
- if (!hasStacks) { return; }
-
- try {
- throw new Error();
- } catch (e) {
- var lines = e.stack.split('\n');
- var firstLine = lines[0].indexOf('@') > 0 ? lines[1] : lines[2];
- var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
- if (!fileNameAndLineNumber) { return; }
-
- rFileName = fileNameAndLineNumber[0];
- return fileNameAndLineNumber[1];
- }
-}
-
-function getFileNameAndLineNumber(stackLine) {
- // Named functions: 'at functionName (filename:lineNumber:columnNumber)'
- var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
- if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
-
- // Anonymous functions: 'at filename:lineNumber:columnNumber'
- var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
- if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
-
- // Firefox style: 'function@filename:lineNumber or @filename:lineNumber'
- var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
- if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
-}
-
var EmptyError = Rx.EmptyError = function() {
this.message = 'Sequence contains no elements.';
this.name = 'EmptyError';
@@ -210,44 +94,16 @@
};
// Shim in iterator support
-var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
- '_es6shim_iterator_';
-// Bug for mozilla version
-if (root.Set && typeof new root.Set()['@@iterator'] === 'function') {
- $iterator$ = '@@iterator';
-}
-
+var $iterator$ = '_es6shim_iterator_';
var doneEnumerator = Rx.doneEnumerator = { done: true, value: undefined };
-var isIterable = Rx.helpers.isIterable = function (o) {
- return o[$iterator$] !== undefined;
-}
-
var isArrayLike = Rx.helpers.isArrayLike = function (o) {
return o && o.length !== undefined;
-}
-
-Rx.helpers.iterator = $iterator$;
+};
var bindCallback = Rx.internals.bindCallback = function (func, thisArg, argCount) {
- if (typeof thisArg === 'undefined') { return func; }
- switch(argCount) {
- case 0:
- return function() {
- return func.call(thisArg)
- };
- case 1:
- return function(arg) {
- return func.call(thisArg, arg);
- }
- case 2:
- return function(value, index) {
- return func.call(thisArg, value, index);
- };
- case 3:
- return function(value, index, collection) {
- return func.call(thisArg, value, index, collection);
- };
+ if (!thisArg) {
+ return func;
}
return function() {
@@ -255,290 +111,40 @@
};
};
-/** Used to determine if values are of the language type Object */
-var dontEnums = ['toString',
- 'toLocaleString',
- 'valueOf',
- 'hasOwnProperty',
- 'isPrototypeOf',
- 'propertyIsEnumerable',
- 'constructor'],
-dontEnumsLength = dontEnums.length;
-
-/** `Object#toString` result shortcuts */
-var argsClass = '[object Arguments]',
- arrayClass = '[object Array]',
- boolClass = '[object Boolean]',
- dateClass = '[object Date]',
- errorClass = '[object Error]',
- funcClass = '[object Function]',
- numberClass = '[object Number]',
- objectClass = '[object Object]',
- regexpClass = '[object RegExp]',
- stringClass = '[object String]';
-
-var toString = Object.prototype.toString,
- hasOwnProperty = Object.prototype.hasOwnProperty,
- supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
- supportNodeClass,
- errorProto = Error.prototype,
- objectProto = Object.prototype,
- stringProto = String.prototype,
- propertyIsEnumerable = objectProto.propertyIsEnumerable;
-
-try {
- supportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
-} catch (e) {
- supportNodeClass = true;
-}
-
-var nonEnumProps = {};
-nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
-nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
-nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
-nonEnumProps[objectClass] = { 'constructor': true };
-
-var support = {};
-(function () {
- var ctor = function() { this.x = 1; },
- props = [];
-
- ctor.prototype = { 'valueOf': 1, 'y': 1 };
- for (var key in new ctor) { props.push(key); }
- for (key in arguments) { }
-
- // Detect if `name` or `message` properties of `Error.prototype` are enumerable by default.
- support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
-
- // Detect if `prototype` properties are enumerable by default.
- support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
-
- // Detect if `arguments` object indexes are non-enumerable
- support.nonEnumArgs = key != 0;
-
- // Detect if properties shadowing those on `Object.prototype` are non-enumerable.
- support.nonEnumShadows = !/valueOf/.test(props);
-}(1));
-
var isObject = Rx.internals.isObject = function(value) {
var type = typeof value;
return value && (type == 'function' || type == 'object') || false;
};
-function keysIn(object) {
- var result = [];
- if (!isObject(object)) {
- return result;
- }
- if (support.nonEnumArgs && object.length && isArguments(object)) {
- object = slice.call(object);
- }
- var skipProto = support.enumPrototypes && typeof object == 'function',
- skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error);
-
- for (var key in object) {
- if (!(skipProto && key == 'prototype') &&
- !(skipErrorProps && (key == 'message' || key == 'name'))) {
- result.push(key);
- }
- }
-
- if (support.nonEnumShadows && object !== objectProto) {
- var ctor = object.constructor,
- index = -1,
- length = dontEnumsLength;
-
- if (object === (ctor && ctor.prototype)) {
- var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),
- nonEnum = nonEnumProps[className];
- }
- while (++index < length) {
- key = dontEnums[index];
- if (!(nonEnum && nonEnum[key]) && hasOwnProperty.call(object, key)) {
- result.push(key);
- }
- }
- }
- return result;
-}
-
-function internalFor(object, callback, keysFunc) {
- var index = -1,
- props = keysFunc(object),
- length = props.length;
-
- while (++index < length) {
- var key = props[index];
- if (callback(object[key], key, object) === false) {
- break;
- }
- }
- return object;
-}
-
-function internalForIn(object, callback) {
- return internalFor(object, callback, keysIn);
-}
-
-function isNode(value) {
- // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
- // methods that are `typeof` "string" and still can coerce nodes to strings
- return typeof value.toString != 'function' && typeof (value + '') == 'string';
-}
-
-var isArguments = function(value) {
- return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
-}
-
-// fallback for browsers that can't detect `arguments` objects by [[Class]]
-if (!supportsArgsClass) {
- isArguments = function(value) {
- return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
- };
-}
-
-var isEqual = Rx.internals.isEqual = function (x, y) {
- return deepEquals(x, y, [], []);
-};
-
-/** @private
- * Used for deep comparison
- **/
-function deepEquals(a, b, stackA, stackB) {
- // exit early for identical values
- if (a === b) {
- // treat `+0` vs. `-0` as not equal
- return a !== 0 || (1 / a == 1 / b);
+var isEqual = Rx.internals.isEqual = function (objA, objB) {
+ if (objA === objB) {
+ return true;
}
- var type = typeof a,
- otherType = typeof b;
-
- // exit early for unlike primitive values
- if (a === a && (a == null || b == null ||
- (type != 'function' && type != 'object' && otherType != 'function' && otherType != 'object'))) {
+ if (!objA || !objB) {
return false;
}
- // compare [[Class]] names
- var className = toString.call(a),
- otherClass = toString.call(b);
-
- if (className == argsClass) {
- className = objectClass;
- }
- if (otherClass == argsClass) {
- otherClass = objectClass;
- }
- if (className != otherClass) {
+ if (typeof objA !== 'object' || typeof objB !== 'object') {
return false;
}
- switch (className) {
- case boolClass:
- case dateClass:
- // coerce dates and booleans to numbers, dates to milliseconds and booleans
- // to `1` or `0` treating invalid dates coerced to `NaN` as not equal
- return +a == +b;
-
- case numberClass:
- // treat `NaN` vs. `NaN` as equal
- return (a != +a) ?
- b != +b :
- // but treat `-0` vs. `+0` as not equal
- (a == 0 ? (1 / a == 1 / b) : a == +b);
-
- case regexpClass:
- case stringClass:
- // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
- // treat string primitives and their corresponding object instances as equal
- return a == String(b);
- }
- var isArr = className == arrayClass;
- if (!isArr) {
- // exit for functions and DOM nodes
- if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
+ var key;
+ // Test for A's keys different from B.
+ for (key in objA) {
+ if (objA.hasOwnProperty(key) &&
+ (!objB.hasOwnProperty(key) || objA[key] !== objB[key])) {
return false;
}
- // in older versions of Opera, `arguments` objects have `Array` constructors
- var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
- ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
-
- // non `Object` object instances with different constructors are not equal
- if (ctorA != ctorB &&
- !(hasOwnProperty.call(a, 'constructor') && hasOwnProperty.call(b, 'constructor')) &&
- !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
- ('constructor' in a && 'constructor' in b)
- ) {
- return false;
- }
- }
- // assume cyclic structures are equal
- // the algorithm for detecting cyclic structures is adapted from ES 5.1
- // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
- var initedStack = !stackA;
- stackA || (stackA = []);
- stackB || (stackB = []);
-
- var length = stackA.length;
- while (length--) {
- if (stackA[length] == a) {
- return stackB[length] == b;
- }
- }
- var size = 0;
- var result = true;
-
- // add `a` and `b` to the stack of traversed objects
- stackA.push(a);
- stackB.push(b);
-
- // recursively compare objects and arrays (susceptible to call stack limits)
- if (isArr) {
- // compare lengths to determine if a deep comparison is necessary
- length = a.length;
- size = b.length;
- result = size == length;
-
- if (result) {
- // deep compare the contents, ignoring non-numeric properties
- while (size--) {
- var index = length,
- value = b[size];
-
- if (!(result = deepEquals(a[size], value, stackA, stackB))) {
- break;
- }
- }
- }
}
- else {
- // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
- // which, in this case, is more costly
- internalForIn(b, function(value, key, b) {
- if (hasOwnProperty.call(b, key)) {
- // count the number of properties.
- size++;
- // deep compare each property value.
- return (result = hasOwnProperty.call(a, key) && deepEquals(a[key], value, stackA, stackB));
- }
- });
-
- if (result) {
- // ensure both objects have the same number of properties
- internalForIn(a, function(value, key, a) {
- if (hasOwnProperty.call(a, key)) {
- // `size` will be `-1` if `a` has more properties than `b`
- return (result = --size > -1);
- }
- });
+ // Test for B's keys missing from A.
+ for (key in objB) {
+ if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
+ return false;
}
}
- stackA.pop();
- stackB.pop();
-
- return result;
-}
+ return true;
+};
var hasProp = {}.hasOwnProperty,
slice = Array.prototype.slice;
@@ -550,22 +156,14 @@
};
var addProperties = Rx.internals.addProperties = function (obj) {
- for(var sources = [], i = 1, len = arguments.length; i < len; i++) { sources.push(arguments[i]); }
- for (var idx = 0, ln = sources.length; idx < ln; idx++) {
- var source = sources[idx];
+ for (var idx = 1, ln = arguments.length; idx < ln; idx++) {
+ var source = arguments[idx];
for (var prop in source) {
obj[prop] = source[prop];
}
}
};
-// Rx Utils
-var addRef = Rx.internals.addRef = function (xs, r) {
- return new AnonymousObservable(function (observer) {
- return new CompositeDisposable(r.getDisposable(), xs.subscribe(observer));
- });
-};
-
function arrayInitialize(count, factory) {
var a = new Array(count);
for (var i = 0; i < count; i++) {
@@ -1200,8 +798,7 @@
.replace(/toString| for [^\]]+/g, '.*?') + '$'
);
- var setImmediate = typeof (setImmediate = freeGlobal && moduleExports && freeGlobal.setImmediate) == 'function' &&
- !reNative.test(setImmediate) && setImmediate;
+ var setImmediate = window.setImmediate;
function postMessageSupported () {
// Ensure not in a worker
@@ -1573,13 +1170,7 @@
}
function Observable(subscribe) {
- if (Rx.config.longStackSupport && hasStacks) {
- var e = tryCatch(thrower)(new Error()).e;
- this.stack = e.stack.substring(e.stack.indexOf('\n') + 1);
- this._subscribe = makeSubscribe(this, subscribe);
- } else {
- this._subscribe = subscribe;
- }
+ this._subscribe = subscribe;
}
observableProto = Observable.prototype;
@@ -1785,7 +1376,7 @@
}
Rx.helpers.isPromise(result) && (result = Rx.Observable.fromPromise(result));
- (Rx.helpers.isArrayLike(result) || Rx.helpers.isIterable(result)) && (result = Rx.Observable.from(result));
+ (Rx.helpers.isArrayLike(result)) && (result = Rx.Observable.from(result));
this.o.onNext(this._wrapResult(result, x, i));
@@ -4509,7 +4088,7 @@
element,
eventName,
eventHandler(o, selector));
- }).publish().refCount();
+ });
};
/**
@@ -5525,41 +5104,6 @@
return dest;
};
-/**
- * Executes a transducer to transform the observable sequence
- * @param {Transducer} transducer A transducer to execute
- * @returns {Observable} An Observable sequence containing the results from the transducer.
- */
-observableProto.transduce = function(transducer) {
- var source = this;
-
- function transformForObserver(o) {
- return {
- '@@transducer/init': function() {
- return o;
- },
- '@@transducer/step': function(obs, input) {
- return obs.onNext(input);
- },
- '@@transducer/result': function(obs) {
- return obs.onCompleted();
- }
- };
- }
-
- return new AnonymousObservable(function(o) {
- var xform = transducer(transformForObserver(o));
- return source.subscribe(
- function(v) {
- var res = tryCatch(xform['@@transducer/step']).call(xform, o, v);
- if (res === errorObj) { o.onError(res.e); }
- },
- function (e) { o.onError(e); },
- function() { xform['@@transducer/result'](o); }
- );
- }, source);
-};
-
var AnonymousObservable = Rx.AnonymousObservable = (function (__super__) {
inherits(AnonymousObservable, __super__);
@@ -6175,25 +5719,4 @@
return Pauser;
}(Subject));
-if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
- root.Rx = Rx;
-
- define(function() {
- return Rx;
- });
-} else if (freeExports && freeModule) {
- // in Node.js or RingoJS
- if (moduleExports) {
- (freeModule.exports = Rx).Rx = Rx;
- } else {
- freeExports.Rx = Rx;
- }
-} else {
- // in a browser or Rhino
- root.Rx = Rx;
-}
-
-// All code before this point will be filtered from stack traces.
-var rEndingLine = captureLine();
-
-}.call(this));
+module.exports = Rx;