@onehat/data 1.8.31 → 1.8.32
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.
|
@@ -8,6 +8,12 @@ describe('MemoryRepository', function() {
|
|
|
8
8
|
model: {
|
|
9
9
|
idProperty: 'key',
|
|
10
10
|
displayProperty: 'value',
|
|
11
|
+
sorters: [
|
|
12
|
+
{
|
|
13
|
+
name: 'key',
|
|
14
|
+
direction: 'ASC',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
11
17
|
properties: [
|
|
12
18
|
{ name: 'key', type: 'int' },
|
|
13
19
|
{ name: 'value' },
|
|
@@ -19,6 +25,7 @@ describe('MemoryRepository', function() {
|
|
|
19
25
|
id: 'foo',
|
|
20
26
|
schema: this.schema,
|
|
21
27
|
isPaginated: true,
|
|
28
|
+
isSorted: true,
|
|
22
29
|
data: [
|
|
23
30
|
{ key: 1, value: 'one', },
|
|
24
31
|
{ key: 2, value: 'two', },
|
|
@@ -148,11 +155,19 @@ describe('MemoryRepository', function() {
|
|
|
148
155
|
|
|
149
156
|
// setPageSize
|
|
150
157
|
this.repository.setPageSize(2);
|
|
158
|
+
this.repository.setPage(2);
|
|
151
159
|
expect(this.repository.pageTotal).to.be.eq(2);
|
|
160
|
+
let entitiesOnPage = this.repository.getEntitiesOnPage();
|
|
161
|
+
expect(_.size(entitiesOnPage)).to.be.eq(2);
|
|
162
|
+
|
|
163
|
+
expect(entitiesOnPage[0].id).to.be.eq(3);
|
|
164
|
+
expect(entitiesOnPage[1].id).to.be.eq(4);
|
|
152
165
|
|
|
153
166
|
// setPage
|
|
154
167
|
this.repository.setPage(3);
|
|
155
168
|
expect(this.repository.pageTotal).to.be.eq(1);
|
|
169
|
+
entitiesOnPage = this.repository.getEntitiesOnPage();
|
|
170
|
+
expect(_.size(entitiesOnPage)).to.be.eq(1);
|
|
156
171
|
|
|
157
172
|
// prevPage
|
|
158
173
|
this.repository.prevPage();
|
|
@@ -206,7 +221,7 @@ describe('MemoryRepository', function() {
|
|
|
206
221
|
const result = this.repository.getFirstBy((entity) => {
|
|
207
222
|
return entity.id > 2;
|
|
208
223
|
});
|
|
209
|
-
expect(result.id).to.be.eq(
|
|
224
|
+
expect(result.id).to.be.eq(3);
|
|
210
225
|
});
|
|
211
226
|
|
|
212
227
|
it('Repository.* retrieve methods, after delete/add', async function() {
|
|
@@ -465,9 +480,13 @@ describe('MemoryRepository', function() {
|
|
|
465
480
|
|
|
466
481
|
});
|
|
467
482
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
483
|
+
describe('toString', function() {
|
|
484
|
+
|
|
485
|
+
it('toString', function() {
|
|
486
|
+
const str = this.repository.toString();
|
|
487
|
+
expect(str).to.be.eq('MemoryRepository {bar} - foo');
|
|
488
|
+
});
|
|
489
|
+
|
|
471
490
|
});
|
|
472
491
|
|
|
473
492
|
});
|
package/package.json
CHANGED
package/src/Repository/Memory.js
CHANGED
|
@@ -429,6 +429,27 @@ class MemoryRepository extends Repository {
|
|
|
429
429
|
}
|
|
430
430
|
/* */
|
|
431
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Get an array of all active Entities on current page,
|
|
434
|
+
* with sorting and filtering applied.
|
|
435
|
+
* @return {array} Entities that passed through filter
|
|
436
|
+
*/
|
|
437
|
+
getEntitiesOnPage = () => {
|
|
438
|
+
if (this.isDestroyed) {
|
|
439
|
+
throw Error('this.getPagedEntities is no longer valid. Repository has been destroyed.');
|
|
440
|
+
}
|
|
441
|
+
const entities = this.getEntities();
|
|
442
|
+
if (!this.isPaginated) {
|
|
443
|
+
return entities;
|
|
444
|
+
}
|
|
445
|
+
const
|
|
446
|
+
pageIx = this.page -1, // zero-indexed page#
|
|
447
|
+
start = pageIx * this.pageSize,
|
|
448
|
+
end = start + this.pageSize;
|
|
449
|
+
return entities.slice(start, end);
|
|
450
|
+
}
|
|
451
|
+
/* */
|
|
452
|
+
|
|
432
453
|
/**
|
|
433
454
|
* Get an array of all Entities
|
|
434
455
|
* @return {Entity[]} Entities that passed through filter
|
|
@@ -564,9 +585,6 @@ class MemoryRepository extends Repository {
|
|
|
564
585
|
|
|
565
586
|
destroy() {
|
|
566
587
|
// objects associated with this RepositoryType
|
|
567
|
-
_.each(this._keyedEntities, (entity) => {
|
|
568
|
-
entity.destroy();
|
|
569
|
-
})
|
|
570
588
|
this._keyedEntities = null;
|
|
571
589
|
this._unsortedEntities = null;
|
|
572
590
|
this._filteredEntities = null;
|