feature/upgrade #12
1 changed files with 6 additions and 11 deletions
|
@ -36,12 +36,7 @@ export class ConverterRegistryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConverter(id: string): Converter {
|
public getConverter(id: string): Converter {
|
||||||
for (let i = 0; i < this.converters.length; i++) {
|
return this.converters.find((converter: Converter): boolean => converter.getId() === id);
|
||||||
if (this.converters[i].getId() === id) {
|
|
||||||
return this.converters[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private init(): void {
|
private init(): void {
|
||||||
|
@ -67,11 +62,11 @@ export class ConverterRegistryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerConverter(converter: Converter): void {
|
private registerConverter(converter: Converter): void {
|
||||||
this.converters.forEach((c: Converter) => {
|
// Don't allow duplicate registration of the same converter id
|
||||||
if (c.getId() === converter.getId()) {
|
if (this.converters.some((c: Converter): boolean => c.getId() === converter.getId())) {
|
||||||
throw new Error('Converter-ID ' + converter.getId() + ' is already registered!');
|
throw new Error(`Converter-ID ${converter.getId()} is already registered!`);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
this.converters.push(converter);
|
this.converters.push(converter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue