"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Provides svg caching functionality to avoid redundant XHR requests.
 * When the retrieved item doesn't exist in cache yet, a request is sent
 * to its 'src' url. The request's promise is cached for that 'src' key
 * and can be used for the whole session without repeating requests.
 */
class Cache {
    constructor() {
        this.cache = new Map();
        this.add = (src, svg) => {
            this.cache.set(src, svg);
        };
        this.get = (src) => {
            const item = this.cache.get(src);
            if (!item) {
                const promise = fetch(src).then(res => res.text());
                this.add(src, promise);
                return promise;
            }
            return item;
        };
        this.reset = () => {
            this.cache.clear();
        };
    }
}
const cache = new Cache();
exports.default = cache;
//# sourceMappingURL=cache.js.map