wed
Version:
Wed is a schema-aware editor for XML documents.
49 lines (46 loc) • 1.44 kB
JavaScript
define(function(require,exports,module){
;
Object.defineProperty(exports, "__esModule", { value: true });
var tap_1 = require("./tap");
var EmptyError_1 = require("../util/EmptyError");
/**
* If the source observable completes without emitting a value, it will emit
* an error. The error will be created at that time by the optional
* `errorFactory` argument, otherwise, the error will be {@link ErrorEmpty}.
*
* @example
*
* const click$ = fromEvent(button, 'click');
*
* clicks$.pipe(
* takeUntil(timer(1000)),
* throwIfEmpty(
* () => new Error('the button was not clicked within 1 second')
* ),
* )
* .subscribe({
* next() { console.log('The button was clicked'); },
* error(err) { console.error(err); },
* });
* @param {Function} [errorFactory] A factory function called to produce the
* error to be thrown when the source observable completes without emitting a
* value.
*/
exports.throwIfEmpty = function (errorFactory) {
if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
return tap_1.tap({
hasValue: false,
next: function () { this.hasValue = true; },
complete: function () {
if (!this.hasValue) {
throw errorFactory();
}
}
});
};
function defaultErrorFactory() {
return new EmptyError_1.EmptyError();
}
//# sourceMappingURL=throwIfEmpty.js.map
return module.exports;
});