"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCustomCachedSelector = exports.globalSelectorCache = void 0;
const toolkit_1 = require("@reduxjs/toolkit");
const re_reselect_1 = __importDefault(require("re-reselect"));
const createSelectorWithLRU = ((selectors, combiner) => (0, toolkit_1.createSelector)(selectors, combiner, {
    memoizeOptions: {
        maxSize: 2,
    },
}));
class CustomMapCache {
    cache = new Map();
    set(key, selectorFn) {
        this.cache.set(key, selectorFn);
    }
    get(key) {
        return this.cache.get(key);
    }
    remove(key) {
        this.cache.delete(key);
    }
    clear() {
        this.cache.clear();
    }
    isEmpty() {
        return this.cache.size === 0;
    }
    isValidCacheKey(key) {
        return typeof key === 'string';
    }
}
const keySelector = ({ chartId }) => chartId;
class GlobalSelectorCache {
    selectorCaches = [];
    registerSelector() {
        const cache = new CustomMapCache();
        this.selectorCaches.push(cache);
        return {
            keySelector,
            cacheObject: cache,
            selectorCreator: createSelectorWithLRU,
        };
    }
    removeKeyFromAll(key) {
        this.selectorCaches.forEach((cache) => {
            cache.remove(key);
        });
    }
}
exports.globalSelectorCache = new GlobalSelectorCache();
exports.createCustomCachedSelector = ((...args) => {
    return (0, re_reselect_1.default)(...args)(exports.globalSelectorCache.registerSelector());
});
//# sourceMappingURL=create_selector.js.map