Browse Source

fix: change subscription logic to query stream

pull/6605/head
Arman Ozak 6 years ago
parent
commit
e3ac63d73b
  1. 16
      npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

16
npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-list.directive.ts

@ -68,22 +68,22 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
}
private subscribeToQuery() {
this.querySubscription.add(
this.list.query$.subscribe(() => {
if (this.list.page !== this.table.offset) this.table.offset = this.list.page;
}),
);
if (!this.querySubscription.closed) this.querySubscription.unsubscribe();
this.querySubscription = this.list.query$.subscribe(() => {
const offset = this.list.page;
if (this.table.offset !== offset) this.table.offset = offset;
});
}
ngOnChanges({ list }: SimpleChanges) {
this.subscribeToQuery();
if (!list.firstChange) return;
const { maxResultCount, page } = list.currentValue;
this.table.limit = maxResultCount;
this.table.offset = page;
this.querySubscription.unsubscribe();
this.subscribeToQuery();
}
ngOnDestroy() {

Loading…
Cancel
Save