@onehat/data 1.18.2 → 1.18.4

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.18.2",
3
+ "version": "1.18.4",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -124,6 +124,7 @@ class AjaxRepository extends Repository {
124
124
  add: false,
125
125
  edit: false,
126
126
  delete: false,
127
+ deletePhantom: false,
127
128
  };
128
129
 
129
130
  }
@@ -537,6 +538,7 @@ class AjaxRepository extends Repository {
537
538
  add: false,
538
539
  edit: false,
539
540
  delete: false,
541
+ deletePhantom: false,
540
542
  };
541
543
  }
542
544
 
@@ -763,7 +765,11 @@ class AjaxRepository extends Repository {
763
765
  return;
764
766
  }
765
767
 
766
- this._operations.delete = true;
768
+ if (entity.isRemotePhantomMode && entity.isPhantom) {
769
+ this._operations.deletePhantom = true;
770
+ } else {
771
+ this._operations.delete = true;
772
+ }
767
773
  entity.isSaving = true;
768
774
 
769
775
  const
@@ -792,7 +798,7 @@ class AjaxRepository extends Repository {
792
798
 
793
799
  // Delete it from this.entities
794
800
  const id = entity.id;
795
- this.entities = _.filter(this.entities, (entity) => entity.id === id);
801
+ this.entities = _.filter(this.entities, (entity) => entity.id !== id);
796
802
  entity.destroy();
797
803
  });
798
804
  }
@@ -810,7 +816,7 @@ class AjaxRepository extends Repository {
810
816
  return;
811
817
  }
812
818
 
813
- this._operations.delete = true;
819
+ this._operations.delete = true; // NOTE: We don't use batchDelete for remotePhantom records
814
820
 
815
821
  const
816
822
  method = this.methods.delete,
@@ -966,8 +972,16 @@ class AjaxRepository extends Repository {
966
972
 
967
973
  // Do we need to reload?
968
974
  if (!this.eventsPaused) {
969
- if (this._operations.add && this.isRemotePhantomMode) {
975
+ if (this.isRemotePhantomMode && (this._operations.add || this._operations.deletePhantom)) {
970
976
  // Do nothing, as we don't want to immediately reload on add for a remote phantom mode record. It won't appear, and it will cause all kinds of trouble!
977
+ if (this._operations.deletePhantom) {
978
+ // sweep existing deleted records and remove them
979
+ _.each(this.entities, (entity) => {
980
+ if (entity.isDeleted && entity.isDestroyed) {
981
+ this.removeEntity(entity);
982
+ }
983
+ })
984
+ }
971
985
  } else if (this._operations.add || this._operations.delete) {
972
986
  this.reload();
973
987
  } else {
@@ -1796,7 +1796,7 @@ export default class Repository extends EventEmitter {
1796
1796
  if (!entity) {
1797
1797
  return;
1798
1798
  }
1799
- if (entity.isPhantom) {
1799
+ if (entity.isPhantom && !entity.isRemotePhantomMode) {
1800
1800
  // Just auto-remove it. Don't bother saving to storage medium.
1801
1801
  this.removeEntity(entity);
1802
1802
  } else {
@@ -1818,7 +1818,9 @@ export default class Repository extends EventEmitter {
1818
1818
  */
1819
1819
  removeEntity(entity) { // standard function notation so it can be called by child class via super.removeEntity
1820
1820
  this.entities = _.filter(this.entities, e => e !== entity);
1821
- entity.destroy();
1821
+ if (!entity.isDestroyed) {
1822
+ entity.destroy();
1823
+ }
1822
1824
  }
1823
1825
 
1824
1826
  /**