Comparing version 1.4.0-beta.2 to 1.4.0
@@ -169,18 +169,2 @@ import { Cache } from './buffer/cache'; | ||
} | ||
appendVirtually(count, fixRight) { | ||
if (fixRight) { | ||
this.items.forEach(item => item.updateIndex(item.$index - count)); | ||
this.cache.shiftIndexes(-count); | ||
this.items = [...this.items]; | ||
} | ||
this.shiftExtremum(count, fixRight); | ||
} | ||
prependVirtually(count, fixRight) { | ||
if (!fixRight) { | ||
this.items.forEach(item => item.updateIndex(item.$index + count)); | ||
this.cache.shiftIndexes(count); | ||
this.items = [...this.items]; | ||
} | ||
this.shiftExtremum(count, fixRight); | ||
} | ||
insertVirtually(items, index, direction, fixRight) { | ||
@@ -187,0 +171,0 @@ if (!this.checkCall.insertVirtual(items, index, direction)) { |
@@ -110,14 +110,2 @@ import { Direction } from '../../inputs/index'; | ||
} | ||
append(items) { | ||
this.startSimulate(items); | ||
this.last.index = items[items.length - 1].$index; | ||
this.first.index = items[0].$index; | ||
this.direction = Direction.forward; | ||
} | ||
prepend(items) { | ||
this.startSimulate(items); | ||
this.last.index = items[0].$index; | ||
this.first.index = items[items.length - 1].$index; | ||
this.direction = Direction.backward; | ||
} | ||
check(items) { | ||
@@ -124,0 +112,0 @@ this.startSimulate(items); |
@@ -1,5 +0,3 @@ | ||
import { Item } from '../../classes/item'; | ||
import Update from './update'; | ||
import Insert from './insert'; | ||
import { BaseAdapterProcessFactory, AdapterProcess, ProcessStatus } from '../misc/index'; | ||
import { Direction } from '../../inputs/index'; | ||
export default class Append extends BaseAdapterProcessFactory(AdapterProcess.append) { | ||
@@ -11,3 +9,3 @@ static run(scroller, { process, options }) { | ||
} | ||
const shouldAppend = Append.doAppend(scroller, params, process !== AdapterProcess.append); | ||
const shouldAppend = Append.doAppend(scroller, process, params); | ||
scroller.workflow.call({ | ||
@@ -18,80 +16,23 @@ process: Append.process, | ||
} | ||
static doAppend(scroller, params, prepend) { | ||
static doAppend(scroller, process, params) { | ||
const { bof, eof, increase, decrease } = params; | ||
const { buffer } = scroller; | ||
const { items, bof, eof, increase, decrease } = params; | ||
const fixRight = (prepend && !increase) || (!prepend && !!decrease); | ||
let result = false; | ||
if ((prepend && bof && !buffer.bof.get()) || (!prepend && eof && !buffer.eof.get())) { | ||
result = Append.doVirtual(scroller, items, prepend, fixRight); | ||
} | ||
else { | ||
if (!buffer.size) { | ||
result = Append.doEmpty(scroller, items, prepend, fixRight); | ||
} | ||
else { | ||
result = Append.doRegular(scroller, items, prepend, fixRight); | ||
} | ||
} | ||
return result; | ||
} | ||
static doVirtual(scroller, items, prepend, fixRight) { | ||
const { buffer, logger, viewport, state: { fetch } } = scroller; | ||
const absIndexToken = fixRight ? 'absMinIndex' : 'absMaxIndex'; | ||
if (!isFinite(buffer[absIndexToken])) { | ||
return false; | ||
} | ||
const prepend = process === AdapterProcess.prepend; | ||
const opposite = prepend ? !increase : decrease; | ||
let beforeIndex, afterIndex, items = params.items; | ||
if (prepend) { | ||
buffer.prependVirtually(items.length, fixRight); | ||
beforeIndex = (bof ? buffer.absMinIndex : buffer.minIndex) + (!buffer.size ? 1 : 0); | ||
items = [...items].reverse(); | ||
} | ||
else { | ||
buffer.appendVirtually(items.length, fixRight); | ||
afterIndex = (eof ? buffer.absMaxIndex : buffer.maxIndex) - (!buffer.size && !opposite ? 1 : 0); | ||
} | ||
const { index, diff } = viewport.getEdgeVisibleItem(buffer.items, Direction.backward); | ||
fetch.firstVisible.index = index; | ||
if (!isNaN(index)) { | ||
fetch.simulate = true; | ||
fetch.firstVisible.delta = -buffer.getSizeByIndex(index) + diff; | ||
} | ||
logger.log(() => `buffer.${[absIndexToken]} value is set to ${buffer[absIndexToken]}`); | ||
logger.stat(`after virtual ${prepend ? 'prepend' : 'append'}`); | ||
return true; | ||
} | ||
static doEmpty(scroller, items, prepend, fixRight) { | ||
const { buffer, state: { fetch } } = scroller; | ||
const absIndexToken = fixRight ? 'absMinIndex' : 'absMaxIndex'; | ||
const shift = prepend && !fixRight ? items.length - 1 : (!prepend && fixRight ? 1 - items.length : 0); | ||
const bufferLimit = buffer[absIndexToken] + (fixRight ? -1 : 1) * (items.length - 1); | ||
const newItems = []; | ||
const startIndex = buffer[prepend ? 'minIndex' : 'maxIndex']; | ||
let index = startIndex; | ||
items.forEach(item => { | ||
const newItem = new Item(index + shift, item, scroller.routines); | ||
Array.prototype[prepend ? 'unshift' : 'push'].call(newItems, newItem); | ||
index += (prepend ? -1 : 1); | ||
return Insert.doInsert(scroller, { | ||
items, | ||
beforeIndex, | ||
afterIndex, | ||
decrease: opposite | ||
}); | ||
if (bufferLimit !== buffer[absIndexToken]) { | ||
buffer[absIndexToken] = bufferLimit; | ||
scroller.logger.log(() => `buffer.${absIndexToken} value is set to ${buffer[absIndexToken]}`); | ||
} | ||
(prepend ? fetch.prepend : fetch.append).call(fetch, newItems); | ||
buffer.setItems(newItems); | ||
fetch.first.indexBuffer = !isNaN(buffer.firstIndex) ? buffer.firstIndex : index; | ||
fetch.last.indexBuffer = !isNaN(buffer.lastIndex) ? buffer.lastIndex : index; | ||
fetch.firstVisible.index = startIndex; | ||
return true; | ||
} | ||
static doRegular(scroller, items, prepend, fixRight) { | ||
const index = scroller.buffer[prepend ? 'firstIndex' : 'lastIndex']; | ||
const updateOptions = { | ||
predicate: ({ $index, data }) => { | ||
if ($index === index) { | ||
return prepend ? [...items.reverse(), data] : [data, ...items]; | ||
} | ||
return true; | ||
}, | ||
fixRight | ||
}; | ||
return Update.doUpdate(scroller, updateOptions); | ||
} | ||
} | ||
//# sourceMappingURL=append.js.map |
export default { | ||
name: 'vscroll', | ||
version: '1.4.0-beta.2' | ||
version: '1.4.0' | ||
}; | ||
//# sourceMappingURL=version.js.map |
@@ -221,18 +221,2 @@ import { __read, __spreadArray } from "tslib"; | ||
}; | ||
Buffer.prototype.appendVirtually = function (count, fixRight) { | ||
if (fixRight) { | ||
this.items.forEach(function (item) { return item.updateIndex(item.$index - count); }); | ||
this.cache.shiftIndexes(-count); | ||
this.items = __spreadArray([], __read(this.items)); | ||
} | ||
this.shiftExtremum(count, fixRight); | ||
}; | ||
Buffer.prototype.prependVirtually = function (count, fixRight) { | ||
if (!fixRight) { | ||
this.items.forEach(function (item) { return item.updateIndex(item.$index + count); }); | ||
this.cache.shiftIndexes(count); | ||
this.items = __spreadArray([], __read(this.items)); | ||
} | ||
this.shiftExtremum(count, fixRight); | ||
}; | ||
Buffer.prototype.insertVirtually = function (items, index, direction, fixRight) { | ||
@@ -239,0 +223,0 @@ if (!this.checkCall.insertVirtual(items, index, direction)) { |
@@ -134,14 +134,2 @@ import { Direction } from '../../inputs/index'; | ||
}; | ||
FetchModel.prototype.append = function (items) { | ||
this.startSimulate(items); | ||
this.last.index = items[items.length - 1].$index; | ||
this.first.index = items[0].$index; | ||
this.direction = Direction.forward; | ||
}; | ||
FetchModel.prototype.prepend = function (items) { | ||
this.startSimulate(items); | ||
this.last.index = items[0].$index; | ||
this.first.index = items[items.length - 1].$index; | ||
this.direction = Direction.backward; | ||
}; | ||
FetchModel.prototype.check = function (items) { | ||
@@ -148,0 +136,0 @@ this.startSimulate(items); |
import { __extends, __read, __spreadArray } from "tslib"; | ||
import { Item } from '../../classes/item'; | ||
import Update from './update'; | ||
import Insert from './insert'; | ||
import { BaseAdapterProcessFactory, AdapterProcess, ProcessStatus } from '../misc/index'; | ||
import { Direction } from '../../inputs/index'; | ||
var Append = /** @class */ (function (_super) { | ||
@@ -17,3 +15,3 @@ __extends(Append, _super); | ||
} | ||
var shouldAppend = Append.doAppend(scroller, params, process !== AdapterProcess.append); | ||
var shouldAppend = Append.doAppend(scroller, process, params); | ||
scroller.workflow.call({ | ||
@@ -24,80 +22,22 @@ process: Append.process, | ||
}; | ||
Append.doAppend = function (scroller, params, prepend) { | ||
Append.doAppend = function (scroller, process, params) { | ||
var bof = params.bof, eof = params.eof, increase = params.increase, decrease = params.decrease; | ||
var buffer = scroller.buffer; | ||
var items = params.items, bof = params.bof, eof = params.eof, increase = params.increase, decrease = params.decrease; | ||
var fixRight = (prepend && !increase) || (!prepend && !!decrease); | ||
var result = false; | ||
if ((prepend && bof && !buffer.bof.get()) || (!prepend && eof && !buffer.eof.get())) { | ||
result = Append.doVirtual(scroller, items, prepend, fixRight); | ||
} | ||
else { | ||
if (!buffer.size) { | ||
result = Append.doEmpty(scroller, items, prepend, fixRight); | ||
} | ||
else { | ||
result = Append.doRegular(scroller, items, prepend, fixRight); | ||
} | ||
} | ||
return result; | ||
}; | ||
Append.doVirtual = function (scroller, items, prepend, fixRight) { | ||
var buffer = scroller.buffer, logger = scroller.logger, viewport = scroller.viewport, fetch = scroller.state.fetch; | ||
var absIndexToken = fixRight ? 'absMinIndex' : 'absMaxIndex'; | ||
if (!isFinite(buffer[absIndexToken])) { | ||
return false; | ||
} | ||
var prepend = process === AdapterProcess.prepend; | ||
var opposite = prepend ? !increase : decrease; | ||
var beforeIndex, afterIndex, items = params.items; | ||
if (prepend) { | ||
buffer.prependVirtually(items.length, fixRight); | ||
beforeIndex = (bof ? buffer.absMinIndex : buffer.minIndex) + (!buffer.size ? 1 : 0); | ||
items = __spreadArray([], __read(items)).reverse(); | ||
} | ||
else { | ||
buffer.appendVirtually(items.length, fixRight); | ||
afterIndex = (eof ? buffer.absMaxIndex : buffer.maxIndex) - (!buffer.size && !opposite ? 1 : 0); | ||
} | ||
var _a = viewport.getEdgeVisibleItem(buffer.items, Direction.backward), index = _a.index, diff = _a.diff; | ||
fetch.firstVisible.index = index; | ||
if (!isNaN(index)) { | ||
fetch.simulate = true; | ||
fetch.firstVisible.delta = -buffer.getSizeByIndex(index) + diff; | ||
} | ||
logger.log(function () { return "buffer." + [absIndexToken] + " value is set to " + buffer[absIndexToken]; }); | ||
logger.stat("after virtual " + (prepend ? 'prepend' : 'append')); | ||
return true; | ||
}; | ||
Append.doEmpty = function (scroller, items, prepend, fixRight) { | ||
var buffer = scroller.buffer, fetch = scroller.state.fetch; | ||
var absIndexToken = fixRight ? 'absMinIndex' : 'absMaxIndex'; | ||
var shift = prepend && !fixRight ? items.length - 1 : (!prepend && fixRight ? 1 - items.length : 0); | ||
var bufferLimit = buffer[absIndexToken] + (fixRight ? -1 : 1) * (items.length - 1); | ||
var newItems = []; | ||
var startIndex = buffer[prepend ? 'minIndex' : 'maxIndex']; | ||
var index = startIndex; | ||
items.forEach(function (item) { | ||
var newItem = new Item(index + shift, item, scroller.routines); | ||
Array.prototype[prepend ? 'unshift' : 'push'].call(newItems, newItem); | ||
index += (prepend ? -1 : 1); | ||
return Insert.doInsert(scroller, { | ||
items: items, | ||
beforeIndex: beforeIndex, | ||
afterIndex: afterIndex, | ||
decrease: opposite | ||
}); | ||
if (bufferLimit !== buffer[absIndexToken]) { | ||
buffer[absIndexToken] = bufferLimit; | ||
scroller.logger.log(function () { return "buffer." + absIndexToken + " value is set to " + buffer[absIndexToken]; }); | ||
} | ||
(prepend ? fetch.prepend : fetch.append).call(fetch, newItems); | ||
buffer.setItems(newItems); | ||
fetch.first.indexBuffer = !isNaN(buffer.firstIndex) ? buffer.firstIndex : index; | ||
fetch.last.indexBuffer = !isNaN(buffer.lastIndex) ? buffer.lastIndex : index; | ||
fetch.firstVisible.index = startIndex; | ||
return true; | ||
}; | ||
Append.doRegular = function (scroller, items, prepend, fixRight) { | ||
var index = scroller.buffer[prepend ? 'firstIndex' : 'lastIndex']; | ||
var updateOptions = { | ||
predicate: function (_a) { | ||
var $index = _a.$index, data = _a.data; | ||
if ($index === index) { | ||
return prepend ? __spreadArray(__spreadArray([], __read(items.reverse())), [data]) : __spreadArray([data], __read(items)); | ||
} | ||
return true; | ||
}, | ||
fixRight: fixRight | ||
}; | ||
return Update.doUpdate(scroller, updateOptions); | ||
}; | ||
return Append; | ||
@@ -104,0 +44,0 @@ }(BaseAdapterProcessFactory(AdapterProcess.append))); |
export default { | ||
name: 'vscroll', | ||
version: '1.4.0-beta.2' | ||
version: '1.4.0' | ||
}; | ||
//# sourceMappingURL=version.js.map |
@@ -48,4 +48,2 @@ import { Item } from './item'; | ||
private shiftExtremum; | ||
appendVirtually(count: number, fixRight: boolean): void; | ||
prependVirtually(count: number, fixRight: boolean): void; | ||
insertVirtually(items: Data[], index: number, direction: Direction, fixRight: boolean): boolean; | ||
@@ -52,0 +50,0 @@ removeVirtually(indexes: number[], fixRight: boolean): void; |
@@ -59,4 +59,2 @@ import { Item } from '../item'; | ||
fill(items: Item[], start: number): void; | ||
append(items: Item[]): void; | ||
prepend(items: Item[]): void; | ||
check(items: Item[]): void; | ||
@@ -63,0 +61,0 @@ update(index: number, delta: number, items: Item[], itemsToRemove: Item[]): void; |
@@ -12,7 +12,4 @@ import { Scroller } from '../../scroller'; | ||
static run(scroller: Scroller, { process, options }: AppendRunOptions): void; | ||
static doAppend(scroller: Scroller, params: AdapterAppendPrependOptions, prepend: boolean): boolean; | ||
static doVirtual(scroller: Scroller, items: unknown[], prepend: boolean, fixRight: boolean): boolean; | ||
static doEmpty(scroller: Scroller, items: unknown[], prepend: boolean, fixRight: boolean): boolean; | ||
static doRegular(scroller: Scroller, items: unknown[], prepend: boolean, fixRight: boolean): boolean; | ||
static doAppend(scroller: Scroller, process: AdapterProcess, params: AdapterAppendPrependOptions): boolean; | ||
} | ||
export {}; |
{ | ||
"name": "vscroll", | ||
"version": "1.4.0-beta.2", | ||
"version": "1.4.0", | ||
"description": "Virtual scroll engine", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundles/vscroll.umd.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
457
3476711
29231