@onehat/data 1.8.8 → 1.8.9

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.8.8",
3
+ "version": "1.8.9",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -357,9 +357,10 @@ class AjaxRepository extends Repository {
357
357
  * Loads data into the Repository.
358
358
  * This loads only a single page of data.
359
359
  * @param {object} params - Params to send to server
360
+ * @param {function} callback - Function to call after loading is complete
360
361
  * @fires beforeLoad,changeData,load,error
361
362
  */
362
- load = async (params) => {
363
+ load = async (params, callback = null) => {
363
364
  if (this.isDestroyed) {
364
365
  throw Error('this.load is no longer valid. Repository has been destroyed.');
365
366
  }
@@ -417,6 +418,10 @@ class AjaxRepository extends Repository {
417
418
 
418
419
  this.emit('changeData', this.entities);
419
420
  this.emit('load', this);
421
+
422
+ if (callback) {
423
+ callback(this.entities);
424
+ }
420
425
  })
421
426
  .finally(() => {
422
427
  this.isLoading = false;
@@ -426,10 +431,11 @@ class AjaxRepository extends Repository {
426
431
  /**
427
432
  * Reload a single entity from storage.
428
433
  * If the entity is in the internal representation, update it.
434
+ * @param {function} callback - Function to call after loading is complete
429
435
  * @returns {entity} The newly updated entity
430
436
  * @fires reloadEntity,beforeLoad,changeData,load,error
431
437
  */
432
- reloadEntity = async (entity) => {
438
+ reloadEntity = async (entity, callback = null) => {
433
439
  if (this.isDestroyed) {
434
440
  throw Error('this.reloadEntity is no longer valid. Repository has been destroyed.');
435
441
  }
@@ -470,6 +476,10 @@ class AjaxRepository extends Repository {
470
476
  this.emit('changeData', this.entities);
471
477
  this.emit('load', this);
472
478
  this.emit('reloadEntity', entity);
479
+
480
+ if (callback) {
481
+ callback(entity);
482
+ }
473
483
  })
474
484
  .finally(() => {
475
485
  this.isLoading = false;