All files / src/services ServiceCollection.ts

70.58% Statements 12/17
100% Branches 2/2
61.53% Functions 8/13
73.33% Lines 11/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3957x         428x 428x       497x 497x                 21x   3x   33x           6x 6x       2x      
export class ServiceCollection<T> {
    services: { name: string; service: T; }[];
    _index: number;
 
    constructor(services?: { name: string, service: T }[]) {
        this.services = services || [];
        this._index = 0;
    }
 
    add(s: { name: string; service: T; }): ServiceCollection<T> {
        this.services.push(s);
        return this;
    }
 
    remove(name: string) : void {
        this.services = this.services.filter(s => s.name !== name)
    }
 
    get name() { return this.services[this._index].name; }
 
    get service() { return this.services[this._index].service; }
 
    get allServices() { return this.services.map(x => x.service) }
 
    get count() { return this.services.length; }
    get index() { return this._index; }
 
    reset() { this._index = 0 }
 
    next(): number {
        this._index = (this._index + 1) % this.count;
        return this._index;
    }
 
    clone(): ServiceCollection<T> {
        return new ServiceCollection([...this.services])
    }
}