import { FactoryProvider , Injector } from '@angular/core' ; import { BaseImageryPlugin , IBaseImageryPluginConstructor } from '../../model/base-imagery-plugin' ; import { ImageryCollectionEntity , PLUGINS_COLLECTIONS } from '../../providers/plugins-collection' ; import { BaseImageryMap } from '../../model/base-imagery-map' ; import { StaticClassProvider } from '@angular/core' ; export function BaseImageryPluginProviderFactory ( pluginsCollections , parent , map ) { const providers = pluginsCollections . reduce < ImageryCollectionEntity [ ] > ( ( previousValue , collection ) => [ ... previousValue , ... collection ] , [ ] ) . filter ( ( value ) => value . prototype instanceof BaseImageryPlugin ) . filter ( ( value ) => value . prototype . supported . some ( ins => map instanceof ins ) ) . map < StaticClassProvider > ( ( value ) => ( { provide : BaseImageryPlugin , useClass : value , multi : true , deps : [ ... value . prototype . deps ] } ) ) ; if ( providers . length === 0 ) { return [ ] ; } const childInjector = Injector . create ( { providers , parent } ) ; return childInjector . get ( BaseImageryPlugin ) ; } export const BaseImageryPluginProvider = { provide : BaseImageryPlugin , useFactory : BaseImageryPluginProviderFactory , deps : [ PLUGINS_COLLECTIONS , Injector , BaseImageryMap ] } ;