servido
Version:
Versatile services for React ⚗️
61 lines (60 loc) • 4.63 kB
TypeScript
import { Service, ServiceClass } from "./service";
import { ServiceDependent } from "./service-dependent";
import { Class, ServiceIdentifier } from "./service-types";
/** Contains the currently constructed services, dependents and requirements. */
export declare class ServiceInstanceStore {
readonly parent?: ServiceInstanceStore;
protected readonly constructed: Map<ServiceClass<Service, any[]>, Map<ServiceIdentifier, Service>>;
protected readonly constructing: Map<Service, Promise<void>>;
protected readonly constructors: Map<Service, ServiceClass<Service, any[]>>;
protected readonly clearIds: Map<Service, symbol>;
protected readonly dependents: Map<Service, Set<ServiceDependent>>;
protected readonly requirements: Map<ServiceDependent, Set<Service>>;
protected readonly circularRequirements: Map<Service, Set<Service>>;
protected readonly circularDependents: Map<Service, Set<Service>>;
protected readonly errorListeners: Set<(error: Error) => void>;
constructor(parent?: ServiceInstanceStore);
has(service: Service): boolean;
protected addRequirement(dependent: ServiceDependent, service: Service): void;
/** Deletes a requirement of a dependent and deletes the set of requirements if it is empty. */
protected deleteRequirement(dependent: ServiceDependent, service: Service): boolean;
hasRequirement(dependent: ServiceDependent, service: Service): boolean;
getRequirements(dependent: ServiceDependent): Set<Service> | undefined;
/** Ensures a set of required services for a dependent (does not iterate through parents since the context of dependents will always be the same). */
protected ensureRequirements(dependent: ServiceDependent): Set<Service>;
hasDependents(service: Service): boolean;
protected getDependents(service: Service): Set<ServiceDependent | undefined>;
protected ensureDependents(service: Service): Set<ServiceDependent>;
addCircularRequirement(dependent: Service, service: Service): void;
protected deleteCircularRequirement(dependent: Service, service: Service): boolean;
protected getCircularRequirements(dependent: Service): Set<Service> | undefined;
/** Ensures a set of required services for a dependent (does not iterate through parents since the context of dependents will always be the same). */
protected ensureCircularRequirements(dependent: Service): Set<Service>;
protected getCircularDependents(dependent: Service): Set<Service> | undefined;
/** Ensures a set of required services for a dependent (does not iterate through parents since the context of dependents will always be the same). */
protected ensureCircularDependents(dependent: Service): Set<Service>;
/** Ensures a map of constructed services for a constructor (does not iterate through parents since instances should always be stored nearest, and only fallback to parents). */
ensureLocalConstructedMap(constructor: ServiceClass): Map<ServiceIdentifier, Service>;
hasConstructed(constructor: ServiceClass, id: ServiceIdentifier): boolean;
/** Gets the nearest constructed instance with the same `id`. If the `id` is undefined, it wil fallback to find the nearest instance. */
getConstructed(constructor: ServiceClass, id: ServiceIdentifier): Service | undefined;
/** Deletes the nearest constructed service with a specific id. */
deleteConstructed(constructor: ServiceClass, id: ServiceIdentifier): boolean;
setConstructed(constructor: ServiceClass, id: ServiceIdentifier, service: Service): void;
setConstructing(service: Service, promise: Promise<void>): void;
getConstructing(service: Service): Promise<void> | undefined;
deleteConstructing(service: Service): boolean;
protected getConstructedSetUp<T extends Service>(constructor: Class<T>): Set<T>;
getConstructedSet(constructor: ServiceClass): Set<Service>;
protected getConstructedIdsUp(constructor: ServiceClass): Set<ServiceIdentifier>;
getConstructedIds(constructor: ServiceClass): Set<ServiceIdentifier>;
getConstructor(service: Service): ServiceClass | undefined;
deleteConstructor(service: Service): boolean;
getClearId(service: Service): symbol | undefined;
setClearId(service: Service, clearId: symbol): symbol;
deleteClearId(service: Service): boolean;
nest(): ServiceInstanceStore;
find(where: (instances: ServiceInstanceStore) => unknown): ServiceInstanceStore | undefined;
onError(listener: (error: Error) => void): () => boolean;
protected notifyError(error: Error): void;
}