rxjs-rails 2.3.14 → 2.3.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rxjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rx.aggregates.js +325 -370
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +1115 -930
- data/vendor/assets/javascripts/rx.all.compat.min.js +4 -3
- data/vendor/assets/javascripts/rx.all.js +1113 -928
- data/vendor/assets/javascripts/rx.all.min.js +3 -3
- data/vendor/assets/javascripts/rx.async.compat.js +16 -20
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +14 -18
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.js +26 -10
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +2 -14
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.js +13 -13
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +586 -378
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.experimental.js +37 -29
- data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
- data/vendor/assets/javascripts/rx.js +586 -378
- data/vendor/assets/javascripts/rx.lite.compat.js +632 -394
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.js +29 -25
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +630 -392
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.sorting.js +72 -0
- data/vendor/assets/javascripts/rx.sorting.min.js +3 -0
- data/vendor/assets/javascripts/rx.testing.js +116 -83
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +127 -101
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- metadata +4 -2
@@ -46,7 +46,11 @@
|
|
46
46
|
defaultSubComparer = helpers.defaultSubComparer,
|
47
47
|
isFunction = helpers.isFunction,
|
48
48
|
isPromise = helpers.isPromise,
|
49
|
-
|
49
|
+
isArrayLike = helpers.isArrayLike,
|
50
|
+
isIterable = helpers.isIterable,
|
51
|
+
observableFromPromise = Observable.fromPromise,
|
52
|
+
observableFrom = Observable.from,
|
53
|
+
deprecate = helpers.deprecate;
|
50
54
|
|
51
55
|
// Defaults
|
52
56
|
var argumentOutOfRange = 'Argument out of range',
|
@@ -67,7 +71,7 @@
|
|
67
71
|
observer.onCompleted();
|
68
72
|
}
|
69
73
|
});
|
70
|
-
});
|
74
|
+
}, source);
|
71
75
|
};
|
72
76
|
|
73
77
|
function extremaBy(source, keySelector, comparer) {
|
@@ -102,24 +106,24 @@
|
|
102
106
|
observer.onNext(list);
|
103
107
|
observer.onCompleted();
|
104
108
|
});
|
105
|
-
});
|
109
|
+
}, source);
|
106
110
|
}
|
107
111
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
return x[0];
|
113
|
-
}
|
112
|
+
function firstOnly(x) {
|
113
|
+
if (x.length === 0) { throw new Error(sequenceContainsNoElements); }
|
114
|
+
return x[0];
|
115
|
+
}
|
114
116
|
|
115
117
|
/**
|
116
118
|
* Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
|
117
119
|
* For aggregation behavior with incremental intermediate results, see Observable.scan.
|
120
|
+
* @deprecated Use #reduce instead
|
118
121
|
* @param {Mixed} [seed] The initial accumulator value.
|
119
122
|
* @param {Function} accumulator An accumulator function to be invoked on each element.
|
120
123
|
* @returns {Observable} An observable sequence containing a single element with the final accumulator value.
|
121
124
|
*/
|
122
125
|
observableProto.aggregate = function () {
|
126
|
+
deprecate('aggregate', 'reduce');
|
123
127
|
var seed, hasSeed, accumulator;
|
124
128
|
if (arguments.length === 2) {
|
125
129
|
seed = arguments[0];
|
@@ -147,28 +151,31 @@
|
|
147
151
|
return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
|
148
152
|
};
|
149
153
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
return
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
154
|
+
/**
|
155
|
+
* Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
|
156
|
+
* @param {Function} [predicate] A function to test each element for a condition.
|
157
|
+
* @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
|
158
|
+
*/
|
159
|
+
observableProto.some = function (predicate, thisArg) {
|
160
|
+
var source = this;
|
161
|
+
return predicate ?
|
162
|
+
source.filter(predicate, thisArg).some() :
|
163
|
+
new AnonymousObservable(function (observer) {
|
164
|
+
return source.subscribe(function () {
|
165
|
+
observer.onNext(true);
|
166
|
+
observer.onCompleted();
|
167
|
+
}, observer.onError.bind(observer), function () {
|
168
|
+
observer.onNext(false);
|
169
|
+
observer.onCompleted();
|
170
|
+
});
|
171
|
+
}, source);
|
172
|
+
};
|
173
|
+
|
174
|
+
/** @deprecated use #some instead */
|
175
|
+
observableProto.any = function () {
|
176
|
+
deprecate('any', 'some');
|
177
|
+
return this.some.apply(this, arguments);
|
178
|
+
};
|
172
179
|
|
173
180
|
/**
|
174
181
|
* Determines whether an observable sequence is empty.
|
@@ -178,22 +185,21 @@
|
|
178
185
|
return this.any().map(not);
|
179
186
|
};
|
180
187
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
};
|
188
|
+
/**
|
189
|
+
* Determines whether all elements of an observable sequence satisfy a condition.
|
190
|
+
* @param {Function} [predicate] A function to test each element for a condition.
|
191
|
+
* @param {Any} [thisArg] Object to use as this when executing callback.
|
192
|
+
* @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
|
193
|
+
*/
|
194
|
+
observableProto.every = function (predicate, thisArg) {
|
195
|
+
return this.filter(function (v) { return !predicate(v); }, thisArg).some().map(not);
|
196
|
+
};
|
197
|
+
|
198
|
+
/** @deprecated use #every instead */
|
199
|
+
observableProto.all = function () {
|
200
|
+
deprecate('all', 'every');
|
201
|
+
return this.every.apply(this, arguments);
|
202
|
+
};
|
197
203
|
|
198
204
|
/**
|
199
205
|
* Determines whether an observable sequence contains a specified element with an optional equality comparer.
|
@@ -226,7 +232,7 @@
|
|
226
232
|
observer.onNext(false);
|
227
233
|
observer.onCompleted();
|
228
234
|
});
|
229
|
-
});
|
235
|
+
}, this);
|
230
236
|
};
|
231
237
|
|
232
238
|
/**
|
@@ -275,13 +281,11 @@
|
|
275
281
|
observer.onNext(-1);
|
276
282
|
observer.onCompleted();
|
277
283
|
});
|
278
|
-
});
|
284
|
+
}, source);
|
279
285
|
};
|
286
|
+
|
280
287
|
/**
|
281
288
|
* Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
|
282
|
-
* @example
|
283
|
-
* var res = source.sum();
|
284
|
-
* var res = source.sum(function (x) { return x.value; });
|
285
289
|
* @param {Function} [selector] A transform function to apply to each element.
|
286
290
|
* @param {Any} [thisArg] Object to use as this when executing callback.
|
287
291
|
* @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
|
@@ -289,68 +293,62 @@
|
|
289
293
|
observableProto.sum = function (keySelector, thisArg) {
|
290
294
|
return keySelector && isFunction(keySelector) ?
|
291
295
|
this.map(keySelector, thisArg).sum() :
|
292
|
-
this.
|
296
|
+
this.reduce(function (prev, curr) {
|
293
297
|
return prev + curr;
|
294
|
-
});
|
298
|
+
}, 0);
|
295
299
|
};
|
296
300
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
});
|
311
|
-
};
|
301
|
+
/**
|
302
|
+
* Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
|
303
|
+
* @example
|
304
|
+
* var res = source.minBy(function (x) { return x.value; });
|
305
|
+
* var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
|
306
|
+
* @param {Function} keySelector Key selector function.
|
307
|
+
* @param {Function} [comparer] Comparer used to compare key values.
|
308
|
+
* @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
|
309
|
+
*/
|
310
|
+
observableProto.minBy = function (keySelector, comparer) {
|
311
|
+
comparer || (comparer = defaultSubComparer);
|
312
|
+
return extremaBy(this, keySelector, function (x, y) { return comparer(x, y) * -1; });
|
313
|
+
};
|
312
314
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
});
|
325
|
-
};
|
315
|
+
/**
|
316
|
+
* Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
|
317
|
+
* @example
|
318
|
+
* var res = source.min();
|
319
|
+
* var res = source.min(function (x, y) { return x.value - y.value; });
|
320
|
+
* @param {Function} [comparer] Comparer used to compare elements.
|
321
|
+
* @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
|
322
|
+
*/
|
323
|
+
observableProto.min = function (comparer) {
|
324
|
+
return this.minBy(identity, comparer).map(function (x) { return firstOnly(x); });
|
325
|
+
};
|
326
326
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
327
|
+
/**
|
328
|
+
* Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
|
329
|
+
* @example
|
330
|
+
* var res = source.maxBy(function (x) { return x.value; });
|
331
|
+
* var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
|
332
|
+
* @param {Function} keySelector Key selector function.
|
333
|
+
* @param {Function} [comparer] Comparer used to compare key values.
|
334
|
+
* @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
|
335
|
+
*/
|
336
|
+
observableProto.maxBy = function (keySelector, comparer) {
|
337
|
+
comparer || (comparer = defaultSubComparer);
|
338
|
+
return extremaBy(this, keySelector, comparer);
|
339
|
+
};
|
340
340
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
});
|
353
|
-
};
|
341
|
+
/**
|
342
|
+
* Returns the maximum value in an observable sequence according to the specified comparer.
|
343
|
+
* @example
|
344
|
+
* var res = source.max();
|
345
|
+
* var res = source.max(function (x, y) { return x.value - y.value; });
|
346
|
+
* @param {Function} [comparer] Comparer used to compare elements.
|
347
|
+
* @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
|
348
|
+
*/
|
349
|
+
observableProto.max = function (comparer) {
|
350
|
+
return this.maxBy(identity, comparer).map(function (x) { return firstOnly(x); });
|
351
|
+
};
|
354
352
|
|
355
353
|
/**
|
356
354
|
* Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
|
@@ -374,28 +372,6 @@
|
|
374
372
|
});
|
375
373
|
};
|
376
374
|
|
377
|
-
function sequenceEqualArray(first, second, comparer) {
|
378
|
-
return new AnonymousObservable(function (observer) {
|
379
|
-
var count = 0, len = second.length;
|
380
|
-
return first.subscribe(function (value) {
|
381
|
-
var equal = false;
|
382
|
-
try {
|
383
|
-
count < len && (equal = comparer(value, second[count++]));
|
384
|
-
} catch (e) {
|
385
|
-
observer.onError(e);
|
386
|
-
return;
|
387
|
-
}
|
388
|
-
if (!equal) {
|
389
|
-
observer.onNext(false);
|
390
|
-
observer.onCompleted();
|
391
|
-
}
|
392
|
-
}, observer.onError.bind(observer), function () {
|
393
|
-
observer.onNext(count === len);
|
394
|
-
observer.onCompleted();
|
395
|
-
});
|
396
|
-
});
|
397
|
-
}
|
398
|
-
|
399
375
|
/**
|
400
376
|
* Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
|
401
377
|
*
|
@@ -411,9 +387,6 @@
|
|
411
387
|
observableProto.sequenceEqual = function (second, comparer) {
|
412
388
|
var first = this;
|
413
389
|
comparer || (comparer = defaultComparer);
|
414
|
-
if (Array.isArray(second)) {
|
415
|
-
return sequenceEqualArray(first, second, comparer);
|
416
|
-
}
|
417
390
|
return new AnonymousObservable(function (observer) {
|
418
391
|
var donel = false, doner = false, ql = [], qr = [];
|
419
392
|
var subscription1 = first.subscribe(function (x) {
|
@@ -449,6 +422,7 @@
|
|
449
422
|
}
|
450
423
|
});
|
451
424
|
|
425
|
+
(isArrayLike(second) || isIterable(second)) && (second = observableFrom(second));
|
452
426
|
isPromise(second) && (second = observableFromPromise(second));
|
453
427
|
var subscription2 = second.subscribe(function (x) {
|
454
428
|
var equal;
|
@@ -483,55 +457,52 @@
|
|
483
457
|
}
|
484
458
|
});
|
485
459
|
return new CompositeDisposable(subscription1, subscription2);
|
486
|
-
});
|
460
|
+
}, first);
|
487
461
|
};
|
488
462
|
|
489
|
-
|
490
|
-
|
491
|
-
|
463
|
+
function elementAtOrDefault(source, index, hasDefault, defaultValue) {
|
464
|
+
if (index < 0) { throw new Error(argumentOutOfRange); }
|
465
|
+
return new AnonymousObservable(function (observer) {
|
466
|
+
var i = index;
|
467
|
+
return source.subscribe(function (x) {
|
468
|
+
if (i-- === 0) {
|
469
|
+
observer.onNext(x);
|
470
|
+
observer.onCompleted();
|
492
471
|
}
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
observer.onError(new Error(argumentOutOfRange));
|
504
|
-
} else {
|
505
|
-
observer.onNext(defaultValue);
|
506
|
-
observer.onCompleted();
|
507
|
-
}
|
508
|
-
});
|
509
|
-
});
|
510
|
-
}
|
472
|
+
}, observer.onError.bind(observer), function () {
|
473
|
+
if (!hasDefault) {
|
474
|
+
observer.onError(new Error(argumentOutOfRange));
|
475
|
+
} else {
|
476
|
+
observer.onNext(defaultValue);
|
477
|
+
observer.onCompleted();
|
478
|
+
}
|
479
|
+
});
|
480
|
+
}, source);
|
481
|
+
}
|
511
482
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
483
|
+
/**
|
484
|
+
* Returns the element at a specified index in a sequence.
|
485
|
+
* @example
|
486
|
+
* var res = source.elementAt(5);
|
487
|
+
* @param {Number} index The zero-based index of the element to retrieve.
|
488
|
+
* @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
|
489
|
+
*/
|
490
|
+
observableProto.elementAt = function (index) {
|
491
|
+
return elementAtOrDefault(this, index, false);
|
492
|
+
};
|
522
493
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
494
|
+
/**
|
495
|
+
* Returns the element at a specified index in a sequence or a default value if the index is out of range.
|
496
|
+
* @example
|
497
|
+
* var res = source.elementAtOrDefault(5);
|
498
|
+
* var res = source.elementAtOrDefault(5, 0);
|
499
|
+
* @param {Number} index The zero-based index of the element to retrieve.
|
500
|
+
* @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
|
501
|
+
* @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.
|
502
|
+
*/
|
503
|
+
observableProto.elementAtOrDefault = function (index, defaultValue) {
|
504
|
+
return elementAtOrDefault(this, index, true, defaultValue);
|
505
|
+
};
|
535
506
|
|
536
507
|
function singleOrDefaultAsync(source, hasDefault, defaultValue) {
|
537
508
|
return new AnonymousObservable(function (observer) {
|
@@ -551,14 +522,11 @@
|
|
551
522
|
observer.onCompleted();
|
552
523
|
}
|
553
524
|
});
|
554
|
-
});
|
525
|
+
}, source);
|
555
526
|
}
|
556
527
|
|
557
528
|
/**
|
558
529
|
* Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
|
559
|
-
* @example
|
560
|
-
* var res = res = source.single();
|
561
|
-
* var res = res = source.single(function (x) { return x === 42; });
|
562
530
|
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
563
531
|
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
564
532
|
* @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
|
@@ -588,211 +556,198 @@
|
|
588
556
|
singleOrDefaultAsync(this, true, defaultValue);
|
589
557
|
};
|
590
558
|
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
559
|
+
function firstOrDefaultAsync(source, hasDefault, defaultValue) {
|
560
|
+
return new AnonymousObservable(function (observer) {
|
561
|
+
return source.subscribe(function (x) {
|
562
|
+
observer.onNext(x);
|
563
|
+
observer.onCompleted();
|
564
|
+
}, observer.onError.bind(observer), function () {
|
565
|
+
if (!hasDefault) {
|
566
|
+
observer.onError(new Error(sequenceContainsNoElements));
|
567
|
+
} else {
|
568
|
+
observer.onNext(defaultValue);
|
569
|
+
observer.onCompleted();
|
570
|
+
}
|
571
|
+
});
|
572
|
+
}, source);
|
573
|
+
}
|
606
574
|
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
575
|
+
/**
|
576
|
+
* Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
|
577
|
+
* @example
|
578
|
+
* var res = res = source.first();
|
579
|
+
* var res = res = source.first(function (x) { return x > 3; });
|
580
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
581
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
582
|
+
* @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
|
583
|
+
*/
|
584
|
+
observableProto.first = function (predicate, thisArg) {
|
585
|
+
return predicate ?
|
586
|
+
this.where(predicate, thisArg).first() :
|
587
|
+
firstOrDefaultAsync(this, false);
|
588
|
+
};
|
621
589
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
|
635
|
-
return predicate ?
|
636
|
-
this.where(predicate).firstOrDefault(null, defaultValue) :
|
637
|
-
firstOrDefaultAsync(this, true, defaultValue);
|
638
|
-
};
|
590
|
+
/**
|
591
|
+
* Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
|
592
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
593
|
+
* @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
|
594
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
595
|
+
* @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
|
596
|
+
*/
|
597
|
+
observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
|
598
|
+
return predicate ?
|
599
|
+
this.where(predicate).firstOrDefault(null, defaultValue) :
|
600
|
+
firstOrDefaultAsync(this, true, defaultValue);
|
601
|
+
};
|
639
602
|
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
603
|
+
function lastOrDefaultAsync(source, hasDefault, defaultValue) {
|
604
|
+
return new AnonymousObservable(function (observer) {
|
605
|
+
var value = defaultValue, seenValue = false;
|
606
|
+
return source.subscribe(function (x) {
|
607
|
+
value = x;
|
608
|
+
seenValue = true;
|
609
|
+
}, observer.onError.bind(observer), function () {
|
610
|
+
if (!seenValue && !hasDefault) {
|
611
|
+
observer.onError(new Error(sequenceContainsNoElements));
|
612
|
+
} else {
|
613
|
+
observer.onNext(value);
|
614
|
+
observer.onCompleted();
|
615
|
+
}
|
616
|
+
});
|
617
|
+
}, source);
|
618
|
+
}
|
656
619
|
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
this.where(predicate, thisArg).last() :
|
669
|
-
lastOrDefaultAsync(this, false);
|
670
|
-
};
|
620
|
+
/**
|
621
|
+
* Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
|
622
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
623
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
624
|
+
* @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
|
625
|
+
*/
|
626
|
+
observableProto.last = function (predicate, thisArg) {
|
627
|
+
return predicate ?
|
628
|
+
this.where(predicate, thisArg).last() :
|
629
|
+
lastOrDefaultAsync(this, false);
|
630
|
+
};
|
671
631
|
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
|
685
|
-
return predicate ?
|
686
|
-
this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
|
687
|
-
lastOrDefaultAsync(this, true, defaultValue);
|
688
|
-
};
|
632
|
+
/**
|
633
|
+
* Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
|
634
|
+
* @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
|
635
|
+
* @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
|
636
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
637
|
+
* @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
|
638
|
+
*/
|
639
|
+
observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
|
640
|
+
return predicate ?
|
641
|
+
this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
|
642
|
+
lastOrDefaultAsync(this, true, defaultValue);
|
643
|
+
};
|
689
644
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
645
|
+
function findValue (source, predicate, thisArg, yieldIndex) {
|
646
|
+
return new AnonymousObservable(function (observer) {
|
647
|
+
var i = 0;
|
648
|
+
return source.subscribe(function (x) {
|
649
|
+
var shouldRun;
|
650
|
+
try {
|
651
|
+
shouldRun = predicate.call(thisArg, x, i, source);
|
652
|
+
} catch (e) {
|
653
|
+
observer.onError(e);
|
654
|
+
return;
|
655
|
+
}
|
656
|
+
if (shouldRun) {
|
657
|
+
observer.onNext(yieldIndex ? i : x);
|
658
|
+
observer.onCompleted();
|
659
|
+
} else {
|
660
|
+
i++;
|
661
|
+
}
|
662
|
+
}, observer.onError.bind(observer), function () {
|
663
|
+
observer.onNext(yieldIndex ? -1 : undefined);
|
664
|
+
observer.onCompleted();
|
665
|
+
});
|
666
|
+
}, source);
|
667
|
+
}
|
713
668
|
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
669
|
+
/**
|
670
|
+
* Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
|
671
|
+
* @param {Function} predicate The predicate that defines the conditions of the element to search for.
|
672
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
673
|
+
* @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
|
674
|
+
*/
|
675
|
+
observableProto.find = function (predicate, thisArg) {
|
676
|
+
return findValue(this, predicate, thisArg, false);
|
677
|
+
};
|
723
678
|
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
679
|
+
/**
|
680
|
+
* Searches for an element that matches the conditions defined by the specified predicate, and returns
|
681
|
+
* an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
|
682
|
+
* @param {Function} predicate The predicate that defines the conditions of the element to search for.
|
683
|
+
* @param {Any} [thisArg] Object to use as `this` when executing the predicate.
|
684
|
+
* @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
|
685
|
+
*/
|
686
|
+
observableProto.findIndex = function (predicate, thisArg) {
|
687
|
+
return findValue(this, predicate, thisArg, true);
|
688
|
+
};
|
734
689
|
|
735
|
-
if (!!root.Set) {
|
736
|
-
/**
|
737
|
-
* Converts the observable sequence to a Set if it exists.
|
738
|
-
* @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
|
739
|
-
*/
|
740
|
-
observableProto.toSet = function () {
|
741
|
-
var source = this;
|
742
|
-
return new AnonymousObservable(function (observer) {
|
743
|
-
var s = new root.Set();
|
744
|
-
return source.subscribe(
|
745
|
-
s.add.bind(s),
|
746
|
-
observer.onError.bind(observer),
|
747
|
-
function () {
|
748
|
-
observer.onNext(s);
|
749
|
-
observer.onCompleted();
|
750
|
-
});
|
751
|
-
});
|
752
|
-
};
|
753
|
-
}
|
754
690
|
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
var
|
764
|
-
return
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
691
|
+
/**
|
692
|
+
* Converts the observable sequence to a Set if it exists.
|
693
|
+
* @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
|
694
|
+
*/
|
695
|
+
observableProto.toSet = function () {
|
696
|
+
if (typeof root.Set === 'undefined') { throw new TypeError(); }
|
697
|
+
var source = this;
|
698
|
+
return new AnonymousObservable(function (observer) {
|
699
|
+
var s = new root.Set();
|
700
|
+
return source.subscribe(
|
701
|
+
s.add.bind(s),
|
702
|
+
observer.onError.bind(observer),
|
703
|
+
function () {
|
704
|
+
observer.onNext(s);
|
705
|
+
observer.onCompleted();
|
706
|
+
});
|
707
|
+
}, source);
|
708
|
+
};
|
709
|
+
|
710
|
+
|
711
|
+
/**
|
712
|
+
* Converts the observable sequence to a Map if it exists.
|
713
|
+
* @param {Function} keySelector A function which produces the key for the Map.
|
714
|
+
* @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
|
715
|
+
* @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
|
716
|
+
*/
|
717
|
+
observableProto.toMap = function (keySelector, elementSelector) {
|
718
|
+
if (typeof root.Map === 'undefined') { throw new TypeError(); }
|
719
|
+
var source = this;
|
720
|
+
return new AnonymousObservable(function (observer) {
|
721
|
+
var m = new root.Map();
|
722
|
+
return source.subscribe(
|
723
|
+
function (x) {
|
724
|
+
var key;
|
725
|
+
try {
|
726
|
+
key = keySelector(x);
|
727
|
+
} catch (e) {
|
728
|
+
observer.onError(e);
|
729
|
+
return;
|
730
|
+
}
|
731
|
+
|
732
|
+
var element = x;
|
733
|
+
if (elementSelector) {
|
769
734
|
try {
|
770
|
-
|
735
|
+
element = elementSelector(x);
|
771
736
|
} catch (e) {
|
772
737
|
observer.onError(e);
|
773
738
|
return;
|
774
739
|
}
|
740
|
+
}
|
775
741
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
m.set(key, element);
|
787
|
-
},
|
788
|
-
observer.onError.bind(observer),
|
789
|
-
function () {
|
790
|
-
observer.onNext(m);
|
791
|
-
observer.onCompleted();
|
792
|
-
});
|
793
|
-
});
|
794
|
-
};
|
795
|
-
}
|
742
|
+
m.set(key, element);
|
743
|
+
},
|
744
|
+
observer.onError.bind(observer),
|
745
|
+
function () {
|
746
|
+
observer.onNext(m);
|
747
|
+
observer.onCompleted();
|
748
|
+
});
|
749
|
+
}, source);
|
750
|
+
};
|
796
751
|
|
797
752
|
return Rx;
|
798
753
|
}));
|