UNPKG

vscroll

Version:
149 lines 4.2 kB
import { Direction } from '../../inputs/index'; var Positions = /** @class */ (function () { function Positions() { this.reset(); } Positions.prototype.reset = function () { this.startDelta = 0; this.before = 0; }; return Positions; }()); var First = /** @class */ (function () { function First() { this.reset(); } First.prototype.reset = function () { this.index = NaN; this.indexBuffer = NaN; this.position = NaN; }; return First; }()); var Last = /** @class */ (function () { function Last() { this.reset(); } Last.prototype.reset = function () { this.index = NaN; this.indexBuffer = NaN; }; return Last; }()); var FirstVisible = /** @class */ (function () { function FirstVisible() { this.reset(); } FirstVisible.prototype.reset = function () { this.index = NaN; this.delta = 0; }; return FirstVisible; }()); var FetchModel = /** @class */ (function () { function FetchModel(directionPriority) { this.directionPriority = directionPriority; this.callCount = 0; this.positions = new Positions(); this.first = new First(); this.last = new Last(); this.firstVisible = new FirstVisible(); this.reset(); } FetchModel.prototype.reset = function () { this._newItemsData = null; this.items = []; this.positions.reset(); this.first.reset(); this.last.reset(); this.firstVisible.reset(); this.hasAnotherPack = false; this.direction = null; this.cancel = null; this.simulate = false; this.isCheck = false; this.doRemove = false; }; Object.defineProperty(FetchModel.prototype, "newItemsData", { get: function () { return this._newItemsData; }, set: function (items) { this._newItemsData = items; if (items && items.length) { this.callCount++; } }, enumerable: false, configurable: true }); Object.defineProperty(FetchModel.prototype, "shouldFetch", { get: function () { return !!this.count; }, enumerable: false, configurable: true }); Object.defineProperty(FetchModel.prototype, "hasNewItems", { get: function () { return !!((this._newItemsData && this._newItemsData.length)); }, enumerable: false, configurable: true }); Object.defineProperty(FetchModel.prototype, "index", { get: function () { return this.first.index; }, enumerable: false, configurable: true }); Object.defineProperty(FetchModel.prototype, "count", { get: function () { return !isNaN(this.first.index) && !isNaN(this.last.index) ? this.last.index - this.first.index + 1 : 0; }, enumerable: false, configurable: true }); FetchModel.prototype.shouldCheckPreSizeExpectation = function (lastBufferedIndex) { if (this.directionPriority === Direction.backward) { return false; } var lastFetched = this.items[this.items.length - 1]; return lastFetched && lastFetched.$index < lastBufferedIndex; }; FetchModel.prototype.startSimulate = function (items) { this.simulate = true; this._newItemsData = items.map(function (item) { return item.data; }); this.items = items; this.hasAnotherPack = false; }; FetchModel.prototype.stopSimulate = function () { this.simulate = false; this.isCheck = false; this.doRemove = false; }; FetchModel.prototype.fill = function (items, start) { this.startSimulate(items); this.first.index = items[0].$index; this.last.index = items[items.length - 1].$index; this.direction = Direction.forward; this.firstVisible.index = start; this.firstVisible.delta = 0; }; FetchModel.prototype.check = function (items) { this.startSimulate(items); this.last.index = items[0].$index; this.first.index = items[items.length - 1].$index; this.isCheck = true; }; FetchModel.prototype.update = function (index, delta, items, itemsToRemove) { this.startSimulate(items); this.firstVisible.index = index; this.firstVisible.delta = delta; this.doRemove = itemsToRemove.length > 0; }; return FetchModel; }()); export { FetchModel }; //# sourceMappingURL=fetch.js.map