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
  });
@@ -295,7 +392,7 @@
295
392
  };
296
393
 
297
394
  // Priority Queue for Scheduling
298
- var PriorityQueue = Rx.Internals.PriorityQueue = function (capacity) {
395
+ var PriorityQueue = Rx.internals.PriorityQueue = function (capacity) {
299
396
  this.items = new Array(capacity);
300
397
  this.length = 0;
301
398
  };
@@ -642,7 +739,7 @@
642
739
  return RefCountDisposable;
643
740
  })();
644
741
 
645
- var ScheduledItem = Rx.Internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
742
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
646
743
  this.scheduler = scheduler;
647
744
  this.state = state;
648
745
  this.action = action;
@@ -1002,7 +1099,7 @@
1002
1099
  return currentScheduler;
1003
1100
  }());
1004
1101
 
1005
- var SchedulePeriodicRecursive = Rx.Internals.SchedulePeriodicRecursive = (function () {
1102
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1006
1103
  function tick(command, recurse) {
1007
1104
  recurse(0, this._period);
1008
1105
  try {
@@ -1046,8 +1143,6 @@
1046
1143
  clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1047
1144
  !reNative.test(clearImmediate) && clearImmediate;
1048
1145
 
1049
- var BrowserMutationObserver = root.MutationObserver || root.WebKitMutationObserver;
1050
-
1051
1146
  function postMessageSupported () {
1052
1147
  // Ensure not in a worker
1053
1148
  if (!root.postMessage || root.importScripts) { return false; }
@@ -1061,40 +1156,8 @@
1061
1156
  return isAsync;
1062
1157
  }
1063
1158
 
1064
- // Use in order, MutationObserver, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1065
- if (!!BrowserMutationObserver) {
1066
-
1067
- var mutationQueue = {}, mutationId = 0;
1068
-
1069
- function drainQueue (mutations) {
1070
- for (var i = 0, len = mutations.length; i < len; i++) {
1071
- var id = mutations[i].target.getAttribute('drainQueue');
1072
- mutationQueue[id]();
1073
- delete mutationQueue[id];
1074
- }
1075
- }
1076
-
1077
- var observer = new BrowserMutationObserver(drainQueue),
1078
- elem = document.createElement('div');
1079
- observer.observe(elem, { attributes: true });
1080
-
1081
- root.addEventListener('unload', function () {
1082
- observer.disconnect();
1083
- observer = null;
1084
- });
1085
-
1086
- scheduleMethod = function (action) {
1087
- var id = mutationId++;
1088
- mutationQueue[id] = action;
1089
- elem.setAttribute('drainQueue', id);
1090
- return id;
1091
- };
1092
-
1093
- clearMethod = function (id) {
1094
- delete mutationQueue[id];
1095
- }
1096
-
1097
- } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1159
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1160
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1098
1161
  scheduleMethod = process.nextTick;
1099
1162
  } else if (typeof setImmediate === 'function') {
1100
1163
  scheduleMethod = setImmediate;
@@ -1342,7 +1405,7 @@
1342
1405
  * @constructor
1343
1406
  * @private
1344
1407
  */
1345
- var Enumerator = Rx.Internals.Enumerator = function (moveNext, getCurrent) {
1408
+ var Enumerator = Rx.internals.Enumerator = function (moveNext, getCurrent) {
1346
1409
  this.moveNext = moveNext;
1347
1410
  this.getCurrent = getCurrent;
1348
1411
  };
@@ -1366,7 +1429,7 @@
1366
1429
  }, function () { return getCurrent(); });
1367
1430
  };
1368
1431
 
1369
- var Enumerable = Rx.Internals.Enumerable = function (getEnumerator) {
1432
+ var Enumerable = Rx.internals.Enumerable = function (getEnumerator) {
1370
1433
  this.getEnumerator = getEnumerator;
1371
1434
  };
1372
1435
 
@@ -1554,7 +1617,7 @@
1554
1617
  * Abstract base class for implementations of the Observer class.
1555
1618
  * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
1556
1619
  */
1557
- var AbstractObserver = Rx.Internals.AbstractObserver = (function (_super) {
1620
+ var AbstractObserver = Rx.internals.AbstractObserver = (function (_super) {
1558
1621
  inherits(AbstractObserver, _super);
1559
1622
 
1560
1623
  /**
@@ -1622,58 +1685,50 @@
1622
1685
  return AbstractObserver;
1623
1686
  }(Observer));
1624
1687
 
1625
- /**
1626
- * Class to create an Observer instance from delegate-based implementations of the on* methods.
1627
- */
1628
- var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1629
- inherits(AnonymousObserver, _super);
1688
+ /**
1689
+ * Class to create an Observer instance from delegate-based implementations of the on* methods.
1690
+ */
1691
+ var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1692
+ inherits(AnonymousObserver, _super);
1630
1693
 
1631
- /**
1632
- * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1633
- *
1634
- * @constructor
1635
- * @param {Any} onNext Observer's OnNext action implementation.
1636
- * @param {Any} onError Observer's OnError action implementation.
1637
- * @param {Any} onCompleted Observer's OnCompleted action implementation.
1638
- */
1639
- function AnonymousObserver(onNext, onError, onCompleted) {
1640
- _super.call(this);
1641
- this._onNext = onNext;
1642
- this._onError = onError;
1643
- this._onCompleted = onCompleted;
1644
- }
1694
+ /**
1695
+ * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1696
+ * @param {Any} onNext Observer's OnNext action implementation.
1697
+ * @param {Any} onError Observer's OnError action implementation.
1698
+ * @param {Any} onCompleted Observer's OnCompleted action implementation.
1699
+ */
1700
+ function AnonymousObserver(onNext, onError, onCompleted) {
1701
+ _super.call(this);
1702
+ this._onNext = onNext;
1703
+ this._onError = onError;
1704
+ this._onCompleted = onCompleted;
1705
+ }
1645
1706
 
1646
- /**
1647
- * Calls the onNext action.
1648
- *
1649
- * @memberOf AnonymousObserver
1650
- * @param {Any} value Next element in the sequence.
1651
- */
1652
- AnonymousObserver.prototype.next = function (value) {
1653
- this._onNext(value);
1654
- };
1707
+ /**
1708
+ * Calls the onNext action.
1709
+ * @param {Any} value Next element in the sequence.
1710
+ */
1711
+ AnonymousObserver.prototype.next = function (value) {
1712
+ this._onNext(value);
1713
+ };
1655
1714
 
1656
- /**
1657
- * Calls the onError action.
1658
- *
1659
- * @memberOf AnonymousObserver
1660
- * @param {Any{ error The error that has occurred.
1661
- */
1662
- AnonymousObserver.prototype.error = function (exception) {
1663
- this._onError(exception);
1664
- };
1715
+ /**
1716
+ * Calls the onError action.
1717
+ * @param {Any} error The error that has occurred.
1718
+ */
1719
+ AnonymousObserver.prototype.error = function (exception) {
1720
+ this._onError(exception);
1721
+ };
1665
1722
 
1666
- /**
1667
- * Calls the onCompleted action.
1668
- *
1669
- * @memberOf AnonymousObserver
1670
- */
1671
- AnonymousObserver.prototype.completed = function () {
1672
- this._onCompleted();
1673
- };
1723
+ /**
1724
+ * Calls the onCompleted action.
1725
+ */
1726
+ AnonymousObserver.prototype.completed = function () {
1727
+ this._onCompleted();
1728
+ };
1674
1729
 
1675
- return AnonymousObserver;
1676
- }(AbstractObserver));
1730
+ return AnonymousObserver;
1731
+ }(AbstractObserver));
1677
1732
 
1678
1733
  var observableProto;
1679
1734
 
@@ -1753,80 +1808,74 @@
1753
1808
  return Observable;
1754
1809
  })();
1755
1810
 
1756
- /** @private */
1757
- var ScheduledObserver = Rx.Internals.ScheduledObserver = (function (_super) {
1758
- inherits(ScheduledObserver, _super);
1759
-
1760
- function ScheduledObserver(scheduler, observer) {
1761
- _super.call(this);
1762
- this.scheduler = scheduler;
1763
- this.observer = observer;
1764
- this.isAcquired = false;
1765
- this.hasFaulted = false;
1766
- this.queue = [];
1767
- this.disposable = new SerialDisposable();
1768
- }
1811
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
1812
+ inherits(ScheduledObserver, _super);
1813
+
1814
+ function ScheduledObserver(scheduler, observer) {
1815
+ _super.call(this);
1816
+ this.scheduler = scheduler;
1817
+ this.observer = observer;
1818
+ this.isAcquired = false;
1819
+ this.hasFaulted = false;
1820
+ this.queue = [];
1821
+ this.disposable = new SerialDisposable();
1822
+ }
1769
1823
 
1770
- /** @private */
1771
- ScheduledObserver.prototype.next = function (value) {
1772
- var self = this;
1773
- this.queue.push(function () {
1774
- self.observer.onNext(value);
1775
- });
1776
- };
1824
+ ScheduledObserver.prototype.next = function (value) {
1825
+ var self = this;
1826
+ this.queue.push(function () {
1827
+ self.observer.onNext(value);
1828
+ });
1829
+ };
1777
1830
 
1778
- /** @private */
1779
- ScheduledObserver.prototype.error = function (exception) {
1780
- var self = this;
1781
- this.queue.push(function () {
1782
- self.observer.onError(exception);
1783
- });
1784
- };
1831
+ ScheduledObserver.prototype.error = function (exception) {
1832
+ var self = this;
1833
+ this.queue.push(function () {
1834
+ self.observer.onError(exception);
1835
+ });
1836
+ };
1785
1837
 
1786
- /** @private */
1787
- ScheduledObserver.prototype.completed = function () {
1788
- var self = this;
1789
- this.queue.push(function () {
1790
- self.observer.onCompleted();
1791
- });
1792
- };
1838
+ ScheduledObserver.prototype.completed = function () {
1839
+ var self = this;
1840
+ this.queue.push(function () {
1841
+ self.observer.onCompleted();
1842
+ });
1843
+ };
1793
1844
 
1794
- /** @private */
1795
- ScheduledObserver.prototype.ensureActive = function () {
1796
- var isOwner = false, parent = this;
1797
- if (!this.hasFaulted && this.queue.length > 0) {
1798
- isOwner = !this.isAcquired;
1799
- this.isAcquired = true;
1800
- }
1801
- if (isOwner) {
1802
- this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
1803
- var work;
1804
- if (parent.queue.length > 0) {
1805
- work = parent.queue.shift();
1806
- } else {
1807
- parent.isAcquired = false;
1808
- return;
1809
- }
1810
- try {
1811
- work();
1812
- } catch (ex) {
1813
- parent.queue = [];
1814
- parent.hasFaulted = true;
1815
- throw ex;
1816
- }
1817
- self();
1818
- }));
1819
- }
1820
- };
1845
+ ScheduledObserver.prototype.ensureActive = function () {
1846
+ var isOwner = false, parent = this;
1847
+ if (!this.hasFaulted && this.queue.length > 0) {
1848
+ isOwner = !this.isAcquired;
1849
+ this.isAcquired = true;
1850
+ }
1851
+ if (isOwner) {
1852
+ this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
1853
+ var work;
1854
+ if (parent.queue.length > 0) {
1855
+ work = parent.queue.shift();
1856
+ } else {
1857
+ parent.isAcquired = false;
1858
+ return;
1859
+ }
1860
+ try {
1861
+ work();
1862
+ } catch (ex) {
1863
+ parent.queue = [];
1864
+ parent.hasFaulted = true;
1865
+ throw ex;
1866
+ }
1867
+ self();
1868
+ }));
1869
+ }
1870
+ };
1821
1871
 
1822
- /** @private */
1823
- ScheduledObserver.prototype.dispose = function () {
1824
- _super.prototype.dispose.call(this);
1825
- this.disposable.dispose();
1826
- };
1872
+ ScheduledObserver.prototype.dispose = function () {
1873
+ _super.prototype.dispose.call(this);
1874
+ this.disposable.dispose();
1875
+ };
1827
1876
 
1828
- return ScheduledObserver;
1829
- }(AbstractObserver));
1877
+ return ScheduledObserver;
1878
+ }(AbstractObserver));
1830
1879
 
1831
1880
  /**
1832
1881
  * Creates an observable sequence from a specified subscribe method implementation.
@@ -1905,6 +1954,38 @@
1905
1954
  });
1906
1955
  };
1907
1956
 
1957
+ /**
1958
+ * Converts a generator function to an observable sequence, using an optional scheduler to enumerate the generator.
1959
+ *
1960
+ * @example
1961
+ * var res = Rx.Observable.fromGenerator(function* () { yield 42; });
1962
+ * var res = Rx.Observable.fromArray(function* () { yield 42; }, Rx.Scheduler.timeout);
1963
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
1964
+ * @returns {Observable} The observable sequence whose elements are pulled from the given generator sequence.
1965
+ */
1966
+ observableProto.fromGenerator = function (genFn, scheduler) {
1967
+ scheduler || (scheduler = currentThreadScheduler);
1968
+ return new AnonymousObservable(function (observer) {
1969
+ var gen;
1970
+ try {
1971
+ gen = genFn();
1972
+ } catch (e) {
1973
+ observer.onError(e);
1974
+ return;
1975
+ }
1976
+
1977
+ return scheduler.scheduleRecursive(function (self) {
1978
+ var next = gen.next();
1979
+ if (next.done) {
1980
+ observer.onCompleted();
1981
+ } else {
1982
+ observer.onNext(next.value);
1983
+ self();
1984
+ }
1985
+ });
1986
+ });
1987
+ };
1988
+
1908
1989
  /**
1909
1990
  * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
1910
1991
  *
@@ -2233,6 +2314,10 @@
2233
2314
  subscribe = function (xs) {
2234
2315
  var subscription = new SingleAssignmentDisposable();
2235
2316
  group.add(subscription);
2317
+
2318
+ // Check for promises support
2319
+ if (isPromise(xs)) { xs = observableFromPromise(xs); }
2320
+
2236
2321
  subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2237
2322
  var s;
2238
2323
  group.remove(subscription);
@@ -2293,37 +2378,40 @@
2293
2378
  return observableFromArray(sources, scheduler).mergeObservable();
2294
2379
  };
2295
2380
 
2296
- /**
2297
- * Merges an observable sequence of observable sequences into an observable sequence.
2298
- * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2299
- */
2300
- observableProto.mergeObservable = observableProto.mergeAll =function () {
2301
- var sources = this;
2302
- return new AnonymousObservable(function (observer) {
2303
- var group = new CompositeDisposable(),
2304
- isStopped = false,
2305
- m = new SingleAssignmentDisposable();
2306
- group.add(m);
2307
- m.setDisposable(sources.subscribe(function (innerSource) {
2308
- var innerSubscription = new SingleAssignmentDisposable();
2309
- group.add(innerSubscription);
2310
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2311
- observer.onNext(x);
2312
- }, observer.onError.bind(observer), function () {
2313
- group.remove(innerSubscription);
2314
- if (isStopped && group.length === 1) {
2315
- observer.onCompleted();
2316
- }
2317
- }));
2318
- }, observer.onError.bind(observer), function () {
2319
- isStopped = true;
2320
- if (group.length === 1) {
2321
- observer.onCompleted();
2322
- }
2323
- }));
2324
- return group;
2325
- });
2326
- };
2381
+ /**
2382
+ * Merges an observable sequence of observable sequences into an observable sequence.
2383
+ * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2384
+ */
2385
+ observableProto.mergeObservable = observableProto.mergeAll =function () {
2386
+ var sources = this;
2387
+ return new AnonymousObservable(function (observer) {
2388
+ var group = new CompositeDisposable(),
2389
+ isStopped = false,
2390
+ m = new SingleAssignmentDisposable();
2391
+
2392
+ group.add(m);
2393
+ m.setDisposable(sources.subscribe(function (innerSource) {
2394
+ var innerSubscription = new SingleAssignmentDisposable();
2395
+ group.add(innerSubscription);
2396
+
2397
+ // Check if Promise or Observable
2398
+ if (isPromise(innerSource)) {
2399
+ innerSource = observableFromPromise(innerSource);
2400
+ }
2401
+
2402
+ innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2403
+ observer.onNext(x);
2404
+ }, observer.onError.bind(observer), function () {
2405
+ group.remove(innerSubscription);
2406
+ if (isStopped && group.length === 1) { observer.onCompleted(); }
2407
+ }));
2408
+ }, observer.onError.bind(observer), function () {
2409
+ isStopped = true;
2410
+ if (group.length === 1) { observer.onCompleted(); }
2411
+ }));
2412
+ return group;
2413
+ });
2414
+ };
2327
2415
 
2328
2416
  /**
2329
2417
  * Returns the values from the source observable sequence only after the other observable sequence produces a value.
@@ -2372,6 +2460,12 @@
2372
2460
  var d = new SingleAssignmentDisposable(), id = ++latest;
2373
2461
  hasLatest = true;
2374
2462
  innerSubscription.setDisposable(d);
2463
+
2464
+ // Check if Promise or Observable
2465
+ if (isPromise(innerSource)) {
2466
+ innerSource = observableFromPromise(innerSource);
2467
+ }
2468
+
2375
2469
  d.setDisposable(innerSource.subscribe(function (x) {
2376
2470
  if (latest === id) {
2377
2471
  observer.onNext(x);
@@ -2922,7 +3016,10 @@
2922
3016
  };
2923
3017
 
2924
3018
  function selectMany(selector) {
2925
- return this.select(selector).mergeObservable();
3019
+ return this.select(function (x, i) {
3020
+ var result = selector(x, i);
3021
+ return isPromise(result) ? observableFromPromise(result) : result;
3022
+ }).mergeObservable();
2926
3023
  }
2927
3024
 
2928
3025
  /**
@@ -2939,24 +3036,28 @@
2939
3036
  * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
2940
3037
  *
2941
3038
  * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
2942
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto.
3039
+ * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3040
+ * source sequence onto which could be either an observable or Promise.
2943
3041
  * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
2944
3042
  * @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.
2945
3043
  */
2946
3044
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector) {
2947
- if (resultSelector) {
2948
- return this.selectMany(function (x) {
2949
- return selector(x).select(function (y) {
2950
- return resultSelector(x, y);
2951
- });
3045
+ if (resultSelector) {
3046
+ return this.selectMany(function (x, i) {
3047
+ var selectorResult = selector(x, i),
3048
+ result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3049
+
3050
+ return result.select(function (y) {
3051
+ return resultSelector(x, y, i);
2952
3052
  });
2953
- }
2954
- if (typeof selector === 'function') {
2955
- return selectMany.call(this, selector);
2956
- }
2957
- return selectMany.call(this, function () {
2958
- return selector;
2959
- });
3053
+ });
3054
+ }
3055
+ if (typeof selector === 'function') {
3056
+ return selectMany.call(this, selector);
3057
+ }
3058
+ return selectMany.call(this, function () {
3059
+ return selector;
3060
+ });
2960
3061
  };
2961
3062
 
2962
3063
  /**
@@ -3300,31 +3401,39 @@
3300
3401
  }).publish().refCount();
3301
3402
  };
3302
3403
 
3303
- /**
3304
- * Converts a Promise to an Observable sequence
3305
- * @param {Promise} A Promises A+ implementation instance.
3306
- * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
3307
- */
3308
- Observable.fromPromise = function (promise) {
3309
- return new AnonymousObservable(function (observer) {
3310
- promise.then(
3311
- function (value) {
3312
- observer.onNext(value);
3313
- observer.onCompleted();
3314
- },
3315
- function (reason) {
3316
- observer.onError(reason);
3317
- });
3404
+ /**
3405
+ * Converts a Promise to an Observable sequence
3406
+ * @param {Promise} An ES6 Compliant promise.
3407
+ * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
3408
+ */
3409
+ var observableFromPromise = Observable.fromPromise = function (promise) {
3410
+ return new AnonymousObservable(function (observer) {
3411
+ promise.then(
3412
+ function (value) {
3413
+ observer.onNext(value);
3414
+ observer.onCompleted();
3415
+ },
3416
+ function (reason) {
3417
+ observer.onError(reason);
3318
3418
  });
3319
- };
3419
+ });
3420
+ };
3320
3421
  /*
3321
3422
  * Converts an existing observable sequence to an ES6 Compatible Promise
3322
3423
  * @example
3323
3424
  * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
3324
- * @param {Function} The constructor of the promise
3425
+ *
3426
+ * // With config
3427
+ * Rx.config.Promise = RSVP.Promise;
3428
+ * var promise = Rx.Observable.return(42).toPromise();
3429
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
3325
3430
  * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
3326
3431
  */
3327
3432
  observableProto.toPromise = function (promiseCtor) {
3433
+ promiseCtor || (promiseCtor = Rx.config.Promise);
3434
+ if (!promiseCtor) {
3435
+ throw new Error('Promise type not provided nor in Rx.config.Promise');
3436
+ }
3328
3437
  var source = this;
3329
3438
  return new promiseCtor(function (resolve, reject) {
3330
3439
  // No cancellation can be done
@@ -3341,6 +3450,21 @@
3341
3450
  });
3342
3451
  });
3343
3452
  };
3453
+ /**
3454
+ * Invokes the asynchronous function, surfacing the result through an observable sequence.
3455
+ * @param {Function} functionAsync Asynchronous function which returns a Promise to run.
3456
+ * @returns {Observable} An observable sequence exposing the function's result value, or an exception.
3457
+ */
3458
+ Observable.startAsync = function (functionAsync) {
3459
+ var promise;
3460
+ try {
3461
+ promise = functionAsync();
3462
+ } catch (e) {
3463
+ return observableThrow(e);
3464
+ }
3465
+ return observableFromPromise(promise);
3466
+ }
3467
+
3344
3468
  /**
3345
3469
  * Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each
3346
3470
  * subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's
@@ -4355,7 +4479,34 @@
4355
4479
  });
4356
4480
  };
4357
4481
 
4358
- var AnonymousObservable = Rx.Internals.AnonymousObservable = (function (_super) {
4482
+ /**
4483
+ * Pauses the underlying observable sequence based upon the observable sequence which yields true/false.
4484
+ * @example
4485
+ * var pauser = new Rx.Subject();
4486
+ * var source = Rx.Observable.interval(100).pausable(pauser);
4487
+ * @param {Observable} pauser The observable sequence used to pause the underlying sequence.
4488
+ * @returns {Observable} The observable sequence which is paused based upon the pauser.
4489
+ */
4490
+ observableProto.pausable = function (pauser) {
4491
+ var self = this;
4492
+ return new AnonymousObservable(function (observer) {
4493
+ var conn = self.publish(),
4494
+ subscription = conn.subscribe(observer),
4495
+ connection = disposableEmpty;
4496
+
4497
+ var pausable = pauser.distinctUntilChanged().subscribe(function (b) {
4498
+ if (b) {
4499
+ connection = conn.connect();
4500
+ } else {
4501
+ connection.dispose();
4502
+ connection = disposableEmpty;
4503
+ }
4504
+ });
4505
+
4506
+ return new CompositeDisposable(subscription, connection, pausable);
4507
+ });
4508
+ };
4509
+ var AnonymousObservable = Rx.AnonymousObservable = (function (_super) {
4359
4510
  inherits(AnonymousObservable, _super);
4360
4511
 
4361
4512
  // Fix subscriber to check for undefined or function returned to decorate as Disposable