UNPKG

@magicbell/core

Version:

Official MagicBell API wrapper

40 lines 975 B
import Store from './Store.js'; /** * A store that keep tracks of pagination as well. * * @example * const store = new PaginatedStore(); * store.push(model); */ export default class PaginatedStore extends Store { total = 0; totalPages; page; perPage; currentPage = 1; get hasNextPage() { return this.currentPage < this.totalPages; } /** * Add a model at the end of the `items` array. */ push(model) { const added = super.push(model); if (added) this.total += 1; return added; } /** * Remove a model from the `items` array. * * If you want to delete a model from the server, use the `delete` method of * the model object instead. */ remove(model) { const removed = super.remove(model); if (removed) this.total = Math.max(0, this.total - 1); return removed; } } //# sourceMappingURL=PaginatedStore.js.map