Skip to content

Instantly share code, notes, and snippets.

@NeuralGlue
Last active January 23, 2020 23:55
Show Gist options
  • Save NeuralGlue/133c0cccd699ca2c94026853a59fca67 to your computer and use it in GitHub Desktop.
Save NeuralGlue/133c0cccd699ca2c94026853a59fca67 to your computer and use it in GitHub Desktop.
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