rxjs-rails 2.2.13 → 2.2.14

Sign up to get free protection for your applications and to get access to all the features.
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;
112
-
113
- // exit early for unlike primitive values
114
- if (a === a &&
115
- !(a && objectTypes[type]) &&
116
- !(b && objectTypes[otherType])) {
117
- return false;
118
- }
185
+ function isFunction(value) {
186
+ return typeof value == 'function';
187
+ }
119
188
 
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
  };
@@ -776,7 +873,7 @@
776
873
  });
777
874
  };
778
875
 
779
- var ScheduledItem = Rx.Internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
876
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
780
877
  this.scheduler = scheduler;
781
878
  this.state = state;
782
879
  this.action = action;
@@ -1067,7 +1164,7 @@
1067
1164
 
1068
1165
  var normalizeTime = Scheduler.normalize;
1069
1166
 
1070
- var SchedulePeriodicRecursive = Rx.Internals.SchedulePeriodicRecursive = (function () {
1167
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1071
1168
  function tick(command, recurse) {
1072
1169
  recurse(0, this._period);
1073
1170
  try {
@@ -1193,8 +1290,6 @@
1193
1290
  clearImmediate = typeof (clearImmediate = freeGlobal && moduleExports && freeGlobal.clearImmediate) == 'function' &&
1194
1291
  !reNative.test(clearImmediate) && clearImmediate;
1195
1292
 
1196
- var BrowserMutationObserver = root.MutationObserver || root.WebKitMutationObserver;
1197
-
1198
1293
  function postMessageSupported () {
1199
1294
  // Ensure not in a worker
1200
1295
  if (!root.postMessage || root.importScripts) { return false; }
@@ -1208,40 +1303,8 @@
1208
1303
  return isAsync;
1209
1304
  }
1210
1305
 
1211
- // Use in order, MutationObserver, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1212
- if (!!BrowserMutationObserver) {
1213
-
1214
- var mutationQueue = {}, mutationId = 0;
1215
-
1216
- function drainQueue (mutations) {
1217
- for (var i = 0, len = mutations.length; i < len; i++) {
1218
- var id = mutations[i].target.getAttribute('drainQueue');
1219
- mutationQueue[id]();
1220
- delete mutationQueue[id];
1221
- }
1222
- }
1223
-
1224
- var observer = new BrowserMutationObserver(drainQueue),
1225
- elem = document.createElement('div');
1226
- observer.observe(elem, { attributes: true });
1227
-
1228
- root.addEventListener('unload', function () {
1229
- observer.disconnect();
1230
- observer = null;
1231
- });
1232
-
1233
- scheduleMethod = function (action) {
1234
- var id = mutationId++;
1235
- mutationQueue[id] = action;
1236
- elem.setAttribute('drainQueue', id);
1237
- return id;
1238
- };
1239
-
1240
- clearMethod = function (id) {
1241
- delete mutationQueue[id];
1242
- }
1243
-
1244
- } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1306
+ // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1307
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1245
1308
  scheduleMethod = process.nextTick;
1246
1309
  } else if (typeof setImmediate === 'function') {
1247
1310
  scheduleMethod = setImmediate;
@@ -1571,7 +1634,7 @@
1571
1634
  * @constructor
1572
1635
  * @private
1573
1636
  */
1574
- var Enumerator = Rx.Internals.Enumerator = function (moveNext, getCurrent) {
1637
+ var Enumerator = Rx.internals.Enumerator = function (moveNext, getCurrent) {
1575
1638
  this.moveNext = moveNext;
1576
1639
  this.getCurrent = getCurrent;
1577
1640
  };
@@ -1595,7 +1658,7 @@
1595
1658
  }, function () { return getCurrent(); });
1596
1659
  };
1597
1660
 
1598
- var Enumerable = Rx.Internals.Enumerable = function (getEnumerator) {
1661
+ var Enumerable = Rx.internals.Enumerable = function (getEnumerator) {
1599
1662
  this.getEnumerator = getEnumerator;
1600
1663
  };
1601
1664
 
@@ -1800,7 +1863,7 @@
1800
1863
  * Abstract base class for implementations of the Observer class.
1801
1864
  * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages.
1802
1865
  */
1803
- var AbstractObserver = Rx.Internals.AbstractObserver = (function (_super) {
1866
+ var AbstractObserver = Rx.internals.AbstractObserver = (function (_super) {
1804
1867
  inherits(AbstractObserver, _super);
1805
1868
 
1806
1869
  /**
@@ -1868,58 +1931,50 @@
1868
1931
  return AbstractObserver;
1869
1932
  }(Observer));
1870
1933
 
1871
- /**
1872
- * Class to create an Observer instance from delegate-based implementations of the on* methods.
1873
- */
1874
- var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1875
- inherits(AnonymousObserver, _super);
1934
+ /**
1935
+ * Class to create an Observer instance from delegate-based implementations of the on* methods.
1936
+ */
1937
+ var AnonymousObserver = Rx.AnonymousObserver = (function (_super) {
1938
+ inherits(AnonymousObserver, _super);
1876
1939
 
1877
- /**
1878
- * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1879
- *
1880
- * @constructor
1881
- * @param {Any} onNext Observer's OnNext action implementation.
1882
- * @param {Any} onError Observer's OnError action implementation.
1883
- * @param {Any} onCompleted Observer's OnCompleted action implementation.
1884
- */
1885
- function AnonymousObserver(onNext, onError, onCompleted) {
1886
- _super.call(this);
1887
- this._onNext = onNext;
1888
- this._onError = onError;
1889
- this._onCompleted = onCompleted;
1890
- }
1940
+ /**
1941
+ * Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
1942
+ * @param {Any} onNext Observer's OnNext action implementation.
1943
+ * @param {Any} onError Observer's OnError action implementation.
1944
+ * @param {Any} onCompleted Observer's OnCompleted action implementation.
1945
+ */
1946
+ function AnonymousObserver(onNext, onError, onCompleted) {
1947
+ _super.call(this);
1948
+ this._onNext = onNext;
1949
+ this._onError = onError;
1950
+ this._onCompleted = onCompleted;
1951
+ }
1891
1952
 
1892
- /**
1893
- * Calls the onNext action.
1894
- *
1895
- * @memberOf AnonymousObserver
1896
- * @param {Any} value Next element in the sequence.
1897
- */
1898
- AnonymousObserver.prototype.next = function (value) {
1899
- this._onNext(value);
1900
- };
1953
+ /**
1954
+ * Calls the onNext action.
1955
+ * @param {Any} value Next element in the sequence.
1956
+ */
1957
+ AnonymousObserver.prototype.next = function (value) {
1958
+ this._onNext(value);
1959
+ };
1901
1960
 
1902
- /**
1903
- * Calls the onError action.
1904
- *
1905
- * @memberOf AnonymousObserver
1906
- * @param {Any{ error The error that has occurred.
1907
- */
1908
- AnonymousObserver.prototype.error = function (exception) {
1909
- this._onError(exception);
1910
- };
1961
+ /**
1962
+ * Calls the onError action.
1963
+ * @param {Any} error The error that has occurred.
1964
+ */
1965
+ AnonymousObserver.prototype.error = function (exception) {
1966
+ this._onError(exception);
1967
+ };
1911
1968
 
1912
- /**
1913
- * Calls the onCompleted action.
1914
- *
1915
- * @memberOf AnonymousObserver
1916
- */
1917
- AnonymousObserver.prototype.completed = function () {
1918
- this._onCompleted();
1919
- };
1969
+ /**
1970
+ * Calls the onCompleted action.
1971
+ */
1972
+ AnonymousObserver.prototype.completed = function () {
1973
+ this._onCompleted();
1974
+ };
1920
1975
 
1921
- return AnonymousObserver;
1922
- }(AbstractObserver));
1976
+ return AnonymousObserver;
1977
+ }(AbstractObserver));
1923
1978
 
1924
1979
  var CheckedObserver = (function (_super) {
1925
1980
  inherits(CheckedObserver, _super);
@@ -1974,80 +2029,74 @@
1974
2029
  return CheckedObserver;
1975
2030
  }(Observer));
1976
2031
 
1977
- /** @private */
1978
- var ScheduledObserver = Rx.Internals.ScheduledObserver = (function (_super) {
1979
- inherits(ScheduledObserver, _super);
1980
-
1981
- function ScheduledObserver(scheduler, observer) {
1982
- _super.call(this);
1983
- this.scheduler = scheduler;
1984
- this.observer = observer;
1985
- this.isAcquired = false;
1986
- this.hasFaulted = false;
1987
- this.queue = [];
1988
- this.disposable = new SerialDisposable();
1989
- }
2032
+ var ScheduledObserver = Rx.internals.ScheduledObserver = (function (_super) {
2033
+ inherits(ScheduledObserver, _super);
2034
+
2035
+ function ScheduledObserver(scheduler, observer) {
2036
+ _super.call(this);
2037
+ this.scheduler = scheduler;
2038
+ this.observer = observer;
2039
+ this.isAcquired = false;
2040
+ this.hasFaulted = false;
2041
+ this.queue = [];
2042
+ this.disposable = new SerialDisposable();
2043
+ }
1990
2044
 
1991
- /** @private */
1992
- ScheduledObserver.prototype.next = function (value) {
1993
- var self = this;
1994
- this.queue.push(function () {
1995
- self.observer.onNext(value);
1996
- });
1997
- };
2045
+ ScheduledObserver.prototype.next = function (value) {
2046
+ var self = this;
2047
+ this.queue.push(function () {
2048
+ self.observer.onNext(value);
2049
+ });
2050
+ };
1998
2051
 
1999
- /** @private */
2000
- ScheduledObserver.prototype.error = function (exception) {
2001
- var self = this;
2002
- this.queue.push(function () {
2003
- self.observer.onError(exception);
2004
- });
2005
- };
2052
+ ScheduledObserver.prototype.error = function (exception) {
2053
+ var self = this;
2054
+ this.queue.push(function () {
2055
+ self.observer.onError(exception);
2056
+ });
2057
+ };
2006
2058
 
2007
- /** @private */
2008
- ScheduledObserver.prototype.completed = function () {
2009
- var self = this;
2010
- this.queue.push(function () {
2011
- self.observer.onCompleted();
2012
- });
2013
- };
2059
+ ScheduledObserver.prototype.completed = function () {
2060
+ var self = this;
2061
+ this.queue.push(function () {
2062
+ self.observer.onCompleted();
2063
+ });
2064
+ };
2014
2065
 
2015
- /** @private */
2016
- ScheduledObserver.prototype.ensureActive = function () {
2017
- var isOwner = false, parent = this;
2018
- if (!this.hasFaulted && this.queue.length > 0) {
2019
- isOwner = !this.isAcquired;
2020
- this.isAcquired = true;
2021
- }
2022
- if (isOwner) {
2023
- this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
2024
- var work;
2025
- if (parent.queue.length > 0) {
2026
- work = parent.queue.shift();
2027
- } else {
2028
- parent.isAcquired = false;
2029
- return;
2030
- }
2031
- try {
2032
- work();
2033
- } catch (ex) {
2034
- parent.queue = [];
2035
- parent.hasFaulted = true;
2036
- throw ex;
2037
- }
2038
- self();
2039
- }));
2040
- }
2041
- };
2066
+ ScheduledObserver.prototype.ensureActive = function () {
2067
+ var isOwner = false, parent = this;
2068
+ if (!this.hasFaulted && this.queue.length > 0) {
2069
+ isOwner = !this.isAcquired;
2070
+ this.isAcquired = true;
2071
+ }
2072
+ if (isOwner) {
2073
+ this.disposable.setDisposable(this.scheduler.scheduleRecursive(function (self) {
2074
+ var work;
2075
+ if (parent.queue.length > 0) {
2076
+ work = parent.queue.shift();
2077
+ } else {
2078
+ parent.isAcquired = false;
2079
+ return;
2080
+ }
2081
+ try {
2082
+ work();
2083
+ } catch (ex) {
2084
+ parent.queue = [];
2085
+ parent.hasFaulted = true;
2086
+ throw ex;
2087
+ }
2088
+ self();
2089
+ }));
2090
+ }
2091
+ };
2042
2092
 
2043
- /** @private */
2044
- ScheduledObserver.prototype.dispose = function () {
2045
- _super.prototype.dispose.call(this);
2046
- this.disposable.dispose();
2047
- };
2093
+ ScheduledObserver.prototype.dispose = function () {
2094
+ _super.prototype.dispose.call(this);
2095
+ this.disposable.dispose();
2096
+ };
2048
2097
 
2049
- return ScheduledObserver;
2050
- }(AbstractObserver));
2098
+ return ScheduledObserver;
2099
+ }(AbstractObserver));
2051
2100
 
2052
2101
  /** @private */
2053
2102
  var ObserveOnObserver = (function (_super) {
@@ -2195,6 +2244,55 @@
2195
2244
  });
2196
2245
  };
2197
2246
 
2247
+ /**
2248
+ * Converts a Promise to an Observable sequence
2249
+ * @param {Promise} An ES6 Compliant promise.
2250
+ * @returns {Observable} An Observable sequence which wraps the existing promise success and failure.
2251
+ */
2252
+ var observableFromPromise = Observable.fromPromise = function (promise) {
2253
+ return new AnonymousObservable(function (observer) {
2254
+ promise.then(
2255
+ function (value) {
2256
+ observer.onNext(value);
2257
+ observer.onCompleted();
2258
+ },
2259
+ function (reason) {
2260
+ observer.onError(reason);
2261
+ });
2262
+ });
2263
+ };
2264
+ /*
2265
+ * Converts an existing observable sequence to an ES6 Compatible Promise
2266
+ * @example
2267
+ * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
2268
+ *
2269
+ * // With config
2270
+ * Rx.config.Promise = RSVP.Promise;
2271
+ * var promise = Rx.Observable.return(42).toPromise();
2272
+ * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
2273
+ * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence.
2274
+ */
2275
+ observableProto.toPromise = function (promiseCtor) {
2276
+ promiseCtor || (promiseCtor = Rx.config.Promise);
2277
+ if (!promiseCtor) {
2278
+ throw new Error('Promise type not provided nor in Rx.config.Promise');
2279
+ }
2280
+ var source = this;
2281
+ return new promiseCtor(function (resolve, reject) {
2282
+ // No cancellation can be done
2283
+ var value, hasValue = false;
2284
+ source.subscribe(function (v) {
2285
+ value = v;
2286
+ hasValue = true;
2287
+ }, function (err) {
2288
+ reject(err);
2289
+ }, function () {
2290
+ if (hasValue) {
2291
+ resolve(value);
2292
+ }
2293
+ });
2294
+ });
2295
+ };
2198
2296
  /**
2199
2297
  * Creates an observable sequence from a specified subscribe method implementation.
2200
2298
  *
@@ -2272,6 +2370,38 @@
2272
2370
  });
2273
2371
  };
2274
2372
 
2373
+ /**
2374
+ * Converts a generator function to an observable sequence, using an optional scheduler to enumerate the generator.
2375
+ *
2376
+ * @example
2377
+ * var res = Rx.Observable.fromGenerator(function* () { yield 42; });
2378
+ * var res = Rx.Observable.fromArray(function* () { yield 42; }, Rx.Scheduler.timeout);
2379
+ * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2380
+ * @returns {Observable} The observable sequence whose elements are pulled from the given generator sequence.
2381
+ */
2382
+ observableProto.fromGenerator = function (genFn, scheduler) {
2383
+ scheduler || (scheduler = currentThreadScheduler);
2384
+ return new AnonymousObservable(function (observer) {
2385
+ var gen;
2386
+ try {
2387
+ gen = genFn();
2388
+ } catch (e) {
2389
+ observer.onError(e);
2390
+ return;
2391
+ }
2392
+
2393
+ return scheduler.scheduleRecursive(function (self) {
2394
+ var next = gen.next();
2395
+ if (next.done) {
2396
+ observer.onCompleted();
2397
+ } else {
2398
+ observer.onNext(next.value);
2399
+ self();
2400
+ }
2401
+ });
2402
+ });
2403
+ };
2404
+
2275
2405
  /**
2276
2406
  * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.
2277
2407
  *
@@ -2710,6 +2840,10 @@
2710
2840
  subscribe = function (xs) {
2711
2841
  var subscription = new SingleAssignmentDisposable();
2712
2842
  group.add(subscription);
2843
+
2844
+ // Check for promises support
2845
+ if (isPromise(xs)) { xs = observableFromPromise(xs); }
2846
+
2713
2847
  subscription.setDisposable(xs.subscribe(observer.onNext.bind(observer), observer.onError.bind(observer), function () {
2714
2848
  var s;
2715
2849
  group.remove(subscription);
@@ -2770,37 +2904,40 @@
2770
2904
  return observableFromArray(sources, scheduler).mergeObservable();
2771
2905
  };
2772
2906
 
2773
- /**
2774
- * Merges an observable sequence of observable sequences into an observable sequence.
2775
- * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2776
- */
2777
- observableProto.mergeObservable = observableProto.mergeAll =function () {
2778
- var sources = this;
2779
- return new AnonymousObservable(function (observer) {
2780
- var group = new CompositeDisposable(),
2781
- isStopped = false,
2782
- m = new SingleAssignmentDisposable();
2783
- group.add(m);
2784
- m.setDisposable(sources.subscribe(function (innerSource) {
2785
- var innerSubscription = new SingleAssignmentDisposable();
2786
- group.add(innerSubscription);
2787
- innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2788
- observer.onNext(x);
2789
- }, observer.onError.bind(observer), function () {
2790
- group.remove(innerSubscription);
2791
- if (isStopped && group.length === 1) {
2792
- observer.onCompleted();
2793
- }
2794
- }));
2795
- }, observer.onError.bind(observer), function () {
2796
- isStopped = true;
2797
- if (group.length === 1) {
2798
- observer.onCompleted();
2799
- }
2800
- }));
2801
- return group;
2802
- });
2803
- };
2907
+ /**
2908
+ * Merges an observable sequence of observable sequences into an observable sequence.
2909
+ * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2910
+ */
2911
+ observableProto.mergeObservable = observableProto.mergeAll =function () {
2912
+ var sources = this;
2913
+ return new AnonymousObservable(function (observer) {
2914
+ var group = new CompositeDisposable(),
2915
+ isStopped = false,
2916
+ m = new SingleAssignmentDisposable();
2917
+
2918
+ group.add(m);
2919
+ m.setDisposable(sources.subscribe(function (innerSource) {
2920
+ var innerSubscription = new SingleAssignmentDisposable();
2921
+ group.add(innerSubscription);
2922
+
2923
+ // Check if Promise or Observable
2924
+ if (isPromise(innerSource)) {
2925
+ innerSource = observableFromPromise(innerSource);
2926
+ }
2927
+
2928
+ innerSubscription.setDisposable(innerSource.subscribe(function (x) {
2929
+ observer.onNext(x);
2930
+ }, observer.onError.bind(observer), function () {
2931
+ group.remove(innerSubscription);
2932
+ if (isStopped && group.length === 1) { observer.onCompleted(); }
2933
+ }));
2934
+ }, observer.onError.bind(observer), function () {
2935
+ isStopped = true;
2936
+ if (group.length === 1) { observer.onCompleted(); }
2937
+ }));
2938
+ return group;
2939
+ });
2940
+ };
2804
2941
 
2805
2942
  /**
2806
2943
  * Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.
@@ -2892,6 +3029,12 @@
2892
3029
  var d = new SingleAssignmentDisposable(), id = ++latest;
2893
3030
  hasLatest = true;
2894
3031
  innerSubscription.setDisposable(d);
3032
+
3033
+ // Check if Promise or Observable
3034
+ if (isPromise(innerSource)) {
3035
+ innerSource = observableFromPromise(innerSource);
3036
+ }
3037
+
2895
3038
  d.setDisposable(innerSource.subscribe(function (x) {
2896
3039
  if (latest === id) {
2897
3040
  observer.onNext(x);
@@ -3728,7 +3871,10 @@
3728
3871
  };
3729
3872
 
3730
3873
  function selectMany(selector) {
3731
- return this.select(selector).mergeObservable();
3874
+ return this.select(function (x, i) {
3875
+ var result = selector(x, i);
3876
+ return isPromise(result) ? observableFromPromise(result) : result;
3877
+ }).mergeObservable();
3732
3878
  }
3733
3879
 
3734
3880
  /**
@@ -3745,24 +3891,28 @@
3745
3891
  * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3746
3892
  *
3747
3893
  * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3748
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto.
3894
+ * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3895
+ * source sequence onto which could be either an observable or Promise.
3749
3896
  * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3750
3897
  * @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.
3751
3898
  */
3752
3899
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector) {
3753
- if (resultSelector) {
3754
- return this.selectMany(function (x) {
3755
- return selector(x).select(function (y) {
3756
- return resultSelector(x, y);
3757
- });
3900
+ if (resultSelector) {
3901
+ return this.selectMany(function (x, i) {
3902
+ var selectorResult = selector(x, i),
3903
+ result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3904
+
3905
+ return result.select(function (y) {
3906
+ return resultSelector(x, y, i);
3758
3907
  });
3759
- }
3760
- if (typeof selector === 'function') {
3761
- return selectMany.call(this, selector);
3762
- }
3763
- return selectMany.call(this, function () {
3764
- return selector;
3765
- });
3908
+ });
3909
+ }
3910
+ if (typeof selector === 'function') {
3911
+ return selectMany.call(this, selector);
3912
+ }
3913
+ return selectMany.call(this, function () {
3914
+ return selector;
3915
+ });
3766
3916
  };
3767
3917
 
3768
3918
  /**
@@ -3922,7 +4072,7 @@
3922
4072
  });
3923
4073
  };
3924
4074
 
3925
- var AnonymousObservable = Rx.Internals.AnonymousObservable = (function (_super) {
4075
+ var AnonymousObservable = Rx.AnonymousObservable = (function (_super) {
3926
4076
  inherits(AnonymousObservable, _super);
3927
4077
 
3928
4078
  // Fix subscriber to check for undefined or function returned to decorate as Disposable