in src/InMemoryProvider.ts [783:815]
private _getKeyValues(
key: string,
limit: number,
offset: number,
reverse: boolean
): ItemType[] {
if (limit <= 0) {
return [];
}
const idxValues = this._indexTree.get(key) as ItemType[];
// get may return undefined, if the key is not found
if (!idxValues) {
return idxValues;
}
if (offset >= idxValues.length) {
return [];
}
// Perf optimisation. No items to skip, and limit is at least the number of items we have in the index.
// we know that we will need the whole index values array to fulfill the results,
// skip using take/drop, return the whole array immediately.
if (offset <= 0 && limit >= idxValues.length) {
return reverse ? idxValues.slice().reverse() : idxValues;
}
const itemsToDrop = Math.min(limit, offset);
const itemsToTake = Math.min(limit, idxValues.length - offset);
return reverse
? takeRight(dropRight(idxValues, itemsToDrop), itemsToTake)
: take(drop(idxValues, itemsToDrop), itemsToTake);
}