Make code shorter.
Some checks failed
continuous-integration/drone the build failed

This commit is contained in:
Manuel Friedli 2018-09-06 14:45:21 +02:00
parent 635b84fbd7
commit 86574e8616

View file

@ -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);
}
}