"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Keeps track of reserved DOM IDs so that the IDs are rendered only once.
 **/
class DOMIdService {
    constructor() {
        this.ids = {};
        // First call returns id, next call (and only the very next) reserves the id until it is released.
        this.reserve = (id, sendId) => {
            if (this.ids[id] && this.ids[id].length) {
                this.ids[id].push(sendId);
            }
            else {
                this.ids[id] = [sendId]; // Just mark that the id is now used. It isn't reserved yet.
                return id;
            }
        };
        this.release = (id, sendId) => {
            if (this.ids[id]) {
                const idx = this.ids[id].indexOf(sendId);
                this.ids[id].splice(idx, 1);
                if (this.ids[id].length > 0) {
                    this.ids[id][0](id);
                }
            }
        };
    }
}
exports.default = DOMIdService;
