@onehat/data 1.22.23 → 1.22.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Repository/Ajax.js +18 -2
package/package.json
CHANGED
package/src/Repository/Ajax.js
CHANGED
|
@@ -477,7 +477,23 @@ class AjaxRepository extends Repository {
|
|
|
477
477
|
this.setBaseParam(this.paramPageSize, this.isPaginated ? this.pageSize : null);
|
|
478
478
|
|
|
479
479
|
if (this.isLoaded && !this.eventsPaused) {
|
|
480
|
-
|
|
480
|
+
const
|
|
481
|
+
currentEntityCount = this.entities.length,
|
|
482
|
+
newPageSize = this.pageSize;
|
|
483
|
+
if (this.page === 1 && currentEntityCount >= newPageSize && this.isPaginated) {
|
|
484
|
+
// Optimization: if we're on page 1 and already have enough entities
|
|
485
|
+
// for the new page size, just truncate the existing data instead of reloading
|
|
486
|
+
const entitiesToRemove = this.entities.splice(newPageSize);
|
|
487
|
+
entitiesToRemove.forEach(entity => entity.destroy());
|
|
488
|
+
this._setPaginationVars();
|
|
489
|
+
this.emit('changeData', this.entities);
|
|
490
|
+
if (this.debugMode) {
|
|
491
|
+
console.log(`Truncated entities from ${currentEntityCount} to ${newPageSize}`);
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
// We need more data or we're not on page 1, so reload
|
|
495
|
+
return this.reload();
|
|
496
|
+
}
|
|
481
497
|
}
|
|
482
498
|
}
|
|
483
499
|
|
|
@@ -496,7 +512,7 @@ class AjaxRepository extends Repository {
|
|
|
496
512
|
* @fires beforeLoad,changeData,load,error
|
|
497
513
|
*/
|
|
498
514
|
async load(params, callback = null) {
|
|
499
|
-
if (this.isTree
|
|
515
|
+
if (this.isTree) {
|
|
500
516
|
return this.loadRootNodes();
|
|
501
517
|
}
|
|
502
518
|
if (this.isDestroyed) {
|