Skip to content

Instantly share code, notes, and snippets.

View atamocius's full-sized avatar
😜

Anton Mata atamocius

😜
View GitHub Profile
@atamocius
atamocius / paging-utils.js
Last active September 2, 2020 12:09
A set of JS functions that help in implementing paging.
import range from 'lodash/range';
/**
* Returns the items in a given page.
* @template T
* @param {number} offset The index offset based on the given `pageIndex`
* (precomputed from `calcOffset`).
* @param {number} itemsPerPage The number of items per page.
* @param {T[]} items The array of items.
*/
@atamocius
atamocius / paging-utils-example.js
Last active September 2, 2020 12:25
An example of how to use the paging utilities
import {
calcPageNumbers,
calcOffset,
calcPageCount,
getPageItems,
} from './paging-utils';
// We'll use lodash's `clamp` function
import clamp from 'lodash/clamp';
@atamocius
atamocius / paging-utils-example-2.js
Last active September 2, 2020 12:34
A slightly more practical example of how to use the paging utilities
import {
calcPageNumbers,
calcOffset,
calcPageCount,
getPageItems,
} from './paging-utils';
// We'll use lodash's `clamp` function
import clamp from 'lodash/clamp';