import { ContainerInstance } from './container-instance.class'; import { ServiceMetadata } from './interfaces/service-metadata.interface'; import { ContainerTreeVisitor, VisitRetrievalOptions } from './interfaces/tree-visitor.interface'; import { Disposable } from './types/disposable.type'; import { ServiceIdentifier } from './types/service-identifier.type'; /** * A collection of individual visitor objects, combined into a collection. * This class implements the {@link ContainerTreeVisitor} interface * (modulo {@link ContainerTreeVisitor.visitContainer}). * * When an event is dispatched upon the collection, all attached * visitors will be notified in the order in which they were * added to the collection. * @experimental * * @example * ```ts * const collection = new VisitorCollection(); * * // Add our visitor to the collection. * collection.addVisitor(new MyVisitor()); * * // Dispatch an event onto the collection, * // which will be broadcast to all attached visitors. * collection.visitChildContainer(Container.ofChild('hello')); * ``` * * @group Tree Visitors */ export declare class VisitorCollection implements Disposable, Omit { /** Whether the instance is disposed. */ disposed: boolean; /** The visitors stored within the collection. */ protected visitors: ContainerTreeVisitor[]; /** * A flag stating whether any visitors are currently present in the collection. * If not, all notifications will be ignored. * * This is mostly for optimisation. */ protected anyVisitorsPresent: boolean; /** * A flag which states whether any visitors should be notified. * If the collection has been disposed or no visitors are present, * this evaluates to `false`. */ protected get notifyVisitors(): boolean; /** * Iterate the list of visitors, excluding any which have been disposed. * Does not perform any iteration if no visitors are present. * * @param callback A function to call for each visitor in the collection. */ forEach(callback: { (visitor: ContainerTreeVisitor): void; }): void; visitChildContainer(child: ContainerInstance): void; visitOrphanedContainer(container: ContainerInstance): void; visitNewService(serviceOptions: ServiceMetadata): void; visitRetrieval(identifier: ServiceIdentifier, options: VisitRetrievalOptions): void; /** * Add a visitor to the collection. * @experimental * * @param visitor The visitor to append to the collection. * @param container The container to initialise the container on. */ addVisitor(visitor: ContainerTreeVisitor, container: ContainerInstance): boolean; /** * Remove a visitor from the collection, * if it was already present. * @experimental * * @param visitor The visitor to remove from the collection. */ removeVisitor(visitor: ContainerTreeVisitor): boolean; /** * Forward any orphaned container events to the visitor * through a proxy visitor attached to the default container. * * This is used when a visitor implements the {@link ContainerTreeVisitor.visitOrphanedContainer} * handler, but the visitor was attached to a non-default container instance. */ protected static forwardOrphanedContainerEvents(upstreamVisitor: ContainerTreeVisitor): boolean; dispose(): void; }