@onehat/data 1.6.9 → 1.6.13
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.
|
@@ -630,6 +630,15 @@ describe('Repository Base', function() {
|
|
|
630
630
|
expect(_.isEqual(entity, dirty[0])).to.be.true;
|
|
631
631
|
});
|
|
632
632
|
|
|
633
|
+
it('isDirty', function() {
|
|
634
|
+
expect(this.repository.isDirty).to.be.false;
|
|
635
|
+
|
|
636
|
+
this.repository.setAutoSave(false);
|
|
637
|
+
const entity = this.repository.getByIx(0);
|
|
638
|
+
entity.value = 'test';
|
|
639
|
+
expect(this.repository.isDirty).to.be.true;
|
|
640
|
+
});
|
|
641
|
+
|
|
633
642
|
it('getDeleted', function() {
|
|
634
643
|
this.repository.setAutoSave(false);
|
|
635
644
|
const entity = this.repository.getByIx(0);
|
|
@@ -718,6 +727,11 @@ describe('Repository Base', function() {
|
|
|
718
727
|
// deleteById
|
|
719
728
|
// deleteDirty
|
|
720
729
|
// deletePhantom
|
|
730
|
+
// undeleteByIx
|
|
731
|
+
// undeleteByRange
|
|
732
|
+
// undeleteBy
|
|
733
|
+
// undeleteById
|
|
734
|
+
// undeleteDeleted
|
|
721
735
|
|
|
722
736
|
});
|
|
723
737
|
|
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -1077,7 +1077,7 @@ class Entity extends EventEmitter {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
1079
1079
|
/**
|
|
1080
|
-
*
|
|
1080
|
+
* Marks a deleted entity as undeleted.
|
|
1081
1081
|
* Only works when autoSave is off for the containing repository
|
|
1082
1082
|
* @fires delete
|
|
1083
1083
|
*/
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -377,6 +377,12 @@ class AjaxRepository extends Repository {
|
|
|
377
377
|
if (this.debugMode) {
|
|
378
378
|
console.log('load result ' + this.name, result);
|
|
379
379
|
}
|
|
380
|
+
|
|
381
|
+
if (this.isDestroyed) {
|
|
382
|
+
// If this repository gets destroyed before it has a chance
|
|
383
|
+
// to process the Ajax request, just ignore the response.
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
380
386
|
|
|
381
387
|
const {
|
|
382
388
|
root,
|
|
@@ -1181,6 +1181,18 @@ export default class Repository extends EventEmitter {
|
|
|
1181
1181
|
return !_.isNil(this.getById(idOrEntity));
|
|
1182
1182
|
}
|
|
1183
1183
|
|
|
1184
|
+
/**
|
|
1185
|
+
* Getter of isDirty for this Repository.
|
|
1186
|
+
* Returns true if any Entities within it are dirty
|
|
1187
|
+
* @return {boolean} isDirty
|
|
1188
|
+
*/
|
|
1189
|
+
get isDirty() {
|
|
1190
|
+
if (this.isDestroyed) {
|
|
1191
|
+
throw Error('this.isDirty is no longer valid. Repository has been destroyed.');
|
|
1192
|
+
}
|
|
1193
|
+
return !!this.getDirty().length;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1184
1196
|
/**
|
|
1185
1197
|
* Convenience function
|
|
1186
1198
|
* Alias for isInRepository
|
|
@@ -1478,6 +1490,52 @@ export default class Repository extends EventEmitter {
|
|
|
1478
1490
|
await this.delete(this.getPhantom());
|
|
1479
1491
|
}
|
|
1480
1492
|
|
|
1493
|
+
/**
|
|
1494
|
+
* Undelete a single Entity by its index (zero-indexed) on the current page
|
|
1495
|
+
* @param {integer} ix - Index
|
|
1496
|
+
* @return {object} entity - Entity
|
|
1497
|
+
*/
|
|
1498
|
+
undeleteByIx = async (ix) => {
|
|
1499
|
+
await this.undelete(this.getByIx(ix));
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* Undelete multiple Entities by their range of indices
|
|
1504
|
+
* (zero-indexed) on the current page
|
|
1505
|
+
* @param {integer} startIx - Index
|
|
1506
|
+
* @param {integer} endIx - Index (inclusive)
|
|
1507
|
+
* @return {array} entities - Array of Entities
|
|
1508
|
+
*/
|
|
1509
|
+
undeleteByRange = async (startIx, endIx) => {
|
|
1510
|
+
await this.undelete(this.getByRange(startIx, endIx));
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Undelete multiple Entities by supplied filter function
|
|
1515
|
+
* @param {function} fn - Filter function to apply to all entities
|
|
1516
|
+
* @return {Entity[]} Entities that passed through filter
|
|
1517
|
+
*/
|
|
1518
|
+
undeleteBy = async (filter) => {
|
|
1519
|
+
await this.undelete(this.getBy(filter));
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
/**
|
|
1523
|
+
* Undelete a single Entity by its id
|
|
1524
|
+
* @param {integer} id - id of record to retrieve
|
|
1525
|
+
* @return {Entity} The Entity with matching id
|
|
1526
|
+
*/
|
|
1527
|
+
undeleteById = async (id) => {
|
|
1528
|
+
await this.undelete(this.getById(id));
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Undelete all deleted Entities
|
|
1533
|
+
* @return {Entity[]} Entities that passed through filter
|
|
1534
|
+
*/
|
|
1535
|
+
undeleteDeleted = async () => {
|
|
1536
|
+
await this.undelete(this.getDeleted());
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1481
1539
|
|
|
1482
1540
|
|
|
1483
1541
|
|