/**
 * Generic Tracker which sets or resets provided flags
 */
export class Tracker {
    constructor(trackedItemsList) {
        this.trackedItems = {};
        this.trackedItems = trackedItemsList.reduce((r, key) => {
            return {
                ...r,
                [key]: false
            };
        }, this.trackedItems);
    }
    getTrackedItems() {
        return { ...this.trackedItems };
    }
    isTracked(key) {
        return this.trackedItems[key];
    }
    track(key) {
        const wasTracked = this.trackedItems[key];
        if (!wasTracked) {
            this.trackedItems[key] = true;
            this.onTrackingChange();
        }
    }
    untrack(key) {
        const wasTracked = this.trackedItems[key];
        if (wasTracked) {
            this.trackedItems[key] = false;
            this.onTrackingChange();
        }
    }
    trackAll() {
        if (this.allTracked()) {
            return;
        }
        this.setAllKeys(true);
        this.onTrackingChange();
    }
    untrackAll() {
        if (this.noneTracked()) {
            return;
        }
        this.setAllKeys(false);
        this.onTrackingChange();
    }
    allTracked() {
        return Object.values(this.trackedItems).every(x => x);
    }
    anyTracked() {
        return Object.values(this.trackedItems).some(x => x);
    }
    noneTracked() {
        return Object.values(this.trackedItems).every(x => !x);
    }
    onTrackingChange() { }
    setAllKeys(value) {
        this.trackedItems = Object.keys(this.trackedItems).reduce((r, key) => {
            return {
                ...r,
                [key]: value
            };
        }, this.trackedItems);
    }
}
//# sourceMappingURL=tracker.js.map