@onehat/data 1.22.21 → 1.22.24

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.22.21",
3
+ "version": "1.22.24",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -367,6 +367,19 @@ class AjaxRepository extends Repository {
367
367
  return convertedConditions;
368
368
  }
369
369
 
370
+ /**
371
+ * Returns current value of any param query conditions
372
+ */
373
+ getParamConditions() {
374
+ const
375
+ existingConditions = this._params.conditions || {},
376
+ convertedConditions = {};
377
+ _.each(existingConditions, (value, key) => {
378
+ convertedConditions['conditions[' + key + ']'] = value;
379
+ });
380
+ return convertedConditions;
381
+ }
382
+
370
383
  /**
371
384
  * Determines if query param exists
372
385
  * @param {string} name - Param name
@@ -464,7 +477,32 @@ class AjaxRepository extends Repository {
464
477
  this.setBaseParam(this.paramPageSize, this.isPaginated ? this.pageSize : null);
465
478
 
466
479
  if (this.isLoaded && !this.eventsPaused) {
467
- return this.reload();
480
+ const
481
+ currentEntityCount = this.entities.length,
482
+ newPageSize = this.pageSize;
483
+
484
+ if (this.page === 1 && currentEntityCount >= newPageSize && this.isPaginated) {
485
+ // Optimization: if we're on page 1 and already have enough entities
486
+ // for the new page size, just truncate the existing data instead of reloading
487
+ const entitiesToRemove = this.entities.splice(newPageSize);
488
+
489
+ entitiesToRemove.forEach(entity => entity.destroy());
490
+
491
+ this._setPaginationVars();
492
+
493
+ this.emit('changeData', this.entities);
494
+
495
+ if (this.debugMode) {
496
+ console.log(`Truncated entities from ${currentEntityCount} to ${newPageSize}`);
497
+ }
498
+ } else {
499
+ // We need more data or we're not on page 1, so reload
500
+ if (this.isTree && this.loadRootNodes) {
501
+ return this.loadRootNodes();
502
+ } else {
503
+ return this.reload();
504
+ }
505
+ }
468
506
  }
469
507
  }
470
508
 
@@ -201,7 +201,7 @@ class OneBuildRepository extends AjaxRepository {
201
201
  }
202
202
  });
203
203
 
204
- if (this.isAutoLoad && this.isLoaded && !this.eventsPaused) {
204
+ if ((this.isAutoLoad || this.isTree) && this.isLoaded && !this.eventsPaused) {
205
205
  if (this.isTree) {
206
206
  return this.loadRootNodes(1);
207
207
  } else {