UNPKG

rx-query

Version:
35 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prefetch = void 0; const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const query_1 = require("./query"); function prefetch(key, ...inputs) { const { query: inputQuery, queryParam, queryConfig } = parseInput(inputs); queryParam .pipe((0, operators_1.mergeMap)((parameter) => (0, query_1.query)(key, parameter, inputQuery, queryConfig).pipe((0, operators_1.observeOn)(rxjs_1.asapScheduler), (0, operators_1.take)(1)))) .subscribe(); } exports.prefetch = prefetch; function parseInput(inputs) { const [firstInput, secondInput, thirdInput] = inputs; const hasParamInput = typeof firstInput !== 'function'; const queryParam = hasParamInput ? (0, rxjs_1.isObservable)(firstInput) ? firstInput : (0, rxjs_1.of)(firstInput) : (0, rxjs_1.of)(null); const query = (typeof firstInput === 'function' ? firstInput : secondInput); const inputConfig = (hasParamInput ? thirdInput : secondInput); return { query, queryParam: queryParam.pipe((0, operators_1.shareReplay)({ refCount: true, bufferSize: 1, })), queryConfig: inputConfig, }; } //# sourceMappingURL=prefetch.js.map