@jovian/type-tools
Version:
TypeTools is a Typescript library for providing extensible tooling runtime validations and type helpers.
43 lines • 1.61 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.hbi = exports.hbiLong = exports.hotblock = void 0;
var ix_config_1 = require("./ix.config");
var ix_entity_1 = require("./ix.entity");
var ix_halflifed_1 = require("./ix.halflifed");
function hotblock(bindTarget, lockName, threshold, initialValue, halflife) {
if (threshold === void 0) { threshold = ix_config_1.ixConfig.hotblock.threshold; }
if (initialValue === void 0) { initialValue = 0; }
if (halflife === void 0) { halflife = ix_config_1.ixConfig.hotblock.halflife; }
if (!bindTarget) {
return null;
}
var hbkey = "__ixe_hotblock_".concat(lockName);
var hbObj = bindTarget[hbkey];
if (!hbObj) {
hbObj = {
tracker: new ix_halflifed_1.HalfLifed({ hl: halflife, v: initialValue }),
last: 0,
threshold: threshold,
passed: false
};
if (bindTarget instanceof ix_entity_1.Entity) {
bindTarget.lcManage(hbObj.tracker);
}
Object.defineProperty(bindTarget, hbkey, { value: hbObj });
}
if (hbObj.tracker.value <= hbObj.threshold) {
hbObj.passed = true;
hbObj.last = Date.now();
hbObj.tracker.add(1);
}
else {
hbObj.passed = false;
}
return hbObj;
}
exports.hotblock = hotblock;
function hbiLong(bindTarget, lockName) { return hotblock(bindTarget, lockName, 4, 4); }
exports.hbiLong = hbiLong;
function hbi(bindTarget, lockName) { return hotblock(bindTarget, lockName, 9, 9); }
exports.hbi = hbi;
//# sourceMappingURL=ix.hotblock.js.map
;