wishthis/node_modules/rxjs/_esm5/internal/operators/sample.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
/** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
export function sample(notifier) {
return function (source) { return source.lift(new SampleOperator(notifier)); };
}
var SampleOperator = /*@__PURE__*/ (function () {
function SampleOperator(notifier) {
this.notifier = notifier;
}
SampleOperator.prototype.call = function (subscriber, source) {
var sampleSubscriber = new SampleSubscriber(subscriber);
var subscription = source.subscribe(sampleSubscriber);
subscription.add(innerSubscribe(this.notifier, new SimpleInnerSubscriber(sampleSubscriber)));
return subscription;
};
return SampleOperator;
}());
var SampleSubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(SampleSubscriber, _super);
function SampleSubscriber() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.hasValue = false;
return _this;
}
SampleSubscriber.prototype._next = function (value) {
this.value = value;
this.hasValue = true;
};
SampleSubscriber.prototype.notifyNext = function () {
this.emitValue();
};
SampleSubscriber.prototype.notifyComplete = function () {
this.emitValue();
};
SampleSubscriber.prototype.emitValue = function () {
if (this.hasValue) {
this.hasValue = false;
this.destination.next(this.value);
}
};
return SampleSubscriber;
}(SimpleOuterSubscriber));
//# sourceMappingURL=sample.js.map