UNPKG

@lotto24-angular/imports-orchestrator

Version:

Orchestrate dynamically imported components in Angular applications

44 lines (43 loc) 1.87 kB
import { ComponentRef, EventEmitter } from '@angular/core'; import { Observable } from 'rxjs'; import { ComponentIO } from './host-directive'; import { ImportsOrchestratorQueueItem } from './service'; export interface ImportLifecycle { /** * Emits when the import has been added to the queue (not started though). As the [import]-@Input may change, this may emit multiple times. */ importQueued: EventEmitter<void>; /** * Emits when importing has started. As the [import]-@Input may change, this may emit multiple times. */ importStarted: EventEmitter<void>; /** * Emits when importing has finished. As the [import]-@Input may change, this may emit multiple times. * The emitted value is whatever is returned as the result of the resolve function */ importFinished: EventEmitter<unknown>; /** * Emits when importing encounters an error. As the [import]-@Input may change, this may emit multiple times. */ importErrored: EventEmitter<unknown>; /** * Emits when importing has finished. Emits for every component that was imported. * When bootstrapping multiple components, this will emit multiple times * Plus, as the [import]-@Input may change, this may emit multiple times for the same component. * */ importComponent?: EventEmitter<ComponentRef<unknown>>; } type Item = Pick<ImportsOrchestratorQueueItem, 'identifier' | 'priority'>; export interface ImportsInterceptorHooks { queued: Observable<Item>; start: Observable<Item>; finish: Observable<Item>; error: Observable<[Item, unknown]>; } export interface ImportObservableComponentIO { readonly inputs$: Observable<ComponentIO>; readonly outputs$: Observable<ComponentIO>; } export type ImportsInterceptor = (identifier: string, hooks: ImportsInterceptorHooks) => void; export {};