UNPKG

vscroll

Version:
57 lines 2.48 kB
import { Direction } from '../../inputs/index'; var CheckBufferCall = /** @class */ (function () { function CheckBufferCall(context, logger) { this.context = context; this.logger = logger; } CheckBufferCall.prototype.fillEmpty = function (items, before, after) { if (!items.length) { this.logger.log('no items to fill the buffer; empty list'); return false; } if (!Number.isInteger(before) && !Number.isInteger(after)) { this.logger.log('no items to fill the buffer; wrong indexes'); return false; } this.logger.log(function () { return "going to fill the buffer with ".concat(items.length, " item(s)"); }); return true; }; CheckBufferCall.prototype.insertInBuffer = function (predicate, before, after) { var index = Number.isInteger(before) ? before : (Number.isInteger(after) ? after : NaN); var found = this.context.items.find(function (item) { return (predicate && predicate(item.get())) || (Number.isInteger(index) && index === item.$index); }); if (!found) { this.logger.log('no items to insert in buffer; empty predicate\'s result'); return NaN; } return found.$index; }; CheckBufferCall.prototype.insertVirtual = function (items, index, direction) { if (!items.length) { this.logger.log('no items to insert virtually; empty list'); return false; } var _a = this.context, firstIndex = _a.firstIndex, lastIndex = _a.lastIndex, finiteAbsMinIndex = _a.finiteAbsMinIndex, finiteAbsMaxIndex = _a.finiteAbsMaxIndex; if (index < finiteAbsMinIndex || index > finiteAbsMaxIndex) { this.logger.log(function () { return 'no items to insert virtually; ' + "selected index (".concat(index, ") does not match virtual area [").concat(finiteAbsMinIndex, "..").concat(finiteAbsMaxIndex, "]"); }); return false; } var before = direction === Direction.backward; if (!(index < firstIndex + (before ? 1 : 0) || index > lastIndex - (before ? 0 : 1))) { this.logger.log(function () { return "no items to insert virtually; selected index (".concat(index, ") belongs Buffer [").concat(firstIndex, "..").concat(lastIndex, "]"); }); return false; } this.logger.log(function () { return "going to insert ".concat(items.length, " item(s) virtually"); }); return true; }; return CheckBufferCall; }()); export { CheckBufferCall }; //# sourceMappingURL=checkCall.js.map