UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

44 lines (41 loc) 1.22 kB
define(function(require,exports,module){ 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 const throwIfEmpty = (errorFactory = defaultErrorFactory) => tap({ hasValue: false, next() { this.hasValue = true; }, complete() { if (!this.hasValue) { throw errorFactory(); } } }); function defaultErrorFactory() { return new EmptyError(); } //# sourceMappingURL=throwIfEmpty.js.map return module.exports; });