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