@onehat/data 1.16.3 → 1.16.6
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/Entity.js +11 -4
- package/src/Repository/Ajax.js +27 -1
- package/src/Repository/Repository.js +6 -6
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -105,7 +105,7 @@ class Entity extends EventEmitter {
|
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* @member {boolean} isPersisted - Whether this object has been persisted in a storage medium
|
|
108
|
-
* @
|
|
108
|
+
* @public
|
|
109
109
|
*/
|
|
110
110
|
this.isPersisted = false;
|
|
111
111
|
|
|
@@ -117,16 +117,22 @@ class Entity extends EventEmitter {
|
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* @member {boolean} isDeleted - Whether this object has been marked for deletion
|
|
120
|
-
* @
|
|
120
|
+
* @public
|
|
121
121
|
*/
|
|
122
122
|
this.isDeleted = false;
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* @member {boolean} isStaged - Whether this object has been marked for saving
|
|
126
|
-
* @
|
|
126
|
+
* @public
|
|
127
127
|
*/
|
|
128
128
|
this.isStaged = false;
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @member {boolean} isSaving - Whether this object is in the process of saving
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
this.isSaving = false;
|
|
135
|
+
|
|
130
136
|
/**
|
|
131
137
|
* @member {boolean} isDestroyed - Whether this object has been destroyed
|
|
132
138
|
* @public
|
|
@@ -143,6 +149,7 @@ class Entity extends EventEmitter {
|
|
|
143
149
|
* @member {boolean} isRemotePhantomMode - Whether this Entity uses the "alternate" CRUD mode, with tempIds from server (see OneBuild repository)
|
|
144
150
|
* On a Repository, this mode overrides repository.isAutoSave, entity.isPersisted, && entity.isDelayedSave.
|
|
145
151
|
* On an Entity, this mode affects the isPhantom getter.
|
|
152
|
+
* @public
|
|
146
153
|
* @readonly
|
|
147
154
|
*/
|
|
148
155
|
this.isRemotePhantomMode = isRemotePhantomMode;
|
|
@@ -1293,7 +1300,7 @@ class Entity extends EventEmitter {
|
|
|
1293
1300
|
}
|
|
1294
1301
|
|
|
1295
1302
|
/**
|
|
1296
|
-
* Marks an entity
|
|
1303
|
+
* Marks an entity for deletion.
|
|
1297
1304
|
* @param {boolean} bool - How it should be marked. Defaults to true.
|
|
1298
1305
|
*/
|
|
1299
1306
|
markDeleted = (bool = true) => {
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -532,6 +532,7 @@ class AjaxRepository extends Repository {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
this._operations.add = true;
|
|
535
|
+
entity.isSaving = true;
|
|
535
536
|
|
|
536
537
|
const
|
|
537
538
|
method = this.methods.add,
|
|
@@ -554,6 +555,8 @@ class AjaxRepository extends Repository {
|
|
|
554
555
|
message
|
|
555
556
|
} = this._processServerResponse(result);
|
|
556
557
|
|
|
558
|
+
entity.isSaving = false;
|
|
559
|
+
|
|
557
560
|
if (!success) {
|
|
558
561
|
this.throwError(message);
|
|
559
562
|
return;
|
|
@@ -590,6 +593,7 @@ class AjaxRepository extends Repository {
|
|
|
590
593
|
if (entity.isRemotePhantomMode) {
|
|
591
594
|
values.isRemotePhantom = true;
|
|
592
595
|
}
|
|
596
|
+
entity.isSaving = true;
|
|
593
597
|
return values;
|
|
594
598
|
}),
|
|
595
599
|
};
|
|
@@ -606,6 +610,10 @@ class AjaxRepository extends Repository {
|
|
|
606
610
|
message
|
|
607
611
|
} = this._processServerResponse(result);
|
|
608
612
|
|
|
613
|
+
_.each(entities, (entity) => {
|
|
614
|
+
entity.isSaving = false;
|
|
615
|
+
});
|
|
616
|
+
|
|
609
617
|
if (!success) {
|
|
610
618
|
this.throwError(message);
|
|
611
619
|
return;
|
|
@@ -634,6 +642,7 @@ class AjaxRepository extends Repository {
|
|
|
634
642
|
}
|
|
635
643
|
|
|
636
644
|
this._operations.edit = true;
|
|
645
|
+
entity.isSaving = true;
|
|
637
646
|
|
|
638
647
|
const
|
|
639
648
|
method = this.methods.edit,
|
|
@@ -656,6 +665,8 @@ class AjaxRepository extends Repository {
|
|
|
656
665
|
message
|
|
657
666
|
} = this._processServerResponse(result);
|
|
658
667
|
|
|
668
|
+
entity.isSaving = false;
|
|
669
|
+
|
|
659
670
|
if (!success) {
|
|
660
671
|
this.throwError(message);
|
|
661
672
|
return;
|
|
@@ -692,6 +703,7 @@ class AjaxRepository extends Repository {
|
|
|
692
703
|
if (entity.isRemotePhantomMode) {
|
|
693
704
|
values.isRemotePhantom = false;
|
|
694
705
|
}
|
|
706
|
+
entity.isSaving = true;
|
|
695
707
|
return values;
|
|
696
708
|
}),
|
|
697
709
|
};
|
|
@@ -708,6 +720,10 @@ class AjaxRepository extends Repository {
|
|
|
708
720
|
message
|
|
709
721
|
} = this._processServerResponse(result);
|
|
710
722
|
|
|
723
|
+
_.each(entities, (entity) => {
|
|
724
|
+
entity.isSaving = false;
|
|
725
|
+
});
|
|
726
|
+
|
|
711
727
|
if (!success) {
|
|
712
728
|
this.throwError(message);
|
|
713
729
|
return;
|
|
@@ -736,6 +752,7 @@ class AjaxRepository extends Repository {
|
|
|
736
752
|
}
|
|
737
753
|
|
|
738
754
|
this._operations.delete = true;
|
|
755
|
+
entity.isSaving = true;
|
|
739
756
|
|
|
740
757
|
const
|
|
741
758
|
method = this.methods.delete,
|
|
@@ -753,6 +770,8 @@ class AjaxRepository extends Repository {
|
|
|
753
770
|
total,
|
|
754
771
|
message
|
|
755
772
|
} = this._processServerResponse(result);
|
|
773
|
+
|
|
774
|
+
entity.isSaving = false;
|
|
756
775
|
|
|
757
776
|
if (!success) {
|
|
758
777
|
this.throwError(message);
|
|
@@ -784,7 +803,10 @@ class AjaxRepository extends Repository {
|
|
|
784
803
|
const
|
|
785
804
|
method = this.methods.delete,
|
|
786
805
|
url = this.api.batchDelete,
|
|
787
|
-
ids = _.map(entities, entity =>
|
|
806
|
+
ids = _.map(entities, (entity) => {
|
|
807
|
+
entity.isSaving = true;
|
|
808
|
+
return entity.id;
|
|
809
|
+
}),
|
|
788
810
|
data = { ids, };
|
|
789
811
|
|
|
790
812
|
return this._send(method, url, data)
|
|
@@ -799,6 +821,10 @@ class AjaxRepository extends Repository {
|
|
|
799
821
|
message
|
|
800
822
|
} = this._processServerResponse(result);
|
|
801
823
|
|
|
824
|
+
_.each(entities, (entity) => {
|
|
825
|
+
entity.isSaving = false;
|
|
826
|
+
});
|
|
827
|
+
|
|
802
828
|
if (!success) {
|
|
803
829
|
this.throwError(message);
|
|
804
830
|
return;
|
|
@@ -991,7 +991,7 @@ export default class Repository extends EventEmitter {
|
|
|
991
991
|
entity = Repository._createEntity(this.schema, data, this, isPersisted, originalIsMapped, isDelayedSave, this.isRemotePhantomMode);
|
|
992
992
|
}
|
|
993
993
|
this._relayEntityEvents(entity);
|
|
994
|
-
this.entities.
|
|
994
|
+
this.entities.unshift(entity);
|
|
995
995
|
|
|
996
996
|
// Create id if needed
|
|
997
997
|
if (!this.isRemotePhantomMode && entity.isPhantom) {
|
|
@@ -1286,7 +1286,7 @@ export default class Repository extends EventEmitter {
|
|
|
1286
1286
|
if (!entities) {
|
|
1287
1287
|
entities = this.entities;
|
|
1288
1288
|
}
|
|
1289
|
-
return _.filter(this.entities, entity => entity.isPhantom);
|
|
1289
|
+
return _.filter(this.entities, entity => entity.isPhantom && !entity.isSaving);
|
|
1290
1290
|
}
|
|
1291
1291
|
|
|
1292
1292
|
/**
|
|
@@ -1296,13 +1296,13 @@ export default class Repository extends EventEmitter {
|
|
|
1296
1296
|
*/
|
|
1297
1297
|
getNonPersisted = (entities = null) => {
|
|
1298
1298
|
if (this.isDestroyed) {
|
|
1299
|
-
this.throwError('this.
|
|
1299
|
+
this.throwError('this.getNonPersisted is no longer valid. Repository has been destroyed.');
|
|
1300
1300
|
return;
|
|
1301
1301
|
}
|
|
1302
1302
|
if (!entities) {
|
|
1303
1303
|
entities = this.entities;
|
|
1304
1304
|
}
|
|
1305
|
-
return _.filter(this.entities, entity => !entity.isPersisted);
|
|
1305
|
+
return _.filter(this.entities, entity => !entity.isPersisted && !entity.isSaving);
|
|
1306
1306
|
}
|
|
1307
1307
|
|
|
1308
1308
|
/**
|
|
@@ -1355,7 +1355,7 @@ export default class Repository extends EventEmitter {
|
|
|
1355
1355
|
if (!entities) {
|
|
1356
1356
|
entities = this.entities;
|
|
1357
1357
|
}
|
|
1358
|
-
return _.filter(entities, entity => entity.isDirty);
|
|
1358
|
+
return _.filter(entities, entity => entity.isDirty && !entity.isSaving);
|
|
1359
1359
|
}
|
|
1360
1360
|
|
|
1361
1361
|
/**
|
|
@@ -1387,7 +1387,7 @@ export default class Repository extends EventEmitter {
|
|
|
1387
1387
|
if (!entities) {
|
|
1388
1388
|
entities = this.entities;
|
|
1389
1389
|
}
|
|
1390
|
-
return _.filter(entities, entity => entity.isStaged);
|
|
1390
|
+
return _.filter(entities, entity => entity.isStaged && !entity.isSaving);
|
|
1391
1391
|
}
|
|
1392
1392
|
|
|
1393
1393
|
/**
|