38 lines
No EOL
1.6 KiB
JavaScript
38 lines
No EOL
1.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.debounce = void 0;
|
|
var lift_1 = require("../util/lift");
|
|
var noop_1 = require("../util/noop");
|
|
var OperatorSubscriber_1 = require("./OperatorSubscriber");
|
|
var innerFrom_1 = require("../observable/innerFrom");
|
|
function debounce(durationSelector) {
|
|
return lift_1.operate(function (source, subscriber) {
|
|
var hasValue = false;
|
|
var lastValue = null;
|
|
var durationSubscriber = null;
|
|
var emit = function () {
|
|
durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
|
|
durationSubscriber = null;
|
|
if (hasValue) {
|
|
hasValue = false;
|
|
var value = lastValue;
|
|
lastValue = null;
|
|
subscriber.next(value);
|
|
}
|
|
};
|
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
|
|
durationSubscriber === null || durationSubscriber === void 0 ? void 0 : durationSubscriber.unsubscribe();
|
|
hasValue = true;
|
|
lastValue = value;
|
|
durationSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, emit, noop_1.noop);
|
|
innerFrom_1.innerFrom(durationSelector(value)).subscribe(durationSubscriber);
|
|
}, function () {
|
|
emit();
|
|
subscriber.complete();
|
|
}, undefined, function () {
|
|
lastValue = durationSubscriber = null;
|
|
}));
|
|
});
|
|
}
|
|
exports.debounce = debounce;
|
|
//# sourceMappingURL=debounce.js.map
|