@magicbell/core
Version:
Official MagicBell API wrapper
44 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Store_js_1 = tslib_1.__importDefault(require("./Store.js"));
/**
* A store that keep tracks of pagination as well.
*
* @example
* const store = new PaginatedStore();
* store.push(model);
*/
class PaginatedStore extends Store_js_1.default {
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;
}
}
exports.default = PaginatedStore;
//# sourceMappingURL=PaginatedStore.js.map