import Target from './Target' ; import ElementsLibrary from './ElementsLibrary' ; import Teleport from '../Teleport' ; import { ElementMapping } from '../types' ; export default class ElementsLibraryTargetMapping { public name : string ; public version : string ; public type : string ; public library : string | ElementsLibrary ; public target : string | Target ; public extends : string | ElementsLibraryTargetMapping ; public maps : object = { } ; private teleport : Teleport ; constructor ( libraryMappingDefinition , instance ) { this . teleport = instance ; Object . assign ( this , libraryMappingDefinition ) ; } param target public setTarget ( target ) { this . target = target ; if ( this . extends ) { const extendedMapping = this . teleport . mapping ( this . extends as string ) ; if ( ! extendedMapping ) throw new Error ( `Mapping '${ this . name }' depends on '${ this . extends }' which was not yet registered for target '${ this . target . name }' Please register it before the current one` ) ; this . extends = extendedMapping ; this . maps = { ... this . extends . maps , ... this . maps , } ; } } param library public setLibrary ( library ) { this . library = library ; } param type public map ( type ) { return this . maps [ type ] ; } }