Current section

Files

Jump to
ckeditor5_phoenix dist src shared async-registry.d.ts
Raw

dist/src/shared/async-registry.d.ts

/**
* Generic async registry for objects with an async destroy method.
* Provides a way to register, unregister, and execute callbacks on objects by ID.
*/
/**
* Generic async registry for objects with an async destroy method.
* Provides a way to register, unregister, and execute callbacks on objects by ID.
*/
export declare class AsyncRegistry<T extends Destructible> {
/**
* Map of registered items.
*/
private readonly items;
/**
* Map of callbacks that are waiting for an item to be registered.
*/
private readonly callbacks;
/**
* Set of watchers that observe changes to the registry.
*/
private readonly watchers;
/**
* Executes a function on an item.
* If the item is not yet registered, it will wait for it to be registered.
*
* @param id The ID of the item.
* @param fn The function to execute.
* @returns A promise that resolves with the result of the function.
*/
execute<R, E extends T = T>(id: RegistryId | null, fn: (item: E) => R): Promise<Awaited<R>>;
/**
* Registers an item.
*
* @param id The ID of the item.
* @param item The item instance.
*/
register(id: RegistryId | null, item: T): void;
/**
* Un-registers an item.
*
* @param id The ID of the item.
*/
unregister(id: RegistryId | null): void;
/**
* Gets all registered items.
*/
getItems(): T[];
/**
* Checks if an item with the given ID is registered.
*
* @param id The ID of the item.
* @returns `true` if the item is registered, `false` otherwise.
*/
hasItem(id: RegistryId | null): boolean;
/**
* Gets a promise that resolves with the item instance for the given ID.
* If the item is not registered yet, it will wait for it to be registered.
*
* @param id The ID of the item.
* @returns A promise that resolves with the item instance.
*/
waitFor<E extends T = T>(id: RegistryId | null): Promise<E>;
/**
* Destroys all registered items and clears the registry.
* This will call the `destroy` method on each item.
*/
destroyAll(): Promise<void>;
/**
* Registers a watcher that will be called whenever the registry changes.
*
* @param watcher The watcher function to register.
* @returns A function to unregister the watcher.
*/
watch(watcher: RegistryWatcher<T>): () => void;
/**
* Un-registers a watcher.
*
* @param watcher The watcher function to unregister.
*/
unwatch(watcher: RegistryWatcher<T>): void;
/**
* Notifies all watchers about changes to the registry.
*/
private notifyWatchers;
}
/**
* Interface for objects that can be destroyed.
*/
export type Destructible = {
destroy: () => Promise<any>;
};
/**
* Identifier of the registry item.
*/
type RegistryId = string;
/**
* Callback type for watching registry changes.
*/
type RegistryWatcher<T> = (items: Map<RegistryId | null, T>) => void;
export {};
//# sourceMappingURL=async-registry.d.ts.map