rxjs-rails 2.2.13 → 2.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +2 -2
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.async.compat.js +23 -47
  6. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  7. data/vendor/assets/javascripts/rx.async.js +23 -47
  8. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  9. data/vendor/assets/javascripts/rx.backpressure.js +81 -0
  10. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -0
  11. data/vendor/assets/javascripts/rx.binding.js +4 -4
  12. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.coincidence.js +3 -3
  14. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.compat.js +536 -386
  16. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  17. data/vendor/assets/javascripts/rx.experimental.js +5 -6
  18. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  19. data/vendor/assets/javascripts/rx.joinpatterns.js +4 -4
  20. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  21. data/vendor/assets/javascripts/rx.lite.compat.js +554 -403
  22. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  23. data/vendor/assets/javascripts/rx.lite.js +554 -403
  24. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  25. data/vendor/assets/javascripts/rx.min.js +2 -2
  26. data/vendor/assets/javascripts/rx.node.js +1 -0
  27. data/vendor/assets/javascripts/rx.testing.js +2 -7
  28. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  29. data/vendor/assets/javascripts/rx.time.js +2 -3
  30. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  31. data/vendor/assets/javascripts/rx.virtualtime.js +5 -5
  32. data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
  33. metadata +4 -2
@@ -21,7 +21,7 @@
21
21
  root = freeGlobal;
22
22
  }
23
23
 
24
- var Rx = { Internals: {} };
24
+ var Rx = { internals: {}, config: {} };
25
25
 
26
26
  // Defaults
27
27
  function noop() { }
@@ -31,6 +31,7 @@
31
31
  function defaultSubComparer(x, y) { return x - y; }
32
32
  function defaultKeySerializer(x) { return x.toString(); }
33
33
  function defaultError(err) { throw err; }
34
+ function isPromise(p) { return typeof p.then === 'function'; }
34
35
 
35
36
  // Errors
36
37
  var sequenceContainsNoElements = 'Sequence contains no elements.';
@@ -42,202 +43,298 @@
42
43
  }
43
44
  }
44
45
 
45
- /** `Object#toString` result shortcuts */
46
- var argsClass = '[object Arguments]',
47
- arrayClass = '[object Array]',
48
- boolClass = '[object Boolean]',
49
- dateClass = '[object Date]',
50
- errorClass = '[object Error]',
51
- funcClass = '[object Function]',
52
- numberClass = '[object Number]',
53
- objectClass = '[object Object]',
54
- regexpClass = '[object RegExp]',
55
- stringClass = '[object String]';
56
-
57
- var toString = Object.prototype.toString,
58
- hasOwnProperty = Object.prototype.hasOwnProperty,
59
- supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
60
- suportNodeClass;
61
-
62
- try {
63
- suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
64
- } catch(e) {
65
- suportNodeClass = true;
46
+ /** `Object#toString` result shortcuts */
47
+ var argsClass = '[object Arguments]',
48
+ arrayClass = '[object Array]',
49
+ boolClass = '[object Boolean]',
50
+ dateClass = '[object Date]',
51
+ errorClass = '[object Error]',
52
+ funcClass = '[object Function]',
53
+ numberClass = '[object Number]',
54
+ objectClass = '[object Object]',
55
+ regexpClass = '[object RegExp]',
56
+ stringClass = '[object String]';
57
+
58
+ var toString = Object.prototype.toString,
59
+ hasOwnProperty = Object.prototype.hasOwnProperty,
60
+ supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
61
+ suportNodeClass,
62
+ errorProto = Error.prototype,
63
+ objectProto = Object.prototype,
64
+ propertyIsEnumerable = objectProto.propertyIsEnumerable;
65
+
66
+ try {
67
+ suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
68
+ } catch(e) {
69
+ suportNodeClass = true;
70
+ }
71
+
72
+ var shadowedProps = [
73
+ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'
74
+ ];
75
+
76
+ var nonEnumProps = {};
77
+ nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
78
+ nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
79
+ nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
80
+ nonEnumProps[objectClass] = { 'constructor': true };
81
+
82
+ var support = {};
83
+ (function () {
84
+ var ctor = function() { this.x = 1; },
85
+ props = [];
86
+
87
+ ctor.prototype = { 'valueOf': 1, 'y': 1 };
88
+ for (var key in new ctor) { props.push(key); }
89
+ for (key in arguments) { }
90
+
91
+ // Detect if `name` or `message` properties of `Error.prototype` are enumerable by default.
92
+ support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
93
+
94
+ // Detect if `prototype` properties are enumerable by default.
95
+ support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
96
+
97
+ // Detect if `arguments` object indexes are non-enumerable
98
+ support.nonEnumArgs = key != 0;
99
+
100
+ // Detect if properties shadowing those on `Object.prototype` are non-enumerable.
101
+ support.nonEnumShadows = !/valueOf/.test(props);
102
+ }(1));
103
+
104
+ function isObject(value) {
105
+ // check if the value is the ECMAScript language type of Object
106
+ // http://es5.github.io/#x8
107
+ // and avoid a V8 bug
108
+ // https://code.google.com/p/v8/issues/detail?id=2291
109
+ var type = typeof value;
110
+ return value && (type == 'function' || type == 'object') || false;
111
+ }
112
+
113
+ function keysIn(object) {
114
+ var result = [];
115
+ if (!isObject(object)) {
116
+ return result;
66
117
  }
67
-
68
- function isNode(value) {
69
- // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
70
- // methods that are `typeof` "string" and still can coerce nodes to strings
71
- return typeof value.toString != 'function' && typeof (value + '') == 'string';
118
+ if (support.nonEnumArgs && object.length && isArguments(object)) {
119
+ object = slice.call(object);
72
120
  }
73
-
74
- function isArguments(value) {
75
- return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
121
+ var skipProto = support.enumPrototypes && typeof object == 'function',
122
+ skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error);
123
+
124
+ for (var key in object) {
125
+ if (!(skipProto && key == 'prototype') &&
126
+ !(skipErrorProps && (key == 'message' || key == 'name'))) {
127
+ result.push(key);
128
+ }
76
129
  }
77
130
 
78
- // fallback for browsers that can't detect `arguments` objects by [[Class]]
79
- if (!supportsArgsClass) {
80
- isArguments = function(value) {
81
- return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
82
- };
131
+ if (support.nonEnumShadows && object !== objectProto) {
132
+ var ctor = object.constructor,
133
+ index = -1,
134
+ length = shadowedProps.length;
135
+
136
+ if (object === (ctor && ctor.prototype)) {
137
+ var className = object === stringProto ? stringClass : object === errorProto ? errorClass : toString.call(object),
138
+ nonEnum = nonEnumProps[className];
139
+ }
140
+ while (++index < length) {
141
+ key = shadowedProps[index];
142
+ if (!(nonEnum && nonEnum[key]) && hasOwnProperty.call(object, key)) {
143
+ result.push(key);
144
+ }
145
+ }
83
146
  }
84
-
85
- function isFunction(value) {
86
- return typeof value == 'function';
147
+ return result;
148
+ }
149
+
150
+ function internalFor(object, callback, keysFunc) {
151
+ var index = -1,
152
+ props = keysFunc(object),
153
+ length = props.length;
154
+
155
+ while (++index < length) {
156
+ var key = props[index];
157
+ if (callback(object[key], key, object) === false) {
158
+ break;
159
+ }
87
160
  }
88
-
89
- // fallback for older versions of Chrome and Safari
90
- if (isFunction(/x/)) {
91
- isFunction = function(value) {
92
- return typeof value == 'function' && toString.call(value) == funcClass;
93
- };
94
- }
95
-
96
- var isEqual = Rx.Internals.isEqual = function (x, y) {
97
- return deepEquals(x, y, [], []);
161
+ return object;
162
+ }
163
+
164
+ function internalForIn(object, callback) {
165
+ return internalFor(object, callback, keysIn);
166
+ }
167
+
168
+ function isNode(value) {
169
+ // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
170
+ // methods that are `typeof` "string" and still can coerce nodes to strings
171
+ return typeof value.toString != 'function' && typeof (value + '') == 'string';
172
+ }
173
+
174
+ function isArguments(value) {
175
+ return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
176
+ }
177
+
178
+ // fallback for browsers that can't detect `arguments` objects by [[Class]]
179
+ if (!supportsArgsClass) {
180
+ isArguments = function(value) {
181
+ return (value && typeof value == 'object') ? hasOwnProperty.call(value, 'callee') : false;
98
182
  };
183
+ }
99
184
 
100
- /** @private
101
- * Used for deep comparison
102
- **/
103
- function deepEquals(a, b, stackA, stackB) {
104
- var result;
105
- // exit early for identical values
106
- if (a === b) {
107
- // treat `+0` vs. `-0` as not equal
108
- return a !== 0 || (1 / a == 1 / b);
109
- }
110
- var type = typeof a,
111
- otherType = typeof b;
185
+ function isFunction(value) {
186
+ return typeof value == 'function';
187
+ }
112
188
 
113
- // exit early for unlike primitive values
114
- if (a === a &&
115
- !(a && objectTypes[type]) &&
116
- !(b && objectTypes[otherType])) {
117
- return false;
118
- }
119
-
120
- // exit early for `null` and `undefined`, avoiding ES3's Function#call behavior
121
- // http://es5.github.io/#x15.3.4.4
122
- if (a == null || b == null) {
123
- return a === b;
124
- }
125
- // compare [[Class]] names
126
- var className = toString.call(a),
127
- otherClass = toString.call(b);
189
+ // fallback for older versions of Chrome and Safari
190
+ if (isFunction(/x/)) {
191
+ isFunction = function(value) {
192
+ return typeof value == 'function' && toString.call(value) == funcClass;
193
+ };
194
+ }
195
+
196
+ var isEqual = Rx.internals.isEqual = function (x, y) {
197
+ return deepEquals(x, y, [], []);
198
+ };
199
+
200
+ /** @private
201
+ * Used for deep comparison
202
+ **/
203
+ function deepEquals(a, b, stackA, stackB) {
204
+ // exit early for identical values
205
+ if (a === b) {
206
+ // treat `+0` vs. `-0` as not equal
207
+ return a !== 0 || (1 / a == 1 / b);
208
+ }
128
209
 
129
- if (className == argsClass) {
130
- className = objectClass;
131
- }
132
- if (otherClass == argsClass) {
133
- otherClass = objectClass;
134
- }
135
- if (className != otherClass) {
136
- return false;
137
- }
138
-
139
- switch (className) {
140
- case boolClass:
141
- case dateClass:
142
- // coerce dates and booleans to numbers, dates to milliseconds and booleans
143
- // to `1` or `0`, treating invalid dates coerced to `NaN` as not equal
144
- return +a == +b;
145
-
146
- case numberClass:
147
- // treat `NaN` vs. `NaN` as equal
148
- return (a != +a)
149
- ? b != +b
150
- // but treat `+0` vs. `-0` as not equal
151
- : (a == 0 ? (1 / a == 1 / b) : a == +b);
152
-
153
- case regexpClass:
154
- case stringClass:
155
- // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
156
- // treat string primitives and their corresponding object instances as equal
157
- return a == String(b);
158
- }
210
+ var type = typeof a,
211
+ otherType = typeof b;
159
212
 
160
- var isArr = className == arrayClass;
161
- if (!isArr) {
162
-
163
- // exit for functions and DOM nodes
164
- if (className != objectClass || (!suportNodeClass && (isNode(a) || isNode(b)))) {
165
- return false;
166
- }
213
+ // exit early for unlike primitive values
214
+ if (a === a && (a == null || b == null ||
215
+ (type != 'function' && type != 'object' && otherType != 'function' && otherType != 'object'))) {
216
+ return false;
217
+ }
167
218
 
168
- // in older versions of Opera, `arguments` objects have `Array` constructors
169
- var ctorA = !supportsArgsClass && isArguments(a) ? Object : a.constructor,
170
- ctorB = !supportsArgsClass && isArguments(b) ? Object : b.constructor;
219
+ // compare [[Class]] names
220
+ var className = toString.call(a),
221
+ otherClass = toString.call(b);
171
222
 
172
- // non `Object` object instances with different constructors are not equal
173
- if (ctorA != ctorB && !(
174
- isFunction(ctorA) && ctorA instanceof ctorA &&
175
- isFunction(ctorB) && ctorB instanceof ctorB
176
- )) {
177
- return false;
178
- }
179
- }
180
-
181
- // assume cyclic structures are equal
182
- // the algorithm for detecting cyclic structures is adapted from ES 5.1
183
- // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
184
- var length = stackA.length;
185
- while (length--) {
186
- if (stackA[length] == a) {
187
- return stackB[length] == b;
188
- }
189
- }
190
-
191
- var size = 0;
192
- result = true;
193
-
194
- // add `a` and `b` to the stack of traversed objects
195
- stackA.push(a);
196
- stackB.push(b);
197
-
198
- // recursively compare objects and arrays (susceptible to call stack limits)
199
- if (isArr) {
200
- length = a.length;
201
- size = b.length;
202
-
203
- // compare lengths to determine if a deep comparison is necessary
204
- result = size == a.length;
205
- // deep compare the contents, ignoring non-numeric properties
206
- while (size--) {
207
- var index = length,
208
- value = b[size];
209
-
210
- if (!(result = deepEquals(a[size], value, stackA, stackB))) {
211
- break;
212
- }
213
- }
214
-
215
- return result;
216
- }
223
+ if (className == argsClass) {
224
+ className = objectClass;
225
+ }
226
+ if (otherClass == argsClass) {
227
+ otherClass = objectClass;
228
+ }
229
+ if (className != otherClass) {
230
+ return false;
231
+ }
232
+ switch (className) {
233
+ case boolClass:
234
+ case dateClass:
235
+ // coerce dates and booleans to numbers, dates to milliseconds and booleans
236
+ // to `1` or `0` treating invalid dates coerced to `NaN` as not equal
237
+ return +a == +b;
238
+
239
+ case numberClass:
240
+ // treat `NaN` vs. `NaN` as equal
241
+ return (a != +a)
242
+ ? b != +b
243
+ // but treat `-0` vs. `+0` as not equal
244
+ : (a == 0 ? (1 / a == 1 / b) : a == +b);
245
+
246
+ case regexpClass:
247
+ case stringClass:
248
+ // coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
249
+ // treat string primitives and their corresponding object instances as equal
250
+ return a == String(b);
251
+ }
252
+ var isArr = className == arrayClass;
253
+ if (!isArr) {
217
254
 
218
- // deep compare each object
219
- for(var key in b) {
220
- if (hasOwnProperty.call(b, key)) {
221
- // count properties and deep compare each property value
222
- size++;
223
- return (result = hasOwnProperty.call(a, key) && deepEquals(a[key], b[key], stackA, stackB));
224
- }
255
+ // exit for functions and DOM nodes
256
+ if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
257
+ return false;
258
+ }
259
+ // in older versions of Opera, `arguments` objects have `Array` constructors
260
+ var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
261
+ ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
262
+
263
+ // non `Object` object instances with different constructors are not equal
264
+ if (ctorA != ctorB &&
265
+ !(hasOwnProperty.call(a, 'constructor') && hasOwnProperty.call(b, 'constructor')) &&
266
+ !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
267
+ ('constructor' in a && 'constructor' in b)
268
+ ) {
269
+ return false;
270
+ }
271
+ }
272
+ // assume cyclic structures are equal
273
+ // the algorithm for detecting cyclic structures is adapted from ES 5.1
274
+ // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
275
+ var initedStack = !stackA;
276
+ stackA || (stackA = []);
277
+ stackB || (stackB = []);
278
+
279
+ var length = stackA.length;
280
+ while (length--) {
281
+ if (stackA[length] == a) {
282
+ return stackB[length] == b;
283
+ }
284
+ }
285
+ var size = 0;
286
+ result = true;
287
+
288
+ // add `a` and `b` to the stack of traversed objects
289
+ stackA.push(a);
290
+ stackB.push(b);
291
+
292
+ // recursively compare objects and arrays (susceptible to call stack limits)
293
+ if (isArr) {
294
+ // compare lengths to determine if a deep comparison is necessary
295
+ length = a.length;
296
+ size = b.length;
297
+ result = size == length;
298
+
299
+ if (result) {
300
+ // deep compare the contents, ignoring non-numeric properties
301
+ while (size--) {
302
+ var index = length,
303
+ value = b[size];
304
+
305
+ if (!(result = deepEquals(a[size], value, stackA, stackB))) {
306
+ break;
307
+ }
225
308
  }
226
-
227
- if (result) {
228
- // ensure both objects have the same number of properties
229
- for (var key in a) {
230
- if (hasOwnProperty.call(a, key)) {
231
- // `size` will be `-1` if `a` has more properties than `b`
232
- return (result = --size > -1);
233
- }
234
- }
309
+ }
310
+ }
311
+ else {
312
+ // deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
313
+ // which, in this case, is more costly
314
+ internalForIn(b, function(value, key, b) {
315
+ if (hasOwnProperty.call(b, key)) {
316
+ // count the number of properties.
317
+ size++;
318
+ // deep compare each property value.
319
+ return (result = hasOwnProperty.call(a, key) && deepEquals(a[key], value, stackA, stackB));
235
320
  }
236
- stackA.pop();
237
- stackB.pop();
238
-
239
- return result;
321
+ });
322
+
323
+ if (result) {
324
+ // ensure both objects have the same number of properties
325
+ internalForIn(a, function(value, key, a) {
326
+ if (hasOwnProperty.call(a, key)) {
327
+ // `size` will be `-1` if `a` has more properties than `b`
328
+ return (result = --size > -1);
329
+ }
330
+ });
331
+ }
240
332
  }
333
+ stackA.pop();
334
+ stackB.pop();
335
+
336
+ return result;
337
+ }
241
338
  var slice = Array.prototype.slice;
242
339
  function argsOrArray(args, idx) {
243
340
  return args.length === 1 && Array.isArray(args[idx]) ?
@@ -247,14 +344,14 @@
247
344
  var hasProp = {}.hasOwnProperty;
248
345
 
249
346
  /** @private */
250
- var inherits = this.inherits = Rx.Internals.inherits = function (child, parent) {
347
+ var inherits = this.inherits = Rx.internals.inherits = function (child, parent) {
251
348
  function __() { this.constructor = child; }
252
349
  __.prototype = parent.prototype;
253
350
  child.prototype = new __();
254
351
  };
255
352
 
256
353
  /** @private */
257
- var addProperties = Rx.Internals.addProperties = function (obj) {
354
+ var addProperties = Rx.internals.addProperties = function (obj) {
258
355
  var sources = slice.call(arguments, 1);
259
356
  for (var i = 0, len = sources.length; i < len; i++) {
260
357
  var source = sources[i];
@@ -265,7 +362,7 @@
265
362
  };
266
363
 
267
364
  // Rx Utils
268
- var addRef = Rx.Internals.addRef = function (xs, r) {
365
+ var addRef = Rx.internals.addRef = function (xs, r) {
269
366
  return new AnonymousObservable(function (observer) {
270
367
  return new CompositeDisposable(r.getDisposable(), xs.subscribe(observer));
271
368
  });
@@ -413,7 +510,7 @@
413
510
  };
414
511
 
415
512
  // Priority Queue for Scheduling
416
- var PriorityQueue = Rx.Internals.PriorityQueue = function (capacity) {
513
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
417
514
  this.items = new Array(capacity);
418
515
  this.length = 0;
419
516
  };
@@ -760,7 +857,7 @@
760
857
  return RefCountDisposable;
761
858
  })();
762
859
 
763
- var ScheduledItem = Rx.Internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
860
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
764
861
  this.scheduler = scheduler;
765
862
  this.state = state;
766
863
  this.action = action;
@@ -1120,7 +1217,7 @@
1120
1217
  return currentScheduler;
1121
1218
  }());
1122
1219
 
1123
- var SchedulePeriodicRecursive = Rx.Internals.SchedulePeriodicRecursive = (function () {
1220
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1124
1221
  function tick(command, recurse) {
1125
1222
  recurse(0, this._period);
1126
1223
  try {
@@ -1164,8 +1261,6 @@
1164
1261
  clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1165
1262
  !reNative.test(clearImmediate) && clearImmediate;
1166
1263
 
1167
- var BrowserMutationObserver = root.MutationObserver || root.WebKitMutationObserver;
1168
-
1169
1264
  function postMessageSupported () {
1170
1265
  // Ensure not in a worker
1171
1266
  if (!root.postMessage || root.importScripts) { return false; }
@@ -1179,40 +1274,8 @@
1179
1274
  return isAsync;
1180
1275
  }
1181
1276
 
1182
- // Use in order, MutationObserver, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1183
- if (!!BrowserMutationObserver) {
1184
-
1185
- var mutationQueue = {}, mutationId = 0;
1186
-
1187
- function drainQueue (mutations) {
1188
- for (var i = 0, len = mutations.length; i < len; i++) {
1189
- var id = mutations[i].target.getAttribute('drainQueue');
1190
- mutationQueue[id]();
1191
- delete mutationQueue[id];
1192
- }
1193
- }
1194
-
1195
- var observer = new BrowserMutationObserver(drainQueue),
1196
- elem = document.createElement('div');
1197
- observer.observe(elem, { attributes: true });
1198
-
1199
- root.addEventListener('unload', function () {
1200
- observer.disconnect();
1201
- observer = null;
1202
- });
1203
-
1204
- scheduleMethod = function (action) {
1205
- var id = mutationId++;
1206
- mutationQueue[id] = action;
1207
- elem.setAttribute('drainQueue', id);
1208
- return id;
1209
- };
1210
-
1211
- clearMethod = function (id) {
1212
- delete mutationQueue[id];
1213
- }
1214
-
1215
- } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1277
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1278
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1216
1279
  scheduleMethod = process.nextTick;
1217
1280
  } else if (typeof setImmediate === 'function') {
1218
1281
  scheduleMethod = setImmediate;
@@ -1460,7 +1523,7 @@
1460
1523
  * @constructor
1461
1524
  * @private
1462
1525
  */
1463
- var Enumerator = Rx.Internals.Enumerator = function (moveNext, getCurrent) {
1526
+ var Enumerator = Rx.internals.Enumerator = function (moveNext, getCurrent) {
1464
1527
  this.moveNext = moveNext;
1465
1528
  this.getCurrent = getCurrent;
1466
1529
  };
@@ -1484,7 +1547,7 @@
1484
1547
  }, function () { return getCurrent(); });
1485
1548
  };
1486
1549
 
1487
- var Enumerable = Rx.Internals.Enumerable = function (getEnumerator) {
1550
+ var Enumerable = Rx.internals.Enumerable = function (getEnumerator) {
1488
1551
  this.getEnumerator = getEnumerator;
1489
1552
  };
1490
1553
 
@@ -1672,7 +1735,7 @@
1672
1735
  * Abstract base class for implementations of the Observer class.
1673
1736
  * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
1674
1737
  */
1675
- var AbstractObserver = Rx.Internals.AbstractObserver = (function (_super) {
1738
+ var AbstractObserver = Rx.internals.AbstractObserver = (function (_super) {
1676
1739
  inherits(AbstractObserver, _super);
1677
1740
 
1678
1741
  /**
@@ -1740,58 +1803,50 @@
1740
1803
  return AbstractObserver;
1741
1804
  }(Observer));
1742
1805
 
1743
- /**
1744
- * Class to create an Observer instance from delegate-based implementations of the on* methods.
1745
- */
1746
- var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1747
- inherits(AnonymousObserver, _super);
1806
+ /**
1807
+ * Class to create an Observer instance from delegate-based implementations of the on* methods.
1808
+ */
1809
+ var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1810
+ inherits(AnonymousObserver, _super);
1748
1811
 
1749
- /**
1750
- * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1751
- *
1752
- * @constructor
1753
- * @param {Any} onNext Observer's OnNext action implementation.
1754
- * @param {Any} onError Observer's OnError action implementation.
1755
- * @param {Any} onCompleted Observer's OnCompleted action implementation.
1756
- */
1757
- function AnonymousObserver(onNext, onError, onCompleted) {
1758
- _super.call(this);
1759
- this._onNext = onNext;
1760
- this._onError = onError;
1761
- this._onCompleted = onCompleted;
1762
- }
1812
+ /**
1813
+ * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1814
+ * @param {Any} onNext Observer's OnNext action implementation.
1815
+ * @param {Any} onError Observer's OnError action implementation.
1816
+ * @param {Any} onCompleted Observer's OnCompleted action implementation.
1817
+ */
1818
+ function AnonymousObserver(onNext, onError, onCompleted) {
1819
+ _super.call(this);
1820
+ this._onNext = onNext;
1821
+ this._onError = onError;
1822
+ this._onCompleted = onCompleted;
1823
+ }
1763
1824
 
1764
- /**
1765
- * Calls the onNext action.
1766
- *
1767
- * @memberOf AnonymousObserver
1768
- * @param {Any} value Next element in the sequence.
1769
- */
1770
- AnonymousObserver.prototype.next = function (value) {
1771
- this._onNext(value);
1772
- };
1825
+ /**
1826
+ * Calls the onNext action.
1827
+ * @param {Any} value Next element in the sequence.
1828
+ */
1829
+ AnonymousObserver.prototype.next = function (value) {
1830
+ this._onNext(value);
1831
+ };
1773
1832
 
1774
- /**
1775
- * Calls the onError action.
1776
- *
1777
- * @memberOf AnonymousObserver
1778
- * @param {Any{ error The error that has occurred.
1779
- */
1780
- AnonymousObserver.prototype.error = function (exception) {
1781
- this._onError(exception);
1782
- };
1833
+ /**
1834
+ * Calls the onError action.
1835
+ * @param {Any} error The error that has occurred.
1836
+ */
1837
+ AnonymousObserver.prototype.error = function (exception) {
1838
+ this._onError(exception);
1839
+ };
1783
1840
 
1784
- /**
1785
- * Calls the onCompleted action.
1786
- *
1787
- * @memberOf AnonymousObserver
1788
- */
1789
- AnonymousObserver.prototype.completed = function () {
1790
- this._onCompleted();
1791
- };
1841
+ /**
1842
+ * Calls the onCompleted action.
1843
+ */
1844
+ AnonymousObserver.prototype.completed = function () {
1845
+ this._onCompleted();
1846
+ };
1792
1847
 
1793
- return AnonymousObserver;
1794
- }(AbstractObserver));
1848
+ return AnonymousObserver;
1849
+ }(AbstractObserver));
1795
1850
 
1796
1851
  var observableProto;
1797
1852
 
@@ -1871,80 +1926,74 @@
1871
1926
  return Observable;
1872
1927
  })();
1873
1928
 
1874
- /** @private */
1875
- var ScheduledObserver = Rx.Internals.ScheduledObserver = (function (_super) {
1876
- inherits(ScheduledObserver, _super);
1877
-
1878
- function ScheduledObserver(scheduler, observer) {
1879
- _super.call(this);
1880
- this.scheduler = scheduler;
1881
- this.observer = observer;
1882
- this.isAcquired = false;
1883
- this.hasFaulted = false;
1884
- this.queue = [];
1885
- this.disposable = new SerialDisposable();
1886
- }
1929
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1930
+ inherits(ScheduledObserver, _super);
1931
+
1932
+ function ScheduledObserver(scheduler, observer) {
1933
+ _super.call(this);
1934
+ this.scheduler = scheduler;
1935
+ this.observer = observer;
1936
+ this.isAcquired = false;
1937
+ this.hasFaulted = false;
1938
+ this.queue = [];
1939
+ this.disposable = new SerialDisposable();
1940
+ }
1887
1941
 
1888
- /** @private */
1889
- ScheduledObserver.prototype.next = function (value) {
1890
- var self = this;
1891
- this.queue.push(function () {
1892
- self.observer.onNext(value);
1893
- });
1894
- };
1942
+ ScheduledObserver.prototype.next = function (value) {
1943
+ var self = this;
1944
+ this.queue.push(function () {
1945
+ self.observer.onNext(value);
1946
+ });
1947
+ };
1895
1948
 
1896
- /** @private */
1897
- ScheduledObserver.prototype.error = function (exception) {
1898
- var self = this;
1899
- this.queue.push(function () {
1900
- self.observer.onError(exception);
1901
- });
1902
- };
1949
+ ScheduledObserver.prototype.error = function (exception) {
1950
+ var self = this;
1951
+ this.queue.push(function () {
1952
+ self.observer.onError(exception);
1953
+ });
1954
+ };
1903
1955
 
1904
- /** @private */
1905
- ScheduledObserver.prototype.completed = function () {
1906
- var self = this;
1907
- this.queue.push(function () {
1908
- self.observer.onCompleted();
1909
- });
1910
- };
1956
+ ScheduledObserver.prototype.completed = function () {
1957
+ var self = this;
1958
+ this.queue.push(function () {
1959
+ self.observer.onCompleted();
1960
+ });
1961
+ };
1911
1962
 
1912
- /** @private */
1913
- ScheduledObserver.prototype.ensureActive = function () {
1914
- var isOwner = false, parent = this;
1915
- if (!this.hasFaulted && this.queue.length > 0) {
1916
- isOwner = !this.isAcquired;
1917
- this.isAcquired = true;
1918
- }
1919
- if (isOwner) {
1920
- this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
1921
- var work;
1922
- if (parent.queue.length > 0) {
1923
- work = parent.queue.shift();
1924
- } else {
1925
- parent.isAcquired = false;
1926
- return;
1927
- }
1928
- try {
1929
- work();
1930
- } catch (ex) {
1931
- parent.queue = [];
1932
- parent.hasFaulted = true;
1933
- throw ex;
1934
- }
1935
- self();
1936
- }));
1937
- }
1938
- };
1963
+ ScheduledObserver.prototype.ensureActive = function () {
1964
+ var isOwner = false, parent = this;
1965
+ if (!this.hasFaulted && this.queue.length > 0) {
1966
+ isOwner = !this.isAcquired;
1967
+ this.isAcquired = true;
1968
+ }
1969
+ if (isOwner) {
1970
+ this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
1971
+ var work;
1972
+ if (parent.queue.length > 0) {
1973
+ work = parent.queue.shift();
1974
+ } else {
1975
+ parent.isAcquired = false;
1976
+ return;
1977
+ }
1978
+ try {
1979
+ work();
1980
+ } catch (ex) {
1981
+ parent.queue = [];
1982
+ parent.hasFaulted = true;
1983
+ throw ex;
1984
+ }
1985
+ self();
1986
+ }));
1987
+ }
1988
+ };
1939
1989
 
1940
- /** @private */
1941
- ScheduledObserver.prototype.dispose = function () {
1942
- _super.prototype.dispose.call(this);
1943
- this.disposable.dispose();
1944
- };
1990
+ ScheduledObserver.prototype.dispose = function () {
1991
+ _super.prototype.dispose.call(this);
1992
+ this.disposable.dispose();
1993
+ };
1945
1994
 
1946
- return ScheduledObserver;
1947
- }(AbstractObserver));
1995
+ return ScheduledObserver;
1996
+ }(AbstractObserver));
1948
1997
 
1949
1998
  /**
1950
1999
  * Creates an observable sequence from a specified subscribe method implementation.
@@ -2023,6 +2072,38 @@
2023
2072
  });
2024
2073
  };
2025
2074
 
2075
+ /**
2076
+ * Converts a generator function to an observable sequence, using an optional scheduler to enumerate the generator.
2077
+ *
2078
+ * @example
2079
+ * var res = Rx.Observable.fromGenerator(function* () { yield 42; });
2080
+ * var res = Rx.Observable.fromArray(function* () { yield 42; }, Rx.Scheduler.timeout);
2081
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2082
+ * @returns {Observable} The observable sequence whose elements are pulled from the given generator sequence.
2083
+ */
2084
+ observableProto.fromGenerator = function (genFn, scheduler) {
2085
+ scheduler || (scheduler = currentThreadScheduler);
2086
+ return new AnonymousObservable(function (observer) {
2087
+ var gen;
2088
+ try {
2089
+ gen = genFn();
2090
+ } catch (e) {
2091
+ observer.onError(e);
2092
+ return;
2093
+ }
2094
+
2095
+ return scheduler.scheduleRecursive(function (self) {
2096
+ var next = gen.next();
2097
+ if (next.done) {
2098
+ observer.onCompleted();
2099
+ } else {
2100
+ observer.onNext(next.value);
2101
+ self();
2102
+ }
2103
+ });
2104
+ });
2105
+ };
2106
+
2026
2107
  /**
2027
2108
  * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
2028
2109
  *
@@ -2351,6 +2432,10 @@
2351
2432
  subscribe = function (xs) {
2352
2433
  var subscription = new SingleAssignmentDisposable();
2353
2434
  group.add(subscription);
2435
+
2436
+ // Check for promises support
2437
+ if (isPromise(xs)) { xs = observableFromPromise(xs); }
2438
+
2354
2439
  subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2355
2440
  var s;
2356
2441
  group.remove(subscription);
@@ -2411,37 +2496,40 @@
2411
2496
  return observableFromArray(sources, scheduler).mergeObservable();
2412
2497
  };
2413
2498
 
2414
- /**
2415
- * Merges an observable sequence of observable sequences into an observable sequence.
2416
- * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2417
- */
2418
- observableProto.mergeObservable = observableProto.mergeAll =function () {
2419
- var sources = this;
2420
- return new AnonymousObservable(function (observer) {
2421
- var group = new CompositeDisposable(),
2422
- isStopped = false,
2423
- m = new SingleAssignmentDisposable();
2424
- group.add(m);
2425
- m.setDisposable(sources.subscribe(function (innerSource) {
2426
- var innerSubscription = new SingleAssignmentDisposable();
2427
- group.add(innerSubscription);
2428
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2429
- observer.onNext(x);
2430
- }, observer.onError.bind(observer), function () {
2431
- group.remove(innerSubscription);
2432
- if (isStopped && group.length === 1) {
2433
- observer.onCompleted();
2434
- }
2435
- }));
2436
- }, observer.onError.bind(observer), function () {
2437
- isStopped = true;
2438
- if (group.length === 1) {
2439
- observer.onCompleted();
2440
- }
2441
- }));
2442
- return group;
2443
- });
2444
- };
2499
+ /**
2500
+ * Merges an observable sequence of observable sequences into an observable sequence.
2501
+ * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2502
+ */
2503
+ observableProto.mergeObservable = observableProto.mergeAll =function () {
2504
+ var sources = this;
2505
+ return new AnonymousObservable(function (observer) {
2506
+ var group = new CompositeDisposable(),
2507
+ isStopped = false,
2508
+ m = new SingleAssignmentDisposable();
2509
+
2510
+ group.add(m);
2511
+ m.setDisposable(sources.subscribe(function (innerSource) {
2512
+ var innerSubscription = new SingleAssignmentDisposable();
2513
+ group.add(innerSubscription);
2514
+
2515
+ // Check if Promise or Observable
2516
+ if (isPromise(innerSource)) {
2517
+ innerSource = observableFromPromise(innerSource);
2518
+ }
2519
+
2520
+ innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2521
+ observer.onNext(x);
2522
+ }, observer.onError.bind(observer), function () {
2523
+ group.remove(innerSubscription);
2524
+ if (isStopped && group.length === 1) { observer.onCompleted(); }
2525
+ }));
2526
+ }, observer.onError.bind(observer), function () {
2527
+ isStopped = true;
2528
+ if (group.length === 1) { observer.onCompleted(); }
2529
+ }));
2530
+ return group;
2531
+ });
2532
+ };
2445
2533
 
2446
2534
  /**
2447
2535
  * Returns the values from the source observable sequence only after the other observable sequence produces a value.
@@ -2490,6 +2578,12 @@
2490
2578
  var d = new SingleAssignmentDisposable(), id = ++latest;
2491
2579
  hasLatest = true;
2492
2580
  innerSubscription.setDisposable(d);
2581
+
2582
+ // Check if Promise or Observable
2583
+ if (isPromise(innerSource)) {
2584
+ innerSource = observableFromPromise(innerSource);
2585
+ }
2586
+
2493
2587
  d.setDisposable(innerSource.subscribe(function (x) {
2494
2588
  if (latest === id) {
2495
2589
  observer.onNext(x);
@@ -3040,7 +3134,10 @@
3040
3134
  };
3041
3135
 
3042
3136
  function selectMany(selector) {
3043
- return this.select(selector).mergeObservable();
3137
+ return this.select(function (x, i) {
3138
+ var result = selector(x, i);
3139
+ return isPromise(result) ? observableFromPromise(result) : result;
3140
+ }).mergeObservable();
3044
3141
  }
3045
3142
 
3046
3143
  /**
@@ -3057,24 +3154,28 @@
3057
3154
  * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3058
3155
  *
3059
3156
  * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3060
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto.
3157
+ * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3158
+ * source sequence onto which could be either an observable or Promise.
3061
3159
  * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3062
3160
  * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3063
3161
  */
3064
3162
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector) {
3065
- if (resultSelector) {
3066
- return this.selectMany(function (x) {
3067
- return selector(x).select(function (y) {
3068
- return resultSelector(x, y);
3069
- });
3163
+ if (resultSelector) {
3164
+ return this.selectMany(function (x, i) {
3165
+ var selectorResult = selector(x, i),
3166
+ result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3167
+
3168
+ return result.select(function (y) {
3169
+ return resultSelector(x, y, i);
3070
3170
  });
3071
- }
3072
- if (typeof selector === 'function') {
3073
- return selectMany.call(this, selector);
3074
- }
3075
- return selectMany.call(this, function () {
3076
- return selector;
3077
- });
3171
+ });
3172
+ }
3173
+ if (typeof selector === 'function') {
3174
+ return selectMany.call(this, selector);
3175
+ }
3176
+ return selectMany.call(this, function () {
3177
+ return selector;
3178
+ });
3078
3179
  };
3079
3180
 
3080
3181
  /**
@@ -3488,31 +3589,39 @@
3488
3589
  }).publish().refCount();
3489
3590
  };
3490
3591
 
3491
- /**
3492
- * Converts a Promise to an Observable sequence
3493
- * @param {Promise} A Promises A+ implementation instance.
3494
- * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
3495
- */
3496
- Observable.fromPromise = function (promise) {
3497
- return new AnonymousObservable(function (observer) {
3498
- promise.then(
3499
- function (value) {
3500
- observer.onNext(value);
3501
- observer.onCompleted();
3502
- },
3503
- function (reason) {
3504
- observer.onError(reason);
3505
- });
3592
+ /**
3593
+ * Converts a Promise to an Observable sequence
3594
+ * @param {Promise} An ES6 Compliant promise.
3595
+ * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
3596
+ */
3597
+ var observableFromPromise = Observable.fromPromise = function (promise) {
3598
+ return new AnonymousObservable(function (observer) {
3599
+ promise.then(
3600
+ function (value) {
3601
+ observer.onNext(value);
3602
+ observer.onCompleted();
3603
+ },
3604
+ function (reason) {
3605
+ observer.onError(reason);
3506
3606
  });
3507
- };
3607
+ });
3608
+ };
3508
3609
  /*
3509
3610
  * Converts an existing observable sequence to an ES6 Compatible Promise
3510
3611
  * @example
3511
3612
  * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
3512
- * @param {Function} The constructor of the promise
3613
+ *
3614
+ * // With config
3615
+ * Rx.config.Promise = RSVP.Promise;
3616
+ * var promise = Rx.Observable.return(42).toPromise();
3617
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
3513
3618
  * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
3514
3619
  */
3515
3620
  observableProto.toPromise = function (promiseCtor) {
3621
+ promiseCtor || (promiseCtor = Rx.config.Promise);
3622
+ if (!promiseCtor) {
3623
+ throw new Error('Promise type not provided nor in Rx.config.Promise');
3624
+ }
3516
3625
  var source = this;
3517
3626
  return new promiseCtor(function (resolve, reject) {
3518
3627
  // No cancellation can be done
@@ -3529,6 +3638,21 @@
3529
3638
  });
3530
3639
  });
3531
3640
  };
3641
+ /**
3642
+ * Invokes the asynchronous function, surfacing the result through an observable sequence.
3643
+ * @param {Function} functionAsync Asynchronous function which returns a Promise to run.
3644
+ * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
3645
+ */
3646
+ Observable.startAsync = function (functionAsync) {
3647
+ var promise;
3648
+ try {
3649
+ promise = functionAsync();
3650
+ } catch (e) {
3651
+ return observableThrow(e);
3652
+ }
3653
+ return observableFromPromise(promise);
3654
+ }
3655
+
3532
3656
  /**
3533
3657
  * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
3534
3658
  * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
@@ -4543,7 +4667,34 @@
4543
4667
  });
4544
4668
  };
4545
4669
 
4546
- var AnonymousObservable = Rx.Internals.AnonymousObservable = (function (_super) {
4670
+ /**
4671
+ * Pauses the underlying observable sequence based upon the observable sequence which yields true/false.
4672
+ * @example
4673
+ * var pauser = new Rx.Subject();
4674
+ * var source = Rx.Observable.interval(100).pausable(pauser);
4675
+ * @param {Observable} pauser The observable sequence used to pause the underlying sequence.
4676
+ * @returns {Observable} The observable sequence which is paused based upon the pauser.
4677
+ */
4678
+ observableProto.pausable = function (pauser) {
4679
+ var self = this;
4680
+ return new AnonymousObservable(function (observer) {
4681
+ var conn = self.publish(),
4682
+ subscription = conn.subscribe(observer),
4683
+ connection = disposableEmpty;
4684
+
4685
+ var pausable = pauser.distinctUntilChanged().subscribe(function (b) {
4686
+ if (b) {
4687
+ connection = conn.connect();
4688
+ } else {
4689
+ connection.dispose();
4690
+ connection = disposableEmpty;
4691
+ }
4692
+ });
4693
+
4694
+ return new CompositeDisposable(subscription, connection, pausable);
4695
+ });
4696
+ };
4697
+ var AnonymousObservable = Rx.AnonymousObservable = (function (_super) {
4547
4698
  inherits(AnonymousObservable, _super);
4548
4699
 
4549
4700
  // Fix subscriber to check for undefined or function returned to decorate as Disposable