UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

40 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.whenDone = whenDone; exports.factoryChain = factoryChain; const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const types_1 = require("../types"); const distinct_pending_1 = require("./distinct-pending"); const join_builder_states_1 = require("./join-builder-states"); const stack_1 = require("./stack"); /** * Operator function that projects each source value to an Observable which is merged in the output Observable, * only if the source value is a BuilderDone state. * * The project function is applied to each value emitted by the source Observable. If the source value is a BuilderDone state, * the project function is called with the result of the BuilderDone state and the index as arguments, and the returned Observable * is merged into the output Observable. If the source value is not a BuilderDone state, it is emitted directly to the output Observable. * @param {Function} project - The function to apply to each BuilderDone value emitted by the source Observable. * @returns {OperatorFunction} - An OperatorFunction that emits the items from the source Observable or the projected Observables. */ function whenDone(project) { return (source) => source.pipe( // This will destroy the observable chain if the state is not a BuilderDone state (0, operators_1.switchMap)((state) => { if ((0, types_1.isBuilderDone)(state)) { return (0, rxjs_1.of)(state.result).pipe((0, operators_1.switchMap)(project)); } return (0, rxjs_1.of)(state); }), (0, distinct_pending_1.distinctPending)()); } /** * * @param tag * @param builders * @param project */ function factoryChain(tag, builders, project) { return (0, rxjs_1.combineLatest)(builders).pipe((0, operators_1.switchMap)((states) => (0, join_builder_states_1.joinBuilderStates)(tag, states, (...args) => (0, rxjs_1.combineLatest)(...project(...args)).pipe((0, operators_1.switchMap)((states) => (0, join_builder_states_1.joinBuilderStates)(tag, states, (...args) => (0, rxjs_1.of)(...args.map((result) => new types_1.BuilderDone(tag, result)))))))), (0, distinct_pending_1.distinctPending)(), (0, stack_1.addToStack)(tag)); } //# sourceMappingURL=when-done.js.map