Reactive-Extensions/RxJS

View on GitHub
src/core/perf/operators/repeat.js

Summary

Maintainability
C
1 day
Test Coverage
Similar blocks of code found in 3 locations. Consider refactoring.
var RepeatObservable = (function(__super__) {
inherits(RepeatObservable, __super__);
function RepeatObservable(value, repeatCount, scheduler) {
this.value = value;
this.repeatCount = repeatCount == null ? -1 : repeatCount;
this.scheduler = scheduler;
__super__.call(this);
}
 
RepeatObservable.prototype.subscribeCore = function (observer) {
var sink = new RepeatSink(observer, this);
return sink.run();
};
 
return RepeatObservable;
}(ObservableBase));
 
function RepeatSink(observer, parent) {
this.observer = observer;
this.parent = parent;
}
 
Function `run` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Identical blocks of code found in 3 locations. Consider refactoring.
RepeatSink.prototype.run = function () {
var observer = this.observer, value = this.parent.value;
function loopRecursive(i, recurse) {
if (i === -1 || i > 0) {
observer.onNext(value);
i > 0 && i--;
}
if (i === 0) { return observer.onCompleted(); }
recurse(i);
}
 
return this.parent.scheduler.scheduleRecursive(this.parent.repeatCount, loopRecursive);
};
 
/**
* Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages.
* @param {Mixed} value Element to repeat.
* @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely.
* @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate.
* @returns {Observable} An observable sequence that repeats the given element the specified number of times.
*/
Similar blocks of code found in 6 locations. Consider refactoring.
Observable.repeat = function (value, repeatCount, scheduler) {
isScheduler(scheduler) || (scheduler = currentThreadScheduler);
return new RepeatObservable(value, repeatCount, scheduler);
};