@mui/x-charts
Version:
The community edition of MUI X Charts components.
44 lines (40 loc) • 1.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createSelector = void 0;
var _reselect = require("reselect");
const reselectCreateSelector = (0, _reselect.createSelectorCreator)({
memoize: _reselect.lruMemoize,
memoizeOptions: {
maxSize: 1,
equalityCheck: Object.is
}
});
const cache = new WeakMap();
/**
* Method wrapping reselect's createSelector to provide caching for chart instances.
*
*/
const createSelector = (...createSelectorArgs) => {
const selector = (state, selectorArgs) => {
const cacheKey = state.cacheKey;
// If there is no cache for the current chart instance, create one.
let cacheForCurrentChartInstance = cache.get(cacheKey);
if (!cacheForCurrentChartInstance) {
cacheForCurrentChartInstance = new Map();
cache.set(cacheKey, cacheForCurrentChartInstance);
}
// If there is a cached selector, execute it.
const cachedSelector = cacheForCurrentChartInstance.get(createSelectorArgs);
if (cachedSelector) {
return cachedSelector(state, selectorArgs);
}
// Otherwise, create a new selector and cache it and execute it.
const fn = reselectCreateSelector(...createSelectorArgs);
cacheForCurrentChartInstance.set(createSelectorArgs, fn);
return fn(state, selectorArgs);
};
return selector;
};
exports.createSelector = createSelector;
;