UNPKG

@itwin/core-frontend

Version:
98 lines 5.14 kB
import { Id64Arg, Id64Set, Id64String } from "@itwin/core-bentley"; import { SubCategoryAppearance, SubCategoryResultRow } from "@itwin/core-common"; import { IModelConnection } from "./IModelConnection"; /** A cancelable paginated request for subcategory information. * @see SubCategoriesCache * @internal */ export interface SubCategoriesRequest { /** The Ids of any categories which were requested but were not yet loaded. */ readonly missingCategoryIds: Id64Set; /** A promise which resolves to true when all of the requested categories have been loaded, or to false if not all categories were loaded. * Categories may fail to load if the request is explicitly canceled or if the IModelConnection is closed before all categories are loaded. */ readonly promise: Promise<boolean>; /** Cancels the request. */ cancel(): void; } /** A cache of information about the subcategories contained within an [[IModelConnection]]. It is populated on demand. * @internal */ export declare class SubCategoriesCache { private readonly _byCategoryId; private readonly _appearances; private readonly _imodel; private _missingAtTimeOfPreload; constructor(imodel: IModelConnection); /** Get the Ids of all subcategories belonging to the category with the specified Id, or undefined if no such information is present. */ getSubCategories(categoryId: string): Id64Set | undefined; /** Get the base appearance of the subcategory with the specified Id, or undefined if no such information is present. */ getSubCategoryAppearance(subCategoryId: Id64String): SubCategoryAppearance | undefined; /** Request that the subcategory information for all of the specified categories is loaded. * If all such information has already been loaded, returns undefined. * Otherwise, dispatches an asynchronous request to load those categories which are not already loaded and returns a cancellable request object * containing the corresponding promise and the set of categories still to be loaded. */ load(categoryIds: Id64Arg): SubCategoriesRequest | undefined; /** Load all subcategories that come from used spatial categories of the iModel into the cache. */ loadAllUsedSpatialSubCategories(): Promise<void>; /** Given categoryIds, return which of these are not cached. */ private getMissing; clear(): void; onIModelConnectionClose(): void; private static createSubCategoryAppearance; private processResults; /** Exposed strictly for tests. * @internal */ add(categoryId: string, subCategoryId: string, appearance: SubCategoryAppearance, override: boolean): void; getCategoryInfo(inputCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.CategoryInfo>>; getSubCategoryInfo(categoryId: Id64String, inputSubCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.SubCategoryInfo>>; private mapSubCategoryInfos; } /** This namespace and the types within it are exported strictly for use in tests. * @internal */ export declare namespace SubCategoriesCache { type Result = SubCategoryResultRow[]; class Request { private readonly _imodel; private readonly _categoryIds; private readonly _result; private _canceled; private _curCategoryIdsIndex; get wasCanceled(): boolean; constructor(categoryIds: Set<string>, imodel: IModelConnection, maxCategoriesPerQuery?: number); cancel(): void; dispatch(): Promise<Result | undefined>; } type QueueFunc = () => void; class QueueEntry { readonly categoryIds: Id64Set; readonly funcs: QueueFunc[]; constructor(categoryIds: Id64Set, func: QueueFunc); } /** A "queue" of SubCategoriesRequests, which consists of between 0 and 2 entries. Each entry specifies the set of category IDs to be loaded and a list of functions to be executed * when loading is completed. This is used to enforce ordering of operations upon subcategories despite the need to asynchronously load them. It incidentally also provides an * opportunity to reduce the number of backend requests by batching consecutive requests. * Chiefly used by [[Viewport]]. * @internal */ class Queue { protected _current?: QueueEntry; protected _next?: QueueEntry; protected _request?: SubCategoriesRequest; protected _disposed: boolean; /** Push a request onto the queue. The requested categories will be loaded if necessary, and then * the supplied function will be invoked. Any previously-pushed requests are guaranteed to be processed before this one. */ push(cache: SubCategoriesCache, categoryIds: Id64Arg, func: QueueFunc): void; /** Cancel all requests and empty the queue. */ [Symbol.dispose](): void; get isEmpty(): boolean; private pushCurrent; private processCurrent; private pushNext; } } //# sourceMappingURL=SubCategoriesCache.d.ts.map