@onehat/data 1.19.10 → 1.19.11

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.19.10",
3
+ "version": "1.19.11",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -399,6 +399,17 @@ class AjaxRepository extends Repository {
399
399
  this.emit('beforeLoad'); // TODO: canceling beforeLoad will cancel the load operation
400
400
  this.markLoading();
401
401
 
402
+ if (params?.showMore) {
403
+ delete params.showMore;
404
+ this.isShowingMore = true;
405
+ } else {
406
+ this.isShowingMore = false;
407
+ }
408
+ if (this.isShowingMore) {
409
+ this.pauseEvents();
410
+ this.setPage(this.page +1);
411
+ this.resumeEvents();
412
+ }
402
413
 
403
414
  if (!_.isNil(params) && _.isObject(params)) {
404
415
  this.setParams(params);
@@ -426,14 +437,23 @@ class AjaxRepository extends Repository {
426
437
  message
427
438
  } = this._processServerResponse(result);
428
439
 
429
- this._destroyEntities();
430
-
431
- // Set the current entities
432
- this.entities = _.map(root, (data) => {
433
- const entity = Repository._createEntity(this.schema, data, repository, true);
434
- this._relayEntityEvents(entity);
435
- return entity;
436
- });
440
+ if (this.isShowingMore) {
441
+ // Add to the current entities
442
+ const newEntities = _.map(root, (data) => {
443
+ const entity = Repository._createEntity(this.schema, data, repository, true);
444
+ this._relayEntityEvents(entity);
445
+ return entity;
446
+ });
447
+ this.entities = this.entities.concat(newEntities);
448
+ } else {
449
+ // Replace the current entities
450
+ this._destroyEntities();
451
+ this.entities = _.map(root, (data) => {
452
+ const entity = Repository._createEntity(this.schema, data, repository, true);
453
+ this._relayEntityEvents(entity);
454
+ return entity;
455
+ });
456
+ }
437
457
 
438
458
  // Set the total records that pass filter
439
459
  this.total = total;
@@ -456,6 +476,11 @@ class AjaxRepository extends Repository {
456
476
  });
457
477
  }
458
478
 
479
+ showMore = (params = {}, callback) => {
480
+ params.showMore = true;
481
+ return this.load(params, callback);
482
+ }
483
+
459
484
  /**
460
485
  * Reload a single entity from storage.
461
486
  * If the entity is in the internal representation, update it.
@@ -102,6 +102,11 @@ export default class Repository extends EventEmitter {
102
102
  */
103
103
  isPaginated: false,
104
104
 
105
+ /**
106
+ * @member {bool} isShowingMore - Whether this repository is in "show more" mode
107
+ */
108
+ isShowingMore: false,
109
+
105
110
  /**
106
111
  * @member {number} pageSize - Max number of entities per page
107
112
  * Example: For "Showing 21-30 of 45" This would be 10