import { FactoryProvider , InjectionToken , ValueProvider } from '@angular/core' ; import { IBaseImageryMapConstructor } from '../model/base-imagery-map' ; export const IMAGERY_MAPS_COLLECTIONS = new InjectionToken < IBaseImageryMapConstructor [ ] [ ] > ( 'IMAGERY_MAPS_COLLECTIONS' ) ; export const IMAGERY_MAPS = new InjectionToken < IImageryMaps > ( 'IMAGERY_MAPS' ) ; export interface IImageryMaps { [ mapType ] : IBaseImageryMapConstructor ; } export function ImageryMapsFactory ( imageryIMapCollection ) { return imageryIMapCollection . reduce ( ( a , b ) => [ ... a , ... b ] , [ ] ) . reduce ( ( object , baseImageryMapConstructor ) => { return { ... object , [ baseImageryMapConstructor . prototype . mapType ] : baseImageryMapConstructor } ; } , { } ) ; } export function createImageryMapsCollection ( imageryMaps ) { return { provide : IMAGERY_MAPS_COLLECTIONS , useValue : imageryMaps , multi : true } ; } export const ImageryMapsProvider = { provide : IMAGERY_MAPS , useFactory : ImageryMapsFactory , deps : [ IMAGERY_MAPS_COLLECTIONS ] } ;