UNPKG

@itwin/unified-selection

Version:

Package for managing unified selection in iTwin.js applications.

73 lines 2.8 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.formIdBindings = formIdBindings; exports.genericExecuteQuery = genericExecuteQuery; exports.releaseMainThreadOnItemsCount = releaseMainThreadOnItemsCount; exports.safeDispose = safeDispose; require("./DisposePolyfill.js"); const rxjs_1 = require("rxjs"); const presentation_shared_1 = require("@itwin/presentation-shared"); /** * Forms ECSql bindings from given ID's. * @internal */ function formIdBindings(property, ids, bindings) { if (ids.length > 1000) { bindings.push({ type: "idset", value: ids }); return `InVirtualSet(?, ${property})`; } if (ids.length === 0) { return `FALSE`; } ids.forEach((id) => bindings.push({ type: "id", value: id })); return `${property} IN (${ids.map(() => "?").join(",")})`; } /** * Executes given ECSql query and extracts data from rows. Additionally handles main thread releasing. * @internal */ async function* genericExecuteQuery({ queryExecutor, parseQueryRow, query, config, }) { const releaseMainThread = (0, presentation_shared_1.createMainThreadReleaseOnTimePassedHandler)(); const reader = queryExecutor.createQueryReader(query, config); for await (const row of reader) { yield parseQueryRow(row); await releaseMainThread(); } } /** * Emits a certain amount of values, then releases the main thread for other timers to use. * @internal */ function releaseMainThreadOnItemsCount(elementCount) { return (obs) => { return obs.pipe((0, rxjs_1.bufferCount)(elementCount), (0, rxjs_1.concatMap)((buff, i) => { const out = (0, rxjs_1.of)(buff); if (i === 0 && buff.length < elementCount) { return out; } return out.pipe((0, rxjs_1.delay)(0)); }), (0, rxjs_1.concatAll)()); }; } /** * A helper that disposes the given object, if it's disposable. * * The first option is to dispose using the deprecated `dispose` method if it exists on the object. * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is * considered as non-disposable and nothing is done with it. * * @internal */ function safeDispose(disposable) { if ("dispose" in disposable) { disposable.dispose(); } else if (Symbol.dispose in disposable) { disposable[Symbol.dispose](); } } //# sourceMappingURL=Utils.js.map