UNPKG

@qualweb/util

Version:
46 lines (45 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Cache = Cache; exports.FullMethodCache = FullMethodCache; function Cache(methodName) { return function (_target, _propertyKey, descriptor) { const method = descriptor.value; descriptor.value = function () { const page = window.qwPage; const element = arguments[0]; const selector = element.getElementSelector(); let result; if (page.isValueCached(selector, methodName)) { result = page.getCachedValue(selector, methodName); } else { result = method.apply(this, arguments); page.cacheValue(selector, methodName, result); } return result; }; }; } function FullMethodCache(methodName) { return function (_target, _propertyKey, descriptor) { const method = descriptor.value; descriptor.value = function () { const page = window.qwPage; const element = arguments[0]; let selector = element.getElementSelector(); for (let i = 2; i < arguments.length; i++) { selector += arguments[i]; } let result; if (page.isValueCached(selector, methodName)) { result = page.getCachedValue(selector, methodName); } else { result = method.apply(this, arguments); page.cacheValue(selector, methodName, result); } return result; }; }; }