@simpli/resource-collection
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -161,24 +161,11 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var currentPage, perPage, resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
currentPage = Number(this.currentPage) || 0; | ||
perPage = Number(this.perPage) || 0; | ||
this.currentPage = 0; | ||
this.perPage = this.maxPerPage; | ||
if (this.orderBy === column) { | ||
this.asc = !this.asc; | ||
} | ||
else { | ||
this.asc = true; | ||
} | ||
this.orderBy = column; | ||
return [4 /*yield*/, this.queryAsExpansible()]; | ||
case 1: | ||
resp = _a.sent(); | ||
this.currentPage = currentPage; | ||
this.perPage = perPage; | ||
return [2 /*return*/, resp]; | ||
if (this.orderBy === column) { | ||
this.asc = !this.asc; | ||
} | ||
else { | ||
this.asc = true; | ||
} | ||
this.orderBy = column; | ||
return [2 /*return*/, this.queryToFirstPage()]; | ||
}); | ||
@@ -185,0 +172,0 @@ }); |
@@ -15,5 +15,5 @@ import { IResource } from './IResource'; | ||
queryToFirstPage(): Promise<void>; | ||
queryOrderBy(column: string): Promise<any>; | ||
queryOrderBy(column: string): Promise<void>; | ||
onBeforeSerialization(): void; | ||
onAfterSerialization(): void; | ||
} |
{ | ||
"name": "@simpli/resource-collection", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A data-structure library to work with ResourceCollections (with Id and Tag) and PageCollections (search and order as well)", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -159,1 +159,49 @@ # Resource-Collection | ||
``` | ||
### Create your ExpansibleCollection | ||
This collection can concat new items. | ||
Note this class expands PageCollection, so this can be used as a regular pagination too. | ||
```typescript | ||
class MyExpansibleCollection extends ExpansibleCollection<MyResource> { | ||
constructor() { | ||
super(MyResource) | ||
} | ||
customFilter: string | null = null | ||
async queryAsPage() { | ||
// implement how to update itself with API calls | ||
// send the PageCollection properties to the server | ||
// { search, currentPage, perPage, orderBy, asc } | ||
// and set other PageCollection properties on response | ||
// this.total = <the amount of all items, as if it wasn't paginated> | ||
// this.items = <the items on the current page> | ||
// the class is prepared to be used with class-transformer library | ||
// example using @simpli/serialized-request: | ||
return await Request.get(`/mything`, {params: this.params}) | ||
.as(this) | ||
.getResponse() | ||
} | ||
} | ||
``` | ||
## ResourceCollection props and methods | ||
```typescript | ||
const subject = new MyExpansibleCollection() | ||
subject.setPerPage(20) | ||
await subject.expand() // showing 20 items | ||
await subject.expand() // showing more 20 items; total = 40 | ||
await subject.expand() // showing more 20 items; total = 60 | ||
subject.customFilter = 'foo' | ||
await subject.update() // updates the information after the filter; still 60 items | ||
// or | ||
await subject.queryToFirstPage() // reset collection to its initial state; showing 20 items | ||
await subject.queryOrderBy('bar') // apply orderby filter | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
207
2739842
21478