"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useSingletonCache;
var _isEqual = _interopRequireDefault(require("../vc-util/isEqual"));
/**
 * Singleton cache will only take latest `cacheParams` as key
 * and return the result for callback matching.
 */
function useSingletonCache() {
  let cacheRef = [null, null];
  const getCache = (cacheKeys, callback) => {
    const filteredKeys = cacheKeys.map(item => item instanceof HTMLElement || Number.isNaN(item) ? '' : item);
    if (!(0, _isEqual.default)(cacheRef[0], filteredKeys)) {
      cacheRef = [filteredKeys, callback()];
    }
    return cacheRef[1];
  };
  return getCache;
}