Last active
January 23, 2020 23:55
-
-
Save NeuralGlue/133c0cccd699ca2c94026853a59fca67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface IPageMetadata { | |
position: { | |
current: number, | |
max: number | |
}, | |
data: { | |
per: number, | |
total: number | |
} | |
} | |
export interface IPagedResponse<T> { | |
data: T[]; | |
page: IPageMetadata; | |
} | |
export class PagedMyObjectDatasourceService implements DataSource<MyObject> { | |
private myObjectSubject = new BehaviorSubject<MyObject[]>([]); | |
private metadataSubject = new BehaviorSubject<IPageMetadata>({position:{current:0,max:0}, data:{per:0, total:0}}) | |
public metaData$ = this.metadataSubject.asObservable(); | |
constructor(private myObjectService: MyObjectService){} | |
connect(collectionViewer: CollectionViewer): Observable<MyObject[]> { | |
return this.myObjectSubject.asObservable(); | |
} | |
disconnect(collectionViewer: CollectionViewer): void { | |
this.myObjectSubject.complete(); | |
this.metadataSubject.complete(); | |
} | |
loadObjects() { | |
this.myObjectService.fetchRemoteObjects() | |
.pipe( | |
catchError(() => of([])) | |
) | |
.subscribe ( (result : IPagedResponse<MyObject> => { | |
this.myobjectSubject.next(result.data); | |
this.metadataSubject.next(result.page); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment