UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

51 lines (47 loc) 1.42 kB
define(function(require,exports,module){ /** PURE_IMPORTS_START _tap,_util_EmptyError PURE_IMPORTS_END */ import { tap } from './tap'; import { EmptyError } from '../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. */ export var throwIfEmpty = function (errorFactory) { if (errorFactory === void 0) { errorFactory = defaultErrorFactory; } return tap({ hasValue: false, next: function () { this.hasValue = true; }, complete: function () { if (!this.hasValue) { throw errorFactory(); } } }); }; function defaultErrorFactory() { return new EmptyError(); } //# sourceMappingURL=throwIfEmpty.js.map return module.exports; });